Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionmanagerserver.c
Go to the documentation of this file.
2 {
3  protected ActionBase m_PendingAction;
4  ref ActionReciveData m_PendingActionReciveData;
5 
7  {
8  m_PendingAction = null;
9  m_PendingActionReciveData = null;
10  }
11 
12  //------------------------------------------
13  //EVENTS
14  //------------------------------------------
15  override void OnJumpStart()
16  {
18  {
20  {
21  OnActionEnd();
23  }
24  else
25  {
26  m_CurrentActionData.m_Action.Interrupt(m_CurrentActionData);
27  }
28  }
29  }
30 
31  override bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
32  {
33  switch (userDataType)
34  {
36  {
37  bool success = true;
38 
39  int actionID = 0;
40  if (!ctx.Read(actionID))
41  return false;
42 
43  ActionBase recvAction = GetAction(actionID);
44  if (!recvAction)
45  return false;
46 
47  if (!recvAction.ReadFromContext(ctx, m_PendingActionReciveData))
48  success = false;
49 
50  m_PendingAction = recvAction;
51 
52  if (recvAction.UseAcknowledgment())
53  {
54  int ackID;
55  if (!ctx.Read(ackID))
56  success = false;
57 
59  }
60 
61  break;
62 
63  }
64 
66  {
67  //Debug.Log("Action want end request, STS = " + m_Player.GetSimulationTimeStamp());
68  int commandID = -10;
69  ctx.Read(commandID);
70 
71  if (commandID == DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT)
72  {
73  //Print("INPUT_UDT_STANDARD_ACTION_END_REQUEST | CMD_ACTIONINT_INTERRUPT");
74  Interrupt();
75  }
76  else
77  {
78  //Print("INPUT_UDT_STANDARD_ACTION_END_REQUEST | m_ActionWantEndRequest");
80  }
81  }
82 
84  {
85  //Debug.Log("Action input ended, STS = " + m_Player.GetSimulationTimeStamp());
86  m_ActionInputWantEnd = true;
87  }
88  default:
89  return false;
90  }
91 
92  if (!success)
93  {
94  //Debug.Log("[AM] OnInputUserDataProcess INPUT_UDT_STANDARD_ACTION_START Error");
95  if (recvAction.UseAcknowledgment())
96  {
97  DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
98  }
99  else
100  {
101  Interrupt();
102  }
103 
104  return false;
105  }
106  return true;
107 
108  }
109 
110  override void StartDeliveredAction()
111  {
112  if (!m_CurrentActionData)
113  {
115  return;
116  }
117 
118  m_Interrupted = false;
119 
120  bool accepted = false;
121  ActionBase pickedAction = m_CurrentActionData.m_Action;
122  ActionTarget target = m_CurrentActionData.m_Target;
123  ItemBase item = m_CurrentActionData.m_MainItem;
124 
125  if (LogManager.IsActionLogEnable())
126  {
127  Debug.ActionLog("Item = " + item + ", " + target.DumpToString(), pickedAction.ToString() , "n/a", "DeliveredAction", m_Player.ToString());
128  }
129 
130  if (!m_Player.GetCommandModifier_Action() && !m_Player.GetCommand_Action() && !m_Player.IsSprinting() && pickedAction && pickedAction.Can(m_Player,target,item))
131  {
132  accepted = true;
133  if (pickedAction.HasTarget())
134  {
135  EntityAI targetEntity;
136  if (EntityAI.CastTo(targetEntity,target.GetObject()))
137  {
138  if (!AdvancedCommunication.Cast(targetEntity) && !Building.Cast(targetEntity) && pickedAction.IsLockTargetOnUse())
139  {
140  //Lock target
141  if (!GetGame().AddActionJuncture(m_Player, targetEntity, 10000))
142  {
143  accepted = false;
144  }
145  }
146  }
147  }
148  }
149 
150  if (accepted)
151  {
152  if (LogManager.IsActionLogEnable())
153  {
154  Debug.ActionLog("Action accepted", pickedAction.ToString() , "n/a", "CheckDeliveredAction", m_Player.ToString() );
155  }
156  //Debug.Log("[AM] Action acccepted");
157  if (pickedAction.UseAcknowledgment())
158  {
159  //Unlock target
161  DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, true);
162  }
163  else
164  {
166  }
167  }
168  else
169  {
170  if (LogManager.IsActionLogEnable())
171  {
172  Debug.ActionLog("Action rejected", pickedAction.ToString() , "n/a", "CheckDeliveredAction", m_Player.ToString() );
173  }
174 
175  if (pickedAction.UseAcknowledgment())
176  {
177  DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
178  }
179  else
180  {
181  Interrupt();
182  }
183  }
184  }
185 
186  override void OnActionEnd()
187  {
188  //Debug.Log("Action ended - hard, STS = " + m_Player.GetSimulationTimeStamp());
190  {
191  if ( m_CurrentActionData.m_Target )
192  {
193  EntityAI targetEntity;
194  if (targetEntity.CastTo(targetEntity, m_CurrentActionData.m_Target.GetObject()) && !Building.Cast(targetEntity))
195  {
196  GetGame().ClearJuncture(m_CurrentActionData.m_Player, targetEntity);
197  }
198  }
199 
200  super.OnActionEnd();
201  }
202  }
203 
204  //pCurrentCommandID is command ID at time of call command handler, some called methods can change actual true value (need call m_Player.GetCurrentCommandID() for actual command ID)
205  override void Update(int pCurrentCommandID)
206  {
207  super.Update(pCurrentCommandID);
208  int currentCommandID = m_Player.GetCurrentCommandID();
209 
210  //Debug.Log("m_ActionWantEnd " + m_ActionInputWantEnd);
211 
212  if (m_PendingAction)
213  {
215  {
216  DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
217  }
218  else
219  {
220  m_ActionWantEndRequest = false;
221  m_ActionInputWantEnd = false;
222 
223  bool success = true;
224  ActionTarget target = new ActionTarget(null, null, -1, vector.Zero, 0);
225 
226  if ( LogManager.IsActionLogEnable() )
227  {
228  Debug.ActionLog("n/a", m_PendingAction.ToString() , "n/a", "HandlePendingAction", m_Player.ToString() );
229  }
230 
231  if (!m_PendingAction.SetupAction(m_Player,target,m_Player.GetItemInHands(),m_CurrentActionData))
232  {
233  success = false;
234  }
235  //Debug.Log("[AM] Action data synced (" + m_Player + ") success: " + success);
236 
237  if (success)
238  {
239  StartDeliveredAction();
240  }
241  else
242  {
243  if (m_PendingAction.UseAcknowledgment())
244  {
245  DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
246  }
247  else
248  {
249  Interrupt();
250  }
251  }
252  }
253 
254  m_PendingAction = null;
255  m_PendingActionReciveData = null;
256  }
257 
259  {
261  {
262  m_CurrentActionData.m_Action.OnUpdateServer(m_CurrentActionData);
263 
264  if (m_CurrentActionData.m_RefreshJunctureTimer > 0)
265  {
266  m_CurrentActionData.m_RefreshJunctureTimer--;
267  }
268  else
269  {
270  m_CurrentActionData.m_RefreshJunctureTimer = m_CurrentActionData.m_Action.GetRefreshReservationTimerValue();
271  if (m_CurrentActionData.m_Target)
272  {
273  EntityAI targetEntity;
274  if ( targetEntity.CastTo(targetEntity, m_CurrentActionData.m_Target.GetObject()) && !Building.Cast(targetEntity) )
275  {
276  GetGame().ExtendActionJuncture(m_CurrentActionData.m_Player, targetEntity, 10000);
277  }
278  }
279  }
280  }
281 
282  //Debug.Log("m_CurrentActionData.m_State: " + m_CurrentActionData.m_State +" m_ActionWantEnd: " + m_ActionWantEndRequest );
283  switch (m_CurrentActionData.m_State)
284  {
285  case UA_AM_PENDING:
286  break;
287 
288  case UA_AM_ACCEPTED:
289  // check currentCommandID before start or reject
290 
291  bool canActionPerform = m_CurrentActionData.m_Action.Can(m_Player, m_CurrentActionData.m_Target, m_CurrentActionData.m_MainItem);
292  if (canActionPerform && ActionPossibilityCheck(currentCommandID))
293  {
294  m_CurrentActionData.m_State = UA_START;
296 
297  if (m_CurrentActionData.m_Action && m_CurrentActionData.m_Action.IsInstant())
298  OnActionEnd();
299  }
300  else
301  {
302  Interrupt();
303  }
305  break;
306 
307  case UA_AM_REJECTED:
308  OnActionEnd();
310  break;
311 
312  default:
314  {
315  m_ActionInputWantEnd = false;
316  m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
317  }
318 
320  {
321  m_ActionWantEndRequest = false;
322  m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
323  }
324  break;
325  }
326  }
327  }
328 
329  override void Interrupt()
330  {
331  super.Interrupt();
332 
334  DayZPlayerSyncJunctures.SendActionInterrupt(m_Player);
335  }
336 
337  override ActionReciveData GetReciveData()
338  {
339  return m_PendingActionReciveData;
340  }
341 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
UA_AM_ACCEPTED
const int UA_AM_ACCEPTED
Definition: constants.c:447
INPUT_UDT_STANDARD_ACTION_END_REQUEST
const int INPUT_UDT_STANDARD_ACTION_END_REQUEST
Definition: _constants.c:3
LogManager
Definition: debug.c:734
m_CurrentActionData
protected ref ActionData m_CurrentActionData
Definition: actionmanagerbase.c:60
m_ActionWantEndRequest
protected bool m_ActionWantEndRequest
Definition: actionmanagerbase.c:52
ActionManagerBase
void ActionManagerBase(PlayerBase player)
Definition: actionmanagerbase.c:62
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
UA_START
const int UA_START
Definition: constants.c:439
ActionTarget
class ActionTargets ActionTarget
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
GetAction
override ActionBase GetAction()
Definition: actioninput.c:482
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
m_Interrupted
bool m_Interrupted
Definition: actionmanagerbase.c:49
INPUT_UDT_STANDARD_ACTION_INPUT_END
const int INPUT_UDT_STANDARD_ACTION_INPUT_END
Definition: _constants.c:4
DayZPlayerSyncJunctures
Definition: dayzplayersyncjunctures.c:4
m_PendingActionAcknowledgmentID
protected int m_PendingActionAcknowledgmentID
Definition: actionmanagerbase.c:58
ActionPossibilityCheck
bool ActionPossibilityCheck(int pCurrentCommandID)
Definition: actionmanagerbase.c:218
UA_AM_REJECTED
const int UA_AM_REJECTED
Definition: constants.c:448
ActionBase
void ActionBase()
Definition: actionbase.c:73
Debug
Definition: debug.c:13
m_ActionInputWantEnd
protected bool m_ActionInputWantEnd
Definition: actionmanagerbase.c:53
INPUT_UDT_STANDARD_ACTION_START
const int INPUT_UDT_STANDARD_ACTION_START
Definition: _constants.c:2
UA_AM_PENDING
const int UA_AM_PENDING
Definition: constants.c:446
AdvancedCommunication
Definition: advancedcommunication.c:141
EntityAI
Definition: building.c:5
ActionManagerServer
Definition: actionmanagerserver.c:1