DayZ 1.30
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 if (!weapon.TestAttachMagazine(weapon.GetCurrentMuzzle(), mag, false, true))
257 return false;
258
259 for (int i = 0, count = weapon.GetMuzzleCount(); i < count; ++i)
260 isLoadedMag |= ( mag == weapon.GetMagazine( i ) );
261
262 return !isLoadedMag;
263 }
264
266 {
267 AttachMagazineActionData action_data = new AttachMagazineActionData;
268 return action_data;
269 }
270
271
272 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
273 {
274 super.WriteToContext(ctx, action_data);
275
276 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
277
278 action_data_am.m_ilOldMagazine.WriteToContext(ctx);
279 }
280
281 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
282 {
283 if (!action_recive_data)
284 {
285 action_recive_data = new AttachMagazineActionReciveData;
286 }
287
288 super.ReadFromContext(ctx, action_recive_data);
289
291 if (!il.ReadFromContext(ctx))
292 return false;
293
294 AttachMagazineActionReciveData recive_data_am = AttachMagazineActionReciveData.Cast(action_recive_data);
295 recive_data_am.m_ilOldMagazine = il;
296
297 return true;
298 }
299
300 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
301 {
302 AttachMagazineActionReciveData recive_data_am = AttachMagazineActionReciveData.Cast(action_recive_data);
303 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
304
305 action_data.m_MainItem = action_recive_data.m_MainItem;
306 if (!action_recive_data.m_Target)
307 {
308 action_data.m_Target = new ActionTarget(NULL, NULL, -1, vector.Zero, 0);
309 }
310 else
311 {
312 action_data.m_Target = action_recive_data.m_Target;
313 }
314 action_data_am.m_ilOldMagazine = recive_data_am.m_ilOldMagazine;
315 }
316
317 override bool Post_SetupAction( ActionData action_data )
318 {
319 if ( !g_Game.IsDedicatedServer() )
320 {
321 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
322 int muzzle_index = wpn.GetCurrentMuzzle();
323
324 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
325 am_action_data.m_oldMagazine = wpn.GetMagazine(muzzle_index);
326
327 ActionTarget newTarget = new ActionTarget(action_data.m_Player.GetWeaponManager().GetPreparedMagazine(), null, -1, vector.Zero, -1);
328 action_data.m_Target = newTarget;
329
331
332 if (!action_data.m_Player.GetWeaponManager().PrepareInventoryLocationForMagazineSwap(wpn, Magazine.Cast(action_data.m_Target.GetObject()), new_il))
333 {
334 return false;
335 }
336 am_action_data.m_ilOldMagazine = new_il;
337 }
338 return true;
339 }
340
341 override bool InventoryReservation( ActionData action_data)
342 {
343 if (g_Game.IsServer())
344 return true;
345
346 if( (IsLocal() || !UseAcknowledgment()) && IsInstant() )
347 return true;
348
349 bool success = true;
350 InventoryLocation oldMagTargetInventoryLocation = NULL;
351 InventoryLocation targetInventoryLocation = NULL;
352 InventoryLocation handInventoryLocation = NULL;
353
354 PlayerBase player = action_data.m_Player;
355 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
356
357 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
358 int muzzle_index = wpn.GetCurrentMuzzle();
359
360 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
361
362 if (am_action_data.m_oldMagazine)
363 {
364 oldMagTargetInventoryLocation = new InventoryLocation;
365 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
366 {
367 success = false;
368 }
369 else
370 {
371 player.GetInventory().AddInventoryReservationEx(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine,GameInventory.c_InventoryReservationTimeoutMS);
372 }
373 }
374
375 if (success)
376 {
377 targetInventoryLocation = new InventoryLocation;
378 targetInventoryLocation.SetAttachment( wpn, new_mag, InventorySlots.MAGAZINE);
379 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
380 {
381 success = false;
382 if (am_action_data.m_oldMagazine)
383 {
384 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
385 }
386 }
387 else
388 {
389 action_data.m_Player.GetInventory().AddInventoryReservationEx( new_mag, targetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
390 }
391 }
392
393 if (success)
394 {
395 handInventoryLocation = new InventoryLocation;
396 handInventoryLocation.SetHands(action_data.m_Player, wpn);
397
398 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
399 {
400 if (am_action_data.m_oldMagazine)
401 {
402 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
403 }
404 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
405 success = false;
406 }
407 else
408 {
409 action_data.m_Player.GetInventory().AddInventoryReservationEx( wpn, handInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
410 }
411 }
412
413 if ( success )
414 {
415 if (am_action_data.m_ilOldMagazine)
416 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
417
418 if (targetInventoryLocation)
419 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
420
421 if (handInventoryLocation)
422 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
423 }
424
425 return success;
426 }
427
428 override void Start( ActionData action_data )
429 {
430 super.Start( action_data );
431 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
432 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
433 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
434 ClearInventoryReservationEx(action_data);
435 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,false) )
436 action_data.m_Player.GetWeaponManager().AttachMagazine(mag, this);
437 else
438 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine, this);
439 InventoryReservation(action_data);
440 }
441
442 override bool HasTarget()
443 {
444 return true;
445 }
446
447 override bool HasProgress()
448 {
449 return false;
450 }
451
452 override typename GetInputType()
453 {
455 }
456
458 {
461 }
462};
const int AC_SINGLE_USE
string m_Text
Определения ActionBase.c:57
bool UseAcknowledgment()
Определения ActionBase.c:1255
ref CCIBase m_ConditionItem
Определения ActionBase.c:63
ref CCTBase m_ConditionTarget
Определения ActionBase.c:64
void ClearInventoryReservationEx(ActionData action_data)
Определения ActionBase.c:1120
bool IsLocal()
Определения ActionBase.c:271
bool IsInstant()
Определения ActionBase.c:294
void ActionTarget(Object object, Object parent, int componentIndex, vector cursorHitPos, float utility, string surfaceName="")
Определения ActionTargets.c:125
DayZGame g_Game
Определения DayZGame.c:4074
Magazine m_oldMagazine
Определения FirearmActionAttachMagazine.c:8
AttachMagazineActionReciveData m_ilOldMagazine
PlayerBase m_Player
Определения ActionBase.c:40
ref ActionTarget m_Target
Определения ActionBase.c:39
ref array< ref InventoryLocation > m_ReservedInventoryLocations
Определения ActionBase.c:42
ItemBase m_MainItem
Определения ActionBase.c:35
Определения ActionBase.c:22
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:428
override void CreateConditionComponents()
Определения FirearmActionAttachMagazine.c:457
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Определения FirearmActionAttachMagazine.c:300
override bool Post_SetupAction(ActionData action_data)
Определения FirearmActionAttachMagazine.c:317
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения FirearmActionAttachMagazine.c:231
override ActionData CreateActionData()
Определения FirearmActionAttachMagazine.c:265
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
Определения FirearmActionAttachMagazine.c:272
override bool InventoryReservation(ActionData action_data)
Определения FirearmActionAttachMagazine.c:341
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
Определения FirearmActionAttachMagazine.c:281
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:1027
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:843