Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
playeragentpool.c
Go to the documentation of this file.
1
9{
10 const int STORAGE_VERSION = 137;
11
12 int m_AgentMask;
13 float m_LastTicked;
14 float m_TotalAgentCount;
15 PlayerBase m_Player;
16
17 ref map<int,float> m_VirusPool;
18
20
21 PluginTransmissionAgents m_PluginTransmissionAgents = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
22
24 {
25 m_Player = player;
26 m_LastTicked = 0;
27 m_VirusPool = new map<int,float>();
28
30 }
31
33 {
34 return STORAGE_VERSION;
35 }
36
42 void ImmuneSystemTick(float value, float deltaT)//this is a regular tick induced in the the player's immune system
43 {
45 SpawnAgents(deltaT);
46 GrowAgents(deltaT);
47 }
48
55 void GrowAgents(float deltaT)
56 {
58 return;
59
60 EStatLevels immunityLevel = m_Player.GetImmunityLevel();
61
62 m_TotalAgentCount = 0;
63 for (int i = 0; i < m_VirusPool.Count(); i++)
64 {
65 int agentId = m_VirusPool.GetKey(i);
66 int maxCount = m_PluginTransmissionAgents.GetAgentMaxCount(agentId);
67
68 EStatLevels agentPotency = m_PluginTransmissionAgents.GetAgentPotencyEx(agentId, m_Player);
69
70 float growDelta;
71
72 if (agentPotency <= immunityLevel)
73 {
74 float temporaryResistance = GetTemporaryResistance(agentId);
75 if (temporaryResistance > 1.0)
76 continue;
77
78 if (m_Player.IsAntibioticsActive() && !m_PluginTransmissionAgents.GrowDuringMedicalDrugsAttack(agentId, EMedicalDrugsType.CHELATION, m_Player))
79 continue;
80
81 if (m_Player.IsChelationActive() && !m_PluginTransmissionAgents.GrowDuringMedicalDrugsAttack(agentId, EMedicalDrugsType.CHELATION, m_Player))
82 continue
83
84 float invasibility = m_PluginTransmissionAgents.GetAgentInvasibilityEx(agentId, m_Player);
85 growDelta = invasibility * deltaT;
86 }
87 else
88 {
89 float dieOffSpeed = m_PluginTransmissionAgents.GetAgentDieOffSpeedEx(agentId, m_Player);
90 growDelta = -dieOffSpeed * deltaT;
91 }
92
93 float oldCount = m_VirusPool.Get(agentId);
94 float newCount = oldCount + growDelta;
95 newCount = Math.Clamp(newCount, 0, maxCount);
96
97 m_TotalAgentCount += newCount;
98 SetAgentCount(agentId, newCount);
99 }
100 }
101
105 protected void ProcessTemporaryResistance(float deltaTime)
106 {
107 foreach (int agentId, float timeResistance : m_AgentTemporaryResistance)
108 {
109 float temporaryResistance = GetTemporaryResistance(agentId);
110
111 if (temporaryResistance > 1.0)
112 {
113 float newResistanceValue = temporaryResistance - deltaTime;
114 SetTemporaryResistance(agentId, newResistanceValue);
115 }
116 else
117 SetTemporaryResistance(agentId, 0.0);
118 }
119 }
120
122 {
123 int count = m_PluginTransmissionAgents.GetAgentList().Count();
124 array<int> agentList = m_PluginTransmissionAgents.GetAgentList().GetKeyArray();
125 foreach (int agentId : agentList)
126 {
127 ctx.Write(agentId);
128 ctx.Write(GetSingleAgentCount(agentId));
129 ctx.Write(GetTemporaryResistance(agentId));
130 }
131 }
132
133 bool OnStoreLoad(ParamsReadContext ctx, int version)
134 {
135 int count;
136 if (version >= 137)
137 {
138 count = m_PluginTransmissionAgents.GetAgentList().Count();
139 }
140 else
141 {
142 if (!ctx.Read(count))
143 return false;
144 }
145
146
147 for (int i = 0; i < count; ++i)
148 {
149 int agentId;
150 if (!ctx.Read(agentId))
151 return false;
152
153 int agentCount;
154 if (!ctx.Read(agentCount))
155 return false;
156
157 if (version >= 137)
158 {
159 float agentTemporaryResistanceTime;
160 if (!ctx.Read(agentTemporaryResistanceTime))
161 return false;
162
163 SetTemporaryResistance(agentId, agentTemporaryResistanceTime);
164 }
165
166 SetAgentCount(agentId, agentCount);
167 }
168
169 return true;
170 }
171
177 void DigestAgent(int agent_id, float count)
178 {
179 AddAgent(agent_id, m_PluginTransmissionAgents.GetAgentDigestibilityEx(agent_id, m_Player) * count);
180 }
181
187 void AddAgent(int agent_id, float count)
188 {
189 if (GetTemporaryResistance(agent_id) > 0)
190 return;
191
192 int max_count = m_PluginTransmissionAgents.GetAgentMaxCount(agent_id);
193
194 if (!m_VirusPool.Contains(agent_id) && count > 0)//if it contains, maybe add count only ?
195 {
196 SetAgentCount(agent_id,count);
197 }
198 else
199 {
200 float newValue = m_VirusPool.Get(agent_id) + count;
201 SetAgentCount(agent_id, newValue);
202 }
203 }
204
209 void RemoveAgent(int agent_id)
210 {
211 SetAgentCount(agent_id, 0);
212 }
213
219 {
220 m_AgentMask = 0;
221 m_VirusPool.Clear();
222
223 ResetTemporaryResistance();
224 }
225
231 void ReduceAgent(int id, float percent)
232 {
233 percent = Math.Clamp(percent, 0, 100);
234 float reduction = percent * 0.01;
235
236 int agentCount = GetSingleAgentCount(id);
237 agentCount -= agentCount * reduction;
238
239 SetAgentCount(id, agentCount);
240 }
245 {
246 return m_AgentMask;
247 }
248
254 int GetSingleAgentCount(int agent_id)
255 {
256 if (m_VirusPool.Contains(agent_id))
257 return m_VirusPool.Get(agent_id);
258
259 return 0;
260 }
261
267 {
268 float agentCount;
269 for (int i = 0; i < m_VirusPool.Count(); i++)
270 agentCount += m_VirusPool.GetElement(i);
271
272 return agentCount;
273 }
274
279 void SpawnAgents(float deltaT)
280 {
281 int count = m_PluginTransmissionAgents.GetAgentList().Count();
282 for (int i = 0; i < count; ++i)
283 {
284 AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
285 int agentId = agent.GetAgentType();
286
287 if (GetSingleAgentCount(agentId) == 0 && agent.AutoinfectCheck(deltaT, m_Player))
288 AddAgent(agentId, agent.GetAutoinfectCount());
289 }
290 }
291
297 void SetAgentCount(int agent_id, float count)
298 {
299 if (count > 0)
300 {
301 //Debug.Log("+ growing agent"+ agent_id.ToString() +"to count: "+count.ToString(), "Agents");
302 m_VirusPool.Set(agent_id, count);
303 m_AgentMask = m_AgentMask | agent_id;
304 }
305 else
306 {
307 //Debug.Log("- REMOVING agent"+ agent_id.ToString(), "Agents");
308 m_VirusPool.Remove(agent_id);
309 m_AgentMask = m_AgentMask & ~agent_id;
310 }
311
312 if (m_Player.m_Agents != m_AgentMask)
313 {
314 m_Player.m_Agents = m_AgentMask;
315 m_Player.SetSynchDirty();
316 }
317 }
318
323 void AntibioticsAttack(float attack_value)
324 {
325 for (int i = 0; i < m_VirusPool.Count(); ++i)
326 {
327 int agentId = m_VirusPool.GetKey(i);
328 float resistance = 1 - m_PluginTransmissionAgents.GetAgentAntiboticsResistanceEx(agentId, m_Player);
329 float delta = attack_value * resistance;
330 float actualAgentCount = m_VirusPool.Get(agentId);
331 float newAgentCount = actualAgentCount - delta;
332 SetAgentCount(agentId, newAgentCount);
333 }
334 }
335
341 void DrugsAttack(EMedicalDrugsType drugType, float attackValue)
342 {
343 switch (drugType)
344 {
345 case EMedicalDrugsType.ANTIBIOTICS:
346 AntibioticsAttack(attackValue);
347 break;
348 default:
349 for (int i = 0; i < m_VirusPool.Count(); ++i)
350 {
351 int agentId = m_VirusPool.GetKey(i);
352 float actualAgentCount = m_VirusPool.Get(agentId);
353 float newAgentCount = actualAgentCount - attackValue;
354 SetAgentCount(agentId, newAgentCount);
355 }
356 }
357 }
358
364 void SetTemporaryResistance(int agentId, float time)
365 {
366 m_AgentTemporaryResistance[agentId] = Math.Clamp(time, 0.0, int.MAX);
367 }
368
374 float GetTemporaryResistance(int agentId)
375 {
376 if (m_AgentTemporaryResistance.Contains(agentId))
377 return m_AgentTemporaryResistance[agentId];
378
379 return 0.0;
380 }
381
385 private void ResetTemporaryResistance()
386 {
387 foreach (int agentId, float value : m_AgentTemporaryResistance)
388 SetTemporaryResistance(agentId, 0.0);
389 }
390
391 void RemoteGrowRequestDebug(ParamsReadContext ctx)
392 {
393 ctx.Read(CachedObjectsParams.PARAM1_INT);
394 int id = CachedObjectsParams.PARAM1_INT.param1;
395 int max = m_PluginTransmissionAgents.GetAgentMaxCount(Math.AbsInt(id));
396 int grow = max / 10;
397
398 if (id > 0)
399 AddAgent(id, grow);
400 else if (id < 0)
401 AddAgent(-id, -grow);
402 }
403
404 void GetDebugObject(array<ref Param> object_out)
405 {
406 int count = m_PluginTransmissionAgents.GetAgentList().Count();
407 for (int i = 0; i < count; i++)
408 {
409 AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
410 string agentName = agent.GetName();
411 int agentId = agent.GetAgentType();
412 int maxAgents = m_PluginTransmissionAgents.GetAgentMaxCount(agentId);
413 string amount = GetSingleAgentCount(agentId).ToString() + "/" + maxAgents.ToString();
414
415 float tempResistance = GetTemporaryResistance(agentId);
416
417 object_out.Insert(new Param4<string,string, int, float>(agentName, amount, agentId, tempResistance));
418 }
419
420 object_out.InsertAt(new Param1<int>(count) ,0);
421 }
422
423 void PrintAgents()
424 {
425 if (m_VirusPool)
426 {
427 for (int i = 0; i < m_VirusPool.Count(); ++i)
428 {
429 Debug.Log("Agent: "+ m_VirusPool.GetKey(i).ToString(), "Agents");
430 Debug.Log("Count: "+ m_VirusPool.GetElement(i).ToString(), "Agents");
431 }
432 }
433 }
434
436 ref array<int> m_VirusPoolArray = new array<int>();
437}
Definition debug.c:2
Definition enmath.c:7
Keeps track of agents and their simulation.
void OnStoreSave(ParamsWriteContext ctx)
void DrugsAttack(EMedicalDrugsType drugType, float attackValue)
Drugs treatment logic.
void RemoveAllAgents()
Remove all agents from Agent Pool.
float GetTotalAgentCount()
Total number of agents active.
void SetTemporaryResistance(int agentId, float time)
Sets temporary resistance time against specified agent contraction.
void PlayerAgentPool(PlayerBase player)
PluginTransmissionAgents m_PluginTransmissionAgents
void RemoveAgent(int agent_id)
Remove agent from Agent Pool.
void AddAgent(int agent_id, float count)
Add agent into Agent Pool.
ref map< int, float > m_AgentTemporaryResistance
int GetAgents()
Reduce bitmask of currently active agents.
float GetTemporaryResistance(int agentId)
Returns remaining temporary resistance time for specified agent.
void ImmuneSystemTick(float value, float deltaT)
Agent pool simulation entry point.
void AntibioticsAttack(float attack_value)
Antibiotics treatment agains agents which are not resistent to it (see agent attributes)
void ProcessTemporaryResistance(float deltaTime)
Temporary resistance simulation.
void ReduceAgent(int id, float percent)
Reduce count of specified agent by a given percentage from Agent Pool.
bool OnStoreLoad(ParamsReadContext ctx, int version)
void DigestAgent(int agent_id, float count)
Digest (add) agent from food/drink in PlayerStomach into Agent Pool.
void SetAgentCount(int agent_id, float count)
Directly set the count of agents for give id in pool.
int GetSingleAgentCount(int agent_id)
Number of agents of specified id.
void SpawnAgents(float deltaT)
Autoinfection mechanism for agents with that attribute enabled.
void GrowAgents(float deltaT)
Agent's growth/death simulation.
Serialization general interface. Serializer API works with:
Definition serializer.c:56
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
EMedicalDrugsType
const int MAX
Definition enconvert.c:27
EStatLevels
Definition estatlevels.c:2
DayZPlayer m_Player
Definition hand_events.c:42
class ModifierDebugObj STORAGE_VERSION
PluginBase GetPlugin(typename plugin_type)
bool IsPluginManagerExists()