24 ProjectileType m_ProjectileType;
26 void AmmoData(
string init_type )
28 m_IsValid =
GetGame().ConfigIsExisting(
"CfgMagazines " + init_type );
31 m_CartridgeType =
GetGame().ConfigGetInt(
"CfgMagazines " + init_type +
" iconCartridge" );
32 m_ProjectileType =
GetGame().ConfigGetInt(
"CfgMagazines " + init_type +
" iconType" );
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"))
189 GetGame().ConfigGetFloatArray(
"cfgMagazines " +
GetType() +
" Reliability ChanceToJam",reliability_array);
195 float GetChanceToJam()
197 int level = GetHealthLevel();
199 if (level >= 0 && level < m_ChanceToJam.Count())
200 return m_ChanceToJam[level];
213 MiscGameplayFunctions.TransferItemProperties(dst.GetItem(), new_pile);
215 new_pile.ServerSetAmmoCount(0);
216 int quantity = GetAmmoCount();
218 for (
int i = 0; i <
Math.Floor( quantity * 0.5 ); ++i)
221 string cartrige_name;
222 ServerAcquireCartridge(damage, cartrige_name);
223 new_pile.ServerStoreCartridge(damage, cartrige_name);
225 new_pile.SetSynchDirty();
236 Magazine new_pile = Magazine.Cast( player.CreateCopyOfItemInInventoryOrGround(
this ) );
239 new_pile.ServerSetAmmoCount(0);
240 int quantity = this.GetAmmoCount();
242 for (
int i = 0; i <
Math.Floor( quantity / 2 ); i++)
245 string cartrige_name;
246 ServerAcquireCartridge(damage, cartrige_name);
247 new_pile.ServerStoreCartridge(damage, cartrige_name);
249 new_pile.SetSynchDirty();
254 void ApplyManipulationDamage()
256 AddHealth(
"",
"Health",-m_ManipulationDamage);
261 if ( GetAmmoCount() == GetAmmoMax() )
274 if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
277 data.SetCalcDetails(
"TMAG: ("+GetAmmoCount()+
"(Ammo count) * " + ConfigGetFloat(
"weightPerQuantityUnit")+
"(weightPerQuantityUnit)) + " + GetConfigWeightModifiedDebugText());
280 return GetConfigWeightModified() + (GetAmmoCount() * ConfigGetFloat(
"weightPerQuantityUnit"));
285 Magazine other_magazine = Magazine.Cast(other_item);
286 int free_space = GetAmmoMax() - GetAmmoCount();
288 return free_space >= other_magazine.GetAmmoCount();
296 if ( other_item.GetType() !=
GetType() )
299 Magazine other_magazine;
300 if (
Class.CastTo(other_magazine, other_item) )
303 int this_free_space = GetAmmoMax() - GetAmmoCount();
304 int numberOfTransferredBullets = 0;
305 int currentAmount = GetAmmoCount();
307 for (
int i = 0; i < this_free_space && other_magazine.GetAmmoCount() > 0 ; i++)
310 string cartrige_name;
311 other_magazine.ServerAcquireCartridge(damage, cartrige_name);
312 if (ServerStoreCartridge(damage, cartrige_name))
313 ++numberOfTransferredBullets;
318 float resultingHealth = (currentAmount * GetHealth() + numberOfTransferredBullets * other_magazine.GetHealth()) / GetAmmoCount();
319 SetHealth(
"",
"", resultingHealth);
322 other_magazine.SetSynchDirty();
327 override bool CanDetachAttachment(
EntityAI parent)
335 return player.GetWeaponManager().CanDetachMagazine(wpn,
this);
338 return super.CanDetachAttachment(parent);
343 super.OnInventoryEnter(player);
346 p.GetWeaponManager().OnMagazineInventoryEnter(
this);
351 super.OnInventoryExit(player);
354 p.GetWeaponManager().OnMagazineInventoryExit(
this);
359 super.OnWasAttached(parent, slot_id);
365 player.GetWeaponManager().OnMagazineAttach(
this);
371 super.OnWasDetached(parent, slot_id);
378 player.GetWeaponManager().OnMagazineDetach(
this);
384 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
385 float damage = 1 - GetHealthLevelValue(newLevel) + 0.001;
387 int cartridgeCount = GetAmmoCount();
388 for (
int i = 0; i < cartridgeCount; ++i)
389 SetCartridgeDamageAtIndex(i, damage);
392 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
394 super.GetDebugActions(outputList);
396 if (GetAmmoCount() > 0)
407 if (action_id ==
EActions.PRINT_BULLETS)
410 Class.CastTo(magazine,
this);
411 for (
int i = 0; i < magazine.GetAmmoCount(); i++)
415 magazine.GetCartridgeAtIndex(i, damage, className);
416 Debug.Log(
string.Format(
"Bullet: %1, Damage %2", className, damage));
421 return super.OnAction(action_id, player, ctx);
424 override bool CanBeFSwaped()
436 class MagazineStorage : Magazine