DayZ 1.24
Loading...
Searching...
No Matches
ActionTakeHybridAttachment.c
Go to the documentation of this file.
1
3{
4 string m_ItemName = "";
5
7 {
8 m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_INVENTORY;
9 m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_INVENTORY;
10 m_Text = "#take";
11 }
12
14 {
17 }
18
19 override bool HasProneException()
20 {
21 return true;
22 }
23
25 {
26 return true;
27 }
28
29 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
30 {
31 EntityAI tgt_entity = EntityAI.Cast(target.GetObject());
32
33 if (tgt_entity && BaseBuildingBase.Cast(tgt_entity) && !tgt_entity.IsBeingPlaced())
34 {
35 string component_name = tgt_entity.GetActionComponentName(target.GetComponentIndex());
36
37 /*if (!tgt_entity.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString(component_name)))
38 return false;*/
39
40 ItemBase attachment = ItemBase.Cast(tgt_entity.FindAttachmentBySlotName(component_name));
41
42 if (attachment && player.GetInventory().CanAddEntityIntoInventory(attachment) && attachment.IsTakeable())
43 return true;
44 }
45 return false;
46 }
47
48 override bool CanBeUsedOnBack()
49 {
50 return true;
51 }
52
54 {
55 bool success = true;
56
58
59 EntityAI tgt_entity = EntityAI.Cast(action_data.m_Target.GetObject());
60 string component_name = tgt_entity.GetActionComponentName(action_data.m_Target.GetComponentIndex());
62
63 if (tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)))
64 {
65 action_data.m_Player.GetInventory().FindFreeLocationFor(attachment, FindInventoryLocationType.ANY, il);
66 if (action_data.m_Player.GetInventory().HasInventoryReservation(attachment, il))
67 success = false;
68 else
69 action_data.m_Player.GetInventory().AddInventoryReservationEx(attachment, il, GameInventory.c_InventoryReservationTimeoutMS);
70 }
71
72 if (success)
73 {
74 if (il)
75 action_data.m_ReservedInventoryLocations.Insert(il);
76 }
77
78 return success;
79 }
80
82 {
83 if (GetGame().IsMultiplayer())
84 return;
85
86 //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
87 EntityAI tgt_entity = EntityAI.Cast(action_data.m_Target.GetObject());
88 string component_name = tgt_entity.GetActionComponentName(action_data.m_Target.GetComponentIndex());
90
91 if (tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)))
92 {
93 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
95 attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
97 //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
98
99 float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
100
101 if (stackable == 0 || stackable >= attachment.GetQuantity())
102 action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
103 else
104 attachment.SplitIntoStackMaxToInventoryLocationClient(il);
105 }
106 //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
107 }
108
110 {
111 //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
112 EntityAI tgt_entity = EntityAI.Cast(action_data.m_Target.GetObject());
113 string component_name = tgt_entity.GetActionComponentName(action_data.m_Target.GetComponentIndex());
115
116 if (tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)))
117 {
118 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
120 attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
122 //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
123 //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
124 float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
125
126 if (stackable == 0 || stackable >= attachment.GetQuantity())
127 action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
128 else
129 attachment.SplitIntoStackMaxToInventoryLocationClient(il);
130 }
131 }
132};
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:790
FindInventoryLocationType
flags for searching locations in inventory
override void OnExecuteClient(ActionData action_data)
override bool ActionConditionContinue(ActionData action_data)
override void OnExecuteServer(ActionData action_data)
override bool InventoryReservation(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
script counterpart to engine's class Inventory
Definition Inventory.c:79
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:687
InventoryLocation.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
proto native CGame GetGame()