Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
bleedingsourcesmanagerserver.c
Go to the documentation of this file.
1 class BleedingSourcesManagerServer extends BleedingSourcesManagerBase
2 {
3  const float TICK_INTERVAL_SEC = 3;
4  float m_Tick;
5  bool m_DisableBloodLoss = false;
6  ref array<int> m_DeleteList = new array<int>;
7 
8  const int STORAGE_VERSION = 103;
9 
10  protected BleedingSourceZone GetBleedingSourceZone(int bit)
11  {
12  return m_BleedingSourceZone.Get(GetSelectionNameFromBit(bit));
13  }
14 
15  int GetStorageVersion()
16  {
17  return STORAGE_VERSION;
18  }
19 
20  void RequestDeletion(int bit)
21  {
22  m_DeleteList.Insert(bit);
23  }
24 
25  override protected void AddBleedingSource(int bit)
26  {
27  #ifdef DEVELOPER
28  if (m_Player && !m_Player.GetAllowDamage())//full invincibility prevents bleeding source creation
29  return;
30  #endif
31 
32  m_Player.SetBleedingBits(m_Player.GetBleedingBits() | bit );
33  super.AddBleedingSource(bit);
34  m_Player.OnBleedingSourceAdded();
35  }
36 
37  override protected bool RemoveBleedingSource(int bit)
38  {
39  if(!super.RemoveBleedingSource(bit))
40  {
41  Error("Failed to remove bleeding source:" + bit);
42  }
43  else
44  {
45  m_Player.OnBleedingSourceRemovedEx(m_Item);
46  }
47 
48  int inverse_bit_mask = ~bit;
49  m_Player.SetBleedingBits(m_Player.GetBleedingBits() & inverse_bit_mask );
50 
51 
52  //infection moved here to allow proper working in singleplayer
53  float chanceToInfect;
54 
55  if (m_Item)
56  {
57  chanceToInfect = m_Item.GetInfectionChance(0, CachedObjectsParams.PARAM1_BOOL);
58  }
59  else
60  {
61  chanceToInfect = PlayerConstants.BLEEDING_SOURCE_CLOSE_INFECTION_CHANCE;
62  }
63  float diceRoll = Math.RandomFloat01();
64  if (diceRoll < chanceToInfect)
65  {
66  m_Player.InsertAgent(eAgents.WOUND_AGENT);
67  }
68 
69  m_Item = null;//reset, so that next call, if induced by self-healing, will have no item
70 
71  return true;
72  }
73 
74  void RemoveAnyBleedingSource()
75  {
76  int bleeding_sources_bits = m_Player.GetBleedingBits();
77  int rightmost_bit = bleeding_sources_bits & (-bleeding_sources_bits);
78 
79  RemoveBleedingSource(rightmost_bit);
80  }
81 
82  void RemoveMostSignificantBleedingSource()
83  {
84  int bit = GetMostSignificantBleedingSource();
85  if( bit != 0)
86  RemoveBleedingSource(bit);
87  }
88 
89  void RemoveMostSignificantBleedingSourceEx(ItemBase item)
90  {
91  SetItem(item);
92  RemoveMostSignificantBleedingSource();
93  }
94 
95  int GetMostSignificantBleedingSource()
96  {
97  int bleeding_sources_bits = m_Player.GetBleedingBits();
98 
99  float highest_flow;
100  int highest_flow_bit;
101  int bit_offset;
102 
103  for(int i = 0; i < BIT_INT_SIZE; i++)
104  {
105  int bit = 1 << bit_offset;
106 
107  if( (bit & bleeding_sources_bits) != 0 )
108  {
109  BleedingSourceZone meta = GetBleedingSourceMeta(bit);
110  if(meta)
111  {
112  if( meta.GetFlowModifier() > highest_flow )
113  {
114  highest_flow = meta.GetFlowModifier();
115  highest_flow_bit = bit;
116  //Print(meta.GetSelectionName());
117  }
118  }
119  }
120  bit_offset++;
121  }
122  return highest_flow_bit;
123  }
124 
125  void OnTick(float delta_time)
126  {
127  m_Tick += delta_time;
128  if( m_Tick > TICK_INTERVAL_SEC )
129  {
130  while( m_DeleteList.Count() > 0 )
131  {
132  RemoveBleedingSource(m_DeleteList.Get(0));
133  m_DeleteList.Remove(0);
134  }
135 
136  float blood_scale = Math.InverseLerp(PlayerConstants.BLOOD_THRESHOLD_FATAL, PlayerConstants.BLEEDING_LOW_PRESSURE_BLOOD, m_Player.GetHealth( "GlobalHealth", "Blood" ));
137  blood_scale = Math.Clamp( blood_scale, PlayerConstants.BLEEDING_LOW_PRESSURE_MIN_MOD, 1 );
138 
139  for(int i = 0; i < m_BleedingSources.Count(); i++)
140  {
141  m_BleedingSources.GetElement(i).OnUpdateServer( m_Tick, blood_scale, m_DisableBloodLoss );
142  }
143  m_Tick = 0;
144  }
145  }
146 
147  void ActivateAllBS()
148  {
149  for(int i = 0; i < m_BleedingSourceZone.Count(); i++)
150  {
151  int bit = m_BleedingSourceZone.GetElement(i).GetBit();
152  if( CanAddBleedingSource(bit) )
153  {
154  AddBleedingSource(bit);
155  }
156  }
157  }
158 
159  //damage must be to "Blood" healthType
160  void ProcessHit(float damage, EntityAI source, int component, string zone, string ammo, vector modelPos)
161  {
162  float dmg_max = m_Player.GetMaxHealth(zone, "Blood");
163  float bleed_threshold = GetGame().ConfigGetFloat("CfgAmmo " + ammo + " DamageApplied bleedThreshold");
164  string damageTypeString = GetGame().ConfigGetTextOut("CfgAmmo " + ammo + " DamageApplied type");
165  bleed_threshold = Math.Clamp(bleed_threshold,0,1);
166  float bleedingChance;
167  bool createBleedingSource = false;
168 
169  // 'true' only when the damageTypeString is handled there
170  if (BleedChanceData.CalculateBleedChance(damageTypeString, damage, bleed_threshold,bleedingChance))
171  {
172  float roll = Math.RandomFloat01();
173  createBleedingSource = bleedingChance != 0 && bleedingChance >= roll;
174 
175  #ifdef DEVELOPER
176  if (LogManager.IsBleedingChancesLogEnable())
177  {
178  Debug.BleedingChancesLog(roll.ToString(), "BleedingSourcesManagerServer" , "n/a", "bleeding random roll:");
179  }
180  #endif
181  }
182  else if (source && source.IsZombie())
183  {
184  int chance = Math.RandomInt(0,100);
185  if (chance <= damage)
186  {
187  createBleedingSource = true;
188  }
189  }
190  else if (damage > (dmg_max * (1 - bleed_threshold)) )
191  {
192  createBleedingSource = true;
193  }
194 
195  if (createBleedingSource)
196  {
197  #ifdef DEVELOPER
198  if (LogManager.IsBleedingChancesLogEnable())
199  {
200  Debug.BleedingChancesLog("true", "BleedingSourcesManagerServer" , "n/a", "Attempting to create bleeding source");
201  }
202  #endif
203  AttemptAddBleedingSource(component);
204  }
205  }
206 
207  void DebugActivateBleedingSource(int source)
208  {
209  RemoveAllSources();
210 
211  if(source >= m_BleedingSourceZone.Count() || !m_BleedingSourceZone.GetElement(source)) return;
212 
213  int bit = m_BleedingSourceZone.GetElement(source).GetBit();
214 
215  if( bit && CanAddBleedingSource(bit) )
216  {
217  AddBleedingSource(bit);
218  }
219  }
220 
221  void SetBloodLoss(bool status)
222  {
223  m_DisableBloodLoss = status;
224  }
225 
226  void OnStoreSave( ParamsWriteContext ctx )
227  {
228  //int count = m_BleedingSources.Count();
229  int active_bits = m_Player.GetBleedingBits();
230  ctx.Write(active_bits);
231 
232  int bit_offset = 0;
233  for(int i = 0; i < BIT_INT_SIZE; i++)
234  {
235  int bit = 1 << bit_offset;
236  if( (bit & active_bits) != 0 )
237  {
238  int active_time = GetBleedingSourceActiveTime(bit);
239  eBleedingSourceType type = GetBleedingSourceType(bit);
240 
241  ctx.Write(active_time);
242  ctx.Write(type);
243  }
244  bit_offset++;
245  }
246  }
247 
248  bool OnStoreLoad( ParamsReadContext ctx, int version )
249  {
250  int active_bits;
251  if(!ctx.Read(active_bits))
252  {
253  return false;
254  }
255 
256  int bit_offset = 0;
257  for(int i = 0; i < BIT_INT_SIZE; i++)
258  {
259  int bit = 1 << bit_offset;
260  if( (bit & active_bits) != 0 && CanAddBleedingSource(bit))
261  {
262  AddBleedingSource(bit);
263  int active_time = 0;
264  if(!ctx.Read(active_time))
265  {
266  return false;
267  }
268  else
269  {
270  SetBleedingSourceActiveTime(bit,active_time);
271  }
272  if( version >= 121 )//type was added in this version
273  {
275  if (!ctx.Read(type))
276  {
277  return false;
278  }
279  else
280  {
281  SetBleedingSourceType(bit,type);
282  }
283  }
284  }
285  bit_offset++;
286  }
287  return true;
288  }
289 
290 
291  void ~BleedingSourcesManagerServer()
292  {
293  if (m_Player && !m_Player.IsAlive())
294  RemoveAllSources();
295  }
296 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
LogManager
Definition: debug.c:734
BleedingSourcesManagerBase
Definition: bleedingsourcesmanagerbase.c:1
eBleedingSourceType
eBleedingSourceType
Definition: bleedingsource.c:1
BleedingSourceZone
Definition: bleedingsourcezone.c:1
CachedObjectsParams
Definition: utilityclasses.c:9
m_Item
protected EntityAI m_Item
Definition: radialquickbarmenu.c:14
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
SetItem
void SetItem(EntityAI item)
Definition: radialquickbarmenu.c:42
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
eAgents
eAgents
Definition: eagents.c:2
vector
Definition: enconvert.c:105
PlayerConstants
Definition: playerconstants.c:1
m_Tick
float m_Tick
Definition: staminahandler.c:139
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
OnTick
private void OnTick(PlayerBase player, float deltaT)
Definition: modifierbase.c:234
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
BleedChanceData
Static data of bleeding chance probabilities; currently used for melee only.
Definition: bleedchancedata.c:4
OnStoreSave
void OnStoreSave(ParamsWriteContext ctx)
Definition: modifierbase.c:229
Debug
Definition: debug.c:13
GetStorageVersion
int GetStorageVersion()
Definition: modifiersmanager.c:170
Math
Definition: enmath.c:6
BIT_INT_SIZE
const int BIT_INT_SIZE
Definition: bitarray.c:4
OnStoreLoad
bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: modifiersmanager.c:270
EntityAI
Definition: building.c:5
STORAGE_VERSION
const int STORAGE_VERSION
Definition: modifiersmanager.c:79