DayZ 1.28
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.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
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 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
386 {
387 foreach (int agentId, float value : m_AgentTemporaryResistance)
388 SetTemporaryResistance(agentId, 0.0);
389 }
390
392 {
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
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
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
437}
map
Определения ControlsXboxNew.c:4
EMedicalDrugsType
Определения EMedicalDrugsType.c:2
EStatLevels
Определения EStatLevels.c:2
const int MAX
Определения EnConvert.c:27
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:316
bool IsPluginManagerExists()
Определения PluginManager.c:306
int GetAgentType()
Определения AgentBase.c:24
string GetName()
Определения AgentBase.c:132
bool AutoinfectCheck(float deltaT, PlayerBase player)
Определения AgentBase.c:89
int GetAutoinfectCount()
Определения AgentBase.c:127
Определения 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/tools/Debug.c:122
Определения 3_Game/tools/Debug.c:2
Определения EnMath.c:7
void OnStoreSave(ParamsWriteContext ctx)
Определения PlayerAgentPool.c:121
void DrugsAttack(EMedicalDrugsType drugType, float attackValue)
Drugs treatment logic.
Определения PlayerAgentPool.c:341
void RemoteGrowRequestDebug(ParamsReadContext ctx)
Определения PlayerAgentPool.c:391
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:364
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:436
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:374
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:385
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:423
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:404
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.
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'.