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 (!
GetGame().IsMultiplayer())
79 ClearUserReservedLocation(eai);
80 eai.GetOnReleaseLock().Invoke(eai);
85 void ClearUserReservedLocationAtIndexSynced(
int index)
88 m_syncClearUserReservationindex = index;
89 else if (!
GetGame().IsMultiplayer())
91 ClearUserReservedLocationAtIndex(index);
95 GetUserReservedLocation(index,il);
97 item.GetOnReleaseLock().Invoke(item);
104 return Man.Cast(GetInventoryOwner());
109 return e == GetEntityInHands();
123 ProcessHandEvent(
new HandEventCreated(GetManOwner(), src));
131 ProcessHandEvent(
new HandEventDestroyed(GetManOwner(), cpy));
142 if (item && item.GetInventory() && item.GetInventory().GetCurrentInventoryLocation(src))
144 switch (src.GetType())
148 HandEvent(mode,
new HandEventDrop(GetManOwner(), src));
152 return super.DropEntity(mode, owner, item);
156 Error(
"No inventory location");
168 if (player.NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(),
null))
172 if (item && item.GetInventory() && item.GetInventory().GetCurrentInventoryLocation(src))
174 switch (src.GetType())
178 HandEventThrow throwEvent =
new HandEventThrow(GetManOwner(), src);
179 throwEvent.SetForce(dir * force);
180 HandEvent(invMode, throwEvent);
184 DropEntity(invMode, player, item);
188 Error(
"No inventory location");
196 Man man_src = Man.Cast(src.GetParent());
197 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HI::RedirectToHandEvent - source location == HANDS, player has to handle this");
201 int r_index = FindUserReservedLocationIndex(item);
206 GetUserReservedLocation(r_index,r_il);
208 ClearUserReservedLocationAtIndex(r_index);
209 int r_type = r_il.GetType();
212 r_il.GetParent().GetOnReleaseLock().Invoke(item);
216 r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(item, r_il.GetSlot());
220 man_src.GetHumanInventory().HandEvent(mode,
new HandEventMoveTo(man_src, src, dst));
226 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HI::RedirectToHandEvent - dst location == HANDS, player has to handle this");
228 Man man_dst = Man.Cast(dst.GetParent());
229 man_dst.GetHumanInventory().HandEvent(mode,
new HandEventTake(man_dst, src));
239 if (GetManOwner().IsAlive() && RedirectToHandEvent(mode, src, dst))
242 return super.TakeToDst(mode, src, dst);
248 if (item.GetInventory().GetCurrentInventoryLocation(src))
251 if (FindFreeLocationFor(item, flags, dst))
253 if (RedirectToHandEvent(mode, src, dst))
257 return super.TakeEntityToInventory(mode, flags, item);
262 Error(
"HumanInventory::TakeEntityToInventory: No inventory location");
269 override bool TakeEntityToCargoEx(
InventoryMode mode, notnull
EntityAI item,
int idx,
int row,
int col)
272 if (item.GetInventory().GetCurrentInventoryLocation(src))
274 switch (src.GetType())
277 if (GetInventoryOwner().IsAlive())
279 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::Take2Cgo(" +
typename.EnumToString(
InventoryMode, mode) +
") item=" + item +
" row=" + row +
" col=" + col);
281 dst.SetCargo(GetInventoryOwner(), item, idx, row, col, item.GetInventory().GetFlipCargo());
283 HandEvent(mode,
new HandEventMoveTo(GetManOwner(), src, dst));
287 return super.TakeEntityToCargoEx(mode, item, idx, row, col);
290 return super.TakeEntityToCargoEx(mode, item, idx, row, col);
294 Error(
"HumanInventory::TakeEntityToCargoEx: No inventory location");
301 if (item.GetInventory().GetCurrentInventoryLocation(src))
303 switch (src.GetType())
306 if (GetInventoryOwner().IsAlive())
310 EntityAI src_entity = GetInventoryOwner();
311 dst.SetAttachment(src_entity, item, slot);
313 HandEvent(mode,
new HandEventMoveTo(GetManOwner(), src, dst));
317 return super.TakeEntityAsAttachmentEx(mode, item, slot);
320 return super.TakeEntityAsAttachmentEx(mode, item, slot);
324 Error(
"HumanInventory::TakeEntityAsAttachmentEx: No inventory location");
331 if (
GameInventory.MakeSrcAndDstForSwap(item1, item2, src1, src2, dst1, dst2))
333 bool handled =
false;
334 switch (src1.GetType())
339 if ( SwappingToPreviousLocation(item1, item2, fswap_dst2) )
342 HandEvent(mode,
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, fswap_dst2));
347 HandEvent(mode,
new HandEventSwap(GetManOwner(), src1, src2, dst1, dst2));
353 switch (src2.GetType())
357 HandEvent(mode,
new HandEventSwap(GetManOwner(), src2, src1, dst2, dst1));
363 return super.SwapEntities(mode, item1, item2);
368 Error(
"HumanInventory::SwapEntities: cannot create src1, src2, dst1, dst2");
375 if (
GameInventory.MakeSrcAndDstForForceSwap(item1, item2, src1, src2, dst1, item2_dst))
377 GameInventory manOwnerInventory = GetManOwner().GetInventory();
380 bool handled =
false;
381 switch (src1.GetType())
385 HandEventBase e =
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, item2_dst);
386 e.ReserveInventory();
393 switch (src2.GetType())
398 if ( SwappingToPreviousLocation(item2, item1, fswap_dst2))
401 HandEvent(mode,
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, fswap_dst2));
406 HandEvent(mode,
new HandEventForceSwap(GetManOwner(), src1, src2, dst1, item2_dst));
413 bool returnValue =
true;
416 returnValue = super.ForceSwapEntities(mode, item1, item2, item2_dst);
421 Error(
"HumanInventory::ForceSwapEntities: No inventory location");
425 override bool LocalDestroyEntity(notnull
EntityAI item)
428 if (item.GetInventory().GetCurrentInventoryLocation(src))
430 switch (src.GetType())
433 if (GetInventoryOwner().IsAlive())
435 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::LocalDestroy inv item=" + item);
436 HandEvent(
InventoryMode.LOCAL,
new HandEventDestroy(GetManOwner(), src));
440 return super.LocalDestroyEntity(item);
443 return super.LocalDestroyEntity(item);
447 Error(
"LocalDestroyEntity: No inventory location");
453 EntityAI itemInHands = GetEntityInHands();
454 if (itemInHands == lambda.m_OldItem)
455 return ReplaceItemInHandsWithNew(mode, lambda);
457 return super.ReplaceItemWithNew(mode, lambda);
462 return ReplaceItemInElsewhereWithNewinHandsImpl(mode,
new HandEventDestroyElsewhereAndReplaceWithNewInHands(GetManOwner(),
null, lambda));
467 if (GetEntityInHands())
469 Error(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl Item in hands, event=" + e.DumpToString());
476 switch (dst.GetType())
479 if (GetInventoryOwner().IsAlive())
481 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl event=" + e);
486 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl DEAD_owner=" + GetInventoryOwner().
GetName() +
"="+ GetInventoryOwner());
487 Error(
"HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl TODO");
491 Error(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl src has to be hands");
496 Error(
"[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl no dst in event, event=" + e.DumpToString());
502 EntityAI itemInHands = GetEntityInHands();
504 if (itemInHands && itemInHands.GetInventory().GetCurrentInventoryLocation(src))
506 switch (src.GetType())
509 if ((mode !=
InventoryMode.SERVER) && GetInventoryOwner().IsAlive())
511 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl event=" + e);
516 if (
LogManager.IsInventoryHFSMLogEnable())
hndDebugPrint(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl DEAD_owner=" + GetInventoryOwner().
GetName() +
"="+ GetInventoryOwner());
521 Error(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl src has to be hands");
526 Error(
"[inv] HumanInventory::ReplaceItemInHandsWithNewImpl No item in hands, event=" + e.DumpToString());
537 return ReplaceItemInHandsWithNewImpl(mode,
new HandEventDestroyAndReplaceWithNewElsewhere(GetManOwner(),
null, lambda));
542 bool SwapToPrevious =
true;
546 if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
548 if (item1.m_OldLocation && item1.m_OldLocation.IsValid() && !item1.m_OldLocation.CollidesWith(src2) && item1.m_OldLocation.GetParent() && item1.m_OldLocation.GetParent().GetHierarchyRootPlayer())
550 dst.Copy(item1.m_OldLocation);
552 int count = item1.GetInventory().GetSlotIdCount();
555 for (
int i = 0; i < count; i++)
557 int slotID = item1.GetInventory().GetSlotId(i);
558 if (src2.GetSlot() == slotID)
563 if (!item1.m_OldLocation.GetParent().GetInventory().LocationCanAddEntity(item1.m_OldLocation))
564 SwapToPrevious =
false;
566 if (CanSwapEntitiesEx(item1,item2))
567 SwapToPrevious =
false;
577 void HandleInventoryManipulation();
579 void Update(
float delta_time)
587 ctx.Write(m_syncClearUserReservationindex);
592 GetUserReservedLocation(m_syncClearUserReservationindex,il);
593 ClearUserReservedLocationAtIndex(m_syncClearUserReservationindex);
595 item.GetOnReleaseLock().Invoke(item);
596 m_syncClearUserReservationindex = -1;
605 if (!ctx.Read(index))
611 ClearUserReservedLocationAtIndex(index);