Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiondismantlepart.c
Go to the documentation of this file.
2 {
3  override void CreateActionComponent()
4  {
5  float time = SetCallbackDuration(m_ActionData.m_MainItem);
6  m_ActionData.m_ActionComponent = new CAContinuousTime( time );
7  }
8 
9  float SetCallbackDuration( ItemBase item )
10  {
11  /*switch( item.Type() )
12  {
13  case Pickaxe:
14  case Shovel:
15  case FieldShovel:
16  return UATimeSpent.BASEBUILDING_DECONSTRUCT_MEDIUM;
17  case FirefighterAxe:
18  return UATimeSpent.BASEBUILDING_DECONSTRUCT_FAST;
19  default:
20  return UATimeSpent.BASEBUILDING_DECONSTRUCT_SLOW;
21  }*/
22  return UATimeSpent.BASEBUILDING_DECONSTRUCT_SLOW;
23  }
24 };
25 
27 {
28  void ActionDismantlePart()
29  {
30  m_CallbackClass = ActionDismantlePartCB;
31  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DISASSEMBLE;
32  m_FullBody = true;
33  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
34 
36  m_Text = "#dismantle";
37  }
38 
39  override void CreateConditionComponents()
40  {
42  m_ConditionTarget = new CCTNone;//CCTNonRuined( UAMaxDistances.BASEBUILDING );
43  }
44 
45  override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
46  {
47  ConstructionActionData construction_action_data = player.GetConstructionActionData();
48  m_Text = "#dismantle " + construction_action_data.GetTargetPart().GetName();
49  }
50 
51  override string GetText()
52  {
53  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
54  if ( player )
55  {
56  ConstructionActionData construction_action_data = player.GetConstructionActionData();
57  ConstructionPart constrution_part = construction_action_data.GetTargetPart();
58 
59  if ( constrution_part )
60  {
61  return "#dismantle" + " " + constrution_part.GetName();
62  }
63  }
64 
65  return "";
66  }
67 
68  override bool CanBeUsedLeaning()
69  {
70  return false;
71  }
72 
73  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
74  {
75  if ( player.IsPlacingLocal() )
76  return false;
77 
78  //Action not allowed if player has broken legs
79  if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
80  return false;
81 
82  return DismantleCondition( player, target, item, true ) && player.m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE;
83  }
84 
85  override bool ActionConditionContinue( ActionData action_data )
86  {
87  return DismantleCondition( action_data.m_Player, action_data.m_Target, action_data.m_MainItem , false ) && action_data.m_Player.m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE;
88  }
89 
90  override void OnFinishProgressServer( ActionData action_data )
91  {
92  BaseBuildingBase base_building = BaseBuildingBase.Cast( action_data.m_Target.GetObject() );
93  Construction construction = base_building.GetConstruction();
94  ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
95  ConstructionPart construction_part = construction_action_data.GetTargetPart();
96 
97  if ( construction.CanDismantlePart( construction_part.GetPartName(), action_data.m_MainItem ) )
98  {
99  //build
100  construction.DismantlePartServer( action_data.m_Player, construction_part.GetPartName(), AT_DISMANTLE_PART );
101 
102  //add damage to tool
103  action_data.m_MainItem.DecreaseHealth( UADamageApplied.DISMANTLE, false );
104  }
105 
106  action_data.m_Player.GetSoftSkillsManager().AddSpecialty( m_SpecialtyWeight );
107  }
108 
109  //setup
110  override bool SetupAction( PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL )
111  {
112  if ( super.SetupAction( player, target, item, action_data, extra_data ) )
113  {
114  SetBuildingAnimation( item );
115 
116  return true;
117  }
118 
119  return false;
120  }
121 
122  protected void SetBuildingAnimation( ItemBase item )
123  {
124  switch ( item.Type() )
125  {
126  case Pickaxe:
127  case Shovel:
128  case FarmingHoe:
129  case FieldShovel:
130  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIG;
131  break;
132  case Pliers:
133  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
134  break;
135  default:
136  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DISASSEMBLE;
137  break;
138  }
139  }
140 
141  protected bool DismantleCondition( PlayerBase player, ActionTarget target, ItemBase item, bool camera_check )
142  {
143  if ( player && !player.IsPlacingLocal() && !player.IsPlacingServer() )
144  {
145  Object target_object = target.GetObject();
146  EntityAI target_entity;
147  if ( target_object && target_object.CanUseConstruction() )
148  {
149  //invalid if is gate and is locked
150  if ( Class.CastTo(target_entity,target_object) && (target_entity.FindAttachmentBySlotName("Att_CombinationLock") || target_entity.FindAttachmentBySlotName("Material_FPole_Flag")) )
151  {
152  return false;
153  }
154 
155  string part_name = target_object.GetActionComponentName( target.GetComponentIndex() );
156 
157  BaseBuildingBase base_building = BaseBuildingBase.Cast( target_object );
158  Construction construction = base_building.GetConstruction();
159  ConstructionPart construction_part = construction.GetConstructionPartToDismantle( part_name, item );
160 
161  if ( construction_part )
162  {
163  /*Print("DismantleCondition");
164  Print(part_name);
165  Print("construction_part.GetPartName: " + construction_part.GetPartName());
166  Print("construction_part.GetMainPartName: " + construction_part.GetMainPartName());
167  Print("-----");*/
168 
169  //invalid on gate if the gate is opened
170  if ( construction_part.IsGate() && base_building.IsOpened() )
171  return false;
172 
173  //camera and position checks
174  bool checked = false;
175 
176  if ( construction_part.IsBase() )
177  checked = true;
178 
179  if ( !checked && base_building.IsPlayerInside( player, part_name ) && !player.GetInputController().CameraIsFreeLook() )
180  {
181  //Camera check (client-only)
182  if ( camera_check )
183  {
184  if ( GetGame() && ( !GetGame().IsDedicatedServer() ) )
185  {
186  if ( base_building.IsFacingCamera( part_name ) )
187  {
188  return false;
189  }
190  }
191  }
192 
193  checked = true;
194  }
195 
196  if ( checked )
197  {
198  ConstructionActionData construction_action_data = player.GetConstructionActionData();
199  construction_action_data.SetTargetPart( construction_part );
200 
201  return true;
202  }
203  }
204  }
205  }
206 
207  return false;
208  }
209 
210  override string GetAdminLogMessage(ActionData action_data)
211  {
212  ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
213  ConstructionPart construction_part = construction_action_data.GetTargetPart();
214 
215  string message = string.Format("Dismantled %1 from %2 with %3", construction_part.GetName(), action_data.m_Target.GetObject().GetDisplayName(), action_data.m_MainItem.GetDisplayName() );
216  return message;
217  }
218 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ConstructionActionData
Definition: constructionactiondata.c:1
ActionDismantlePart
Definition: actiondismantlepart.c:26
UADamageApplied
Definition: actionconstants.c:130
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
CAContinuousTime
Definition: cacontinuoustime.c:1
FarmingHoe
Definition: farminghoe.c:1
Construction
void Construction(BaseBuildingBase parent)
Definition: construction.c:26
UASoftSkillsWeight
Definition: actionconstants.c:118
CCTNone
Definition: cctnone.c:1
AT_DISMANTLE_PART
const int AT_DISMANTLE_PART
Definition: _constants.c:7
eBrokenLegs
eBrokenLegs
Definition: ebrokenlegs.c:1
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
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
Object
Definition: objecttyped.c:1
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
m_Text
protected string m_Text
Definition: actionbase.c:49
ConstructionPart
Definition: constructionpart.c:1
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5
ActionDismantlePartCB
Definition: actiondismantlepart.c:1