11 int m_syncClearUserReservationindex = -1;
16 proto native
EntityAI GetEntityInHands();
21 proto native
bool CanAddEntityInHands(
EntityAI e);
30 proto native
bool TestAddEntityInHands(
EntityAI e,
bool do_resevation_check,
bool do_item_check,
bool do_lock_check,
bool do_occupancy_test,
bool do_script_check);
35 proto native
bool CanRemoveEntityInHands();
37 proto native
bool CanOpenInventory();
44 proto native
EntityAI CreateInHands(
string typeName);
46 proto native
int GetUserReservedLocationCount();
47 proto native
int FindUserReservedLocationIndex(notnull
EntityAI e);
49 proto native
void GetUserReservedLocation(
int index, out notnull
InventoryLocation dst);
50 proto native
int FindFirstUserReservedLocationIndexForContainer(notnull
EntityAI e);
53 proto native
void ClearUserReservedLocation(notnull
EntityAI eai);
54 proto native
bool ClearUserReservedLocationAtIndex(
int index);
55 proto native
void ClearUserReservedLocationForContainer(notnull
EntityAI eai);
56 proto native
bool GetDebugFlag();
65 override EntityAI CreateInInventory(
string type)
67 EntityAI newEntity = super.CreateInInventory(type);
68 if (newEntity == null)
69 newEntity = CreateInHands(type);
73 void ClearUserReservedLocationSynced(notnull
EntityAI eai)
76 m_syncClearUserReservationindex = FindUserReservedLocationIndex(eai);
77 else if (!
g_Game.IsMultiplayer())
79 ClearUserReservedLocation(eai);
80 eai.GetOnReleaseLock().Invoke(eai);
85 void ClearUserReservedLocationAtIndexSynced(
int index)
88 m_syncClearUserReservationindex = index;
89 else if (!
g_Game.IsMultiplayer())
91 ClearUserReservedLocationAtIndex(index);
95 GetUserReservedLocation(index,il);
97 item.GetOnReleaseLock().Invoke(item);
109 return e == GetEntityInHands();
123 ProcessHandEvent(
new HandEventCreated(GetManOwner(), src));
131 ProcessHandEvent(
new HandEventDestroyed(GetManOwner(), cpy));
147 switch (src.GetType())
151 HandEvent(mode,
new HandEventDrop(GetManOwner(), src));
155 return super.DropEntity(mode, owner, item);
160 Error(
"No inventory location");
172 if (player.NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), null))
181 switch (src.GetType())
185 HandEventThrow throwEvent =
new HandEventThrow(GetManOwner(), src);
186 throwEvent.SetForce(dir * force);
187 HandEvent(invMode, throwEvent);
191 DropEntity(invMode, player, item);
196 Error(
"No inventory location");
204 Man man_src = Man.Cast(src.GetParent());
205 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HI::RedirectToHandEvent - source location == HANDS, player has to handle this");
209 int r_index = FindUserReservedLocationIndex(item);
214 GetUserReservedLocation(r_index,r_il);
216 ClearUserReservedLocationAtIndex(r_index);
217 int r_type = r_il.GetType();
220 r_il.GetParent().GetOnReleaseLock().Invoke(item);
224 r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(item, r_il.GetSlot());
228 man_src.GetHumanInventory().HandEvent(mode,
new HandEventMoveTo(man_src, src, dst));
234 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HI::RedirectToHandEvent - dst location == HANDS, player has to handle this");
236 Man man_dst = Man.Cast(dst.GetParent());
237 man_dst.GetHumanInventory().HandEvent(mode,
new HandEventTake(man_dst, src));
247 if (GetManOwner().IsAlive() && RedirectToHandEvent(mode, src, dst))
250 return super.TakeToDst(mode, src, dst);
256 if (item.GetInventory().GetCurrentInventoryLocation(src))
261 if (RedirectToHandEvent(mode, src, dst))
265 return super.TakeEntityToInventory(mode, flags, item);
270 Error(
"HumanInventory::TakeEntityToInventory: No inventory location");
277 override bool TakeEntityToCargoEx(
InventoryMode mode, notnull
EntityAI item,
int idx,
int row,
int col)
283 switch (src.GetType())
287 if (inventoryOwner.IsAlive())
289 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::Take2Cgo(" +
typename.EnumToString(
InventoryMode, mode) +
") item=" + item +
" row=" + row +
" col=" + col);
291 dst.SetCargo(inventoryOwner, item, idx, row, col, itemInventory.
GetFlipCargo());
293 HandEvent(mode,
new HandEventMoveTo(GetManOwner(), src, dst));
297 return super.TakeEntityToCargoEx(mode, item, idx, row, col);
300 return super.TakeEntityToCargoEx(mode, item, idx, row, col);
304 Error(
"HumanInventory::TakeEntityToCargoEx: No inventory location");
311 if (item.GetInventory().GetCurrentInventoryLocation(src))
313 switch (src.GetType())
317 if (inventoryOwner.IsAlive())
321 dst.SetAttachment(inventoryOwner, item, slot);
323 HandEvent(mode,
new HandEventMoveTo(GetManOwner(), src, dst));
327 return super.TakeEntityAsAttachmentEx(mode, item, slot);
330 return super.TakeEntityAsAttachmentEx(mode, item, slot);
334 Error(
"HumanInventory::TakeEntityAsAttachmentEx: No inventory location");
343 bool handled =
false;
344 switch (src1.GetType())
352 HandEvent(mode,
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, fswap_dst2));
357 HandEvent(mode,
new HandEventSwap(GetManOwner(), src1, src2, dst1, dst2));
363 switch (src2.GetType())
367 HandEvent(mode,
new HandEventSwap(GetManOwner(), src2, src1, dst2, dst1));
373 return super.SwapEntities(mode, item1, item2);
378 Error(
"HumanInventory::SwapEntities: cannot create src1, src2, dst1, dst2");
387 GameInventory manOwnerInventory = GetManOwner().GetInventory();
390 bool handled =
false;
391 switch (src1.GetType())
395 HandEventBase e =
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, item2_dst);
396 e.ReserveInventory();
403 switch (src2.GetType())
411 HandEvent(mode,
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, fswap_dst2));
416 HandEvent(mode,
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, item2_dst));
423 bool returnValue =
true;
426 returnValue = super.ForceSwapEntities(mode, item1, item2, item2_dst);
431 Error(
"HumanInventory::ForceSwapEntities: No inventory location");
435 override bool LocalDestroyEntity(notnull
EntityAI item)
438 if (item.GetInventory().GetCurrentInventoryLocation(src))
440 switch (src.GetType())
445 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::LocalDestroy inv item=" + item);
446 HandEvent(
InventoryMode.LOCAL,
new HandEventDestroy(GetManOwner(), src));
450 return super.LocalDestroyEntity(item);
453 return super.LocalDestroyEntity(item);
457 Error(
"LocalDestroyEntity: No inventory location");
463 EntityAI itemInHands = GetEntityInHands();
464 if (itemInHands == lambda.m_OldItem)
467 return super.ReplaceItemWithNew(mode, lambda);
472 HandEventBase heb =
new HandEventDestroyElsewhereAndReplaceWithNewInHands(GetManOwner(), null, lambda);
478 if (GetEntityInHands())
480 Error(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl Item in hands, event=" + e.DumpToString());
487 switch (dst.GetType())
492 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl event=" + e);
498 Error(
"HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl TODO");
502 Error(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl src has to be hands");
507 Error(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl no dst in event, event=" + e.DumpToString());
513 EntityAI itemInHands = GetEntityInHands();
515 if (itemInHands && itemInHands.GetInventory().GetCurrentInventoryLocation(src))
517 switch (src.GetType())
522 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl event=" + e);
532 Error(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl src has to be hands");
537 Error(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl No item in hands, event=" + e.DumpToString());
549 HandEventBase heb =
new HandEventDestroyAndReplaceWithNewElsewhere(GetManOwner(), null, lambda);
555 bool SwapToPrevious =
true;
562 if (item1.m_OldLocation && item1.m_OldLocation.IsValid() && !item1.m_OldLocation.CollidesWith(src2) && item1.m_OldLocation.GetParent() && item1.m_OldLocation.GetParent().GetHierarchyRootPlayer())
564 dst.Copy(item1.m_OldLocation);
569 for (
int i = 0; i < count; ++i)
571 int slotID = item1Inventory.
GetSlotId(i);
572 if (src2.GetSlot() == slotID)
577 if (!item1.m_OldLocation.GetParent().GetInventory().LocationCanAddEntity(item1.m_OldLocation))
578 SwapToPrevious =
false;
581 SwapToPrevious =
false;
601 ctx.Write(m_syncClearUserReservationindex);
606 GetUserReservedLocation(m_syncClearUserReservationindex,il);
607 ClearUserReservedLocationAtIndex(m_syncClearUserReservationindex);
609 item.GetOnReleaseLock().Invoke(item);
610 m_syncClearUserReservationindex = -1;
619 if (!ctx.Read(index))
625 ClearUserReservedLocationAtIndex(index);