DayZ 1.24
Loading...
Searching...
No Matches
WeaponManager.c
Go to the documentation of this file.
2{
4
6
7 protected int m_LastAcknowledgmentID;
8
12 protected int m_PendingWeaponAction;
14
15 protected bool m_canEnd;
16 protected bool m_justStart;
17 protected bool m_InProgress;
18 protected bool m_IsEventSended;
19 protected bool m_WantContinue;
20 protected bool m_InIronSight;
21 protected bool m_InOptic;
22 protected bool m_readyToStart;
24 protected MagazineStorage m_MagazineInHand;
25 protected ActionBase m_ControlAction;
27
28 protected const int FORCE_EJECT_BULLET_TIMEOUT = 2000;
29#ifdef DIAG_DEVELOPER
30 protected int m_BurstOption;
31#endif
32 //Reload
37
38 //Jamming
39 protected float m_NewJamChance;
40 protected bool m_WaitToSyncJamChance;
41
42
44
76 //----------------------------------------------------------------------------
77 // Weapon Action conditions
78 //----------------------------------------------------------------------------
80 {
81 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
82 return false;
83
84 if (m_player.IsLiftWeapon() || !m_player.IsRaised() || wpn.IsDamageDestroyed() || m_player.GetDayZPlayerInventory().IsProcessing() || !m_player.IsWeaponRaiseCompleted() || m_player.IsFighting())
85 return false;
86
87 return true;
88
89 }
90
91
93 {
94 if (!wpn || !mag)
95 return false;
96
97 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
98 return false;
99
100 if (wpn.IsDamageDestroyed())
101 return false;
102
103 //if ( mag.GetHierarchyRootPlayer() && mag.GetHierarchyRootPlayer() != m_player )
104 //return false;
105
106 if (m_player.IsItemsToDelete())
107 return false;
108
109 if (reservationCheck && (m_player.GetInventory().HasInventoryReservation(wpn, null) || m_player.GetInventory().HasInventoryReservation(mag, null)))
110 return false;
111
114
115 mag.GetInventory().GetCurrentInventoryLocation(invLoc);
117
118
119 //magazine is already in weapon
120 if (Class.CastTo(wnp2, invLoc.GetParent()))
121 return false;
122
123 int muzzleIndex = wpn.GetCurrentMuzzle();
124
125 if (wpn.CanAttachMagazine(muzzleIndex, mag))
126 return true;
127
128 return false;
129
130 }
131 //---------------------------------------------------------------------------
132
134 {
135 if (!wpn || !mag)
136 return false;
137
138 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
139 return false;
140
141 if (mag.IsDamageDestroyed() || wpn.IsDamageDestroyed())
142 return false;
143
144 //if ( mag.GetHierarchyRootPlayer() && mag.GetHierarchyRootPlayer() != m_player )
145 //return false;
146
147 if (m_player.IsItemsToDelete())
148 return false;
149
150 if (reservationCheck && (m_player.GetInventory().HasInventoryReservation(wpn, null) || m_player.GetInventory().HasInventoryReservation(mag, null)))
151 return false;
152
153
156
157 mag.GetInventory().GetCurrentInventoryLocation(invLoc);
159
160 //second magazine is already in weapon
161 if (Class.CastTo(wnp2, invLoc.GetParent()))
162 return false;
163
164 int muzzleIndex = wpn.GetCurrentMuzzle();
165
167 if (!Class.CastTo(mag2, wpn.GetMagazine(muzzleIndex)))
168 return false;
169
171 return true;
172
174
176 return true;
177
178 return false;
179 }
180 //----------------------------------------------------------------------------
182 {
183 if (!wpn || !mag)
184 return false;
185
186 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
187 return false;
188
189 if (mag.GetHierarchyParent() != wpn)
190 return false;
191
192 if (m_player.IsItemsToDelete())
193 return false;
194
195 if (reservationCheck && (m_player.GetInventory().HasInventoryReservation(wpn, null) || m_player.GetInventory().HasInventoryReservation(mag, null)))
196 return false;
197
198 return true;
199 }
200 //---------------------------------------------------------------------------
202 {
203 if (!wpn || !mag)
204 return false;
205
206 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
207 return false;
208
209 if (mag.IsDamageDestroyed() || wpn.IsDamageDestroyed())
210 return false;
211
212 if (wpn.IsJammed())
213 return false;
214
215 if (m_player.IsItemsToDelete())
216 return false;
217
218 if (reservationCheck && (m_player.GetInventory().HasInventoryReservation(wpn, null) || m_player.GetInventory().HasInventoryReservation(mag, null)))
219 return false;
220
221 for (int i = 0; i < wpn.GetMuzzleCount(); i++)
222 {
223 if (wpn.CanChamberBullet(i, mag))
224 return true;
225 }
226
227 return false;
228 }
229 //---------------------------------------------------------------------------
231 {
232 if (!wpn)
233 return false;
234
235 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
236 return false;
237
238 if (wpn.IsDamageDestroyed())
239 return false;
240
241 if (m_player.IsItemsToDelete())
242 return false;
243
244 if (reservationCheck && m_player.GetInventory().HasInventoryReservation(wpn, null))
245 return false;
246
247
248 if (!wpn.IsJammed(/*wpn.GetCurrentMuzzle()*/))
249 return false;
250
251 return true;
252 }
253
255 {
256 if (!wpn)
257 return false;
258
259 if (m_player.GetHumanInventory().GetEntityInHands() != wpn)
260 return false;
261
262 if (m_player.IsItemsToDelete())
263 return false;
264
265 if (reservationCheck && m_player.GetInventory().HasInventoryReservation(wpn, null))
266 return false;
267
268 if (!wpn.CanEjectBullet())
269 return false;
270
271 if (wpn.IsJammed(/*wpn.GetCurrentMuzzle()*/))
272 return false;
273
274 return true;
275 }
276
281 //----------------------------------------------------------------------------
283 {
286 if (Weapon_Base.CastTo(weapon, m_player.GetItemInHands()))
287 {
288 weapon.GetInventory().GetCurrentInventoryLocation(ilWeapon);
289 if (m_player.GetInventory().HasInventoryReservation(weapon, ilWeapon))
290 return false;
291 else
292 m_player.GetInventory().AddInventoryReservationEx(weapon, ilWeapon, GameInventory.c_InventoryReservationTimeoutMS);
293 }
294
295 if (invLoc)
296 {
297 if (m_player.GetInventory().HasInventoryReservation(invLoc.GetItem(), invLoc))
298 {
299 m_player.GetInventory().ClearInventoryReservationEx(weapon, ilWeapon);
300 return false;
301 }
302 else
303 m_player.GetInventory().AddInventoryReservationEx(invLoc.GetItem(), invLoc, GameInventory.c_InventoryReservationTimeoutMS);
304 }
305
306 if (mag)
307 {
310
311 if (m_player.GetInventory().HasInventoryReservation(mag, m_TargetInventoryLocation))
312 //if ( !m_player.GetInventory().AddInventoryReservationEx( mag, m_TargetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS) )
313 {
314 m_player.GetInventory().ClearInventoryReservationEx(weapon, ilWeapon);
315 if (invLoc)
316 m_player.GetInventory().ClearInventoryReservationEx(invLoc.GetItem(), invLoc);
317 return false;
318 }
319 else
320 m_player.GetInventory().AddInventoryReservationEx(mag, m_TargetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
321 }
324
325 return true;
326 }
327
328 //----------------------------------------------------------------------------
329 // Weapon Actions
330 //----------------------------------------------------------------------------
335
340
348
353
358
363
365 {
366 if (m_InProgress) m_WantContinue = false;
367 }
368
369 bool Unjam(ActionBase control_action = NULL)
370 {
372 }
373
378
380 {
381 int mi = m_WeaponInHand.GetCurrentMuzzle();
382 if (!m_WeaponInHand.IsChamberFiredOut(mi) && !m_WeaponInHand.IsChamberEmpty(mi))
383 {
384 int actual_time = GetGame().GetTime();
386 return false;
387 }
388 return true;
389 }
390
392 {
393 if (m_WeaponInHand)
394 {
395 int mi = m_WeaponInHand.GetCurrentMuzzle();
396 if (!m_WeaponInHand.IsChamberFiredOut(mi) && !m_WeaponInHand.IsChamberEmpty(mi))
397 {
400 }
401 else
403 }
404 return false;
405 }
406
411
413 {
414 int mi = wpn.GetCurrentMuzzle();
415 if (wpn.IsChamberFiredOut(mi) || wpn.IsJammed() || wpn.IsChamberEmpty(mi))
416 {
417 wpn.ProcessWeaponEvent(new WeaponEventTrigger(m_player));
418 return;
419 }
420
421 if (wpn.JamCheck(0))
422 wpn.ProcessWeaponEvent(new WeaponEventTriggerToJam(m_player));
423 else
424 wpn.ProcessWeaponEvent(new WeaponEventTrigger(m_player));
425 }
426
427#ifdef DIAG_DEVELOPER
428 int GetBurstOption()
429 {
430 return m_BurstOption;
431 }
432
433 void SetBurstOption(int value)
434 {
436 }
437#endif
438 //-------------------------------------------------------------------------------------
439 // Synchronize - initialize from client side
440 //-------------------------------------------------------------------------------------
441
442 //Client
443 private void Synchronize()
444 {
445 if (GetGame().IsClient())
446 {
449
453
454
455 switch (m_PendingWeaponAction)
456 {
458 {
460 break;
461 }
463 {
465 m_PendingInventoryLocation.WriteToContext(ctx);
466 break;
467 }
469 {
470 m_PendingInventoryLocation.WriteToContext(ctx);
471 break;
472 }
474 {
476 break;
477 }
479 {
481 break;
482 }
483 case AT_WPN_UNJAM:
484 {
485 break;
486 }
488 {
489 break;
490 }
491 default:
492 break;
493 }
494 ctx.Send();
495 //if( !m_player.GetDayZPlayerInventory().HasLockedHands() )
496 // m_player.GetDayZPlayerInventory().LockHands();
497 }
498 }
499
500
502 {
504 pCtx.Read(m_NewJamChance);
505 else
506 {
510 {
512 m_readyToStart = true;
514 {
515 if (m_PendingWeaponAction >= 0)
516 {
517 if (!(GetGame().IsServer() && GetGame().IsMultiplayer()))
518 {
520 ItemBase weapon = m_player.GetItemInHands();
521 weapon.GetInventory().GetCurrentInventoryLocation(ilWeapon);
522 m_player.GetInventory().ClearInventoryReservationEx(m_player.GetItemInHands(), ilWeapon);
523
525 m_PendingTargetMagazine.GetInventory().ClearInventoryReservationEx(m_PendingTargetMagazine, m_TargetInventoryLocation);
526
528 m_player.GetInventory().ClearInventoryReservationEx(NULL, m_PendingInventoryLocation);
529 }
534 m_InProgress = false;
535 }
536 }
537 }
538 }
539 }
540
541
542 //Server
544 {
546 int mi;
548 int slotID;
549 bool accepted = false;
551 {
552 if (!ctx.Read(m_PendingWeaponAction))
553 return false;
554
556 return false;
557
559 {
560 GetGame().ClearJuncture(m_player, m_PendingTargetMagazine);
562 }
563 m_InProgress = true;
564 m_IsEventSended = false;
565 Magazine mag = NULL;
566
567 Weapon_Base.CastTo(wpn, m_player.GetItemInHands());
568 if (wpn)
569 mi = wpn.GetCurrentMuzzle();
570
571 switch (m_PendingWeaponAction)
572 {
574 {
575 if (!ctx.Read(mag))
576 break;
577
578 if (!mag || !wpn)
579 break;
580
581 slotID = wpn.GetSlotFromMuzzleIndex(mi);
582 il = new InventoryLocation();
583 il.SetAttachment(wpn, mag, slotID);
584 if (GetGame().AddInventoryJunctureEx(m_player, mag, il, false, 10000))
585 accepted = true;
586
588 break;
589 }
591 {
592 if (!ctx.Read(mag))
593 break;
594
595 il = new InventoryLocation();
596 if (!il.ReadFromContext(ctx))
597 break;
598
599 if (!mag || !wpn)
600 break;
601
602 if (!wpn.GetMagazine(mi))
603 break;
604
605 if (GetGame().AddActionJuncture(m_player, mag, 10000))
606 accepted = true;
609
610 break;
611 }
613 {
614 il = new InventoryLocation();
615 if (!il.ReadFromContext(ctx))
616 break;
617
618 if (!il.IsValid())
619 break;
620
621 if (!wpn)
622 break;
623
624 Magazine det_mag = wpn.GetMagazine(mi);
625 mag = Magazine.Cast(il.GetItem());
626 if (!det_mag || (mag != det_mag))
627 break;
628
629 if (GetGame().AddInventoryJunctureEx(m_player, il.GetItem(), il, true, 10000))
630 accepted = true;
633 break;
634 }
636 {
637 ctx.Read(mag);
638
639 if (!mag)
640 break;
641
642 if (GetGame().AddActionJuncture(m_player, mag, 10000))
643 accepted = true;
645 break;
646 }
648 {
649 ctx.Read(mag);
650
651 if (!mag)
652 break;
653
654 if (GetGame().AddActionJuncture(m_player, mag, 10000))
655 accepted = true;
657 break;
658 }
659 case AT_WPN_UNJAM:
660 {
661 accepted = true;
662 //Unjam();
663 break;
664 }
666 {
667 accepted = true;
668 break;
669 }
671 {
672 accepted = true;
673 break;
674 }
675 default:
676 Error("unknown actionID=" + m_PendingWeaponAction);
677 break;
678 }
680 }
681
682 return accepted;
683 }
684
686 {
687 //if it is controled by action inventory reservation and synchronization provide action itself
688 if (control_action)
689 {
690 m_ControlAction = ActionBase.Cast(control_action);
692 m_InProgress = true;
693 m_IsEventSended = false;
697
698 return true;
699 }
700
701
702 if (GetGame().IsMultiplayer() && GetGame().IsServer())
703 return false;
704
706 return false;
708 return false;
709
711 m_InProgress = true;
712 m_IsEventSended = false;
713
714 if (!GetGame().IsMultiplayer())
715 m_readyToStart = true;
716 else
717 Synchronize();
718
719 return true;
720 }
721
723 {
724 m_WeaponInHand = Weapon_Base.Cast(m_player.GetItemInHands());
725 if (!m_WeaponInHand)
726 {
728 return;
729 }
730 switch (m_PendingWeaponAction)
731 {
733 {
734 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventAttachMagazine(m_player, m_PendingTargetMagazine));
735 break;
736 }
738 {
739 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventSwapMagazine(m_player, m_PendingTargetMagazine, m_PendingInventoryLocation));
740 break;
741 }
743 {
745 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventDetachMagazine(m_player, mag, m_PendingInventoryLocation));
746 break;
747 }
749 {
750 m_WantContinue = false;
751 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventLoad1Bullet(m_player, m_PendingTargetMagazine));
752 break;
753 }
755 {
756 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventLoad1Bullet(m_player, m_PendingTargetMagazine));
757 break;
758 }
760 {
761 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventContinuousLoadBulletEnd(m_player));
762 break;
763 }
764 case AT_WPN_UNJAM:
765 {
766 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventUnjam(m_player, NULL));
767 break;
768 }
770 {
771 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventMechanism(m_player, NULL));
772 break;
773 }
775 {
776 m_player.GetDayZPlayerInventory().PostWeaponEvent(new WeaponEventSetNextMuzzleMode(m_player, NULL));
777 break;
778 }
779 default:
780 m_InProgress = false;
781 Error("unknown actionID=" + m_PendingWeaponAction);
782 }
783 m_IsEventSended = true;
784 m_canEnd = false;
785 }
786
788 {
789 return m_InProgress;
790 }
791
792 void SetRunning(bool value)
793 {
795 }
796
797 void Refresh()
798 {
800 }
801
802 void Update(float deltaT)
803 {
804 if (m_WeaponInHand != m_player.GetItemInHands())
805 {
806 if (m_WeaponInHand)
807 {
808 m_SuitableMagazines.Clear();
810 }
811 m_WeaponInHand = Weapon_Base.Cast(m_player.GetItemInHands());
812 if (m_WeaponInHand)
813 {
815 //SET new magazine
817 m_WeaponInHand.SetSyncJammingChance(0);
818 }
820 }
821
822 if (m_WeaponInHand)
823 {
825 {
827
830 }
831
832 if (!GetGame().IsMultiplayer())
833 m_WeaponInHand.SetSyncJammingChance(m_WeaponInHand.GetChanceToJam());
834 else
835 {
836 if (m_NewJamChance >= 0)
837 {
838 m_WeaponInHand.SetSyncJammingChance(m_NewJamChance);
839 m_NewJamChance = -1;
840 m_WaitToSyncJamChance = false;
841 }
842 if (GetGame().IsServer() && !m_WaitToSyncJamChance)
843 {
846 if (Math.AbsFloat(m_WeaponInHand.GetSyncChanceToJam() - m_WeaponInHand.GetChanceToJam()) > 0.001)
847 {
850 }
851 }
852 }
853
854 if (m_readyToStart)
855 {
857 m_readyToStart = false;
858 return;
859 }
860
862 return;
863
864 if (m_canEnd)
865 {
866 if (m_WeaponInHand.IsIdle())
868 else if (m_justStart)
869 {
870 m_InIronSight = m_player.IsInIronsights();
871 m_InOptic = m_player.IsInOptics();
872
874 {
875 //'RequestResetADSSync' can be called here, if ADS reset is desired
876 m_player.ExitSights();
877 }
878
879 m_justStart = false;
880 }
881
882 }
883 else
884 {
885 m_canEnd = true;
886 m_justStart = true;
887 }
888 }
889 else
890 {
891 if (m_MagazineInHand != m_player.GetItemInHands())
892 {
893 m_MagazineInHand = MagazineStorage.Cast(m_player.GetItemInHands());
896 }
897
898
899 }
900 }
901
903 {
904 if (!m_InProgress)
905 return;
906
907 if (!m_ControlAction)
908 {
909 if (GetGame().IsServer() && GetGame().IsMultiplayer())
910 {
912 GetGame().ClearJuncture(m_player, m_PendingTargetMagazine);
913 }
914 else
915 {
917 il.SetHands(m_player, m_player.GetItemInHands());
918 m_player.GetInventory().ClearInventoryReservationEx(m_player.GetItemInHands(), il);
919
921 m_player.GetInventory().ClearInventoryReservationEx(m_PendingTargetMagazine, m_TargetInventoryLocation);
922
924 m_player.GetInventory().ClearInventoryReservationEx(m_PendingInventoryLocation.GetItem(), m_PendingInventoryLocation);
925 }
926 }
927
934 //m_WeaponInHand = NULL;
935 m_InProgress = false;
936 m_readyToStart = false;
937 m_WantContinue = true;
938
939 }
940
942 {
943 if (m_WeaponInHand)
944 {
945 if (delay == 0)
948 }
949 }
950
952 {
953 if (m_WeaponInHand)
954 {
956
957 if (state)
958 {
959 HumanCommandWeapons hcw = m_player.GetCommandModifier_Weapons();
960 if (hcw)
961 hcw.SetInitState(state.m_animState);
962 }
963 }
964 }
965
967 {
968 return m_WantContinue;
969 }
970
972 {
973 for (int i = 0; i < m_SuitableMagazines.Count(); i++)
974 {
975 if (!m_SuitableMagazines.Get(i) || m_SuitableMagazines.Get(i).IsRuined())
976 {
977 m_SuitableMagazines.Remove(i);
978 i--;
979 continue;
980 }
981 if (m_SuitableMagazines.Get(i).GetAmmoCount() > 0)
982 return m_SuitableMagazines.Get(i);
983 }
984
985 return null;
986 }
987
989 {
990 for (int i = startIdx; i < m_SuitableMagazines.Count(); i++)
991 {
992 if (m_SuitableMagazines.Get(i).GetAmmoCount() > 0)
993 {
994 startIdx = i;
995 return m_SuitableMagazines.Get(i);
996 }
997 }
998 return null;
999 }
1000
1002 {
1003 if (mag)
1004 {
1005 Weapon_Base weapon = Weapon_Base.Cast(mag.GetHierarchyParent());
1006
1007 if (weapon)
1008 return;
1009 }
1010
1011 int i;
1012 MagazineStorage sMag = MagazineStorage.Cast(mag);
1013 if (sMag)
1014 {
1015 for (i = 0; i < m_MagazineStorageInInventory.Count(); i++)
1016 {
1017 MagazineStorage s_mag_i = m_MagazineStorageInInventory[i];
1018 if (!s_mag_i)
1019 {
1020 m_MagazineStorageInInventory.RemoveOrdered(i);
1021 i--;
1022 continue;
1023 }
1024
1026 break;
1027 }
1029
1030 SetSutableMagazines(); //TODO optimalize
1031 return;
1032 }
1033
1034 if (mag)
1035 {
1036
1037 for (i = 0; i < m_MagazinePilesInInventory.Count(); i++)
1038 {
1040 if (!mag_i)
1041 {
1042 m_MagazinePilesInInventory.RemoveOrdered(i);
1043 i--;
1044 continue;
1045 }
1046
1047
1049 break;
1050 }
1051 m_MagazinePilesInInventory.InsertAt(mag, i);
1052 SetSutableMagazines(); //TODO optimalize
1053 }
1054
1055 }
1056
1058 {
1059 m_SuitableMagazines.RemoveItem(mag);
1060
1061 MagazineStorage sMag = MagazineStorage.Cast(mag);
1062 if (sMag)
1063 {
1065 return;
1066 }
1067
1068 if (mag)
1069 m_MagazinePilesInInventory.RemoveItem(mag);
1070 }
1071
1076
1081
1083 {
1084 return mag1.GetAmmoCount() - mag2.GetAmmoCount();
1085 }
1086
1088 {
1091 int low_mag1, high_mag1;
1092 int low_mag2, high_mag2;
1093 int i, j;
1094
1095 for (i = 0; i < m_MagazineStorageInInventory.Count(); i++)
1096 {
1097 MagazineStorage mag = m_MagazineStorageInInventory.Get(i);
1098 mag.GetNetworkID(low_mag1, high_mag1);
1099 for (j = 0; j < magazines.Count(); j++)
1100 {
1101 magazines.Get(j).GetNetworkID(low_mag2, high_mag2);
1102 if (low_mag1 > low_mag2)
1103 break;
1104 else if (low_mag1 == low_mag2)
1105 {
1106 if (high_mag1 > high_mag2)
1107 break;
1108 }
1109 }
1110 magazines.InsertAt(mag, j);
1111 }
1112
1115
1116 for (i = 0; i < m_MagazinePilesInInventory.Count(); i++)
1117 {
1119 pile.GetNetworkID(low_mag1, high_mag1);
1120 for (j = 0; j < magazines_piles.Count(); j++)
1121 {
1122 magazines_piles.Get(j).GetNetworkID(low_mag2, high_mag2);
1123 if (low_mag1 > low_mag2)
1124 break;
1125 else if (low_mag1 == low_mag2)
1126 {
1127 if (high_mag1 > high_mag2)
1128 break;
1129 }
1130 }
1131 magazines_piles.InsertAt(pile, j);
1132 }
1133
1136
1138 }
1139
1141 {
1142 m_SuitableMagazines.Clear();
1143 int i;
1144
1145 if (m_WeaponInHand)
1146 {
1147 int mi = m_WeaponInHand.GetCurrentMuzzle();
1148
1149 for (i = 0; i < m_MagazineStorageInInventory.Count(); i++)
1150 {
1151 MagazineStorage s_mag = m_MagazineStorageInInventory[i];
1152
1153 if (!s_mag)
1154 {
1155 m_MagazineStorageInInventory.RemoveOrdered(i);
1156 i--;
1157 continue;
1158 }
1159
1160 if (m_WeaponInHand.TestAttachMagazine(mi, s_mag, false, true))
1161 m_SuitableMagazines.Insert(s_mag);
1162 }
1163
1164 for (i = 0; i < m_MagazinePilesInInventory.Count(); i++)
1165 {
1167 if (!mag)
1168 {
1169 m_MagazinePilesInInventory.RemoveOrdered(i);
1170 i--;
1171 continue;
1172 }
1173
1174 if (m_WeaponInHand.CanChamberFromMag(mi, mag))
1175 m_SuitableMagazines.Insert(mag);
1176 }
1177 //TODO m_MagazineStorageInInventory and m_MagazinePilesInInventory always sort
1178 }
1179 else if (m_MagazineInHand)
1180 {
1181 for (i = 0; i < m_MagazinePilesInInventory.Count(); i++)
1182 {
1184 if (!m_mag)
1185 {
1186 m_MagazinePilesInInventory.RemoveOrdered(i);
1187 i--;
1188 continue;
1189 }
1190 if (m_MagazineInHand.IsCompatiableAmmo(m_mag))
1191 m_SuitableMagazines.Insert(m_mag);
1192 }
1193 }
1194 else
1196
1197 }
1198
1200 {
1201 if (m_WeaponInHand)
1202 m_WeaponInHand.ResetBurstCount();
1203 }
1204
1206 {
1207 if (m_WeaponInHand)
1208 {
1209 int mi = m_WeaponInHand.GetCurrentMuzzle();
1210 return m_WeaponInHand.GetCurrentModeName(mi);
1211 }
1212 return "";
1213 }
1214
1216 {
1217 int muzzleIndex = wpn.GetCurrentMuzzle();
1218 Magazine old_mag = Magazine.Cast(wpn.GetMagazine(muzzleIndex));
1220
1221 if (old_mag)
1222 {
1224 if (result)
1225 {
1226 new_mag.GetInventory().GetCurrentInventoryLocation(new_il);
1227 new_il.SetItem(old_mag);
1228 }
1229 else
1230 {
1232 float dir[4];
1233 if (!result)
1234 new_il.SetGroundEx(old_mag, m_player.GetPosition(), dir);
1235 }
1236 }
1237 return true;
1238 }
1239}
const int INPUT_UDT_WEAPON_ACTION
Definition _constants.c:7
const int AT_WPN_DETACH_MAGAZINE
Definition _constants.c:12
const int AT_WPN_LOAD_MULTI_BULLETS_END
Definition _constants.c:17
const int AT_WPN_ATTACH_MAGAZINE
Definition _constants.c:10
const int AT_WPN_LOAD_BULLET
Definition _constants.c:13
const int AT_WPN_UNJAM
Definition _constants.c:14
const int AT_WPN_SWAP_MAGAZINE
Definition _constants.c:11
const int AT_WPN_LOAD_MULTI_BULLETS_START
Definition _constants.c:16
const int AT_WPN_EJECT_BULLET
Definition _constants.c:15
const int AT_WPN_SET_NEXT_MUZZLE_MODE
Definition _constants.c:18
Super root of all classes in Enforce script.
Definition EnScript.c:11
static void SendWeaponJamChance(DayZPlayer pPlayer, float jamChance)
static const int SJ_WEAPON_ACTION_ACK_REJECT
static const int SJ_WEAPON_ACTION_ACK_ACCEPT
static const int SJ_WEAPON_SET_JAMMING_CHANCE
static void SendWeaponActionAcknowledgment(DayZPlayer pPlayer, int AckID, bool accept)
script counterpart to engine's class Inventory
Definition Inventory.c:79
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:687
static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
Definition Inventory.c:645
InventoryLocation.
provides access to slot configuration
Definition EnMath.c:7
proto static native bool CanStoreInputUserData()
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
override float GetChanceToJam()
bool EjectBulletVerified(ActionBase control_action=NULL)
string GetCurrentModeName()
void SetSutableMagazines()
PlayerBase m_player
bool CanUnjam(Weapon_Base wpn, bool reservationCheck=true)
void DelayedRefreshAnimationState(int delay)
bool CanEjectBulletVerified()
bool CanLoadBullet(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool CanAttachMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
ActionBase m_ControlAction
int m_PendingWeaponActionAcknowledgmentID
ref array< Magazine > m_MagazinePilesInInventory
bool AttachMagazine(Magazine mag, ActionBase control_action=NULL)
int m_ForceEjectBulletTimestamp
bool LoadBullet(Magazine mag, ActionBase control_action=NULL)
bool CanEjectBullet(Weapon_Base wpn, bool reservationCheck=true)
bool LoadMultiBullet(Magazine mag, ActionBase control_action=NULL)
bool PrepareInventoryLocationForMagazineSwap(notnull Weapon_Base wpn, notnull Magazine new_mag, out InventoryLocation new_il)
Magazine m_PendingTargetMagazine
bool DetachMagazine(InventoryLocation invLoc, ActionBase control_action=NULL)
void LoadMultiBulletStop()
bool SetNextMuzzleMode()
int m_LastAcknowledgmentID
void SortMagazineAfterLoad()
bool m_WaitToSyncJamChance
ref array< Magazine > m_SuitableMagazines
void OnWeaponActionEnd()
void RefreshAnimationState()
bool CanSwapMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
Magazine GetNextPreparedMagazine(out int startIdx)
Weapon_Base m_WeaponInHand
bool SwapMagazine(Magazine mag, ActionBase control_action=NULL)
const float MAX_DROP_MAGAZINE_DISTANCE_SQ
void Update(float deltaT)
const int FORCE_EJECT_BULLET_TIMEOUT
bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
ref array< MagazineStorage > m_MagazineStorageInInventory
bool CanFire(Weapon_Base wpn)
bool CanDetachMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
void OnSyncJuncture(int pJunctureID, ParamsReadContext pCtx)
void SetEjectBulletTryTimestamp()
Magazine m_PreparedMagazine
int CompareMagazinesSuitability(Magazine mag1, Magazine mag2)
bool Unjam(ActionBase control_action=NULL)
void SetRunning(bool value)
void WeaponManager(PlayerBase player)
ref InventoryLocation m_PendingInventoryLocation
bool SwapMagazineEx(Magazine mag, InventoryLocation invLoc, ActionBase control_action=NULL)
void Fire(Weapon_Base wpn)
ref InventoryLocation m_TargetInventoryLocation
bool EjectBullet(ActionBase control_action=NULL)
int m_PendingWeaponAction
bool StartAction(int action, Magazine mag, InventoryLocation il, ActionBase control_action=NULL)
MagazineStorage m_MagazineInHand
Magazine GetPreparedMagazine()
void OnMagazineDetach(Magazine mag)
int m_AnimationRefreshCooldown
void OnMagazineAttach(Magazine mag)
void OnMagazineInventoryExit(Magazine mag)
void OnMagazineInventoryEnter(Magazine mag)
void StartPendingAction()
bool InventoryReservation(Magazine mag, InventoryLocation invLoc)
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition Crossbow.c:27
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float AbsFloat(float f)
Returns absolute value.