DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
BleedingSourcesManagerServer.c
См. документацию.
1class BleedingSourcesManagerServer extends BleedingSourcesManagerBase
2{
3 const float TICK_INTERVAL_SEC = 3;
4 float m_Tick;
5 bool m_DisableBloodLoss = false;
7
8 const int STORAGE_VERSION = 103;
9
14
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 {
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
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
83 {
85 if( bit != 0)
87 }
88
94
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 {
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;
129 {
130 while( m_DeleteList.Count() > 0 )
131 {
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
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 {
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 ENABLE_LOGGING
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 ENABLE_LOGGING
199 {
200 Debug.BleedingChancesLog("true", "BleedingSourcesManagerServer" , "n/a", "Attempting to create bleeding source");
201 }
202 #endif
204 }
205 }
206
208 {
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 {
218 }
219 }
220
221 void SetBloodLoss(bool status)
222 {
223 m_DisableBloodLoss = status;
224 }
225
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);
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 {
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
292 {
293 if (m_Player && !m_Player.IsAlive())
295 }
296}
eBleedingSourceType
Определения BleedingSource.c:2
const int BIT_INT_SIZE
Определения BitArray.c:4
eAgents
Определения EAgents.c:3
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
static bool CalculateBleedChance(string damageType, float bloodDamage, float bleedThreshold, out float bleedChance)
returns 'false' when damageType is unhandled
Определения BleedChanceData.c:70
Static data of bleeding chance probabilities; currently used for melee only.
Определения BleedChanceData.c:5
float GetFlowModifier()
Определения BleedingSourceZone.c:61
void DebugActivateBleedingSource(int source)
Определения BleedingSourcesManagerServer.c:207
void SetBloodLoss(bool status)
Определения BleedingSourcesManagerServer.c:221
int GetBleedingSourceActiveTime(int bit)
Определения BleedingSourcesManagerBase.c:274
void SetItem(ItemBase item)
Определения BleedingSourcesManagerBase.c:64
void RemoveMostSignificantBleedingSource()
Определения BleedingSourcesManagerServer.c:82
void OnTick(float delta_time)
Определения BleedingSourcesManagerServer.c:125
void AddBleedingSource(int bit)
Определения BleedingSourcesManagerServer.c:25
void OnStoreSave(ParamsWriteContext ctx)
Определения BleedingSourcesManagerServer.c:226
bool AttemptAddBleedingSource(int component)
Определения BleedingSourcesManagerBase.c:194
eBleedingSourceType GetBleedingSourceType(int bit)
Определения BleedingSourcesManagerBase.c:299
BleedingSourceZone GetBleedingSourceMeta(int bit)
Определения BleedingSourcesManagerBase.c:127
string GetSelectionNameFromBit(int bit)
Определения BleedingSourcesManagerBase.c:189
ref map< int, ref BleedingSource > m_BleedingSources
Определения BleedingSourcesManagerBase.c:3
ref array< int > m_DeleteList
Определения BleedingSourcesManagerServer.c:6
void SetBleedingSourceActiveTime(int bit, int time)
Определения BleedingSourcesManagerBase.c:284
void ProcessHit(float damage, EntityAI source, int component, string zone, string ammo, vector modelPos)
Определения BleedingSourcesManagerServer.c:160
const float TICK_INTERVAL_SEC
Определения BleedingSourcesManagerServer.c:3
bool RemoveBleedingSource(int bit)
Определения BleedingSourcesManagerServer.c:37
bool CanAddBleedingSource(int bit)
Определения BleedingSourcesManagerBase.c:241
ref map< string, ref BleedingSourceZone > m_BleedingSourceZone
Определения BleedingSourcesManagerBase.c:4
bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения BleedingSourcesManagerServer.c:248
void SetBleedingSourceType(int bit, eBleedingSourceType type)
Определения BleedingSourcesManagerBase.c:292
void RequestDeletion(int bit)
Определения BleedingSourcesManagerServer.c:20
void RemoveMostSignificantBleedingSourceEx(ItemBase item)
Определения BleedingSourcesManagerServer.c:89
BleedingSourceZone GetBleedingSourceZone(int bit)
Определения BleedingSourcesManagerServer.c:10
proto native float ConfigGetFloat(string path)
Get float value from config on path.
string ConfigGetTextOut(string path)
Get string value from config on path.
Определения Game.c:463
static ref Param1< bool > PARAM1_BOOL
Определения UtilityClasses.c:12
static void BleedingChancesLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Определения Debug.c:162
Определения Debug.c:2
Определения Building.c:6
Определения InventoryItem.c:731
static bool IsBleedingChancesLogEnable()
Определения Debug.c:733
Определения Debug.c:594
Определения EnMath.c:7
static const float BLEEDING_LOW_PRESSURE_MIN_MOD
Определения PlayerConstants.c:177
static const float BLEEDING_LOW_PRESSURE_BLOOD
Определения PlayerConstants.c:176
static const float BLEEDING_SOURCE_CLOSE_INFECTION_CHANCE
Определения PlayerConstants.c:179
static const int BLOOD_THRESHOLD_FATAL
Определения PlayerConstants.c:97
Определения PlayerConstants.c:2
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto string ToString(bool simple=true)
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
Serializer ParamsWriteContext
Определения gameplay.c:16
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:126
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'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].