DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Magazine.c
См. документацию.
1typedef Magazine Magazine_Base;
2
4{
5 None = 0,
6 Pistol = 1,
9 Shell = 4,
11}
12
13enum ProjectileType
14{
15 None = 0,
16 Tracer = 1,
17 AP = 2
18}
19
20
21class AmmoData
22{
23 bool m_IsValid;
24 CartridgeType m_CartridgeType;
25 ProjectileType m_ProjectileType;
26
27 void AmmoData( string init_type )
28 {
29 m_IsValid = g_Game.ConfigIsExisting( "CfgMagazines " + init_type );
30 if ( m_IsValid )
31 {
32 m_CartridgeType = g_Game.ConfigGetInt( "CfgMagazines " + init_type + " iconCartridge" );
33 m_ProjectileType = g_Game.ConfigGetInt( "CfgMagazines " + init_type + " iconType" );
34 }
35 }
36}
37
38class Magazine : InventoryItemSuper
39{
40 protected static ref map<string, ref AmmoData> m_AmmoData;
41 ref array<string> m_CompatiableAmmo;
42 ref array<float> m_ChanceToJam;
43 protected float m_ManipulationDamage;
44
45 void Magazine ()
46 {
47 m_ChanceToJam = new array<float>;
48 InitReliability(m_ChanceToJam);
49 m_ManipulationDamage = ConfigGetFloat("manipulationDamage");
50 m_CompatiableAmmo = new array<string>;
51 ConfigGetTextArray("ammoItems", m_CompatiableAmmo);
52 if ( !g_Game.IsDedicatedServer() )
53 {
54 if ( !m_AmmoData )
55 m_AmmoData = new map<string, ref AmmoData>;
56
57 string classname = ClassName();
58 if ( !m_AmmoData.Contains(classname) )
59 {
60 ref AmmoData new_data = new AmmoData( classname );
61 if ( new_data.m_IsValid )
62 m_AmmoData.Insert( classname, new AmmoData( classname ) );
63 }
64 }
65 }
66
68 proto native int GetAmmoCount();
70 proto native void ServerSetAmmoCount(int ammoCount);
71 proto native void LocalSetAmmoCount(int ammoCount);
72
79 proto bool LocalAcquireCartridge(out float dmg, out string cartTypeName);
80 proto bool ServerAcquireCartridge(out float dmg, out string cartTypeName);
87 proto native bool LocalStoreCartridge(float ammoDamage, string cartTypeName);
88 proto native bool ServerStoreCartridge(float ammoDamage, string cartTypeName);
89
97 proto bool GetCartridgeAtIndex(int cartIndex, out float dmg, out string cartTypeName);
98
106 proto bool SetCartridgeAtIndex(int cartIndex, out float dmg, out string cartTypeName);
107
114 proto bool SetCartridgeDamageAtIndex(int cartIndex, float dmg);
115
116
117 static AmmoData GetAmmoData( string classname )
118 {
119 if ( !m_AmmoData )
120 m_AmmoData = new map<string, ref AmmoData>;
121 if ( !m_AmmoData.Contains(classname) )
122 {
123 ref AmmoData new_data = new AmmoData( classname );
124 if ( new_data.m_IsValid )
125 m_AmmoData.Insert( classname, new AmmoData( classname ) );
126 return new_data;
127 }
128 else
129 {
130 return m_AmmoData.Get( classname );
131 }
132 }
133
134 protected void UpdateAnimation();
135
136 bool IsCompatiableAmmo( ItemBase ammo )
137 {
138 if ( m_CompatiableAmmo && ammo )
139 return ( m_CompatiableAmmo.Find( ammo.GetType() ) > -1 );
140 else
141 return false;
142 }
143
144 bool CanAddCartridges(int count)
145 {
146 int spc_avail = GetAmmoMax() - GetAmmoCount();
147 return count <= spc_avail;
148 }
149
151 void ServerAddAmmoCount(int ammoCount)
152 {
153 ServerSetAmmoCount(GetAmmoCount() + ammoCount);
154 }
155 void LocalAddAmmoCount(int ammoCount)
156 {
157 LocalSetAmmoCount(GetAmmoCount() + ammoCount);
158 }
160 int GetAmmoMax()
161 {
162 return ItemBaseType.Cast(GetEntityType()).m_Count;
163 }
165 void ServerSetAmmoMax()
166 {
167 ServerSetAmmoCount( GetAmmoMax() );
168 }
169 void LocalSetAmmoMax()
170 {
171 LocalSetAmmoCount( GetAmmoMax() );
172 }
174 override bool IsMagazine()
175 {
176 return true;
177 }
178
180 bool LocalAcquireCartridgeEx(out float ammoDamage, out string cartTypeName)
181 {
182 bool changeAmmoCount = LocalAcquireCartridge(ammoDamage, cartTypeName);
183 UpdateAnimation();
184 return changeAmmoCount;
185 }
186
188 bool ServerAcquireCartridgeEx(out float ammoDamage, out string cartTypeName)
189 {
190 bool changeAmmoCount = ServerAcquireCartridge(ammoDamage, cartTypeName);
191 UpdateAnimation();
192 return changeAmmoCount;
193 }
194
196 bool ServerStoreCartridgeEx(float ammoDamage, string cartTypeName)
197 { bool changeAmmoCount = ServerStoreCartridge(ammoDamage, cartTypeName);
198 UpdateAnimation();
199 return changeAmmoCount;
200 }
201
202
203 override bool CanBeSplit()
204 {
205 if ( m_CanThisBeSplit )
206 return ( GetAmmoCount() > 1 );
207
208 return false;
209 }
210
211 bool InitReliability(out array<float> reliability_array)
212 {
213 if (g_Game.ConfigIsExisting("cfgMagazines " + GetType() + " Reliability ChanceToJam"))
214 {
215 g_Game.ConfigGetFloatArray("cfgMagazines " + GetType() + " Reliability ChanceToJam",reliability_array);
216 return true;
217 }
218 return false;
219 }
220
221 float GetChanceToJam()
222 {
223 int level = GetHealthLevel();
224
225 if (level >= 0 && level < m_ChanceToJam.Count())
226 return m_ChanceToJam[level];
227 else
228 return 0.0;
229 }
230
231 override void SplitItemToInventoryLocation( notnull InventoryLocation dst )
232 {
233 if ( !CanBeSplit() )
234 return;
235
236 Magazine new_pile = Magazine.Cast( GameInventory.LocationCreateEntity( dst, GetType(), ECE_IN_INVENTORY, RF_DEFAULT ) );
237 if( new_pile )
238 {
239 MiscGameplayFunctions.TransferItemProperties(dst.GetItem(), new_pile);
240
241 new_pile.ServerSetAmmoCount(0);
242 int quantity = GetAmmoCount();
243
244 for (int i = 0; i < Math.Floor( quantity * 0.5 ); ++i)
245 {
246 float damage;
247 string cartrige_name;
248 ServerAcquireCartridge(damage, cartrige_name);
249 new_pile.ServerStoreCartridge(damage, cartrige_name);
250 }
251 new_pile.SetSynchDirty();
252 SetSynchDirty();
253 }
254 }
255
256 override void SplitItem(PlayerBase player)
257 {
258 if ( !CanBeSplit() )
259 return;
260
261
262 Magazine new_pile = Magazine.Cast( player.CreateCopyOfItemInInventoryOrGround( this ) );
263 if( new_pile )
264 {
265 new_pile.ServerSetAmmoCount(0);
266 int quantity = this.GetAmmoCount();
267
268 for (int i = 0; i < Math.Floor( quantity / 2 ); i++)
269 {
270 float damage;
271 string cartrige_name;
272 ServerAcquireCartridge(damage, cartrige_name);
273 new_pile.ServerStoreCartridge(damage, cartrige_name);
274 }
275 new_pile.SetSynchDirty();
276 SetSynchDirty();
277 }
278 }
279
280 void ApplyManipulationDamage()
281 {
282 AddHealth("","Health",-m_ManipulationDamage);
283 }
284
285 override bool IsFullQuantity()
286 {
287 if ( GetAmmoCount() == GetAmmoMax() )
288 {
289 return true;
290 }
291 else
292 {
293 return false;
294 }
295 }
296
297 override protected float GetWeightSpecialized(bool forceRecalc = false)
298 {
299 #ifdef DEVELOPER
300 if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
301 {
302 WeightDebugData data = WeightDebug.GetWeightDebug(this);
303 data.SetCalcDetails("TMAG: ("+GetAmmoCount()+"(Ammo count) * " + ConfigGetFloat("weightPerQuantityUnit")+"(weightPerQuantityUnit)) + " + GetConfigWeightModifiedDebugText());
304 }
305 #endif
306 return GetConfigWeightModified() + (GetAmmoCount() * ConfigGetFloat("weightPerQuantityUnit"));
307 }
308
309 override bool IsCombineAll( ItemBase other_item, bool use_stack_max = false)
310 {
311 Magazine other_magazine = Magazine.Cast(other_item);
312 int free_space = GetAmmoMax() - GetAmmoCount();
313
314 return free_space >= other_magazine.GetAmmoCount();
315 }
316
317 override void CombineItems( ItemBase other_item, bool use_stack_max = false )
318 {
319 if ( !CanBeCombined(other_item) )
320 return;
321
322 if ( other_item.GetType() != GetType() )
323 return;
324
325 Magazine other_magazine;
326 if ( Class.CastTo(other_magazine, other_item) )
327 {
328 //int other_item_quantity = other_magazine.GetAmmoCount();
329 int this_free_space = GetAmmoMax() - GetAmmoCount();
330 int numberOfTransferredBullets = 0;
331 int currentAmount = GetAmmoCount();
332
333 for (int i = 0; i < this_free_space && other_magazine.GetAmmoCount() > 0 ; i++)
334 {
335 float damage;
336 string cartrige_name;
337 other_magazine.ServerAcquireCartridge(damage, cartrige_name);
338 if (ServerStoreCartridge(damage, cartrige_name))
339 ++numberOfTransferredBullets;
340 }
341
342 if (g_Game.IsServer())
343 {
344 float resultingHealth = (currentAmount * GetHealth() + numberOfTransferredBullets * other_magazine.GetHealth()) / GetAmmoCount();
345 SetHealth("", "", resultingHealth);
346 }
347 OnCombine(other_item);
348 other_magazine.SetSynchDirty();
349 SetSynchDirty();
350 }
351 }
352
353 override bool CanDetachAttachment(EntityAI parent)
354 {
355 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
356 if (player)
357 {
358 Weapon_Base wpn = Weapon_Base.Cast(parent);
359 if (wpn)
360 {
361 return player.GetWeaponManager().CanDetachMagazine(wpn,this);
362 }
363 }
364 return super.CanDetachAttachment(parent);
365 }
366
367 override void OnInventoryEnter(Man player)
368 {
369 super.OnInventoryEnter(player);
370
371 PlayerBase p = PlayerBase.Cast(player);
372 p.GetWeaponManager().OnMagazineInventoryEnter(this);
373 }
374
375 override void OnInventoryExit(Man player)
376 {
377 super.OnInventoryExit(player);
378
379 PlayerBase p = PlayerBase.Cast(player);
380 p.GetWeaponManager().OnMagazineInventoryExit(this);
381 }
382
383 override void OnWasAttached( EntityAI parent, int slot_id )
384 {
385 super.OnWasAttached(parent, slot_id);
386
387 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
388 Weapon_Base wpn = Weapon_Base.Cast(parent);
389 if (wpn && player)
390 {
391 player.GetWeaponManager().OnMagazineAttach(this);
392 }
393 }
394
395 override void OnWasDetached( EntityAI parent, int slot_id )
396 {
397 super.OnWasDetached(parent, slot_id);
398
399 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
400 Weapon_Base wpn = Weapon_Base.Cast(parent);
401
402 if (wpn && player)
403 {
404 player.GetWeaponManager().OnMagazineDetach(this);
405 }
406 }
407
408 override void EEHealthLevelChanged( int oldLevel, int newLevel, string zone )
409 {
410 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
411 float damage = 1 - GetHealthLevelValue(newLevel) + 0.001;
412
413 int cartridgeCount = GetAmmoCount();
414 for (int i = 0; i < cartridgeCount; ++i)
415 SetCartridgeDamageAtIndex(i, damage);
416 }
417
418 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
419 {
420 if (GetAmmoCount() > 0)
421 {
422 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.LIGHT_GREY));
423 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.PRINT_BULLETS, "Print Bullets", FadeColors.LIGHT_GREY));
424 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
425 }
426
427 super.GetDebugActions(outputList);
428 }
429
430 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
431 {
432 if (g_Game.IsServer())
433 {
434 if (action_id == EActions.PRINT_BULLETS)
435 {
436 Magazine magazine;
437 Class.CastTo(magazine, this);
438 for (int i = 0; i < magazine.GetAmmoCount(); i++)
439 {
440 float damage;
441 string className;
442 magazine.GetCartridgeAtIndex(i, damage, className);
443 Debug.Log(string.Format("Bullet: %1, Damage %2", className, damage));
444 }
445 }
446 }
447
448 return super.OnAction(action_id, player, ctx);
449 }
450
451 override bool CanBeFSwaped()
452 {
453 Weapon_Base wpn = Weapon_Base.Cast(GetHierarchyParent());
454 if (wpn)
455 {
456 return false;
457 }
458
459 return true;
460 }
461}
462
463class MagazineStorage : Magazine
464{
465 override void SetActions()
466 {
467 super.SetActions();
468 AddAction(ActionLoadMagazine);
469 AddAction(ActionEmptyMagazine);
470 AddAction(ActionLoadMagazineQuick);
471 }
472}
Param4< int, int, string, int > TSelectableActionInfoWithColor
class LogManager EntityAI
eBleedingSourceType GetType()
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
override bool CanDetachAttachment(EntityAI parent)
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
string Debug()
Определения CachedEquipmentStorageBase.c:26
bool m_IsValid
Определения CatchingContextBase.c:17
const int ECE_IN_INVENTORY
Определения CentralEconomy.c:37
const int RF_DEFAULT
Определения CentralEconomy.c:66
map
Определения ControlsXboxNew.c:4
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Определения DayZAnimal.c:136
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Определения DayZAnimal.c:125
DayZGame g_Game
Определения DayZGame.c:4074
EActions
Определения EActions.c:2
class GP5GasMask extends MaskBase ItemBase
void OnCombine(ItemBase other_item)
Определения ItemBase.c:2269
bool IsFullQuantity()
Определения ItemBase.c:3491
override bool CanBeSplit()
Определения ItemBase.c:1533
void SplitItemToInventoryLocation(notnull InventoryLocation dst)
Определения ItemBase.c:1917
bool IsCombineAll(ItemBase other_item, bool use_stack_max=false)
Определения ItemBase.c:2199
void CombineItems(ItemBase other_item, bool use_stack_max=true)
Определения ItemBase.c:2243
void OnInventoryEnter(Man player)
Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter.
Определения ItemBase.c:3902
float GetWeightSpecialized(bool forceRecalc=false)
Определения ItemBase.c:3511
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Определения ItemBase.c:2137
override void OnWasAttached(EntityAI parent, int slot_id)
Определения ItemBase.c:1326
bool m_CanThisBeSplit
Определения ItemBase.c:63
void SplitItem(PlayerBase player)
Определения ItemBase.c:1953
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
Определения ItemBase.c:3914
Magazine Magazine_Base
Определения Magazine.c:1
CartridgeType
Определения Magazine.c:4
@ Pistol
Определения Magazine.c:6
@ Shell
Определения Magazine.c:9
@ Arrow
Определения Magazine.c:10
@ FullPower
Определения Magazine.c:8
@ Intermediate
Определения Magazine.c:7
enum CartridgeType Tracer
override void OnWasDetached(EntityAI parent, int slot_id)
overrides the base behavior - intentional
Определения RemoteDetonator.c:237
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Определения Magnum.c:252
void SetCalcDetails(string details)
Определения 3_Game/DayZ/tools/Debug.c:934
Keffiyeh_LightBlue SetActions
Определения consumables.c:149
Serializer ParamsReadContext
Определения gameplay.c:15
@ None
Определения EnWorld.c:73
const int SAT_DEBUG_ACTION
Определения 3_Game/DayZ/constants.c:486