Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousquantityrepeat.c
Go to the documentation of this file.
2 {
3  protected float m_ItemQuantity;
4  protected float m_SpentQuantity;
5  protected float m_ItemMaxQuantity;
6  protected float m_TimeElpased;
7  protected float m_QuantityUsedPerSecond;
8  protected float m_AdjustedQuantityUsedPerSecond;
9  protected float m_DefaultTimeToRepeat;
10  protected ref Param1<float> m_SpentUnits;
11 
12  void CAContinuousQuantityRepeat( float quantity_used_per_second, float time_to_repeat )
13  {
14  m_QuantityUsedPerSecond = quantity_used_per_second;
15  m_DefaultTimeToRepeat = time_to_repeat;
16  }
17 
18  override void Setup( ActionData action_data )
19  {
20  m_TimeElpased = 0;
21  m_SpentQuantity = 0;
22 
23  if ( !m_SpentUnits )
24  {
25  m_SpentUnits = new Param1<float>( 0 );
26  }
27  else
28  {
29  m_SpentUnits.param1 = 0;
30  }
31 
32  m_ItemMaxQuantity = action_data.m_MainItem.GetQuantityMax();
33  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
34  }
35 
36 
37  override int Execute( ActionData action_data )
38  {
39  if ( !action_data.m_Player )
40  {
41  return UA_ERROR;
42  }
43 
44  if ( m_ItemQuantity <= 0 )
45  {
46  return UA_FINISHED;
47  }
48  else
49  {
50  if ( m_SpentQuantity < m_ItemQuantity )
51  {
52  m_AdjustedQuantityUsedPerSecond = action_data.m_Player.GetSoftSkillsManager().AddSpecialtyBonus( m_QuantityUsedPerSecond, m_Action.GetSpecialtyWeight(), true);
53  m_SpentQuantity += m_AdjustedQuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
54  m_TimeElpased += action_data.m_Player.GetDeltaT();
55 
56  if ( m_TimeElpased >= m_DefaultTimeToRepeat )
57  {
58  CalcAndSetQuantity( action_data );
59  Setup(action_data); //reset data after repeat
60  }
61 
62  return UA_PROCESSING;
63  }
64  else
65  {
66  CalcAndSetQuantity( action_data );
67  OnCompletePogress(action_data);
68  return UA_FINISHED;
69  }
70  }
71  }
72 
73  override int Cancel( ActionData action_data )
74  {
75  if ( !action_data.m_Player )
76  {
77  return UA_ERROR;
78  }
79  if (GetProgress() > 0)
80  {
81  CalcAndSetQuantity( action_data );
82  }
83  return UA_CANCEL;
84  }
85 
86  override float GetProgress()
87  {
88  //float progress = ( m_ItemQuantity - m_SpentQuantity ) / m_ItemMaxQuantity;
89  return ( m_ItemQuantity - m_SpentQuantity ) / m_ItemMaxQuantity;
90  }
91 
92  //---------------------------------------------------------------------------
93 
94 
95  void CalcAndSetQuantity( ActionData action_data )
96  {
97  if ( GetGame().IsServer() )
98  {
99  if ( m_SpentUnits )
100  {
101  m_SpentUnits.param1 = m_SpentQuantity;
102  SetACData(m_SpentUnits);
103  }
104 
105  action_data.m_MainItem.AddQuantity( -m_SpentQuantity, false, false );
106  }
107  }
108 }
GetGame
proto native CGame GetGame()
CAContinuousBase
Definition: cacontinuousbase.c:1
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
UA_CANCEL
const int UA_CANCEL
Definition: constants.c:437
CAContinuousQuantityRepeat
Definition: cacontinuousquantityrepeat.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
m_Action
enum ActionInputType m_Action