DayZ 1.24
Loading...
Searching...
No Matches
HumanInventory.c
Go to the documentation of this file.
1
10{
12 //int m_UserReservationToClear = -1;
17
22
31
36
38
45
51
57
65 override EntityAI CreateInInventory(string type)
66 {
67 EntityAI newEntity = super.CreateInInventory(type);
68 if (newEntity == null)
70 return newEntity;
71 }
72
74 {
75 if (GetGame().IsClient())
77 else if (!GetGame().IsMultiplayer())
78 {
80 eai.GetOnReleaseLock().Invoke(eai);
81 }
82
83 }
84
86 {
87 if (GetGame().IsClient())
89 else if (!GetGame().IsMultiplayer())
90 {
92
94
96 EntityAI item = il.GetItem();
97 item.GetOnReleaseLock().Invoke(item);
98 }
99
100 }
101
103 {
104 return Man.Cast(GetInventoryOwner());
105 }
106
108 {
109 return e == GetEntityInHands();
110 }
111
113
117
119 {
121 cpy.Copy(src);
122 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] OnEntityInHandsCreated src=" + InventoryLocation.DumpToStringNullSafe(cpy));
123 ProcessHandEvent(new HandEventCreated(GetManOwner(), src));
124 }
125
127 {
129 cpy.Copy(src);
130 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] OnEntityInHandsDestroyed src=" + InventoryLocation.DumpToStringNullSafe(cpy));
131 ProcessHandEvent(new HandEventDestroyed(GetManOwner(), cpy));
132 }
133
135 {
136 return true;
137 }
138
140 {
142 if (item && item.GetInventory() && item.GetInventory().GetCurrentInventoryLocation(src))
143 {
144 switch (src.GetType())
145 {
146 case InventoryLocationType.HANDS:
147 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::DropEntity(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
148 HandEvent(mode, new HandEventDrop(GetManOwner(), src));
149 return true;
150
151 default:
152 return super.DropEntity(mode, owner, item);
153 }
154 }
155
156 Error("No inventory location");
157 return false;
158 }
159
161 {
162 if (GetGame().IsServer() && GetGame().IsMultiplayer())
163 return false;
164
165 DayZPlayer player = DayZPlayer.Cast(item.GetHierarchyRootPlayer());
167
168 if (player.NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), null))
169 invMode = InventoryMode.JUNCTURE;
170
172 if (item && item.GetInventory() && item.GetInventory().GetCurrentInventoryLocation(src))
173 {
174 switch (src.GetType())
175 {
176 case InventoryLocationType.HANDS:
177 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::ThrowEntity item=" + item);
178 HandEventThrow throwEvent = new HandEventThrow(GetManOwner(), src);
179 throwEvent.SetForce(dir * force);
181 return true;
182
183 default:
185 return true;
186 }
187 }
188 Error("No inventory location");
189 return false;
190 }
191
193 {
194 if (src.GetType() == InventoryLocationType.HANDS)
195 {
196 Man man_src = Man.Cast(src.GetParent());
197 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HI::RedirectToHandEvent - source location == HANDS, player has to handle this");
198
199 EntityAI item = src.GetItem();
200
202
203 if (r_index >= 0)
204 {
207
209 int r_type = r_il.GetType();
210 if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO)
211 r_il.GetParent().GetOnReleaseLock().Invoke(item);
212 else if (r_type == InventoryLocationType.ATTACHMENT)
213 r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(item, r_il.GetSlot());
214 }
215
216 man_src.GetHumanInventory().HandEvent(mode, new HandEventMoveTo(man_src, src, dst));
217 return true;
218 }
219
220 if (dst.GetType() == InventoryLocationType.HANDS)
221 {
222 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HI::RedirectToHandEvent - dst location == HANDS, player has to handle this");
223
224 Man man_dst = Man.Cast(dst.GetParent());
225 man_dst.GetHumanInventory().HandEvent(mode, new HandEventTake(man_dst, src));
226 return true;
227 }
228 return false;
229 }
230
232 {
234
235 if (GetManOwner().IsAlive() && RedirectToHandEvent(mode, src, dst))
236 return true;
237
238 return super.TakeToDst(mode, src, dst);
239 }
240
242 {
244 if (item.GetInventory().GetCurrentInventoryLocation(src))
245 {
247 if (FindFreeLocationFor(item, flags, dst))
248 {
250 return true;
251
252 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item);
253 return super.TakeEntityToInventory(mode, flags, item);
254 }
255 else
256 return false; // no room
257 }
258 Error("HumanInventory::TakeEntityToInventory: No inventory location");
259 return false;
260 }
261
266 {
268 if (item.GetInventory().GetCurrentInventoryLocation(src))
269 {
270 switch (src.GetType())
271 {
272 case InventoryLocationType.HANDS:
273 if (GetInventoryOwner().IsAlive())
274 {
275 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " row=" + row + " col=" + col);
277 dst.SetCargo(GetInventoryOwner(), item, idx, row, col, item.GetInventory().GetFlipCargo());
278
279 HandEvent(mode, new HandEventMoveTo(GetManOwner(), src, dst));
280 return true;
281 }
282
283 return super.TakeEntityToCargoEx(mode, item, idx, row, col);
284
285 default:
286 return super.TakeEntityToCargoEx(mode, item, idx, row, col);
287 }
288 }
289
290 Error("HumanInventory::TakeEntityToCargoEx: No inventory location");
291 return false;
292 }
293
295 {
297 if (item.GetInventory().GetCurrentInventoryLocation(src))
298 {
299 switch (src.GetType())
300 {
301 case InventoryLocationType.HANDS:
302 if (GetInventoryOwner().IsAlive())
303 {
304 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::Take2Att(" + typename.EnumToString(InventoryMode, mode) + ") item=" + item + " slot=" + slot);
307 dst.SetAttachment(src_entity, item, slot);
308
309 HandEvent(mode, new HandEventMoveTo(GetManOwner(), src, dst));
310 return true;
311 }
312
313 return super.TakeEntityAsAttachmentEx(mode, item, slot);
314
315 default:
316 return super.TakeEntityAsAttachmentEx(mode, item, slot);
317 }
318 }
319
320 Error("HumanInventory::TakeEntityAsAttachmentEx: No inventory location");
321 return false;
322 }
323
325 {
328 {
329 bool handled = false;
330 switch (src1.GetType())
331 {
332 case InventoryLocationType.HANDS:
336 {
337 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::Swap HandEventForceSwap(" + typename.EnumToString(InventoryMode, mode) + ") IH=src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2));
338 HandEvent(mode, new HandEventForceSwap(GetManOwner(), src1, src2, dst1, fswap_dst2));
339 }
340 else
341 {
342 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::Swap HandEventSwap(" + typename.EnumToString(InventoryMode, mode) + ") src1=" + InventoryLocation.DumpToStringNullSafe(src1) + "src2=" + InventoryLocation.DumpToStringNullSafe(src2));
344 }
345 handled = true;
346 break;
347 }
348
349 switch (src2.GetType())
350 {
351 case InventoryLocationType.HANDS:
352 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::Swap HandEventSwap2(" + typename.EnumToString(InventoryMode, mode) + ") src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " IH=src2=" + InventoryLocation.DumpToStringNullSafe(src2));
354 handled = true;
355 break;
356 }
357
358 if (!handled)
359 return super.SwapEntities(mode, item1, item2);
360
361 return true;
362 }
363
364 Error("HumanInventory::SwapEntities: cannot create src1, src2, dst1, dst2");
365 return false;
366 }
367
369 {
372 {
374
375 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::FSwap(" + typename.EnumToString(InventoryMode, mode) + ") dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(item2_dst));
376 bool handled = false;
377 switch (src1.GetType())
378 {
379 case InventoryLocationType.HANDS:
381 HandEventBase e = new HandEventForceSwap(GetManOwner(), src1, src2, dst1, item2_dst);
382 e.ReserveInventory();
383 HandEvent(mode, e);
384 handled = true;
385 break;
386
387 }
388
389 switch (src2.GetType())
390 {
391 case InventoryLocationType.HANDS:
395 {
397 HandEvent(mode, new HandEventForceSwap(GetManOwner(), src1, src2, dst1, fswap_dst2));
398 }
399 else
400 {
402 HandEvent(mode, new HandEventForceSwap(GetManOwner(), src1, src2, dst1, item2_dst));
403 }
404
405 handled = true;
406 break;
407 }
408
409 bool returnValue = true;
410
411 if (!handled)
412 returnValue = super.ForceSwapEntities(mode, item1, item2, item2_dst);
413
414 return returnValue;
415 }
416
417 Error("HumanInventory::ForceSwapEntities: No inventory location");
418 return false;
419 }
420
422 {
424 if (item.GetInventory().GetCurrentInventoryLocation(src))
425 {
426 switch (src.GetType())
427 {
428 case InventoryLocationType.HANDS:
429 if (GetInventoryOwner().IsAlive())
430 {
431 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::LocalDestroy inv item=" + item);
432 HandEvent(InventoryMode.LOCAL, new HandEventDestroy(GetManOwner(), src));
433 return true;
434 }
435
436 return super.LocalDestroyEntity(item);
437
438 default:
439 return super.LocalDestroyEntity(item);
440 }
441 }
442
443 Error("LocalDestroyEntity: No inventory location");
444 return false;
445 }
446
448 {
450 if (itemInHands == lambda.m_OldItem)
452
453 return super.ReplaceItemWithNew(mode, lambda);
454 }
455
457 {
458 return ReplaceItemInElsewhereWithNewinHandsImpl(mode, new HandEventDestroyElsewhereAndReplaceWithNewInHands(GetManOwner(), null, lambda));
459 }
460
462 {
463 if (GetEntityInHands())
464 {
465 Error("[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl Item in hands, event=" + e.DumpToString());
466 return false;
467 }
468
469 InventoryLocation dst = e.GetDst();
470 if (dst)
471 {
472 switch (dst.GetType())
473 {
474 case InventoryLocationType.HANDS:
475 if (GetInventoryOwner().IsAlive())
476 {
477 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl event=" + e);
478 HandEvent(mode, e);
479 return true;
480 }
481
482 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl DEAD_owner=" + GetInventoryOwner().GetName() + "=" + GetInventoryOwner());
483 Error("HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl TODO"); // replace-with-new in corpse's hands, not implemented
484 return false;
485
486 default:
487 Error("[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl src has to be hands");
488 return false;
489 }
490 }
491
492 Error("[inv] HumanInventory::ReplaceItemInElsewhereWithNewinHandsImpl no dst in event, event=" + e.DumpToString());
493 return false;
494 }
495
497 {
500 if (itemInHands && itemInHands.GetInventory().GetCurrentInventoryLocation(src))
501 {
502 switch (src.GetType())
503 {
504 case InventoryLocationType.HANDS:
505 if ((mode != InventoryMode.SERVER) && GetInventoryOwner().IsAlive())
506 {
507 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::ReplaceItemInHandsWithNewImpl event=" + e);
508 HandEvent(mode, e);
509 return true;
510 }
511
512 if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[inv] HumanInventory::ReplaceItemInHandsWithNewImpl DEAD_owner=" + GetInventoryOwner().GetName() + "=" + GetInventoryOwner());
513 HandEvent(mode, e);
514 return true;
515
516 default:
517 Error("[inv] HumanInventory::ReplaceItemInHandsWithNewImpl src has to be hands");
518 return false;
519 }
520 }
521
522 Error("[inv] HumanInventory::ReplaceItemInHandsWithNewImpl No item in hands, event=" + e.DumpToString());
523 return false;
524 }
525
530
532 {
533 return ReplaceItemInHandsWithNewImpl(mode, new HandEventDestroyAndReplaceWithNewElsewhere(GetManOwner(), null, lambda));
534 }
535
537 {
538 bool SwapToPrevious = true;
541 dst = new InventoryLocation();
542 if (item1.GetInventory().GetCurrentInventoryLocation(src1) && item2.GetInventory().GetCurrentInventoryLocation(src2))
543 {
544 if (item1.m_OldLocation && item1.m_OldLocation.IsValid() && !item1.m_OldLocation.CollidesWith(src2) && item1.m_OldLocation.GetParent() && item1.m_OldLocation.GetParent().GetHierarchyRootPlayer())
545 {
546 dst.Copy(item1.m_OldLocation);
547
548 int count = item1.GetInventory().GetSlotIdCount();
549 if (count > 0 && src2.GetType() == InventoryLocationType.ATTACHMENT) //item2 is currently attached somewhere
550 {
551 for (int i = 0; i < count; i++)
552 {
553 int slotID = item1.GetInventory().GetSlotId(i);
554 if (src2.GetSlot() == slotID) //can be attached into the same slot. And will be.
555 return false;
556 }
557 }
558
559 if (!item1.m_OldLocation.GetParent().GetInventory().LocationCanAddEntity(item1.m_OldLocation))
560 SwapToPrevious = false;
561
563 SwapToPrevious = false;
564
565 if (SwapToPrevious)
566 return true;
567 }
568 }
569
570 return false;
571 }
572
574
595
597 {
598 validation.m_Result = InventoryValidationResult.SUCCESS;
599
600 int index = -1;
601 if (!ctx.Read(index))
602 {
604 return true;
605 }
606
608 //m_UserReservationToClear = index;
609
610 return true;
611 }
612}
InventoryCommandType
Definition Inventory.c:3
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
InventoryValidationResult
Definition Inventory.c:30
const int INPUT_UDT_INVENTORY
Definition _constants.c:9
void hndDebugPrint(string s)
Definition HandFSM.c:1
FindInventoryLocationType
flags for searching locations in inventory
InventoryLocationType
types of Inventory Location
script counterpart to engine's class Inventory
Definition Inventory.c:79
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:1166
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
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:1178
proto native EntityAI GetInventoryOwner()
Engine native functions.
proto native bool FindFreeLocationFor(notnull EntityAI item, FindInventoryLocationType flags, out notnull InventoryLocation loc)
FindFreeLocationFor.
Abstracted event, not to be used, only inherited.
represent hand state base
inventory for plain man/human
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)
override bool ReplaceItemWithNew(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
proto native void SetUserReservedLocation(notnull EntityAI eai, notnull InventoryLocation dst)
int m_syncClearUserReservationindex
void ClearUserReservedLocationAtIndexSynced(int index)
proto native EntityAI CreateInHands(string typeName)
creates new entity in hands
proto native EntityAI GetEntityInHands()
override bool TakeEntityAsAttachmentEx(InventoryMode mode, notnull EntityAI item, int slot)
bool ProcessHandEvent(HandEventBase e)
proto native void ClearUserReservedLocationForContainer(notnull EntityAI eai)
proto native int GetUserReservedLocationCount()
proto native int FindCollidingUserReservedLocationIndex(notnull EntityAI e, notnull InventoryLocation dst)
proto native bool CanAddEntityInHands(EntityAI e)
alternative for TestAddEntityInHands(e, true, true, true);
bool HandEvent(InventoryMode mode, HandEventBase e)
proto native int FindFirstUserReservedLocationIndexForContainer(notnull EntityAI e)
void ClearUserReservedLocationSynced(notnull EntityAI eai)
void OnHandsEnteredStableState(HandStateBase src, HandStateBase dst)
void OnEntityInHandsDestroyed(InventoryLocation src)
bool ReplaceItemInHandsWithNewElsewhere(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
proto native bool CanOpenInventory()
void OnHandsExitedStableState(HandStateBase src, HandStateBase dst)
bool RedirectToHandEvent(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
bool ReplaceItemElsewhereWithNewInHands(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
bool HasEntityInHands(EntityAI e)
proto native void ClearUserReservedLocation(notnull EntityAI eai)
override EntityAI CreateInInventory(string type)
creates entity somewhere in inventory
void HandleInventoryManipulation()
override bool TakeEntityToInventory(InventoryMode mode, FindInventoryLocationType flags, notnull EntityAI item)
proto native int FindUserReservedLocationIndex(notnull EntityAI e)
void OnHandsStateChanged(HandStateBase src, HandStateBase dst)
override bool LocalDestroyEntity(notnull EntityAI item)
override bool DropEntity(InventoryMode mode, EntityAI owner, notnull EntityAI item)
proto native bool CanRemoveEntityInHands()
bool ValidateUserReservationCancel(inout Serializer ctx, InventoryValidation validation)
bool ReplaceItemInHandsWithNewImpl(InventoryMode mode, HandEventBase e)
override bool TakeEntityToCargoEx(InventoryMode mode, notnull EntityAI item, int idx, int row, int col)
Put item into into cargo on specific cargo location.
proto native void GetUserReservedLocation(int index, out notnull InventoryLocation dst)
bool ReplaceItemInHandsWithNew(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
override bool TakeToDst(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
proto native bool ClearUserReservedLocationAtIndex(int index)
override bool ForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
bool SwappingToPreviousLocation(EntityAI item1, EntityAI item2, out InventoryLocation dst)
override bool SwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
bool ReplaceItemInElsewhereWithNewinHandsImpl(InventoryMode mode, HandEventBase e)
void OnEntityInHandsCreated(InventoryLocation src)
proto native bool GetDebugFlag()
bool ThrowEntity(EntityAI item, vector dir, float force)
void Update(float delta_time)
InventoryLocation.
static string DumpToStringNullSafe(InventoryLocation loc)
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:749
base class for transformation operations (creating one item from another)
proto static native bool CanStoreInputUserData()
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
proto native owned string GetName()