Client LuaCsForBarotrauma
AfflictionSpaceHerpes.cs
1 using Microsoft.Xna.Framework;
2 using System.Linq;
3 
4 namespace Barotrauma
5 {
11  {
12  private float invertControlsCooldown = 60.0f;
13  private float stunCoolDown = 60.0f;
14  private float invertControlsTimer;
15 
16  private float invertControlsToggleTimer;
17 
18  public AfflictionSpaceHerpes(AfflictionPrefab prefab, float strength) : base(prefab, strength)
19  {
20  }
21 
22  public override void Update(CharacterHealth characterHealth, Limb targetLimb, float deltaTime)
23  {
24  base.Update(characterHealth, targetLimb, deltaTime);
25 
26  if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
27 
28  invertControlsCooldown -= deltaTime;
29  if (invertControlsCooldown <= 0.0f)
30  {
31  //invert controls every 126-234 seconds when strength is close to 0
32  //every 56-104 seconds when strength is close to 100
33  invertControlsCooldown = (180.0f - Strength) * Rand.Range(0.7f, 1.3f);
34  invertControlsTimer = MathHelper.Lerp(10.0f, 60.0f, Strength / 100.0f) * Rand.Range(0.7f, 1.3f);
35  }
36  else if (invertControlsTimer > 0.0f)
37  {
38  //randomly toggle inverted controls on/off every 5 seconds
39  invertControlsToggleTimer -= deltaTime;
40  if (invertControlsToggleTimer <= 0.0f)
41  {
42  invertControlsToggleTimer = 5.0f;
43  if (Rand.Range(0.0f, 1.0f) < 0.5f)
44  {
45  characterHealth.ReduceAfflictionOnAllLimbs("invertcontrols".ToIdentifier(), 100);
46  }
47  else
48  {
49  var invertControlsAffliction = AfflictionPrefab.List.FirstOrDefault(ap => ap.Identifier == "invertcontrols");
50  characterHealth.ApplyAffliction(null, new Affliction(invertControlsAffliction, 5.0f));
51  }
52  }
53 
54  invertControlsTimer -= deltaTime;
55  }
56 
57 
58  if (Strength > 50.0f)
59  {
60  stunCoolDown -= deltaTime;
61  if (stunCoolDown <= 0.0f)
62  {
63  //stun every 126-234 seconds when strength is close to 0
64  //stun 56-104 seconds when strength is close to 100
65  stunCoolDown = (180.0f - Strength) * Rand.Range(0.7f, 1.3f);
66  float stunDuration = MathHelper.Lerp(3.0f, 10.0f, Strength / 100.0f) * Rand.Range(0.7f, 1.3f);
67  characterHealth.Character.SetStun(stunDuration);
68  }
69  }
70  }
71  }
72 }
virtual float Strength
Definition: Affliction.cs:31
Affliction(AfflictionPrefab prefab, float strength)
Definition: Affliction.cs:97
AfflictionPrefab is a prefab that defines a type of affliction that can be applied to a character....
static IEnumerable< AfflictionPrefab > List
A special affliction type that periodically inverts the character's controls and stuns the character....
AfflictionSpaceHerpes(AfflictionPrefab prefab, float strength)
override void Update(CharacterHealth characterHealth, Limb targetLimb, float deltaTime)
void ApplyAffliction(Limb targetLimb, Affliction affliction, bool allowStacking=true, bool ignoreUnkillability=false)
void ReduceAfflictionOnAllLimbs(Identifier afflictionIdOrType, float amount, ActionType? treatmentAction=null, Character attacker=null)
void SetStun(float newStun, bool allowStunDecrease=false, bool isNetworkMessage=false)
static NetworkMember NetworkMember
Definition: GameMain.cs:190