Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousminewood.c
Go to the documentation of this file.
2 {
3  protected float m_TimeElpased;
4  protected float m_AdjustedTimeBetweenMaterialDrops;
5  protected float m_CycleTimeOverride;
6  protected float m_TimeBetweenMaterialDrops;
7  protected float m_DamageToMiningItemEachDrop;
8  protected float m_AdjustedDamageToMiningItemEachDrop;
9  protected int m_AmountOfDrops;
10  protected int m_CurrentAssumedDrops;
11  protected ref map<string,int> m_MaterialAndQuantityMap;
12  protected float m_TimeToComplete;
13  protected ref Param1<float> m_SpentUnits;
14  protected bool m_DataLoaded = false;
15  protected const int MINEDITEM_MAX = 5;
16  protected ItemBase m_MinedItem[MINEDITEM_MAX];
17  protected ItemBase m_SecondaryItem;
18 
19  void CAContinuousMineWood(float time_between_drops)
20  {
21  m_TimeBetweenMaterialDrops = time_between_drops;
22  m_CycleTimeOverride = -1.0;
23  }
24 
25  override void Setup( ActionData action_data )
26  {
27  m_TimeElpased = 0;
28  if ( !m_SpentUnits )
29  {
30  m_SpentUnits = new Param1<float>(0);
31  }
32  else
33  {
34  m_SpentUnits.param1 = 0;
35  }
36  m_MaterialAndQuantityMap = new map<string,int>;
37  m_DataLoaded = GetMiningData(action_data);
38 
39  if (m_CycleTimeOverride > -1.0)
40  {
41  m_TimeBetweenMaterialDrops = m_CycleTimeOverride;
42  if (!action_data.m_MainItem) //hand action
43  m_TimeBetweenMaterialDrops = m_TimeBetweenMaterialDrops * 3;
44  }
45  m_AdjustedTimeBetweenMaterialDrops = action_data.m_Player.GetSoftSkillsManager().SubtractSpecialtyBonus( m_TimeBetweenMaterialDrops, m_Action.GetSpecialtyWeight(), true );
46  m_TimeToComplete = m_AmountOfDrops * m_AdjustedTimeBetweenMaterialDrops;
47  }
48 
49  override int Execute( ActionData action_data )
50  {
51  Object targetObject;
52  Class.CastTo(targetObject, action_data.m_Target.GetObject());
53  if ( !action_data.m_Player || !m_DataLoaded )
54  {
55  return UA_ERROR;
56  }
57 
58  if ( (action_data.m_MainItem && action_data.m_MainItem.IsDamageDestroyed()) || targetObject.IsDamageDestroyed() )
59  {
60  return UA_FINISHED;
61  }
62  else
63  {
64  if ( m_TimeElpased < m_AdjustedTimeBetweenMaterialDrops )
65  {
66  m_TimeElpased += action_data.m_Player.GetDeltaT();
67  }
68  else
69  {
70  if ( GetGame().IsServer() )
71  {
72  float damage = 0;
73  if (m_AmountOfDrops > 0)
74  damage = (1 / m_AmountOfDrops) * 100;
75 
76  targetObject.DecreaseHealth("", "", damage, targetObject.CanBeAutoDeleted());
77  CreatePrimaryItems(action_data);
78  if (action_data.m_MainItem)
79  action_data.m_MainItem.DecreaseHealth( "", "", m_AdjustedDamageToMiningItemEachDrop );
80  else
81  {
82  DamagePlayersHands(action_data.m_Player);
83  }
84 
85  if ( targetObject.IsDamageDestroyed() ) //client does not know the target is destroyed yet, happens on the next Execute!
86  {
87  if ( m_SpentUnits )
88  {
89  m_SpentUnits.param1 = m_TimeElpased;
90  SetACData(m_SpentUnits);
91  }
92 
93  if ( WoodBase.Cast(targetObject) )
94  {
95  WoodBase target_woodbase = WoodBase.Cast(targetObject);
96 
97  if (target_woodbase.GetSecondaryOutput() != "")
98  CreateSecondaryItems(action_data,target_woodbase.GetSecondaryOutput(),target_woodbase.GetSecondaryDropsAmount());
99  }
100 
101  if (action_data.m_MainItem)
102  {
103  targetObject.OnTreeCutDown( action_data.m_MainItem );
104  }
105  else
106  {
107  targetObject.OnTreeCutDown( action_data.m_Player );
108  }
109  }
110  }
111 
112  m_CurrentAssumedDrops++;
113  if (m_AmountOfDrops > 0 && m_CurrentAssumedDrops >= m_AmountOfDrops) //assumed end, client does not know the target is destroyed yet
114  {
115  OnCompletePogress(action_data);
116  return UA_FINISHED;
117  }
118 
119  m_TimeElpased = m_TimeElpased - m_AdjustedTimeBetweenMaterialDrops;
120  OnCompletePogress(action_data);
121  }
122  return UA_PROCESSING;
123  }
124  }
125 
126  override float GetProgress()
127  {
128  return m_TimeElpased/m_AdjustedTimeBetweenMaterialDrops;
129  }
130 
131  //---------------------------------------------------------------------------
132 
133  bool GetMiningData(ActionData action_data )
134  {
135  MineActionData adata = MineActionData.Cast(action_data);
136  WoodBase ntarget;
137  if ( Class.CastTo(ntarget, action_data.m_Target.GetObject()) )
138  {
139  m_AmountOfDrops = ntarget.GetAmountOfDropsEx(action_data.m_MainItem,adata.m_HarvestType);
140  m_CurrentAssumedDrops = 0;
141  m_CycleTimeOverride = ntarget.GetCycleTimeOverride(); //TODO
142  ntarget.GetMaterialAndQuantityMapEx(action_data.m_MainItem,m_MaterialAndQuantityMap, adata.m_HarvestType);
143  m_DamageToMiningItemEachDrop = ntarget.GetDamageToMiningItemEachDropEx(action_data.m_MainItem, adata.m_HarvestType );
144  m_AdjustedDamageToMiningItemEachDrop = action_data.m_Player.GetSoftSkillsManager().SubtractSpecialtyBonus( m_DamageToMiningItemEachDrop, m_Action.GetSpecialtyWeight(), true );
145  return true;
146  }
147  return false;
148  }
149 
150  void CreatePrimaryItems(ActionData action_data)
151  {
152  string material;
153  int increment;
154  for (int i = 0; i < m_MaterialAndQuantityMap.Count(); i++)
155  {
156  material = m_MaterialAndQuantityMap.GetKey(i);
157 
158  if (material != "")
159  {
160  increment = m_MaterialAndQuantityMap.GetElement(i);
161 
162  if ( !m_MinedItem[i] )
163  {
164  m_MinedItem[i] = ItemBase.Cast(GetGame().CreateObjectEx(material,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
165  m_MinedItem[i].SetQuantity(increment);
166  }
167  else if (m_MinedItem[i].HasQuantity())
168  {
169  if ( m_MinedItem[i].IsFullQuantity() )
170  {
171  int stack_max = m_MinedItem[i].GetQuantityMax();
172 
173  increment -= stack_max - m_MinedItem[i].GetQuantity();
174  if (increment >= 1.0)
175  {
176  m_MinedItem[i] = ItemBase.Cast(GetGame().CreateObjectEx(material,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
177  m_MinedItem[i].SetQuantity(increment,false);
178  }
179  }
180  else
181  {
182  m_MinedItem[i].AddQuantity(increment,false);
183  }
184  }
185  else
186  {
187  m_MinedItem[i] = ItemBase.Cast(GetGame().CreateObjectEx(material,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
188  }
189  }
190  }
191  }
192 
193  void CreateSecondaryItems(ActionData action_data, string material_secondary = "", int quantity_secondary = -1)
194  {
195  if (material_secondary == "" || quantity_secondary <= 0)
196  {
197  return;
198  }
199 
200  m_SecondaryItem = ItemBase.Cast(GetGame().CreateObjectEx(material_secondary,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
201  if ( !m_SecondaryItem.HasQuantity() )
202  {
203  CreateSecondaryItems(action_data,material_secondary,quantity_secondary - 1);
204  return;
205  }
206 
207  int increment = quantity_secondary;
208  int stack_max = m_SecondaryItem.GetQuantityMax();
209  int stacks_amount;
210 
211  stacks_amount = Math.Ceil(increment/stack_max);
212 
213  for (int i = 0; i < stacks_amount; i++)
214  {
215  if (increment > stack_max)
216  {
217  m_SecondaryItem.SetQuantity(stack_max);
218  increment -= stack_max;
219  m_SecondaryItem = ItemBase.Cast(GetGame().CreateObjectEx(material_secondary,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
220  }
221  else
222  {
223  m_SecondaryItem.SetQuantity(increment);
224  }
225  }
226  }
227 
228  void DamagePlayersHands(PlayerBase player)
229  {
230  ItemBase gloves = ItemBase.Cast(player.FindAttachmentBySlotName("Gloves"));
231  if ( gloves && !gloves.IsDamageDestroyed() )
232  {
233  gloves.DecreaseHealth("","",m_AdjustedDamageToMiningItemEachDrop);
234  }
235  else
236  {
237  int rand = Math.RandomIntInclusive(0,9);
238  if ( rand == 0 )
239  {
240  rand = Math.RandomIntInclusive(0,1);
241  if ( rand == 0 && !player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll") )
242  {
243  player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("RightForeArmRoll");
244  }
245  else if ( rand == 1 && !player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("RightForeArmRoll") )
246  {
247  player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll");
248  }
249  }
250  }
251  }
252 };
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
WoodBase
void WoodBase()
Definition: woodbase.c:30
HasQuantity
bool HasQuantity()
Definition: itembase.c:3311
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
IsFullQuantity
bool IsFullQuantity()
Definition: itembase.c:3321
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
Object
Definition: objecttyped.c:1
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
CAContinuousMineWood
Definition: cacontinuousminewood.c:1
Math
Definition: enmath.c:6
m_Action
enum ActionInputType m_Action
MineActionData
Definition: actionminetree.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10