DayZ 1.24
Loading...
Searching...
No Matches
ActionPushCar.c
Go to the documentation of this file.
1class ActionPushCarDataReceiveData : ActionReciveData
2{
4}
5
7{
9 int m_EndType = 0;
10
13
14 vector m_Origin = "0 0 0";
15
18}
19
21{
26
28 {
29 if (!action_data.m_Player)
30 return UA_ERROR;
31
33 {
34 m_TimeElpased += action_data.m_Player.GetDeltaT();
35 m_TotalTimeElpased += action_data.m_Player.GetDeltaT();
36 return UA_PROCESSING;
37 }
38 else
39 {
44
45 return UA_CANCEL;
46 }
47
48 return UA_FINISHED;
49 }
50}
51
53{
54 private static float PUSH_FORCE_IMPULSE_INCREMENT = 200.0;
56
57 override void CreateActionComponent()
58 {
59 m_ActionData.m_ActionComponent = new CAContinuousRepeatPushCar(10.0);
60 }
61
63 {
64 super.ProgressActionComponent();
65
66 ActionPushCarData data = ActionPushCarData.Cast(m_ActionData);
68 }
69
70 override void EndActionComponent()
71 {
72 m_ActionDataPushCar = ActionPushCarData.Cast(m_ActionData);
73
75 {
76 super.EndActionComponent();
77 return;
78 }
79
80 if (m_ActionDataPushCar.m_State == UA_FINISHED)
81 {
82 if (m_ActionDataPushCar.m_EndType == 1)
83 SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
84 else if (m_ActionDataPushCar.m_EndType == 0)
85 SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
86 }
87 else if (m_ActionDataPushCar.m_State == UA_CANCEL)
88 {
90 if (action.HasAlternativeInterrupt())
91 SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
92 else
93 SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
94
95 return;
96 }
97
99 }
100
102 {
103 CarScript car = actionData.m_Car;
104
105 actionData.m_HorizontalDirectionRandom = Math.RandomFloat(1.0, 3.5);
106 actionData.m_VerticalDirectionRandom = Math.RandomFloat(-0.5, 0.5);
107
108 float bodyMass = dBodyGetMass(car);
109 float invBodyMass = 1.0 / bodyMass;
110 float force = dBodyGetMass(car) * PUSH_FORCE_IMPULSE_INCREMENT * car.GetPushForceCoefficientMultiplier();
111
112 float easedProgress = Easing.EaseInOutSine(actionData.m_ActionComponent.GetProgress());
113
114 vector impulse = car.GetDirection() * force * (float)actionData.m_PushDirection;
116 impulse[0] = impulse[0] * actionData.m_HorizontalDirectionRandom;
117 impulse[1] = impulse[1] * actionData.m_VerticalDirectionRandom;
119
120 actionData.m_Player.DepleteStamina(EStaminaModifiers.PUSH_CAR);
121
122 dBodyApplyImpulseAt(car, impulse, car.ModelToWorld(car.GetEnginePos()));
123 }
124}
125
127{
129 {
131 m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_VEHICLE_PUSH;
132 m_FullBody = true;
133 m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
134
135 m_Text = "#push_car";
136 }
137
138 override typename GetInputType()
139 {
141 }
142
148
150 {
151 return true;
152 }
153
155 {
157 return data;
158 }
159
160 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
161 {
162 if (!player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH))
163 return false;
164
165 if (!player.GetSurfaceType())
166 return false;
167
169 return false;
170
171 if (!player.CanConsumeStamina(EStaminaConsumers.PUSH))
172 return false;
173
175 if (car)
176 {
177 if (car.GetGear() != CarGear.NEUTRAL)
178 return false;
179
180 if (Math.AbsFloat(GetDirectionDot(car, player)) < 0.85)
181 return false;
182
183 return true;
184 }
185
186 return false;
187 }
188
190 {
191 super.OnUpdate(action_data);
192
194 if (data.m_NeedUpdate)
195 {
196 if (!data.m_Player.CanConsumeStamina(EStaminaConsumers.PUSH))
197 {
198 data.m_State = UA_CANCEL;
199 data.m_NeedUpdate = false;
200
201 return;
202 }
203
204 if (vector.Distance(data.m_Car.GetPosition(), data.m_Origin) > 0.5)
205 {
206 data.m_State = UA_FINISHED;
207 data.m_EndType = 0;
208 data.m_NeedUpdate = false;
209 }
210 }
211 }
212
214 {
215 super.OnStart(action_data);
216
218 data.m_Car = GetCar(action_data.m_Target);
219 data.m_Origin = data.m_Car.GetPosition();
220 data.m_NeedUpdate = true;
221 }
222
224 {
225 super.OnStartServer(action_data);
226
228
229 if (data.m_Car)
230 {
231 data.m_Car.SetBrake(0.0);
232 data.m_Car.SetHandbrake(0.0);
233 data.m_Car.SetBrakesActivateWithoutDriver(false);
234 }
235
236 data.m_PushDirection = -1;
237 if (GetDirectionDot(data.m_Car, data.m_Player) > 0)
238 data.m_PushDirection = 1;
239
240 }
241
243 {
244 super.OnEndServer(action_data);
245
247 if (data.m_Car)
248 data.m_Car.SetBrakesActivateWithoutDriver(true);
249 }
250
252 {
253 super.OnEndInput(action_data);
254
256 data.m_State = UA_CANCEL;
257 data.m_EndType = 1;
258 data.m_NeedUpdate = false;
259 }
260
262 {
263 super.WriteToContext(ctx, action_data);
264
266
267 ctx.Write(data.m_Car);
268 }
269
271 {
274
275 super.ReadFromContext(ctx, action_recive_data);
276
278 if (!ctx.Read(car))
279 return false;
280
282 receiveData.m_Car = car;
283
284 return true;
285 }
286
294
296 {
297 return vector.Dot(target.GetDirection(), player.GetDirection());
298 }
299
300 private CarScript GetCar(ActionTarget target)
301 {
302 if (target.IsProxy())
303 return CarScript.Cast(target.GetParent());
304
305 return CarScript.Cast(target.GetObject());
306 }
307}
bool m_FullBody
Definition ActionBase.c:52
string m_Text
Definition ActionBase.c:49
bool IsInReach(PlayerBase player, ActionTarget target, float maxDistance=1.0)
Definition ActionBase.c:856
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
int m_StanceMask
Definition ActionBase.c:53
ActionEmptyMagazine CreateActionComponent
override void EndActionComponent()
ActionPushCarData m_ActionDataPushCar
vector m_Origin
int m_EndType
ActionPushCarDataReceiveData m_PushDirection
float m_VerticalDirectionRandom
override void ProgressActionComponent()
float m_HorizontalDirectionRandom
void ApplyForce(ActionPushCarData actionData)
CAContinuousRepeatPushCar PUSH_FORCE_IMPULSE_INCREMENT
bool m_NeedUpdate
CarScript m_Car
EStaminaConsumers
EStaminaModifiers
override void OnEndServer(ActionData action_data)
override void CreateConditionComponents()
override void OnEndInput(ActionData action_data)
override void OnStartServer(ActionData action_data)
override ActionData CreateActionData()
override void OnUpdate(ActionData action_data)
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
CarScript GetCar(ActionTarget target)
override void OnStart(ActionData action_data)
override bool HasAlternativeInterrupt()
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
override GetInputType()
float GetDirectionDot(Object target, EntityAI player)
void SetACData(Param units)
Definition CABase.c:38
void OnCompletePogress(ActionData action_data)
ref Param1< float > m_SpentUnits
void CAContinuousRepeatPushCar(float time_to_complete_action)
override int Execute(ActionData action_data)
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition Easing.c:3
static float EaseInOutSine(float t)
Definition Easing.c:14
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
const float SMALL
const float DEFAULT
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition EnConvert.c:271
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static proto float AbsFloat(float f)
Returns absolute value.
proto void dBodyApplyImpulseAt(notnull IEntity body, vector impulse, vector pos)
Applies impuls on a pos position in world coordinates.
proto native float dBodyGetMass(notnull IEntity ent)
const int UA_FINISHED
Definition constants.c:436
const int UA_ERROR
Definition constants.c:455
const int UA_PROCESSING
Definition constants.c:434
const int UA_CANCEL
Definition constants.c:437