Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
handanimatedforceswapping.c
Go to the documentation of this file.
1 // When editing this, take a look at HandAnimatedMoveToDst_W4T_Basic as well
2 // They can not be inherited from each other because of different inheritance
3 class HandAnimatedMoveToDst_W4T_Basic extends HandStateBase
4 {
5  ref InventoryLocation m_Dst;
6 
7  override void OnEntry(HandEventBase e)
8  {
9  Man player = e.m_Player;
10  if (m_Dst && m_Dst.IsValid())
11  {
12  EntityAI item = m_Dst.GetItem();
14  if (item.GetInventory().GetCurrentInventoryLocation(src))
15  {
16  if (GameInventory.LocationCanMoveEntity(src, m_Dst))
17  {
18  GameInventory.LocationSyncMoveEntity(src, m_Dst);
19  player.OnItemInHandsChanged();
20  }
21  else
22  {
23  #ifdef DEVELOPER
24  if ( LogManager.IsInventoryHFSMLogEnable() )
25  {
26  Debug.InventoryHFSMLog("[hndfsm] HandAnimatedMoveToDst_W4T_Basic - not allowed");
27  }
28  #endif
29  }
30  }
31  else
32  Error("[hndfsm] " + Object.GetDebugName(e.m_Player) + " STS = " + e.m_Player.GetSimulationTimeStamp() + " HandAnimatedMoveToDst_W4T_Basic - item " + item + " has no Inventory or Location, inv=" + item.GetInventory());
33  }
34  else
35  Error("[hndfsm] HandAnimatedMoveToDst_W4T_Basic - event has no valid m_Dst");
36 
37  super.OnEntry(e);
38  }
39 
40  override void OnAbort(HandEventBase e)
41  {
42  m_Dst = null;
43  super.OnAbort(e);
44  }
45 
46  override void OnExit(HandEventBase e)
47  {
48  m_Dst = null;
49  super.OnExit(e);
50  }
51 
52  override bool IsWaitingForActionFinish() { return true; }
53 };
54 
56 {
57  ref InventoryLocation m_Src1 = null;
58  ref InventoryLocation m_Src2 = null;
59  ref InventoryLocation m_Dst1 = null;
60  ref InventoryLocation m_Dst2 = null;
61 
62  void HandForceSwapingAnimated_Show(Man player = null, HandStateBase parent = null, WeaponActions action = WeaponActions.NONE, int actionType = -1) { }
63 
64  override void OnEntry(HandEventBase e)
65  {
66  if (m_Src1 && m_Src2 && m_Dst1 && m_Dst2)
67  {
68  //InventoryLocation dummy;
69  //dummy.Copy(m_Dst2);
70  //if (GameInventory.CanForceSwapEntitiesEx(m_Src1.GetItem(), m_Dst1, m_Src2.GetItem(), dummy) && dummy == m_Dst2)
71  //{
72 
74 
75  GameInventory.LocationSwap(m_Src1, m_Src2, m_Dst1, m_Dst2);
76  e.m_Player.OnItemInHandsChanged();
77  //}
78  //else
79  //{
80  // if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandForceSwapingAnimated_Show - not allowed");
81  //}
82  }
83  else
84  Error("[hndfsm] HandForceSwappingAnimated_Show is not properly configured!");
85 
86  super.OnEntry(e);
87  }
88 
89  override void OnAbort(HandEventBase e)
90  {
91  m_Src1 = null;
92  m_Src2 = null;
93  m_Dst1 = null;
94  m_Dst2 = null;
95  super.OnAbort(e);
96  }
97 
98  override void OnExit(HandEventBase e)
99  {
100  m_Src1 = null;
101  m_Src2 = null;
102  m_Dst1 = null;
103  m_Dst2 = null;
104  super.OnExit(e);
105  }
106 
107  override bool IsWaitingForActionFinish() { return true; }
108 };
109 
110 
111 class HandAnimatedForceSwapping extends HandStateBase
112 {
113  ref InventoryLocation m_Src1 = null;
114  ref InventoryLocation m_Src2 = null;
115  ref InventoryLocation m_Dst1 = null;
116  ref InventoryLocation m_Dst2 = null;
117 
118  ref HandStartHidingAnimated m_Start;
119  ref HandAnimatedMoveToDst_W4T m_Show;
120  ref HandAnimatedMoveToDst_W4T_Basic m_Hide;
121 
122  void HandAnimatedForceSwapping(Man player = null, HandStateBase parent = null)
123  {
124  // setup nested state machine
125  m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
126  m_Show = new HandAnimatedMoveToDst_W4T(player, this, WeaponActions.SHOW, -1);
127  m_Hide = new HandAnimatedMoveToDst_W4T_Basic(player, this);
128 
129  // events:
130  HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
131  HandEventBase _AEh_ = new HandAnimEventChanged;
132  HandEventBase __Xd_ = new HandEventDestroyed;
133 
134  m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
135 
136  m_FSM.AddTransition(new HandTransition( m_Start, _AEh_, m_Hide ));
137  m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show )); // no animation in Hide step
138  m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
139  m_FSM.AddTransition(new HandTransition( m_Hide, _fin_, null ));
140  m_FSM.AddTransition(new HandTransition( m_Show, __Xd_, null ));
141  m_FSM.AddTransition(new HandTransition( m_Hide, __Xd_, null ));
142 
143  m_FSM.SetInitialState(m_Start);
144  }
145 
146  override void OnEntry(HandEventBase e)
147  {
148  HandEventForceSwap efs = HandEventForceSwap.Cast(e);
149  if (efs)
150  {
151  if ( efs.GetSrc().GetType() == InventoryLocationType.HANDS )
152  {
153  m_Start.m_ActionType = efs.m_AnimationID;
154 
155  m_Src1 = efs.GetSrc();
156  m_Src2 = efs.m_Src2;
157  m_Dst1 = efs.GetDst();
158  m_Dst2 = efs.m_Dst2;
159 
160  m_Show.m_ActionType = efs.m_Animation2ID;
161  }
162  else
163  {
164  m_Start.m_ActionType = efs.m_Animation2ID;
165 
166  m_Src1 = efs.m_Src2;
167  m_Src2 = efs.GetSrc();
168  m_Dst1 = efs.m_Dst2;
169  m_Dst2 = efs.GetDst();
170 
171  m_Show.m_ActionType = efs.m_AnimationID;
172  }
173 
174  m_Hide.m_Dst = m_Dst1;
175  m_Show.m_Dst = m_Dst2;
176 
177  if (!GetGame().IsDedicatedServer())
178  {
179  e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
180  e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
181  }
182  }
183 
184  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
185  }
186 
187  override void OnAbort(HandEventBase e)
188  {
189  if ( !GetGame().IsDedicatedServer())
190  {
191  if (m_Dst1)
192  {
193  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
194  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
195  }
196  }
197  else
198  {
199  if (m_Dst1)
200  {
201  GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
202  GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
203  }
204  }
205 
206  m_Src1 = null;
207  m_Src2 = null;
208  m_Dst1 = null;
209  m_Dst2 = null;
210 
211  super.OnAbort(e);
212  }
213 
214  override void OnExit(HandEventBase e)
215  {
216  if ( !GetGame().IsDedicatedServer())
217  {
218  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
219  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
220  }
221  else
222  {
223  GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
224  GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
225  }
226 
227  m_Src1 = null;
228  m_Src2 = null;
229  m_Dst1 = null;
230  m_Dst2 = null;
231 
232  super.OnExit(e);
233  }
234 };
235 
236 class HandAnimatedForceSwapping_Inst extends HandStateBase
237 {
238  ref InventoryLocation m_Src1 = null;
239  ref InventoryLocation m_Src2 = null;
240  ref InventoryLocation m_Dst1 = null;
241  ref InventoryLocation m_Dst2 = null;
242 
243  ref HandStartHidingAnimated m_Start;
245 
246  void HandAnimatedForceSwapping_Inst(Man player = null, HandStateBase parent = null)
247  {
248  // setup nested state machine
249  m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
250  m_Swap = new HandForceSwappingAnimated_Show(player, this, WeaponActions.SHOW, -1);
251 
252  // events:
253  HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
254  HandEventBase _AEh_ = new HandAnimEventChanged;
255  HandEventBase __Xd_ = new HandEventDestroyed;
256 
257  m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
258 
259  m_FSM.AddTransition(new HandTransition( m_Start, _AEh_, m_Swap ));
260  m_FSM.AddTransition(new HandTransition( m_Swap, _fin_, null ));
261  m_FSM.AddTransition(new HandTransition( m_Swap, __Xd_, null ));
262 
263  m_FSM.SetInitialState(m_Start);
264  }
265 
266  override void OnEntry(HandEventBase e)
267  {
268  HandEventForceSwap efs = HandEventForceSwap.Cast(e);
269  if (efs)
270  {
271  if ( efs.GetSrc().GetType() == InventoryLocationType.HANDS )
272  {
273  m_Start.m_ActionType = efs.m_AnimationID;
274 
275  m_Src1 = efs.GetSrc();
276  m_Src2 = efs.m_Src2;
277  m_Dst1 = efs.GetDst();
278  m_Dst2 = efs.m_Dst2;
279 
280  m_Swap.m_ActionType = efs.m_Animation2ID;
281  }
282  else
283  {
284  m_Start.m_ActionType = efs.m_Animation2ID;
285 
286  m_Src1 = efs.m_Src2;
287  m_Src2 = efs.GetSrc();
288  m_Dst1 = efs.m_Dst2;
289  m_Dst2 = efs.GetDst();
290 
291  m_Swap.m_ActionType = efs.m_AnimationID;
292  }
293 
294  m_Swap.m_Src1 = m_Src1;
295  m_Swap.m_Dst1 = m_Dst1;
296  m_Swap.m_Src2 = m_Src2;
297  m_Swap.m_Dst2 = m_Dst2;
298 
299  if (!GetGame().IsDedicatedServer())
300  {
301  e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
302  e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
303  }
304  }
305 
306  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
307  }
308 
309  override void OnAbort(HandEventBase e)
310  {
311  if ( !GetGame().IsDedicatedServer())
312  {
313  if (m_Dst1)
314  {
315  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
316  }
317  if (m_Dst2)
318  {
319  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
320  }
321  }
322  else
323  {
324  if (m_Dst1)
325  {
326  GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
327  }
328  if (m_Dst2)
329  {
330  GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
331  }
332  }
333 
334  m_Src1 = null;
335  m_Src2 = null;
336  m_Dst1 = null;
337  m_Dst2 = null;
338 
339  super.OnAbort(e);
340  }
341 
342  override void OnExit(HandEventBase e)
343  {
344  if ( !GetGame().IsDedicatedServer())
345  {
346  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
347  e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
348  }
349  else
350  {
351  GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
352  GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
353  }
354 
355  m_Src1 = null;
356  m_Src2 = null;
357  m_Dst1 = null;
358  m_Dst2 = null;
359 
360  super.OnExit(e);
361  }
362 };
363 
GetGame
proto native CGame GetGame()
HandStateBase
represent hand state base
Definition: handanimatedforceswapping.c:3
HandTransition
FSMTransition< HandStateBase, HandEventBase, HandActionBase, HandGuardBase > HandTransition
Definition: handfsm.c:28
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
OnAbort
override void OnAbort()
Definition: remotedetonator.c:300
LogManager
Definition: debug.c:734
OnExit
override void OnExit(HandEventBase e)
Definition: hand_states.c:28
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
HandEventBase
Abstracted event, not to be used, only inherited.
Definition: hand_events.c:194
WeaponActions
WeaponActions
actions
Definition: human.c:808
IsWaitingForActionFinish
class WeaponChambering_Cartridge_InnerMag extends WeaponChambering_Base IsWaitingForActionFinish
Definition: weaponchambering.c:190
HandFSM
Hand finite state machine.
HandStartAction
simple class starting animation action specified by m_action and m_actionType
Definition: handanimatedforceswapping.c:55
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
Object
Definition: objecttyped.c:1
Debug
Definition: debug.c:13
HandForceSwappingAnimated_Show
Definition: handanimatedswapping.c:1
EntityAI
Definition: building.c:5
OnEntry
HandStateEquipped OnEntry
Definition: weaponchambering.c:208
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78