DayZ 1.27
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 = GetGame().ConfigIsExisting( "CfgMagazines " + init_type );
30 if ( m_IsValid )
31 {
32 m_CartridgeType = GetGame().ConfigGetInt( "CfgMagazines " + init_type + " iconCartridge" );
33 m_ProjectileType = GetGame().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 ( !GetGame().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 bool IsCompatiableAmmo( ItemBase ammo )
135 {
136 if ( m_CompatiableAmmo && ammo )
137 return ( m_CompatiableAmmo.Find( ammo.GetType() ) > -1 );
138 else
139 return false;
140 }
141
142 bool CanAddCartridges(int count)
143 {
144 int spc_avail = GetAmmoMax() - GetAmmoCount();
145 return count <= spc_avail;
146 }
147
149 void ServerAddAmmoCount(int ammoCount)
150 {
151 ServerSetAmmoCount(GetAmmoCount() + ammoCount);
152 }
153 void LocalAddAmmoCount(int ammoCount)
154 {
155 LocalSetAmmoCount(GetAmmoCount() + ammoCount);
156 }
158 int GetAmmoMax()
159 {
160 return m_Count;
161 }
163 void ServerSetAmmoMax()
164 {
165 ServerSetAmmoCount( GetAmmoMax() );
166 }
167 void LocalSetAmmoMax()
168 {
169 LocalSetAmmoCount( GetAmmoMax() );
170 }
172 override bool IsMagazine()
173 {
174 return true;
175 }
176
177
178 override bool CanBeSplit()
179 {
180 if ( m_CanThisBeSplit )
181 return ( GetAmmoCount() > 1 );
182
183 return false;
184 }
185
186 bool InitReliability(out array<float> reliability_array)
187 {
188 if (GetGame().ConfigIsExisting("cfgMagazines " + GetType() + " Reliability ChanceToJam"))
189 {
190 GetGame().ConfigGetFloatArray("cfgMagazines " + GetType() + " Reliability ChanceToJam",reliability_array);
191 return true;
192 }
193 return false;
194 }
195
196 float GetChanceToJam()
197 {
198 int level = GetHealthLevel();
199
200 if (level >= 0 && level < m_ChanceToJam.Count())
201 return m_ChanceToJam[level];
202 else
203 return 0.0;
204 }
205
206 override void SplitItemToInventoryLocation( notnull InventoryLocation dst )
207 {
208 if ( !CanBeSplit() )
209 return;
210
211 Magazine new_pile = Magazine.Cast( GameInventory.LocationCreateEntity( dst, GetType(), ECE_IN_INVENTORY, RF_DEFAULT ) );
212 if( new_pile )
213 {
214 MiscGameplayFunctions.TransferItemProperties(dst.GetItem(), new_pile);
215
216 new_pile.ServerSetAmmoCount(0);
217 int quantity = GetAmmoCount();
218
219 for (int i = 0; i < Math.Floor( quantity * 0.5 ); ++i)
220 {
221 float damage;
222 string cartrige_name;
223 ServerAcquireCartridge(damage, cartrige_name);
224 new_pile.ServerStoreCartridge(damage, cartrige_name);
225 }
226 new_pile.SetSynchDirty();
227 SetSynchDirty();
228 }
229 }
230
231 override void SplitItem(PlayerBase player)
232 {
233 if ( !CanBeSplit() )
234 return;
235
236
237 Magazine new_pile = Magazine.Cast( player.CreateCopyOfItemInInventoryOrGround( this ) );
238 if( new_pile )
239 {
240 new_pile.ServerSetAmmoCount(0);
241 int quantity = this.GetAmmoCount();
242
243 for (int i = 0; i < Math.Floor( quantity / 2 ); i++)
244 {
245 float damage;
246 string cartrige_name;
247 ServerAcquireCartridge(damage, cartrige_name);
248 new_pile.ServerStoreCartridge(damage, cartrige_name);
249 }
250 new_pile.SetSynchDirty();
251 SetSynchDirty();
252 }
253 }
254
255 void ApplyManipulationDamage()
256 {
257 AddHealth("","Health",-m_ManipulationDamage);
258 }
259
260 override bool IsFullQuantity()
261 {
262 if ( GetAmmoCount() == GetAmmoMax() )
263 {
264 return true;
265 }
266 else
267 {
268 return false;
269 }
270 }
271
272 override protected float GetWeightSpecialized(bool forceRecalc = false)
273 {
274 #ifdef DEVELOPER
275 if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
276 {
277 WeightDebugData data = WeightDebug.GetWeightDebug(this);
278 data.SetCalcDetails("TMAG: ("+GetAmmoCount()+"(Ammo count) * " + ConfigGetFloat("weightPerQuantityUnit")+"(weightPerQuantityUnit)) + " + GetConfigWeightModifiedDebugText());
279 }
280 #endif
281 return GetConfigWeightModified() + (GetAmmoCount() * ConfigGetFloat("weightPerQuantityUnit"));
282 }
283
284 override bool IsCombineAll( ItemBase other_item, bool use_stack_max = false)
285 {
286 Magazine other_magazine = Magazine.Cast(other_item);
287 int free_space = GetAmmoMax() - GetAmmoCount();
288
289 return free_space >= other_magazine.GetAmmoCount();
290 }
291
292 override void CombineItems( ItemBase other_item, bool use_stack_max = false )
293 {
294 if ( !CanBeCombined(other_item) )
295 return;
296
297 if ( other_item.GetType() != GetType() )
298 return;
299
300 Magazine other_magazine;
301 if ( Class.CastTo(other_magazine, other_item) )
302 {
303 //int other_item_quantity = other_magazine.GetAmmoCount();
304 int this_free_space = GetAmmoMax() - GetAmmoCount();
305 int numberOfTransferredBullets = 0;
306 int currentAmount = GetAmmoCount();
307
308 for (int i = 0; i < this_free_space && other_magazine.GetAmmoCount() > 0 ; i++)
309 {
310 float damage;
311 string cartrige_name;
312 other_magazine.ServerAcquireCartridge(damage, cartrige_name);
313 if (ServerStoreCartridge(damage, cartrige_name))
314 ++numberOfTransferredBullets;
315 }
316
317 if (GetGame().IsServer())
318 {
319 float resultingHealth = (currentAmount * GetHealth() + numberOfTransferredBullets * other_magazine.GetHealth()) / GetAmmoCount();
320 SetHealth("", "", resultingHealth);
321 }
322 OnCombine(other_item);
323 other_magazine.SetSynchDirty();
324 SetSynchDirty();
325 }
326 }
327
328 override bool CanDetachAttachment(EntityAI parent)
329 {
330 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
331 if (player)
332 {
333 Weapon_Base wpn = Weapon_Base.Cast(parent);
334 if (wpn)
335 {
336 return player.GetWeaponManager().CanDetachMagazine(wpn,this);
337 }
338 }
339 return super.CanDetachAttachment(parent);
340 }
341
342 override void OnInventoryEnter(Man player)
343 {
344 super.OnInventoryEnter(player);
345
346 PlayerBase p = PlayerBase.Cast(player);
347 p.GetWeaponManager().OnMagazineInventoryEnter(this);
348 }
349
350 override void OnInventoryExit(Man player)
351 {
352 super.OnInventoryExit(player);
353
354 PlayerBase p = PlayerBase.Cast(player);
355 p.GetWeaponManager().OnMagazineInventoryExit(this);
356 }
357
358 override void OnWasAttached( EntityAI parent, int slot_id )
359 {
360 super.OnWasAttached(parent, slot_id);
361
362 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
363 Weapon_Base wpn = Weapon_Base.Cast(parent);
364 if (wpn && player)
365 {
366 player.GetWeaponManager().OnMagazineAttach(this);
367 }
368 }
369
370 override void OnWasDetached( EntityAI parent, int slot_id )
371 {
372 super.OnWasDetached(parent, slot_id);
373
374 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
375 Weapon_Base wpn = Weapon_Base.Cast(parent);
376
377 if (wpn && player)
378 {
379 player.GetWeaponManager().OnMagazineDetach(this);
380 }
381 }
382
383 override void EEHealthLevelChanged( int oldLevel, int newLevel, string zone )
384 {
385 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
386 float damage = 1 - GetHealthLevelValue(newLevel) + 0.001;
387
388 int cartridgeCount = GetAmmoCount();
389 for (int i = 0; i < cartridgeCount; ++i)
390 SetCartridgeDamageAtIndex(i, damage);
391 }
392
393 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
394 {
395 super.GetDebugActions(outputList);
396
397 if (GetAmmoCount() > 0)
398 {
399 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.LIGHT_GREY));
400 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.PRINT_BULLETS, "Print Bullets", FadeColors.LIGHT_GREY));
401 }
402 }
403
404 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
405 {
406 if (GetGame().IsServer())
407 {
408 if (action_id == EActions.PRINT_BULLETS)
409 {
410 Magazine magazine;
411 Class.CastTo(magazine, this);
412 for (int i = 0; i < magazine.GetAmmoCount(); i++)
413 {
414 float damage;
415 string className;
416 magazine.GetCartridgeAtIndex(i, damage, className);
417 Debug.Log(string.Format("Bullet: %1, Damage %2", className, damage));
418 }
419 }
420 }
421
422 return super.OnAction(action_id, player, ctx);
423 }
424
425 override bool CanBeFSwaped()
426 {
427 Weapon_Base wpn = Weapon_Base.Cast(GetHierarchyParent());
428 if (wpn)
429 {
430 return false;
431 }
432
433 return true;
434 }
435}
436
437class MagazineStorage : Magazine
438{
439 override void SetActions()
440 {
441 super.SetActions();
442 AddAction(ActionLoadMagazine);
443 AddAction(ActionEmptyMagazine);
444 AddAction(ActionLoadMagazineQuick);
445 }
446}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Определения EntityAI.c:97
class LogManager EntityAI
eBleedingSourceType GetType()
Определения BleedingSource.c:63
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
void SetActions()
Определения AdvancedCommunication.c:213
bool m_IsValid
Определения CatchingContextBase.c:17
const int ECE_IN_INVENTORY
Определения CentralEconomy.c:36
const int RF_DEFAULT
Определения CentralEconomy.c:65
map
Определения ControlsXboxNew.c:4
EActions
Определения EActions.c:2
class GP5GasMask extends MaskBase ItemBase
void SplitItem(PlayerBase player)
Определения ItemBase.c:6739
void SplitItemToInventoryLocation(notnull InventoryLocation dst)
Определения ItemBase.c:6706
float GetWeightSpecialized(bool forceRecalc=false)
Определения ItemBase.c:8179
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Определения ItemBase.c:7114
void CombineItems(ItemBase other_item, bool use_stack_max=true)
Определения ItemBase.c:7016
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:8566
void OnCombine(ItemBase other_item)
Определения ItemBase.c:7042
int m_Count
Определения ItemBase.c:4802
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Определения ItemBase.c:6910
override bool CanBeSplit()
Определения ItemBase.c:6348
bool IsCombineAll(ItemBase other_item, bool use_stack_max=false)
Определения ItemBase.c:6972
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:8579
bool IsFullQuantity()
Определения ItemBase.c:8159
bool m_CanThisBeSplit
Определения ItemBase.c:4837
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Определения ItemBase.c:7071
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Определения ItemBase.c:6808
override void OnWasAttached(EntityAI parent, int slot_id)
Определения ItemBase.c:6147
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)
Определения RemoteDetonator.c:237
void Debug()
Определения UniversalTemperatureSource.c:349
proto native bool ConfigIsExisting(string path)
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto native void ConfigGetFloatArray(string path, out TFloatArray values)
Get array of floats from config on path.
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Определения Magnum.c:247
override void SetActions()
Определения Magnum.c:58
void SetCalcDetails(string details)
Определения Debug.c:816
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
@ None
Определения EnWorld.c:73
const int SAT_DEBUG_ACTION
Определения constants.c:452