Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
inventory.c
Go to the documentation of this file.
1 //-------------------------------------------------------
3 {
4  MOVE,
7  SWAP,
12 };
14 {
15  TAKE,
16  SWAP,
17  //LOAD, ///< load mag from ground
18 };
19 
22 {
27 };
28 
30 {
32  JUNCTURE,
34 };
35 
37 {
41 };
42 
44 {
45  bool m_IsJuncture = false;
46  bool m_IsRemote = false;
47 
50 
51  bool IsAuthoritative()
52  {
53  return !m_IsJuncture && !m_IsRemote;
54  }
55 };
56 
58 {
61 }
62 
63 enum FindInventoryReservationMode
64 {
66  LEGACY,
68  ITEM,
70  DST,
72  EQUAL,
73 };
74 
79 {
80  protected static int m_inventory_check_context = InventoryCheckContext.DEFAULT;
81 
82 //-------------------------------------------------------
85 
90  proto native EntityAI GetInventoryOwner();
91 
92 #ifdef DEVELOPER
93 
97  proto native void DumpInventoryDebug();
98 
103  static proto native void DumpStaticInventoryDebug();
104 #endif
105 
116  proto native bool HasEntityInInventory(notnull EntityAI item);
117 
125  proto native bool EnumerateInventory(InventoryTraversalType tt, out array<EntityAI> items);
126 
132  proto native int CountInventory();
133 
134 
136  proto native CargoBase GetCargo();
137  proto native CargoBase GetCargoFromIndex(int index);
141  proto native EntityAI CreateEntityInCargo(string typeName);
148  proto native EntityAI CreateEntityInCargoEx(string typeName, int idx, int row, int col, bool flip);
149 
150  proto native bool HasEntityInCargo(notnull EntityAI e);
151  proto native bool HasEntityInCargoEx(notnull EntityAI e, int idx, int row, int col);
152  proto native bool CanAddEntityInCargo(notnull EntityAI e, bool flip);
153  proto native bool CanAddEntityInCargoEx(notnull EntityAI e, int idx, int row, int col, bool flip);
154  proto native bool CanAddEntityInCargoExLoc(InventoryLocation loc);
155  proto native bool TestAddEntityInCargoEx(notnull EntityAI e, int idx, int row, int col, bool flip, bool do_resevation_check, bool do_item_check, bool do_lock_check, bool do_occupancy_test, bool do_script_check, bool do_script_load_check);
156  proto native bool TestAddEntityInCargoExLoc(notnull InventoryLocation loc, bool do_resevation_check, bool do_item_check, bool do_lock_check, bool do_occupancy_test, bool do_script_check, bool do_script_load_check);
157  //proto native bool AddEntityInCargo (notnull EntityAI owner, EntityAI cargo);
158  //proto native bool AddEntityInCargoEx (notnull EntityAI owner, notnull EntityAI e, int idx, int row, int col);
159  proto native bool CanRemoveEntityInCargo(notnull EntityAI e);
160  proto native bool CanRemoveEntityInCargoEx(notnull EntityAI e, int idx, int row, int col);
162 
163 
165 
169  proto native int GetSlotId(int index);
173  proto native int GetSlotIdCount();
178  proto native int GetAttachmentSlotId(int index);
182  proto native int GetAttachmentSlotsCount();
186  /*proto native*/bool HasAttachmentSlot(int slotId) //TODO - flip to code
187  {
188  int count = GetAttachmentSlotsCount();
189  for (int i = 0; i < count; i++)
190  {
191  if (GetAttachmentSlotId(i) == slotId)
192  return true;
193  }
194  return false;
195  }
199  proto native bool HasInventorySlot(int slotId);
203  proto native int AttachmentCount();
207  proto native EntityAI CreateAttachment(string typeName);
213  proto native EntityAI CreateAttachmentEx(string typeName, int slotId);
218  proto native EntityAI GetAttachmentFromIndex(int index);
222  proto native EntityAI FindAttachment(int slot);
226  proto native EntityAI FindAttachmentByName(string slotName);
230  proto native bool HasAttachment(notnull EntityAI e);
234  proto native bool HasAttachmentEx(notnull EntityAI e, int slot);
239  proto native bool CanAddAttachment(notnull EntityAI e);
244  proto native bool CanAddAttachmentEx(notnull EntityAI e, int slot);
245 
246  proto native bool CanRemoveAttachment(EntityAI attachment);
247  proto native bool CanRemoveAttachmentEx(EntityAI attachment, int slot);
248 
249  //proto native bool RemoveAttachment(EntityAI attachment);
250  //proto native bool RemoveAttachmentEx(EntityAI attachment, int slot);
251 
255  proto native EntityAI FindPlaceholderForSlot(int slot);
256  proto native bool IsPlaceholderEntity(notnull Object e);
258 
259 
266  proto native bool GetCurrentInventoryLocation(out notnull InventoryLocation loc);
267 
274  proto native bool FindFreeLocationFor(notnull EntityAI item, FindInventoryLocationType flags, out notnull InventoryLocation loc);
281  proto native bool FindFreeLocationForEx(notnull EntityAI item, FindInventoryLocationType flags, notnull InventoryLocation exclude, out notnull InventoryLocation loc);
282 
289  proto native bool FindFirstFreeLocationForNewEntity(string item_type, FindInventoryLocationType flags, out notnull InventoryLocation loc);
290 
323  proto native int FindFreeLocationsFor(notnull EntityAI item, FindInventoryLocationType flags, out notnull array<ref InventoryLocation> locs);
324 
331  static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation);
339  static proto native EntityAI LocationCreateLocalEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation);
345  static proto native bool LocationCanAddEntity(notnull InventoryLocation inv_loc);
346 
347  //Added script check to LocationCanAddEntity
348  static bool LocationCanAddEntityEx(notnull InventoryLocation inv_loc)
349  {
350  return LocationCanAddEntity(inv_loc);
351  }
352 
358  static proto native bool LocationTestAddEntity(notnull InventoryLocation inv_loc, bool do_resevation_check, bool do_item_check, bool do_lock_check, bool do_occupancy_test, bool do_script_check, bool do_script_load_check);
364  static proto native bool LocationCanRemoveEntity(notnull InventoryLocation inv_loc);
371  static proto native bool LocationCanMoveEntity(notnull InventoryLocation src, notnull InventoryLocation dst);
372 
373  static int GetInventoryCheckContext()
374  {
375  return m_inventory_check_context;
376  }
377 
378  static bool LocationCanMoveEntitySyncCheck(notnull InventoryLocation src, notnull InventoryLocation dst)
379  {
380  m_inventory_check_context = InventoryCheckContext.SYNC_CHECK;
381  bool result = LocationCanMoveEntity(src, dst);
382  m_inventory_check_context = InventoryCheckContext.DEFAULT;
383  return result;
384 
385  }
391  static proto native EntityAI LocationGetEntity(notnull InventoryLocation inv_loc);
392 
393 
395  bool IsInCargo()
396  {
398  GetCurrentInventoryLocation(lcn);
399  if (lcn.GetType() == InventoryLocationType.CARGO)
400  {
401  return true;
402  }
403 
404  return false;
405  }
406 
408  bool IsAttachment()
409  {
411  GetCurrentInventoryLocation(lcn);
412  if (lcn.GetType() == InventoryLocationType.ATTACHMENT)
413  {
414  return true;
415  }
416 
417  return false;
418  }
419 
421  bool IsCargoInHiearchy()
422  {
424  EntityAI ent = GetInventoryOwner();
425  while (ent)
426  {
427  if (ent.GetInventory().GetCurrentInventoryLocation(lcn) && lcn.IsValid())
428  {
429  if (lcn.GetType() == InventoryLocationType.CARGO || lcn.GetType() == InventoryLocationType.PROXYCARGO)
430  return true;
431  }
432 
433  ent = ent.GetHierarchyParent();
434  }
435 
436  return false;
437  }
438 
440  bool GetCurrentAttachmentSlotInfo(out int slot_id, out string slot_name)
441  {
442  slot_id = InventorySlots.INVALID;
443  slot_name = "";
445  GetCurrentInventoryLocation(lcn);
446  if (lcn.GetType() == InventoryLocationType.ATTACHMENT)
447  {
448  slot_id = lcn.GetSlot();
449  slot_name = InventorySlots.GetSlotName(slot_id);
450  return true;
451  }
452  return false;
453  }
454 
455  static void OnServerInventoryCommandStatic(ParamsReadContext ctx)
456  {
457  int tmp = -1;
458  ctx.Read(tmp);
459 
460  int type = -1;
461  if (!ctx.Read(type))
462  return;
463 
464  switch (type)
465  {
466  case InventoryCommandType.SYNC_MOVE:
467  {
470 
471  src.ReadFromContext(ctx);
472  dst.ReadFromContext(ctx);
473  if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms ServerInventoryCommand cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
474 
475  if (!src.GetItem() || !dst.GetItem())
476  {
477  LogError("[syncinv] ServerInventoryCommand (cmd=SYNC_MOVE) dropped, item not in bubble");
478  break; // not in bubble
479  }
480 
481  LocationSyncMoveEntity(src, dst);
482  break;
483  }
484 
485  case InventoryCommandType.HAND_EVENT:
486  {
487  HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
488  if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms ServerInventoryCommand cmd=" + typename.EnumToString(InventoryCommandType, type) + " event=" + e.DumpToString());
489 
490  if (!e.GetSrcEntity())
491  {
492  Error("[syncinv] ServerInventoryCommand (cmd=HAND_EVENT) dropped, item not in bubble");
493  break; // not in bubble
494  }
495  e.m_Player.GetHumanInventory().ProcessHandEvent(e);
496  break;
497  }
498 
499  case InventoryCommandType.FORCESWAP:
500  case InventoryCommandType.SWAP:
501  {
506  src1.ReadFromContext(ctx);
507  src2.ReadFromContext(ctx);
508  dst1.ReadFromContext(ctx);
509  dst2.ReadFromContext(ctx);
510 
511  if (src1.IsValid() && src2.IsValid() && dst1.IsValid() && dst2.IsValid())
512  {
513  if (LogManager.IsSyncLogEnable()) syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms ServerInventoryCommand Swap src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
514 
515  LocationSwap(src1, src2, dst1, dst2);
516  }
517  else
518  Error("ServerInventoryCommand - cannot swap, invalid location input: src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
519 
520  break;
521  }
522  }
523  }
524 
530  static proto native bool LocationAddEntity(notnull InventoryLocation inv_loc);
536  static proto native bool LocationRemoveEntity(notnull InventoryLocation inv_loc);
537 
543  static proto native bool LocationMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc);
544 
551  static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc);
552 
558  static proto native bool LocationSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2);
559 
565  static proto native bool ServerLocationMoveEntity(notnull EntityAI item, ParamsWriteContext ctx);
566 
574  static proto native bool ServerLocationSyncMoveEntity(Man player, notnull EntityAI item, ParamsWriteContext ctx);
575 
581  static proto native bool ServerLocationSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, ParamsWriteContext ctx);
582 
588  static proto native bool ServerHandEvent(notnull Man player, notnull EntityAI item, ParamsWriteContext ctx);
589 
599  static proto native bool PrepareDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix = false, int conflictCheckDepth = -1);
600  static proto native bool TestDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix = false, int conflictCheckDepth = -1);
601 
612  static proto native bool CanSwapEntities(notnull EntityAI item1, notnull EntityAI item2);
613 
614  static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
615  {
616  int slot;
619 
620  item2.GetInventory().GetCurrentInventoryLocation(il2);
621  slot = il2.GetSlot();
622 
623  if (item1.GetQuantity() > item1.GetTargetQuantityMax(slot))
624  return false;
625 
626 
627  item1.GetInventory().GetCurrentInventoryLocation(il1);
628  slot = il1.GetSlot();
629 
630  if (item2.GetQuantity() > item2.GetTargetQuantityMax(slot))
631  return false;
632 
633  if (!item1.CanSwapEntities(item2, il2, il1) || !item2.CanSwapEntities(item1, il1, il2))
634  {
635  return false;
636  }
637 
638  return CanSwapEntities(item1,item2);
639  }
640 
650  static proto native bool CanForceSwapEntities(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst);
651  static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
652  {
653  if (!CanForceSwapEntities(item1, item1_dst, item2, item2_dst) )
654  return false;
655 
656  int slot;
658 
659  if (!item1.CanBeFSwaped())
660  return false;
661 
662  if ( item1_dst == null)
663  {
664  item2.GetInventory().GetCurrentInventoryLocation(il);
665  slot = il.GetSlot();
666  }
667  else
668  {
669  slot = item1_dst.GetSlot();
670  }
671 
672  if ( item1.GetQuantity() > item1.GetTargetQuantityMax(slot) )
673  return false;
674 
675  if ( item2_dst == null)
676  {
677  item1.GetInventory().GetCurrentInventoryLocation(il);
678  slot = il.GetSlot();
679  }
680  else
681  {
682  slot = item2_dst.GetSlot();
683  }
684 
685  if (!item1.CanSwapEntities(item2, item2_dst, item1_dst) || !item2.CanSwapEntities(item1, item1_dst, item2_dst))
686  {
687  return false;
688  }
689 
690  if ( item2.GetQuantity() > item2.GetTargetQuantityMax(slot) )
691  return false;
692 
693  return true;
694  }
695 
696  proto native bool CanAddSwappedEntity(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2);
697 
699  const int c_InventoryReservationTimeoutMS = 5000;
700  const int c_InventoryReservationTimeoutShortMS = 3000;
701 
702  static proto native bool AddInventoryReservation(EntityAI item, InventoryLocation dst, int timeout_ms);
703  bool AddInventoryReservationEx(EntityAI item, InventoryLocation dst, int timeout_ms)
704  {
705  if (GetGame().IsMultiplayer() && GetGame().IsServer() )
706  return true;
707 
708  bool ret_val = AddInventoryReservation(item, dst, timeout_ms);
709  #ifdef DEVELOPER
710  if ( LogManager.IsInventoryReservationLogEnable() )
711  {
712  DayZPlayer player = GetGame().GetPlayer();
713  if ( player )
714  {
715  if (item)
716  Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / " + item.ToString() + " / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "AddInventoryReservation", player.ToString() );
717  else
718  Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / null / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "AddInventoryReservation", player.ToString() );
719  }
720  }
721  #endif
722  return ret_val;
723  }
724 
725  static proto native bool ExtendInventoryReservation(EntityAI item, InventoryLocation dst, int timeout_ms);
726  bool ExtendInventoryReservationEx(EntityAI item, InventoryLocation dst, int timeout_ms)
727  {
728  if (GetGame().IsMultiplayer() && GetGame().IsServer() )
729  return true;
730 
731  bool ret_val = ExtendInventoryReservation(item,dst,timeout_ms);
732  #ifdef DEVELOPER
733  if ( LogManager.IsInventoryReservationLogEnable() )
734  {
735  DayZPlayer player = GetGame().GetPlayer();
736  if ( player )
737  {
738  if (item)
739  Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / " + item.ToString() + " / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ExtendInventoryReservation", player.ToString() );
740  else
741  Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / null / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ExtendInventoryReservation", player.ToString() );
742  }
743  }
744  #endif
745  return ret_val;
746  }
747 
748  static proto native bool ClearInventoryReservation(EntityAI item, InventoryLocation dst);
749  bool ClearInventoryReservationEx(EntityAI item, InventoryLocation dst)
750  {
751  if (GetGame().IsMultiplayer() && GetGame().IsServer() )
752  return true;
753 
754  bool ret_val = ClearInventoryReservation(item,dst);
755  #ifdef DEVELOPER
756  if ( LogManager.IsInventoryReservationLogEnable() )
757  {
758  DayZPlayer player = GetGame().GetPlayer();
759  if ( player )
760  {
761  if (item)
762  Debug.InventoryMoveLog("Reservation cleared result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / " + item.ToString() + " / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ClearInventoryReservation", player.ToString() );
763  else
764  Debug.InventoryMoveLog("Reservation cleared result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / null / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ClearInventoryReservation", player.ToString() );
765  }
766  }
767  #endif
768  return ret_val;
769  }
770 
772  static proto native bool HasInventoryReservation(EntityAI item, InventoryLocation dst);
774  static proto native bool HasInventoryReservationCanAdd(EntityAI item, InventoryLocation dst);
775 
777  static proto native bool HasInventoryReservationEx(EntityAI item, InventoryLocation dst, FindInventoryReservationMode itemMode, FindInventoryReservationMode parentMode);
778  static proto native bool GetInventoryReservationCount(EntityAI item, InventoryLocation dst);
779  proto native int GetAnyInventoryReservationCount();
781 
783  proto native bool CanLockInventoryWithKey(notnull EntityAI key);
784  proto native bool CanUnlockInventoryWithKey(notnull EntityAI key);
785  proto native void LockInventoryWithKey(notnull EntityAI key);
786  proto native void UnlockInventoryWithKey(notnull EntityAI key);
787  proto native bool HasKeys();
788 
789  proto native void LockInventory(int lockType);
790  proto native void UnlockInventory(int lockType);
791  proto native int GetScriptLockCount();
792  proto native bool IsInventoryUnlocked();
793  proto native bool IsInventoryLocked();
794  proto native bool IsInventoryLockedForLockType(int lockType);
795  proto native bool SetSlotLock(int slot, bool locked);
796  proto native bool GetSlotLock(int slot);
798 
800  const float c_MaxItemDistanceRadius = 2.5;
801  static proto native bool CheckRequestSrc(notnull Man requestingPlayer, notnull InventoryLocation src, float radius);
802  static proto native bool CheckDropRequest(notnull Man requestingPlayer, notnull InventoryLocation src, float radius);
803  static proto native bool CheckTakeItemRequest(notnull Man requestingPlayer, notnull InventoryLocation src, notnull InventoryLocation dst, float radius);
804  static proto native bool CheckMoveToDstRequest(notnull Man requestingPlayer, notnull InventoryLocation src, notnull InventoryLocation dst, float radius);
805  static proto native bool CheckSwapItemsRequest(notnull Man requestingPlayer, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, float radius);
806  static proto native bool CheckManipulatedObjectsDistances(notnull EntityAI e0, notnull EntityAI e1, float radius);
808 
812 
816  void Init()
817  {
818  GetInventoryOwner().OnInventoryInit();
819  }
820 
822  bool OnStoreLoad(ParamsReadContext ctx, int version)
823  {
824  return true;
825  }
826  void OnAfterStoreLoad();
828  void OnStoreSave(ParamsWriteContext ctx);
829 
830  void EEInit()
831  {
833  if (GetCurrentInventoryLocation(src))
834  {
835  if (src.GetType() == InventoryLocationType.HANDS)
836  {
837  Man man = Man.Cast(src.GetParent());
838  if (man)
839  {
840  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("Inventory::EEInit - Man=" + man + " item=" + this);
841  man.GetHumanInventory().OnEntityInHandsCreated(src);
842  }
843  }
844  }
845  }
846 
847  void EEDelete(EntityAI parent)
848  {
849  EntityAI item = GetInventoryOwner();
850  Man player = item.GetHierarchyRootPlayer();
851  if (player)
852  player.GetInventory().ClearInventoryReservationEx(item, null);
853  }
854 
861  EntityAI CreateInInventory(string type)
862  {
864  if (FindFirstFreeLocationForNewEntity(type, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, loc))
865  {
866  switch (loc.GetType())
867  {
868  case InventoryLocationType.ATTACHMENT:
869  return loc.GetParent().GetInventory().CreateAttachmentEx(type, loc.GetSlot());
870  case InventoryLocationType.CARGO:
871  return loc.GetParent().GetInventory().CreateEntityInCargoEx(type, loc.GetIdx(), loc.GetRow(), loc.GetCol(), loc.GetFlip());
872  default:
873  Error("CreateInInventory: unknown location for item");
874  break;
875  }
876  }
877 
878  return null;
879  }
880 
891  bool CanAddEntityToInventory(notnull EntityAI item, int flag = FindInventoryLocationType.ANY)
892  {
894  bool result = FindFreeLocationFor(item, flag, il);
895  return result;
896  }
911  bool AddEntityToInventory(notnull EntityAI item)
912  {
914  bool result = FindFreeLocationFor(item, FindInventoryLocationType.ANY, il);
915  if (result)
916  return LocationAddEntity(il);
917 
918  return result;
919  }
920 
924  bool CanRemoveEntity()
925  {
927  if (GetCurrentInventoryLocation(il))
928  return LocationCanRemoveEntity(il);
929 
930  return false;
931  }
932 
933  // Script version of CanAddEntity* methods based on InventoryLocation
946  bool CanAddEntityInto(notnull EntityAI item, FindInventoryLocationType flags = FindInventoryLocationType.ANY)
947  {
949  return FindFreeLocationFor(item, flags, loc) && !item.IsHologram();
950  }
951 
955  bool CanAddEntityIntoInventory(notnull EntityAI item)
956  {
957  return CanAddEntityInto(item, FindInventoryLocationType.ANY_CARGO | FindInventoryLocationType.ATTACHMENT);
958  }
959 
963  bool CanAddEntityIntoHands(notnull EntityAI item)
964  {
965  return CanAddEntityInto(item, FindInventoryLocationType.HANDS);
966  }
967 
969  bool OnInputUserDataProcess(ParamsReadContext ctx);
970  bool OnInventoryJunctureFromServer(ParamsReadContext ctx);
971  bool OnInventoryJunctureRepairFromServer(ParamsReadContext ctx);
972  void OnInventoryJunctureFailureFromServer(ParamsReadContext ctx);
973  void OnServerInventoryCommand(ParamsReadContext ctx);
975 
976  void OnInventoryFailure(InventoryCommandType type, InventoryValidationReason reason, InventoryLocation src, InventoryLocation dst);
977 
998  bool TakeEntityToInventory(InventoryMode mode, FindInventoryLocationType flags, notnull EntityAI item)
999  {
1000  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1001 
1003  if (item.GetInventory().GetCurrentInventoryLocation(src))
1004  {
1006  if (FindFreeLocationFor(item, flags, dst))
1007  return TakeToDst(mode, src, dst);
1008 
1009  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " Warning - no room for item");
1010  return false;
1011  }
1012  Error("[inv] I::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " Error - src has no inventory location");
1013  return false;
1014  }
1015 
1017  bool TakeEntityToTargetInventory(InventoryMode mode, notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
1018  {
1019  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Target(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1020 
1022  if (item.GetInventory().GetCurrentInventoryLocation(src))
1023  {
1025 
1026  if (target.GetInventory().FindFreeLocationFor(item, flags, dst))
1027  return TakeToDst(mode, src, dst);
1028 
1029  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Target(" + typename.EnumToString(InventoryMode, mode) + ") target=" + target + " item=" + item + " Warning - no room for item in target");
1030  return false;
1031  }
1032  Error("[inv] I::Take2Target(" + typename.EnumToString(InventoryMode, mode) + ") target=" + target + " item=" + item + " Error - src has no inventory location");
1033  return false;
1034  }
1035 
1042  bool TakeToDst (InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
1043  {
1044  bool ret;
1045  switch (mode)
1046  {
1047  case InventoryMode.SERVER:
1048  ret = LocationSyncMoveEntity(src, dst);
1049  if (ret && dst.IsValid())
1050  InventoryInputUserData.SendServerMove(null, InventoryCommandType.SYNC_MOVE, src, dst);
1051  return ret;
1052  case InventoryMode.LOCAL:
1053  ret = LocationSyncMoveEntity(src, dst);
1054  return ret;
1055  default:
1056  return false;
1057  }
1058  return false;
1059  }
1060 
1066  bool TakeEntityToCargo(InventoryMode mode, notnull EntityAI item)
1067  {
1068  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1069  return TakeEntityToInventory(mode, FindInventoryLocationType.CARGO, item);
1070  }
1071 
1073  bool TakeEntityToTargetCargo(InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
1074  {
1075  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2TargetCgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + "to cargo of target=" + target);
1076  return TakeEntityToTargetInventory(mode, target, FindInventoryLocationType.CARGO, item);
1077  }
1078 
1084  bool TakeEntityToCargoEx(InventoryMode mode, notnull EntityAI item, int idx, int row, int col)
1085  {
1086  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " row=" + row + " col=" + col);
1088  if (item.GetInventory().GetCurrentInventoryLocation(src))
1089  {
1091  dst.SetCargo(GetInventoryOwner(), item, idx, row, col, item.GetInventory().GetFlipCargo());
1092 
1093  return TakeToDst(mode, src, dst);
1094  }
1095  Error("[inv] I::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " row=" + row + " col=" + col + " Error - src has no inventory location");
1096  return false;
1097  }
1098 
1100  bool TakeEntityToTargetCargoEx(InventoryMode mode, notnull CargoBase cargo, notnull EntityAI item, int row, int col)
1101  {
1102  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2TargetCgoEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + "to cargo of target=" + cargo.GetCargoOwner() + " row=" + row + " col=" + col);
1104  if (item.GetInventory().GetCurrentInventoryLocation(src))
1105  {
1107  dst.SetCargoAuto(cargo, item, row, col, item.GetInventory().GetFlipCargo());
1108 
1109  return TakeToDst(mode, src, dst);
1110  }
1111  Error("[inv] I::Take2TargetCgoEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + "to cargo of target=" + cargo.GetCargoOwner() + " row=" + row + " col=" + col);
1112  return false;
1113  }
1114 
1115  bool TakeEntityAsAttachmentEx(InventoryMode mode, notnull EntityAI item, int slot)
1116  {
1117  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " slot=" + slot);
1118  return TakeEntityAsTargetAttachmentEx(mode, GetInventoryOwner(), item, slot);
1119  }
1120 
1122  bool TakeEntityAsTargetAttachmentEx(InventoryMode mode, notnull EntityAI target, notnull EntityAI item, int slot)
1123  {
1124  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2TargetAttEx(" + typename.EnumToString(InventoryMode, mode) + ") as ATT of target=" + target + " item=" + item + " slot=" + slot);
1126  if (item.GetInventory().GetCurrentInventoryLocation(src))
1127  {
1128 
1129  EntityAI att = target.GetInventory().FindAttachment(slot);
1130  if (att)
1131  {
1132  att.CombineItemsClient(item, true);
1133  return true;
1134  }
1135  else
1136  {
1138  dst.SetAttachment(target, item, slot);
1139  return TakeToDst(mode, src, dst);
1140  }
1141  }
1142  Error("[inv] I::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " Error - src has no inventory location");
1143  return false;
1144  }
1145 
1146  bool TakeEntityAsAttachment(InventoryMode mode, notnull EntityAI item)
1147  {
1148  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2Att(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1149  return TakeEntityToInventory(mode, FindInventoryLocationType.ATTACHMENT, item);
1150  }
1151 
1152  bool TakeEntityAsTargetAttachment(InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
1153  {
1154  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1155  return TakeEntityToTargetInventory(mode, target, FindInventoryLocationType.ATTACHMENT, item);
1156  }
1157 
1159  static bool MakeDstForSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, out InventoryLocation dst1, out InventoryLocation dst2)
1160  {
1161  if (dst1 == null)
1162  dst1 = new InventoryLocation();
1163 
1164  dst1.Copy(src1);
1165  dst1.CopyLocationFrom(src2, false);
1166  dst1.SetFlip(src1.GetItem().GetInventory().GetFlipCargo()); // update flip flag from inventory item
1167 
1168  if (dst2 == null)
1169  dst2 = new InventoryLocation();
1170 
1171  dst2.Copy(src2);
1172  dst2.CopyLocationFrom(src1, false);
1173  dst2.SetFlip(src2.GetItem().GetInventory().GetFlipCargo()); // update flip flag from inventory item
1174  return true;
1175  }
1176 
1178  static bool MakeSrcAndDstForSwap(notnull EntityAI item1, notnull EntityAI item2, out InventoryLocation src1, out InventoryLocation src2, out InventoryLocation dst1, out InventoryLocation dst2)
1179  {
1180  if (src1 == null)
1181  src1 = new InventoryLocation();
1182  if (src2 == null)
1183  src2 = new InventoryLocation();
1184  if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
1185  return MakeDstForSwap(src1, src2, dst1, dst2);
1186  return false;
1187  }
1188 
1190  static bool MakeSrcAndDstForForceSwap(notnull EntityAI item1, notnull EntityAI item2, out InventoryLocation src1, out InventoryLocation src2, out InventoryLocation dst1, notnull InventoryLocation dst2)
1191  {
1192  if (src1 == null)
1193  src1 = new InventoryLocation();
1194  if (src2 == null)
1195  src2 = new InventoryLocation();
1196 
1197  if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
1198  {
1199  // src1 -> dst_of(src2)
1200  if (dst1 == null)
1201  dst1 = new InventoryLocation();
1202 
1203  dst1.Copy(src1);
1204  dst1.CopyLocationFrom(src2, false);
1205  dst1.SetFlip(dst1.GetItem().GetInventory().GetFlipCargo());
1206 
1207  // src2 -> dst2 from user
1208  return true;
1209  }
1210 
1211  return false;
1212  }
1213 
1214  bool SwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
1215  {
1216  return false;
1217  }
1218 
1219  bool ForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
1220  {
1221  return false;
1222  }
1223 
1224  static bool SetGroundPosByOwner(EntityAI owner, notnull EntityAI item, out InventoryLocation ground)
1225  {
1226  vector m4[4];
1227  Math3D.MatrixIdentity4(m4);
1228  bool success = GameInventory.PrepareDropEntityPos(owner, item, m4, false, GameConstants.INVENTORY_ENTITY_DROP_OVERLAP_DEPTH);
1229  ground.SetGround(item, m4);
1230  return success;
1231  }
1232 
1233  bool DropEntity(InventoryMode mode, EntityAI owner, notnull EntityAI item)
1234  {
1235  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Drop(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1237  if (item.GetInventory().GetCurrentInventoryLocation(src))
1238  {
1240  if (!SetGroundPosByOwner(owner, item, dst))
1241  {
1242  OnInventoryFailure(InventoryCommandType.SYNC_MOVE, InventoryValidationReason.DROP_PREVENTED, src, dst);
1243  return false;
1244  }
1245 
1246  return TakeToDst(mode, src, dst);
1247  }
1248 
1249  Error("DropEntity - No inventory location");
1250  return false;
1251  }
1252 
1253  static bool SetGroundPosByTransform(EntityAI owner, notnull EntityAI item, out InventoryLocation ground, vector transform[4])
1254  {
1255  bool success = GameInventory.PrepareDropEntityPos(owner, item, transform, true, GameConstants.INVENTORY_ENTITY_DROP_OVERLAP_DEPTH);
1256  ground.SetGround(item, transform);
1257  return success;
1258  }
1259 
1260  bool DropEntityWithTransform(InventoryMode mode, EntityAI owner, notnull EntityAI item, vector transform[4])
1261  {
1262  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Drop(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1264  if (item.GetInventory().GetCurrentInventoryLocation(src))
1265  {
1267  SetGroundPosByTransform(owner, item, dst, transform);
1268 
1269  return TakeToDst(mode, src, dst);
1270  }
1271 
1272  Error("DropEntityWithTransform - No inventory location");
1273  return false;
1274  }
1275 
1276  static void SetGroundPosByOwnerBounds(EntityAI owner, notnull EntityAI item, out InventoryLocation ground, vector halfExtents, float angle, float cosAngle, float sinAngle)
1277  {
1278  vector m4[4];
1279  owner.GetTransform(m4);
1280 
1281  vector randomPos = Vector(Math.RandomFloat(-halfExtents[0], halfExtents[0]), 0, Math.RandomFloat(-halfExtents[2], halfExtents[2]));
1282  randomPos = vector.RotateAroundZero(randomPos, vector.Up, cosAngle, sinAngle);
1283 
1284  float dist = randomPos[0] * m4[1][0] + randomPos[1] * m4[1][1] + randomPos[2] * m4[1][2];
1285 
1286  m4[3][0] = m4[3][0] + randomPos[0];
1287  m4[3][1] = m4[3][1] - dist + halfExtents[1];
1288  m4[3][2] = m4[3][2] + randomPos[2];
1289 
1290  item.PlaceOnSurfaceRotated(m4, Vector(m4[3][0], m4[3][1], m4[3][2]));
1291 
1292  ground.SetGround(item, m4);
1293  }
1294 
1295  bool DropEntityInBounds(InventoryMode mode, EntityAI owner, notnull EntityAI item, vector halfExtents, float angle, float cosAngle, float sinAngle)
1296  {
1297  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::Drop(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1298 
1300  if (item.GetInventory().GetCurrentInventoryLocation(src))
1301  {
1302  InventoryLocation dst = new InventoryLocation();
1303 
1304  SetGroundPosByOwnerBounds(owner, item, dst, halfExtents, angle, cosAngle, sinAngle);
1305 
1306  return TakeToDst(mode, src, dst);
1307  }
1308 
1309  Error("DropEntityInBounds - No inventory location");
1310  return false;
1311  }
1312 
1313  bool LocalDestroyEntity(notnull EntityAI item)
1314  {
1315  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::LocalDestroyEntity inv item=" + item);
1317  if (item.GetInventory().GetCurrentInventoryLocation(src))
1318  {
1319  if (src.GetType() == InventoryLocationType.HANDS)
1320  Error("[inv] Source location == HANDS, player has to handle this");
1321 
1322  GetGame().ObjectDelete(src.GetItem());
1323  return true;
1324  }
1325 
1326  Error("LocalDestroyEntity: No inventory location");
1327  return false;
1328  }
1329 
1330  bool ReplaceItemWithNew(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
1331  {
1333  if (lambda.m_OldItem.GetInventory().GetCurrentInventoryLocation(src))
1334  {
1335  if (LogManager.IsInventoryMoveLogEnable()) inventoryDebugPrint("[inv] I::ReplaceItemWithNew executing lambda=" + lambda + "on old_item=" + lambda.m_OldItem);
1336  lambda.Execute();
1337  return true;
1338  }
1339 
1340  Error("[inv] I::ReplaceItemWithNew - no inventory location");
1341  return false;
1342  }
1343 
1344  proto native bool GetFlipCargo();
1345  proto native void SetFlipCargo(bool flip);
1346  proto native void FlipCargo();
1347  proto native void ResetFlipCargo();
1349 }
GetGame
proto native CGame GetGame()
DROP_PREVENTED
@ DROP_PREVENTED
Definition: inventory.c:40
InventoryValidationReason
InventoryValidationReason
Definition: inventory.c:36
LogError
void LogError(string message, LogTemplateID template_id=0)
Creates error log (optional) from LogTemplate which are registred.
Definition: logtemplates.c:129
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
m_IsJuncture
bool m_IsJuncture
Definition: hand_events.c:49
SUCCESS
@ SUCCESS
Definition: inventory.c:33
DESTROY
@ DESTROY
destroy of entity right in inventory
Definition: inventory.c:9
LogManager
Definition: debug.c:734
DST
enum InventoryCheckContext DST
Find a reservation for the dst EXCLUDING the item, item and dst required.
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
ITEM
enum InventoryCheckContext ITEM
Find a reservation for the item EXCLUDING the dst, item and dst required.
InventoryJunctureType
InventoryJunctureType
Definition: inventory.c:13
m_IsRemote
bool m_IsRemote
Definition: hand_events.c:50
JUNCTURE
@ JUNCTURE
'Juncture' operation is used whenever there is possibility of race condition, i.e....
Definition: inventory.c:25
HAND_EVENT
@ HAND_EVENT
event for hands
Definition: inventory.c:6
FORCESWAP
@ FORCESWAP
Forced swap two entities. First goes to second's place, second goes "somewhere else".
Definition: inventory.c:8
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
InventoryValidationResult
InventoryValidationResult
Definition: inventory.c:29
InventoryCommandType
InventoryCommandType
Definition: inventory.c:2
LOCAL
@ LOCAL
'Local' operation executes from where it is run
Definition: inventory.c:24
InventoryValidation
Definition: inventory.c:43
HandEventBase
Abstracted event, not to be used, only inherited.
Definition: hand_events.c:194
UNKNOWN
@ UNKNOWN
Definition: inventory.c:38
DayZPlayer
Definition: dayzplayerimplement.c:72
TAKE
@ TAKE
taking from ground
Definition: inventory.c:15
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
EQUAL
enum InventoryCheckContext EQUAL
Find an exact reservation for item and dst, item and dst required.
ClearInventoryReservation
void ClearInventoryReservation()
Definition: hand_events.c:184
LEGACY
enum InventoryCheckContext LEGACY
The original logic, finds anything depending on the parameters, item or dst required.
MOVE
@ MOVE
generic move, may involve animations
Definition: inventory.c:4
USER_RESERVATION_CANCEL
@ USER_RESERVATION_CANCEL
Clear user reserved inventory space.
Definition: inventory.c:11
vector
Definition: enconvert.c:105
inventoryDebugPrint
void inventoryDebugPrint(string s)
Definition: debug.c:19
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
CargoBase
represents base for cargo storage for entities
Definition: cargo.c:6
Object
Definition: objecttyped.c:1
slotName
PlayerSpawnPreset slotName
InventoryInputUserData
Definition: inventoryinputuserdata.c:2
SYNC_CHECK
@ SYNC_CHECK
Definition: inventory.c:60
JUNCTURE_DENIED
@ JUNCTURE_DENIED
Definition: inventory.c:39
OnInventoryFailure
override void OnInventoryFailure(InventoryCommandType type, InventoryValidationReason reason, InventoryLocation src, InventoryLocation dst)
Definition: dayzplayerinventory.c:640
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
CanSwapEntities
override bool CanSwapEntities(EntityAI otherItem, InventoryLocation otherDestination, InventoryLocation destination)
Definition: fireplacebase.c:2491
array< EntityAI >
PREDICTIVE
@ PREDICTIVE
'Predictive' means that the operation uses Client-Side Prediction, i.e. the action runs the same code...
Definition: inventory.c:23
GameConstants
Definition: constants.c:612
Debug
Definition: debug.c:13
InventoryTraversalType
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition: gameplay.c:5
GetTime
float GetTime()
Definition: notificationsystem.c:35
syncDebugPrint
void syncDebugPrint(string s)
Definition: debug.c:1
ReplaceItemWithNewLambdaBase
base class for transformation operations (creating one item from another)
Definition: replaceitemwithnewlambdabase.c:4
REPLACE
@ REPLACE
replace of entity in inventory (@NOTE: hands goes through HAND_EVENT)
Definition: inventory.c:10
SWAP
@ SWAP
swap two entities (simple swap of compatible objects)
Definition: inventory.c:7
Math
Definition: enmath.c:6
SYNC_MOVE
@ SYNC_MOVE
synchronous move. action is finished immeadiately, no animations involved
Definition: inventory.c:5
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
SERVER
@ SERVER
'Server' mode operation is required if and only if the operation runs only on server (creates and/or ...
Definition: inventory.c:26
Math3D
Definition: enmath3d.c:27
FAILED
@ FAILED
Definition: inventory.c:31
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
InventoryCheckContext
InventoryCheckContext
Definition: inventory.c:57
DEFAULT
@ DEFAULT
Definition: inventory.c:59