DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
FirearmActionAttachMagazine.c
См. документацию.
5class AttachMagazineActionData : ActionData
6{
8 Magazine m_oldMagazine;
9}
10
12{
13 //-----------------------------------------------------
14 // Action events and methods
15 //-----------------------------------------------------
17 {
18 m_Text = "#attach";
19 }
20
21 override int GetActionCategory()
22 {
23 return AC_SINGLE_USE;
24 }
25
26 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
27 {
28 if (!super.ActionCondition( player, target, item ))
29 return false;
30
31 HumanCommandWeapons hcw = player.GetCommandModifier_Weapons();
32 Magazine mag = Magazine.Cast(target.GetObject());
33 Weapon_Base wpn = Weapon_Base.Cast(item);
34 return mag && (player.GetWeaponManager().CanAttachMagazine(wpn,mag) || player.GetWeaponManager().CanSwapMagazine(wpn,mag)) && (!hcw || hcw.GetRunningAction() != WeaponActions.RELOAD);
35 }
36
37 override bool ActionConditionContinue( ActionData action_data )
38 {
39 return true;
40 }
41
43 {
44 AttachMagazineActionData action_data = new AttachMagazineActionData;
45 return action_data;
46 }
47
48
49 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
50 {
51 super.WriteToContext(ctx, action_data);
52
53 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
54
55 action_data_am.m_ilOldMagazine.WriteToContext(ctx);
56 }
57
58 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
59 {
60 if (!action_recive_data)
61 {
62 action_recive_data = new AttachMagazineActionReciveData;
63 }
64
65 super.ReadFromContext(ctx, action_recive_data);
66
68 if (!il.ReadFromContext(ctx))
69 return false;
70
71 AttachMagazineActionReciveData recive_data_am = AttachMagazineActionReciveData.Cast(action_recive_data);
72 recive_data_am.m_ilOldMagazine = il;
73
74 return true;
75 }
76
77 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
78 {
79 AttachMagazineActionReciveData recive_data_am = AttachMagazineActionReciveData.Cast(action_recive_data);
80 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
81
82 action_data.m_MainItem = action_recive_data.m_MainItem;
83 if (!action_recive_data.m_Target)
84 {
85 action_data.m_Target = new ActionTarget(NULL, NULL, -1, vector.Zero, 0);
86 }
87 else
88 {
89 action_data.m_Target = action_recive_data.m_Target;
90 }
91 action_data_am.m_ilOldMagazine = recive_data_am.m_ilOldMagazine;
92 }
93
94 override bool Post_SetupAction( ActionData action_data )
95 {
96 if ( !g_Game.IsDedicatedServer() )
97 {
98 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
99 int muzzle_index = wpn.GetCurrentMuzzle();
100
101 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
102 am_action_data.m_oldMagazine = wpn.GetMagazine(muzzle_index);
103
105
106 if (!action_data.m_Player.GetWeaponManager().PrepareInventoryLocationForMagazineSwap(wpn, Magazine.Cast(action_data.m_Target.GetObject()), new_il))
107 {
108 return false;
109 }
110 am_action_data.m_ilOldMagazine = new_il;
111 }
112 return true;
113 }
114
115 override bool InventoryReservation( ActionData action_data)
116 {
117 if( (IsLocal() || !UseAcknowledgment()) && IsInstant() )
118 return true;
119
120 bool success = true;
121 InventoryLocation oldMagTargetInventoryLocation = NULL;
122 InventoryLocation targetInventoryLocation = NULL;
123 InventoryLocation handInventoryLocation = NULL;
124
125 PlayerBase player = action_data.m_Player;
126 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
127
128 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
129 int muzzle_index = wpn.GetCurrentMuzzle();
130
131 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
132
133 if (am_action_data.m_oldMagazine)
134 {
135 oldMagTargetInventoryLocation = new InventoryLocation;
136 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
137 {
138 success = false;
139 }
140 else
141 {
142 player.GetInventory().AddInventoryReservationEx(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine,GameInventory.c_InventoryReservationTimeoutMS);
143 }
144 }
145
146 if (success)
147 {
148 targetInventoryLocation = new InventoryLocation;
149 targetInventoryLocation.SetAttachment( wpn, new_mag, InventorySlots.MAGAZINE);
150 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
151 {
152 success = false;
153 if (am_action_data.m_oldMagazine)
154 {
155 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
156 }
157 }
158 else
159 {
160 action_data.m_Player.GetInventory().AddInventoryReservationEx( new_mag, targetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
161 }
162 }
163
164 if (success)
165 {
166 handInventoryLocation = new InventoryLocation;
167 handInventoryLocation.SetHands(action_data.m_Player, wpn);
168
169 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
170 {
171 if (am_action_data.m_oldMagazine)
172 {
173 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
174 }
175 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
176 success = false;
177 }
178 else
179 {
180 action_data.m_Player.GetInventory().AddInventoryReservationEx( wpn, handInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
181 }
182 }
183
184 if ( success )
185 {
186 if (am_action_data.m_ilOldMagazine)
187 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
188
189 if (targetInventoryLocation)
190 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
191
192 if (handInventoryLocation)
193 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
194 }
195
196 return success;
197 }
198
199 override void Start( ActionData action_data )
200 {
201 super.Start( action_data );
202 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
203 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
204 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
205 ClearInventoryReservationEx(action_data);
206 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,false) )
207 action_data.m_Player.GetWeaponManager().AttachMagazine(mag, this);
208 else
209 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine, this);
210 InventoryReservation(action_data);
211 }
212
214 {
215 return true;
216 }
217
219 {
220 return true;
221 }
222};
223
224
226{
230
231 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
232 {
233 if (!super.ActionCondition( player, target, item ))
234 return false;
235
236 HumanCommandWeapons hcw = player.GetCommandModifier_Weapons();
237 if (hcw && hcw.GetRunningAction() == WeaponActions.RELOAD)
238 return false;
239
240 Magazine magazine;
241 #ifdef SERVER
242 magazine = Magazine.Cast(target.GetObject());
243 #else
244 magazine = Magazine.Cast(player.GetWeaponManager().GetPreparedMagazine());
245 #endif
246 if (!magazine)
247 return false;
248
249 MagazineStorage mag = MagazineStorage.Cast(magazine);
250 if (!mag)
251 return false;
252
253 Weapon weapon = Weapon.Cast(item);
254 bool isLoadedMag = false;
255
256 for (int i = 0, count = weapon.GetMuzzleCount(); i < count; ++i)
257 isLoadedMag |= ( mag == weapon.GetMagazine( i ) );
258
259 return !isLoadedMag;
260 }
261
263 {
264 AttachMagazineActionData action_data = new AttachMagazineActionData;
265 return action_data;
266 }
267
268
269 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
270 {
271 super.WriteToContext(ctx, action_data);
272
273 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
274
275 action_data_am.m_ilOldMagazine.WriteToContext(ctx);
276 }
277
278 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
279 {
280 if (!action_recive_data)
281 {
282 action_recive_data = new AttachMagazineActionReciveData;
283 }
284
285 super.ReadFromContext(ctx, action_recive_data);
286
288 if (!il.ReadFromContext(ctx))
289 return false;
290
291 AttachMagazineActionReciveData recive_data_am = AttachMagazineActionReciveData.Cast(action_recive_data);
292 recive_data_am.m_ilOldMagazine = il;
293
294 return true;
295 }
296
297 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
298 {
299 AttachMagazineActionReciveData recive_data_am = AttachMagazineActionReciveData.Cast(action_recive_data);
300 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
301
302 action_data.m_MainItem = action_recive_data.m_MainItem;
303 if (!action_recive_data.m_Target)
304 {
305 action_data.m_Target = new ActionTarget(NULL, NULL, -1, vector.Zero, 0);
306 }
307 else
308 {
309 action_data.m_Target = action_recive_data.m_Target;
310 }
311 action_data_am.m_ilOldMagazine = recive_data_am.m_ilOldMagazine;
312 }
313
314 override bool Post_SetupAction( ActionData action_data )
315 {
316 if ( !g_Game.IsDedicatedServer() )
317 {
318 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
319 int muzzle_index = wpn.GetCurrentMuzzle();
320
321 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
322 am_action_data.m_oldMagazine = wpn.GetMagazine(muzzle_index);
323
324 ActionTarget newTarget = new ActionTarget(action_data.m_Player.GetWeaponManager().GetPreparedMagazine(), null, -1, vector.Zero, -1);
325 action_data.m_Target = newTarget;
326
328
329 if (!action_data.m_Player.GetWeaponManager().PrepareInventoryLocationForMagazineSwap(wpn, Magazine.Cast(action_data.m_Target.GetObject()), new_il))
330 {
331 return false;
332 }
333 am_action_data.m_ilOldMagazine = new_il;
334 }
335 return true;
336 }
337
338 override bool InventoryReservation( ActionData action_data)
339 {
340 if (g_Game.IsServer())
341 return true;
342
343 if( (IsLocal() || !UseAcknowledgment()) && IsInstant() )
344 return true;
345
346 bool success = true;
347 InventoryLocation oldMagTargetInventoryLocation = NULL;
348 InventoryLocation targetInventoryLocation = NULL;
349 InventoryLocation handInventoryLocation = NULL;
350
351 PlayerBase player = action_data.m_Player;
352 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
353
354 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
355 int muzzle_index = wpn.GetCurrentMuzzle();
356
357 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
358
359 if (am_action_data.m_oldMagazine)
360 {
361 oldMagTargetInventoryLocation = new InventoryLocation;
362 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
363 {
364 success = false;
365 }
366 else
367 {
368 player.GetInventory().AddInventoryReservationEx(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine,GameInventory.c_InventoryReservationTimeoutMS);
369 }
370 }
371
372 if (success)
373 {
374 targetInventoryLocation = new InventoryLocation;
375 targetInventoryLocation.SetAttachment( wpn, new_mag, InventorySlots.MAGAZINE);
376 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
377 {
378 success = false;
379 if (am_action_data.m_oldMagazine)
380 {
381 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
382 }
383 }
384 else
385 {
386 action_data.m_Player.GetInventory().AddInventoryReservationEx( new_mag, targetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
387 }
388 }
389
390 if (success)
391 {
392 handInventoryLocation = new InventoryLocation;
393 handInventoryLocation.SetHands(action_data.m_Player, wpn);
394
395 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
396 {
397 if (am_action_data.m_oldMagazine)
398 {
399 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
400 }
401 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
402 success = false;
403 }
404 else
405 {
406 action_data.m_Player.GetInventory().AddInventoryReservationEx( wpn, handInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
407 }
408 }
409
410 if ( success )
411 {
412 if (am_action_data.m_ilOldMagazine)
413 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
414
415 if (targetInventoryLocation)
416 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
417
418 if (handInventoryLocation)
419 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
420 }
421
422 return success;
423 }
424
425 override void Start( ActionData action_data )
426 {
427 super.Start( action_data );
428 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
429 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
430 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
431 ClearInventoryReservationEx(action_data);
432 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,false) )
433 action_data.m_Player.GetWeaponManager().AttachMagazine(mag, this);
434 else
435 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine, this);
436 InventoryReservation(action_data);
437 }
438
439 override bool HasTarget()
440 {
441 return true;
442 }
443
444 override bool HasProgress()
445 {
446 return false;
447 }
448
449 override typename GetInputType()
450 {
452 }
453
455 {
458 }
459};
const int AC_SINGLE_USE
ActionBase ActionData
Определения ActionBase.c:30
class ActionTargets ActionTarget
DayZGame g_Game
Определения DayZGame.c:3942
Magazine m_oldMagazine
Определения FirearmActionAttachMagazine.c:8
AttachMagazineActionReciveData m_ilOldMagazine
string m_Text
Определения ActionBase.c:64
bool UseAcknowledgment()
Определения ActionBase.c:1146
ref CCIBase m_ConditionItem
Определения ActionBase.c:70
bool IsInstant()
Определения ActionBase.c:268
void ClearInventoryReservationEx(ActionData action_data)
Определения ActionBase.c:1040
ref CCTBase m_ConditionTarget
Определения ActionBase.c:71
bool IsLocal()
Определения ActionBase.c:262
ref InventoryLocation m_ilOldMagazine
Определения FirearmActionAttachMagazine.c:3
Определения CCINonRuined.c:2
Определения CCTSelf.c:2
override bool CanBePerformedFromInventory()
Определения FirearmActionAttachMagazine.c:213
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
Определения FirearmActionAttachMagazine.c:58
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
Определения FirearmActionAttachMagazine.c:49
override bool InventoryReservation(ActionData action_data)
Определения FirearmActionAttachMagazine.c:115
override bool ActionConditionContinue(ActionData action_data)
Определения FirearmActionAttachMagazine.c:37
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения FirearmActionAttachMagazine.c:26
override int GetActionCategory()
Определения FirearmActionAttachMagazine.c:21
override void Start(ActionData action_data)
Определения FirearmActionAttachMagazine.c:199
override bool CanBePerformedFromQuickbar()
Определения FirearmActionAttachMagazine.c:218
override bool Post_SetupAction(ActionData action_data)
Определения FirearmActionAttachMagazine.c:94
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Определения FirearmActionAttachMagazine.c:77
override ActionData CreateActionData()
Определения FirearmActionAttachMagazine.c:42
override void Start(ActionData action_data)
Определения FirearmActionAttachMagazine.c:425
override void CreateConditionComponents()
Определения FirearmActionAttachMagazine.c:454
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Определения FirearmActionAttachMagazine.c:297
override bool Post_SetupAction(ActionData action_data)
Определения FirearmActionAttachMagazine.c:314
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения FirearmActionAttachMagazine.c:231
override ActionData CreateActionData()
Определения FirearmActionAttachMagazine.c:262
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
Определения FirearmActionAttachMagazine.c:269
override bool InventoryReservation(ActionData action_data)
Определения FirearmActionAttachMagazine.c:338
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
Определения FirearmActionAttachMagazine.c:278
void FirearmActionBase()
const int c_InventoryReservationTimeoutMS
reservations
script counterpart to engine's class Inventory
proto native int GetRunningAction()
returns -1 when no action is running or RELOAD,MECHANISM, ....
Определения human.c:1000
proto native void SetHands(notnull EntityAI parent, EntityAI e)
sets current inventory location type to Hands
proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId)
sets current inventory location type to Attachment with slot id set to <slotId>
bool ReadFromContext(ParamsReadContext ctx)
Определения InventoryLocation.c:310
InventoryLocation.
Определения InventoryLocation.c:30
provides access to slot configuration
Определения InventorySlots.c:6
Определения PlayerBaseClient.c:2
shorthand
Определения BoltActionRifle_Base.c:6
script counterpart to engine's class Weapon
static const vector Zero
Определения EnConvert.c:123
Определения EnConvert.c:119
Serializer ParamsReadContext
Определения gameplay.c:15
Serializer ParamsWriteContext
Определения gameplay.c:16
WeaponActions
actions
Определения human.c:816