DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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
3class HandAnimatedMoveToDst_W4T_Basic extends HandStateBase
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 {
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 GameInventory.LocationSwap(m_Src1, m_Src2, m_Dst1, m_Dst2);
73 e.m_Player.OnItemInHandsChanged();
74 //}
75 //else
76 //{
77 // hndDebugPrint("[hndfsm] HandForceSwapingAnimated_Show - not allowed");
78 //}
79 }
80 else
81 Error("[hndfsm] HandForceSwappingAnimated_Show is not properly configured!");
82
83 super.OnEntry(e);
84 }
85
86 override void OnAbort(HandEventBase e)
87 {
88 m_Src1 = null;
89 m_Src2 = null;
90 m_Dst1 = null;
91 m_Dst2 = null;
92 super.OnAbort(e);
93 }
94
95 override void OnExit(HandEventBase e)
96 {
97 m_Src1 = null;
98 m_Src2 = null;
99 m_Dst1 = null;
100 m_Dst2 = null;
101 super.OnExit(e);
102 }
103
104 override bool IsWaitingForActionFinish() { return true; }
105};
106
107
108class HandAnimatedForceSwapping extends HandStateBase
109{
110 ref InventoryLocation m_Src1 = null;
111 ref InventoryLocation m_Src2 = null;
112 ref InventoryLocation m_Dst1 = null;
113 ref InventoryLocation m_Dst2 = null;
114
115 ref HandStartHidingAnimated m_Start;
116 ref HandAnimatedMoveToDst_W4T m_Show;
117 ref HandAnimatedMoveToDst_W4T_Basic m_Hide;
118
119 void HandAnimatedForceSwapping(Man player = null, HandStateBase parent = null)
120 {
121 // setup nested state machine
122 m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
123 m_Show = new HandAnimatedMoveToDst_W4T(player, this, WeaponActions.SHOW, -1);
124 m_Hide = new HandAnimatedMoveToDst_W4T_Basic(player, this);
125
126 // events:
127 HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
128 HandEventBase _AEh_ = new HandAnimEventChanged;
129 HandEventBase __Xd_ = new HandEventDestroyed;
130
131 m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
132
133 m_FSM.AddTransition(new HandTransition( m_Start, _AEh_, m_Hide ));
134 m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show )); // no animation in Hide step
135 m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
136 m_FSM.AddTransition(new HandTransition( m_Hide, _fin_, null ));
137 m_FSM.AddTransition(new HandTransition( m_Show, __Xd_, null ));
138 m_FSM.AddTransition(new HandTransition( m_Hide, __Xd_, null ));
139
140 m_FSM.SetInitialState(m_Start);
141 }
142
143 override void OnEntry(HandEventBase e)
144 {
145 HandEventForceSwap efs = HandEventForceSwap.Cast(e);
146 if (efs)
147 {
148 if ( efs.GetSrc().GetType() == InventoryLocationType.HANDS )
149 {
150 m_Start.m_ActionType = efs.m_AnimationID;
151
152 m_Src1 = efs.GetSrc();
153 m_Src2 = efs.m_Src2;
154 m_Dst1 = efs.GetDst();
155 m_Dst2 = efs.m_Dst2;
156
157 m_Show.m_ActionType = efs.m_Animation2ID;
158 }
159 else
160 {
161 m_Start.m_ActionType = efs.m_Animation2ID;
162
163 m_Src1 = efs.m_Src2;
164 m_Src2 = efs.GetSrc();
165 m_Dst1 = efs.m_Dst2;
166 m_Dst2 = efs.GetDst();
167
168 m_Show.m_ActionType = efs.m_AnimationID;
169 }
170
171 m_Hide.m_Dst = m_Dst1;
172 m_Show.m_Dst = m_Dst2;
173
174 if (!GetGame().IsDedicatedServer())
175 {
176 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
177 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
178 }
179 }
180
181 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
182 }
183
184 override void OnAbort(HandEventBase e)
185 {
186 if ( !GetGame().IsDedicatedServer())
187 {
188 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
189 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
190 }
191 else
192 {
193 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
194 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
195 }
196
197 m_Src1 = null;
198 m_Src2 = null;
199 m_Dst1 = null;
200 m_Dst2 = null;
201
202 super.OnAbort(e);
203 }
204
205 override void OnExit(HandEventBase e)
206 {
207 if ( !GetGame().IsDedicatedServer())
208 {
209 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
210 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
211 }
212 else
213 {
214 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
215 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
216 }
217
218 m_Src1 = null;
219 m_Src2 = null;
220 m_Dst1 = null;
221 m_Dst2 = null;
222
223 super.OnExit(e);
224 }
225};
226
227class HandAnimatedForceSwapping_Inst extends HandStateBase
228{
229 ref InventoryLocation m_Src1 = null;
230 ref InventoryLocation m_Src2 = null;
231 ref InventoryLocation m_Dst1 = null;
232 ref InventoryLocation m_Dst2 = null;
233
234 ref HandStartHidingAnimated m_Start;
236
237 void HandAnimatedForceSwapping_Inst(Man player = null, HandStateBase parent = null)
238 {
239 // setup nested state machine
240 m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
241 m_Swap = new HandForceSwappingAnimated_Show(player, this, WeaponActions.SHOW, -1);
242
243 // events:
244 HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
245 HandEventBase _AEh_ = new HandAnimEventChanged;
246 HandEventBase __Xd_ = new HandEventDestroyed;
247
248 m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
249
250 m_FSM.AddTransition(new HandTransition( m_Start, _AEh_, m_Swap ));
251 m_FSM.AddTransition(new HandTransition( m_Swap, _fin_, null ));
252 m_FSM.AddTransition(new HandTransition( m_Swap, __Xd_, null ));
253
254 m_FSM.SetInitialState(m_Start);
255 }
256
257 override void OnEntry(HandEventBase e)
258 {
259 HandEventForceSwap efs = HandEventForceSwap.Cast(e);
260 if (efs)
261 {
262 if ( efs.GetSrc().GetType() == InventoryLocationType.HANDS )
263 {
264 m_Start.m_ActionType = efs.m_AnimationID;
265
266 m_Src1 = efs.GetSrc();
267 m_Src2 = efs.m_Src2;
268 m_Dst1 = efs.GetDst();
269 m_Dst2 = efs.m_Dst2;
270
271 m_Swap.m_ActionType = efs.m_Animation2ID;
272 }
273 else
274 {
275 m_Start.m_ActionType = efs.m_Animation2ID;
276
277 m_Src1 = efs.m_Src2;
278 m_Src2 = efs.GetSrc();
279 m_Dst1 = efs.m_Dst2;
280 m_Dst2 = efs.GetDst();
281
282 m_Swap.m_ActionType = efs.m_AnimationID;
283 }
284
285 m_Swap.m_Src1 = m_Src1;
286 m_Swap.m_Dst1 = m_Dst1;
287 m_Swap.m_Src2 = m_Src2;
288 m_Swap.m_Dst2 = m_Dst2;
289
290 if (!GetGame().IsDedicatedServer())
291 {
292 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
293 e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
294 }
295 }
296
297 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
298 }
299
300 override void OnAbort(HandEventBase e)
301 {
302 if ( !GetGame().IsDedicatedServer())
303 {
304 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
305 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
306 }
307 else
308 {
309 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
310 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
311 }
312
313 m_Src1 = null;
314 m_Src2 = null;
315 m_Dst1 = null;
316 m_Dst2 = null;
317
318 super.OnAbort(e);
319 }
320
321 override void OnExit(HandEventBase e)
322 {
323 if ( !GetGame().IsDedicatedServer())
324 {
325 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
326 e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
327 }
328 else
329 {
330 GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
331 GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
332 }
333
334 m_Src1 = null;
335 m_Src2 = null;
336 m_Dst1 = null;
337 m_Dst2 = null;
338
339 super.OnExit(e);
340 }
341};
342
FSMTransition< HandStateBase, HandEventBase, HandActionBase, HandGuardBase > HandTransition
Definition HandFSM.c:20
InventoryLocationType
types of Inventory Location
proto native bool ClearJuncture(Man player, notnull EntityAI item)
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:158
script counterpart to engine's class Inventory
Definition Inventory.c:77
static proto native bool LocationSwap(notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
swaps two entities
const int c_InventoryReservationTimeoutShortMS
Definition Inventory.c:684
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...
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...
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 void OnAbort(HandEventBase e)
override void OnEntry(HandEventBase e)
override void OnExit(HandEventBase e)
void HandForceSwapingAnimated_Show(Man player=null, HandStateBase parent=null, WeaponActions action=WeaponActions.NONE, int actionType=-1)
override bool IsWaitingForActionFinish()
represent hand state base
void HandAnimatedForceSwapping_Inst(Man player=null, HandStateBase parent=null)
override void OnAbort(HandEventBase e)
override bool IsWaitingForActionFinish()
waiting for active animation action/actionType finish
override void OnEntry(HandEventBase e)
ref InventoryLocation m_Dst
ref HandStartHidingAnimated m_Start
ref HandForceSwappingAnimated_Show m_Swap
void HandAnimatedForceSwapping(Man player=null, HandStateBase parent=null)
ref InventoryLocation m_Src2
override void OnExit(HandEventBase e)
ref InventoryLocation m_Dst1
ref InventoryLocation m_Dst2
ref HandAnimatedMoveToDst_W4T_Basic m_Hide
ref HandAnimatedMoveToDst_W4T m_Show
ref InventoryLocation m_Src1
InventoryLocation.
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:620
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
WeaponActions
actions
Definition human.c:798