45 bool m_IsJuncture =
false;
46 bool m_IsRemote =
false;
51 bool IsAuthoritative()
63 enum FindInventoryReservationMode
90 proto native
EntityAI GetInventoryOwner();
97 proto native
void DumpInventoryDebug();
103 static proto native
void DumpStaticInventoryDebug();
116 proto native
bool HasEntityInInventory(notnull
EntityAI item);
132 proto native
int CountInventory();
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);
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);
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);
159 proto native
bool CanRemoveEntityInCargo(notnull
EntityAI e);
160 proto native
bool CanRemoveEntityInCargoEx(notnull
EntityAI e,
int idx,
int row,
int col);
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 bool HasAttachmentSlot(
int slotId)
188 int count = GetAttachmentSlotsCount();
189 for (
int i = 0; i < count; i++)
191 if (GetAttachmentSlotId(i) == slotId)
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);
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);
246 proto native
bool CanRemoveAttachment(
EntityAI attachment);
247 proto native
bool CanRemoveAttachmentEx(
EntityAI attachment,
int slot);
255 proto native
EntityAI FindPlaceholderForSlot(
int slot);
256 proto native
bool IsPlaceholderEntity(notnull
Object e);
266 proto native
bool GetCurrentInventoryLocation(out notnull
InventoryLocation loc);
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);
350 return LocationCanAddEntity(inv_loc);
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);
373 static int GetInventoryCheckContext()
375 return m_inventory_check_context;
381 bool result = LocationCanMoveEntity(src, dst);
398 GetCurrentInventoryLocation(lcn);
411 GetCurrentInventoryLocation(lcn);
421 bool IsCargoInHiearchy()
427 if (ent.GetInventory().GetCurrentInventoryLocation(lcn) && lcn.IsValid())
433 ent = ent.GetHierarchyParent();
440 bool GetCurrentAttachmentSlotInfo(out
int slot_id, out
string slot_name)
445 GetCurrentInventoryLocation(lcn);
448 slot_id = lcn.GetSlot();
471 src.ReadFromContext(ctx);
472 dst.ReadFromContext(ctx);
475 if (!src.GetItem() || !dst.GetItem())
477 LogError(
"[syncinv] ServerInventoryCommand (cmd=SYNC_MOVE) dropped, item not in bubble");
481 LocationSyncMoveEntity(src, dst);
490 if (!e.GetSrcEntity())
492 Error(
"[syncinv] ServerInventoryCommand (cmd=HAND_EVENT) dropped, item not in bubble");
495 e.m_Player.GetHumanInventory().ProcessHandEvent(e);
506 src1.ReadFromContext(ctx);
507 src2.ReadFromContext(ctx);
508 dst1.ReadFromContext(ctx);
509 dst2.ReadFromContext(ctx);
511 if (src1.IsValid() && src2.IsValid() && dst1.IsValid() && dst2.IsValid())
515 LocationSwap(src1, src2, dst1, dst2);
536 static proto native
bool LocationRemoveEntity(notnull
InventoryLocation inv_loc);
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);
612 static proto native
bool CanSwapEntities(notnull
EntityAI item1, notnull
EntityAI item2);
614 static bool CanSwapEntitiesEx(notnull
EntityAI item1, notnull
EntityAI item2)
620 item2.GetInventory().GetCurrentInventoryLocation(il2);
621 slot = il2.GetSlot();
623 if (item1.GetQuantity() > item1.GetTargetQuantityMax(slot))
627 item1.GetInventory().GetCurrentInventoryLocation(il1);
628 slot = il1.GetSlot();
630 if (item2.GetQuantity() > item2.GetTargetQuantityMax(slot))
633 if (!item1.CanSwapEntities(item2, il2, il1) || !item2.CanSwapEntities(item1, il1, il2))
653 if (!CanForceSwapEntities(item1, item1_dst, item2, item2_dst) )
659 if (!item1.CanBeFSwaped())
662 if ( item1_dst ==
null)
664 item2.GetInventory().GetCurrentInventoryLocation(il);
669 slot = item1_dst.GetSlot();
672 if ( item1.GetQuantity() > item1.GetTargetQuantityMax(slot) )
675 if ( item2_dst ==
null)
677 item1.GetInventory().GetCurrentInventoryLocation(il);
682 slot = item2_dst.GetSlot();
685 if (!item1.CanSwapEntities(item2, item2_dst, item1_dst) || !item2.CanSwapEntities(item1, item1_dst, item2_dst))
690 if ( item2.GetQuantity() > item2.GetTargetQuantityMax(slot) )
699 const int c_InventoryReservationTimeoutMS = 5000;
700 const int c_InventoryReservationTimeoutShortMS = 3000;
708 bool ret_val = AddInventoryReservation(item, dst, timeout_ms);
710 if (
LogManager.IsInventoryReservationLogEnable() )
716 Debug.InventoryMoveLog(
"Reservation result: " + ret_val +
" - STS = " + player.GetSimulationTimeStamp() +
" / " + item.ToString() +
" / " +
InventoryLocation.DumpToStringNullSafe(dst),
"n/a" ,
"n/a",
"AddInventoryReservation", player.ToString() );
718 Debug.InventoryMoveLog(
"Reservation result: " + ret_val +
" - STS = " + player.GetSimulationTimeStamp() +
" / null / " +
InventoryLocation.DumpToStringNullSafe(dst),
"n/a" ,
"n/a",
"AddInventoryReservation", player.ToString() );
731 bool ret_val = ExtendInventoryReservation(item,dst,timeout_ms);
733 if (
LogManager.IsInventoryReservationLogEnable() )
739 Debug.InventoryMoveLog(
"Reservation result: " + ret_val +
" - STS = " + player.GetSimulationTimeStamp() +
" / " + item.ToString() +
" / " +
InventoryLocation.DumpToStringNullSafe(dst),
"n/a" ,
"n/a",
"ExtendInventoryReservation", player.ToString() );
741 Debug.InventoryMoveLog(
"Reservation result: " + ret_val +
" - STS = " + player.GetSimulationTimeStamp() +
" / null / " +
InventoryLocation.DumpToStringNullSafe(dst),
"n/a" ,
"n/a",
"ExtendInventoryReservation", player.ToString() );
756 if (
LogManager.IsInventoryReservationLogEnable() )
762 Debug.InventoryMoveLog(
"Reservation cleared result: " + ret_val +
" - STS = " + player.GetSimulationTimeStamp() +
" / " + item.ToString() +
" / " +
InventoryLocation.DumpToStringNullSafe(dst),
"n/a" ,
"n/a",
"ClearInventoryReservation", player.ToString() );
764 Debug.InventoryMoveLog(
"Reservation cleared result: " + ret_val +
" - STS = " + player.GetSimulationTimeStamp() +
" / null / " +
InventoryLocation.DumpToStringNullSafe(dst),
"n/a" ,
"n/a",
"ClearInventoryReservation", player.ToString() );
777 static proto native
bool HasInventoryReservationEx(
EntityAI item,
InventoryLocation dst, FindInventoryReservationMode itemMode, FindInventoryReservationMode parentMode);
779 proto native
int GetAnyInventoryReservationCount();
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();
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);
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);
806 static proto native
bool CheckManipulatedObjectsDistances(notnull
EntityAI e0, notnull
EntityAI e1,
float radius);
818 GetInventoryOwner().OnInventoryInit();
826 void OnAfterStoreLoad();
833 if (GetCurrentInventoryLocation(src))
837 Man man = Man.Cast(src.GetParent());
841 man.GetHumanInventory().OnEntityInHandsCreated(src);
849 EntityAI item = GetInventoryOwner();
850 Man player = item.GetHierarchyRootPlayer();
852 player.GetInventory().ClearInventoryReservationEx(item,
null);
861 EntityAI CreateInInventory(
string type)
866 switch (loc.GetType())
869 return loc.GetParent().GetInventory().CreateAttachmentEx(type, loc.GetSlot());
871 return loc.GetParent().GetInventory().CreateEntityInCargoEx(type, loc.GetIdx(), loc.GetRow(), loc.GetCol(), loc.GetFlip());
873 Error(
"CreateInInventory: unknown location for item");
894 bool result = FindFreeLocationFor(item, flag, il);
911 bool AddEntityToInventory(notnull
EntityAI item)
916 return LocationAddEntity(il);
924 bool CanRemoveEntity()
927 if (GetCurrentInventoryLocation(il))
928 return LocationCanRemoveEntity(il);
949 return FindFreeLocationFor(item, flags, loc) && !item.IsHologram();
955 bool CanAddEntityIntoInventory(notnull
EntityAI item)
963 bool CanAddEntityIntoHands(notnull
EntityAI item)
1003 if (item.GetInventory().GetCurrentInventoryLocation(src))
1006 if (FindFreeLocationFor(item, flags, dst))
1007 return TakeToDst(mode, src, dst);
1012 Error(
"[inv] I::Take2Inv(" +
typename.EnumToString(
InventoryMode, mode) +
") item=" + item +
" Error - src has no inventory location");
1022 if (item.GetInventory().GetCurrentInventoryLocation(src))
1026 if (target.GetInventory().FindFreeLocationFor(item, flags, dst))
1027 return TakeToDst(mode, src, dst);
1029 if (
LogManager.IsInventoryMoveLogEnable())
inventoryDebugPrint(
"[inv] I::Take2Target(" +
typename.EnumToString(
InventoryMode, mode) +
") target=" + target +
" item=" + item +
" Warning - no room for item in target");
1032 Error(
"[inv] I::Take2Target(" +
typename.EnumToString(
InventoryMode, mode) +
") target=" + target +
" item=" + item +
" Error - src has no inventory location");
1048 ret = LocationSyncMoveEntity(src, dst);
1049 if (ret && dst.IsValid())
1053 ret = LocationSyncMoveEntity(src, dst);
1088 if (item.GetInventory().GetCurrentInventoryLocation(src))
1091 dst.SetCargo(GetInventoryOwner(), item, idx, row, col, item.GetInventory().GetFlipCargo());
1093 return TakeToDst(mode, src, dst);
1095 Error(
"[inv] I::Take2Cgo(" +
typename.EnumToString(
InventoryMode, mode) +
") item=" + item +
" row=" + row +
" col=" + col +
" Error - src has no inventory location");
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))
1107 dst.SetCargoAuto(cargo, item, row, col, item.GetInventory().GetFlipCargo());
1109 return TakeToDst(mode, src, dst);
1111 Error(
"[inv] I::Take2TargetCgoEx(" +
typename.EnumToString(
InventoryMode, mode) +
") item=" + item +
"to cargo of target=" + cargo.GetCargoOwner() +
" row=" + row +
" col=" + col);
1118 return TakeEntityAsTargetAttachmentEx(mode, GetInventoryOwner(), item, slot);
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))
1129 EntityAI att = target.GetInventory().FindAttachment(slot);
1132 att.CombineItemsClient(item,
true);
1138 dst.SetAttachment(target, item, slot);
1139 return TakeToDst(mode, src, dst);
1142 Error(
"[inv] I::Take2AttEx(" +
typename.EnumToString(
InventoryMode, mode) +
") item=" + item +
" Error - src has no inventory location");
1165 dst1.CopyLocationFrom(src2,
false);
1166 dst1.SetFlip(src1.GetItem().GetInventory().GetFlipCargo());
1172 dst2.CopyLocationFrom(src1,
false);
1173 dst2.SetFlip(src2.GetItem().GetInventory().GetFlipCargo());
1184 if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
1185 return MakeDstForSwap(src1, src2, dst1, dst2);
1197 if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
1204 dst1.CopyLocationFrom(src2,
false);
1205 dst1.SetFlip(dst1.GetItem().GetInventory().GetFlipCargo());
1227 Math3D.MatrixIdentity4(m4);
1228 bool success =
GameInventory.PrepareDropEntityPos(owner, item, m4,
false,
GameConstants.INVENTORY_ENTITY_DROP_OVERLAP_DEPTH);
1229 ground.SetGround(item, m4);
1237 if (item.GetInventory().GetCurrentInventoryLocation(src))
1240 if (!SetGroundPosByOwner(owner, item, dst))
1246 return TakeToDst(mode, src, dst);
1249 Error(
"DropEntity - No inventory location");
1255 bool success =
GameInventory.PrepareDropEntityPos(owner, item, transform,
true,
GameConstants.INVENTORY_ENTITY_DROP_OVERLAP_DEPTH);
1256 ground.SetGround(item, transform);
1264 if (item.GetInventory().GetCurrentInventoryLocation(src))
1267 SetGroundPosByTransform(owner, item, dst, transform);
1269 return TakeToDst(mode, src, dst);
1272 Error(
"DropEntityWithTransform - No inventory location");
1279 owner.GetTransform(m4);
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);
1284 float dist = randomPos[0] * m4[1][0] + randomPos[1] * m4[1][1] + randomPos[2] * m4[1][2];
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];
1290 item.PlaceOnSurfaceRotated(m4,
Vector(m4[3][0], m4[3][1], m4[3][2]));
1292 ground.SetGround(item, m4);
1300 if (item.GetInventory().GetCurrentInventoryLocation(src))
1304 SetGroundPosByOwnerBounds(owner, item, dst, halfExtents, angle, cosAngle, sinAngle);
1306 return TakeToDst(mode, src, dst);
1309 Error(
"DropEntityInBounds - No inventory location");
1313 bool LocalDestroyEntity(notnull
EntityAI item)
1317 if (item.GetInventory().GetCurrentInventoryLocation(src))
1320 Error(
"[inv] Source location == HANDS, player has to handle this");
1322 GetGame().ObjectDelete(src.GetItem());
1326 Error(
"LocalDestroyEntity: No inventory location");
1333 if (lambda.m_OldItem.GetInventory().GetCurrentInventoryLocation(src))
1335 if (
LogManager.IsInventoryMoveLogEnable())
inventoryDebugPrint(
"[inv] I::ReplaceItemWithNew executing lambda=" + lambda +
"on old_item=" + lambda.m_OldItem);
1340 Error(
"[inv] I::ReplaceItemWithNew - no inventory location");
1344 proto native
bool GetFlipCargo();
1345 proto native
void SetFlipCargo(
bool flip);
1346 proto native
void FlipCargo();
1347 proto native
void ResetFlipCargo();