Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiontakematerialtohands.c
Go to the documentation of this file.
2 {
4  {
5  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
6  m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HANDS;
7  m_Text = "#take";
8  }
9 
10  override void CreateConditionComponents()
11  {
14  }
15 
16  override bool HasProneException()
17  {
18  return true;
19  }
20 
21  override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
22  {
23  ConstructionActionData construction_action_data = player.GetConstructionActionData();
24  EntityAI attachment = construction_action_data.GetActualAttachmentToDetach();
25 
26  if ( attachment )
27  {
28  m_Text = "#take " + attachment.GetDisplayName();
29  }
30  }
31 
32  override typename GetInputType()
33  {
35  }
36 
37  override bool HasProgress()
38  {
39  return false;
40  }
41 
42  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
43  {
44  EntityAI target_entity = EntityAI.Cast( target.GetObject() );
45  if ( target_entity && target_entity.CanUseConstruction() )
46  {
47  BaseBuildingBase base_building = BaseBuildingBase.Cast( target_entity );
48  if(!base_building.IsPlayerInside(player,""))
49  return false;
50 
51  ConstructionActionData construction_action_data = player.GetConstructionActionData();
52  string main_part_name = target_entity.GetActionComponentName( target.GetComponentIndex() );
53  //Print(main_part_name);
54 
55  if ( GetGame().IsMultiplayer() || GetGame().IsServer() )
56  {
57  construction_action_data.RefreshAttachmentsToDetach( target_entity, main_part_name );
58  }
59  EntityAI attachment = construction_action_data.GetActualAttachmentToDetach();
60 
61  if ( attachment && player.GetInventory().CanAddEntityIntoHands( attachment ) && attachment.GetHierarchyRootPlayer() != player )
62  {
63  return true;
64  }
65  }
66 
67  return false;
68  }
69 
70  override bool CanContinue( ActionData action_data )
71  {
72  return true;
73  }
74 
75  override void OnExecuteClient( ActionData action_data )
76  {
77  OnExecuteImpl(action_data);
78  }
79 
80  protected void OnExecuteImpl( ActionData action_data )
81  {
82  ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
83  ItemBase item_target = ItemBase.Cast( construction_action_data.GetActualAttachmentToDetach() );
84  if( item_target )
85  {
86  float stackable = item_target.GetTargetQuantityMax();
87 
88  if( stackable == 0 || stackable >= item_target.GetQuantity() )
89  {
90  //take to hands
91  action_data.m_Player.PredictiveTakeEntityToHands( item_target );
92  }
93  else if( stackable != 0 && stackable < item_target.GetQuantity() )
94  {
95  //split and take to hands
96  item_target.SplitIntoStackMaxHandsClient( action_data.m_Player );
97  }
98  }
99  }
100 
101  override void OnExecuteServer( ActionData action_data )
102  {
103  if (GetGame().IsMultiplayer())
104  return; // multiplayer handled on client side via OnExecuteClient
105  else
106  OnExecuteImpl(action_data); // single player
107  }
108 
109  override void CreateAndSetupActionCallback( ActionData action_data )
110  {
111  ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
112  EntityAI target = construction_action_data.GetActualAttachmentToDetach();
113 
114  bool heavy_item = false;
115  ActionBaseCB callback;
116  if ( target && target.ConfigIsExisting("heavyItem") && target.ConfigGetBool("heavyItem") )
117  {
118  heavy_item = true;
119  }
120 
121  if( heavy_item )
122  {
123  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HEAVY,GetCallbackClassTypename(),DayZPlayerConstants.STANCEMASK_ERECT));
124  }
125  else
126  {
127  if( action_data.m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT) )
128  {
129  Class.CastTo(callback, action_data.m_Player.AddCommandModifier_Action(DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS,GetCallbackClassTypename()));
130  }
131  else
132  {
133  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HANDS,GetCallbackClassTypename(),DayZPlayerConstants.STANCEMASK_PRONE));
134  }
135  }
136  callback.SetActionData(action_data);
137  callback.InitActionComponent();
138  action_data.m_Callback = callback;
139  }
140 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ConstructionActionData
Definition: constructionactiondata.c:1
CCINotPresent
Definition: ccinotpresent.c:1
ContinuousInteractActionInput
Definition: actioninput.c:521
ActionTakeMaterialToHands
Definition: actiontakematerialtohands.c:1
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
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
ActionBaseCB
Definition: animatedactionbase.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5