Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HealSupportStationComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/SupportStation", description: "")]
3 {
4  [Attribute("SOUND_HEAL_SELF", desc: "Sound effect played when heal is updated and not done. Broadcast to players. Leave empty if no sfx", category: "Heal/Repair Support Station")]
5  protected string m_sOnHealBloodUpdateSoundEffectEventName;
6 
7  protected ref SCR_AudioSourceConfiguration m_OnHealBloodUpdateAudioSourceConfiguration;
8 
9  //------------------------------------------------------------------------------------------------
11  SCR_AudioSourceConfiguration GetOnHealBloodUpdateAudioConfig()
12  {
13  //~ Create Audio source if it does not yet exist
16 
18  }
19 }
20 
21 class SCR_HealSupportStationComponent : SCR_BaseDamageHealSupportStationComponent
22 {
23  [Attribute("1000", desc: "Max blood amount healed each execute. If you hold the action it will heal each time the action ends", category: "Heal/Repair Support Station")]
24  protected float m_iBloodHealedEachExecute;
25 
26  [Attribute("100", desc: "Supply cost for ever 'm_iBloodHealedEachExecute' damage healed. If the left over blood amount is less then it will of course be cheaper with a min value of 1", category: "Heal/Repair Support Station")]
27  protected int m_iSupplyCostBloodHealed;
28 
29  [Attribute("1", desc: "The max blood scaled that this support station can heal. 1 == 100%", params: "0.01 1", category: "Heal/Repair Support Station")]
30  protected float m_fMaxBloodScaled;
31 
32  //------------------------------------------------------------------------------------------------
34  {
35  return ESupportStationType.HEAL;
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  protected override float GetDamageOrStateToHeal(IEntity actionOwner, IEntity actionUser, notnull SCR_BaseDamageHealSupportStationAction action, out EDamageType activeDoT, out notnull array<HitZone> hitZones)
40  {
41  float damageToHeal = super.GetDamageOrStateToHeal(actionOwner, actionUser, action, activeDoT, hitZones);
42  if (damageToHeal > 0)
43  return damageToHeal;
44 
46  if (!healAction)
47  return damageToHeal;
48 
49  HitZone bloodHitZone = healAction.GetBloodHitZoneToHeal();
50  if (!bloodHitZone)
51  return damageToHeal;
52 
53  hitZones.Clear();
54  hitZones.Insert(bloodHitZone);
55 
56  return Math.Clamp(action.GetActionDamageManager().GetHitZonesDamage(m_fMaxBloodScaled, hitZones), 0, m_iBloodHealedEachExecute);
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  protected override int GetSupplyCostAction(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
61  {
62  if (!AreSuppliesEnabled())
63  return 0;
64 
66 
67  array<HitZone> hitZones = {};
68  EDamageType activeDoT;
69  float damageToHeal = GetDamageOrStateToHeal(actionOwner, actionUser, damageHealAction, activeDoT, hitZones);
70  if (activeDoT != -1)
71  return super.GetSupplyCostAction(actionOwner, actionUser, action);
72 
73  //~ Not a character
74  SCR_CharacterDamageManagerComponent characterDamageManager = SCR_CharacterDamageManagerComponent.Cast(damageHealAction.GetActionDamageManager());
75  if (!characterDamageManager)
76  return super.GetSupplyCostAction(actionOwner, actionUser, action);
77 
78  HitZone bloodHitZone = characterDamageManager.GetBloodHitZone();
79 
80  //~ No blood hitZone or bloodhitZone full health, use default logic
81  if (hitZones.Count() != 1 || hitZones[0] != bloodHitZone)
82  return super.GetSupplyCostAction(actionOwner, actionUser, action);
83 
84  //~ Calculate the supply cost
85  float bloodHealCost = (damageToHeal / m_iBloodHealedEachExecute) * m_iSupplyCostBloodHealed;
86 
87  //~ There is damage so there should always be a cost of 1
88  if ((bloodHealCost + m_iBaseSupplyCostOnUse) < 1)
89  return 1;
90 
91  return Math.Ceil(bloodHealCost + m_iBaseSupplyCostOnUse);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
96  {
98  array<HitZone> hitZones = {};
99  EDamageType activeDoT;
100  float damageToHeal = GetDamageOrStateToHeal(actionOwner, actionUser, damageHealAction, activeDoT, hitZones);
101  if (activeDoT != -1)
102  {
103  super.OnExecutedServer(actionOwner, actionUser, action);
104  return;
105  }
106 
107  //~ Not a character
108  SCR_CharacterDamageManagerComponent characterDamageManager = SCR_CharacterDamageManagerComponent.Cast(SCR_BaseDamageHealSupportStationAction.Cast(action).GetActionDamageManager());
109  if (!characterDamageManager)
110  {
111  super.OnExecutedServer(actionOwner, actionUser, action);
112  return;
113  }
114  HitZone bloodHitZone = characterDamageManager.GetBloodHitZone();
115 
116  //~ No blood hitZone or bloodhitZone full health, use default logic
117  if (hitZones.Count() != 1 || hitZones[0] != bloodHitZone)
118  {
119  super.OnExecutedServer(actionOwner, actionUser, action);
120  return;
121  }
122 
123  //~ Consume supplies
124  if (AreSuppliesEnabled())
125  {
126  //~ Failed to consume supplies, meaning there weren't enough supplies for the action
127  if (!OnConsumeSuppliesServer(GetSupplyCostAction(actionOwner, actionUser, action)))
128  return;
129  }
130 
131  //~ Heal the blood hitZone
132  characterDamageManager.HealHitZones(damageToHeal, true, m_fMaxBloodScaled, hitZones);
133 
134  //~ Get healstate
136  if (bloodHitZone.GetHealthScaled() < m_fMaxBloodScaled)
137  healState = SCR_EDamageSupportStationHealState.BLOOD_UPDATE;
138  else if (m_fMaxBloodScaled < 1 && bloodHitZone.GetHealthScaled() == m_fMaxBloodScaled)
139  healState = SCR_EDamageSupportStationHealState.BLOOD_DONE_NOT_FULL_HEAL;
140  else
141  healState = SCR_EDamageSupportStationHealState.BLOOD_DONE;
142 
143  RplId ownerId;
144  RplId userId;
145  int playerId;
146  FindEntityIds(actionOwner, actionUser, ownerId, userId, playerId);
147 
148  OnExecuteDamageSystem(actionOwner, actionUser, healState, SCR_BaseDamageHealSupportStationAction.Cast(action), bloodHitZone.GetHealthScaled());
149  Rpc(OnExecuteDamageSystemBroadcast, ownerId, userId, healState, action.GetActionID(), bloodHitZone.GetHealthScaled());
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  protected override void OnExecuteDamageSystem(IEntity actionOwner, IEntity actionUser, SCR_EDamageSupportStationHealState healState, SCR_BaseDamageHealSupportStationAction action, float healthScaled)
154  {
155  //~ Could not send notification as unknown owner or user
156  if (!actionOwner || !actionUser)
157  {
158  //~ Action was still succesfully executed
159  OnSuccessfullyExecuted(actionOwner, actionUser, action);
160  return;
161  }
162 
163  bool isBloodHealState = false;
164 
165  //~ Play sound effect
167  if (classData)
168  {
169  switch (healState)
170  {
171  case SCR_EDamageSupportStationHealState.BLOOD_UPDATE :
172  {
173  isBloodHealState = true;
174  PlaySoundEffect(classData.GetOnHealBloodUpdateAudioConfig(), actionOwner, action);
175  break;
176  }
177  case SCR_EDamageSupportStationHealState.BLOOD_DONE_NOT_FULL_HEAL :
178  {
179  isBloodHealState = true;
180  PlaySoundEffect(GetOnUseAudioConfig(), actionOwner, action);
181  break;
182  }
183  case SCR_EDamageSupportStationHealState.BLOOD_DONE :
184  {
185  isBloodHealState = true;
186  PlaySoundEffect(GetOnUseAudioConfig(), actionOwner, action);
187 
188  //~ Play done voice event (if any)
189  PlayCharacterVoiceEvent(actionUser);
190  break;
191  }
192  }
193  }
194 
195  //~ Blood not healed, use default logic
196  if (!isBloodHealState)
197  {
198  super.OnExecuteDamageSystem(actionOwner, actionUser, healState, action, healthScaled);
199  return;
200  }
201 
202  //~ On succesfully executed
203  OnSuccessfullyExecuted(actionOwner, actionUser, action);
204 
205  //~ Do not send notification
207  return;
208 
209  SendDamageSupportStationNotification(actionOwner, actionUser, action, healState, healthScaled);
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  protected override void SendDamageSupportStationNotification(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action, SCR_EDamageSupportStationHealState healState, float healthScaled)
214  {
215  //~ Editable entity not found
216  SCR_EditableEntityComponent userEditableEntity = SCR_EditableEntityComponent.Cast(actionUser.FindComponent(SCR_EditableEntityComponent));
217  if (!userEditableEntity)
218  return;
219 
220  int ownerPlayerID;
221 
222  SCR_PossessingManagerComponent possesionManager = SCR_PossessingManagerComponent.GetInstance();
223  if (possesionManager)
224  {
225  ownerPlayerID = possesionManager.GetPlayerIdFromControlledEntity(actionOwner);
226  }
227  else
228  {
229  SCR_EditableEntityComponent ownerEditableEntity = SCR_EditableEntityComponent.Cast(actionOwner.FindComponent(SCR_EditableEntityComponent));
230 
231  if (ownerEditableEntity)
232  ownerPlayerID = ownerEditableEntity.GetPlayerID();
233  }
234 
235  //~ If owner is AI do not send notification
236  if (ownerPlayerID <= 0)
237  return;
238 
239  RplId userRplId = Replication.FindId(userEditableEntity);
240 
241  ECharacterHitZoneGroup notificationHitZoneGroup = ECharacterHitZoneGroup.VIRTUAL;
243  if (healAction)
244  notificationHitZoneGroup = healAction.GetHitZoneGroup();
245 
246  //~ Send correct notification
247  switch (healState)
248  {
249  case SCR_EDamageSupportStationHealState.HEAL_UPDATE :
250  {
251  if (SCR_PlayerController.GetLocalPlayerId() == ownerPlayerID)
252  SCR_NotificationsComponent.SendLocal(ENotification.SUPPORTSTATION_HEALED_BY_OTHER_UPDATE, userRplId, notificationHitZoneGroup, healthScaled * 1000);
253  return;
254  }
255  case SCR_EDamageSupportStationHealState.HEAL_DONE_NOT_FULL_HEAL :
256  {
257  if (SCR_PlayerController.GetLocalPlayerId() == ownerPlayerID)
258  SCR_NotificationsComponent.SendLocal(ENotification.SUPPORTSTATION_HEALED_BY_OTHER_DONE_NOT_FULL, userRplId, notificationHitZoneGroup, healthScaled * 1000);
259  return;
260  }
261  case SCR_EDamageSupportStationHealState.HEAL_DONE :
262  {
263  if (SCR_PlayerController.GetLocalPlayerId() == ownerPlayerID)
264  SCR_NotificationsComponent.SendLocal(ENotification.SUPPORTSTATION_HEALED_BY_OTHER_DONE, userRplId, notificationHitZoneGroup, 1);
265 
266  return;
267  }
268  }
269  }
270 }
OnExecuteDamageSystem
protected override void OnExecuteDamageSystem(IEntity actionOwner, IEntity actionUser, SCR_EDamageSupportStationHealState healState, SCR_BaseDamageHealSupportStationAction action, float healthScaled)
Definition: SCR_HealSupportStationComponent.c:153
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
ECharacterHitZoneGroup
ECharacterHitZoneGroup
Definition: SCR_CharacterDamageManagerComponent.c:1
SCR_PlayerController
Definition: SCR_PlayerController.c:31
m_iBaseSupplyCostOnUse
protected int m_iBaseSupplyCostOnUse
Definition: SCR_BaseSupportStationComponent.c:100
m_OnHealBloodUpdateAudioSourceConfiguration
protected ref SCR_AudioSourceConfiguration m_OnHealBloodUpdateAudioSourceConfiguration
Definition: SCR_HealSupportStationComponent.c:5
FindEntityIds
protected void FindEntityIds(IEntity owner, IEntity user, out RplId ownerId, out RplId userId, out int playerId)
Definition: SCR_BaseSupportStationComponent.c:148
HitZone
Definition: HitZone.c:12
GetDamageOrStateToHeal
protected override float GetDamageOrStateToHeal(IEntity actionOwner, IEntity actionUser, notnull SCR_BaseDamageHealSupportStationAction action, out EDamageType activeDoT, out notnull array< HitZone > hitZones)
Definition: SCR_HealSupportStationComponent.c:39
OnSuccessfullyExecuted
protected void OnSuccessfullyExecuted(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
Definition: SCR_BaseSupportStationComponent.c:214
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetSupportStationType
ESupportStationType GetSupportStationType()
Definition: SCR_BaseSupportStationComponent.c:395
SCR_HealSupportStationAction
Definition: SCR_HealSupportStationAction.c:1
PlaySoundEffect
protected void PlaySoundEffect(SCR_AudioSourceConfiguration audioConfig, notnull IEntity soundOwner, SCR_BaseUseSupportStationAction action)
Definition: SCR_BaseSupportStationComponent.c:222
PlayCharacterVoiceEvent
protected void PlayCharacterVoiceEvent(IEntity character)
Definition: SCR_BaseSupportStationComponent.c:269
m_sOnHealBloodUpdateSoundEffectEventName
protected string m_sOnHealBloodUpdateSoundEffectEventName
Definition: SCR_HealSupportStationComponent.c:3
ENotification
ENotification
Definition: ENotification.c:4
GetSendNotificationOnUse
bool GetSendNotificationOnUse()
Definition: SCR_BaseSupportStationComponent.c:28
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
OnConsumeSuppliesServer
protected bool OnConsumeSuppliesServer(int amount)
Definition: SCR_BaseSupportStationComponent.c:630
OnExecutedServer
override void OnExecutedServer(notnull IEntity actionOwner, notnull IEntity actionUser, notnull SCR_BaseUseSupportStationAction action)
Definition: SCR_HealSupportStationComponent.c:95
ESupportStationType
ESupportStationType
Definition: ESupportStationType.c:2
Attribute
SCR_HealSupportStationComponentClass SCR_BaseDamageHealSupportStationComponentClass Attribute("1000", desc:"Max blood amount healed each execute. If you hold the action it will heal each time the action ends", category:"Heal/Repair Support Station")
Definition: SCR_HealSupportStationComponent.c:23
OnExecuteDamageSystemBroadcast
protected void OnExecuteDamageSystemBroadcast(RplId ownerId, RplId userId, SCR_EDamageSupportStationHealState healState, int actionId, float healthScaled)
Definition: SCR_BaseDamageHealSupportStationComponent.c:288
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_HealSupportStationComponentClass
Definition: SCR_HealSupportStationComponent.c:2
SCR_BaseDamageHealSupportStationAction
Allows healing of action owner (not user)
Definition: SCR_BaseDamageHealSupportStationAction.c:2
EDamageType
EDamageType
Definition: EDamageType.c:12
SCR_BaseDamageHealSupportStationComponentClass
Definition: SCR_BaseDamageHealSupportStationComponent.c:2
SendDamageSupportStationNotification
protected override void SendDamageSupportStationNotification(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action, SCR_EDamageSupportStationHealState healState, float healthScaled)
Definition: SCR_HealSupportStationComponent.c:213
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
AreSuppliesEnabled
bool AreSuppliesEnabled()
Definition: SCR_BaseSupportStationComponent.c:644
SCR_EDamageSupportStationHealState
SCR_EDamageSupportStationHealState
Definition: SCR_BaseDamageHealSupportStationComponent.c:366
SCR_BaseUseSupportStationAction
Definition: SCR_BaseUseSupportStationAction.c:1
GetOnUseAudioConfig
SCR_AudioSourceConfiguration GetOnUseAudioConfig()
Definition: SCR_BaseSupportStationComponent.c:54
CreateSoundAudioConfig
SCR_AudioSourceConfiguration CreateSoundAudioConfig(string soundEventName)
Definition: SCR_BaseDamageHealSupportStationComponent.c:16
GetSupplyCostAction
protected override int GetSupplyCostAction(IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action)
Definition: SCR_HealSupportStationComponent.c:60
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180