Dayz Explorer 1.29.162510
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.ANTIBIOTICS, 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 }
241
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 AntibioticsAttackEx(attack_value, EMedicalDrugsType.ANTIBIOTICS);
326 }
327
328 void AntibioticsAttackEx(float attack_value, EMedicalDrugsType drugType)
329 {
330 for (int i = 0; i < m_VirusPool.Count(); ++i)
331 {
332 int agentId = m_VirusPool.GetKey(i);
333 float resistance = 1 - m_PluginTransmissionAgents.GetAgentSpecificDrugResistance(agentId, drugType, m_Player);
334 float delta = attack_value * resistance;
335 float actualAgentCount = m_VirusPool.Get(agentId);
336 float newAgentCount = actualAgentCount - delta;
337 SetAgentCount(agentId, newAgentCount);
338 }
339 }
340
346 void DrugsAttack(EMedicalDrugsType drugType, float attackValue)
347 {
348 for (int i = 0; i < m_VirusPool.Count(); ++i)
349 {
350 //getting the immunity of the agent and exiting the function early if that agent is immune to the drug
351 int agentId = m_VirusPool.GetKey(i);
352 float resistance = 1 - m_PluginTransmissionAgents.GetAgentSpecificDrugResistance(agentId, drugType, m_Player);
353 float delta = attackValue * resistance;
354 float actualAgentCount = m_VirusPool.Get(agentId);
355 float newAgentCount = actualAgentCount - delta;
356 SetAgentCount(agentId, newAgentCount);
357 }
358 }
359
365 void SetTemporaryResistance(int agentId, float time)
366 {
367 m_AgentTemporaryResistance[agentId] = Math.Clamp(time, 0.0, int.MAX);
368 }
369
375 float GetTemporaryResistance(int agentId)
376 {
377 if (m_AgentTemporaryResistance.Contains(agentId))
378 return m_AgentTemporaryResistance[agentId];
379
380 return 0.0;
381 }
382
386 private void ResetTemporaryResistance()
387 {
388 foreach (int agentId, float value : m_AgentTemporaryResistance)
389 SetTemporaryResistance(agentId, 0.0);
390 }
391
392 void RemoteGrowRequestDebug(ParamsReadContext ctx)
393 {
394 ctx.Read(CachedObjectsParams.PARAM1_INT);
395 int id = CachedObjectsParams.PARAM1_INT.param1;
396 int max = m_PluginTransmissionAgents.GetAgentMaxCount(Math.AbsInt(id));
397 int grow = max / 10;
398
399 if (id > 0)
400 AddAgent(id, grow);
401 else if (id < 0)
402 AddAgent(-id, -grow);
403 }
404
405 void GetDebugObject(array<ref Param> object_out)
406 {
407 int count = m_PluginTransmissionAgents.GetAgentList().Count();
408 for (int i = 0; i < count; i++)
409 {
410 AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
411 string agentName = agent.GetName();
412 int agentId = agent.GetAgentType();
413 int maxAgents = m_PluginTransmissionAgents.GetAgentMaxCount(agentId);
414 string amount = GetSingleAgentCount(agentId).ToString() + "/" + maxAgents.ToString();
415
416 float tempResistance = GetTemporaryResistance(agentId);
417
418 object_out.Insert(new Param4<string,string, int, float>(agentName, amount, agentId, tempResistance));
419 }
420
421 object_out.InsertAt(new Param1<int>(count) ,0);
422 }
423
424 void PrintAgents()
425 {
426 if (m_VirusPool)
427 {
428 for (int i = 0; i < m_VirusPool.Count(); ++i)
429 {
430 Debug.Log("Agent: "+ m_VirusPool.GetKey(i).ToString(), "Agents");
431 Debug.Log("Count: "+ m_VirusPool.GetElement(i).ToString(), "Agents");
432 }
433 }
434 }
435
437 ref array<int> m_VirusPoolArray = new array<int>();
438}
string Debug()
int GetAgentType()
Definition agentbase.c:33
string GetName()
Definition agentbase.c:146
bool AutoinfectCheck(float deltaT, PlayerBase player)
Definition agentbase.c:103
int GetAutoinfectCount()
Definition agentbase.c:141
Definition enmath.c:7
void OnStoreSave(ParamsWriteContext ctx)
void DrugsAttack(EMedicalDrugsType drugType, float attackValue)
Drugs attack calculation.
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 AntibioticsAttackEx(float attack_value, EMedicalDrugsType drugType)
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.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
EMedicalDrugsType
const int MAX
Definition enconvert.c:27
EStatLevels
Definition estatlevels.c:2
Serializer ParamsReadContext
Definition gameplay.c:15
Serializer ParamsWriteContext
Definition gameplay.c:16
PluginBase GetPlugin(typename plugin_type)
bool IsPluginManagerExists()