DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PlayerAgentPool.c
См. документацию.
1
9{
10 const int STORAGE_VERSION = 137;
11
16
18
20
21 PluginTransmissionAgents m_PluginTransmissionAgents = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
22
24 {
25 m_Player = player;
26 m_LastTicked = 0;
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
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
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
387 {
388 foreach (int agentId, float value : m_AgentTemporaryResistance)
389 SetTemporaryResistance(agentId, 0.0);
390 }
391
393 {
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
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
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
438}
EMedicalDrugsType
Определения EMedicalDrugsType.c:2
EStatLevels
Определения EStatLevels.c:2
const int MAX
Определения EnConvert.c:27
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:325
bool IsPluginManagerExists()
Определения PluginManager.c:315
int GetAgentType()
Определения AgentBase.c:33
string GetName()
Определения AgentBase.c:146
bool AutoinfectCheck(float deltaT, PlayerBase player)
Определения AgentBase.c:103
int GetAutoinfectCount()
Определения AgentBase.c:141
Определения AgentBase.c:2
static ref Param1< int > PARAM1_INT
Определения UtilityClasses.c:11
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Определения 3_Game/DayZ/tools/Debug.c:182
Определения 3_Game/DayZ/tools/Debug.c:2
Определения EnMath.c:7
void OnStoreSave(ParamsWriteContext ctx)
Определения PlayerAgentPool.c:121
void DrugsAttack(EMedicalDrugsType drugType, float attackValue)
Drugs attack calculation.
Определения PlayerAgentPool.c:346
void RemoteGrowRequestDebug(ParamsReadContext ctx)
Определения PlayerAgentPool.c:392
void RemoveAllAgents()
Remove all agents from Agent Pool.
Определения PlayerAgentPool.c:218
float GetTotalAgentCount()
Total number of agents active.
Определения PlayerAgentPool.c:266
void SetTemporaryResistance(int agentId, float time)
Sets temporary resistance time against specified agent contraction.
Определения PlayerAgentPool.c:365
void PlayerAgentPool(PlayerBase player)
Определения PlayerAgentPool.c:23
float m_TotalAgentCount
Определения PlayerAgentPool.c:14
PluginTransmissionAgents m_PluginTransmissionAgents
Определения PlayerAgentPool.c:21
void RemoveAgent(int agent_id)
Remove agent from Agent Pool.
Определения PlayerAgentPool.c:209
ref array< int > m_VirusPoolArray
DEPRECATED.
Определения PlayerAgentPool.c:437
void AddAgent(int agent_id, float count)
Add agent into Agent Pool.
Определения PlayerAgentPool.c:187
ref map< int, float > m_AgentTemporaryResistance
Определения PlayerAgentPool.c:19
float m_LastTicked
Определения PlayerAgentPool.c:13
PlayerBase m_Player
Определения PlayerAgentPool.c:15
ref map< int, float > m_VirusPool
Определения PlayerAgentPool.c:17
int GetAgents()
Reduce bitmask of currently active agents.
Определения PlayerAgentPool.c:244
float GetTemporaryResistance(int agentId)
Returns remaining temporary resistance time for specified agent.
Определения PlayerAgentPool.c:375
void AntibioticsAttackEx(float attack_value, EMedicalDrugsType drugType)
Определения PlayerAgentPool.c:328
int m_AgentMask
Определения PlayerAgentPool.c:12
void ImmuneSystemTick(float value, float deltaT)
Agent pool simulation entry point.
Определения PlayerAgentPool.c:42
void AntibioticsAttack(float attack_value)
Antibiotics treatment agains agents which are not resistent to it (see agent attributes)
Определения PlayerAgentPool.c:323
void ProcessTemporaryResistance(float deltaTime)
Temporary resistance simulation.
Определения PlayerAgentPool.c:105
void ReduceAgent(int id, float percent)
Reduce count of specified agent by a given percentage from Agent Pool.
Определения PlayerAgentPool.c:231
bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения PlayerAgentPool.c:133
void ResetTemporaryResistance()
Resets temporary resistance for all agents (internal usage only)
Определения PlayerAgentPool.c:386
void DigestAgent(int agent_id, float count)
Digest (add) agent from food/drink in PlayerStomach into Agent Pool.
Определения PlayerAgentPool.c:177
const int STORAGE_VERSION
Определения PlayerAgentPool.c:10
int GetStorageVersion()
Определения PlayerAgentPool.c:32
void PrintAgents()
Определения PlayerAgentPool.c:424
void SetAgentCount(int agent_id, float count)
Directly set the count of agents for give id in pool.
Определения PlayerAgentPool.c:297
void GetDebugObject(array< ref Param > object_out)
Определения PlayerAgentPool.c:405
int GetSingleAgentCount(int agent_id)
Number of agents of specified id.
Определения PlayerAgentPool.c:254
void SpawnAgents(float deltaT)
Autoinfection mechanism for agents with that attribute enabled.
Определения PlayerAgentPool.c:279
void GrowAgents(float deltaT)
Agent's growth/death simulation.
Определения PlayerAgentPool.c:55
Определения PlayerBaseClient.c:2
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения CachedEquipmentStorage.c:4
Serializer ParamsReadContext
Определения gameplay.c:15
Serializer ParamsWriteContext
Определения gameplay.c:16
static proto int AbsInt(int i)
Returns absolute value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.