Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
modifiersmanager.c
Go to the documentation of this file.
1 //max 32 synced modifiers supported
3 {
4 
7  MODIFIER_SYNC_CONTAMINATION = 0x00000004,//stage1
8  MODIFIER_SYNC_CONTAMINATION2 = 0x00000008,//stage2 and stage3 share the same sync id
10  MODIFIER_SYNC_DROWNING = 0x00000020,
11  MODIFIER_SYNC_FEVER = 0x00000040,
12  //0x00000080,
13  //0x00000100,
14  //0x00000200,
15  //0x00000400,
16  //0x00000800,
17  //0x00001000,
19 };
20 
21 
22 
23 
25 
29 };
30 
35 
37 {
38  string m_Name;
39  int m_ID;
40  bool m_IsActive;
41  bool m_IsLocked;
42 
43  void ModifierDebugObj(int id, string name, bool active, bool locked)
44  {
45  m_Name = name;
46  m_ID = id;
47  m_IsActive = active;
48  m_IsLocked = locked;
49  }
50 
51  string GetName()
52  {
53  return m_Name;
54  }
55 
56  int GetID()
57  {
58  return m_ID;
59  }
60 
61  bool IsActive()
62  {
63  return m_IsActive;
64  }
65 
66  bool IsLocked()
67  {
68  return m_IsLocked;
69  }
70 }
71 
72 class ModifiersManager
73 {
78  bool m_AllowModifierTick = false;
79  const int STORAGE_VERSION = 121;
81  {
84  m_Player = player;
85 
86  Init();
87  }
88 
89  void Init()
90  {
91  #ifdef DEVELOPER
93  #endif
95  //AddModifier(new BoneRegen);
96  //AddModifier(new Health);
100  //AddModifier(new Shock);
104  AddModifier(new ThirstMdfr);
106  //AddModifier(new Blinded);
107  //AddModifier(new BrokenArms);
108  AddModifier(new BrokenLegsMdfr); // <-- Broken legs are here
111  AddModifier(new FeverMdfr);
116  //AddModifier(new Tremor);
124  AddModifier(new WetMdfr);
128  AddModifier(new BreathVapourMdfr);
129  AddModifier(new ShockMdfr);
143  AddModifier(new MaskMdfr);
144  AddModifier(new FliesMdfr);
146  }
147 
148  void SetModifiers(bool enable)
149  {
150  if (m_AllowModifierTick == enable)
151  return;
152 
153  m_AllowModifierTick = enable;
154 
155  #ifdef DIAG_DEVELOPER
156  #ifndef SERVER
157  DiagMenu.SetValue(DiagMenuIDs.CHEATS_MODIFIERS, enable);
158  #endif
159  #endif
160 
161  if ( !enable )
162  {
163  for (int i = 0; i < m_ModifierList.Count(); i++)
164  {
165  m_ModifierList.GetElement(i).ResetLastTickTime();
166  }
167  }
168  }
169 
171  {
172  return STORAGE_VERSION;
173  }
174 
176  {
177  return m_AllowModifierTick;
178  }
179 
180  void AddModifier(ModifierBase modifier)
181  {
182  modifier.InitBase(m_Player,this);
183  int id = modifier.GetModifierID();
184 
185  if (id < 1)
186  {
187  Error("modifiers ID must be 1 or higher(for debugging reasons)");
188  }
189 
190  //TODO: add a check for duplicity
191  m_ModifierList.Insert(id, modifier);
192  m_ModifierListArray.Insert(modifier);
193  }
194 
195  bool IsModifierActive(eModifiers modifier_id)
196  {
197  return m_ModifierList.Get(modifier_id).IsActive();
198  }
199 
200  void OnScheduledTick(float delta_time)
201  {
202  if(!m_AllowModifierTick) return;
203 
205  {
206  m.Tick(delta_time);
207  }
208 
209  }
210 
212  {
213  for(int i = 0; i < m_ModifierList.Count(); i++)
214  {
215  m_ModifierList.GetElement(i).Deactivate();
216  }
217  }
218 
219  void ActivateModifier(int modifier_id, bool triggerEvent = EActivationType.TRIGGER_EVENT_ON_ACTIVATION)
220  {
221  m_ModifierList.Get(modifier_id).ActivateRequest(triggerEvent);
222  }
223 
224  void DeactivateModifier(int modifier_id, bool triggerEvent = true)
225  {
226  m_ModifierList.Get(modifier_id).Deactivate(triggerEvent);
227  }
228 
230  {
231  CachedObjectsArrays.ARRAY_INT.Clear();
232 
233  int modifier_count;
234  for(int x = 0; x < m_ModifierList.Count(); x++)
235  {
236  ModifierBase mdfr = m_ModifierList.GetElement(x);
237  if( mdfr.IsActive() && mdfr.IsPersistent() )
238  {
239  modifier_count++;
240  //save the modifier id
241  CachedObjectsArrays.ARRAY_INT.Insert( mdfr.GetModifierID() );
242  if( mdfr.IsTrackAttachedTime() )
243  {
244  //save the overall attached time
245  CachedObjectsArrays.ARRAY_INT.Insert( mdfr.GetAttachedTime() );
246  }
247  }
248  }
249 
250  //write the count
251  //CachedObjectsParams.PARAM1_INT.param1 = modifier_count;
252  //PrintString("Saving modifiers count: "+ modifier_count);
253  ctx.Write(modifier_count);
254 
255  //write the individual modifiers and respective attached times
256  for(int i = 0; i < CachedObjectsArrays.ARRAY_INT.Count(); i++)
257  {
258  int item = CachedObjectsArrays.ARRAY_INT.Get(i);
259  //PrintString( "saving item: "+item );
260  ctx.Write(item);
261  }
262 
263  for (int z = 0; z < m_ParamList.Count(); z++)
264  {
265  m_ParamList.Get(z).Serialize(ctx);
266  }
267 
268  }
269 
270  bool OnStoreLoad( ParamsReadContext ctx, int version )
271  {
272  int modifier_count;
273  if(!ctx.Read(modifier_count))
274  return false;
275  //PrintString("Loading modifiers count: "+ modifier_count);
276  for(int i = 0; i < modifier_count; i++)
277  {
278  int modifier_id;
279  if(!ctx.Read(modifier_id))
280  return false;
281  //PrintString( "loading item: "+modifier_id );
282  //int modifier_id = CachedObjectsParams.PARAM1_INT.param1;
283  ModifierBase modifier = GetModifier(modifier_id);
284  if( modifier )
285  {
286  if( modifier.IsTrackAttachedTime() )
287  {
288  int time;
289  if(!ctx.Read(time))//get the attached time
290  return false;
291  modifier.SetAttachedTime( time );
292  }
293 
294  ActivateModifier(modifier_id, EActivationType.TRIGGER_EVENT_ON_CONNECT);
295  }
296  else
297  {
298  Debug.LogError("DB loading: non-existent modifier with id:"+modifier_id.ToString());
299  }
300  }
301 
302  for (int x = 0; x < m_ParamList.Count(); x++)
303  {
304  if(!m_ParamList.Get(x).Deserializer(ctx))
305  {
306  return false;
307  }
308  }
309  return true;
310  }
311 
312  ModifierBase GetModifier(int modifier_id)
313  {
314  return m_ModifierList.Get(modifier_id);
315  }
316 
318  {
319  return m_Player;
320  }
321 
322  void SetModifierLock(int modifier_id, bool state)
323  {
324  m_ModifierList.Get(modifier_id).SetLock(state);
325  }
326 
327 
328  bool GetModifierLock(int modifier_id)
329  {
330  return m_ModifierList.Get(modifier_id).IsLocked();
331  }
332 
334  {
335  modifiers.Clear();
336  for(int i = 1;i < eModifiers.COUNT; i++)
337  {
338  if(m_ModifierList.Contains(i))
339  {
340  ModifierBase modifier = m_ModifierList.Get(i);
341  int modifier_id = modifier.GetModifierID();
342  string modifier_name = modifier.GetName();
343  bool active = modifier.IsActive();
344  string debug_text = modifier.GetDebugTextSimple();
345  bool is_locked = modifier.IsLocked();
346 
347  if(active && debug_text != "")
348  {
349  modifier_name +=" | "+debug_text;
350  }
351  ModifierDebugObj obj = new ModifierDebugObj(modifier_id, modifier_name, active, is_locked);
352 
353  modifiers.Insert( obj );
354  }
355  }
356  }
357 
358  void ResetAll()
359  {
360  bool hasAreaExposureModifier = IsModifierActive(eModifiers.MDF_AREAEXPOSURE);
361  bool hasMaksModifier = IsModifierActive(eModifiers.MDF_MASK);
362 
364 
365  if (hasAreaExposureModifier)
366  ActivateModifier(eModifiers.MDF_AREAEXPOSURE);
367 
368  if (hasMaksModifier)
369  ActivateModifier(eModifiers.MDF_MASK);
370  }
371 }
HemolyticReactionMdfr
Definition: hemolyticreaction.c:1
ImmunityBoost
Definition: immunityboost.c:1
MODIFIER_SYNC_CONTAMINATION2
@ MODIFIER_SYNC_CONTAMINATION2
Definition: modifiersmanager.c:8
BrokenLegsMdfr
Definition: brokenlegs.c:1
ContaminationStage3Mdfr
Definition: contamination3.c:1
BleedingCheckMdfr
Definition: bleeding.c:2
TRIGGER_EVENT_ON_ACTIVATION
@ TRIGGER_EVENT_ON_ACTIVATION
Definition: modifiersmanager.c:27
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
ToxicityMdfr
Definition: toxicity.c:1
IsModifiersEnable
bool IsModifiersEnable()
Definition: modifiersmanager.c:175
ContaminationStage1Mdfr
Definition: contamination.c:1
MaskMdfr
Definition: mask.c:1
DiagMenu
Definition: endebug.c:232
GetPlayer
PlayerBase GetPlayer()
Definition: modifiersmanager.c:317
TRIGGER_EVENT_ON_CONNECT
@ TRIGGER_EVENT_ON_CONNECT
Definition: modifiersmanager.c:28
MODIFIER_SYNC_ZONE_EXPOSURE
@ MODIFIER_SYNC_ZONE_EXPOSURE
Definition: modifiersmanager.c:9
UnconsciousnessMdfr
Definition: unconsciousness.c:1
m_Name
string m_Name
Definition: bioslobbyservice.c:35
m_Player
class ModifierDebugObj m_Player
InfluenzaMdfr
Definition: influenza.c:1
SetModifierLock
void SetModifierLock(int modifier_id, bool state)
Definition: modifiersmanager.c:322
ShockDamageMdfr
Definition: shockdamage.c:1
MODIFIER_SYNC_WOUND_INFECT_1
@ MODIFIER_SYNC_WOUND_INFECT_1
Definition: modifiersmanager.c:5
EpinephrineMdfr
Definition: epinephrinemdfr.c:1
MODIFIER_SYNC_WOUND_INFECT_2
@ MODIFIER_SYNC_WOUND_INFECT_2
Definition: modifiersmanager.c:6
AddModifier
void AddModifier(ModifierBase modifier)
Definition: modifiersmanager.c:180
m_ParamList
ref array< ref Param > m_ParamList
Definition: modifiersmanager.c:77
m_IsLocked
bool m_IsLocked
Definition: modifierbase.c:27
HeatBufferMdfr
Definition: heatbuffer.c:1
ResetAll
void ResetAll()
Definition: modifiersmanager.c:358
StomachMdfr
Definition: stomach.c:1
DeactivateModifier
void DeactivateModifier(int modifier_id, bool triggerEvent=true)
Definition: modifiersmanager.c:224
OnScheduledTick
void OnScheduledTick(float delta_time)
Definition: modifiersmanager.c:200
FeverMdfr
Definition: fever.c:1
EActivationType
EActivationType
Definition: modifiersmanager.c:24
LAST_INDEX
@ LAST_INDEX
Definition: modifiersmanager.c:18
VomitStuffedMdfr
Definition: vomitstuffed.c:1
m_ModifierListArray
ref array< ref ModifierBase > m_ModifierListArray
Definition: modifiersmanager.c:76
OnStoreSave
void OnStoreSave(ParamsWriteContext ctx)
Definition: modifiersmanager.c:229
m_ModifierList
ref map< int, ref ModifierBase > m_ModifierList
Definition: modifiersmanager.c:75
WoundInfectStage1Mdfr
Definition: woundinfection.c:14
IsModifierActive
bool IsModifierActive(eModifiers modifier_id)
Definition: modifiersmanager.c:195
StuffedStomachMdfr
Definition: stuffedstomach.c:1
DEFAULT_TICK_TIME_INACTIVE_LONG
const int DEFAULT_TICK_TIME_INACTIVE_LONG
Definition: modifiersmanager.c:34
DrowningMdfr
Definition: drowning.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
ThirstMdfr
Definition: thirst.c:1
BloodRegenMdfr
Definition: bloodregen.c:1
MODIFIER_SYNC_FEVER
@ MODIFIER_SYNC_FEVER
Definition: modifiersmanager.c:11
FliesMdfr
Definition: flies.c:1
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
DEFAULT_TICK_TIME_ACTIVE
const int DEFAULT_TICK_TIME_ACTIVE
Definition: modifiersmanager.c:31
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
ShockMdfr
Definition: shock.c:1
HeartAttackMdfr
Definition: heartattack.c:1
ModifiersManager
void ModifiersManager(PlayerBase player)
Definition: modifiersmanager.c:80
m_IsActive
bool m_IsActive
Definition: modifierbase.c:20
HealthRegenMdfr
Definition: healthregen.c:1
PoisoningMdfr
Definition: poisoning.c:1
AreaExposureMdfr
Definition: areaexposure.c:1
DEFAULT_TICK_TIME_ACTIVE_SHORT
const int DEFAULT_TICK_TIME_ACTIVE_SHORT
Definition: modifiersmanager.c:32
TRIGGER_EVENT_OFF
@ TRIGGER_EVENT_OFF
Definition: modifiersmanager.c:26
BurningMdfr
Definition: burning.c:1
DisinfectionMdfr
Definition: disinfectmdfr.c:1
eModifiers
eModifiers
Definition: emodifiers.c:1
MorphineMdfr
Definition: morphinemdfr.c:1
MODIFIER_SYNC_CONTAMINATION
@ MODIFIER_SYNC_CONTAMINATION
Definition: modifiersmanager.c:7
ModifierBase
Definition: breathvapourmdfr.c:3
BrainDiseaseMdfr
Definition: braindisease.c:1
Init
void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: modifiersmanager.c:89
TestDiseaseMdfr
Definition: testdisease.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
eModifierSyncIDs
eModifierSyncIDs
Definition: modifiersmanager.c:2
ModifierDebugObj
Definition: modifiersmanager.c:36
PainKillersMdfr
Definition: painkillersmdfr.c:1
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
m_AllowModifierTick
bool m_AllowModifierTick
Definition: modifiersmanager.c:78
GetModifierLock
bool GetModifierLock(int modifier_id)
Definition: modifiersmanager.c:328
HeatComfortMdfr
Definition: heatcomfortmdfr.c:1
ImmuneSystemMdfr
Definition: immunesystem.c:1
Debug
Definition: debug.c:13
ContaminationStage2Mdfr
Definition: contamination2.c:1
CommonColdMdfr
Definition: commoncold.c:1
GetStorageVersion
int GetStorageVersion()
Definition: modifiersmanager.c:170
WoundInfectStage2Mdfr
Definition: woundinfection2.c:1
FatigueMdfr
Definition: fatigue.c:1
SalineMdfr
Definition: saline.c:1
DeactivateAllModifiers
void DeactivateAllModifiers()
Definition: modifiersmanager.c:211
MODIFIER_SYNC_DROWNING
@ MODIFIER_SYNC_DROWNING
Definition: modifiersmanager.c:10
SalmonellaMdfr
Definition: salmonella.c:1
ActivateModifier
void ActivateModifier(int modifier_id, bool triggerEvent=EActivationType.TRIGGER_EVENT_ON_ACTIVATION)
Definition: modifiersmanager.c:219
CharcoalMdfr
Definition: charcoalmdfr.c:1
HungerMdfr
Definition: hunger.c:1
SetModifiers
void SetModifiers(bool enable)
Definition: modifiersmanager.c:148
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49
OnStoreLoad
bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: modifiersmanager.c:270
WetMdfr
Definition: wet.c:1
AntibioticsMdfr
Definition: antibiotics.c:1
CholeraMdfr
Definition: cholera.c:1
GetModifier
ModifierBase GetModifier(int modifier_id)
Definition: modifiersmanager.c:312
STORAGE_VERSION
const int STORAGE_VERSION
Definition: modifiersmanager.c:79
CachedObjectsArrays
Definition: utilityclasses.c:40
DEFAULT_TICK_TIME_INACTIVE
const int DEFAULT_TICK_TIME_INACTIVE
Definition: modifiersmanager.c:33
DbgGetModifiers
void DbgGetModifiers(array< ref ModifierDebugObj > modifiers)
Definition: modifiersmanager.c:333