3 const float MAX_DROP_MAGAZINE_DISTANCE_SQ = 4;
30 protected int m_BurstOption;
81 if(
m_player.GetEntityInHands() != wpn )
87 return !wpn.IsCoolDown();
96 if (
m_player.GetEntityInHands() != wpn )
99 if ( wpn.IsDamageDestroyed())
108 if ( reservationCheck && (
m_player.GetInventory().HasInventoryReservation(wpn, null) ||
m_player.GetInventory().HasInventoryReservation(mag, null)))
114 mag.GetInventory().GetCurrentInventoryLocation(invLoc);
119 if (
Class.CastTo(wnp2, invLoc.GetParent()) )
122 int muzzleIndex = wpn.GetCurrentMuzzle();
124 if (wpn.CanAttachMagazine(muzzleIndex, mag))
137 if (
m_player.GetEntityInHands() != wpn )
140 if ( mag.IsDamageDestroyed() || wpn.IsDamageDestroyed())
149 if ( reservationCheck && (
m_player.GetInventory().HasInventoryReservation(wpn, null) ||
m_player.GetInventory().HasInventoryReservation(mag, null)))
156 mag.GetInventory().GetCurrentInventoryLocation(invLoc);
160 if(
Class.CastTo(wnp2, invLoc.GetParent()) )
163 int muzzleIndex = wpn.GetCurrentMuzzle();
166 if( !
Class.CastTo(mag2, wpn.GetMagazine(muzzleIndex)) )
185 if (
m_player.GetEntityInHands() != wpn )
188 if ( mag.GetHierarchyParent() != wpn )
194 if ( reservationCheck && (
m_player.GetInventory().HasInventoryReservation(wpn, null) ||
m_player.GetInventory().HasInventoryReservation(mag, null)))
205 if (
m_player.GetEntityInHands() != wpn)
208 if (mag.IsDamageDestroyed() || wpn.IsDamageDestroyed())
217 if (reservationCheck && (
m_player.GetInventory().HasInventoryReservation(wpn, null) ||
m_player.GetInventory().HasInventoryReservation(mag, null)))
220 for (
int i = 0; i < wpn.GetMuzzleCount(); i++)
222 if (wpn.CanChamberBullet(i, mag))
236 if (
m_player.GetEntityInHands() != wpn)
239 if (mag.IsDamageDestroyed() || wpn.IsDamageDestroyed())
248 if (reservationCheck && (
m_player.GetInventory().HasInventoryReservation(wpn, null) ||
m_player.GetInventory().HasInventoryReservation(mag, null)))
252 bool fireout =
false;
253 for (
int i = 0; i < wpn.GetMuzzleCount(); i++)
258 if (wpn.CanChamberBullet(i, mag) )
265 if (wpn.HasInternalMagazine(i))
267 if ((wpn.GetInternalMagazineCartridgeCount(i)) < wpn.GetInternalMagazineMaxCartridgeCount(i))
273 if (wpn.IsChamberFiredOut(i))
291 if(
m_player.GetEntityInHands() != wpn)
294 if( wpn.IsDamageDestroyed())
300 if ( reservationCheck &&
m_player.GetInventory().HasInventoryReservation(wpn, null))
304 if( !wpn.IsJammed() )
315 if(
m_player.GetEntityInHands() != wpn)
321 if( reservationCheck &&
m_player.GetInventory().HasInventoryReservation(wpn, null))
324 if( !wpn.CanEjectBullet() )
345 weapon.GetInventory().GetCurrentInventoryLocation(ilWeapon);
411 if (PrepareInventoryLocationForMagazineSwap(
m_WeaponInHand, mag, il) )
440 return StartAction(
AT_WPN_UNJAM, NULL, NULL, control_action);
453 int actual_time =
g_Game.GetTime();
487 int mi = wpn.GetCurrentMuzzle();
488 if ( wpn.IsChamberFiredOut(mi) || wpn.IsJammed() || wpn.IsChamberEmpty(mi) )
490 wpn.ProcessWeaponEvent(
new WeaponEventTrigger(
m_player));
496 wpn.ProcessWeaponEvent(
new WeaponEventTriggerToJam(
m_player));
500 wpn.ProcessWeaponEvent(
new WeaponEventTrigger(
m_player));
507 return m_BurstOption;
510 void SetBurstOption(
int value)
512 m_BurstOption = value;
525 ScriptInputUserData ctx =
new ScriptInputUserData;
581 if (pJunctureID == DayZPlayerSyncJunctures.SJ_WEAPON_SET_JAMMING_CHANCE )
587 int AcknowledgmentID;
588 pCtx.Read(AcknowledgmentID);
591 if (pJunctureID == DayZPlayerSyncJunctures.SJ_WEAPON_ACTION_ACK_ACCEPT)
595 else if (pJunctureID == DayZPlayerSyncJunctures.SJ_WEAPON_ACTION_ACK_REJECT)
601 InventoryLocation ilWeapon =
new InventoryLocation();
603 GameInventory playerInventory =
m_player.GetInventory();
604 weapon.GetInventory().GetCurrentInventoryLocation(ilWeapon);
634 InventoryLocation il;
636 bool accepted =
false;
654 Weapon_Base.CastTo( wpn,
m_player.GetItemInHands() );
656 mi = wpn.GetCurrentMuzzle();
662 if ( !ctx.Read(mag) )
668 slotID = wpn.GetSlotFromMuzzleIndex(mi);
669 il =
new InventoryLocation();
670 il.SetAttachment(wpn,mag,slotID);
671 if(
g_Game.AddInventoryJunctureEx(
m_player, mag, il,
false, 10000) )
679 if ( !ctx.Read(mag) )
682 il =
new InventoryLocation();
683 if (!il.ReadFromContext(ctx))
689 if ( !wpn.GetMagazine(mi) )
701 il =
new InventoryLocation();
702 if ( !il.ReadFromContext(ctx) )
711 Magazine det_mag = wpn.GetMagazine(mi);
712 mag = Magazine.Cast(il.GetItem());
713 if ( !det_mag || ( mag != det_mag) )
716 if (
g_Game.AddInventoryJunctureEx(
m_player, il.GetItem(), il,
true, 10000))
772 bool StartAction(
int action, Magazine mag, InventoryLocation il, ActionBase control_action = NULL)
783 StartPendingAction();
792 if ( !ScriptInputUserData.CanStoreInputUserData() )
801 if ( !
g_Game.IsMultiplayer() )
809 void StartPendingAction()
848 m_player.GetDayZPlayerInventory().PostWeaponEvent(
new WeaponEventContinuousLoadBulletEnd(
m_player) );
853 m_player.GetDayZPlayerInventory().PostWeaponEvent(
new WeaponEventUnjam(
m_player, NULL) );
858 m_player.GetDayZPlayerInventory().PostWeaponEvent(
new WeaponEventMechanism(
m_player, NULL) );
863 m_player.GetDayZPlayerInventory().PostWeaponEvent(
new WeaponEventSetNextMuzzleMode(
m_player, NULL) );
879 void SetRunning(
bool value)
889 void Update(
float deltaT )
903 SetSutableMagazines();
917 RefreshAnimationState();
921 if (!
g_Game.IsMultiplayer())
935 float actual_chance_to_jam;
947 StartPendingAction();
989 SetSutableMagazines();
997 void OnWeaponActionEnd()
1013 InventoryLocation il =
new InventoryLocation();
1015 GameInventory playerInventory =
m_player.GetInventory();
1016 il.SetHands(
m_player, itemInHands);
1044 void DelayedRefreshAnimationState(
int delay)
1050 RefreshAnimationState();
1056 void RefreshAnimationState()
1064 HumanCommandWeapons hcw =
m_player.GetCommandModifier_Weapons();
1067 hcw.SetInitState(state.m_animState);
1078 Magazine GetPreparedMagazine()
1084 if (!mag || mag.IsRuined() || (mag.GetHierarchyParent() && mag.GetHierarchyParent().IsWeapon()) )
1091 if(!mag.GetHierarchyParent() || mag.GetHierarchyParent().GetInventory().AreChildrenAccessible())
1093 if (mag.GetAmmoCount() > 0)
1101 Magazine GetNextPreparedMagazine( out
int startIdx )
1105 for (
int i = startIdx; i < count; ++i)
1108 if (mag && mag.GetAmmoCount() > 0 && (!mag.GetHierarchyParent() || mag.GetHierarchyParent().GetInventory().AreChildrenAccessible()))
1117 void OnMagazineInventoryEnter(Magazine mag)
1121 Weapon_Base weapon = Weapon_Base.Cast(mag.GetHierarchyParent());
1128 MagazineStorage sMag = MagazineStorage.Cast(mag);
1141 if(CompareMagazinesSuitability(s_mag_i,sMag)<0)
1146 SetSutableMagazines();
1164 if(CompareMagazinesSuitability(mag_i,mag)<0)
1170 SetSutableMagazines();
1175 void OnMagazineInventoryExit(Magazine mag)
1179 MagazineStorage sMag = MagazineStorage.Cast(mag);
1192 void OnMagazineAttach(Magazine mag)
1194 OnMagazineInventoryExit(mag);
1197 void OnMagazineDetach(Magazine mag)
1199 OnMagazineInventoryEnter(mag);
1202 int CompareMagazinesSuitability( Magazine mag1, Magazine mag2 )
1204 return mag1.GetAmmoCount() - mag2.GetAmmoCount();
1207 void SortMagazineAfterLoad()
1209 array<MagazineStorage> magazines =
new array<MagazineStorage>;
1210 array<Magazine> magazines_piles =
new array<Magazine>;
1211 int low_mag1, high_mag1;
1212 int low_mag2, high_mag2;
1218 mag.GetNetworkID(low_mag1,high_mag1);
1219 for( j = 0; j < magazines.Count(); j++)
1221 magazines.Get(j).GetNetworkID(low_mag2,high_mag2);
1222 if(low_mag1 > low_mag2)
1226 else if (low_mag1 == low_mag2)
1228 if( high_mag1 > high_mag2 )
1234 magazines.InsertAt(mag,j);
1243 pile.GetNetworkID(low_mag1,high_mag1);
1244 for( j = 0; j < magazines_piles.Count(); j++)
1246 magazines_piles.Get(j).GetNetworkID(low_mag2,high_mag2);
1247 if(low_mag1 > low_mag2)
1251 else if (low_mag1 == low_mag2)
1253 if( high_mag1 > high_mag2 )
1259 magazines_piles.InsertAt(pile,j);
1265 SetSutableMagazines();
1268 void SetSutableMagazines()
1335 string GetCurrentModeName()
1345 bool PrepareInventoryLocationForMagazineSwap( notnull Weapon_Base wpn, notnull Magazine new_mag, out InventoryLocation new_il )
1347 int muzzleIndex = wpn.GetCurrentMuzzle();
1348 Magazine old_mag = Magazine.Cast(wpn.GetMagazine(muzzleIndex));
1349 InventoryLocation temp =
new InventoryLocation();
1353 bool result = GameInventory.CanSwapEntitiesEx(new_mag, old_mag);
1356 new_mag.GetInventory().GetCurrentInventoryLocation(new_il);
1357 new_il.SetItem(old_mag);
1361 result = GameInventory.CanForceSwapEntitiesEx(new_mag, null, old_mag, new_il);
1365 new_il.SetGroundEx( old_mag,
m_player.GetPosition(), dir);