Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionattachtoconstruction.c
Go to the documentation of this file.
2 {
4  {
5  m_Text = "#attach";
6  }
7 
8  override void CreateConditionComponents()
9  {
12  }
13 
14  override ActionData CreateActionData()
15  {
16  AttachActionData action_data = new AttachActionData;
17  return action_data;
18  }
19 
20  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
21  {
22  EntityAI target_entity = EntityAI.Cast( target.GetObject() );
23 
24  if ( target_entity && target_entity.CanUseConstruction() )
25  {
26  string selection = target_entity.GetActionComponentName( target.GetComponentIndex() );
27  ConstructionActionData construction_action_data = player.GetConstructionActionData();
28  int slot_id = construction_action_data.GetAttachmentSlotFromSelection( player, target_entity, item, selection );
29  BaseBuildingBase base_building;
30 
31  if ( slot_id != -1 )
32  {
33  base_building = BaseBuildingBase.Cast( target_entity );
34  if ( base_building.CheckSlotVerticalDistance( slot_id, player ) && base_building.IsPlayerInside(player,"") )
35  {
36  construction_action_data.SetSlotId( slot_id );
37 
38  return true;
39  }
40  }
41  else if ( item.IsKindOf("CombinationLock") )
42  {
43  base_building = BaseBuildingBase.Cast( target_entity );
44 
45  //simpler hack
46  /*construction_action_data.SetSlotId( InventorySlots.GetSlotIdFromString("Att_CombinationLock") );
47  return true;*/
48 
50  bool found = base_building.GetInventory().FindFreeLocationFor(item,FindInventoryLocationType.ATTACHMENT,loc);
51 
52  if (found)
53  {
54  //Print("slot name: " + InventorySlots.GetSlotName(loc.GetSlot()) );
55  construction_action_data.SetSlotId( loc.GetSlot() );
56 
57  return true;
58  }
59  }
60  }
61 
62  return false;
63  }
64 
65  override void OnStartClient( ActionData action_data )
66  {
67  //set action initiator
68  ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
69  construction_action_data.SetActionInitiator( action_data.m_Player );
70  }
71 
72  protected void OnExecuteImpl( ActionData action_data )
73  {
74  EntityAI target_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
75  ItemBase item = ItemBase.Cast( action_data.m_MainItem );
76 
77  ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
78  int slot_id = construction_action_data.GetSlotId();
79 
80  if ( slot_id != -1 )
81  {
82  ItemBase attachment = ItemBase.Cast( target_entity.GetInventory().FindAttachment( slot_id ) );
83 
84  if ( attachment )
85  {
86  //combine
87  attachment.CombineItemsClient( item );
88  }
89  else// if( target_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
90  {
91  ItemBase item_base = ItemBase.Cast( item );
92  float stackable = item_base.GetTargetQuantityMax( slot_id );
93 
94  if( stackable == 0 || stackable >= item_base.GetQuantity() )
95  {
96  action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(target_entity, item, slot_id);
97  }
98  else if( stackable != 0 && stackable < item_base.GetQuantity() )
99  {
100  item_base.SplitIntoStackMaxClient( target_entity, slot_id );
101  }
102  }
103  }
104  }
105 
106  override void OnExecuteClient( ActionData action_data )
107  {
108  ClearInventoryReservationEx(action_data);
109  OnExecuteImpl(action_data);
110  }
111 
112  override void OnExecuteServer( ActionData action_data )
113  {
114  if ( !GetGame().IsMultiplayer() )
115  {
116  ClearInventoryReservationEx(action_data);
117 
118  OnExecuteImpl(action_data); // single player
119  }
120  }
121 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ConstructionActionData
Definition: constructionactiondata.c:1
ActionAttachToConstruction
Definition: actionattachtoconstruction.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
AttachActionData
Definition: actionattach.c:1
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
BaseBuildingBase
Definition: fence.c:1
CCTCursor
Definition: cctcursor.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
m_Text
protected string m_Text
Definition: actionbase.c:49
ActionSingleUseBase
Definition: actionsingleusebase.c:41
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
EntityAI
Definition: building.c:5