DayZ 1.24
Loading...
Searching...
No Matches
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
11 MODIFIER_SYNC_FEVER = 0x00000040,
12 //0x00000080,
13 //0x00000100,
14 //0x00000200,
15 //0x00000400,
16 //0x00000800,
17 //0x00001000,
19};
20
21
29
34
36{
37 string m_Name;
38 int m_ID;
41
42 void ModifierDebugObj(int id, string name, bool active, bool locked)
43 {
44 m_Name = name;
45 m_ID = id;
48 }
49
50 string GetName()
51 {
52 return m_Name;
53 }
54
55 int GetID()
56 {
57 return m_ID;
58 }
59
60 bool IsActive()
61 {
62 return m_IsActive;
63 }
64
65 bool IsLocked()
66 {
67 return m_IsLocked;
68 }
69}
70
72{
77 bool m_AllowModifierTick = false;
78 const int STORAGE_VERSION = 121;
87
88 void Init()
89 {
90#ifdef DEVELOPER
92#endif
94 //AddModifier(new BoneRegen);
95 //AddModifier(new Health);
99 //AddModifier(new Shock);
105 //AddModifier(new Blinded);
106 //AddModifier(new BrokenArms);
107 AddModifier(new BrokenLegsMdfr); // <-- Broken legs are here
115 //AddModifier(new Tremor);
123 AddModifier(new WetMdfr);
145 }
146
148 {
150 return;
151
153
154#ifdef DIAG_DEVELOPER
155#ifndef SERVER
156 DiagMenu.SetValue(DiagMenuIDs.CHEATS_MODIFIERS, enable);
157#endif
158#endif
159
160 if (!enable)
161 {
162 for (int i = 0; i < m_ModifierList.Count(); i++)
163 m_ModifierList.GetElement(i).ResetLastTickTime();
164 }
165 }
166
168 {
169 return STORAGE_VERSION;
170 }
171
173 {
174 return m_AllowModifierTick;
175 }
176
178 {
179 modifier.InitBase(m_Player, this);
180 int id = modifier.GetModifierID();
181
182 if (id < 1)
183 Error("modifiers ID must be 1 or higher(for debugging reasons)");
184
185 //TODO: add a check for duplicity
186 m_ModifierList.Insert(id, modifier);
188 }
189
191 {
192 return m_ModifierList.Get(modifier_id).IsActive();
193 }
194
196 {
197 if (!m_AllowModifierTick) return;
198
200 m.Tick(delta_time);
201
202 }
203
205 {
206 for (int i = 0; i < m_ModifierList.Count(); i++)
207 m_ModifierList.GetElement(i).Deactivate();
208 }
209
210 void ActivateModifier(int modifier_id, bool triggerEvent = EActivationType.TRIGGER_EVENT_ON_ACTIVATION)
211 {
212 m_ModifierList.Get(modifier_id).ActivateRequest(triggerEvent);
213 }
214
216 {
217 m_ModifierList.Get(modifier_id).Deactivate(triggerEvent);
218 }
219
221 {
223
224 int modifier_count;
225 for (int x = 0; x < m_ModifierList.Count(); x++)
226 {
227 ModifierBase mdfr = m_ModifierList.GetElement(x);
228 if (mdfr.IsActive() && mdfr.IsPersistent())
229 {
231 //save the modifier id
232 CachedObjectsArrays.ARRAY_INT.Insert(mdfr.GetModifierID());
233 if (mdfr.IsTrackAttachedTime())
234 {
235 //save the overall attached time
236 CachedObjectsArrays.ARRAY_INT.Insert(mdfr.GetAttachedTime());
237 }
238 }
239 }
240
241 //write the count
242 //CachedObjectsParams.PARAM1_INT.param1 = modifier_count;
243 //PrintString("Saving modifiers count: "+ modifier_count);
244 ctx.Write(modifier_count);
245
246 //write the individual modifiers and respective attached times
247 for (int i = 0; i < CachedObjectsArrays.ARRAY_INT.Count(); i++)
248 {
250 //PrintString( "saving item: "+item );
251 ctx.Write(item);
252 }
253
254 for (int z = 0; z < m_ParamList.Count(); z++)
255 m_ParamList.Get(z).Serialize(ctx);
256
257 }
258
260 {
261 int modifier_count;
262 if (!ctx.Read(modifier_count))
263 return false;
264 //PrintString("Loading modifiers count: "+ modifier_count);
265 for (int i = 0; i < modifier_count; i++)
266 {
267 int modifier_id;
268 if (!ctx.Read(modifier_id))
269 return false;
270 //PrintString( "loading item: "+modifier_id );
271 //int modifier_id = CachedObjectsParams.PARAM1_INT.param1;
273 if (modifier)
274 {
275 if (modifier.IsTrackAttachedTime())
276 {
277 int time;
278 if (!ctx.Read(time)) //get the attached time
279 return false;
280 modifier.SetAttachedTime(time);
281 }
282
283 ActivateModifier(modifier_id, EActivationType.TRIGGER_EVENT_ON_CONNECT);
284 }
285 else
286 Debug.LogError("DB loading: non-existent modifier with id:" + modifier_id.ToString());
287 }
288
289 for (int x = 0; x < m_ParamList.Count(); x++)
290 {
291 if (!m_ParamList.Get(x).Deserializer(ctx))
292 return false;
293 }
294 return true;
295 }
296
301
303 {
304 return m_Player;
305 }
306
308 {
309 m_ModifierList.Get(modifier_id).SetLock(state);
310 }
311
312
314 {
315 return m_ModifierList.Get(modifier_id).IsLocked();
316 }
317
319 {
320 modifiers.Clear();
321 for (int i = 1; i < eModifiers.COUNT; i++)
322 {
323 if (m_ModifierList.Contains(i))
324 {
326 int modifier_id = modifier.GetModifierID();
327 string modifier_name = modifier.GetName();
328 bool active = modifier.IsActive();
329 string debug_text = modifier.GetDebugTextSimple();
330 bool is_locked = modifier.IsLocked();
331
332 if (active && debug_text != "")
333 modifier_name += " | " + debug_text;
335
336 modifiers.Insert(obj);
337 }
338 }
339 }
340
341 void ResetAll()
342 {
343 bool hasAreaExposureModifier = IsModifierActive(eModifiers.MDF_AREAEXPOSURE);
345
347
349 ActivateModifier(eModifiers.MDF_AREAEXPOSURE);
350
351 if (hasMaksModifier)
353 }
354}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
override Widget Init()
Definition DayZGame.c:120
DiagMenuIDs
Definition EDiagMenuIDs.c:2
DayZPlayer m_Player
Definition Hand_Events.c:42
void SetModifiers()
Icon x
PlayerBase GetPlayer()
void OnStoreSave(ParamsWriteContext ctx)
bool m_AllowModifierTick
int GetStorageVersion()
const int STORAGE_VERSION
void DeactivateModifier(int modifier_id, bool triggerEvent=true)
ModifierBase GetModifier(int modifier_id)
void DeactivateAllModifiers()
bool IsModifiersEnable()
eModifierSyncIDs
@ MODIFIER_SYNC_FEVER
@ MODIFIER_SYNC_CONTAMINATION2
@ MODIFIER_SYNC_WOUND_INFECT_1
@ LAST_INDEX
@ MODIFIER_SYNC_ZONE_EXPOSURE
@ MODIFIER_SYNC_WOUND_INFECT_2
@ MODIFIER_SYNC_DROWNING
@ MODIFIER_SYNC_CONTAMINATION
void ActivateModifier(int modifier_id, bool triggerEvent=EActivationType.TRIGGER_EVENT_ON_ACTIVATION)
EActivationType
@ TRIGGER_EVENT_ON_CONNECT
@ TRIGGER_EVENT_OFF
@ TRIGGER_EVENT_ON_ACTIVATION
void DbgGetModifiers(array< ref ModifierDebugObj > modifiers)
bool GetModifierLock(int modifier_id)
const int DEFAULT_TICK_TIME_INACTIVE
bool OnStoreLoad(ParamsReadContext ctx, int version)
void ModifiersManager(PlayerBase player)
const int DEFAULT_TICK_TIME_ACTIVE_SHORT
void AddModifier(ModifierBase modifier)
void SetModifierLock(int modifier_id, bool state)
ref array< ref Param > m_ParamList
void ResetAll()
ref map< int, ref ModifierBase > m_ModifierList
const int DEFAULT_TICK_TIME_ACTIVE
ref array< ref ModifierBase > m_ModifierListArray
const int DEFAULT_TICK_TIME_INACTIVE_LONG
void OnScheduledTick()
static ref TIntArray ARRAY_INT
Definition Debug.c:14
static void LogError(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as error message.
Definition Debug.c:341
Definition Mask.c:2
void ModifierDebugObj(int id, string name, bool active, bool locked)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
Definition Wet.c:2
eModifiers
Definition eModifiers.c:2
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static proto void SetValue(int id, int value)
Set value at the given script id.
proto native bool IsModifierActive()
is modifier active