Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DataCollectorHealingItemsModule.c
Go to the documentation of this file.
2 class ConsumableTypeStats : Managed
3 {
4  [Attribute("0", UIWidgets.ComboBox, "Item type", "", ParamEnumArray.FromEnum(SCR_EConsumableType) )]
5  protected SCR_EConsumableType m_eConsumableType;
6 
7  [Attribute("0", UIWidgets.ComboBox, "Stat to affect when used on self", "", ParamEnumArray.FromEnum(SCR_EDataStats) )]
8  protected SCR_EDataStats m_eDataStatsSelf;
9 
10  [Attribute("0", UIWidgets.ComboBox, "Stat to affect when used on a different character", "", ParamEnumArray.FromEnum(SCR_EDataStats) )]
11  protected SCR_EDataStats m_eDataStatsFriend;
12 
13  //------------------------------------------------------------------------------------------------
14  SCR_EConsumableType GetConsumableType()
15  {
16  return m_eConsumableType;
17  }
18 
19  //------------------------------------------------------------------------------------------------
20  SCR_EDataStats GetStat(bool self)
21  {
22  if (self)
23  return m_eDataStatsSelf;
24 
25  return m_eDataStatsFriend;
26  }
27 };
28 
31 {
32  [Attribute("", UIWidgets.Object, "Healing Items")]
33  protected ref array<ref ConsumableTypeStats> m_aConsumableTypes;
34 
35  protected ref map<int, IEntity> m_mTrackedPlayers = new map<int, IEntity>();
36 
37  //------------------------------------------------------------------------------------------------
38  protected override void AddInvokers(IEntity player)
39  {
40  super.AddInvokers(player);
41  if (!player)
42  return;
43 
44  SCR_ChimeraCharacter chimeraPlayer = SCR_ChimeraCharacter.Cast(player);
45  if (!chimeraPlayer)
46  return;
47 
48  SCR_CharacterControllerComponent characterController = SCR_CharacterControllerComponent.Cast(chimeraPlayer.GetCharacterController());
49  if (!characterController)
50  return;
51 
52  characterController.m_OnItemUseEndedInvoker.Insert(HealingItemUsed);
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  protected override void RemoveInvokers(IEntity player)
57  {
58  super.RemoveInvokers(player);
59  if (!player)
60  return;
61 
62  SCR_ChimeraCharacter chimeraPlayer = SCR_ChimeraCharacter.Cast(player);
63  if (!chimeraPlayer)
64  return;
65 
66  SCR_CharacterControllerComponent characterController = SCR_CharacterControllerComponent.Cast(chimeraPlayer.GetCharacterController());
67  if (!characterController)
68  return;
69 
70  characterController.m_OnItemUseEndedInvoker.Remove(HealingItemUsed);
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  protected void HealingItemUsed(IEntity item, bool ActionCompleted, ItemUseParameters animParams)
75  {
76  if (!item || !ActionCompleted)
77  return;
78 
79  SCR_ConsumableItemComponent consumableItem = SCR_ConsumableItemComponent.Cast(item.FindComponent(SCR_ConsumableItemComponent));
80  if (!consumableItem)
81  return;
82 
83  IEntity user = consumableItem.GetCharacterOwner();
84  if (!user)
85  return;
86 
87  IEntity target = consumableItem.GetTargetCharacter();
88  if (!target)
89  target = user;
90 
91  int userID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
92  if (userID == 0) // Non-player character
93  return;
94 
95  SCR_EConsumableType typeId = consumableItem.GetConsumableType();
96 
97  for (int i = m_aConsumableTypes.Count() - 1; i >= 0; i--)
98  {
99  if (m_aConsumableTypes[i].GetConsumableType() == typeId)
100  {
101  GetGame().GetDataCollector().GetPlayerData(userID).AddStat(m_aConsumableTypes[i].GetStat(target == user));
102  return;
103  }
104  }
105 
106  Print("SCR_DataCollectorHealingItemsModule:HealingItemUsed: Error: Unidentified Healing item typeId. Value is " + typeId + ".", LogLevel.WARNING);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override void OnPlayerSpawned(int playerID, IEntity controlledEntity)
111  {
112  IEntity ent = m_mTrackedPlayers.Get(playerID);
113  if (ent)
114  RemoveInvokers(ent);
115 
116  AddInvokers(controlledEntity);
117 
118  m_mTrackedPlayers.Insert(playerID, controlledEntity);
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  override void OnPlayerDisconnected(int playerID, IEntity controlledEntity = null)
123  {
124  m_mTrackedPlayers.Remove(playerID);
125  }
126 
127 #ifdef ENABLE_DIAG
128  //------------------------------------------------------------------------------------------------
129  override void OnControlledEntityChanged(IEntity from, IEntity to)
130  {
131  super.OnControlledEntityChanged(from, to);
132 
133  if (to)
134  {
135  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(to);
136  m_mTrackedPlayers.Insert(playerID, to);
137  }
138  else if (from)
139  {
140  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(from);
141  m_mTrackedPlayers.Remove(playerID);
142  }
143  }
144 #endif
145 
146  //------------------------------------------------------------------------------------------------
147  override void Update(float timeTick)
148  {
149  //If there's no data collector, do nothing
150  if (!GetGame().GetDataCollector())
151  return;
152 
153  m_fTimeSinceUpdate += timeTick;
154 
155  if (m_fTimeSinceUpdate < m_fUpdatePeriod)
156  return;
157 
158  SCR_PlayerData playerData;
159  int playerId;
160 
161  for (int i = m_mTrackedPlayers.Count() - 1; i >= 0; i--)
162  {
163  playerId = m_mTrackedPlayers.GetKey(i);
164  playerData = GetGame().GetDataCollector().GetPlayerData(playerId);
165 
166  //DEBUG display
167 #ifdef ENABLE_DIAG
168  if (m_StatsVisualization)
169  {
170  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.BANDAGESSELF).SetText(playerData.GetStat(SCR_EDataStats.BANDAGE_SELF).ToString());
171  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.BANDAGESFRIENDLIES).SetText(playerData.GetStat(SCR_EDataStats.BANDAGE_FRIENDLIES).ToString());
172  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.TOURNIQUETSSELF).SetText(playerData.GetStat(SCR_EDataStats.TOURNIQUET_SELF).ToString());
173  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.TOURNIQUETSFRIENDLIES).SetText(playerData.GetStat(SCR_EDataStats.TOURNIQUET_FRIENDLIES).ToString());
174  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.SALINESELF).SetText(playerData.GetStat(SCR_EDataStats.SALINE_SELF).ToString());
175  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.SALINEFRIENDLIES).SetText(playerData.GetStat(SCR_EDataStats.SALINE_FRIENDLIES).ToString());
176  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.MORPHINESELF).SetText(playerData.GetStat(SCR_EDataStats.MORPHINE_SELF).ToString());
177  m_StatsVisualization.Get(SCR_EHealingItemsModuleStats.MORPHINEFRIENDLIES).SetText(playerData.GetStat(SCR_EDataStats.MORPHINE_FRIENDLIES).ToString());
178  }
179 #endif
180  }
181  m_fTimeSinceUpdate = 0;
182  }
183 
184 #ifdef ENABLE_DIAG
185  //------------------------------------------------------------------------------------------------
186  override void CreateVisualization()
187  {
188  super.CreateVisualization();
189  if (!m_StatsVisualization)
190  return;
191 
192  CreateEntry("Bandages on self: ", 0, SCR_EHealingItemsModuleStats.BANDAGESSELF);
193  CreateEntry("Bandages on friendlies: ", 0, SCR_EHealingItemsModuleStats.BANDAGESFRIENDLIES);
194  CreateEntry("Tourniquets on self: ", 0, SCR_EHealingItemsModuleStats.TOURNIQUETSSELF);
195  CreateEntry("Tourniquets on friendlies: ", 0, SCR_EHealingItemsModuleStats.TOURNIQUETSFRIENDLIES);
196  CreateEntry("saline on self: ", 0, SCR_EHealingItemsModuleStats.SALINESELF);
197  CreateEntry("saline on friendlies: ", 0, SCR_EHealingItemsModuleStats.SALINEFRIENDLIES);
198  CreateEntry("Morphine on self: ", 0, SCR_EHealingItemsModuleStats.MORPHINESELF);
199  CreateEntry("Morphine on friendlies: ", 0, SCR_EHealingItemsModuleStats.MORPHINEFRIENDLIES);
200  }
201 #endif
202 };
203 
204 #ifdef ENABLE_DIAG
205 enum SCR_EHealingItemsModuleStats
206 {
207  BANDAGESSELF,
208  BANDAGESFRIENDLIES,
209  TOURNIQUETSSELF,
210  TOURNIQUETSFRIENDLIES,
211  SALINESELF,
212  SALINEFRIENDLIES,
213  MORPHINESELF,
214  MORPHINEFRIENDLIES
215 };
216 #endif
SCR_EConsumableType
SCR_EConsumableType
Type of consumable gadget.
Definition: SCR_ConsumableEffectBase.c:2
m_fTimeSinceUpdate
protected float m_fTimeSinceUpdate
Definition: SCR_RestrictedDeployableSpawnPointComponent.c:89
SCR_DataCollectorHealingItemsModule
Definition: SCR_DataCollectorHealingItemsModule.c:30
OnControlledEntityChanged
protected void OnControlledEntityChanged(IEntity from, IEntity to)
Runs every time the controlled entity has been changed.
Definition: SCR_ItemPlacementComponent.c:113
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ItemUseParameters
Definition: ItemUseParameters.c:15
SCR_PlayerData
Definition: SCR_PlayerData.c:2
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
Attribute
typedef Attribute
Post-process effect of scripted camera.
ConsumableTypeStats
Definition: SCR_DataCollectorHealingItemsModule.c:2
GetConsumableType
SCR_EConsumableType GetConsumableType()
Definition: SCR_ConsumableItemComponent.c:216
SCR_EDataStats
SCR_EDataStats
Definition: SCR_PlayerData.c:950
GetDataCollector
SCR_DataCollectorComponent GetDataCollector()
Definition: game.c:90
SCR_DataCollectorModule
Definition: SCR_DataCollectorModule.c:2
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468