Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousemptymagazine.c
Go to the documentation of this file.
2 {
3  protected float m_TargetUnits;
4  protected float m_SpentQuantity;
5  protected float m_Time;
6  protected float m_TimeToEjectOneBullet;
7  protected ref Param1<float> m_SpentUnits;
8 
9  void CAContinuousEmptyMagazine( float eject_time )
10  {
11  m_TimeToEjectOneBullet = eject_time;
12  m_Time = 0;
13  }
14 
15  override void Setup( ActionData action_data )
16  {
17  if ( !m_SpentUnits )
18  {
19  m_SpentUnits = new Param1<float>(0);
20  }
21  else
22  {
23  m_SpentUnits.param1 = 0;
24  }
25  m_SpentQuantity = 0;
26  Magazine itm;
27  Class.CastTo(itm, action_data.m_MainItem);
28  m_TargetUnits = itm.GetAmmoCount();
29 
30  }
31 
32  override int Execute( ActionData action_data )
33  {
34  if ( !action_data.m_Player )
35  {
36  return UA_ERROR;
37  }
38 
39  if ( m_TargetUnits == 0 )
40  {
41  return UA_FINISHED;
42  }
43  else
44  {
45  if ( m_SpentQuantity < m_TargetUnits )
46  {
47  m_Time += action_data.m_Player.GetDeltaT();
48  if ( m_Time > m_TimeToEjectOneBullet )
49  {
50  m_Time = 0;
51  m_SpentQuantity += 1;
52  }
53  return UA_PROCESSING;
54  }
55  else
56  {
57  CalcAndSetQuantity( action_data );
58  OnCompletePogress(action_data);
59  return UA_FINISHED;
60  }
61  }
62  }
63 
64  override int Cancel( ActionData action_data )
65  {
66  if ( !action_data.m_Player || !action_data.m_MainItem )
67  {
68  return UA_ERROR;
69  }
70 
71  CalcAndSetQuantity( action_data );
72  return UA_CANCEL;
73  }
74 
75  override float GetProgress()
76  {
77  //float progress = m_SpentQuantity/m_TargetUnits;
78  return m_SpentQuantity/m_TargetUnits;
79  }
80 
81  //---------------------------------------------------------------------------
82 
83  void CalcAndSetQuantity( ActionData action_data )
84  {
85  if ( GetGame().IsServer() )
86  {
87  if ( action_data.m_MainItem )
88  {
89  Magazine itm;
90  Class.CastTo(itm, action_data.m_MainItem);
91  if ( m_SpentUnits )
92  {
93  m_SpentUnits.param1 = m_SpentQuantity;
94  SetACData(m_SpentUnits);
95  }
96  itm.ServerAddAmmoCount(-m_SpentQuantity);
97  }
98  }
99  }
100 };
GetGame
proto native CGame GetGame()
CAContinuousBase
Definition: cacontinuousbase.c:1
m_Time
protected float m_Time
Definition: carscript.c:146
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
UA_CANCEL
const int UA_CANCEL
Definition: constants.c:437
CAContinuousEmptyMagazine
Definition: cacontinuousemptymagazine.c:1
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10