25 ProjectileType m_ProjectileType;
27 void AmmoData(
string init_type )
32 m_CartridgeType =
GetGame().ConfigGetInt(
"CfgMagazines " + init_type +
" iconCartridge" );
33 m_ProjectileType =
GetGame().ConfigGetInt(
"CfgMagazines " + init_type +
" iconType" );
43 protected float m_ManipulationDamage;
48 InitReliability(m_ChanceToJam);
49 m_ManipulationDamage = ConfigGetFloat(
"manipulationDamage");
51 ConfigGetTextArray(
"ammoItems", m_CompatiableAmmo);
52 if ( !
GetGame().IsDedicatedServer() )
57 string classname = ClassName();
58 if ( !m_AmmoData.Contains(classname) )
60 ref AmmoData new_data =
new AmmoData( classname );
61 if ( new_data.m_IsValid )
62 m_AmmoData.Insert( classname,
new AmmoData( classname ) );
68 proto native
int GetAmmoCount();
70 proto native
void ServerSetAmmoCount(
int ammoCount);
71 proto native
void LocalSetAmmoCount(
int ammoCount);
79 proto
bool LocalAcquireCartridge(out
float dmg, out
string cartTypeName);
80 proto
bool ServerAcquireCartridge(out
float dmg, out
string cartTypeName);
87 proto native
bool LocalStoreCartridge(
float ammoDamage,
string cartTypeName);
88 proto native
bool ServerStoreCartridge(
float ammoDamage,
string cartTypeName);
97 proto
bool GetCartridgeAtIndex(
int cartIndex, out
float dmg, out
string cartTypeName);
106 proto
bool SetCartridgeAtIndex(
int cartIndex, out
float dmg, out
string cartTypeName);
114 proto
bool SetCartridgeDamageAtIndex(
int cartIndex,
float dmg);
117 static AmmoData GetAmmoData(
string classname )
121 if ( !m_AmmoData.Contains(classname) )
123 ref AmmoData new_data =
new AmmoData( classname );
124 if ( new_data.m_IsValid )
125 m_AmmoData.Insert( classname,
new AmmoData( classname ) );
130 return m_AmmoData.Get( classname );
134 bool IsCompatiableAmmo(
ItemBase ammo )
136 if ( m_CompatiableAmmo && ammo )
137 return ( m_CompatiableAmmo.Find( ammo.GetType() ) > -1 );
142 bool CanAddCartridges(
int count)
144 int spc_avail = GetAmmoMax() - GetAmmoCount();
145 return count <= spc_avail;
149 void ServerAddAmmoCount(
int ammoCount)
151 ServerSetAmmoCount(GetAmmoCount() + ammoCount);
153 void LocalAddAmmoCount(
int ammoCount)
155 LocalSetAmmoCount(GetAmmoCount() + ammoCount);
163 void ServerSetAmmoMax()
165 ServerSetAmmoCount( GetAmmoMax() );
167 void LocalSetAmmoMax()
169 LocalSetAmmoCount( GetAmmoMax() );
172 override bool IsMagazine()
178 override bool CanBeSplit()
181 return ( GetAmmoCount() > 1 );
186 bool InitReliability(out
array<float> reliability_array)
188 if (
GetGame().ConfigIsExisting(
"cfgMagazines " +
GetType() +
" Reliability ChanceToJam"))
190 GetGame().ConfigGetFloatArray(
"cfgMagazines " +
GetType() +
" Reliability ChanceToJam",reliability_array);
196 float GetChanceToJam()
198 int level = GetHealthLevel();
200 if (level >= 0 && level < m_ChanceToJam.Count())
201 return m_ChanceToJam[level];
214 MiscGameplayFunctions.TransferItemProperties(dst.GetItem(), new_pile);
216 new_pile.ServerSetAmmoCount(0);
217 int quantity = GetAmmoCount();
219 for (
int i = 0; i <
Math.Floor( quantity * 0.5 ); ++i)
222 string cartrige_name;
223 ServerAcquireCartridge(damage, cartrige_name);
224 new_pile.ServerStoreCartridge(damage, cartrige_name);
226 new_pile.SetSynchDirty();
237 Magazine new_pile = Magazine.Cast( player.CreateCopyOfItemInInventoryOrGround(
this ) );
240 new_pile.ServerSetAmmoCount(0);
241 int quantity = this.GetAmmoCount();
243 for (
int i = 0; i <
Math.Floor( quantity / 2 ); i++)
246 string cartrige_name;
247 ServerAcquireCartridge(damage, cartrige_name);
248 new_pile.ServerStoreCartridge(damage, cartrige_name);
250 new_pile.SetSynchDirty();
255 void ApplyManipulationDamage()
257 AddHealth(
"",
"Health",-m_ManipulationDamage);
262 if ( GetAmmoCount() == GetAmmoMax() )
275 if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
278 data.SetCalcDetails(
"TMAG: ("+GetAmmoCount()+
"(Ammo count) * " + ConfigGetFloat(
"weightPerQuantityUnit")+
"(weightPerQuantityUnit)) + " + GetConfigWeightModifiedDebugText());
281 return GetConfigWeightModified() + (GetAmmoCount() * ConfigGetFloat(
"weightPerQuantityUnit"));
286 Magazine other_magazine = Magazine.Cast(other_item);
287 int free_space = GetAmmoMax() - GetAmmoCount();
289 return free_space >= other_magazine.GetAmmoCount();
297 if ( other_item.GetType() !=
GetType() )
300 Magazine other_magazine;
301 if (
Class.CastTo(other_magazine, other_item) )
304 int this_free_space = GetAmmoMax() - GetAmmoCount();
305 int numberOfTransferredBullets = 0;
306 int currentAmount = GetAmmoCount();
308 for (
int i = 0; i < this_free_space && other_magazine.GetAmmoCount() > 0 ; i++)
311 string cartrige_name;
312 other_magazine.ServerAcquireCartridge(damage, cartrige_name);
313 if (ServerStoreCartridge(damage, cartrige_name))
314 ++numberOfTransferredBullets;
319 float resultingHealth = (currentAmount * GetHealth() + numberOfTransferredBullets * other_magazine.GetHealth()) / GetAmmoCount();
320 SetHealth(
"",
"", resultingHealth);
323 other_magazine.SetSynchDirty();
328 override bool CanDetachAttachment(
EntityAI parent)
336 return player.GetWeaponManager().CanDetachMagazine(wpn,
this);
339 return super.CanDetachAttachment(parent);
344 super.OnInventoryEnter(player);
347 p.GetWeaponManager().OnMagazineInventoryEnter(
this);
352 super.OnInventoryExit(player);
355 p.GetWeaponManager().OnMagazineInventoryExit(
this);
358 override void OnWasAttached(
EntityAI parent,
int slot_id )
360 super.OnWasAttached(parent, slot_id);
366 player.GetWeaponManager().OnMagazineAttach(
this);
372 super.OnWasDetached(parent, slot_id);
379 player.GetWeaponManager().OnMagazineDetach(
this);
385 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
386 float damage = 1 - GetHealthLevelValue(newLevel) + 0.001;
388 int cartridgeCount = GetAmmoCount();
389 for (
int i = 0; i < cartridgeCount; ++i)
390 SetCartridgeDamageAtIndex(i, damage);
393 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
395 if (GetAmmoCount() > 0)
402 super.GetDebugActions(outputList);
409 if (action_id ==
EActions.PRINT_BULLETS)
412 Class.CastTo(magazine,
this);
413 for (
int i = 0; i < magazine.GetAmmoCount(); i++)
417 magazine.GetCartridgeAtIndex(i, damage, className);
418 Debug.Log(
string.Format(
"Bullet: %1, Damage %2", className, damage));
423 return super.OnAction(action_id, player, ctx);
426 override bool CanBeFSwaped()
438class MagazineStorage : Magazine
Param4< int, int, string, int > TSelectableActionInfoWithColor
eBleedingSourceType GetType()
void AddAction(typename actionName)
const int ECE_IN_INVENTORY
Super root of all classes in Enforce script.
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:
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
proto native CGame GetGame()
const int SAT_DEBUG_ACTION
void SplitItem(PlayerBase player)
void SplitItemToInventoryLocation(notnull InventoryLocation dst)
float GetWeightSpecialized(bool forceRecalc=false)
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.
void OnCombine(ItemBase other_item)
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
bool IsCombineAll(ItemBase other_item, bool use_stack_max=false)
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
enum CartridgeType Tracer
override void OnWasDetached(EntityAI parent, int slot_id)