Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionattachwithswich.c
Go to the documentation of this file.
2 {
4  {
5  }
6 
7  override void CreateConditionComponents()
8  {
11  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_ATTACHITEM;
12  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
13  }
14 
15  override typename GetInputType()
16  {
18  }
19 
20  override bool CanBePerformedFromInventory()
21  {
22  return true;
23  }
24 
25  override ActionData CreateActionData()
26  {
27  AttachActionData action_data = new AttachActionData;
28  return action_data;
29  }
30 
31  override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
32  {
34  if (!GetGame().IsDedicatedServer())
35  {
36  EntityAI target_entity;
37 
38  if ( target.IsProxy() )
39  {
40  target_entity = EntityAI.Cast( target.GetParent() );
41  }
42  else
43  {
44  target_entity = EntityAI.Cast( target.GetObject() );
45  }
46 
47  if (!target_entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il ))
48  return false;
49  }
50 
51  if ( super.SetupAction( player, target, item, action_data, extra_data))
52  {
53  if (!GetGame().IsDedicatedServer())
54  {
55  AttachActionData action_data_a = AttachActionData.Cast(action_data);
56  action_data_a.m_AttSlot = il.GetSlot();
57  }
58  return true;
59  }
60  return false;
61  }
62 
63 
64  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
65  {
66  EntityAI target_entity = EntityAI.Cast( target.GetObject() );
67  if( !item.CanSwitchDuringAttach(target_entity) )
68  return false;
69 
70  if ( target_entity && item )
71  {
72  if ( target_entity.GetInventory() && target_entity.GetInventory().CanAddAttachment( item ) )
73  {
74  return true;
75  }
76  }
77  return false;
78  }
79 
80  override void OnExecuteServer( ActionData action_data )
81  {
82  if (GetGame().IsMultiplayer())
83  return;
84 
85  ClearInventoryReservationEx(action_data);
86  AttachActionData action_data_a = AttachActionData.Cast(action_data);
87  EntityAI target_EAI;
88 
89  if ( action_data.m_Target.IsProxy() )
90  {
91  target_EAI = EntityAI.Cast( action_data_a.m_Target.GetParent() );
92  }
93  else
94  {
95  target_EAI = EntityAI.Cast( action_data_a.m_Target.GetObject() );
96  }
97 
98  if (target_EAI && action_data_a.m_MainItem)
99  {
101  il.SetAttachment( target_EAI, action_data.m_MainItem, action_data_a.m_AttSlot );
102  action_data.m_Player.PredictiveForceSwapEntities( target_EAI, action_data.m_MainItem, il );
103  }
104  }
105 
106  override void OnExecuteClient( ActionData action_data )
107  {
108  ClearInventoryReservationEx(action_data);
109  AttachActionData action_data_a = AttachActionData.Cast(action_data);
110 
111  EntityAI target_EAI;
112 
113  if ( action_data.m_Target.IsProxy() )
114  {
115  target_EAI = EntityAI.Cast( action_data_a.m_Target.GetParent() );
116  }
117  else
118  {
119  target_EAI = EntityAI.Cast( action_data_a.m_Target.GetObject() );
120  }
121 
122  if (target_EAI && action_data_a.m_MainItem)
123  {
125  il.SetAttachment( target_EAI, action_data.m_MainItem, action_data_a.m_AttSlot );
126  action_data.m_Player.PredictiveForceSwapEntities( target_EAI, action_data.m_MainItem, il );
127  }
128  }
129 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
ActionAttachWithSwitch
Definition: actionattachwithswich.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
AttachActionData
Definition: actionattach.c:1
UAMaxDistances
Definition: actionconstants.c:104
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
CCTNonRuined
Definition: cctnonruined.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
ActionAttach
ActionAttachWheels ActionAttach
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
InventoryOnlyActionInput
Definition: actioninput.c:934
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5