Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
playeragentpool.c
Go to the documentation of this file.
2 {
3  ref map<int,float> m_VirusPool = new map<int,float>;
4  ref array<int> m_VirusPoolArray = new array<int>;
5  float m_LastTicked = 0;
6  float m_TotalAgentCount;
7  PlayerBase m_Player;
8  int m_AgentMask;
9 
10  const int STORAGE_VERSION = 100;
11 
12  PluginTransmissionAgents m_PluginTransmissionAgents = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
13 
14  void PlayerAgentPool(PlayerBase player)
15  {
16  m_Player = player;
17  }
18 
19  void ~PlayerAgentPool()
20  {
21 
22  }
23 
24  int GetStorageVersion()
25  {
26  return STORAGE_VERSION;
27  }
28 
29  void PrintAgents()
30  {
31  if( m_VirusPool )
32  {
33  for(int i = 0; i < m_VirusPool.Count(); i++)
34  {
35  Debug.Log("Agent: "+ m_VirusPool.GetKey(i).ToString(), "Agents");
36  Debug.Log("Count: "+ m_VirusPool.GetElement(i).ToString(), "Agents");
37  }
38 
39  }
40  }
41 
42  void ImmuneSystemTick(float value, float deltaT)//this is a regular tick induced in the the player's immune system
43  {
44  SpawnAgents(deltaT);
45  GrowAgents(deltaT);
46  }
47 
48  void GrowAgents(float deltaT)
49  {
50  if ( !IsPluginManagerExists() )//check if modules are running
51  return;
52 
53  EStatLevels immunity_level = m_Player.GetImmunityLevel();
54 
55  m_TotalAgentCount = 0;
56  for(int i = 0; i < m_VirusPool.Count(); i++)
57  {
58  int agent_id = m_VirusPool.GetKey(i);
59  int max_count = m_PluginTransmissionAgents.GetAgentMaxCount( agent_id );
60 
61  EStatLevels agent_potency = m_PluginTransmissionAgents.GetAgentPotencyEx( agent_id, m_Player );
62 
63  float grow_delta;
64 
65  if( agent_potency <= immunity_level )
66  {
67  bool grow_during_antibiotics = m_PluginTransmissionAgents.GrowDuringAntibioticsAttack(agent_id, m_Player);
68  if (m_Player.IsAntibioticsActive() && !grow_during_antibiotics)
69  continue;
70  float invasibility = m_PluginTransmissionAgents.GetAgentInvasibilityEx( agent_id, m_Player );
71  grow_delta = invasibility * deltaT;
72  }
73  else
74  {
75  float dieoff_speed = m_PluginTransmissionAgents.GetAgentDieOffSpeedEx( agent_id, m_Player );
76  grow_delta = -dieoff_speed * deltaT;
77  }
78 
79  //Print( agent_id );
80  //Print( grow_delta );
81 
82  float old_count = m_VirusPool.Get( agent_id );
83  float new_count = old_count + grow_delta;
84  new_count = Math.Clamp(new_count, 0,max_count);
85 
86  m_TotalAgentCount += new_count;
87  SetAgentCount(agent_id, new_count);
88  }
89  }
90 
91  void OnStoreSave(ParamsWriteContext ctx)
92  {
93  //Debug.Log("PlayerAgentPool OnStoreSave called", "Agents");
94 
95  ctx.Write( m_VirusPool.Count() );
96  for(int i = 0; i < m_VirusPool.Count();i++)
97  {
98  int key = m_VirusPool.GetKey(i);
99  int value = m_VirusPool.GetElement(i);
100  ctx.Write( key );
101  ctx.Write( value );
102  }
103  }
104 
105  bool OnStoreLoad(ParamsReadContext ctx, int version)
106  {
107  //Debug.Log("PlayerAgentPool OnStoreLoad called", "Agents");
108  int count;
109 
110  if(!ctx.Read(count))
111  {
112  return false;
113  }
114 
115  for(int i = 0; i < count;i++)
116  {
117  int key;
118  int value;
119  if(!ctx.Read(key))
120  {
121  return false;
122  }
123 
124  if(!ctx.Read(value))
125  {
126  return false;
127  }
128 
129  SetAgentCount( key,value );
130  }
131 
132  return true;
133  }
134  void DigestAgent(int agent_id, float count)
135  {
136  AddAgent(agent_id, m_PluginTransmissionAgents.GetAgentDigestibility(agent_id) * count);
137  }
138 
139  void AddAgent(int agent_id, float count)
140  {
141  int max_count = m_PluginTransmissionAgents.GetAgentMaxCount(agent_id);
142 
143  if( !m_VirusPool.Contains(agent_id) && count > 0 )//if it contains, maybe add count only ?
144  {
145  //m_VirusPool.Insert( agent_id, Math.Clamp(count,0,max_count) );
146  SetAgentCount(agent_id,count);
147  }
148  else
149  {
150  float new_value = m_VirusPool.Get(agent_id) + count;
151  //Print(new_value);
152  SetAgentCount(agent_id,new_value);
153  }
154  }
155 
156 /*
157  void RemoveAgent(int agent_id)
158  {
159  if( m_VirusPool.Contains(agent_id) )
160  {
161  m_VirusPool.Remove( agent_id );
162  }
163  }
164  */
165  void RemoveAgent(int agent_id)
166  {
167  SetAgentCount(agent_id, 0);
168  }
169 
170  void RemoveAllAgents()
171  {
172  m_AgentMask = 0;
173  m_VirusPool.Clear();
174  }
175 
176  /*
177  array<int GetAgents()
178  {
179  m_VirusPoolArray.Clear();
180 
181  for(int i = 0; i < m_VirusPool.Count();i++)
182  {
183  m_VirusPoolArray.Insert( m_VirusPool.GetKey(i) );
184  }
185 
186  return m_VirusPoolArray;
187  }
188  */
189 
190  int GetAgents()
191  {
192  return m_AgentMask;
193  }
194 
195  int GetSingleAgentCount(int agent_id)
196  {
197  if( m_VirusPool.Contains(agent_id) )
198  {
199  return m_VirusPool.Get( agent_id );
200  }
201  else return 0;
202  }
203 
204  float GetTotalAgentCount()
205  {
206  float agent_count;
207  for(int i = 0; i < m_VirusPool.Count(); i++)
208  {
209  agent_count += m_VirusPool.GetElement(i);
210  }
211  return agent_count;
212  }
213 
214  void SpawnAgents(float deltaT)
215  {
216  int count = m_PluginTransmissionAgents.GetAgentList().Count();
217  for(int i = 0; i < count;i++)
218  {
219  AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
220  int agent_id = agent.GetAgentType();
221 
222  if( GetSingleAgentCount(agent_id)==0 && agent.AutoinfectCheck(deltaT, m_Player) )
223  {
224  AddAgent(agent_id,100);
225  }
226  }
227  }
228 
229 
230  void SetAgentCount(int agent_id, float count)
231  {
232  if(count > 0)
233  {
234  //Debug.Log("+ growing agent"+ agent_id.ToString() +"to count: "+count.ToString(), "Agents");
235  m_VirusPool.Set( agent_id, count);
236  m_AgentMask = m_AgentMask | agent_id;
237  }
238  else
239  {
240  //Debug.Log("- REMOVING agent"+ agent_id.ToString(), "Agents");
241  m_VirusPool.Remove( agent_id );
242  m_AgentMask = m_AgentMask & ~agent_id;
243  }
244  if(m_Player.m_Agents != m_AgentMask)
245  {
246  m_Player.m_Agents = m_AgentMask;
247  m_Player.SetSynchDirty();
248  }
249  }
250 
251  void AntibioticsAttack(float attack_value)
252  {
253  for(int i = 0; i < m_VirusPool.Count(); i++)
254  {
255  int agent_id = m_VirusPool.GetKey(i);
256  float antibiotics_resistance = 1 - m_PluginTransmissionAgents.GetAgentAntiboticsResistanceEx(agent_id, m_Player);
257  float delta = attack_value * antibiotics_resistance;
258  float old_count = m_VirusPool.Get( agent_id );
259  float new_count = old_count - delta;
260  //PrintString("delta:"+delta.ToString());
261  //PrintString("old_count:"+old_count.ToString());
262  //PrintString("new_count:"+new_count.ToString());
263  SetAgentCount(agent_id, new_count);
264  }
265  }
266 
267 
268  void RemoteGrowRequestDebug(ParamsReadContext ctx)
269  {
270  ctx.Read(CachedObjectsParams.PARAM1_INT);
271  int id = CachedObjectsParams.PARAM1_INT.param1;
272  int max = m_PluginTransmissionAgents.GetAgentMaxCount(Math.AbsInt(id));
273  int grow = max / 10;
274  if(id > 0)
275  {
276  AddAgent(id, grow);
277  }
278  else if( id < 0)
279  {
280  AddAgent(-id, -grow);
281  }
282  }
283 
284  void GetDebugObject(array<ref Param> object_out)
285  {
286  int count = m_PluginTransmissionAgents.GetAgentList().Count();
287  for(int i = 0; i < count;i++)
288  {
289  AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
290  string agent_name = agent.GetName();
291  int agent_id = agent.GetAgentType();
292  int max_agents = m_PluginTransmissionAgents.GetAgentMaxCount(agent_id);
293  string amount = GetSingleAgentCount(agent_id).ToString() + "/" + max_agents.ToString();
294  object_out.Insert( new Param3<string,string, int>(agent_name, amount, agent_id) );
295  }
296  object_out.InsertAt(new Param1<int>(count) ,0);
297  }
298 }
CachedObjectsParams
Definition: utilityclasses.c:9
Param3
Definition: entityai.c:95
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerAgentPool
Definition: playeragentpool.c:1
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
IsPluginManagerExists
bool IsPluginManagerExists()
Definition: pluginmanager.c:306
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
AgentBase
Definition: brainagent.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
EStatLevels
EStatLevels
Definition: estatlevels.c:1
Debug
Definition: debug.c:13
Math
Definition: enmath.c:6
STORAGE_VERSION
const int STORAGE_VERSION
Definition: modifiersmanager.c:79