DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
BleedingSourcesManagerBase.c
Go to the documentation of this file.
2{
6 static ref map<int, int> m_BleedingSourcesZonesMaskByLocation = new map<int, int>;//for each inventory location, keep a bitmask where a bit is set to 1 for each bleeding source zone that belongs to that location
7 static ref set<int> m_BleedingSourcesLocationsList = new set<int>;
8 ItemBase m_Item;//item used to remove the bleeding source
10 //ref map<string, int> m_FireGeomToBit = new map<string, int>;
12 protected int m_Bit;
13 int m_BitOffset = 0;
14
16 {
17 m_Player = player;
18 Init();
19 }
20
21 protected void Init()
22 {
23 //dmgZone_head
25 //dmgZone_torso
26 RegisterBleedingZoneEx("Neck", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL,"", "-180 0 0" , "0.02 -0.05 0.05", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.HEADGEAR);
32 //dmgZone_leftArm
37 //dmgZone_rightArm
42 //dmgZone_leftHand
43 RegisterBleedingZoneEx("LeftForeArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0.1 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.GLOVES);
44 //dmgZone_rightHand
45 RegisterBleedingZoneEx("RightForeArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "-0.1 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.GLOVES);
46 //dmgZone_leftLeg
51 //dmgZone_rightLeg
56 //dmgZone_leftFoot
57 RegisterBleedingZoneEx("LeftFoot",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 180 0" , "0 0 0.035", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.LEGS);
59 //dmgZone_rightFoot
60 RegisterBleedingZoneEx("RightFoot",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 0 0" , "0 0 -0.035", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.LEGS);
62 }
63
64 protected void SetItem(ItemBase item)
65 {
66 m_Item = item;
67 }
68
69
71 {
73 }
74
75
76 //for inventory location, get the active bits
78 {
79 if (m_BleedingSourcesByLocation.Contains(inv_location))
80 {
81 return m_BleedingSourcesByLocation.Get(inv_location);
82 }
83
84 return 0;
85 }
86
87 //for inventory location, get the active bits
89 {
90 if (m_BleedingSourcesZonesMaskByLocation.Contains(inv_location))
91 {
92 return (~m_BleedingSourcesZonesMaskByLocation.Get(inv_location) & GetBleedingSourceBitsByInvLocation(inv_location)) | (m_BleedingSourcesZonesMaskByLocation.Get(inv_location) & ~GetBleedingSourceBitsByInvLocation(inv_location));//xor
93 }
94
95 return 0;
96 }
97
99 {
100 name.ToLower();
101 int bit = GetBitFromSelectionName(name);
102
103 return m_Player.GetBleedingBits() & bit;
104 }
105
106
107 protected int GetBitFromSelectionID(int id)
108 {
110 m_Player.GetActionComponentNameList(id, CachedObjectsArrays.ARRAY_STRING, "fire");
111
112 for (int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
113 {
114 /*
115 string name = CachedObjectsArrays.ARRAY_STRING.Get(i);
116 PrintString(name);
117 */
119 if ( bit !=0 )
120 {
121 return bit;
122 }
123 }
124 return 0;
125 }
126
128 {
130 }
131
133 {
134 return m_BitOffset;
135 }
136
137 protected void RegisterBleedingZoneEx(string name, int max_time, string bone = "", vector orientation = "0 0 0", vector offset = "0 0 0", float flow_modifier = 1, string particle_name = "BleedingSourceEffect", int inv_location = 0)
138 {
140 {
141 Error("Too many bleeding sources, max is "+BIT_INT_SIZE.ToString());
142 }
143 else
144 {
145 name.ToLower();
146 //PrintString(name);
147 //int bit = Math.Pow(2, m_BitOffset);
148 m_Bit = 1 << m_BitOffset;
149 //PrintString(bit.ToString());
150 string bone_name = bone;
151
152 if (bone_name == "")
153 {
154 bone_name = name;
155 }
156
157 m_BleedingSourceZone.Insert(name, new BleedingSourceZone(name, m_Bit, offset, orientation, bone_name, max_time, flow_modifier, particle_name));
158 m_BleedingSourceZone.Get(name).SetInvLocation(inv_location);
159 m_BitToFireGeom.Insert(m_Bit, name);
160 m_BleedingSourcesZonesMaskByLocation.Set( inv_location, m_BleedingSourcesZonesMaskByLocation.Get(inv_location) | m_Bit);//set a bit to 1 to already existing bitmask for that location
161 m_BleedingSourcesLocationsList.Insert(inv_location);
162 m_BitOffset++;
163 }
164 }
165 protected void RegisterBleedingZone(string name, int max_time, string bone = "", vector orientation = "0 0 0", vector offset = "0 0 0", float flow_modifier = 1, string particle_name = "BleedingSourceEffect")
166 {
167 RegisterBleedingZoneEx(name, max_time, bone, orientation, offset, flow_modifier, particle_name);
168 }
169
171 {
172 //int count = m_BleedingSources.Count();
173 while (m_BleedingSources.Count() > 0 )
174 {
175 int bit = m_BleedingSources.GetKey(0);
177 }
178 }
179
180 protected int GetBitFromSelectionName(string name)
181 {
182 if (!m_BleedingSourceZone.Get(name))
183 {
184 return 0;
185 }
186 return m_BleedingSourceZone.Get(name).GetBit();
187 }
188
189 protected string GetSelectionNameFromBit(int bit)
190 {
191 return m_BitToFireGeom.Get(bit);
192 }
193
195 {
197
198 if ( bit == 0 )
199 {
200 return false;
201 }
202
203 if ( CanAddBleedingSource(bit) )
204 {
206 return true;
207 }
208 return false;
209 }
210
211 bool AttemptAddBleedingSourceBySelection(string selection_name)
212 {
213 selection_name.ToLower();
214 int bit = GetBitFromSelectionName(selection_name);
215
216 if ( bit == 0 )
217 {
218 return false;
219 }
220
221 if ( CanAddBleedingSource(bit) )
222 {
224 return true;
225 }
226 return false;
227 }
228
229
231 {
232 if(CanAddBleedingSource(bit))
233 {
234 AddBleedingSourceEx(bit, type, context);
235 return true;
236 }
237 return false;
238 }
239
240
241 protected bool CanAddBleedingSource(int bit)
242 {
243 if (!GetBleedingSourceMeta(bit))
244 {
245 return false;
246 }
247 if ((m_Player.GetBleedingBits() & bit) == 0)
248 {
249 return true;
250 }
251 return false;
252 }
253
254 protected void AddBleedingSourceEx(int bit, eBleedingSourceType type = eBleedingSourceType.NORMAL, int context = 0)
255 {
257 m_BleedingSources.Get(bit).SetType(type);
258 }
259
260 protected void AddBleedingSource(int bit)
261 {
263 vector orientation = bsz.GetOrientation();
264 vector offset = bsz.GetOffset();
265 string bone_name = bsz.GetBoneName();
266 float flow_modifier = bsz.GetFlowModifier();
267 int max_time = bsz.GetMaxTime();
268 string particle_name = bsz.GetParticleName();
269 int inventory_loc = bsz.GetInvLocation();
270 m_BleedingSourcesByLocation.Set(inventory_loc, (m_BleedingSourcesByLocation.Get(inventory_loc) | bit));
271 m_BleedingSources.Insert(bit, new BleedingSource(m_Player, bit,bone_name, orientation, offset, max_time, flow_modifier, particle_name) );
272
273 m_Player.OnBleedingSourceAdded();
274 }
275
277 {
278 int time = -1;
279 if (m_BleedingSources.Contains(bit))
280 {
281 time = m_BleedingSources.Get(bit).GetActiveTime();
282 }
283 return time;
284 }
285
286 void SetBleedingSourceActiveTime(int bit, int time)
287 {
288 if (m_BleedingSources.Contains(bit))
289 {
290 m_BleedingSources.Get(bit).SetActiveTime(time);
291 }
292 }
293
295 {
296 if (m_BleedingSources.Contains(bit))
297 {
298 m_BleedingSources.Get(bit).SetType(type);
299 }
300 }
302 {
303 if (m_BleedingSources.Contains(bit))
304 {
305 return m_BleedingSources.Get(bit).GetType();
306 }
307 return -1;
308 }
309
310 protected bool RemoveBleedingSource(int bit)
311 {
312 if (m_BleedingSources.Contains(bit))
313 {
315 int inventory_loc = bsz.GetInvLocation();
316 m_BleedingSourcesByLocation.Set(inventory_loc, (m_BleedingSourcesByLocation.Get(inventory_loc) & ~bit));//deactivate the bit
317 m_BleedingSources.Remove(bit);
318 m_Player.OnBleedingSourceRemovedEx(m_Item);
319 return true;
320 }
321 return false;
322 }
323
325 {
326 return m_BleedingSources.Count();
327 }
328
329 /*void ChangeBleedingIndicatorVisibility(bool visible)
330 {
331 int count = m_BleedingSources.Count();
332 for (int i = 0; i < count; i++)
333 {
334 m_BleedingSources.GetElement(i).ToggleSourceBleedingIndication(visible);
335 }
336 }*/
337}
void BleedingSource(PlayerBase player, int bit, string bone, vector orientation, vector offset, int max_time, float flow_modifier, string particle_name)
eBleedingSourceType
const int BIT_INT_SIZE
Definition BitArray.c:4
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
string name
void SetBleedingSourceActiveTime(int bit, int time)
ref map< int, int > m_BleedingSourcesByLocation
int GetBleedingSourceBitsByInvLocation(int inv_location)
protected bool CanAddBleedingSource(int bit)
ref map< int, ref BleedingSource > m_BleedingSources
void BleedingSourcesManagerBase(PlayerBase player)
protected bool RemoveBleedingSource(int bit)
protected void RegisterBleedingZone(string name, int max_time, string bone="", vector orientation="0 0 0", vector offset="0 0 0", float flow_modifier=1, string particle_name="BleedingSourceEffect")
bool AttemptAddBleedingSourceDirectly(int bit, eBleedingSourceType type=eBleedingSourceType.NORMAL, int context=0)
protected int GetBitFromSelectionID(int id)
protected void AddBleedingSourceEx(int bit, eBleedingSourceType type=eBleedingSourceType.NORMAL, int context=0)
void SetBleedingSourceType(int bit, eBleedingSourceType type)
int GetFreeBleedingSourceBitsByInvLocation(int inv_location)
eBleedingSourceType GetBleedingSourceType(int bit)
protected BleedingSourceZone GetBleedingSourceMeta(int bit)
protected int GetBitFromSelectionName(string name)
ref map< string, ref BleedingSourceZone > m_BleedingSourceZone
static ref set< int > m_BleedingSourcesLocationsList
protected void SetItem(ItemBase item)
static ref map< int, int > m_BleedingSourcesZonesMaskByLocation
bool AttemptAddBleedingSourceBySelection(string selection_name)
protected void RegisterBleedingZoneEx(string name, int max_time, string bone="", vector orientation="0 0 0", vector offset="0 0 0", float flow_modifier=1, string particle_name="BleedingSourceEffect", int inv_location=0)
protected void AddBleedingSource(int bit)
protected string GetSelectionNameFromBit(int bit)
static ref TStringArray ARRAY_STRING
provides access to slot configuration
static const float BLEEDING_SOURCE_FLOW_MODIFIER_LOW
static const float BLEEDING_SOURCE_FLOW_MODIFIER_HIGH
static const float BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM
static const int BLEEDING_SOURCE_DURATION_NORMAL
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
proto int ToLower()
Changes string to lowercase. Returns length.