DayZ 1.24
Loading...
Searching...
No Matches
Magazine.c
Go to the documentation of this file.
2
11
13{
14 None = 0,
15 Tracer = 1,
16 AP = 2
17}
18
19
20class AmmoData
21{
22 bool m_IsValid;
25
26 void AmmoData(string init_type)
27 {
28 m_IsValid = GetGame().ConfigIsExisting("CfgMagazines " + init_type);
29 if (m_IsValid)
30 {
31 m_CartridgeType = GetGame().ConfigGetInt("CfgMagazines " + init_type + " iconCartridge");
32 m_ProjectileType = GetGame().ConfigGetInt("CfgMagazines " + init_type + " iconType");
33 }
34 }
35}
36
38{
41 ref array<float> m_ChanceToJam;
42 protected float m_ManipulationDamage;
43
44 void Magazine()
45 {
46 m_ChanceToJam = new array<float>;
47 InitReliability(m_ChanceToJam);
48 m_ManipulationDamage = ConfigGetFloat("manipulationDamage");
50 ConfigGetTextArray("ammoItems", m_CompatiableAmmo);
51 if (!GetGame().IsDedicatedServer())
52 {
53 if (!m_AmmoData)
55
56 string classname = ClassName();
57 if (!m_AmmoData.Contains(classname))
58 {
60 if (new_data.m_IsValid)
62 }
63 }
64 }
65
71
88
96 proto bool GetCartridgeAtIndex(int cartIndex, out float dmg, out string cartTypeName);
97
105 proto bool SetCartridgeAtIndex(int cartIndex, out float dmg, out string cartTypeName);
106
114
115
116 static AmmoData GetAmmoData(string classname)
117 {
118 if (!m_AmmoData)
120 if (!m_AmmoData.Contains(classname))
121 {
123 if (new_data.m_IsValid)
125 return new_data;
126 }
127 else
128 return m_AmmoData.Get(classname);
129 }
130
132 {
133 if (m_CompatiableAmmo && ammo)
134 return (m_CompatiableAmmo.Find(ammo.GetType()) > -1);
135 else
136 return false;
137 }
138
139 bool CanAddCartridges(int count)
140 {
142 return count <= spc_avail;
143 }
144
147 {
149 }
151 {
153 }
155 int GetAmmoMax()
156 {
157 return m_Count;
158 }
160 void ServerSetAmmoMax()
161 {
163 }
164 void LocalSetAmmoMax()
165 {
167 }
169 override bool IsMagazine()
170 {
171 return true;
172 }
173
174
175 override bool CanBeSplit()
176 {
178 return (GetAmmoCount() > 1);
179
180 return false;
181 }
182
183 bool InitReliability(out array<float> reliability_array)
184 {
185 if (GetGame().ConfigIsExisting("cfgMagazines " + GetType() + " Reliability ChanceToJam"))
186 {
187 GetGame().ConfigGetFloatArray("cfgMagazines " + GetType() + " Reliability ChanceToJam", reliability_array);
188 return true;
189 }
190 return false;
191 }
192
193 float GetChanceToJam()
194 {
195 int level = GetHealthLevel();
196
197 if (level >= 0 && level < m_ChanceToJam.Count())
198 return m_ChanceToJam[level];
199 else
200 return 0.0;
201 }
202
204 {
205 if (!CanBeSplit())
206 return;
207
209 if (new_pile)
210 {
211 MiscGameplayFunctions.TransferItemProperties(dst.GetItem(), new_pile);
212
213 new_pile.ServerSetAmmoCount(0);
214 int quantity = GetAmmoCount();
215
216 for (int i = 0; i < Math.Floor(quantity * 0.5); ++i)
217 {
218 float damage;
219 string cartrige_name;
221 new_pile.ServerStoreCartridge(damage, cartrige_name);
222 }
223 new_pile.SetSynchDirty();
224 SetSynchDirty();
225 }
226 }
227
228 override void SplitItem(PlayerBase player)
229 {
230 if (!CanBeSplit())
231 return;
232
233
234 Magazine new_pile = Magazine.Cast(player.CreateCopyOfItemInInventoryOrGround(this));
235 if (new_pile)
236 {
237 new_pile.ServerSetAmmoCount(0);
238 int quantity = this.GetAmmoCount();
239
240 for (int i = 0; i < Math.Floor(quantity / 2); i++)
241 {
242 float damage;
243 string cartrige_name;
245 new_pile.ServerStoreCartridge(damage, cartrige_name);
246 }
247 new_pile.SetSynchDirty();
248 SetSynchDirty();
249 }
250 }
251
253 {
254 AddHealth("", "Health", -m_ManipulationDamage);
255 }
256
257 override bool IsFullQuantity()
258 {
259 if (GetAmmoCount() == GetAmmoMax())
260 return true;
261 else
262 return false;
263 }
264
265 override protected float GetWeightSpecialized(bool forceRecalc = false)
266 {
267#ifdef DEVELOPER
268 if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
269 {
270 WeightDebugData data = WeightDebug.GetWeightDebug(this);
271 data.SetCalcDetails("TMAG: (" + GetAmmoCount() + "(Ammo count) * " + ConfigGetFloat("weightPerQuantityUnit") + "(weightPerQuantityUnit)) + " + GetConfigWeightModifiedDebugText());
272 }
273#endif
274 return GetConfigWeightModified() + (GetAmmoCount() * ConfigGetFloat("weightPerQuantityUnit"));
275 }
276
277 override bool IsCombineAll(ItemBase other_item, bool use_stack_max = false)
278 {
281
282 return free_space >= other_magazine.GetAmmoCount();
283 }
284
285 override void CombineItems(ItemBase other_item, bool use_stack_max = false)
286 {
288 return;
289
290 if (other_item.GetType() != GetType())
291 return;
292
295 {
296 //int other_item_quantity = other_magazine.GetAmmoCount();
300
301 for (int i = 0; i < this_free_space && other_magazine.GetAmmoCount() > 0 ; i++)
302 {
303 float damage;
304 string cartrige_name;
305 other_magazine.ServerAcquireCartridge(damage, cartrige_name);
308 }
309
310 if (GetGame().IsServer())
311 {
312 float resultingHealth = (currentAmount * GetHealth() + numberOfTransferredBullets * other_magazine.GetHealth()) / GetAmmoCount();
313 SetHealth("", "", resultingHealth);
314 }
316 other_magazine.SetSynchDirty();
317 SetSynchDirty();
318 }
319 }
320
321 override bool CanDetachAttachment(EntityAI parent)
322 {
323 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
324 if (player)
325 {
326 Weapon_Base wpn = Weapon_Base.Cast(parent);
327 if (wpn)
328 return player.GetWeaponManager().CanDetachMagazine(wpn, this);
329 }
330 return super.CanDetachAttachment(parent);
331 }
332
333 override void OnInventoryEnter(Man player)
334 {
335 super.OnInventoryEnter(player);
336
338 p.GetWeaponManager().OnMagazineInventoryEnter(this);
339 }
340
341 override void OnInventoryExit(Man player)
342 {
343 super.OnInventoryExit(player);
344
346 p.GetWeaponManager().OnMagazineInventoryExit(this);
347 }
348
349 override void OnWasAttached(EntityAI parent, int slot_id)
350 {
351 super.OnWasAttached(parent, slot_id);
352
353 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
354 Weapon_Base wpn = Weapon_Base.Cast(parent);
355 if (wpn && player)
356 player.GetWeaponManager().OnMagazineAttach(this);
357 }
358
359 override void OnWasDetached(EntityAI parent, int slot_id)
360 {
361 super.OnWasDetached(parent, slot_id);
362
363 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
364 Weapon_Base wpn = Weapon_Base.Cast(parent);
365
366 if (wpn && player)
367 player.GetWeaponManager().OnMagazineDetach(this);
368 }
369
370 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
371 {
372 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
373 float damage = 1 - GetHealthLevelValue(newLevel) + 0.001;
374
376 for (int i = 0; i < cartridgeCount; ++i)
378 }
379
381 {
382 super.GetDebugActions(outputList);
383
384 if (GetAmmoCount() > 0)
385 {
386 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.LIGHT_GREY));
387 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.PRINT_BULLETS, "Print Bullets", FadeColors.LIGHT_GREY));
388 }
389 }
390
391 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
392 {
393 if (GetGame().IsServer())
394 {
395 if (action_id == EActions.PRINT_BULLETS)
396 {
398 Class.CastTo(magazine, this);
399 for (int i = 0; i < magazine.GetAmmoCount(); i++)
400 {
401 float damage;
402 string className;
403 magazine.GetCartridgeAtIndex(i, damage, className);
404 Debug.Log(string.Format("Bullet: %1, Damage %2", className, damage));
405 }
406 }
407 }
408
409 return super.OnAction(action_id, player, ctx);
410 }
411
412 override bool CanBeFSwaped()
413 {
414 Weapon_Base wpn = Weapon_Base.Cast(GetHierarchyParent());
415 if (wpn)
416 return false;
417
418 return true;
419 }
420}
421
422class MagazineStorage : Magazine
423{
424 override void SetActions()
425 {
426 super.SetActions();
430 }
431}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition EntityAI.c:97
eBleedingSourceType GetType()
void AddAction(typename actionName)
void SetActions()
const int ECE_IN_INVENTORY
const int RF_DEFAULT
EActions
Definition EActions.c:2
void SplitItem(PlayerBase player)
Definition ItemBase.c:6476
void SplitItemToInventoryLocation(notnull InventoryLocation dst)
Definition ItemBase.c:6443
float GetWeightSpecialized(bool forceRecalc=false)
Definition ItemBase.c:8020
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition ItemBase.c:6834
void CombineItems(ItemBase other_item, bool use_stack_max=true)
Definition ItemBase.c:6737
void OnInventoryEnter(Man player)
Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter.
Definition ItemBase.c:8449
void OnCombine(ItemBase other_item)
Definition ItemBase.c:6763
int m_Count
Definition ItemBase.c:4700
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition ItemBase.c:6635
override bool CanBeSplit()
Definition ItemBase.c:6180
bool IsCombineAll(ItemBase other_item, bool use_stack_max=false)
Definition ItemBase.c:6698
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
Definition ItemBase.c:8462
bool IsFullQuantity()
Definition ItemBase.c:8000
bool m_CanThisBeSplit
Definition ItemBase.c:4742
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition ItemBase.c:6792
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition ItemBase.c:6535
override void OnWasAttached(EntityAI parent, int slot_id)
Definition ItemBase.c:5983
Magazine Magazine_Base
Definition Magazine.c:1
CartridgeType
Definition Magazine.c:4
@ Pistol
Definition Magazine.c:6
@ Shell
Definition Magazine.c:9
@ FullPower
Definition Magazine.c:8
@ Intermediate
Definition Magazine.c:7
enum CartridgeType Tracer
enum CartridgeType None
Definition Magazine.c:5
override void OnWasDetached(EntityAI parent, int slot_id)
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Debug.c:14
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.
Definition Debug.c:133
script counterpart to engine's class Inventory
Definition Inventory.c:79
static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new item directly at location
InventoryLocation.
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Floor(float f)
Returns floor of value.
const int SAT_DEBUG_ACTION
Definition constants.c:424