DayZ 1.24
Loading...
Searching...
No Matches
Hand_Guards.c
Go to the documentation of this file.
1
2
7{
14 bool GuardCondition(HandEventBase e) { return true; }
15};
16
17
18class HandGuardAnd extends HandGuardBase
19{
22
23 void HandGuardAnd(HandGuardBase arg0 = null, HandGuardBase arg1 = null) { m_arg0 = arg0; m_arg1 = arg1; }
24
26 {
27 bool result = m_arg0.GuardCondition(e) && m_arg1.GuardCondition(e);
28
29#ifdef DEVELOPER
31 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type() + " && " + m_arg1.Type(), "HandGuardAnd", "n/a", "GuardCondition", e.m_Player.ToString());
32#endif
33
34 return result;
35 }
36};
37
38class HandGuardNot extends HandGuardBase
39{
41
42 void HandGuardNot(HandGuardBase arg0 = null) { m_arg0 = arg0; }
43
45 {
46 bool result = !m_arg0.GuardCondition(e);
47
48#ifdef DEVELOPER
50 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type(), "HandGuardNot", "n/a", "GuardCondition", e.m_Player.ToString());
51#endif
52 return result;
53 }
54};
55
56class HandGuardOr extends HandGuardBase
57{
60
61 void HandGuardOr(HandGuardBase arg0 = null, HandGuardBase arg1 = null) { m_arg0 = arg0; m_arg1 = arg1; }
62
64 {
65 bool result = m_arg0.GuardCondition(e) || m_arg1.GuardCondition(e);
66
67#ifdef DEVELOPER
69 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type() + " || " + m_arg1.Type(), "HandGuardOr", "n/a", "GuardCondition", e.m_Player.ToString());
70#endif
71 return result;
72 }
73};
74
76{
77 protected Man m_Player;
79
81 {
82 EntityAI eai = e.GetSrcEntity();
83 if (eai != NULL /* && CanTakeInHands*/)
84 {
85#ifdef DEVELOPER
87 Debug.InventoryHFSMLog("GuardCondition result: true - " + eai, "HandGuardHasItemInEvent", "n/a", "GuardCondition", m_Player.ToString());
88#endif
89 return true;
90 }
91
92#ifdef DEVELOPER
94 Debug.InventoryHFSMLog("GuardCondition result: false - " + eai, "HandGuardHasItemInEvent", "n/a", "GuardCondition", m_Player.ToString());
95#endif
96
97 return false;
98 }
99};
100
102{
104
106 {
107 EntityAI eai = e.GetSrcEntity();
108 bool result = false;
109 if (eai)
110 {
111 if (eai.IsWeapon())
112 result = true;
113 }
114#ifdef DEVELOPER
116 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardHasWeaponInEvent", "n/a", "GuardCondition", e.m_Player.ToString());
117#endif
118 return result;
119 }
120};
121
122class HandGuardIsSameItemInHands extends HandGuardBase
123{
124 protected Man m_Player;
126
128 {
129 bool result = false;
130 if (e.GetSrcEntity() == m_Player.GetHumanInventory().GetEntityInHands())
131 result = true;
132
133#ifdef DEVELOPER
135 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - srcItem = " + e.GetSrcEntity() + " hnd= " + m_Player.GetHumanInventory().GetEntityInHands(), "HandGuardIsSameItemInHands", "n/a", "GuardCondition", e.m_Player.ToString());
136#endif
137 return result;
138 }
139};
140
141class HandGuardHasDestroyedItemInHands extends HandGuardBase
142{
143 protected Man m_Player;
145
147 {
148 EntityAI hnd = m_Player.GetHumanInventory().GetEntityInHands();
149 if (e.GetSrcEntity())
150 {
151 if (e.GetSrcEntity() == hnd)
152 {
153#ifdef DEVELOPER
155 Debug.InventoryHFSMLog("GuardCondition result: true - has same entity in hands " + hnd, "HandGuardHasDestroyedItemInHands", "n/a", "GuardCondition", m_Player.ToString());
156#endif
157 return true;
158 }
159
160 if (hnd == null)
161 {
162#ifdef DEVELOPER
164 Debug.InventoryHFSMLog("GuardCondition result: true - hands already empty", "HandGuardHasDestroyedItemInHands", "n/a", "GuardCondition", m_Player.ToString());
165#endif
166 return true;
167 }
168 }
169 else
170 {
171#ifdef DEVELOPER
173 Debug.InventoryHFSMLog("GuardCondition result: true - hands already empty and item destroyed", "HandGuardHasDestroyedItemInHands", "n/a", "GuardCondition", m_Player.ToString());
174#endif
175 return true;
176 }
177#ifdef DEVELOPER
179 Debug.InventoryHFSMLog("GuardCondition result: false - destroyed entity not in hands", "HandGuardHasDestroyedItemInHands", "n/a", "GuardCondition", m_Player.ToString());
180#endif
181 return false;
182 }
183};
184
185class HandGuardHasItemInHands extends HandGuardBase
186{
187 protected Man m_Player;
189
191 {
192 bool result = false;
193 if (m_Player.GetHumanInventory().GetEntityInHands())
194 result = true;
195
196#ifdef DEVELOPER
198 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_Player.GetHumanInventory().GetEntityInHands(), "HandGuardHasItemInHands", "n/a", "GuardCondition", m_Player.ToString());
199#endif
200 return result;
201 }
202};
203
205class HandGuardHasRoomForItem extends HandGuardBase
206{
207 protected Man m_Player;
209
211 {
212 if (e.GetDst() && e.GetDst().IsValid())
213 {
214 if (!GetGame().IsDedicatedServer())
215 {
216 if (m_Player)
217 m_Player.GetHumanInventory().ClearInventoryReservationEx(e.GetDst().GetItem(), e.GetDst());
218 }
219
220 if (!GameInventory.LocationTestAddEntity(e.GetDst(), false, true, true, true, true, false))
221 {
222#ifdef DEVELOPER
224 Debug.InventoryHFSMLog("GuardCondition result: false - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()), "HandGuardHasRoomForItem", "n/a", "GuardCondition", m_Player.ToString());
225#endif
226 //if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandGuardHasRoomForItem - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()));
227 //Error("[hndfsm] HandGuardHasRoomForItem - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()));
228 return false;
229 }
230
231
232 if (!GetGame().IsDedicatedServer())
233 {
234 if (m_Player)
235 m_Player.GetHumanInventory().AddInventoryReservationEx(e.GetDst().GetItem(), e.GetDst(), GameInventory.c_InventoryReservationTimeoutShortMS);
236 }
237
238#ifdef DEVELOPER
240 Debug.InventoryHFSMLog("GuardCondition result: true", "HandGuardHasRoomForItem", "n/a", "GuardCondition", m_Player.ToString());
241#endif
242 return true;
243 }
244
245#ifdef DEVELOPER
247 Debug.InventoryHFSMLog("GuardCondition result: false - e.m_Dst is null", "HandGuardHasRoomForItem", "n/a", "GuardCondition", m_Player.ToString());
248#endif
249
250 return false;
251 }
252};
253
254class HandGuardCanMove extends HandGuardBase
255{
256 protected Man m_Player;
257 void HandGuardCanMove(Man p = null) { m_Player = p; }
258
260 {
261 HandEventMoveTo es = HandEventMoveTo.Cast(e);
262
263 bool result = e.m_IsJuncture || e.m_IsRemote;
264 if (result == false)
265 result = GameInventory.LocationCanMoveEntity(es.GetSrc(), es.GetDst());
266
267#ifdef DEVELOPER
269 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanMove", "n/a", "GuardCondition", m_Player.ToString());
270#endif
271
272 return result;
273 }
274};
275
276class HandGuardCanSwap extends HandGuardBase
277{
278 protected Man m_Player;
279 void HandGuardCanSwap(Man p = NULL) { m_Player = p; }
280
282 {
284
285 bool result = e.m_IsJuncture || e.m_IsRemote;
286 if (result == false)
287 result = GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem());
288
289#ifdef DEVELOPER
291 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanSwap", "n/a", "GuardCondition", m_Player.ToString());
292#endif
293 //if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandGuardCanSwap guard - cannot swap");
294 return result;
295 }
296};
297
298class HandGuardCanForceSwap extends HandGuardBase
299{
300 protected Man m_Player;
302
304 {
305 HandEventForceSwap es = HandEventForceSwap.Cast(e);
306
307 bool result = e.m_IsJuncture || e.m_IsRemote;
308 if (result == false)
309 {
310 result = GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem());
311
312 if (result == false && es.m_Dst2)
313 result = GameInventory.CanForceSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Dst, es.m_Src2.GetItem(), es.m_Dst2);
314 }
315
316#ifdef DEVELOPER
318 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanForceSwap", "n/a", "GuardCondition", m_Player.ToString());
319#endif
320
321 return result;
322 }
323};
324
325class HandGuardInstantForceSwap extends HandGuardBase
326{
327 protected Man m_Player;
329
331 {
332 HandEventForceSwap es = HandEventForceSwap.Cast(e);
333
334 InventoryLocation src1 = es.m_Src;
335 InventoryLocation dst2 = es.m_Dst2;
336
337 bool result = false;
338 if (src1.GetType() == InventoryLocationType.CARGO && dst2.GetType() == InventoryLocationType.CARGO)
339 {
340 if (src1.GetParent() == dst2.GetParent())
341 result = true;
342 }
343
344#ifdef DEVELOPER
346 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardInstantForceSwap", "n/a", "GuardCondition", m_Player.ToString());
347#endif
348
349 return result;
350 }
351};
352
354
DayZPlayer m_Player
Definition Hand_Events.c:42
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 bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:610
static proto native bool LocationTestAddEntity(notnull InventoryLocation inv_loc, bool do_resevation_check, bool do_item_check, bool do_lock_check, bool do_occupancy_test, bool do_script_check, bool do_script_load_check)
test if the entity contained in inv_loc.m_item can be added to ground/attachment/cargo/hands/....
static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
Definition Inventory.c:645
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.
TODO(kumarjac): This guard is unused but it has a fault and doesn't conform with maximimal/minimal ch...
Definition Hand_Guards.c:7
ref HandGuardBase m_arg0
Definition Hand_Guards.c:20
void HandGuardIsSameItemInHands(Man p=null)
void HandGuardInstantForceSwap(Man p=NULL)
ref HandGuardBase m_arg1
Definition Hand_Guards.c:21
void HandGuardCanMove(Man p=null)
void HandGuardHasRoomForItem(Man p=null)
void HandGuardCanSwap(Man p=NULL)
void HandGuardHasDestroyedItemInHands(Man p=null)
void HandGuardNot(HandGuardBase arg0=null)
Definition Hand_Guards.c:42
void HandGuardOr(HandGuardBase arg0=null, HandGuardBase arg1=null)
Definition Hand_Guards.c:61
void HandGuardHasItemInEvent(Man p=null)
Definition Hand_Guards.c:78
void HandGuardCanForceSwap(Man p=NULL)
void HandGuardAnd(HandGuardBase arg0=null, HandGuardBase arg1=null)
Definition Hand_Guards.c:23
bool GuardCondition(HandEventBase e)
Definition Hand_Guards.c:14
void HandGuardHasItemInHands(Man p=null)
override bool GuardCondition(HandEventBase e)
Definition Hand_Guards.c:25
void HandGuardHasWeapoonInEvent(Man p=null)
override bool GuardCondition(HandEventBase e)
InventoryLocation.
static string DumpToStringNullSafe(InventoryLocation loc)
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:749
proto native CGame GetGame()