Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HitZone.c
Go to the documentation of this file.
2 {
3  protected ref ScriptInvokerVoid m_OnHealthChanged;
4  protected ref ScriptInvoker m_OnDamageStateChanged; // TODO: make it a ScriptInvoker w/ ScriptedHitZone
5 
6  //------------------------------------------------------------------------------------------------
9  EHitZoneGroup GetHitZoneGroup()
10  {
11  return EHitZoneGroup.VIRTUAL;
12  }
13 
14  //------------------------------------------------------------------------------------------------
18  ScriptInvokerVoid GetOnHealthChanged(bool createNew = true)
19  {
20  if (!m_OnHealthChanged && createNew)
21  m_OnHealthChanged = new ScriptInvokerVoid();
22 
23  return m_OnHealthChanged;
24  }
25 
26  //------------------------------------------------------------------------------------------------
29  ScriptInvoker GetOnDamageStateChanged(bool createNew = true)
30  {
31  if (!m_OnDamageStateChanged && createNew)
32  m_OnDamageStateChanged = new ScriptInvoker();
33 
34  return m_OnDamageStateChanged;
35  }
36 
37  //------------------------------------------------------------------------------------------------
39  IEntity GetOwner()
40  {
41  HitZoneContainerComponent container = GetHitZoneContainer();
42  if (container)
43  return container.GetOwner();
44 
45  return null;
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  override protected void OnHealthSet()
50  {
51  if (m_OnHealthChanged)
52  m_OnHealthChanged.Invoke();
53  }
54 
55  //------------------------------------------------------------------------------------------------
57  override protected void OnDamageStateChanged()
58  {
59  if (m_OnDamageStateChanged)
60  m_OnDamageStateChanged.Invoke(this);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  override float ComputeEffectiveDamage(notnull BaseDamageContext damageContext, bool isDOT)
65  {
66  if (damageContext.damageValue == 0)
67  return 0;
68 
69  if (damageContext.damageType == EDamageType.TRUE)
70  return damageContext.damageValue;
71 
72  //apply base multiplier
73  float effectiveDamage = damageContext.damageValue * GetBaseDamageMultiplier();
74  //apply damage multiplier for this specific damage type
75  effectiveDamage *= GetDamageMultiplier(damageContext.damageType);
76 
77  //DOT doesn't get affected by damage reduction/thresholds, and neither does healing.
78  if (isDOT || effectiveDamage < 0)
79  return effectiveDamage;
80 
81  //apply flat damage reduction
82  effectiveDamage -= GetDamageReduction();
83 
84  //if its less than the damage threshold we discard the damage.
85  //if the damage to take becomes negative (healing) because of the flat damage reduction, this should reset it back to 0 dmg to take.
86  if (effectiveDamage < GetDamageThreshold())
87  effectiveDamage = 0;
88 
89  return effectiveDamage;
90  }
91 
92  // TODO@FAC. To be implemented in gamecode in future also add regen scale multiplier!!!
93  //------------------------------------------------------------------------------------------------
98  void CustomRegeneration(IEntity target, float itemRegenerationDuration, float itemRegenerationSpeed = 0, float itemAbsoluteRegenerationAmount = 0)
99  {
100  if (itemRegenerationSpeed) // If a regeneration time is set, regen will occur for given amount of time at the itemRegenerationSpeed
101  {
102  GetGame().GetCallqueue().CallLater(RemoveCustomRegeneration, itemRegenerationDuration * 1000, false, target, itemRegenerationSpeed);
103  }
104  else if (itemAbsoluteRegenerationAmount) // If an absolute regen amount is set instead of a duration, the regen will last until the amount of points has been distributed at the itemRegenerationSpeed
105  {
106  itemRegenerationSpeed = itemAbsoluteRegenerationAmount / itemRegenerationDuration;
107  GetGame().GetCallqueue().CallLater(RemoveCustomRegeneration, itemRegenerationDuration * 1000, false, target, itemRegenerationSpeed);
108  }
109  else // If regenerating value is 0, quit.
110  {
111  Print("Consumable with regenerating abilities was used but no duration or amount was defined", LogLevel.WARNING);
112  return;
113  }
114 
115  float currentRegen = GetDamageOverTime(EDamageType.HEALING);
116  SetDamageOverTime(EDamageType.HEALING, currentRegen + itemRegenerationSpeed * -1);
117  }
118 
119  //-----------------------------------------------------------------------------------------------------------
123  void RemoveCustomRegeneration(IEntity target, float itemRegenerationSpeed)
124  {
125  // if healing was removed somehow before the regeneration was finished, don't remove again
126  if (GetDamageOverTime(EDamageType.HEALING) + itemRegenerationSpeed > 0)
127  SetDamageOverTime(EDamageType.HEALING, 0);
128  else
129  SetDamageOverTime(EDamageType.HEALING, (GetDamageOverTime(EDamageType.HEALING) + itemRegenerationSpeed));
130  }
131 
132 #ifdef WORKBENCH
133  //------------------------------------------------------------------------------------------------
134  void DrawDebug();
135 #endif
136 }
BaseDamageContext
Definition: BaseDamageContext.c:12
HitZone
Definition: HitZone.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
HitZoneContainerComponent
Definition: HitZoneContainerComponent.c:12
GetDamageThreshold
float GetDamageThreshold()
Definition: SCR_DestructibleEntity.c:112
SCR_HitZone
Definition: SCR_HitZone.c:1
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
EDamageType
EDamageType
Definition: EDamageType.c:12
GetDamageReduction
float GetDamageReduction()
Definition: SCR_DestructibleEntity.c:102
GetDamageMultiplier
float GetDamageMultiplier(EDamageType type)
Definition: SCR_DestructibleEntity.c:92