Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiondetachfromtarget.c
Go to the documentation of this file.
2 {
3 
4  override void CreateConditionComponents()
5  {
8  }
9 
11  {
12  m_Text = "#take_to_hands";
13  }
14 
15  override typename GetInputType()
16  {
18  }
19 
20  override ActionData CreateActionData()
21  {
22  DetachActionData action_data = new DetachActionData;
23  return action_data;
24  }
25 
26  int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
27  {
28  EntityAI target_entity = EntityAI.Cast(target.GetObject());
29 
30  if ( player && target_entity )
31  {
32  array<string> selections = new array<string>();
33  target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
34 
35  if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
36  {
37  for(int i = 0; i < selections.Count(); i++ )
38  {
39  int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
40  EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
41 
42  if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
43  {
44  if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
45  return target_slot_id;
46  }
47  }
48  }
49  }
50  return InventorySlots.INVALID;
51  }
52 
53  override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
54  {
55  int attSlotId = InventorySlots.INVALID;
56  if (!GetGame().IsDedicatedServer() )
57  {
58  attSlotId = FindSlotIdToDetach(player, target, item);
59  }
60 
61  if ( super.SetupAction( player, target, item, action_data, extra_data))
62  {
63  if (!GetGame().IsDedicatedServer())
64  {
65  if(attSlotId != InventorySlots.INVALID)
66  {
67  DetachActionData action_data_a = DetachActionData.Cast(action_data);
68  action_data_a.m_AttSlot = attSlotId;
69  return true;
70  }
71  return false;
72  }
73  return true;
74  }
75  return false;
76  }
77 
78  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
79  {
80  if ( GetGame().IsMultiplayer() && GetGame().IsServer() ) return true;
81 
82  return FindSlotIdToDetach(player, target, item) != InventorySlots.INVALID);
83  }
84 
85  override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
86  {
87  int target_slot_id = FindSlotIdToDetach(player, target, null);
88  EntityAI target_entity = EntityAI.Cast( target.GetObject() );
89 
90  if(target_slot_id != InventorySlots.INVALID)
91  {
92  return target_entity.GetInventory().FindAttachment(target_slot_id);
93  }
94  return null;
95  }
96 
97  override void OnExecuteClient( ActionData action_data )
98  {
99  Process(action_data);
100  }
101 
102  override void OnExecuteServer( ActionData action_data )
103  {
104  if(!GetGame().IsMultiplayer())
105  Process(action_data);
106  }
107 
108  void Process( ActionData action_data )
109  {
110  ClearInventoryReservationEx(action_data);
111 
112  DetachActionData action_data_a = DetachActionData.Cast(action_data);
113  EntityAI target_entity = EntityAI.Cast( action_data_a.m_Target.GetObject() );
114 
115  ItemBase attachment = ItemBase.Cast(target_entity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
116 
117  if(attachment)
118  {
119  float stackable = attachment.GetTargetQuantityMax();
120  if( stackable == 0 || stackable >= attachment.GetQuantity() )
121  {
122  //take to hands
123  action_data.m_Player.PredictiveTakeEntityToHands( attachment );
124  }
125  else if( stackable != 0 && stackable < attachment.GetQuantity() )
126  {
127  //split and take to hands
128  attachment.SplitIntoStackMaxHandsClient( action_data.m_Player );
129  }
130  }
131  }
132 }
133 
134 class ActionDetachFromTarget_SpecificSlot: ActionDetachFromTarget
135 {
136  string m_slotToDetach;
137 
138  override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
139  {
140  EntityAI target_entity = EntityAI.Cast(target.GetObject());
141 
142  if ( player && target_entity )
143  {
144  array<string> selections = new array<string>();
145  target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
146 
147  if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
148  {
149  for(int i = 0; i < selections.Count(); i++ )
150  {
151  if( selections[i] == m_slotToDetach )
152  {
153  int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
154  EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
155 
156  if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
157  {
158  if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
159  return target_slot_id;
160  }
161  }
162  }
163  }
164  }
165  return InventorySlots.INVALID;
166  }
167 }
168 
170 {
171  string m_slotsToDetach;
172 
173  override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
174  {
175  EntityAI target_entity = EntityAI.Cast(target.GetObject());
176 
177  if ( player && target_entity )
178  {
179  array<string> selections = new array<string>();
180  target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
181 
182  if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
183  {
184  for(int i = 0; i < selections.Count(); i++ )
185  {
186  if (selections[i].Contains(m_slotsToDetach))
187  {
188  int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
189  EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
190 
191  if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
192  {
193  if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
194  return target_slot_id;
195  }
196  }
197  }
198  }
199  }
200  return InventorySlots.INVALID;
201  }
202 }
203 
204 
205 class ActionDetachFromTarget_SpecificSlot_WoodenLogs: ActionDetachFromTarget_SpecificSlot
206 {
208  {
209  m_slotToDetach = "truck_01_woodenlogs";
210  }
211 }
212 
213 class ActionDetachFromTarget_SpecificSlot_WoodenPlanks: ActionDetachFromTarget_SpecificSlot
214 {
216  {
217  m_slotToDetach = "truck_01_woodenplanks";
218  }
219 }
220 
221 class ActionDetachFromTarget_SpecificSlot_MetalSheets: ActionDetachFromTarget_SpecificSlot
222 {
224  {
225  m_slotToDetach = "truck_01_metalsheets";
226  }
227 }
228 
230 {
232  {
233  m_slotsToDetach = "truck_01_barrel";
234  }
235 }
236 
238 {
240  {
241  m_slotsToDetach = "truck_01_woodencrate";
242  }
243 }
ItemBase
Definition: inventoryitem.c:730
DetachActionData
Definition: actiondetach.c:1
GetGame
proto native CGame GetGame()
ActionDetachFromTarget_SpecificSlot_MetalSheets
ActionDetachFromTarget_SpecificSlot_WoodenPlanks ActionDetachFromTarget_SpecificSlot ActionDetachFromTarget_SpecificSlot_MetalSheets()
Definition: actiondetachfromtarget.c:223
FindSlotIdToDetach
override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
Definition: actiondetachfromtarget.c:138
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
m_slotToDetach
ActionDetachFromTarget m_slotToDetach
ContinuousInteractActionInput
Definition: actioninput.c:521
CCINone
Definition: ccinone.c:1
ActionDetachFromTarget
Definition: actiondetachfromtarget.c:1
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
ActionInteractBase
Definition: actioninteractbase.c:54
ActionDetachFromTarget_SpecificSlot_WoodenPlanks
Definition: actiondetachfromtarget.c:213
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
ActionDetachFromTarget_SpecificSlotsCategory
Definition: actiondetachfromtarget.c:169
Object
Definition: objecttyped.c:1
CCTCursor
Definition: cctcursor.c:1
m_slotsToDetach
string m_slotsToDetach
Definition: actiondetachfromtarget.c:139
array< string >
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionDetachFromTarget_SpecificSlotsCategory_Barrel
Definition: actiondetachfromtarget.c:229
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
EntityAI
Definition: building.c:5
ActionDetachFromTarget_SpecificSlot_WoodenLogs
ActionDetachFromTarget_SpecificSlotsCategory ActionDetachFromTarget ActionDetachFromTarget_SpecificSlot_WoodenLogs()
Definition: actiondetachfromtarget.c:207
ActionDetachFromTarget_SpecificSlotsCategory_WoodenCrate
ActionDetachFromTarget_SpecificSlotsCategory_Barrel ActionDetachFromTarget_SpecificSlotsCategory ActionDetachFromTarget_SpecificSlotsCategory_WoodenCrate()
Definition: actiondetachfromtarget.c:239