DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Inventory.c
Go to the documentation of this file.
1//-------------------------------------------------------
3{
12};
14{
16 SWAP,
17 //LOAD, ///< load mag from ground
18};
20{
25};
26
28{
32};
33
35{
39};
40
42{
43 bool m_IsJuncture = false;
44 bool m_IsRemote = false;
45
48
50 {
51 return !m_IsJuncture && !m_IsRemote;
52 }
53};
54
56{
59}
60
61enum FindInventoryReservationMode
62{
71};
72
77{
78 protected static int m_inventory_check_context = InventoryCheckContext.DEFAULT;
79
80//-------------------------------------------------------
83
88 proto native EntityAI GetInventoryOwner ();
89
90#ifdef DEVELOPER
95 proto native void DumpInventoryDebug ();
96
101 static proto native void DumpStaticInventoryDebug ();
102#endif
103
114 proto native bool HasEntityInInventory (notnull EntityAI item);
115
124
130 proto native int CountInventory ();
131
132
134 proto native CargoBase GetCargo ();
135 proto native CargoBase GetCargoFromIndex (int index);
139 proto native EntityAI CreateEntityInCargo (string typeName);
146 proto native EntityAI CreateEntityInCargoEx (string typeName, int idx, int row, int col, bool flip);
147
148 proto native bool HasEntityInCargo (notnull EntityAI e);
149 proto native bool HasEntityInCargoEx (notnull EntityAI e, int idx, int row, int col);
150 proto native bool CanAddEntityInCargo (notnull EntityAI e, bool flip);
151 proto native bool CanAddEntityInCargoEx (notnull EntityAI e, int idx, int row, int col, bool flip);
153 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);
154 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);
155 //proto native bool AddEntityInCargo (notnull EntityAI owner, EntityAI cargo);
156 //proto native bool AddEntityInCargoEx (notnull EntityAI owner, notnull EntityAI e, int idx, int row, int col);
157 proto native bool CanRemoveEntityInCargo (notnull EntityAI e);
158 proto native bool CanRemoveEntityInCargoEx (notnull EntityAI e, int idx, int row, int col);
160
161
163
167 proto native int GetSlotId (int index);
171 proto native int GetSlotIdCount ();
176 proto native int GetAttachmentSlotId (int index);
180 proto native int GetAttachmentSlotsCount ();
184 proto native bool HasInventorySlot (int slotId);
188 proto native int AttachmentCount ();
192 proto native EntityAI CreateAttachment (string typeName);
198 proto native EntityAI CreateAttachmentEx (string typeName, int slotId);
203 proto native EntityAI GetAttachmentFromIndex (int index);
207 proto native EntityAI FindAttachment (int slot);
211 proto native EntityAI FindAttachmentByName (string slotName);
215 proto native bool HasAttachment (notnull EntityAI e);
219 proto native bool HasAttachmentEx (notnull EntityAI e, int slot);
224 proto native bool CanAddAttachment (notnull EntityAI e);
229 proto native bool CanAddAttachmentEx (notnull EntityAI e, int slot);
230
231 proto native bool CanRemoveAttachment (EntityAI attachment);
232 proto native bool CanRemoveAttachmentEx (EntityAI attachment, int slot);
233
234 //proto native bool RemoveAttachment(EntityAI attachment);
235 //proto native bool RemoveAttachmentEx(EntityAI attachment, int slot);
236
240 proto native EntityAI FindPlaceholderForSlot(int slot);
241 proto native bool IsPlaceholderEntity (notnull Object e);
243
244
251 proto native bool GetCurrentInventoryLocation (out notnull InventoryLocation loc);
252
259 proto native bool FindFreeLocationFor (notnull EntityAI item, FindInventoryLocationType flags, out notnull InventoryLocation loc);
266 proto native bool FindFreeLocationForEx (notnull EntityAI item, FindInventoryLocationType flags, notnull InventoryLocation exclude, out notnull InventoryLocation loc);
267
274 proto native bool FindFirstFreeLocationForNewEntity (string item_type, FindInventoryLocationType flags, out notnull InventoryLocation loc);
275
308 proto native int FindFreeLocationsFor (notnull EntityAI item, FindInventoryLocationType flags, out notnull array<ref InventoryLocation> locs);
309
316 static proto native EntityAI LocationCreateEntity (notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation);
324 static proto native EntityAI LocationCreateLocalEntity (notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation);
330 static proto native bool LocationCanAddEntity(notnull InventoryLocation inv_loc);
331
332 //Added script check to LocationCanAddEntity
333 static bool LocationCanAddEntityEx(notnull InventoryLocation inv_loc)
334 {
335 return LocationCanAddEntity (inv_loc);
336 }
337
343 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);
349 static proto native bool LocationCanRemoveEntity(notnull InventoryLocation inv_loc);
356 static proto native bool LocationCanMoveEntity(notnull InventoryLocation src, notnull InventoryLocation dst);
357
359 {
361 }
362
364 {
366 bool result = LocationCanMoveEntity(src, dst);
368 return result;
369
370 }
376 static proto native EntityAI LocationGetEntity(notnull InventoryLocation inv_loc);
377
378
381 {
384 if ( lcn.GetType() == InventoryLocationType.CARGO)
385 {
386 return true;
387 }
388
389 return false;
390 }
391
394 {
397 if ( lcn.GetType() == InventoryLocationType.ATTACHMENT)
398 {
399 return true;
400 }
401
402 return false;
403 }
404
407 {
410 EntityAI parent = lcn.GetParent();
411
412 while (parent) //while with limit
413 {
414 if (lcn.GetType() == InventoryLocationType.CARGO || lcn.GetType() == InventoryLocationType.PROXYCARGO)
415 {
416 return true;
417 }
418
419 parent.GetInventory().GetCurrentInventoryLocation(lcn);
420 parent = lcn.GetParent();
421 }
422
423 return false;
424 }
425
427 bool GetCurrentAttachmentSlotInfo(out int slot_id, out string slot_name)
428 {
429 slot_id = InventorySlots.INVALID;
430 slot_name = "";
433 if (lcn.GetType() == InventoryLocationType.ATTACHMENT)
434 {
435 slot_id = lcn.GetSlot();
436 slot_name = InventorySlots.GetSlotName(slot_id);
437 return true;
438 }
439 return false;
440 }
441
443 {
444 int tmp = -1;
445 ctx.Read(tmp);
446
447 int type = -1;
448 if (!ctx.Read(type))
449 return;
450
451 switch (type)
452 {
453 case InventoryCommandType.SYNC_MOVE:
454 {
457
458 src.ReadFromContext(ctx);
459 dst.ReadFromContext(ctx);
460 syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms ServerInventoryCommand cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
461
462 if (!src.GetItem() || !dst.GetItem())
463 {
464 LogError("[syncinv] ServerInventoryCommand (cmd=SYNC_MOVE) dropped, item not in bubble");
465 break; // not in bubble
466 }
467
468 LocationSyncMoveEntity(src, dst);
469 break;
470 }
471
472 case InventoryCommandType.HAND_EVENT:
473 {
474 HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
475 syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms ServerInventoryCommand cmd=" + typename.EnumToString(InventoryCommandType, type) + " event=" + e.DumpToString());
476
477 if (!e.GetSrcEntity())
478 {
479 Error("[syncinv] ServerInventoryCommand (cmd=HAND_EVENT) dropped, item not in bubble");
480 break; // not in bubble
481 }
482 e.m_Player.GetHumanInventory().ProcessHandEvent(e);
483 break;
484 }
485
486 case InventoryCommandType.FORCESWAP:
487 case InventoryCommandType.SWAP:
488 {
493 src1.ReadFromContext(ctx);
494 src2.ReadFromContext(ctx);
495 dst1.ReadFromContext(ctx);
496 dst2.ReadFromContext(ctx);
497
498 if (src1.IsValid() && src2.IsValid() && dst1.IsValid() && dst2.IsValid())
499 {
500 syncDebugPrint("[syncinv] t=" + GetGame().GetTime() + "ms ServerInventoryCommand Swap src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
501
502 LocationSwap(src1, src2, dst1, dst2);
503 }
504 else
505 Error("ServerInventoryCommand - cannot swap, invalid location input: src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
506
507 break;
508 }
509 }
510 }
511
517 static proto native bool LocationAddEntity (notnull InventoryLocation inv_loc);
523 static proto native bool LocationRemoveEntity (notnull InventoryLocation inv_loc);
524
530 static proto native bool LocationMoveEntity (notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc);
531
538 static proto native bool LocationSyncMoveEntity (notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc);
539
545 static proto native bool LocationSwap (notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2);
546
552 static proto native bool ServerLocationMoveEntity (notnull EntityAI item, ParamsWriteContext ctx);
553
561 static proto native bool ServerLocationSyncMoveEntity (Man player, notnull EntityAI item, ParamsWriteContext ctx);
562
568 static proto native bool ServerLocationSwap (notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, ParamsWriteContext ctx);
569
575 static proto native bool ServerHandEvent (notnull Man player, notnull EntityAI item, ParamsWriteContext ctx);
576
586 static proto native bool PrepareDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix = false, int conflictCheckDepth = -1);
587 static proto native bool TestDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix = false, int conflictCheckDepth = -1);
588
599 static proto native bool CanSwapEntities(notnull EntityAI item1, notnull EntityAI item2);
600
601 static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
602 {
603 int slot;
606
607 item2.GetInventory().GetCurrentInventoryLocation(il2);
608 slot = il2.GetSlot();
609
610 if( item1.GetQuantity() > item1.GetTargetQuantityMax(slot) )
611 return false;
612
613
614 item1.GetInventory().GetCurrentInventoryLocation(il1);
615 slot = il1.GetSlot();
616
617 if( item2.GetQuantity() > item2.GetTargetQuantityMax(slot) )
618 return false;
619
620 if(!item1.CanSwapEntities(item2, il2, il1) || !item2.CanSwapEntities(item1, il1, il2))
621 {
622 return false;
623 }
624
625 return CanSwapEntities(item1,item2);
626 }
627
637 static proto native bool CanForceSwapEntities(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst);
638 static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
639 {
640 if (!CanForceSwapEntities(item1, item1_dst, item2, item2_dst) )
641 return false;
642
643 int slot;
645
646 if ( item1_dst == null)
647 {
648 item2.GetInventory().GetCurrentInventoryLocation(il);
649 slot = il.GetSlot();
650 }
651 else
652 {
653 slot = item1_dst.GetSlot();
654 }
655
656 if ( item1.GetQuantity() > item1.GetTargetQuantityMax(slot) )
657 return false;
658
659 if ( item2_dst == null)
660 {
661 item1.GetInventory().GetCurrentInventoryLocation(il);
662 slot = il.GetSlot();
663 }
664 else
665 {
666 slot = item2_dst.GetSlot();
667 }
668
669 if (!item1.CanSwapEntities(item2, item2_dst, item1_dst) || !item2.CanSwapEntities(item1, item1_dst, item2_dst))
670 {
671 return false;
672 }
673
674 if ( item2.GetQuantity() > item2.GetTargetQuantityMax(slot) )
675 return false;
676
677 return true;
678 }
679
680 proto native bool CanAddSwappedEntity(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2);
681
685
686 static proto native bool AddInventoryReservation(EntityAI item, InventoryLocation dst, int timeout_ms);
688 {
689 if (GetGame().IsMultiplayer() && GetGame().IsServer() )
690 return true;
691
692 bool ret_val = AddInventoryReservation(item, dst, timeout_ms);
693 #ifdef DEVELOPER
695 {
696 DayZPlayer player = GetGame().GetPlayer();
697 if ( player )
698 {
699 if (item)
700 Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / " + item.ToString() + " / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "AddInventoryReservation", player.ToString() );
701 else
702 Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / null / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "AddInventoryReservation", player.ToString() );
703 }
704 }
705 #endif
706 return ret_val;
707 }
708
709 static proto native bool ExtendInventoryReservation(EntityAI item, InventoryLocation dst, int timeout_ms);
711 {
712 if (GetGame().IsMultiplayer() && GetGame().IsServer() )
713 return true;
714
715 bool ret_val = ExtendInventoryReservation(item,dst,timeout_ms);
716 #ifdef DEVELOPER
718 {
719 DayZPlayer player = GetGame().GetPlayer();
720 if ( player )
721 {
722 if (item)
723 Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / " + item.ToString() + " / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ExtendInventoryReservation", player.ToString() );
724 else
725 Debug.InventoryMoveLog("Reservation result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / null / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ExtendInventoryReservation", player.ToString() );
726 }
727 }
728 #endif
729 return ret_val;
730 }
731
732 static proto native bool ClearInventoryReservation(EntityAI item, InventoryLocation dst);
734 {
735 if (GetGame().IsMultiplayer() && GetGame().IsServer() )
736 return true;
737
738 bool ret_val = ClearInventoryReservation(item,dst);
739 #ifdef DEVELOPER
741 {
742 DayZPlayer player = GetGame().GetPlayer();
743 if ( player )
744 {
745 if (item)
746 Debug.InventoryMoveLog("Reservation cleared result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / " + item.ToString() + " / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ClearInventoryReservation", player.ToString() );
747 else
748 Debug.InventoryMoveLog("Reservation cleared result: " + ret_val + " - STS = " + player.GetSimulationTimeStamp() + " / null / " + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "ClearInventoryReservation", player.ToString() );
749 }
750 }
751 #endif
752 return ret_val;
753 }
754
756 static proto native bool HasInventoryReservation(EntityAI item, InventoryLocation dst);
758 static proto native bool HasInventoryReservationCanAdd(EntityAI item, InventoryLocation dst);
759
761 static proto native bool HasInventoryReservationEx(EntityAI item, InventoryLocation dst, FindInventoryReservationMode itemMode, FindInventoryReservationMode parentMode);
762 static proto native bool GetInventoryReservationCount(EntityAI item, InventoryLocation dst);
764
766 proto native bool CanLockInventoryWithKey (notnull EntityAI key);
767 proto native bool CanUnlockInventoryWithKey (notnull EntityAI key);
768 proto native void LockInventoryWithKey (notnull EntityAI key);
769 proto native void UnlockInventoryWithKey (notnull EntityAI key);
770 proto native bool HasKeys ();
771
772 proto native void LockInventory (int lockType);
773 proto native void UnlockInventory (int lockType);
774 proto native int GetScriptLockCount ();
775 proto native bool IsInventoryUnlocked ();
776 proto native bool IsInventoryLocked ();
777 proto native bool IsInventoryLockedForLockType (int lockType);
778 proto native bool SetSlotLock (int slot, bool locked);
779 proto native bool GetSlotLock (int slot);
781
783 const float c_MaxItemDistanceRadius = 2.5;
784 static proto native bool CheckRequestSrc (notnull Man requestingPlayer, notnull InventoryLocation src, float radius);
785 static proto native bool CheckDropRequest (notnull Man requestingPlayer, notnull InventoryLocation src, float radius);
786 static proto native bool CheckTakeItemRequest (notnull Man requestingPlayer, notnull InventoryLocation src, notnull InventoryLocation dst, float radius);
787 static proto native bool CheckMoveToDstRequest (notnull Man requestingPlayer, notnull InventoryLocation src, notnull InventoryLocation dst, float radius);
788 static proto native bool CheckSwapItemsRequest (notnull Man requestingPlayer, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, float radius);
789 static proto native bool CheckManipulatedObjectsDistances (notnull EntityAI e0, notnull EntityAI e1, float radius);
791
795
799 void Init ()
800 {
801 GetInventoryOwner().OnInventoryInit();
802 }
803
805 bool OnStoreLoad (ParamsReadContext ctx, int version)
806 {
807 return true;
808 }
812
813 void EEInit ()
814 {
817 {
818 if (src.GetType() == InventoryLocationType.HANDS)
819 {
820 Man man = Man.Cast(src.GetParent());
821 if (man)
822 {
823 inventoryDebugPrint("Inventory::EEInit - Man=" + man + " item=" + this);
824 man.GetHumanInventory().OnEntityInHandsCreated(src);
825 }
826 }
827 }
828 }
829
830 void EEDelete (EntityAI parent)
831 {
833 Man player = item.GetHierarchyRootPlayer();
834 if (player)
835 player.GetInventory().ClearInventoryReservationEx(item, null);
836 }
837
845 {
848 {
849 switch (loc.GetType())
850 {
851 case InventoryLocationType.ATTACHMENT: return loc.GetParent().GetInventory().CreateAttachmentEx(type, loc.GetSlot()); break;
852 case InventoryLocationType.CARGO: return loc.GetParent().GetInventory().CreateEntityInCargoEx(type, loc.GetIdx(), loc.GetRow(), loc.GetCol(), loc.GetFlip()); break;
853 default: Error("CreateInInventory: unknown location for item"); break;
854 }
855 }
856 return null;
857 }
858
870 {
872 bool result = FindFreeLocationFor(item, flag, il);
873 return result;
874 }
889 bool AddEntityToInventory (notnull EntityAI item)
890 {
892 bool result = FindFreeLocationFor(item, FindInventoryLocationType.ANY, il);
893 if (result)
894 return LocationAddEntity(il);
895 return result;
896 }
897
902 {
905 return LocationCanRemoveEntity(il);
906 return false;
907 }
908
909 // Script version of CanAddEntity* methods based on InventoryLocation
923 {
925 return FindFreeLocationFor(item, flags, loc) && !item.IsHologram();
926 }
927
932 {
933 return CanAddEntityInto(item, FindInventoryLocationType.ANY_CARGO | FindInventoryLocationType.ATTACHMENT);
934 }
935
939 bool CanAddEntityIntoHands (notnull EntityAI item)
940 {
942 }
943
951
953
975 {
976 inventoryDebugPrint("[inv] I::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
977
979 if (item.GetInventory().GetCurrentInventoryLocation(src))
980 {
982 if (FindFreeLocationFor(item, flags, dst))
983 return TakeToDst(mode, src, dst);
984
985 inventoryDebugPrint("[inv] I::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " Warning - no room for item");
986 return false;
987 }
988 Error("[inv] I::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " Error - src has no inventory location");
989 return false;
990 }
991
994 {
995 inventoryDebugPrint("[inv] I::Take2Target(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
996
998 if (item.GetInventory().GetCurrentInventoryLocation(src))
999 {
1001
1002 if (target.GetInventory().FindFreeLocationFor(item, flags, dst))
1003 return TakeToDst(mode, src, dst);
1004
1005 inventoryDebugPrint("[inv] I::Take2Target(" + typename.EnumToString(InventoryMode, mode) + ") target=" + target + " item=" + item + " Warning - no room for item in target");
1006 return false;
1007 }
1008 Error("[inv] I::Take2Target(" + typename.EnumToString(InventoryMode, mode) + ") target=" + target + " item=" + item + " Error - src has no inventory location");
1009 return false;
1010 }
1011
1018 bool TakeToDst (InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
1019 {
1020 bool ret;
1021 switch (mode)
1022 {
1023 case InventoryMode.SERVER:
1024 ret = LocationSyncMoveEntity(src, dst);
1025 if (ret && dst.IsValid())
1027 return ret;
1028 case InventoryMode.LOCAL:
1029 ret = LocationSyncMoveEntity(src, dst);
1030 //InventoryInputUserData.SendInputUserDataMove(InventoryCommandType.SYNC_MOVE, src, dst);
1031 //Print(ret);
1032 return ret;
1033 default:
1034 return false;
1035 }
1036 return false;
1037 }
1038
1044 bool TakeEntityToCargo (InventoryMode mode, notnull EntityAI item)
1045 {
1046 inventoryDebugPrint("[inv] I::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1047 return TakeEntityToInventory(mode, FindInventoryLocationType.CARGO, item);
1048 }
1049
1051 bool TakeEntityToTargetCargo (InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
1052 {
1053 inventoryDebugPrint("[inv] I::Take2TargetCgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + "to cargo of target=" + target);
1054 return TakeEntityToTargetInventory(mode, target, FindInventoryLocationType.CARGO, item);
1055 }
1056
1062 bool TakeEntityToCargoEx (InventoryMode mode, notnull EntityAI item, int idx, int row, int col)
1063 {
1064 inventoryDebugPrint("[inv] I::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " row=" + row + " col=" + col);
1066 if (item.GetInventory().GetCurrentInventoryLocation(src))
1067 {
1069 dst.SetCargo(GetInventoryOwner(), item, idx, row, col, item.GetInventory().GetFlipCargo());
1070
1071 return TakeToDst(mode, src, dst);
1072 }
1073 Error("[inv] I::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " row=" + row + " col=" + col + " Error - src has no inventory location");
1074 return false;
1075 }
1076
1078 bool TakeEntityToTargetCargoEx (InventoryMode mode, notnull CargoBase cargo, notnull EntityAI item, int row, int col)
1079 {
1080 inventoryDebugPrint("[inv] I::Take2TargetCgoEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + "to cargo of target=" + cargo.GetCargoOwner() + " row=" + row + " col=" + col);
1082 if (item.GetInventory().GetCurrentInventoryLocation(src))
1083 {
1085 dst.SetCargoAuto(cargo, item, row, col, item.GetInventory().GetFlipCargo());
1086
1087 return TakeToDst(mode, src, dst);
1088 }
1089 Error("[inv] I::Take2TargetCgoEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + "to cargo of target=" + cargo.GetCargoOwner() + " row=" + row + " col=" + col);
1090 return false;
1091 }
1092
1093 bool TakeEntityAsAttachmentEx (InventoryMode mode, notnull EntityAI item, int slot)
1094 {
1095 inventoryDebugPrint("[inv] I::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " slot=" + slot);
1096 return TakeEntityAsTargetAttachmentEx(mode, GetInventoryOwner(), item, slot);
1097 }
1098
1100 bool TakeEntityAsTargetAttachmentEx (InventoryMode mode, notnull EntityAI target, notnull EntityAI item, int slot)
1101 {
1102 inventoryDebugPrint("[inv] I::Take2TargetAttEx(" + typename.EnumToString(InventoryMode, mode) + ") as ATT of target=" + target + " item=" + item + " slot=" + slot);
1104 if (item.GetInventory().GetCurrentInventoryLocation(src))
1105 {
1106
1107 EntityAI att = target.GetInventory().FindAttachment(slot);
1108
1109 if(att)
1110 {
1111 att.CombineItemsClient(item, true );
1112 return true;
1113 }
1114 else
1115 {
1117 dst.SetAttachment(target, item, slot);
1118 return TakeToDst(mode, src, dst);
1119 }
1120 }
1121 Error("[inv] I::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " Error - src has no inventory location");
1122 return false;
1123 }
1124
1126 {
1127 inventoryDebugPrint("[inv] I::Take2Att(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1128 return TakeEntityToInventory(mode, FindInventoryLocationType.ATTACHMENT, item);
1129 }
1130
1131 bool TakeEntityAsTargetAttachment (InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
1132 {
1133 inventoryDebugPrint("[inv] I::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1134 return TakeEntityToTargetInventory(mode, target, FindInventoryLocationType.ATTACHMENT, item);
1135 }
1136
1138 static bool MakeDstForSwap (notnull InventoryLocation src1, notnull InventoryLocation src2, out InventoryLocation dst1, out InventoryLocation dst2)
1139 {
1140 if (dst1 == null)
1141 dst1 = new InventoryLocation;
1142 dst1.Copy(src1);
1143 dst1.CopyLocationFrom(src2, false);
1144 dst1.SetFlip(src1.GetItem().GetInventory().GetFlipCargo()); // update flip flag from inventory item
1145
1146 if (dst2 == null)
1147 dst2 = new InventoryLocation;
1148 dst2.Copy(src2);
1149 dst2.CopyLocationFrom(src1, false);
1150 dst2.SetFlip(src2.GetItem().GetInventory().GetFlipCargo()); // update flip flag from inventory item
1151 return true;
1152 }
1153
1155 static bool MakeSrcAndDstForSwap (notnull EntityAI item1, notnull EntityAI item2, out InventoryLocation src1, out InventoryLocation src2, out InventoryLocation dst1, out InventoryLocation dst2)
1156 {
1157 if (src1 == null)
1158 src1 = new InventoryLocation;
1159 if (src2 == null)
1160 src2 = new InventoryLocation;
1161 if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
1162 return MakeDstForSwap(src1, src2, dst1, dst2);
1163 return false;
1164 }
1165
1167 static bool MakeSrcAndDstForForceSwap (notnull EntityAI item1, notnull EntityAI item2, out InventoryLocation src1, out InventoryLocation src2, out InventoryLocation dst1, notnull InventoryLocation dst2)
1168 {
1169 if (src1 == null)
1170 src1 = new InventoryLocation;
1171 if (src2 == null)
1172 src2 = new InventoryLocation;
1173 if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
1174 {
1175 // src1 -> dst_of(src2)
1176 if (dst1 == null)
1177 dst1 = new InventoryLocation;
1178 dst1.Copy(src1);
1179 dst1.CopyLocationFrom(src2, false);
1180 dst1.SetFlip(dst1.GetItem().GetInventory().GetFlipCargo());
1181
1182 // src2 -> dst2 from user
1183 return true;
1184 }
1185
1186 return false;
1187 }
1188
1189 bool SwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
1190 {
1191 return false;
1192 }
1193
1194 bool ForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
1195 {
1196 return false;
1197 }
1198
1199 static bool SetGroundPosByOwner(EntityAI owner, notnull EntityAI item, out InventoryLocation ground)
1200 {
1201 vector m4[4];
1204 ground.SetGround(item, m4);
1205 return success;
1206 }
1207
1208 bool DropEntity(InventoryMode mode, EntityAI owner, notnull EntityAI item)
1209 {
1210 inventoryDebugPrint("[inv] I::Drop(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1212 if (item.GetInventory().GetCurrentInventoryLocation(src))
1213 {
1215 if (!SetGroundPosByOwner(owner, item, dst))
1216 {
1217 OnInventoryFailure(InventoryCommandType.SYNC_MOVE, InventoryValidationReason.DROP_PREVENTED, src, dst);
1218 return false;
1219 }
1220
1221 return TakeToDst(mode, src, dst);
1222 }
1223
1224 Error("DropEntity - No inventory location");
1225 return false;
1226 }
1227
1228 static bool SetGroundPosByTransform(EntityAI owner, notnull EntityAI item, out InventoryLocation ground, vector transform[4])
1229 {
1230 bool success = GameInventory.PrepareDropEntityPos(owner, item, transform, true, GameConstants.INVENTORY_ENTITY_DROP_OVERLAP_DEPTH);
1231 ground.SetGround(item, transform);
1232 return success;
1233 }
1234
1235 bool DropEntityWithTransform(InventoryMode mode, EntityAI owner, notnull EntityAI item, vector transform[4])
1236 {
1237 inventoryDebugPrint("[inv] I::Drop(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1239 if (item.GetInventory().GetCurrentInventoryLocation(src))
1240 {
1242 if (!SetGroundPosByTransform(owner, item, dst, transform))
1243 {
1244 OnInventoryFailure(InventoryCommandType.SYNC_MOVE, InventoryValidationReason.DROP_PREVENTED, src, dst);
1245 return false;
1246 }
1247
1248 return TakeToDst(mode, src, dst);
1249 }
1250
1251 Error("DropEntityWithTransform - No inventory location");
1252 return false;
1253 }
1254
1255 static void SetGroundPosByOwnerBounds(EntityAI owner, notnull EntityAI item, out InventoryLocation ground, vector halfExtents, float angle, float cosAngle, float sinAngle)
1256 {
1257 vector m4[4];
1258 owner.GetTransform(m4);
1259
1260 vector randomPos = Vector(Math.RandomFloat(-halfExtents[0], halfExtents[0]), 0, Math.RandomFloat(-halfExtents[2], halfExtents[2]));
1261 randomPos = vector.RotateAroundZero(randomPos, vector.Up, cosAngle, sinAngle);
1262
1263 float dist = randomPos[0] * m4[1][0] + randomPos[1] * m4[1][1] + randomPos[2] * m4[1][2];
1264
1265 m4[3][0] = m4[3][0] + randomPos[0];
1266 m4[3][1] = m4[3][1] - dist + halfExtents[1];
1267 m4[3][2] = m4[3][2] + randomPos[2];
1268
1269 item.PlaceOnSurfaceRotated(m4, Vector(m4[3][0], m4[3][1], m4[3][2]));
1270
1271 ground.SetGround(item, m4);
1272 }
1273
1274 bool DropEntityInBounds(InventoryMode mode, EntityAI owner, notnull EntityAI item, vector halfExtents, float angle, float cosAngle, float sinAngle)
1275 {
1276 inventoryDebugPrint("[inv] I::Drop(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
1277
1279 if (item.GetInventory().GetCurrentInventoryLocation(src))
1280 {
1282
1283 SetGroundPosByOwnerBounds(owner, item, dst, halfExtents, angle, cosAngle, sinAngle);
1284
1285 return TakeToDst(mode, src, dst);
1286 }
1287
1288 Error("DropEntityInBounds - No inventory location");
1289 return false;
1290 }
1291
1292 bool LocalDestroyEntity(notnull EntityAI item)
1293 {
1294 inventoryDebugPrint("[inv] I::LocalDestroyEntity inv item=" + item);
1296 if (item.GetInventory().GetCurrentInventoryLocation(src))
1297 {
1298 if (src.GetType() == InventoryLocationType.HANDS)
1299 Error("[inv] Source location == HANDS, player has to handle this");
1300
1301 GetGame().ObjectDelete(src.GetItem());
1302 return true;
1303 }
1304
1305 Error("LocalDestroyEntity: No inventory location");
1306 return false;
1307 }
1308
1310 {
1312 if (lambda.m_OldItem.GetInventory().GetCurrentInventoryLocation(src))
1313 {
1314 inventoryDebugPrint("[inv] I::ReplaceItemWithNew executing lambda=" + lambda + "on old_item=" + lambda.m_OldItem);
1315 lambda.Execute();
1316 return true;
1317 }
1318
1319 Error("[inv] I::ReplaceItemWithNew - no inventory location");
1320 return false;
1321 }
1322
1323 proto native bool GetFlipCargo();
1324 proto native void SetFlipCargo(bool flip);
1325 proto native void FlipCargo();
1326 proto native void ResetFlipCargo();
1328};
1329
void syncDebugPrint(string s)
Definition Debug.c:1
void inventoryDebugPrint(string s)
Definition Debug.c:19
InventoryJunctureType
Definition Inventory.c:14
@ TAKE
taking from ground
Definition Inventory.c:15
@ SWAP
swap two entities (simple swap of compatible objects)
Definition Inventory.c:7
enum InventoryCheckContext LEGACY
The original logic, finds anything depending on the parameters, item or dst required.
InventoryCommandType
Definition Inventory.c:3
@ USER_RESERVATION_CANCEL
Clear user reserved inventory space.
Definition Inventory.c:11
@ FORCESWAP
Forced swap two entities. First goes to second's place, second goes "somewhere else".
Definition Inventory.c:8
@ DESTROY
destroy of entity right in inventory
Definition Inventory.c:9
@ REPLACE
replace of entity in inventory (@NOTE: hands goes through HAND_EVENT)
Definition Inventory.c:10
@ SYNC_MOVE
synchronous move. action is finished immeadiately, no animations involved
Definition Inventory.c:5
@ HAND_EVENT
event for hands
Definition Inventory.c:6
@ MOVE
generic move, may involve animations
Definition Inventory.c:4
enum InventoryCheckContext EQUAL
Find an exact reservation for item and dst, item and dst required.
InventoryMode
Definition Inventory.c:20
@ SERVER
'Server' mode operation is required if and only if the operation runs only on server (creates and/or ...
Definition Inventory.c:24
@ PREDICTIVE
'Predictive' means that the operation uses Client-Side Prediction, i.e. the action runs the same code...
Definition Inventory.c:21
@ LOCAL
'Local' operation executes from where it is run
Definition Inventory.c:22
enum InventoryCheckContext DST
Find a reservation for the dst EXCLUDING the item, item and dst required.
InventoryValidationResult
Definition Inventory.c:28
@ JUNCTURE
'Juncture' operation is used whenever there is possibility of race condition, i.e....
Definition Inventory.c:23
@ SUCCESS
Definition Inventory.c:31
@ FAILED
Definition Inventory.c:29
InventoryValidationReason
Definition Inventory.c:35
@ DROP_PREVENTED
Definition Inventory.c:38
@ UNKNOWN
Definition Inventory.c:36
@ JUNCTURE_DENIED
Definition Inventory.c:37
enum InventoryCheckContext ITEM
Find a reservation for the item EXCLUDING the dst, item and dst required.
InventoryCheckContext
Definition Inventory.c:56
@ SYNC_CHECK
Definition Inventory.c:58
@ DEFAULT
Definition Inventory.c:57
void ClearInventoryReservation()
FindInventoryLocationType
flags for searching locations in inventory
InventoryLocationType
types of Inventory Location
void LogError(string message, LogTemplateID template_id=0)
Creates error log (optional) from LogTemplate which are registred.
float GetTime()
proto native void ObjectDelete(Object obj)
proto native DayZPlayer GetPlayer()
represents base for cargo storage for entities
Definition Cargo.c:7
Definition Debug.c:14
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
script counterpart to engine's class Inventory
Definition Inventory.c:77
bool TakeEntityToTargetCargoEx(InventoryMode mode, notnull CargoBase cargo, notnull EntityAI item, int row, int col)
Put item into into cargo on specific cargo location of another entity.
Definition Inventory.c:1078
proto native bool IsInventoryLockedForLockType(int lockType)
proto native bool HasAttachmentEx(notnull EntityAI e, int slot)
brief Returns True if entity is attached to this in slot
proto native CargoBase GetCargoFromIndex(int index)
bool DropEntity(InventoryMode mode, EntityAI owner, notnull EntityAI item)
Definition Inventory.c:1208
proto native bool CanUnlockInventoryWithKey(notnull EntityAI key)
proto native EntityAI CreateAttachmentEx(string typeName, int slotId)
Create Entity of specified type as attachment of entity.
EntityAI CreateInInventory(string type)
creates entity somewhere in inventory
Definition Inventory.c:844
static proto native bool LocationAddEntity(notnull InventoryLocation inv_loc)
adds item to inventory location
proto native bool CanAddSwappedEntity(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
bool OnInventoryJunctureFromServer(ParamsReadContext ctx)
Definition Inventory.c:946
static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
Definition Inventory.c:638
bool IsCargoInHiearchy()
Returns true if item of his hiearchy parents are in cargo.
Definition Inventory.c:406
proto native EntityAI GetAttachmentFromIndex(int index)
bool SwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:1189
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
proto native bool GetFlipCargo()
bool ForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
Definition Inventory.c:1194
static proto native bool HasInventoryReservation(EntityAI item, InventoryLocation dst)
Internally: HasInventoryReservationEx(item, dst, FindInventoryReservationMode.LEGACY,...
proto native int CountInventory()
almost identical to EnumerateInventory except it does not return items
static proto native bool ServerLocationMoveEntity(notnull EntityAI item, ParamsWriteContext ctx)
removes item from current inventory location and adds it to destination + sync via inventory command
static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new item directly at location
proto native bool CanRemoveEntityInCargo(notnull EntityAI e)
void EEDelete(EntityAI parent)
Definition Inventory.c:830
bool CanRemoveEntity()
Returns if entity can be removed from its current location.
Definition Inventory.c:901
static proto native bool LocationSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
swaps two entities
proto native bool CanAddAttachment(notnull EntityAI e)
Check if attachment can be added to any slot.
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:683
static proto native bool LocationRemoveEntity(notnull InventoryLocation inv_loc)
removes item from inventory location
proto native bool IsPlaceholderEntity(notnull Object e)
bool TakeEntityAsAttachmentEx(InventoryMode mode, notnull EntityAI item, int slot)
Definition Inventory.c:1093
proto native void UnlockInventoryWithKey(notnull EntityAI key)
proto native int AttachmentCount()
Returns count of attachments attached to this item.
proto native bool IsInventoryLocked()
proto native bool CanAddEntityInCargo(notnull EntityAI e, bool flip)
static proto native bool ClearInventoryReservation(EntityAI item, InventoryLocation dst)
proto native EntityAI CreateEntityInCargo(string typeName)
Create Entity of specified type in cargo of entity.
bool TakeEntityToCargo(InventoryMode mode, notnull EntityAI item)
moves item to cargo of this intentory
Definition Inventory.c:1044
static void SetGroundPosByOwnerBounds(EntityAI owner, notnull EntityAI item, out InventoryLocation ground, vector halfExtents, float angle, float cosAngle, float sinAngle)
Definition Inventory.c:1255
const float c_MaxItemDistanceRadius
anti-cheats
Definition Inventory.c:783
proto native bool CanAddEntityInCargoEx(notnull EntityAI e, int idx, int row, int col, bool flip)
proto native bool CanLockInventoryWithKey(notnull EntityAI key)
locks
bool OnInputUserDataProcess(ParamsReadContext ctx)
synchronization
Definition Inventory.c:945
static proto native bool HasInventoryReservationCanAdd(EntityAI item, InventoryLocation dst)
Internally: !HasInventoryReservationEx(item, dst, FindInventoryReservationMode.ITEM,...
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)
static protected int m_inventory_check_context
Definition Inventory.c:78
proto native bool SetSlotLock(int slot, bool locked)
proto native bool CanAddEntityInCargoExLoc(InventoryLocation loc)
bool DropEntityInBounds(InventoryMode mode, EntityAI owner, notnull EntityAI item, vector halfExtents, float angle, float cosAngle, float sinAngle)
Definition Inventory.c:1274
const int c_InventoryReservationTimeoutShortMS
Definition Inventory.c:684
proto native EntityAI CreateAttachment(string typeName)
Create Entity of specified type as attachment of entity.
bool ClearInventoryReservationEx(EntityAI item, InventoryLocation dst)
Definition Inventory.c:733
static proto native bool HasInventoryReservationEx(EntityAI item, InventoryLocation dst, FindInventoryReservationMode itemMode, FindInventoryReservationMode parentMode)
itemMode will iterate over item reservations, parentMode will iterate over parent reservations
proto native bool HasAttachment(notnull EntityAI e)
brief Returns True if entity is attached to this
static proto native bool PrepareDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix=false, int conflictCheckDepth=-1)
Finds a transformation for the item to be dropped to If the initial transforation overlaps with anoth...
void OnServerInventoryCommand(ParamsReadContext ctx)
Definition Inventory.c:949
static bool SetGroundPosByOwner(EntityAI owner, notnull EntityAI item, out InventoryLocation ground)
Definition Inventory.c:1199
static proto native bool CheckTakeItemRequest(notnull Man requestingPlayer, notnull InventoryLocation src, notnull InventoryLocation dst, float radius)
bool CanAddEntityInto(notnull EntityAI item, FindInventoryLocationType flags=FindInventoryLocationType.ANY)
Asks inventory if item could be placed in inventory, hands, etc.
Definition Inventory.c:922
void OnAfterStoreLoad()
Definition Inventory.c:809
bool AddInventoryReservationEx(EntityAI item, InventoryLocation dst, int timeout_ms)
Definition Inventory.c:687
bool TakeToDst(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
move src to dst
Definition Inventory.c:1018
static void OnServerInventoryCommandStatic(ParamsReadContext ctx)
Definition Inventory.c:442
bool TakeEntityToCargoEx(InventoryMode mode, notnull EntityAI item, int idx, int row, int col)
moves item on specific cargo location
Definition Inventory.c:1062
proto native void ResetFlipCargo()
proto native bool GetCurrentInventoryLocation(out notnull InventoryLocation loc)
returns information about current item location
static int GetInventoryCheckContext()
Definition Inventory.c:358
bool TakeEntityAsTargetAttachment(InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
Definition Inventory.c:1131
proto native bool IsInventoryUnlocked()
bool AddEntityToInventory(notnull EntityAI item)
add entity somewhere in inventory
Definition Inventory.c:889
proto native bool HasEntityInCargo(notnull EntityAI e)
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)
proto native void SetFlipCargo(bool flip)
bool ReplaceItemWithNew(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
Definition Inventory.c:1309
bool TakeEntityAsAttachment(InventoryMode mode, notnull EntityAI item)
Definition Inventory.c:1125
static proto native bool CheckMoveToDstRequest(notnull Man requestingPlayer, notnull InventoryLocation src, notnull InventoryLocation dst, float radius)
proto native bool EnumerateInventory(InventoryTraversalType tt, out array< EntityAI > items)
enumerate inventory using traversal type and filling items array
proto native bool HasKeys()
proto native bool FindFreeLocationForEx(notnull EntityAI item, FindInventoryLocationType flags, notnull InventoryLocation exclude, out notnull InventoryLocation loc)
FindFreeLocationForEx.
void EEInit()
Definition Inventory.c:813
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
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...
void Init()
script functions
Definition Inventory.c:799
proto native bool FindFreeLocationFor(notnull EntityAI item, FindInventoryLocationType flags, out notnull InventoryLocation loc)
FindFreeLocationFor.
static proto native bool AddInventoryReservation(EntityAI item, InventoryLocation dst, int timeout_ms)
static proto native EntityAI LocationCreateLocalEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new local item directly at location @NOTE: the item is created localy, i.e....
proto native bool HasInventorySlot(int slotId)
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
proto native EntityAI FindAttachmentByName(string slotName)
Returns attached entity in slot (you can use EntityAI.GetActionComponentName to get slot id)
proto native void FlipCargo()
static proto native bool CheckRequestSrc(notnull Man requestingPlayer, notnull InventoryLocation src, float radius)
proto native CargoBase GetCargo()
cargo
bool TakeEntityToInventory(InventoryMode mode, FindInventoryLocationType flags, notnull EntityAI item)
Put item anywhere into this entity (as attachment or into cargo, recursively)
Definition Inventory.c:974
static proto native bool CheckDropRequest(notnull Man requestingPlayer, notnull InventoryLocation src, float radius)
static bool LocationCanAddEntityEx(notnull InventoryLocation inv_loc)
Definition Inventory.c:333
proto native bool CanRemoveAttachment(EntityAI attachment)
proto native bool HasEntityInCargoEx(notnull EntityAI e, int idx, int row, int col)
static proto native bool GetInventoryReservationCount(EntityAI item, InventoryLocation dst)
proto native void LockInventoryWithKey(notnull EntityAI key)
bool CanAddEntityIntoInventory(notnull EntityAI item)
Test if entity can be put to the inventory (Cargo, ProxyCargo, Attachment)
Definition Inventory.c:931
proto native bool CanAddAttachmentEx(notnull EntityAI e, int slot)
Check if attachment can be added to slot @NOTE: Note that slot index IS NOT slot ID!...
proto native int GetAttachmentSlotsCount()
static proto native bool TestDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix=false, int conflictCheckDepth=-1)
proto native EntityAI FindPlaceholderForSlot(int slot)
Returns placeholder entity for slot (naked arms, legs etc)
proto native int GetSlotId(int index)
attachments
proto native bool FindFirstFreeLocationForNewEntity(string item_type, FindInventoryLocationType flags, out notnull InventoryLocation loc)
FindFirstFreeLocationForNewEntity.
static proto native bool ServerLocationSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, ParamsWriteContext ctx)
swaps two entities
static proto native bool CanForceSwapEntities(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
test if forced swap can be performed.
static proto native bool ExtendInventoryReservation(EntityAI item, InventoryLocation dst, int timeout_ms)
proto native EntityAI FindAttachment(int slot)
Returns attached entity in slot (you can use InventorySlots.GetSlotIdFromString(name) to get slot id)
proto native bool HasEntityInInventory(notnull EntityAI item)
query inventory if item is somewhere
proto native bool CanRemoveEntityInCargoEx(notnull EntityAI e, int idx, int row, int col)
bool OnStoreLoad(ParamsReadContext ctx, int version)
db load hooks
Definition Inventory.c:805
proto native bool GetSlotLock(int slot)
proto native void UnlockInventory(int lockType)
proto native int GetAttachmentSlotId(int index)
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)
test if the entity contained in inv_loc.m_item can be added to ground/attachment/cargo/hands/....
proto native int GetScriptLockCount()
static proto native bool CheckManipulatedObjectsDistances(notnull EntityAI e0, notnull EntityAI e1, float radius)
bool LocalDestroyEntity(notnull EntityAI item)
Definition Inventory.c:1292
bool TakeEntityToTargetCargo(InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
Put item into into cargo of another entity.
Definition Inventory.c:1051
void OnInventoryFailure(InventoryCommandType type, InventoryValidationReason reason, InventoryLocation src, InventoryLocation dst)
Definition Inventory.c:952
proto native bool CanRemoveAttachmentEx(EntityAI attachment, int slot)
proto native EntityAI CreateEntityInCargoEx(string typeName, int idx, int row, int col, bool flip)
Create Entity of specified type in cargo of entity at coordinates (row, col)
static proto native bool CheckSwapItemsRequest(notnull Man requestingPlayer, notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, float radius)
bool IsInCargo()
Returns true if this Inventory owner is in cargo of something.
Definition Inventory.c:380
static bool SetGroundPosByTransform(EntityAI owner, notnull EntityAI item, out InventoryLocation ground, vector transform[4])
Definition Inventory.c:1228
static proto native bool LocationMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
removes item from current inventory location and adds it to destination
bool TakeEntityToTargetInventory(InventoryMode mode, notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
helper that finds location first, then moves the entity into it
Definition Inventory.c:993
bool CanAddEntityIntoHands(notnull EntityAI item)
Test if entity can be put into hands.
Definition Inventory.c:939
void OnStoreSave(ParamsWriteContext ctx)
db store hook
Definition Inventory.c:811
proto native EntityAI GetInventoryOwner()
Engine native functions.
proto native int GetSlotIdCount()
static bool MakeDstForSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, out InventoryLocation dst1, out InventoryLocation dst2)
helper function for swap
Definition Inventory.c:1138
bool GetCurrentAttachmentSlotInfo(out int slot_id, out string slot_name)
Returns true if the item is currently attached and outputs attachment slot id and name.
Definition Inventory.c:427
void OnInventoryJunctureFailureFromServer(ParamsReadContext ctx)
Definition Inventory.c:948
static proto native bool LocationCanRemoveEntity(notnull InventoryLocation inv_loc)
queries if the entity contained in inv_loc.m_item can be removed from ground/attachment/cargo/hands/....
bool DropEntityWithTransform(InventoryMode mode, EntityAI owner, notnull EntityAI item, vector transform[4])
Definition Inventory.c:1235
bool CanAddEntityToInventory(notnull EntityAI item, int flag=FindInventoryLocationType.ANY)
ask inventory if item could be placed somewhere in inventory
Definition Inventory.c:869
bool TakeEntityAsTargetAttachmentEx(InventoryMode mode, notnull EntityAI target, notnull EntityAI item, int slot)
put item as attachment of target
Definition Inventory.c:1100
proto native int FindFreeLocationsFor(notnull EntityAI item, FindInventoryLocationType flags, out notnull array< ref InventoryLocation > locs)
searches inventory for suitable location for @item
static proto native bool CanSwapEntities(notnull EntityAI item1, notnull EntityAI item2)
test if ordinary swap can be performed.
bool OnInventoryJunctureRepairFromServer(ParamsReadContext ctx)
Definition Inventory.c:947
static proto native bool LocationCanAddEntity(notnull InventoryLocation inv_loc)
queries if the entity contained in inv_loc.m_item can be added to ground/attachment/cargo/hands/....
proto native void LockInventory(int lockType)
static proto native bool ServerHandEvent(notnull Man player, notnull EntityAI item, ParamsWriteContext ctx)
hand event to clients
static proto native EntityAI LocationGetEntity(notnull InventoryLocation inv_loc)
static bool LocationCanMoveEntitySyncCheck(notnull InventoryLocation src, notnull InventoryLocation dst)
Definition Inventory.c:363
bool IsAttachment()
Returns true if this Inventory owner is an attachment of something.
Definition Inventory.c:393
bool ExtendInventoryReservationEx(EntityAI item, InventoryLocation dst, int timeout_ms)
Definition Inventory.c:710
static proto native bool ServerLocationSyncMoveEntity(Man player, notnull EntityAI item, ParamsWriteContext ctx)
synchronously removes item from current inventory location and adds it to destination + sync via inve...
Abstracted event, not to be used, only inherited.
override string DumpToString()
static void SendServerMove(Man player, int type, notnull InventoryLocation src, notnull InventoryLocation dst)
InventoryLocation.
proto native int GetType()
returns type of InventoryLocation
proto native bool IsValid()
verify current set inventory location
proto native int GetCol()
returns column of cargo if current type is Cargo / ProxyCargo
proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip)
based on Cargo.IsProxyCargo uses SetProxyCargo or SetCargo respectively
proto native int GetRow()
returns row of cargo if current type is Cargo / ProxyCargo
proto native void SetCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip)
sets current inventory location type to Cargo with coordinates (idx, row, col)
proto native InventoryLocation CopyLocationFrom(notnull InventoryLocation rhs, bool copyFlip)
copies location to another location without m_item member
proto native int GetIdx()
returns index of cargo if current type is Cargo / ProxyCargo
proto native InventoryLocation Copy(notnull InventoryLocation rhs)
copies location data to another location
proto native void SetFlip(bool flip)
proto native EntityAI GetParent()
returns parent of current inventory location
bool ReadFromContext(ParamsReadContext ctx)
proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId)
sets current inventory location type to Attachment with slot id set to <slotId>
proto native EntityAI GetItem()
returns item of current inventory location
proto native bool GetFlip()
returns flip status of cargo
proto native int GetSlot()
returns slot id if current type is Attachment
static string DumpToStringNullSafe(InventoryLocation loc)
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
const int INVALID
Invalid slot (-1)
InventoryValidationResult m_Result
Definition Inventory.c:46
InventoryValidationReason m_Reason
Definition Inventory.c:47
static bool IsInventoryReservationLogEnable()
Definition Debug.c:610
Definition EnMath.c:7
base class for transformation operations (creating one item from another)
void Execute(HumanInventoryWithFSM fsm_to_notify=null)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)
Rotate a vector around 0,0,0.
Definition EnConvert.c:477
static const vector Up
Definition EnConvert.c:107
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition gameplay.c:6
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
const int INVENTORY_ENTITY_DROP_OVERLAP_DEPTH
Definition constants.c:885
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Definition EnMath3D.c:233
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].