25 ProjectileType m_ProjectileType;
27 void AmmoData(
string init_type )
41 ref array<string> m_CompatiableAmmo;
42 ref array<float> m_ChanceToJam;
43 protected float m_ManipulationDamage;
47 m_ChanceToJam =
new array<float>;
48 InitReliability(m_ChanceToJam);
49 m_ManipulationDamage = ConfigGetFloat(
"manipulationDamage");
50 m_CompatiableAmmo =
new array<string>;
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()
181 return ( GetAmmoCount() > 1 );
186 bool InitReliability(out array<float> reliability_array)
188 if (
GetGame().ConfigIsExisting(
"cfgMagazines " +
GetType() +
" Reliability ChanceToJam"))
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();
231 override void SplitItem(PlayerBase player)
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)
277 WeightDebugData data = WeightDebug.GetWeightDebug(
this);
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)
330 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
333 Weapon_Base wpn = Weapon_Base.Cast(parent);
336 return player.GetWeaponManager().CanDetachMagazine(wpn,
this);
339 return super.CanDetachAttachment(parent);
344 super.OnInventoryEnter(player);
346 PlayerBase p = PlayerBase.Cast(player);
347 p.GetWeaponManager().OnMagazineInventoryEnter(
this);
352 super.OnInventoryExit(player);
354 PlayerBase p = PlayerBase.Cast(player);
355 p.GetWeaponManager().OnMagazineInventoryExit(
this);
360 super.OnWasAttached(parent, slot_id);
362 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
363 Weapon_Base wpn = Weapon_Base.Cast(parent);
366 player.GetWeaponManager().OnMagazineAttach(
this);
372 super.OnWasDetached(parent, slot_id);
374 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
375 Weapon_Base wpn = Weapon_Base.Cast(parent);
379 player.GetWeaponManager().OnMagazineDetach(
this);
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 super.GetDebugActions(outputList);
397 if (GetAmmoCount() > 0)
408 if (action_id ==
EActions.PRINT_BULLETS)
411 Class.CastTo(magazine,
this);
412 for (
int i = 0; i < magazine.GetAmmoCount(); i++)
416 magazine.GetCartridgeAtIndex(i, damage, className);
417 Debug.Log(
string.Format(
"Bullet: %1, Damage %2", className, damage));
422 return super.OnAction(action_id, player, ctx);
425 override bool CanBeFSwaped()
427 Weapon_Base wpn = Weapon_Base.Cast(GetHierarchyParent());
437class MagazineStorage : Magazine
Param4< int, int, string, int > TSelectableActionInfoWithColor
eBleedingSourceType GetType()
void AddAction(typename actionName)
const int ECE_IN_INVENTORY
class GP5GasMask extends MaskBase ItemBase
void SplitItem(PlayerBase player)
void SplitItemToInventoryLocation(notnull InventoryLocation dst)
float GetWeightSpecialized(bool forceRecalc=false)
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
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)
override bool CanBeSplit()
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 GetDebugActions(out TSelectableActionInfoArrayEx outputList)
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
override void OnWasAttached(EntityAI parent, int slot_id)
enum CartridgeType Tracer
override void OnWasDetached(EntityAI parent, int slot_id)
proto native bool ConfigIsExisting(string path)
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto native void ConfigGetFloatArray(string path, out TFloatArray values)
Get array of floats from config on path.
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
override void SetActions()
void SetCalcDetails(string details)
Serializer ParamsReadContext
proto native CGame GetGame()
const int SAT_DEBUG_ACTION