Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
13  override void CreateConditionComponents()
14  {
17  }
18 
19  override bool HasProneException()
20  {
21  return true;
22  }
23 
24  override bool ActionConditionContinue( ActionData action_data )
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  {
44  return true;
45  }
46  }
47  return false;
48  }
49 
50  override bool CanBeUsedOnBack()
51  {
52  return true;
53  }
54 
55  override bool InventoryReservation(ActionData action_data)
56  {
57  bool success = true;
58 
60 
61  EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
62  string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
63  ItemBase attachment;
64 
65  if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
66  {
67  action_data.m_Player.GetInventory().FindFreeLocationFor( attachment , FindInventoryLocationType.ANY, il );
68  if ( action_data.m_Player.GetInventory().HasInventoryReservation( attachment, il) )
69  {
70  success = false;
71  }
72  else
73  {
74  action_data.m_Player.GetInventory().AddInventoryReservationEx( attachment, il, GameInventory.c_InventoryReservationTimeoutMS);
75  }
76  }
77 
78  if ( success )
79  {
80  if( il )
81  action_data.m_ReservedInventoryLocations.Insert(il);
82  }
83 
84  return success;
85  }
86 
87  override void OnExecuteServer( ActionData action_data )
88  {
89  if (GetGame().IsMultiplayer())
90  return;
91 
92  //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
93  EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
94  string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
95  ItemBase attachment;
96 
97  if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
98  {
99  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
100  InventoryLocation targetInventoryLocation = new InventoryLocation;
101  attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
102  ClearInventoryReservationEx(action_data);
103  //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
104 
105  float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
106 
107  if( stackable == 0 || stackable >= attachment.GetQuantity() )
108  {
109  action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
110  }
111  else
112  {
113  attachment.SplitIntoStackMaxToInventoryLocationClient( il );
114  }
115  }
116  //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
117  }
118 
119  override void OnExecuteClient( ActionData action_data )
120  {
121  //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
122  EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
123  string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
124  ItemBase attachment;
125 
126  if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
127  {
128  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
129  InventoryLocation targetInventoryLocation = new InventoryLocation;
130  attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
131  ClearInventoryReservationEx(action_data);
132  //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
133  //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
134  float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
135 
136  if( stackable == 0 || stackable >= attachment.GetQuantity() )
137  {
138  action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
139  }
140  else
141  {
142  attachment.SplitIntoStackMaxToInventoryLocationClient( il );
143  }
144  }
145  }
146 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CCINone
Definition: ccinone.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
ActionInteractBase
Definition: actioninteractbase.c:54
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
BaseBuildingBase
Definition: fence.c:1
CCTCursor
Definition: cctcursor.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
ActionTakeHybridAttachment
Definition: actiontakehybridattachment.c:2
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78