Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
animatedactionbase.c
Go to the documentation of this file.
2 {
3  protected ActionData m_ActionData;
4  protected SoundOnVehicle m_SoundObject;//object of sound playing on entity
5  protected bool m_Canceled;//helps prevent doubled calling of actionbase End method
6  protected bool m_Interrupted;//force callback to wait till action syncs its interruption
7 
8 
9  void ActionBaseCB()
10  {
11  }
12 
13  int GetPossileStanceMask()
14  {
15  return m_ActionData.m_PossibleStanceMask;
16  }
17 
18  //Command events
19  override void OnFinish(bool pCanceled)
20  {
21  if ( LogManager.IsActionLogEnable() )
22  {
23  if ( m_ActionData)
24  Debug.ActionLog("Time stamp: " + m_ActionData.m_Player.GetSimulationTimeStamp(), m_ActionData.m_Action.ToString() , "n/a", "OnFinish", m_ActionData.m_Player.ToString() );
25  else
26  Debug.ActionLog("n/a", this.ToString() , "n/a", "OnFinish", "n/a" );
27  }
28  if ( m_SoundObject )
29  {
30  GetGame().ObjectDelete(m_SoundObject);
31  }
32  if ( m_ActionData && m_ActionData.m_Player )
33  {
34  if ( pCanceled )
35  {
36  m_ActionData.m_State = m_ActionData.m_ActionComponent.Interrupt(m_ActionData);
37  }
38 
39  AnimatedActionBase action = AnimatedActionBase.Cast(m_ActionData.m_Action);
40 
41  if(action)
42  action.End(m_ActionData);
43  }
44  }
45 
46  void SetCommand( int command_uid )
47  {
48  InternalCommand(command_uid);
49  }
50 
51  //---------------------------------------------------------------
52  //Action Component handlers
53  void CreateActionComponent()
54  {
55  m_ActionData.m_ActionComponent = new CADummy;
56  }
57 
58  void InitActionComponent()
59  {
60  }
61 
62  void ProgressActionComponent()
63  {
64  if ( m_ActionData.m_ActionComponent )
65  {
66  m_ActionData.m_State = m_ActionData.m_ActionComponent.Execute(m_ActionData);
67  }
68  }
69 
70  void EndActionComponent()
71  {
72  }
73 
75  void Interrupt()
76  {
77  if ( GetGame().IsServer() )
78  {
79  if ( LogManager.IsActionLogEnable() )
80  {
81  Debug.ActionLog("n/a", this.ToString() , "n/a", "Interrupt", m_ActionData.m_Player.ToString() );
82  }
83  if ( GetGame().IsMultiplayer() )
84  {
85  DayZPlayerSyncJunctures.SendActionInterrupt(m_ActionData.m_Player);
86  }
87  }
88  else
89  {
90  if (ScriptInputUserData.CanStoreInputUserData())
91  {
94  ctx.Write(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
95  ctx.Send();
96  }
97  }
98  m_Interrupted = true;
99  }
100 
101  void SetActionData(ActionData action_data )
102  {
103  m_ActionData = action_data;
104  }
105 
106  override bool IsUserActionCallback()
107  {
108  return true;
109  }
110 
111  float GetActionComponentProgress()
112  {
113  if ( m_ActionData.m_ActionComponent )
114  {
115  return m_ActionData.m_ActionComponent.GetProgress();
116  }
117  return 0;
118  }
119 
120  int GetActionState()
121  {
122  return m_ActionData.m_State;
123  }
124 
125  ActionTarget GetTarget()
126  {
127  return m_ActionData.m_Target;
128  }
129 };
130 
131 
132 
134 {
135  protected int m_CommandUID; //tells which command should be used for callback
136  protected int m_CommandUIDProne;
137  protected typename m_CallbackClass; //tells which callback should be instantiated
138 
139 
140  //-----------------------------------------------------
141  // Action events and methods
142  //-----------------------------------------------------
143  void AnimatedActionBase()
144  {
145  // definable
146  m_CallbackClass = ActionBaseCB;
147  }
148 
149  protected void OnAlternativeEndServer( PlayerBase player ) //method called when action has not met conditions in action component
150  {
151  }
152  protected void OnAlternativeEndClient( PlayerBase player ) //method called when action has not met conditions in action component
153  {
154  }
155 
156  protected void OnInterruptServer( PlayerBase player ) //method called when action has not met conditions in action component
157  {
158  }
159  protected void OnInterruptClient( PlayerBase player ) //method called when action has not met conditions in action component
160  {
161  }
162 
163  protected void OnExecute( ActionData action_data )
164  {
165  }
166 
167  protected void OnExecuteServer( ActionData action_data )
168  {
169  }
170 
171  protected void OnExecuteClient( ActionData action_data )
172  {
173  }
174 
175  //TODO MW - add comment
176  void OnAnimationEvent( ActionData action_data )
177  {
178  if (action_data && !action_data.m_WasExecuted)
179  {
180  ActionBase action = action_data.m_Action;
181 
182  if (action && ( !action.UseMainItem() || action_data.m_MainItem ) && ( !action.HasTarget() || action_data.m_Target ))
183  {
184  if ( LogManager.IsActionLogEnable() )
185  {
186  Debug.ActionLog("Time stamp: " + action_data.m_Player.GetSimulationTimeStamp(), this.ToString() , "n/a", "OnExecute", action_data.m_Player.ToString() );
187  }
188  OnExecute(action_data);
189 
190  if (GetGame().IsServer())
191  OnExecuteServer(action_data);
192  else
193  OnExecuteClient(action_data);
194 
195  action_data.m_WasExecuted = true;
196  action_data.m_WasActionStarted = true;
197  }
198  }
199  }
200 
201  override bool ActionConditionContinue( ActionData action_data ) //condition for action
202  {
203  return ActionCondition(action_data.m_Player,action_data.m_Target,action_data.m_MainItem);
204  }
205 
206  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
207  {
208  return true;
209  }
210 
211  //TODO MW - add comment
212  protected int GetActionCommand( PlayerBase player )
213  {
214  if ( HasProneException() )
215  {
216  if ( player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT))
217  return m_CommandUID;
218  else
219  return m_CommandUIDProne;
220  }
221  return m_CommandUID;
222  }
223 
224  protected typename GetCallbackClassTypename()
225  {
226  return m_CallbackClass;
227  }
228 
229  // if it is set to true if action have special fullbody animation for prone and additive for crouch and erect
230  override bool HasProneException()
231  {
232  return false;
233  }
234 
235  //TODO MW - add comment
236  protected void CreateAndSetupActionCallback( ActionData action_data )
237  {
238  //Print("ActionBase.c | CreateAndSetupActionCallback | DBG ACTION CALLBACK CREATION CALLED");
239  ActionBaseCB callback;
240  if ( IsFullBody(action_data.m_Player) )
241  {
242  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(GetActionCommand(action_data.m_Player),GetCallbackClassTypename(),GetStanceMask(action_data.m_Player)));
243  //Print("ActionBase.c | CreateAndSetupActionCallback | DBG command starter");
244  }
245  else
246  {
247  Class.CastTo(callback, action_data.m_Player.AddCommandModifier_Action(GetActionCommand(action_data.m_Player),GetCallbackClassTypename()));
248  //Print("ActionBase.c | CreateAndSetupActionCallback | DBG command modif starter: "+callback.ToString()+" id:"+GetActionCommand().ToString());
249 
250  }
251  callback.SetActionData(action_data);
252  callback.InitActionComponent(); //jtomasik - tohle mozna patri do constructoru callbacku?
253  action_data.m_Callback = callback;
254  }
255 
256 
257 
258  // ACTION LOGIC -------------------------------------------------------------------
259  // called from actionmanager.c
260  override void Start( ActionData action_data ) //Setup on start of action
261  {
262  super.Start( action_data );
263  //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
264 
265  if( !IsInstant() )
266  {
267  CreateAndSetupActionCallback(action_data);
268  }
269  /*Debug
270  SendMessageToClient( player, "ActionBase.c : Start");
271  Print("ActionBase.c : Start");
272  */
273  }
274 
275  // THIS Interrupt is use for ACTUAL handling of intrrupt on action side - WARNING Interrupt without parametr is used for initialize interrupt
276  override void Interrupt( ActionData action_data )
277  {
278  if ( action_data.m_Callback )
279  {
280  action_data.m_Callback.Cancel();
281  }
282  else
283  {
284  End( action_data );
285  }
286  }
287 
288  void OnJumpStart()
289  {
290 
291  }
292 
293  // called from ActionBaseCB.c
294  void Do( ActionData action_data, int state )
295  {
296  if ( state == UA_ERROR || !action_data.m_Callback || !action_data.m_Player || !action_data.m_ActionComponent ) //jtomasik - tohle mozna muze byt v CancelCondtion metodu callbacku?
297  {
298 #ifdef DIAG_DEVELOPER
299  if ( LogManager.IsActionLogEnable() )
300  {
301  Debug.ActionLog("ABRUPT CANCEL, CONDITIONS NOT MET", this.ToString() , "n/a", "Do", action_data.m_Player.ToString() );
302  }
303 #endif
304  if ( action_data.m_Callback && action_data.m_Player )
305  {
306  action_data.m_Callback.Interrupt();
307  }
308  else
309  {
310  Debug.ActionLog("PLAYER LOST", this.ToString() , "n/a", "Do", action_data.m_Player.ToString() );
311  }
312  }
313  else
314  {
315  switch ( state )
316  {
317  case UA_PROCESSING:
318  if ( CanContinue(action_data) )
319  {
320  action_data.m_Callback.ProgressActionComponent();
321  InformPlayers(action_data.m_Player, action_data.m_Target, UA_PROCESSING);
322  }
323  else
324  {
325  action_data.m_Callback.Interrupt();
326  InformPlayers(action_data.m_Player, action_data.m_Target, UA_CANCEL);
327  Do(action_data, UA_CANCEL);
328  }
329  break;
330 
331  case UA_FINISHED:
332  InformPlayers(action_data.m_Player,action_data.m_Target,UA_FINISHED);
333  action_data.m_Callback.EndActionComponent();
334  break;
335 
336  case UA_CANCEL:
337  InformPlayers(action_data.m_Player,action_data.m_Target,UA_CANCEL);
338  action_data.m_Callback.EndActionComponent();
339  break;
340 
341  case UA_INITIALIZE:
342  if ( !CanContinue(action_data) )
343  {
344  action_data.m_Callback.Interrupt();
345  InformPlayers(action_data.m_Player, action_data.m_Target, UA_CANCEL);
346  Do(action_data, UA_CANCEL);
347  }
348  default:
349  Debug.ActionLog("Action component returned wrong value", this.ToString() , "n/a", "Do", action_data.m_Player.ToString() );
350  action_data.m_Callback.Interrupt();
351  break;
352  }
353  }
354  }
355 
356  // called from ActionBaseCB.c
357  override void End( ActionData action_data )
358  {
359  if ( action_data.m_Player )
360  {
361  if ( GetGame().IsServer() )
362  {
363  OnEndServer(action_data);
364  action_data.m_Player.SetSoundCategoryHash(0);
365  }
366  else
367  {
368  OnEndClient(action_data);
369  }
370  OnEnd(action_data);
371 
372  // Xbox Achievemnts
373  if ( action_data.m_WasActionStarted )
374  {
375  if ( IsEat() )
376  {
377  GetGame().GetAnalyticsClient().OnActionEat();
378  }
379  else if ( IsDrink() )
380  {
381  GetGame().GetAnalyticsClient().OnActionDrink();
382  }
383 
384  action_data.m_WasActionStarted = false;
385  }
386 
387  action_data.m_Player.GetActionManager().OnActionEnd();
388 
389 
390  }
391  else
392  {
393  if ( LogManager.IsActionLogEnable() )
394  {
395  Debug.ActionLog("Ation could not be finished right at the end", this.ToString() , "n/a", "End", action_data.m_Player.ToString() );
396  }
397  action_data.m_Callback.Interrupt();
398  }
399  }
400 
401  override float GetProgress( ActionData action_data )
402  {
403  if ( action_data.m_ActionComponent )
404  {
405  return action_data.m_ActionComponent.GetProgress();
406  }
407  return 0;
408  }
409 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
INPUT_UDT_STANDARD_ACTION_END_REQUEST
const int INPUT_UDT_STANDARD_ACTION_END_REQUEST
Definition: _constants.c:3
LogManager
Definition: debug.c:734
IsFullBody
bool IsFullBody(PlayerBase player)
Definition: actionbase.c:553
OnEndClient
void OnEndClient(ActionData action_data)
Definition: actionbase.c:1036
ScriptInputUserData
Definition: gameplay.c:120
OnEnd
override void OnEnd()
Definition: jumpevents.c:23
CADummy
Definition: cadummy.c:1
IsEat
bool IsEat()
Definition: actionbase.c:271
ToString
proto string ToString()
InformPlayers
protected void InformPlayers(PlayerBase player, ActionTarget target, int state)
DEPRECATED delivers message ids to clients based on given context.
UA_CANCEL
const int UA_CANCEL
Definition: constants.c:437
AnimatedActionBase
Definition: animatedactionbase.c:133
IsDrink
bool IsDrink()
Definition: actionbase.c:276
GetStanceMask
protected int GetStanceMask(PlayerBase player)
Definition: actionbase.c:539
PlayerBase
Definition: playerbaseclient.c:1
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
OnEndServer
void OnEndServer(ActionData action_data)
Definition: actionbase.c:1039
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
UA_INITIALIZE
const int UA_INITIALIZE
Definition: constants.c:444
HumanCommandActionCallback
Definition: statecb.c:1
m_Interrupted
bool m_Interrupted
Definition: actionmanagerbase.c:49
DayZPlayerSyncJunctures
Definition: dayzplayersyncjunctures.c:4
CanContinue
protected bool CanContinue(ActionData action_data)
Definition: actionbase.c:748
ActionBase
void ActionBase()
Definition: actionbase.c:73
Debug
Definition: debug.c:13
IsInstant
bool IsInstant()
Definition: actionbase.c:250
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
ActionBaseCB
Definition: animatedactionbase.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
InternalCommand
proto native void InternalCommand(int pInternalCommandId)