Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuoustransferquantity.c
Go to the documentation of this file.
2 {
3  protected float m_TargetUnits;
4  protected float m_SpentQuantity;
5  protected float m_ItemQuantity;
6  protected float m_SourceQuantity;
7  protected float m_QuantityFilledPerSecond;
8  protected float m_TimeToComplete;
9  protected ref Param1<float> m_SpentUnits;
10 
11  void CAContinuousTransferQuantity( float quantity_filled_per_second )
12  {
13  m_QuantityFilledPerSecond = quantity_filled_per_second;
14  }
15 
16  override void Setup( ActionData action_data )
17  {
18  m_SpentQuantity = 0;
19  if ( !m_SpentUnits )
20  {
21  m_SpentUnits = new Param1<float>(0);
22  }
23  else
24  {
25  m_SpentUnits.param1 = 0;
26  }
27  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
28  ItemBase trg;
29  if ( Class.CastTo(trg, action_data.m_Target.GetObject()) )
30  {
31  m_SourceQuantity = trg.GetQuantity();
32  }
33  m_TargetUnits = action_data.m_MainItem.GetQuantityMax();
34  m_TimeToComplete= (Math.Min((m_TargetUnits-m_ItemQuantity),m_SourceQuantity))/m_QuantityFilledPerSecond;
35  }
36 
37  override int Execute( ActionData action_data )
38  {
39  if ( !action_data.m_Player )
40  {
41  return UA_ERROR;
42  }
43  ItemBase trg;
44  Class.CastTo(trg, action_data.m_Target.GetObject());
45  if ( action_data.m_MainItem.GetQuantity() >= action_data.m_MainItem.GetQuantityMax() || trg.GetQuantity() == 0 )
46  {
47  return UA_FINISHED;
48  }
49  else
50  {
51  if ( m_SpentQuantity < m_TargetUnits && m_SpentQuantity < m_SourceQuantity )
52  {
53  m_SpentQuantity += m_QuantityFilledPerSecond * action_data.m_Player.GetDeltaT();
54  float val = m_ItemQuantity-m_SpentQuantity;
55  if ( m_Action ) m_Action.SendMessageToClient(action_data.m_Player, val.ToString());
56  return UA_PROCESSING;
57  }
58  else
59  {
60  CalcAndSetQuantity( action_data );
61  OnCompletePogress(action_data);
62  return UA_FINISHED;
63  }
64  }
65  }
66 
67  override override int Cancel( ActionData action_data )
68  {
69  if ( !action_data.m_Player )
70  {
71  return UA_ERROR;
72  }
73 
74  CalcAndSetQuantity( action_data );
75  return UA_CANCEL;
76  }
77 
78  override float GetProgress()
79  {
80  float progress = (m_SpentQuantity*m_QuantityFilledPerSecond)/m_TimeToComplete;
81  return (m_SpentQuantity*m_QuantityFilledPerSecond)/m_TimeToComplete;
82  }
83  //---------------------------------------------------------------------------
84 
85  void CalcAndSetQuantity( ActionData action_data )
86  {
87  if ( GetGame().IsServer() )
88  {
89  if ( m_SpentUnits )
90  {
91  m_SpentUnits.param1 = m_SpentQuantity;
92  SetACData(m_SpentUnits);
93  }
94  action_data.m_MainItem.AddQuantity(m_SpentQuantity);
95  ItemBase trg;
96  if ( Class.CastTo(trg, action_data.m_Target.GetObject()) )
97  {
98  trg.AddQuantity(-m_SpentQuantity,false,false);
99  }
100  }
101  }
102 };
ItemBase
Definition: inventoryitem.c:730
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
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
CAContinuousTransferQuantity
Definition: cacontinuoustransferquantity.c:1
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
Math
Definition: enmath.c:6
m_Action
enum ActionInputType m_Action
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10