DayZ 1.24
Loading...
Searching...
No Matches
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
4{
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 {
17 {
19 player.OnItemInHandsChanged();
20 }
21 else
22 {
23#ifdef DEVELOPER
25 Debug.InventoryHFSMLog("[hndfsm] HandAnimatedMoveToDst_W4T_Basic - not allowed");
26#endif
27 }
28 }
29 else
30 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());
31 }
32 else
33 Error("[hndfsm] HandAnimatedMoveToDst_W4T_Basic - event has no valid m_Dst");
34
35 super.OnEntry(e);
36 }
37
38 override void OnAbort(HandEventBase e)
39 {
40 m_Dst = null;
41 super.OnAbort(e);
42 }
43
44 override void OnExit(HandEventBase e)
45 {
46 m_Dst = null;
47 super.OnExit(e);
48 }
49
50 override bool IsWaitingForActionFinish() { return true; }
51};
52
54{
59
61
62 override void OnEntry(HandEventBase e)
63 {
64 if (m_Src1 && m_Src2 && m_Dst1 && m_Dst2)
65 {
66 //InventoryLocation dummy;
67 //dummy.Copy(m_Dst2);
68 //if (GameInventory.CanForceSwapEntitiesEx(m_Src1.GetItem(), m_Dst1, m_Src2.GetItem(), dummy) && dummy == m_Dst2)
69 //{
70
72
73 GameInventory.LocationSwap(m_Src1, m_Src2, m_Dst1, m_Dst2);
74 e.m_Player.OnItemInHandsChanged();
75 //}
76 //else
77 //{
78 // if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandForceSwapingAnimated_Show - not allowed");
79 //}
80 }
81 else
82 Error("[hndfsm] HandForceSwappingAnimated_Show is not properly configured!");
83
84 super.OnEntry(e);
85 }
86
87 override void OnAbort(HandEventBase e)
88 {
89 m_Src1 = null;
90 m_Src2 = null;
91 m_Dst1 = null;
92 m_Dst2 = null;
93 super.OnAbort(e);
94 }
95
96 override void OnExit(HandEventBase e)
97 {
98 m_Src1 = null;
99 m_Src2 = null;
100 m_Dst1 = null;
101 m_Dst2 = null;
102 super.OnExit(e);
103 }
104
105 override bool IsWaitingForActionFinish() { return true; }
106};
107
108
109class HandAnimatedForceSwapping extends HandStateBase
110{
115
116 ref HandStartHidingAnimated m_Start;
119
121 {
122 // setup nested state machine
123 m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
124 m_Show = new HandAnimatedMoveToDst_W4T(player, this, WeaponActions.SHOW, -1);
125 m_Hide = new HandAnimatedMoveToDst_W4T_Basic(player, this);
126
127 // events:
128 HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
129 HandEventBase _AEh_ = new HandAnimEventChanged;
130 HandEventBase __Xd_ = new HandEventDestroyed;
131
132 m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
133
134 m_FSM.AddTransition(new HandTransition(m_Start, _AEh_, m_Hide));
135 m_FSM.AddTransition(new HandTransition(m_Hide, _AEh_, m_Show)); // no animation in Hide step
136 m_FSM.AddTransition(new HandTransition(m_Show, _fin_, null));
137 m_FSM.AddTransition(new HandTransition(m_Hide, _fin_, null));
138 m_FSM.AddTransition(new HandTransition(m_Show, __Xd_, null));
139 m_FSM.AddTransition(new HandTransition(m_Hide, __Xd_, null));
140
141 m_FSM.SetInitialState(m_Start);
142 }
143
144 override void OnEntry(HandEventBase e)
145 {
146 HandEventForceSwap efs = HandEventForceSwap.Cast(e);
147 if (efs)
148 {
149 if (efs.GetSrc().GetType() == InventoryLocationType.HANDS)
150 {
151 m_Start.m_ActionType = efs.m_AnimationID;
152
153 m_Src1 = efs.GetSrc();
154 m_Src2 = efs.m_Src2;
155 m_Dst1 = efs.GetDst();
156 m_Dst2 = efs.m_Dst2;
157
158 m_Show.m_ActionType = efs.m_Animation2ID;
159 }
160 else
161 {
162 m_Start.m_ActionType = efs.m_Animation2ID;
163
164 m_Src1 = efs.m_Src2;
165 m_Src2 = efs.GetSrc();
166 m_Dst1 = efs.m_Dst2;
167 m_Dst2 = efs.GetDst();
168
169 m_Show.m_ActionType = efs.m_AnimationID;
170 }
171
172 m_Hide.m_Dst = m_Dst1;
173 m_Show.m_Dst = m_Dst2;
174
175 if (!GetGame().IsDedicatedServer())
176 {
177 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
178 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
179 }
180 }
181
182 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
183 }
184
185 override void OnAbort(HandEventBase e)
186 {
187 if (!GetGame().IsDedicatedServer())
188 {
189 if (m_Dst1)
190 {
191 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
192 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
193 }
194 }
195 else
196 {
197 if (m_Dst1)
198 {
199 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
200 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
201 }
202 }
203
204 m_Src1 = null;
205 m_Src2 = null;
206 m_Dst1 = null;
207 m_Dst2 = null;
208
209 super.OnAbort(e);
210 }
211
212 override void OnExit(HandEventBase e)
213 {
214 if (!GetGame().IsDedicatedServer())
215 {
216 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
217 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
218 }
219 else
220 {
221 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
222 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
223 }
224
225 m_Src1 = null;
226 m_Src2 = null;
227 m_Dst1 = null;
228 m_Dst2 = null;
229
230 super.OnExit(e);
231 }
232};
233
234class HandAnimatedForceSwapping_Inst extends HandStateBase
235{
236 ref InventoryLocation m_Src1 = null;
237 ref InventoryLocation m_Src2 = null;
238 ref InventoryLocation m_Dst1 = null;
239 ref InventoryLocation m_Dst2 = null;
240
241 ref HandStartHidingAnimated m_Start;
243
245 {
246 // setup nested state machine
247 m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
248 m_Swap = new HandForceSwappingAnimated_Show(player, this, WeaponActions.SHOW, -1);
249
250 // events:
251 HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
252 HandEventBase _AEh_ = new HandAnimEventChanged;
253 HandEventBase __Xd_ = new HandEventDestroyed;
254
255 m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
256
257 m_FSM.AddTransition(new HandTransition(m_Start, _AEh_, m_Swap));
258 m_FSM.AddTransition(new HandTransition(m_Swap, _fin_, null));
259 m_FSM.AddTransition(new HandTransition(m_Swap, __Xd_, null));
260
261 m_FSM.SetInitialState(m_Start);
262 }
263
264 override void OnEntry(HandEventBase e)
265 {
266 HandEventForceSwap efs = HandEventForceSwap.Cast(e);
267 if (efs)
268 {
269 if (efs.GetSrc().GetType() == InventoryLocationType.HANDS)
270 {
271 m_Start.m_ActionType = efs.m_AnimationID;
272
273 m_Src1 = efs.GetSrc();
274 m_Src2 = efs.m_Src2;
275 m_Dst1 = efs.GetDst();
276 m_Dst2 = efs.m_Dst2;
277
278 m_Swap.m_ActionType = efs.m_Animation2ID;
279 }
280 else
281 {
282 m_Start.m_ActionType = efs.m_Animation2ID;
283
284 m_Src1 = efs.m_Src2;
285 m_Src2 = efs.GetSrc();
286 m_Dst1 = efs.m_Dst2;
287 m_Dst2 = efs.GetDst();
288
289 m_Swap.m_ActionType = efs.m_AnimationID;
290 }
291
292 m_Swap.m_Src1 = m_Src1;
293 m_Swap.m_Dst1 = m_Dst1;
294 m_Swap.m_Src2 = m_Src2;
295 m_Swap.m_Dst2 = m_Dst2;
296
297 if (!GetGame().IsDedicatedServer())
298 {
299 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
300 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
301 }
302 }
303
304 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
305 }
306
307 override void OnAbort(HandEventBase e)
308 {
309 if (!GetGame().IsDedicatedServer())
310 {
311 if (m_Dst1)
312 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
313 if (m_Dst2)
314 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
315 }
316 else
317 {
318 if (m_Dst1)
319 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
320 if (m_Dst2)
321 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
322 }
323
324 m_Src1 = null;
325 m_Src2 = null;
326 m_Dst1 = null;
327 m_Dst2 = null;
328
329 super.OnAbort(e);
330 }
331
332 override void OnExit(HandEventBase e)
333 {
334 if (!GetGame().IsDedicatedServer())
335 {
336 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
337 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
338 }
339 else
340 {
341 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
342 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
343 }
344
345 m_Src1 = null;
346 m_Src2 = null;
347 m_Dst1 = null;
348 m_Dst2 = null;
349
350 super.OnExit(e);
351 }
352};
353
FSMTransition< HandStateBase, HandEventBase, HandActionBase, HandGuardBase > HandTransition
Definition HandFSM.c:27
InventoryLocationType
types of Inventory Location
Definition Debug.c:14
static void InventoryHFSMLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition Debug.c:183
script counterpart to engine's class Inventory
Definition Inventory.c:79
const int c_InventoryReservationTimeoutShortMS
Definition Inventory.c:688
static proto native bool LocationSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
swaps two entities
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
static proto native bool LocationCanMoveEntity(notnull InventoryLocation src, notnull InventoryLocation dst)
queries if the entity contained in inv_loc.m_item can be moved to another location This is a shorthan...
Abstracted event, not to be used, only inherited.
Hand finite state machine.
simple class starting animation action specified by m_action and m_actionType
override bool IsWaitingForActionFinish()
void HandForceSwapingAnimated_Show(Man player=null, HandStateBase parent=null, WeaponActions action=WeaponActions.NONE, int actionType=-1)
override void OnAbort(HandEventBase e)
override void OnEntry(HandEventBase e)
override void OnExit(HandEventBase e)
represent hand state base
override void OnExit(HandEventBase e)
ref InventoryLocation m_Dst
override void OnEntry(HandEventBase e)
override bool IsWaitingForActionFinish()
waiting for active animation action/actionType finish
ref InventoryLocation m_Dst1
ref InventoryLocation m_Src1
void HandAnimatedForceSwapping_Inst(Man player=null, HandStateBase parent=null)
ref HandAnimatedMoveToDst_W4T_Basic m_Hide
ref HandForceSwappingAnimated_Show m_Swap
ref HandAnimatedMoveToDst_W4T m_Show
override void OnAbort(HandEventBase e)
ref HandStartHidingAnimated m_Start
ref InventoryLocation m_Dst2
void HandAnimatedForceSwapping(Man player=null, HandStateBase parent=null)
ref InventoryLocation m_Src2
InventoryLocation.
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:749
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
WeaponActions
actions
Definition human.c:796