DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
DayZPlayerInventory.c
Go to the documentation of this file.
1//Post event containers
3{
5 bool ReserveInventory(HumanInventory inventory){return true;}
7}
8
9
11{
14
16 {
17 m_mode = mode;
18 m_src = src;
19 m_dst = dst;
20 }
21
22 override bool ReserveInventory(HumanInventory inventory)
23 {
25 {
26 return false;
27 }
28 return true;
29 }
30
32 {
34 }
35}
36
38{
43
44 void DeferredSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
45 {
46 m_mode = mode;
47 m_item1 = item1;
48 m_item2 = item2;
49 m_dst1 = dst1;
50 m_dst2 = dst2;
51 }
52
53 override bool ReserveInventory(HumanInventory inventory)
54 {
56 {
57 return false;
58 }
60 {
62 return false;
63 }
64 return true;
65 }
66
68 {
71 }
72}
73
75{
80
81 void DeferredForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
82 {
83 m_mode = mode;
84 m_item1 = item1;
85 m_item2 = item2;
86 m_dst1 = dst1;
87 m_dst2 = dst2;
88 }
89
90 override bool ReserveInventory(HumanInventory inventory)
91 {
93 {
94 return false;
95 }
97 {
99 return false;
100 }
101 return true;
102 }
103
104 override void ClearInventoryReservation(HumanInventory inventory)
105 {
108 }
109}
110
112{
115 {
116 m_mode = mode;
117 m_event = e;
118 }
119
120 override bool ReserveInventory(HumanInventory inventory)
121 {
122 return m_event.ReserveInventory();
123 }
124
126 {
128 }
129}
130
131
136{
139 //protected ref HandEventBase m_PostedHandEvent = NULL; /// deferred hand event
140
141
144 // states with animations
145 protected ref HandAnimatedTakingFromAtt m_Taking;
146 protected ref HandAnimatedMovingToAtt m_MovingTo;
147 protected ref HandAnimatedSwapping m_Swapping;
148 protected ref HandAnimatedForceSwapping m_FSwapping;
149 protected ref HandAnimatedForceSwapping_Inst m_FSwappingInst;
150
152 {
153 }
154
155 DayZPlayer GetDayZPlayerOwner () { return DayZPlayer.Cast(GetInventoryOwner()); }
156
158 {
159 DayZPlayer player;
160 if (!Class.CastTo(player, GetInventoryOwner()))
161 {
162 return false;
163 }
164
165 return (player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_CLIENT && player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_REMOTE);
166 }
167
168 bool IsOwner()
169 {
170 DayZPlayer player;
171 if (!Class.CastTo(player, GetInventoryOwner()))
172 {
173 return false;
174 }
175
176 return (player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT || player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_SERVER || player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_SINGLEPLAYER);
177 }
178
179 bool IsProxy()
180 {
181 DayZPlayer player;
182 if (!Class.CastTo(player, GetInventoryOwner()))
183 {
184 return false;
185 }
186
187 return (player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_REMOTE || player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_REMOTE);
188 }
189
190 override void Init ()
191 {
192 hndDebugPrint("[hndfsm] Creating DayZPlayer Inventory FSM");
193
194 CreateStableStates(); // stable states needs to be created first
195
196 m_Taking = new HandAnimatedTakingFromAtt(GetManOwner(), null);
197 m_MovingTo = new HandAnimatedMovingToAtt(GetManOwner(), null);
198 m_Swapping = new HandAnimatedSwapping(GetManOwner(), null);
199 m_FSwapping = new HandAnimatedForceSwapping(GetManOwner(), null);
200 m_FSwappingInst = new HandAnimatedForceSwapping_Inst(GetManOwner(), null);
201
202 // events
203 HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
204 HandEventBase _abt_ = new HandEventHumanCommandActionAborted;
205 HandEventBase __T__ = new HandEventTake;
206 HandEventBase __M__ = new HandEventMoveTo;
207 HandEventBase __W__ = new HandEventSwap;
208 //HandEventBase __D__ = new HandEventDropping;
209 HandEventBase __Xd_ = new HandEventDestroyed;
210 HandEventBase __F__ = new HandEventForceSwap;
211
212 // setup transitions
213 m_FSM.AddTransition(new HandTransition( m_Empty , __T__, m_Taking, NULL, new HandSelectAnimationOfTakeToHandsEvent(GetManOwner())));
214 m_FSM.AddTransition(new HandTransition( m_Taking , _fin_, m_Empty, null, new HandGuardNot(new HandGuardHasItemInHands(GetManOwner()))));
215 m_FSM.AddTransition(new HandTransition( m_Taking , _fin_, m_Equipped, null, null));
216 m_FSM.AddTransition(new HandTransition( m_Taking , __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
217 m_Taking.AddTransition(new HandTransition( m_Taking.m_Hide, _abt_, m_Empty));
218 m_Taking.AddTransition(new HandTransition( m_Taking.m_Show, _abt_, m_Equipped));
219
220 m_FSM.AddTransition(new HandTransition( m_Equipped, __M__, m_MovingTo, NULL, new HandSelectAnimationOfMoveFromHandsEvent(GetManOwner())));
221 m_FSM.AddTransition(new HandTransition( m_MovingTo, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
222 m_FSM.AddTransition(new HandTransition( m_MovingTo, _fin_, m_Equipped, null, new HandGuardHasItemInHands(GetManOwner())));
223 m_FSM.AddTransition(new HandTransition( m_MovingTo, _fin_, m_Empty , null, null));
224 m_MovingTo.AddTransition(new HandTransition( m_MovingTo.m_Hide, _abt_, m_Equipped));
225 m_MovingTo.AddTransition(new HandTransition( m_MovingTo.m_Show, _abt_, m_Empty));
226
227 m_FSM.AddTransition(new HandTransition( m_Equipped, __W__, m_Swapping, NULL, new HandSelectAnimationOfSwapInHandsEvent(GetManOwner())));
228 m_FSM.AddTransition(new HandTransition( m_Swapping, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
229 m_FSM.AddTransition(new HandTransition( m_Swapping, _fin_, m_Empty, null, new HandGuardNot(new HandGuardHasItemInHands(GetManOwner()))));
230 m_FSM.AddTransition(new HandTransition( m_Swapping, _fin_, m_Equipped, null, null));
231 m_FSM.AddTransition(new HandTransition( m_Swapping, _abt_, m_Equipped, null, null));
232
233 m_FSM.AddTransition(new HandTransition( m_Equipped, __F__, m_FSwappingInst, NULL, new HandGuardAnd( new HandSelectAnimationOfForceSwapInHandsEvent(GetManOwner()), new HandGuardInstantForceSwap(GetManOwner()) ) ));
234 m_FSM.AddTransition(new HandTransition(m_FSwappingInst, _fin_, m_Equipped, null, new HandGuardHasItemInHands(GetManOwner())));
235 m_FSM.AddTransition(new HandTransition(m_FSwappingInst, _fin_, m_Empty, null, null));
236 m_FSM.AddTransition(new HandTransition(m_FSwappingInst, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
237 m_FSM.AddTransition(new HandTransition( m_FSwappingInst, _abt_, m_Equipped, null, null));
238
239 m_FSM.AddTransition(new HandTransition( m_Equipped, __F__, m_FSwapping, NULL, new HandSelectAnimationOfForceSwapInHandsEvent(GetManOwner())));
240 m_FSM.AddTransition(new HandTransition(m_FSwapping, _fin_, m_Equipped, null, new HandGuardHasItemInHands(GetManOwner())));
241 m_FSM.AddTransition(new HandTransition(m_FSwapping, _fin_, m_Empty, null, null));
242 m_FSM.AddTransition(new HandTransition(m_FSwapping, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
243 m_FSwapping.AddTransition(new HandTransition( m_FSwapping.m_Start, _abt_, m_Equipped));
244 m_FSwapping.AddTransition(new HandTransition( m_FSwapping.m_Hide, _abt_, m_Empty));
245 m_FSwapping.AddTransition(new HandTransition( m_FSwapping.m_Show, _abt_, m_Equipped));
246
247 super.Init(); // initialize ordinary human fsm (no anims)
248 }
249
255 {
257 //m_postedHandEvent = null;
258 }
259
261 {
264 }
265
267 {
268 HumanCommandWeapons hcw = GetDayZPlayerOwner().GetCommandModifier_Weapons();
269
270 Weapon_Base weapon;
271 Class.CastTo(weapon, GetEntityInHands());
272
273 if (hcw && weapon && weapon.CanProcessWeaponEvents() && !weapon.IsIdle())
274 {
275 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: ABORT! notifying running state=" + weapon.GetCurrentState()); }
276 weapon.ProcessWeaponAbortEvent(new WeaponEventHumanCommandActionAborted(GetDayZPlayerOwner()));
277 }
278 }
279
285 {
286 if (m_DeferredWeaponEvent == NULL)
287 {
289 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(GetInventoryOwner()) + " Posted event m_DeferredWeaponEvent=" + m_DeferredWeaponEvent.DumpToString()); }
290 }
291 else
292 Error("[wpnfsm] " + Object.GetDebugName(GetInventoryOwner()) + " warning - pending event already posted, curr_event=" + m_DeferredWeaponEvent.DumpToString() + " new_event=" + e.DumpToString());
293 }
294
296 {
297 Weapon_Base weapon;
298 Class.CastTo(weapon, GetEntityInHands());
299
300 string secondPart = " - ENTITY IN HANDS IS NOT A WEAPON: " + Object.GetDebugName(GetEntityInHands());
301
302 string firstPart = "[wpnfsm] " + Object.GetDebugName(GetInventoryOwner()) + " failed to perform weaponevent " + m_DeferredWeaponEvent.DumpToString();
303 if (weapon)
304 {
305 secondPart = " on " + Object.GetDebugName(GetEntityInHands()) + " which is in state " + weapon.GetCurrentState();
306 secondPart += " with physical state: J: " + weapon.IsJammed() + " | ";
307 for (int i = 0; i < weapon.GetMuzzleCount(); ++i)
308 {
309 secondPart += "Chamber_" + i + ": B(" + weapon.IsChamberFull(i) + ") F(" + weapon.IsChamberFiredOut(i) + ") E(" + weapon.IsChamberEmpty(i) + ") | ";
310 secondPart += "Magazine_" + i + ": " + weapon.GetMagazine(i);
311 if (i < weapon.GetMuzzleCount() - 1)
312 secondPart += " | ";
313 }
314 }
315
316 Error(firstPart + secondPart);
318 }
319
320 void HandleWeaponEvents (float dt, out bool exitIronSights)
321 {
322 HumanCommandWeapons hcw = GetDayZPlayerOwner().GetCommandModifier_Weapons();
323
324 Weapon_Base weapon;
325 Class.CastTo(weapon, GetEntityInHands());
326
327 if (hcw && weapon && weapon.CanProcessWeaponEvents())
328 {
329 weapon.GetCurrentState().OnUpdate(dt);
330
331 if (LogManager.IsWeaponLogEnable()) { wpnDebugSpamALot("[wpnfsm] " + Object.GetDebugName(weapon) + " HCW: playing A=" + typename.EnumToString(WeaponActions, hcw.GetRunningAction()) + " AT=" + WeaponActionTypeToString(hcw.GetRunningAction(), hcw.GetRunningActionType()) + " fini=" + hcw.IsActionFinished()); }
332
333 if (!weapon.IsIdle())
334 {
335 while (true)
336 {
337 int weaponEventId = hcw.IsEvent();
338 if (weaponEventId == -1)
339 {
340 break;
341 }
342
343 if (weaponEventId == WeaponEvents.CHANGE_HIDE)
344 {
345 break;
346 }
347
348 WeaponEventBase anim_event = WeaponAnimEventFactory(weaponEventId, GetDayZPlayerOwner(), NULL);
349 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " HandleWeapons: event arrived " + typename.EnumToString(WeaponEvents, weaponEventId) + "(" + weaponEventId + ") fsm_ev=" + anim_event.ToString()); }
350 if (anim_event != NULL)
351 {
352 weapon.ProcessWeaponEvent(anim_event);
353 }
354 }
355
356 if (hcw.IsActionFinished())
357 {
358 if (weapon.IsWaitingForActionFinish())
359 {
360 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: finished! notifying waiting state=" + weapon.GetCurrentState()); }
361 weapon.ProcessWeaponEvent(new WeaponEventHumanCommandActionFinished(GetDayZPlayerOwner()));
362 }
363 else
364 {
365 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: ABORT! notifying running state=" + weapon.GetCurrentState()); }
366 weapon.ProcessWeaponAbortEvent(new WeaponEventHumanCommandActionAborted(GetDayZPlayerOwner()));
367 }
368 }
369 }
370
372 {
373 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: deferred " + m_DeferredWeaponEvent.DumpToString()); }
374 if (weapon.ProcessWeaponEvent(m_DeferredWeaponEvent))
375 {
376 exitIronSights = true;
377 fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: resetting deferred event" + m_DeferredWeaponEvent.DumpToString());
380 }
381 else if (!m_DeferredWeaponTimer.IsRunning())
382 {
383 m_DeferredWeaponTimer.Run(3, this, "DeferredWeaponFailed");
384 }
385 }
386 }
387 }
388
389 void HandleInventory(float dt)
390 {
391 HumanCommandWeapons hcw = GetDayZPlayerOwner().GetCommandModifier_Weapons();
392
393 EntityAI ih = GetEntityInHands();
394 Weapon_Base weapon;
395 Class.CastTo(weapon, ih);
396
397 if (hcw)
398 {
399 m_FSM.GetCurrentState().OnUpdate(dt);
400
401 #ifdef DEVELOPER
402 hndDebugSpamALot("[hndfsm] HCW: playing A=" + typename.EnumToString(WeaponActions, hcw.GetRunningAction()) + " AT=" + WeaponActionTypeToString(hcw.GetRunningAction(), hcw.GetRunningActionType()) + " fini=" + hcw.IsActionFinished());
403 #endif
404
405 if ( !m_FSM.GetCurrentState().IsIdle() || !m_FSM.IsRunning() )
406 {
407 while (true)
408 {
409 int weaponEventId = hcw.IsEvent();
410 if (weaponEventId == -1)
411 {
412 break;
413 }
414
415 HandEventBase anim_event = HandAnimEventFactory(weaponEventId, GetManOwner(), NULL);
416 #ifdef DEVELOPER
417 hndDebugPrint("[hndfsm] HandleInventory: event arrived " + typename.EnumToString(WeaponEvents, weaponEventId) + "(" + weaponEventId + ") fsm_ev=" + anim_event.ToString());
418 #endif
419 if (anim_event != NULL)
420 {
421 SyncHandEventToRemote(anim_event);
422 ProcessHandEvent(anim_event);
423 }
424 }
425
426 if (hcw.IsActionFinished())
427 {
428 if (m_FSM.GetCurrentState().IsWaitingForActionFinish())
429 {
430 #ifdef DEVELOPER
431 hndDebugPrint("[hndfsm] Hand-Weapon event: finished! notifying waiting state=" + m_FSM.GetCurrentState());
432 #endif
433 HandEventBase fin_event = new HandEventHumanCommandActionFinished(GetManOwner());
434 SyncHandEventToRemote(fin_event);
435 ProcessHandEvent(fin_event);
436 }
437 else
438 {
439 #ifdef DEVELOPER
440 hndDebugPrint("[hndfsm] Hand-Weapon event: ABORT! notifying running state=" + m_FSM.GetCurrentState());
441 #endif
442 HandEventBase abt_event = new HandEventHumanCommandActionAborted(GetManOwner());
443 SyncHandEventToRemote(abt_event);
444 ProcessHandAbortEvent(abt_event);
445 //m_FSM.ProcessHandAbortEvent(new WeaponEventHumanCommandActionAborted(GetManOwner()));
446 }
447 }
448 }
449 }
450 }
451
452
454
461 {
462 int tmp = -1;
463 ctx.Read(tmp);
464 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " store Juncture packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
465
467
468 return true;
469 }
470
472
479 {
480/* InventoryLocation il = new InventoryLocation;
481 if (!il.ReadFromContext(ctx) )
482 return false;
483
484 InventoryLocation il_current = new InventoryLocation;
485
486 EntityAI item = il.GetItem();
487 item.GetInventory().GetCurrentInventoryLocation(il_current);
488
489 if( !il_current.CompareLocationOnly(il))
490 {
491 LocationMoveEntity(il_current,il);
492 }*/
493 return true;
494 }
495
497
504 {
518 if (GetGame().IsDedicatedServer())
519 {
520 return;
521 }
522
523 int udtIdentifier = -1;
524 if (!ctx.Read(udtIdentifier) || udtIdentifier != INPUT_UDT_INVENTORY)
525 {
526 return;
527 }
528
532
533 InventoryCommandType type = -1;
534 if (!ctx.Read(type))
535 {
536 return;
537 }
538
539 switch (type)
540 {
541 case InventoryCommandType.SYNC_MOVE:
542 {
543 src.ReadFromContext(ctx);
544 dst.ReadFromContext(ctx);
545 break;
546 }
547 case InventoryCommandType.HAND_EVENT:
548 {
549 HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
550 src = e.GetSrc();
551 dst = e.GetDst();
552 break;
553 }
554 case InventoryCommandType.SWAP:
555 {
556 src.ReadFromContext(ctx);
557 temp.ReadFromContext(ctx);
558 dst.ReadFromContext(ctx);
559 temp.ReadFromContext(ctx);
560 break;
561 }
562 case InventoryCommandType.FORCESWAP:
563 {
564 break;
565 }
566 case InventoryCommandType.DESTROY:
567 {
568 src.ReadFromContext(ctx);
569 break;
570 }
571 }
572
574 if (!ctx.Read(reason))
575 {
576 reason = InventoryValidationReason.UNKNOWN;
577 }
578
579 OnInventoryFailure(type, reason, src, dst);
580 }
581
583 {
584 if (reason == InventoryValidationReason.DROP_PREVENTED)
585 {
587 return;
588 }
589
590 }
591
597 {
598 int tmp = -1;
599 ctx.Read(tmp);
600 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " handle JunctureData packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
601
603 ProcessInputData(ctx, true, false);
604 }
605
610 proto native void StoreJunctureData (ParamsReadContext ctx);
612
613
615
622 {
623 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " store InputUserData packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
625 return true;
626 }
627
633 {
634 int tmp = -1;
635 ctx.Read(tmp);
636 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " handle InputUserData packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
637
639 ProcessInputData(ctx, false, false);
640 }
641
645 proto native void StoreInputUserData(ParamsReadContext ctx);
647
649 {
650 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " remote handling InputUserData packet from server");
651
652 ProcessInputData(ctx, false, true);
653 }
654
656 {
657 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " DZPInventory command from server");
658
659 ProcessInputData(ctx, true, true);
660 }
661
663 {
665
668
669 src.ReadFromContext(ctx);
670 dst.ReadFromContext(ctx);
671
672 #ifdef DEVELOPER
674 {
675 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + "src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst), "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
676 }
677 #endif
678
679 if (validation.m_IsRemote && (!src.GetItem() || !dst.GetItem()))
680 {
681 #ifdef DEVELOPER
683 {
684 Debug.InventoryMoveLog("Failed - item not in bubble", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
685 }
686 #endif
687
688 syncDebugPrint("[syncinv] HandleInputData remote input (cmd=SYNC_MOVE) dropped, item not in bubble! src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
689 return true;
690 }
691
694 {
695 #ifdef DEVELOPER
697 {
698 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
699 }
700 #endif
701
702 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " failed src check with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src));
704 return true;
705 }
706
709 {
710 #ifdef DEVELOPER
712 {
713 Debug.InventoryMoveLog("Failed - CheckMoveToDstRequest", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
714 }
715 #endif
716
717 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
719 return true;
720 }
722
723 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " HandleInputData t=" + GetGame().GetTime() + "ms received cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
724
726 if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
727 {
729 if (result_mv == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
730 {
731 #ifdef DEVELOPER
733 {
734 Debug.InventoryMoveLog("Juncture not required", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
735 }
736 #endif
737
739
740 LocationSyncMoveEntity(src, dst);
741
742 validation.m_Result = InventoryValidationResult.SUCCESS;
743 return true;
744 }
745 else if (result_mv == JunctureRequestResult.JUNCTURE_ACQUIRED)
746 {
747 #ifdef DEVELOPER
749 {
750 Debug.InventoryMoveLog("Juncture sended", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
751 }
752 #endif
753
755 {
756 #ifdef DEVELOPER
757 DumpInventoryDebug();
759 {
760 Debug.InventoryMoveLog("Failed - LocationCanMoveEntity - Juncture denied", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
761 }
762 #endif
763
764 return true;
765 }
766
767 validation.m_Result = InventoryValidationResult.JUNCTURE;
769 return true;
770 }
771 else if (result_mv == JunctureRequestResult.JUNCTURE_DENIED)
772 {
773 #ifdef DEVELOPER
775 {
776 Debug.InventoryMoveLog("Juncture denied", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
777 }
778 #endif
779
780 validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
781 return true;
782 }
783 else
784 {
785 Error("[syncinv] HandleInputData: unexpected return code from AcquireInventoryJunctureFromServer");
786
787 return true;
788 }
789 }
790
791 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
792 {
794 }
795
796 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
797 {
798 CheckForRope(src, dst);
799 }
800
802 {
803 #ifdef DEVELOPER
804 DumpInventoryDebug();
806 {
807 Debug.InventoryMoveLog("Failed - LocationCanMoveEntity", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
808 }
809 #endif
810
811 Error("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT move cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
812 return true;
813 }
814
815 #ifdef DEVELOPER
817 {
818 Debug.InventoryMoveLog("Success - LocationSyncMoveEntity", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
819 }
820 #endif
821
822 LocationSyncMoveEntity(src, dst);
823
824 validation.m_Result = InventoryValidationResult.SUCCESS;
825 return true;
826 }
827
829 {
831
832 HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
834
835 EntityAI itemSrc = e.GetSrcEntity();
836 EntityAI itemDst = e.GetSecondSrcEntity();
837
838 #ifdef DEVELOPER
840 {
841 Debug.InventoryMoveLog("STS = " + e.m_Player.GetSimulationTimeStamp() + " event= " + e.ToString(), "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
842 }
843 #endif
844
845 if (validation.m_IsRemote && !e.GetSrcEntity())
846 {
847 #ifdef DEVELOPER
849 {
850 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
851 }
852 #endif
853
854 Error("[syncinv] HandleInputData remote input (cmd=HAND_EVENT) dropped, item not in bubble");
855
859 return true;
860 }
861
863 if (itemSrc)
864 RemoveMovableOverride(itemSrc);
865 if (itemDst)
866 RemoveMovableOverride(itemDst);
867
868 if (!e.CheckRequestSrc())
869 {
870 #ifdef DEVELOPER
872 {
873 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
874 }
875 #endif
876
877 if (!validation.m_IsRemote)
878 {
879 ctx = new ScriptInputUserData;
881 }
882
883 if (itemSrc)
884 RemoveMovableOverride(itemSrc);
885 if (itemDst)
886 RemoveMovableOverride(itemDst);
887
888 return true;
889 }
890
892 if (!validation.m_IsRemote && !e.CheckRequestEx(validation))
893 {
894 #ifdef DEVELOPER
896 {
897 Debug.InventoryMoveLog("Failed - CheckRequest", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
898 }
899 #endif
900
902
903 ctx = new ScriptInputUserData;
905
907 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " event=" + e.DumpToString());
908 if (itemSrc)
909 RemoveMovableOverride(itemSrc);
910 if (itemDst)
911 RemoveMovableOverride(itemDst);
912 return true;
913 }
914
915 if (!e.CanPerformEventEx(validation))
916 {
917 #ifdef DEVELOPER
919 {
920 Debug.InventoryMoveLog("Failed - CanPerformEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
921 }
922 #endif
923
925
926 ctx = new ScriptInputUserData;
928
929 syncDebugPrint("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT do cmd=HAND_EVENT e=" + e.DumpToString());
930 if (itemSrc)
931 RemoveMovableOverride(itemSrc);
932 if (itemDst)
933 RemoveMovableOverride(itemDst);
934 return true;
935 }
936 if (itemSrc)
937 RemoveMovableOverride(itemSrc);
938 if (itemDst)
939 RemoveMovableOverride(itemDst);
940
942 if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
943 {
945 if (result_ev == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
946 {
947 #ifdef DEVELOPER
949 {
950 Debug.InventoryMoveLog("Juncture not required", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
951 }
952 #endif
953
955 }
956 else if (result_ev == JunctureRequestResult.JUNCTURE_ACQUIRED)
957 {
958 #ifdef DEVELOPER
960 {
961 Debug.InventoryMoveLog("Juncture sended", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
962 }
963 #endif
964
965 ctx = new ScriptInputUserData;
967
968 validation.m_Result = InventoryValidationResult.JUNCTURE;
969
970 if (itemSrc)
971 EnableMovableOverride(itemSrc);
972 if (itemDst)
973 EnableMovableOverride(itemDst);
974 return true;
975 }
976 else if (result_ev == JunctureRequestResult.JUNCTURE_DENIED)
977 {
978 #ifdef DEVELOPER
980 {
981 Debug.InventoryMoveLog("Juncture denied", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
982 }
983 #endif
984
985 validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
986 return true;
987 }
988 else
989 {
990 Error("[syncinv] HandleInputData: unexpected return code from AcquireInventoryJunctureFromServer");
991
992 return true;
993 }
994 }
995
996 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
997 {
998 CheckForRope(e.GetSrc(), e.GetDst());
999 }
1000
1001 #ifdef DEVELOPER
1003 {
1004 Debug.InventoryMoveLog("Success - ProcessHandEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1005 }
1006 #endif
1007
1008 validation.m_Result = InventoryValidationResult.SUCCESS;
1009 if (!e.m_Player.GetHumanInventory().ProcessHandEvent(e))
1010 {
1012 //result = InventoryValidationResult.FAILURE;
1013 }
1014
1015 return true;
1016 }
1017
1018 bool ValidateSwap(inout Serializer ctx, InventoryValidation validation)
1019 {
1021
1024
1027
1028 bool skippedSwap = false;
1029
1030 src1.ReadFromContext(ctx);
1031 src2.ReadFromContext(ctx);
1032 dst1.ReadFromContext(ctx);
1033 dst2.ReadFromContext(ctx);
1034 ctx.Read(skippedSwap);
1035
1036 #ifdef DEVELOPER
1038 {
1039 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2), "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1040 }
1041 #endif
1042
1043 if (validation.m_IsRemote && (!src1.GetItem() || !src2.GetItem()))
1044 {
1045 if (skippedSwap)
1046 {
1047 #ifdef DEVELOPER
1049 {
1050 Debug.InventoryMoveLog("Remote - skipped", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1051 }
1052 #endif
1053 //syncDebugPrint("[syncinv] HandleInputData remote input (cmd=SWAP) dropped, swap is skipped");
1054 }
1055 else
1056 {
1057 #ifdef DEVELOPER
1059 {
1060 Debug.InventoryMoveLog("Failed - item1 or item2 not exist", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1061 }
1062 #endif
1063
1064 Error("[syncinv] HandleInputData remote input (cmd=SWAP) dropped, item not in bubble");
1065 }
1066
1067 return true;
1068 }
1069
1072
1074 {
1075 #ifdef DEVELOPER
1077 {
1078 Debug.InventoryMoveLog("Failed - CheckRequestSrc1", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1079 }
1080 #endif
1081
1082 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " failed src1 check with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src1=" + InventoryLocation.DumpToStringNullSafe(src1));
1085 return true;
1086 }
1087
1089 {
1090 #ifdef DEVELOPER
1092 {
1093 Debug.InventoryMoveLog("Failed - CheckRequestSrc2", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1094 }
1095 #endif
1096 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " failed src2 check with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2));
1099 return true;
1100 }
1101
1103 if (!validation.m_IsRemote && !PlayerCheckSwapItemsRequest(src1, src2, dst1, dst2, GameInventory.c_MaxItemDistanceRadius))
1104 {
1105 #ifdef DEVELOPER
1107 {
1108 Debug.InventoryMoveLog("Failed - CheckSwapItemsRequest", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1109 }
1110 #endif
1111
1112 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
1115 return true;
1116 }
1117
1120
1121 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
1122 {
1125 }
1126
1127 if (!GameInventory.CanForceSwapEntitiesEx(src1.GetItem(), dst1, src2.GetItem(), dst2))
1128 {
1129 #ifdef DEVELOPER
1130 DumpInventoryDebug();
1131
1133 {
1134 Debug.InventoryMoveLog("Failed - CanForceSwapEntitiesEx", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1135 }
1136 #endif
1137
1138 Error("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT swap cmd=" + typename.EnumToString(InventoryCommandType, type) + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) +" | src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
1139 return true;
1140 }
1141
1142 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
1143 {
1144 AddInventoryReservationEx(dst1.GetItem(), dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
1145 AddInventoryReservationEx(dst2.GetItem(), dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
1146 }
1147
1148 if (!(src1.IsValid() && src2.IsValid() && dst1.IsValid() && dst2.IsValid()))
1149 {
1150 Error("HandleInputData: cmd=" + typename.EnumToString(InventoryCommandType, type) + " invalid input(s): src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
1151 return true;
1152 }
1153
1155 if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1156 {
1158 if (result_sw == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
1159 {
1160 #ifdef DEVELOPER
1162 {
1163 Debug.InventoryMoveLog("Juncture not required", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1164 }
1165 #endif
1166
1168 }
1169 else if (result_sw == JunctureRequestResult.JUNCTURE_ACQUIRED)
1170 {
1171 #ifdef DEVELOPER
1173 {
1174 Debug.InventoryMoveLog("Juncture sended", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1175 }
1176 #endif
1177
1178 validation.m_Result = InventoryValidationResult.JUNCTURE;
1181 return true;
1182 }
1183 else if (result_sw == JunctureRequestResult.JUNCTURE_DENIED)
1184 {
1185 #ifdef DEVELOPER
1187 {
1188 Debug.InventoryMoveLog("Juncture denied", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1189 }
1190 #endif
1191
1192 validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
1193 return true;
1194 }
1195 else
1196 {
1197 Error("[syncinv] HandleInputData: unexpected return code from TryAcquireTwoInventoryJuncturesFromServer"); return true;
1198
1199 return true;
1200 }
1201 }
1202
1203 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT )
1204 {
1207 }
1208
1209 #ifdef DEVELOPER
1211 {
1212 Debug.InventoryMoveLog("Success - item swap", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1213 }
1214 #endif
1215
1216 bool isNotSkipped = LocationSwap(src1, src2, dst1, dst2);
1217
1218 ctx = new ScriptInputUserData();
1219 InventoryInputUserData.SerializeSwap(ctx, src1, src2, dst1, dst2, !isNotSkipped);
1220
1221 validation.m_Result = InventoryValidationResult.SUCCESS;
1222 return true;
1223 }
1224
1226 {
1228
1229 if (validation.m_IsJuncture)
1230 {
1238 return true;
1239 }
1240
1242 src.ReadFromContext(ctx);
1243
1244 #ifdef DEVELOPER
1246 {
1247 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src), "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1248 }
1249 #endif
1250
1251 if (validation.m_IsRemote && !src.GetItem())
1252 {
1253 #ifdef DEVELOPER
1255 {
1256 Debug.InventoryMoveLog("Failed item not exist", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1257 }
1258 #endif
1259
1260 Error("[syncinv] HandleInputData remote input (cmd=DESTROY) dropped, item not in bubble");
1261 return true;
1262 }
1263
1265 {
1266 #ifdef DEVELOPER
1268 {
1269 Debug.InventoryMoveLog("Failed CheckRequestSrc", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1270 }
1271 #endif
1272
1273 return true;
1274 }
1275
1278 {
1279 #ifdef DEVELOPER
1281 {
1282 Debug.InventoryMoveLog("Failed CheckDropRequest", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1283 }
1284 #endif
1285
1286 return true;
1287 }
1288
1289 #ifdef DEVELOPER
1291 {
1292 Debug.InventoryMoveLog("Success ObjectDelete", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1293 }
1294 #endif
1295
1296 GetGame().ObjectDelete(src.GetItem());
1297
1298 validation.m_Result = InventoryValidationResult.SUCCESS;
1299 return true;
1300 }
1301
1306 bool ProcessInputData(ParamsReadContext ctx, bool isJuncture, bool isRemote)
1307 {
1308 if (isJuncture && isRemote)
1309 {
1311 return false;
1312 }
1313
1314 int type = -1;
1315 if (!ctx.Read(type))
1316 {
1317 return false;
1318 }
1319
1320 InventoryValidation validation();
1321 validation.m_IsJuncture = isJuncture;
1322 validation.m_IsRemote = isRemote;
1323
1325 Serializer serializer = ctx;
1326
1327 switch (type)
1328 {
1329 case InventoryCommandType.USER_RESERVATION_CANCEL:
1330 if (!ValidateUserReservationCancel(serializer, validation))
1331 {
1332 return false;
1333 }
1334 break;
1335 case InventoryCommandType.SYNC_MOVE:
1336 if (!ValidateSyncMove(serializer, validation))
1337 {
1338 return false;
1339 }
1340 break;
1341 case InventoryCommandType.HAND_EVENT:
1342 if (!ValidateHandEvent(serializer, validation))
1343 {
1344 return false;
1345 }
1346 break;
1347 case InventoryCommandType.SWAP:
1348 if (!ValidateSwap(serializer, validation))
1349 {
1350 return false;
1351 }
1352 break;
1353 case InventoryCommandType.DESTROY:
1354 if (!ValidateDestroy(serializer, validation))
1355 {
1356 return false;
1357 }
1358 break;
1359 default:
1360 break;
1361 }
1362
1363 bool canSendJuncture = !isJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER;
1364
1365 switch (validation.m_Result)
1366 {
1367 case InventoryValidationResult.FAILED:
1368 if (canSendJuncture)
1369 {
1371 if (!serializer.CanWrite())
1372 {
1373 ScriptInputUserData writeableSerializer();
1374 writeableSerializer.CopyFrom(serializer);
1375 serializer = writeableSerializer;
1376 }
1377
1378 serializer.Write(validation.m_Reason);
1379
1380 GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY_FAILURE, serializer);
1381 }
1382 break;
1383 case InventoryValidationResult.JUNCTURE:
1384 if (canSendJuncture)
1385 {
1386 GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY, serializer);
1387 StoreInputForRemotes(isJuncture, isRemote, serializer);
1388 }
1389 else
1390 {
1391 Error("InventoryValidationResult.JUNCTURE returned when not possible to send!");
1392 }
1393 break;
1394 case InventoryValidationResult.SUCCESS:
1395 StoreInputForRemotes(isJuncture, isRemote, serializer);
1396 break;
1397 }
1398
1399 return true;
1400 }
1401
1403 {
1404 ItemBase itemIB = ItemBase.Cast(item);
1405 if (itemIB)
1406 itemIB.SetCanBeMovedOverride(false);
1407 }
1408
1410 {
1411 ItemBase itemIB = ItemBase.Cast(item);
1412 if (itemIB)
1413 itemIB.SetCanBeMovedOverride(true);
1414 }
1415
1416 // Hacky solution for dealing with fencekit rope related issues, could be fixed by introducing some indicator that this item behaves differently or sth..
1418 {
1419 Rope rope = Rope.Cast(src.GetItem());
1420 if (rope)
1421 rope.SetTargetLocation(dst);
1422 }
1423
1425 {
1426 return GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER || GetDayZPlayerOwner() == GetGame().GetPlayer());
1427 }
1428
1429 bool StoreInputForRemotes (bool handling_juncture, bool remote, ParamsReadContext ctx)
1430 {
1431 if (!handling_juncture && !remote && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1432 {
1433 #ifdef DEVELOPER
1435 {
1436 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp(), "n/a" , "n/a", "StoreInputForRemotes", GetDayZPlayerOwner().ToString() );
1437 }
1438 #endif
1439 GetDayZPlayerOwner().StoreInputForRemotes(ctx); // @NOTE: needs to be called _after_ the operation
1440 return true;
1441 }
1442 return false;
1443 }
1444
1445 override bool TakeToDst (InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
1446 {
1447 if (!GetManOwner().IsAlive())
1448 return super.TakeToDst(mode,src,dst);
1449
1450 #ifdef DEVELOPER
1452 {
1453 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
1454 }
1455 #endif
1456
1457 switch ( mode )
1458 {
1459 case InventoryMode.SERVER:
1460 if (RedirectToHandEvent(mode, src, dst))
1461 {
1462 #ifdef DEVELOPER
1464 {
1465 Debug.InventoryMoveLog("RedirectToHandEvent", "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
1466 }
1467 #endif
1468 return true;
1469 }
1470
1471
1472 if (GetDayZPlayerOwner().NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
1473 {
1474
1475 if (GetGame().AddInventoryJunctureEx(GetDayZPlayerOwner(), src.GetItem(), dst, true, GameInventory.c_InventoryReservationTimeoutMS))
1476 {
1477 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " DZPI::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + ") got juncture");
1478
1479 }
1480 else
1481 {
1482 #ifdef DEVELOPER
1484 {
1485 Debug.InventoryMoveLog("Juncture failed", "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
1486 }
1487 #endif
1488 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " DZPI::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + ") got juncture");
1489 return false;
1490 }
1491
1492 }
1493
1496
1498
1499 syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " store input for remote - DZPI::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + " server sync move src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
1500 GetDayZPlayerOwner().StoreInputForRemotes(ctx); // @TODO: is this right place? maybe in HandleInputData(server=true, ...)
1501 #ifdef DEVELOPER
1503 {
1504 Debug.InventoryMoveLog("Success - store input for remote mode - " + typename.EnumToString(InventoryMode, mode) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
1505 }
1506 #endif
1507 return true;
1508
1509 case InventoryMode.LOCAL:
1510 LocationSyncMoveEntity(src, dst);
1511 return true;
1512 }
1513 if(!super.TakeToDst(mode,src,dst))
1514 {
1515 if (!m_DeferredEvent)
1516 {
1517 m_DeferredEvent = new DeferredTakeToDst(mode,src,dst);
1518 if( m_DeferredEvent.ReserveInventory(this) )
1519 return true;
1520 }
1521
1522 m_DeferredEvent = null;
1523 return false;
1524 }
1525 return true;
1526 }
1527
1528 void HandleTakeToDst( DeferredEvent deferred_event )
1529 {
1530 DeferredTakeToDst deferred_take_to_dst = DeferredTakeToDst.Cast(deferred_event);
1531 if( deferred_take_to_dst )
1532 {
1533 #ifdef DEVELOPER
1535 {
1536 Debug.InventoryHFSMLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp(), "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1537 }
1538 #endif
1539
1540
1541 deferred_take_to_dst.ClearInventoryReservation(this);
1542 inventoryDebugPrint("[inv] I::Take2Dst(" + typename.EnumToString(InventoryMode, deferred_take_to_dst.m_mode) + ") src=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_src) + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_dst));
1543
1544 switch (deferred_take_to_dst.m_mode)
1545 {
1546 case InventoryMode.PREDICTIVE:
1547 #ifdef DEVELOPER
1549 {
1550 Debug.InventoryHFSMLog("PREDICTIVE ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1551 }
1552 #endif
1553
1554 if (LocationCanMoveEntity(deferred_take_to_dst.m_src,deferred_take_to_dst.m_dst))
1555 {
1556 InventoryInputUserData.SendInputUserDataMove(InventoryCommandType.SYNC_MOVE, deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst);
1557 LocationSyncMoveEntity(deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst);
1558 }
1559 else
1560 {
1561 #ifdef DEVELOPER
1563 {
1564 Debug.InventoryMoveLog("Can not move entity (PREDICTIVE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item = " + deferred_take_to_dst.m_dst.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_dst), "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1565 }
1566 #endif
1567 }
1568 break;
1569 case InventoryMode.JUNCTURE:
1570 #ifdef DEVELOPER
1572 {
1573 Debug.InventoryHFSMLog("JUNCTURE ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1574 }
1575 #endif
1576
1577 if (LocationCanMoveEntity(deferred_take_to_dst.m_src,deferred_take_to_dst.m_dst))
1578 {
1579 DayZPlayer player = GetGame().GetPlayer();
1580 player.GetHumanInventory().AddInventoryReservationEx(deferred_take_to_dst.m_dst.GetItem(), deferred_take_to_dst.m_dst, GameInventory.c_InventoryReservationTimeoutShortMS);
1581 EnableMovableOverride(deferred_take_to_dst.m_dst.GetItem());
1582 InventoryInputUserData.SendInputUserDataMove(InventoryCommandType.SYNC_MOVE, deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst);
1583 }
1584 else
1585 {
1586 #ifdef DEVELOPER
1588 {
1589 Debug.InventoryMoveLog("Can not move entity (JUNCTURE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item = " + deferred_take_to_dst.m_dst.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_dst), "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1590 }
1591 #endif
1592 }
1593 break;
1594 case InventoryMode.LOCAL:
1595 #ifdef DEVELOPER
1597 {
1598 Debug.InventoryHFSMLog("LOCAL ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1599 }
1600 #endif
1601 break;
1602 case InventoryMode.SERVER:
1603 #ifdef DEVELOPER
1605 {
1606 Debug.InventoryHFSMLog("SERVER ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
1607 }
1608 #endif
1609 break;
1610
1611 break;
1612 default:
1613 Error("HandEvent - Invalid mode");
1614 }
1615 }
1616 }
1617
1618 override bool SwapEntities (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
1619 {
1620 #ifdef DEVELOPER
1622 {
1623 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + item1 + " item2 = " + item2, "n/a" , "n/a", "SwapEntities", GetDayZPlayerOwner().ToString() );
1624 }
1625 #endif
1626
1627 InventoryLocation src1, src2, dst1, dst2;
1628 if( mode == InventoryMode.LOCAL )
1629 {
1630 if (GameInventory.MakeSrcAndDstForSwap(item1, item2, src1, src2, dst1, dst2))
1631 {
1632 LocationSwap(src1, src2, dst1, dst2);
1633 return true;
1634 }
1635 }
1636
1637 if(!super.SwapEntities(mode,item1,item2))
1638 {
1639 if(!m_DeferredEvent)
1640 {
1641 if( GameInventory.MakeSrcAndDstForSwap(item1, item2, src1, src2, dst1, dst2) );
1642 {
1643 m_DeferredEvent = new DeferredSwapEntities(mode, item1, item2, dst1, dst2);
1644 if( m_DeferredEvent.ReserveInventory(this) )
1645 return true;
1646 }
1647 }
1648 m_DeferredEvent = null;
1649 return false;
1650 }
1651 return true;
1652 }
1653
1654 void HandleSwapEntities( DeferredEvent deferred_event )
1655 {
1656 DeferredSwapEntities deferred_swap_entities = DeferredSwapEntities.Cast(deferred_event);
1657 if( deferred_swap_entities )
1658 {
1659 deferred_swap_entities.ClearInventoryReservation(this);
1660 InventoryLocation src1, src2, dst1, dst2;
1661 if (GameInventory.MakeSrcAndDstForSwap(deferred_swap_entities.m_item1, deferred_swap_entities.m_item2, src1, src2, dst1, dst2))
1662 {
1663 inventoryDebugPrint("[inv] I::Swap(" + typename.EnumToString(InventoryMode, deferred_swap_entities.m_mode) + ") src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst2));
1664
1665 switch (deferred_swap_entities.m_mode)
1666 {
1667 case InventoryMode.PREDICTIVE:
1668 if (CanSwapEntitiesEx(deferred_swap_entities.m_dst1.GetItem(),deferred_swap_entities.m_dst2.GetItem()) )
1669 {
1670 InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_swap_entities.m_dst1, deferred_swap_entities.m_dst2);
1671 LocationSwap(src1, src2, deferred_swap_entities.m_dst1, deferred_swap_entities.m_dst2);
1672 }
1673 else
1674 {
1675 #ifdef DEVELOPER
1677 {
1678 Debug.InventoryMoveLog("Can not swap (PREDICTIVE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
1679 }
1680 #endif
1681 }
1682 break;
1683
1684 case InventoryMode.JUNCTURE:
1685 if (CanSwapEntitiesEx(deferred_swap_entities.m_dst1.GetItem(),deferred_swap_entities.m_dst2.GetItem()) )
1686 {
1687 DayZPlayer player = GetGame().GetPlayer();
1688 player.GetHumanInventory().AddInventoryReservationEx(deferred_swap_entities.m_dst1.GetItem(), deferred_swap_entities.m_dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
1689 player.GetHumanInventory().AddInventoryReservationEx(deferred_swap_entities.m_dst2.GetItem(), deferred_swap_entities.m_dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
1690 EnableMovableOverride(deferred_swap_entities.m_dst1.GetItem());
1691 EnableMovableOverride(deferred_swap_entities.m_dst2.GetItem());
1692 InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_swap_entities.m_dst1, deferred_swap_entities.m_dst2);
1693 }
1694 else
1695 {
1696 #ifdef DEVELOPER
1698 {
1699 Debug.InventoryMoveLog("Can not swap (JUNCTURE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
1700 }
1701 #endif
1702 }
1703 break;
1704
1705 case InventoryMode.LOCAL:
1706 break;
1707
1708 default:
1709 Error("SwapEntities - HandEvent - Invalid mode");
1710 }
1711 }
1712 else
1713 Error("SwapEntities - MakeSrcAndDstForSwap - no inv loc");
1714 }
1715 }
1716
1717 override bool ForceSwapEntities (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
1718 {
1719 #ifdef DEVELOPER
1721 {
1722 Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + item1 + " item2 = " + item2 + " dst=" + InventoryLocation.DumpToStringNullSafe(item2_dst), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
1723 }
1724 #endif
1725
1726
1727 if( mode == InventoryMode.LOCAL )
1728 {
1729 InventoryLocation src1, src2, dst1;
1730 if (GameInventory.MakeSrcAndDstForForceSwap(item1, item2, src1, src2, dst1, item2_dst))
1731 {
1732 LocationSwap(src1, src2, dst1, item2_dst);
1733 return true;
1734 }
1735
1736 }
1737
1738 if(!super.ForceSwapEntities(mode,item1,item2,item2_dst))
1739 {
1740 if(!m_DeferredEvent)
1741 {
1742 if (GameInventory.MakeSrcAndDstForForceSwap(item1, item2, src1, src2, dst1, item2_dst))
1743 {
1744 m_DeferredEvent = new DeferredForceSwapEntities(mode,item1,item2, dst1, item2_dst);
1745 if( m_DeferredEvent.ReserveInventory(this))
1746 return true;
1747
1748 }
1749 }
1750 m_DeferredEvent = null;
1751 return false;
1752 }
1753
1754 return true;
1755 }
1756
1758 {
1759 DeferredForceSwapEntities deferred_force_swap_entities = DeferredForceSwapEntities.Cast(deferred_event);
1760 if( deferred_force_swap_entities )
1761 {
1762 deferred_force_swap_entities.ClearInventoryReservation(this);
1765 deferred_force_swap_entities.m_item1.GetInventory().GetCurrentInventoryLocation(src1);
1766 deferred_force_swap_entities.m_item2.GetInventory().GetCurrentInventoryLocation(src2);
1767
1768 DayZPlayer player = GetGame().GetPlayer();
1769
1770 inventoryDebugPrint("[inv] I::FSwap(" + typename.EnumToString(InventoryMode, deferred_force_swap_entities.m_mode) + ") src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst2));
1771
1772 switch (deferred_force_swap_entities.m_mode)
1773 {
1774 case InventoryMode.PREDICTIVE:
1775 if (CanForceSwapEntitiesEx(deferred_force_swap_entities.m_dst1.GetItem(),deferred_force_swap_entities.m_dst1,deferred_force_swap_entities.m_dst2.GetItem(), deferred_force_swap_entities.m_dst2))
1776 {
1777 InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2);
1778 LocationSwap(src1, src2, deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2);
1779 }
1780 else
1781 {
1782 #ifdef DEVELOPER
1784 {
1785 Debug.InventoryMoveLog("Can not force swap (PREDICTIVE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_force_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_force_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
1786 }
1787 #endif
1788 }
1789 break;
1790
1791 case InventoryMode.JUNCTURE:
1792 if (CanForceSwapEntitiesEx(deferred_force_swap_entities.m_dst1.GetItem(),deferred_force_swap_entities.m_dst1,deferred_force_swap_entities.m_dst2.GetItem(), deferred_force_swap_entities.m_dst2))
1793 {
1794 player.GetHumanInventory().AddInventoryReservationEx(deferred_force_swap_entities.m_item1, deferred_force_swap_entities.m_dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
1795 player.GetHumanInventory().AddInventoryReservationEx(deferred_force_swap_entities.m_item2, deferred_force_swap_entities.m_dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
1796
1797 InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2);
1798 }
1799 else
1800 {
1801 #ifdef DEVELOPER
1803 {
1804 Debug.InventoryMoveLog("Can not force swap (JUNCTURE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_force_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_force_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
1805 }
1806 #endif
1807 }
1808 break;
1809
1810 case InventoryMode.LOCAL:
1811 break;
1812
1813 default:
1814 Error("ForceSwapEntities - HandEvent - Invalid mode");
1815 }
1816 }
1817 }
1818
1820 {
1821 if (GetGame().IsServer())
1822 {
1823 if (e.IsServerSideOnly())
1824 Error("[syncinv] " + Object.GetDebugName(player) + " SendServerHandEventViaJuncture - called on server side event only, e=" + e.DumpToString());
1825
1826 if (player.IsAlive())
1827 {
1828 InventoryLocation dst = e.GetDst();
1829 InventoryLocation src = e.GetSrc();
1830 if (src.IsValid() && dst.IsValid())
1831 {
1832 if (player.NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
1833 {
1834 syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + ") need juncture src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
1835
1836 if (GetGame().AddInventoryJunctureEx(player, src.GetItem(), dst, true, GameInventory.c_InventoryReservationTimeoutMS))
1837 syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + ") got juncture");
1838 else
1839 syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + ") !got juncture");
1840 }
1841
1842 syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + " server hand event src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
1843
1846 player.SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY, ctx);
1847 syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " store input for remote - SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + " server hand event src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
1848 player.StoreInputForRemotes(ctx); // @TODO: is this right place? maybe in HandleInputData(server=true, ...)
1849 }
1850 }
1851 else
1852 {
1853 Error("[syncinv] SendServerHandEventViaJuncture - called on dead player, juncture is for living only");
1854 }
1855 }
1856 }
1857
1861 override void NetSyncCurrentStateID (int id)
1862 {
1863 super.NetSyncCurrentStateID(id);
1864
1865 GetDayZPlayerOwner().GetItemAccessor().OnItemInHandsChanged();
1866 }
1867
1874 override void OnAfterStoreLoad ()
1875 {
1876 GetDayZPlayerOwner().GetItemAccessor().OnItemInHandsChanged(true);
1877 }
1878
1883 {
1884 if (GetEntityInHands())
1885 {
1886 Weapon_Base wpn = Weapon_Base.Cast(GetEntityInHands());
1887 if (wpn)
1888 {
1890
1892 if (pb && e)
1893 {
1894 pb.GetWeaponManager().SetRunning(true);
1895
1896 fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(wpn) + " recv event from remote: created event=" + e);
1897 if (e.GetEventID() == WeaponEventID.HUMANCOMMAND_ACTION_ABORTED)
1898 {
1899 wpn.ProcessWeaponAbortEvent(e);
1900 }
1901 else
1902 {
1903 wpn.ProcessWeaponEvent(e);
1904 }
1905 pb.GetWeaponManager().SetRunning(false);
1906 }
1907 }
1908 else
1909 Error("OnEventForRemoteWeapon - entity in hands, but not weapon. item=" + GetEntityInHands());
1910 }
1911 else
1912 Error("OnEventForRemoteWeapon - no entity in hands");
1913 return true;
1914 }
1915
1916
1921 {
1922 HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
1923 if (e)
1924 {
1925 hndDebugSpam("[hndfsm] recv event from remote: created event=" + e);
1926 //m_FSM.ProcessEvent(e);
1927 if (e.GetEventID() == HandEventID.HUMANCOMMAND_ACTION_ABORTED)
1928 {
1930 m_FSM.ProcessAbortEvent(e, aa);
1931 }
1932 else
1933 {
1934 m_FSM.ProcessEvent(e);
1935 }
1936
1937 return true;
1938 }
1939 return false;
1940 }
1941
1943 {
1945 if (p && p.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1946 {
1948
1950 e.WriteToContext(ctx);
1951
1952 hndDebugPrint("[hndfsm] send 2 remote: sending e=" + e + " id=" + e.GetEventID() + " p=" + p + " e=" + e.DumpToString());
1953 p.StoreInputForRemotes(ctx);
1954 }
1955 }
1956
1958 {
1959 super.OnHandsExitedStableState(src, dst);
1960
1961 hndDebugPrint("[hndfsm] hand fsm exit stable src=" + src.Type().ToString());
1962 }
1963
1965 {
1966 super.OnHandsEnteredStableState(src, dst);
1967
1968 hndDebugPrint("[hndfsm] hand fsm entered stable dst=" + dst.Type().ToString());
1969 }
1970
1972 {
1973 super.OnHandsStateChanged(src, dst);
1974
1975 hndDebugPrint("[hndfsm] hand fsm changed state src=" + src.Type().ToString() + " ---> dst=" + dst.Type().ToString());
1976
1977 if (src.IsIdle())
1978 OnHandsExitedStableState(src, dst);
1979
1980 if (dst.IsIdle())
1981 OnHandsEnteredStableState(src, dst);
1982
1983#ifdef BOT
1985 if (p && p.m_Bot)
1986 {
1987 p.m_Bot.ProcessEvent(new BotEventOnItemInHandsChanged(p));
1988 }
1989#endif
1990 }
1991
1993 {
1994 if (!IsProcessing())
1995 {
1996 EntityAI itemInHands = GetEntityInHands();
1997
1998 InventoryLocation handInventoryLocation();
1999 handInventoryLocation.SetHands(GetInventoryOwner(), itemInHands);
2000
2001 InventoryValidation validation();
2002 if (e.CanPerformEventEx(validation))
2003 {
2004 m_DeferredEvent = new DeferredHandEvent(mode, e);
2005 if (m_DeferredEvent.ReserveInventory(this))
2006 {
2007 return true;
2008 }
2009 }
2010
2011 m_DeferredEvent = null;
2012
2014 if (!GetGame().IsMultiplayer() || GetGame().IsClient())
2015 {
2017 OnInventoryFailure(InventoryCommandType.HAND_EVENT, validation.m_Reason, e.GetSrc(), e.GetDst());
2018 }
2019 else
2020 {
2021 ScriptInputUserData serializer();
2022
2024 serializer.Write(validation.m_Reason);
2025
2026 GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY_FAILURE, serializer);
2027 }
2028 }
2029
2030 return false;
2031 }
2032
2033
2034 void HandleHandEvent(DeferredEvent deferred_event)
2035 {
2037 InventoryValidation validation();
2038
2039 DeferredHandEvent deferred_hand_event = DeferredHandEvent.Cast(deferred_event);
2040 if (deferred_hand_event)
2041 {
2042 #ifdef DEVELOPER
2044 {
2045 Debug.InventoryHFSMLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp(), "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString() );
2046 }
2047 #endif
2048
2049
2050 hndDebugPrint("[inv] HumanInventory::HandEvent(" + typename.EnumToString(InventoryMode, deferred_hand_event.m_mode) + ") ev=" + deferred_hand_event.m_event.DumpToString());
2051
2052 switch (deferred_hand_event.m_mode)
2053 {
2054 case InventoryMode.PREDICTIVE:
2055 #ifdef DEVELOPER
2057 {
2058 Debug.InventoryHFSMLog("PREDICTIVE", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString() );
2059 }
2060 #endif
2061 deferred_hand_event.ClearInventoryReservation(this);
2062 if (deferred_hand_event.m_event.CanPerformEventEx(validation))
2063 {
2065 ProcessHandEvent(deferred_hand_event.m_event);
2066 }
2067 break;
2068
2069 case InventoryMode.JUNCTURE:
2070 #ifdef DEVELOPER
2072 {
2073 Debug.InventoryHFSMLog("JUNCTURE", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString() );
2074 }
2075 #endif
2076 deferred_hand_event.ClearInventoryReservation(this);
2077 if (deferred_hand_event.m_event.CanPerformEventEx(validation))
2078 {
2079 deferred_hand_event.ReserveInventory(this);
2081
2082 //Functionality to prevent desync when two players perform interfering action at the same time
2083 EntityAI itemSrc = deferred_hand_event.m_event.GetSrcEntity();
2084 EntityAI itemDst = null;
2085 if (deferred_hand_event.m_event.GetDst())
2086 itemDst = deferred_hand_event.m_event.GetDst().GetItem();
2087 if (itemSrc)
2088 EnableMovableOverride(itemSrc);
2089 if (itemDst)
2090 EnableMovableOverride(itemDst);
2091 }
2092 break;
2093
2094 case InventoryMode.LOCAL:
2095 #ifdef DEVELOPER
2097 {
2098 Debug.InventoryHFSMLog("LOCAL", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString() );
2099 }
2100 #endif
2101 deferred_hand_event.ClearInventoryReservation(this);
2102 ProcessHandEvent(deferred_hand_event.m_event);
2103 //PostHandEvent(deferred_hand_event.m_event);
2104 break;
2105
2106 case InventoryMode.SERVER:
2107 #ifdef DEVELOPER
2109 {
2110 Debug.InventoryHFSMLog("SERVER", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString() );
2111 }
2112 #endif
2113 hndDebugPrint("[inv] DZPI::HandEvent(" + typename.EnumToString(InventoryMode, deferred_hand_event.m_mode) + ")");
2114 if (!deferred_hand_event.m_event.IsServerSideOnly())
2115 {
2116 if (GetDayZPlayerOwner().IsAlive())
2117 {
2119 }
2120 else
2121 {
2123 }
2124 }
2125 else
2126 {
2127 ProcessHandEvent(deferred_hand_event.m_event);
2128 }
2129 break;
2130
2131 default:
2132 Error("HumanInventory::HandEvent - Invalid mode");
2133 }
2134 }
2135 }
2136
2138 {
2139 super.HandleInventoryManipulation();
2141 {
2146
2147 m_DeferredEvent = null;
2148 }
2149 }
2150
2151
2152
2154 {
2155 return !m_FSM.GetCurrentState().IsIdle() || m_DeferredEvent || m_DeferredPostedHandEvent;
2156 }
2157
2158 bool PlayerCheckRequestSrc ( notnull InventoryLocation src, float radius )
2159 {
2160 bool result = true;
2161
2162 EntityAI ent = src.GetParent();
2163 if ( ent )
2164 {
2165 PlayerBase player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
2166 if (player)
2167 {
2168 if ( GetDayZPlayerOwner() != player )
2169 {
2170 if (player.IsAlive())
2171 {
2172 if (!player.IsRestrained() && !player.IsUnconscious())
2173 {
2174 return false;
2175 }
2176 }
2177 }
2178 }
2179 }
2180
2181 if ( result )
2182 {
2183 result = CheckRequestSrc( GetManOwner(), src, radius);
2184 }
2185
2186 return result;
2187 }
2188
2189 bool PlayerCheckRequestDst ( notnull InventoryLocation src, notnull InventoryLocation dst, float radius )
2190 {
2191 bool result = true;
2192
2193 EntityAI ent = dst.GetParent();
2194 if ( ent )
2195 {
2196 PlayerBase player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
2197 if (player)
2198 {
2199 if ( GetDayZPlayerOwner() != player )
2200 {
2201 if (player.IsAlive())
2202 {
2203 if (!player.IsRestrained() && !player.IsUnconscious())
2204 {
2205 return false;
2206 }
2207 }
2208 }
2209 }
2210 }
2211
2212 if ( result )
2213 {
2214 result = CheckMoveToDstRequest( GetManOwner(), src, dst, radius);
2215 }
2216
2217 return result;
2218 }
2219
2220 bool PlayerCheckSwapItemsRequest( notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, float radius)
2221 {
2222 bool result = true;
2223
2224 EntityAI ent = dst1.GetParent();
2225 PlayerBase player;
2226 if ( ent )
2227 {
2228 player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
2229 if (player)
2230 {
2231 if ( GetDayZPlayerOwner() != player )
2232 {
2233 if (player.IsAlive())
2234 {
2235 if (!player.IsRestrained() && !player.IsUnconscious())
2236 {
2237 return false;
2238 }
2239 }
2240 }
2241 }
2242 }
2243
2244 ent = dst2.GetParent();
2245 if ( ent )
2246 {
2247 player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
2248 if (player)
2249 {
2250 if ( GetDayZPlayerOwner() != player )
2251 {
2252 if (player.IsAlive())
2253 {
2254 if (!player.IsRestrained() && !player.IsUnconscious())
2255 {
2256 return false;
2257 }
2258 }
2259 }
2260 }
2261 }
2262
2263
2264 if ( result )
2265 {
2266 result = CheckSwapItemsRequest( GetManOwner(), src1, src2, dst1, dst2, GameInventory.c_MaxItemDistanceRadius);
2267 }
2268
2269 return result;
2270
2271 }
2272
2273 bool PlayerCheckDropRequest ( notnull InventoryLocation src, float radius )
2274 {
2275 bool result = true;
2276
2277 EntityAI ent = src.GetParent();
2278 if ( ent )
2279 {
2280 PlayerBase player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
2281 if (player)
2282 {
2283 if ( GetDayZPlayerOwner() != player )
2284 {
2285 if (player.IsAlive())
2286 {
2287 if (!player.IsRestrained() && !player.IsUnconscious())
2288 {
2289 return false;
2290 }
2291 }
2292 }
2293 }
2294 }
2295
2296 if ( result )
2297 {
2298 result = CheckDropRequest( GetManOwner(), src, radius);
2299 }
2300
2301 return result;
2302 }
2303};
2304
void syncDebugPrint(string s)
Definition Debug.c:1
void inventoryDebugPrint(string s)
Definition Debug.c:19
InventoryCommandType
Definition Inventory.c:3
InventoryMode
Definition Inventory.c:20
InventoryValidationResult
Definition Inventory.c:28
InventoryValidationReason
Definition Inventory.c:35
const int INPUT_UDT_INVENTORY
Definition _constants.c:9
const int INPUT_UDT_HAND_REMOTE_EVENT
Definition _constants.c:14
void wpnDebugSpamALot(string s)
Definition Debug.c:21
void wpnDebugPrint(string s)
Definition Debug.c:9
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:861
override Widget Init()
Definition DayZGame.c:122
protected ref HandAnimatedForceSwapping_Inst m_FSwappingInst
protected ref HandAnimatedTakingFromAtt m_Taking
deferred weapon event
override void OnAfterStoreLoad()
engine reaction to load from database originates in: engine - Person::BinLoad script - PlayerBase....
bool PlayerCheckDropRequest(notnull InventoryLocation src, float radius)
bool ValidateSyncMove(inout Serializer ctx, InventoryValidation validation)
bool ValidateHandEvent(inout Serializer ctx, InventoryValidation validation)
void EnableMovableOverride(EntityAI item)
bool ProcessInputData(ParamsReadContext ctx, bool isJuncture, bool isRemote)
protected ref HandAnimatedMovingToAtt m_MovingTo
m_DeferredEvent
void HandleHandEvent(DeferredEvent deferred_event)
protected void OnHandleStoredInputUserData(ParamsReadContext ctx)
bool IsProcessing()
void HandleWeaponEvents(float dt, out bool exitIronSights)
proto native void StoreInputUserData(ParamsReadContext ctx)
void SyncHandEventToRemote(HandEventBase e)
void HandleTakeToDst(DeferredEvent deferred_event)
void DeferredForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
bool ValidateDestroy(inout Serializer ctx, InventoryValidation validation)
void CheckForRope(InventoryLocation src, InventoryLocation dst)
protected ref HandAnimatedForceSwapping m_FSwapping
bool PlayerCheckRequestSrc(notnull InventoryLocation src, float radius)
void AbortWeaponEvent()
override void OnInventoryFailure(InventoryCommandType type, InventoryValidationReason reason, InventoryLocation src, InventoryLocation dst)
void PostWeaponEvent(WeaponEventBase e)
override void NetSyncCurrentStateID(int id)
protected void OnHandleStoredJunctureData(ParamsReadContext ctx)
override void OnHandsEnteredStableState(HandStateBase src, HandStateBase dst)
bool IsServerOrLocalPlayer()
override bool TakeToDst(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
override void OnInventoryJunctureFailureFromServer(ParamsReadContext ctx)
void RemoveMovableOverride(EntityAI item)
override void HandleInventoryManipulation()
override bool OnInventoryJunctureFromServer(ParamsReadContext ctx)
protected ref HandEventBase m_DeferredPostedHandEvent
override bool SwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
override bool OnInventoryJunctureRepairFromServer(ParamsReadContext ctx)
void DeferredTakeToDst(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
override void OnHandsExitedStableState(HandStateBase src, HandStateBase dst)
void CancelHandEvent()
cancels any handevents that will be executed this frame @NOTE: this is used in situations where the p...
override void OnHandsStateChanged(HandStateBase src, HandStateBase dst)
bool OnHandEventForRemote(ParamsReadContext ctx)
ref InventoryLocation m_dst1
ref WeaponEventBase m_DeferredWeaponEvent
deferred hand event
void OnInputUserDataForRemote(ParamsReadContext ctx)
DayZPlayer GetDayZPlayerOwner()
override bool ForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
bool ValidateSwap(inout Serializer ctx, InventoryValidation validation)
void HandleSwapEntities(DeferredEvent deferred_event)
bool PlayerCheckSwapItemsRequest(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, float radius)
void HandleInventory(float dt)
void DeferredWeaponFailed()
ref InventoryLocation m_dst
void HandleForceSwapEntities(DeferredEvent deferred_event)
ref Timer m_DeferredWeaponTimer
bool PlayerCheckRequestDst(notnull InventoryLocation src, notnull InventoryLocation dst, float radius)
bool OnEventForRemoteWeapon(ParamsReadContext ctx)
override void OnServerInventoryCommand(ParamsReadContext ctx)
proto native void StoreJunctureData(ParamsReadContext ctx)
protected ref HandAnimatedSwapping m_Swapping
ref InventoryLocation m_dst2
DeferredSwapEntities m_item1
override bool HandEvent(InventoryMode mode, HandEventBase e)
void CancelWeaponEvent()
class DeferredEvent m_src
EntityAI m_item2
static void SendServerHandEventViaJuncture(notnull DayZPlayer player, HandEventBase e)
bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
proto string ToString()
WeaponEventBase WeaponAnimEventFactory(WeaponEvents type, DayZPlayer p=NULL, Magazine m=NULL)
creates animation system events
Definition Events.c:251
WeaponEventBase CreateWeaponEventFromContext(ParamsReadContext ctx)
Definition Events.c:281
WeaponEventID
identifier for events. mainly for rpc purposes
Definition Events.c:6
ProcessEventResult
Definition FSMBase.c:33
void fsmDebugSpam(string s)
Definition HFSMBase.c:5
bool CheckRequestSrc()
Definition Hand_Events.c:88
bool IsAuthoritative()
Definition Hand_Events.c:48
bool ReserveInventory()
HandEventBase HandAnimEventFactory(WeaponEvents type, Man p=null, InventoryLocation src=null)
JunctureRequestResult
Definition Hand_Events.c:28
HandEventID
events
Definition Hand_Events.c:7
bool IsOwner()
Definition Hand_Events.c:53
void ClearInventoryReservation()
bool IsProxy()
Definition Hand_Events.c:58
void hndDebugSpam(string s)
Definition HandFSM.c:9
void hndDebugSpamALot(string s)
Definition HandFSM.c:13
void hndDebugPrint(string s)
Definition HandFSM.c:1
FSMTransition< HandStateBase, HandEventBase, HandActionBase, HandGuardBase > HandTransition
Definition HandFSM.c:20
bool TryAcquireInventoryJunctureFromServer(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst)
Definition Junctures.c:2
bool TryAcquireTwoInventoryJuncturesFromServer(notnull Man player, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
Definition Junctures.c:29
float GetTime()
proto native void ObjectDelete(Object obj)
proto native DayZPlayer GetPlayer()
Super root of all classes in Enforce script.
Definition EnScript.c:11
override void OnItemInHandsChanged()
Definition Debug.c:14
static void InventoryHFSMLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition Debug.c:158
static void InventoryMoveLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition Debug.c:148
void ClearInventoryReservation(HumanInventory inventory)
bool ReserveInventory(HumanInventory inventory)
InventoryMode m_mode
void DeferredHandEvent(InventoryMode mode, HandEventBase e)
override bool ReserveInventory(HumanInventory inventory)
ref HandEventBase m_event
override void ClearInventoryReservation(HumanInventory inventory)
override bool ReserveInventory(HumanInventory inventory)
void DeferredSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
override void ClearInventoryReservation(HumanInventory inventory)
ref InventoryLocation m_dst1
ref InventoryLocation m_dst2
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
Definition Inventory.c:638
static bool MakeSrcAndDstForSwap(notnull EntityAI item1, notnull EntityAI item2, out InventoryLocation src1, out InventoryLocation src2, out InventoryLocation dst1, out InventoryLocation dst2)
helper function for swap
Definition Inventory.c:1155
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:683
const float c_MaxItemDistanceRadius
anti-cheats
Definition Inventory.c:783
const int c_InventoryReservationTimeoutShortMS
Definition Inventory.c:684
bool ClearInventoryReservationEx(EntityAI item, InventoryLocation dst)
Definition Inventory.c:733
bool AddInventoryReservationEx(EntityAI item, InventoryLocation dst, int timeout_ms)
Definition Inventory.c:687
static bool MakeSrcAndDstForForceSwap(notnull EntityAI item1, notnull EntityAI item2, out InventoryLocation src1, out InventoryLocation src2, out InventoryLocation dst1, notnull InventoryLocation dst2)
helper function for ForceSwap
Definition Inventory.c:1167
static proto native bool LocationCanMoveEntity(notnull InventoryLocation src, notnull InventoryLocation dst)
queries if the entity contained in inv_loc.m_item can be moved to another location This is a shorthan...
static bool LocationCanMoveEntitySyncCheck(notnull InventoryLocation src, notnull InventoryLocation dst)
Definition Inventory.c:363
Abstracted event, not to be used, only inherited.
override bool ReserveInventory()
override EntityAI GetSecondSrcEntity()
override void ClearInventoryReservation()
override string DumpToString()
override bool AcquireInventoryJunctureFromServer(notnull Man player)
override void WriteToContext(ParamsWriteContext ctx)
override bool IsServerSideOnly()
override bool CheckRequestSrc()
override InventoryLocation GetDst()
represent hand state base
override bool IsIdle()
idle state does not expect any animation events
proto native int GetRunningAction()
returns -1 when no action is running or RELOAD,MECHANISM, ....
proto native bool IsActionFinished()
proto native int IsEvent()
return -1 when there is no event, otherwise it returns pId of event from animation
proto native int GetRunningActionType()
returns -1 when no action is running or appropriate action type
inventory for plain man/human
HumanInventory... with FSM (synchronous, no anims)
static void SerializeSwap(ParamsWriteContext ctx, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, bool skippedSwap)
swap
static void SendInputUserDataHandEvent(HandEventBase e)
static void SendServerHandEventViaInventoryCommand(notnull Man player, HandEventBase e)
static void SendInputUserDataSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, bool skippedSwap=false)
static void SerializeHandEvent(ParamsWriteContext ctx, HandEventBase e)
hand
static void SendInputUserDataMove(int type, notnull InventoryLocation src, notnull InventoryLocation dst)
static void SerializeMove(ParamsWriteContext ctx, int type, notnull InventoryLocation src, notnull InventoryLocation dst)
move
InventoryLocation.
proto native bool IsValid()
verify current set inventory location
proto native void SetHands(notnull EntityAI parent, EntityAI e)
sets current inventory location type to Hands
proto native EntityAI GetParent()
returns parent of current inventory location
bool ReadFromContext(ParamsReadContext ctx)
proto native EntityAI GetItem()
returns item of current inventory location
static string DumpToStringNullSafe(InventoryLocation loc)
InventoryValidationResult m_Result
Definition Inventory.c:46
InventoryValidationReason m_Reason
Definition Inventory.c:47
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:620
static bool IsInventoryMoveLogEnable()
Definition Debug.c:600
static bool IsWeaponLogEnable()
Definition Debug.c:640
proto static native bool CanStoreInputUserData()
proto native bool CopyFrom(ParamsReadContext other)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
proto native bool CanWrite()
override void Stop()
signalize mechanism manipulation
Definition Events.c:35
WeaponEventID GetEventID()
returns id from enum WeaponEventID
Definition Events.c:42
string DumpToString()
Definition Events.c:62
proto native void StoreInputForRemotes(ParamsWriteContext ctx)
DayZPlayerInstanceType
defined in C++
proto native DayZPlayerInstanceType GetInstanceType()
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.
WeaponActions
actions
Definition human.c:798
WeaponEvents
events
Definition human.c:945
string WeaponActionTypeToString(int A, int AT)
Definition human.c:925