DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionDismantlePart.c
Go to the documentation of this file.
2{
3 override void CreateActionComponent()
4 {
7 }
8
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 }*/
23 }
24};
25
27{
29 {
31 m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DISASSEMBLE;
32 m_FullBody = true;
33 m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
34
36 m_Text = "#dismantle";
37 }
38
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}
const int AT_DISMANTLE_PART
Definition _constants.c:7
protected float m_SpecialtyWeight
Definition ActionBase.c:68
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
protected string m_Text
Definition ActionBase.c:49
protected bool m_FullBody
Definition ActionBase.c:52
protected int m_StanceMask
Definition ActionBase.c:53
class ActionTargets ActionTarget
void Construction(BaseBuildingBase parent)
eBrokenLegs
Definition EBrokenLegs.c:2
PlayerBase GetPlayer()
protected ActionData m_ActionData
ItemBase m_MainItem
Definition ActionBase.c:28
PlayerBase m_Player
Definition ActionBase.c:33
ref CABase m_ActionComponent
Definition ActionBase.c:30
ref ActionTarget m_Target
Definition ActionBase.c:32
float SetCallbackDuration(ItemBase item)
override void CreateActionComponent()
override void OnFinishProgressServer(ActionData action_data)
override bool CanBeUsedLeaning()
override bool ActionConditionContinue(ActionData action_data)
override void OnActionInfoUpdate(PlayerBase player, ActionTarget target, ItemBase item)
protected void SetBuildingAnimation(ItemBase item)
override string GetAdminLogMessage(ActionData action_data)
override void CreateConditionComponents()
protected bool DismantleCondition(PlayerBase player, ActionTarget target, ItemBase item, bool camera_check)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=NULL)
override string GetText()
override bool IsFacingCamera(string selection)
Definition Fence.c:678
override bool IsPlayerInside(PlayerBase player, string selection)
Definition Fence.c:615
override bool IsOpened()
Definition Fence.c:110
Super root of all classes in Enforce script.
Definition EnScript.c:11
ConstructionPart GetTargetPart()
void SetTargetPart(ConstructionPart target_part)
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
const float DISMANTLE
const float BASEBUILDING_DECONSTRUCT_SLOW
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.