24 ProjectileType m_ProjectileType;
26 void AmmoData(
string init_type )
42 protected float m_ManipulationDamage;
47 InitReliability(m_ChanceToJam);
48 m_ManipulationDamage = ConfigGetFloat(
"manipulationDamage");
50 ConfigGetTextArray(
"ammoItems", m_CompatiableAmmo);
51 if ( !
GetGame().IsDedicatedServer() )
56 string classname = ClassName();
57 if ( !m_AmmoData.Contains(classname) )
59 ref AmmoData new_data =
new AmmoData( classname );
60 if ( new_data.m_IsValid )
61 m_AmmoData.Insert( classname,
new AmmoData( classname ) );
67 proto native
int GetAmmoCount();
69 proto native
void ServerSetAmmoCount(
int ammoCount);
70 proto native
void LocalSetAmmoCount(
int ammoCount);
78 proto
bool LocalAcquireCartridge(out
float dmg, out
string cartTypeName);
79 proto
bool ServerAcquireCartridge(out
float dmg, out
string cartTypeName);
86 proto native
bool LocalStoreCartridge(
float ammoDamage,
string cartTypeName);
87 proto native
bool ServerStoreCartridge(
float ammoDamage,
string cartTypeName);
96 proto
bool GetCartridgeAtIndex(
int cartIndex, out
float dmg, out
string cartTypeName);
105 proto
bool SetCartridgeAtIndex(
int cartIndex, out
float dmg, out
string cartTypeName);
113 proto
bool SetCartridgeDamageAtIndex(
int cartIndex,
float dmg);
116 static AmmoData GetAmmoData(
string classname )
120 if ( !m_AmmoData.Contains(classname) )
122 ref AmmoData new_data =
new AmmoData( classname );
123 if ( new_data.m_IsValid )
124 m_AmmoData.Insert( classname,
new AmmoData( classname ) );
129 return m_AmmoData.Get( classname );
133 bool IsCompatiableAmmo(
ItemBase ammo )
135 if ( m_CompatiableAmmo && ammo )
136 return ( m_CompatiableAmmo.Find( ammo.GetType() ) > -1 );
141 bool CanAddCartridges(
int count)
143 int spc_avail = GetAmmoMax() - GetAmmoCount();
144 return count <= spc_avail;
148 void ServerAddAmmoCount(
int ammoCount)
150 ServerSetAmmoCount(GetAmmoCount() + ammoCount);
152 void LocalAddAmmoCount(
int ammoCount)
154 LocalSetAmmoCount(GetAmmoCount() + ammoCount);
162 void ServerSetAmmoMax()
164 ServerSetAmmoCount( GetAmmoMax() );
166 void LocalSetAmmoMax()
168 LocalSetAmmoCount( GetAmmoMax() );
171 override bool IsMagazine()
180 return ( GetAmmoCount() > 1 );
185 bool InitReliability(out
array<float> reliability_array)
187 if (
GetGame().ConfigIsExisting(
"cfgMagazines " +
GetType() +
" Reliability ChanceToJam"))
195 float GetChanceToJam()
197 int level = GetHealthLevel();
199 if (level >= 0 && level < m_ChanceToJam.Count())
200 return m_ChanceToJam[level];
240 MiscGameplayFunctions.TransferItemProperties(dst.GetItem(), new_pile);
242 new_pile.ServerSetAmmoCount(0);
243 int quantity = GetAmmoCount();
245 for (
int i = 0; i <
Math.
Floor( quantity * 0.5 ); ++i)
248 string cartrige_name;
249 ServerAcquireCartridge(damage, cartrige_name);
250 new_pile.ServerStoreCartridge(damage, cartrige_name);
252 new_pile.SetSynchDirty();
263 Magazine new_pile = Magazine.Cast( player.CreateCopyOfItemInInventoryOrGround(
this ) );
266 new_pile.ServerSetAmmoCount(0);
267 int quantity = this.GetAmmoCount();
269 for (
int i = 0; i <
Math.
Floor( quantity / 2 ); i++)
272 string cartrige_name;
273 ServerAcquireCartridge(damage, cartrige_name);
274 new_pile.ServerStoreCartridge(damage, cartrige_name);
276 new_pile.SetSynchDirty();
281 void ApplyManipulationDamage()
283 AddHealth(
"",
"Health",-m_ManipulationDamage);
288 if ( GetAmmoCount() == GetAmmoMax() )
301 if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
304 data.
SetCalcDetails(
"TMAG: ("+GetAmmoCount()+
"(Ammo count) * " + ConfigGetFloat(
"weightPerQuantityUnit")+
"(weightPerQuantityUnit)) + " + GetConfigWeightModifiedDebugText());
307 return GetConfigWeightModified() + (GetAmmoCount() * ConfigGetFloat(
"weightPerQuantityUnit"));
339 Magazine other_magazine = Magazine.Cast(other_item);
340 int free_space = GetAmmoMax() - GetAmmoCount();
342 return free_space >= other_magazine.GetAmmoCount();
350 if ( other_item.GetType() !=
GetType() )
353 Magazine other_magazine;
357 int this_free_space = GetAmmoMax() - GetAmmoCount();
358 int numberOfTransferredBullets = 0;
359 int currentAmount = GetAmmoCount();
361 for (
int i = 0; i < this_free_space && other_magazine.GetAmmoCount() > 0 ; i++)
364 string cartrige_name;
365 other_magazine.ServerAcquireCartridge(damage, cartrige_name);
366 if (ServerStoreCartridge(damage, cartrige_name))
367 ++numberOfTransferredBullets;
372 float resultingHealth = (currentAmount * GetHealth() + numberOfTransferredBullets * other_magazine.GetHealth()) / GetAmmoCount();
373 SetHealth(
"",
"", resultingHealth);
376 other_magazine.SetSynchDirty();
381 override bool CanDetachAttachment(
EntityAI parent)
389 return player.GetWeaponManager().CanDetachMagazine(wpn,
this);
392 return super.CanDetachAttachment(parent);
397 super.OnInventoryEnter(player);
400 p.GetWeaponManager().OnMagazineInventoryEnter(
this);
405 super.OnInventoryExit(player);
408 p.GetWeaponManager().OnMagazineInventoryExit(
this);
413 super.OnWasAttached(parent, slot_id);
419 player.GetWeaponManager().OnMagazineAttach(
this);
432 super.OnWasDetached(parent, slot_id);
439 player.GetWeaponManager().OnMagazineDetach(
this);
445 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
446 float damage = 1 - GetHealthLevelValue(newLevel) + 0.001;
448 int cartridgeCount = GetAmmoCount();
449 for (
int i = 0; i < cartridgeCount; ++i)
450 SetCartridgeDamageAtIndex(i, damage);
453 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
455 super.GetDebugActions(outputList);
465 if (action_id ==
EActions.PRINT_BULLETS)
469 for (
int i = 0; i < magazine.GetAmmoCount(); i++)
473 magazine.GetCartridgeAtIndex(i, damage, className);
474 Debug.
Log(
string.Format(
"Bullet: %1, Damage %2", className, damage));
479 return super.OnAction(action_id, player, ctx);
483class MagazineStorage : Magazine
eBleedingSourceType GetType()
Param4< int, int, string, int > TSelectableActionInfoWithColor
void AddAction(typename actionName)
const int ECE_IN_INVENTORY
void OnCombine(ItemBase other_item)
override bool CanBeSplit()
bool OnAction(int action_id, Man player, ParamsReadContext ctx)
override protected float GetWeightSpecialized(bool forceRecalc=false)
void SplitItemToInventoryLocation(notnull InventoryLocation dst)
bool IsCombineAll(ItemBase other_item, bool use_stack_max=false)
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
void CombineItems(ItemBase other_item, bool use_stack_max=true)
void OnInventoryEnter(Man player)
Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter.
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
override void OnWasAttached(EntityAI parent, int slot_id)
void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
void SplitItem(PlayerBase player)
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
enum CartridgeType Tracer
override void OnWasDetached(EntityAI parent, int slot_id)
proto native void ConfigGetFloatArray(string path, out TFloatArray values)
Get array of floats from config on path.
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto native bool ConfigIsExisting(string path)
Super root of all classes in Enforce script.
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.
script counterpart to engine's class Inventory
static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new item directly at location
Serialization general interface. Serializer API works with:
void SetCalcDetails(string details)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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