Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionemptymagazine.c
Go to the documentation of this file.
2 {
3  Magazine m_magazinePile;
4 }
5 
6 class ActionEmptyMagazineCB : ActionContinuousBaseCB
7 {
8  override void CreateActionComponent()
9  {
10  m_ActionData.m_ActionComponent = new CAContinuousRepeat(UATimeSpent.MAG_EMPTY);
11  }
12 };
13 
15 {
16  void ActionEmptyMagazine()
17  {
18  m_CallbackClass = ActionEmptyMagazineCB;
19  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_EMPTYMAG;
20  m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_EMPTYMAG;
21  m_Text = "#empty_magazine";
22  }
23 
24  override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
25  {
26  if ( super.SetupAction( player, target, item, action_data, extra_data))
27  {
28  EmptyMagazineActionData emActionData = EmptyMagazineActionData.Cast(action_data);
29  emActionData.m_magazinePile = NULL;
30  return true;
31  }
32  return false;
33  }
34 
35  override ActionData CreateActionData()
36  {
38  return action_data;
39  }
40 
41  override void CreateConditionComponents()
42  {
45  }
46 
47  override bool HasProneException()
48  {
49  return true;
50  }
51 
52  bool CanEmpty(ItemBase item)
53  {
54  Magazine mag;
55  return ( item && Class.CastTo(mag, item) && mag.GetAmmoCount() > 0 );
56  }
57 
58  override bool ActionConditionContinue( ActionData action_data )
59  {
60  return CanEmpty(action_data.m_MainItem);
61  }
62 
63  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
64  {
65  Magazine itm;
66  return CanEmpty(item);
67  }
68 
69  override bool HasTarget()
70  {
71  return false;
72  }
73 
74  override void OnExecuteServer( ActionData action_data )
75  {
76  EmptyMagazineActionData emActionData = EmptyMagazineActionData.Cast(action_data);
77 
78  Magazine mag;
79  if (!Class.CastTo(mag, action_data.m_MainItem))
80  return;
81 
82  //float dmg;
83  //string bulletType;
84 
85  /*int ammoCount = mag.GetAmmoCount();
86  if(GetAmmoCount() > 0)
87  {
88  mag.Get
89  mag.SetAmmoCount( ammoCount - 1 );
90  array< Magazine > piles;
91 
92  if( !callback.m_magazinePile )
93  {
94  piles = MiscGameplayFunctions.CreateMagazinePilesFromBullet(bulletType, action_data.m_Player.GetPosition(),1,dmg);
95  if( piles.Count() > 0 )
96  callback.m_magazinePile = piles.Get(0);
97  }
98  else
99  {
100  if( callback.m_magazinePile.GetAmmoMax() > callback.m_magazinePile.GetAmmoCount() && (vector.Distance(action_data.m_Player.GetPosition(), callback.m_magazinePile.GetPosition()) < MAX_GROUND_PILE_DISTANCE ) )
101  {
102  callback.m_magazinePile.StoreCartridge(dmg, bulletType);
103  }
104  else
105  {
106  piles = MiscGameplayFunctions.CreateMagazinePilesFromBullet(bulletType, action_data.m_Player.GetPosition(),1,dmg);
107  if( piles.Count() > 0 )
108  callback.m_magazinePile = piles.Get(0);
109  }
110  }
111 
112 
113 
114  } */
115 
116 
117 
118  //----Uncomment after AcquireCartridge will work
119 
120  float dmg;
121  string ammoType;
122 
123  if ( !mag.ServerAcquireCartridge(dmg,ammoType) )
124  return;
125 
126  mag.ApplyManipulationDamage();
127 
128  string magazineTypeName;
129  GetGame().ConfigGetText( "CfgAmmo " + ammoType + " spawnPileType" , magazineTypeName);
130 
131  if ( !DayZPlayerUtils.HandleStoreCartridge(action_data.m_Player, NULL, -1, dmg, ammoType, magazineTypeName, false) )
132  {
133  array< Magazine > piles;
134 
135  if ( !emActionData.m_magazinePile )
136  {
137  piles = MiscGameplayFunctions.CreateMagazinePilesFromBullet(ammoType,action_data.m_Player.GetPosition(),1,dmg);
138  if ( piles.Count() > 0 )
139  emActionData.m_magazinePile = piles.Get(0);
140  }
141  else
142  {
143  if ( emActionData.m_magazinePile.GetAmmoMax() > emActionData.m_magazinePile.GetAmmoCount() && (vector.DistanceSq(action_data.m_Player.GetPosition(), emActionData.m_magazinePile.GetPosition()) < (UAMaxDistances.DEFAULT * UAMaxDistances.DEFAULT) ) )
144  {
145  emActionData.m_magazinePile.ServerStoreCartridge(dmg,ammoType);
146  }
147  else
148  {
149  piles = MiscGameplayFunctions.CreateMagazinePilesFromBullet(ammoType, action_data.m_Player.GetPosition(), 1, dmg);
150  if ( piles.Count() > 0 )
151  emActionData.m_magazinePile = piles.Get(0);
152  }
153  }
154  //emActionData.m_magazinePile.SetSynchDirty();
155  }
156  //mag.SetSynchDirty();
157  }
158 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CAContinuousRepeat
Definition: cacontinuousrepeat.c:1
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
DayZPlayerUtils
private void DayZPlayerUtils()
cannot be instantiated
Definition: dayzplayerutils.c:461
CCTNone
Definition: cctnone.c:1
UAMaxDistances
Definition: actionconstants.c:104
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
ActionEmptyMagazine
Definition: actionemptymagazine.c:14
CreateActionComponent
ActionEmptyMagazine CreateActionComponent
Definition: actionemptymagazine.c:8
array< Magazine >
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
EmptyMagazineActionData
Definition: actionemptymagazine.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10