Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousfertilizegardenslot.c
Go to the documentation of this file.
2 {
3  protected float m_SlotFertilizerNeed;
4  protected float m_TimeToComplete;
5  protected float m_SpentQuantityTotal;
6  protected float m_StartQuantity;
7  protected Slot m_Slot;
8  protected string m_Selection;
9 
10  void CAContinuousFertilizeGardenSlot( float quantity_used_per_second )
11  {
12  m_QuantityUsedPerSecond = quantity_used_per_second;
13  m_TimeToComplete = 0;
14  }
15 
16  override void Setup( ActionData action_data )
17  {
18  GardenBase target_GB;
19  if ( Class.CastTo(target_GB, action_data.m_Target.GetObject() ) )
20  {
21  m_SpentQuantity = 0;
22  m_StartQuantity = action_data.m_MainItem.GetQuantity();
23 
24  if ( !m_SpentUnits )
25  {
26  m_SpentUnits = new Param1<float>(0);
27  }
28  else
29  {
30  m_SpentUnits.param1 = 0;
31  }
32 
33  if ( action_data.m_MainItem )
34  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
35 
36  if ( target_GB )
37  {
38  /*string selection = target_GB.GetActionComponentName(action_data.m_Target.GetComponentIndex());
39 
40  Slot slot = target_GB.GetSlotBySelection( selection );*/
41 
42  array<string> selections = new array<string>;
43  target_GB.GetActionComponentNameList(action_data.m_Target.GetComponentIndex(), selections);
44 
45  for (int s = 0; s < selections.Count(); s++)
46  {
47  //string selection = selections[s];
48  m_Selection = selections[s];
49  m_Slot = target_GB.GetSlotBySelection( m_Selection );
50  if (m_Slot)
51  break;
52  }
53 
54 
55  string item_type = action_data.m_MainItem.GetType();
56  float consumed_quantity = GetGame().ConfigGetFloat( "cfgVehicles " + item_type + " Horticulture ConsumedQuantity" );
57 
58  float max = m_Slot.GetFertilizerQuantityMax();
59 
60  m_SlotFertilizerNeed = max - consumed_quantity;
61  }
62  m_TimeToComplete = (Math.Min(m_SlotFertilizerNeed,m_ItemQuantity))/m_QuantityUsedPerSecond;
63  }
64  }
65 
66 
67  override int Execute( ActionData action_data )
68  {
69  if ( !action_data.m_Player )
70  {
71  return UA_ERROR;
72  }
73 
74  if ( m_SpentQuantity >= m_ItemQuantity )
75  {
76  return UA_FINISHED;
77  }
78  else
79  {
80  if ( m_SpentQuantity <= m_ItemQuantity )
81  {
82  m_SpentQuantity += m_QuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
83  float val = action_data.m_Player.GetSoftSkillsManager().AddSpecialtyBonus( m_SpentQuantity, m_Action.GetSpecialtyWeight(), true );
84  GardenBase garden_base;
85  Class.CastTo(garden_base, action_data.m_Target.GetObject() );
86  //string selection = garden_base.GetActionComponentName(action_data.m_Target.GetComponentIndex());
87 
88  m_SpentQuantityTotal += m_SpentQuantity;
89 
90  if (GetGame().IsServer())
91  {
92  action_data.m_MainItem.AddQuantity( -m_SpentQuantity );
93  }
94 
95  garden_base.Fertilize( action_data.m_Player, action_data.m_MainItem, val, m_Selection );
96 
97  return UA_PROCESSING;
98  }
99  else
100  {
101  CalcAndSetQuantity( action_data );
102  OnCompletePogress(action_data);
103  return UA_FINISHED;
104  }
105  }
106  }
107 
108  override float GetProgress()
109  {
110  /*if ( m_TimeToComplete == 0) //Prevent division by 0 case
111  {
112  return -1;
113  }*/
114  return -(m_SpentQuantityTotal / m_StartQuantity);
115  //return (m_SpentQuantity)/m_ItemQuantity;///(m_TimeToComplete * m_QuantityUsedPerSecond)/m_ItemQuantity;
116  }
117 };
GetGame
proto native CGame GetGame()
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
CAContinuousQuantity
Definition: cacontinuousquantity.c:1
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
CalcAndSetQuantity
protected void CalcAndSetQuantity()
Definition: fireplacebase.c:2622
array< string >
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
CAContinuousFertilizeGardenSlot
Definition: cacontinuousfertilizegardenslot.c:1
Math
Definition: enmath.c:6
GardenBase
Definition: gardenplot.c:1
m_Action
enum ActionInputType m_Action
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10