cacontinuousminewood.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. class CAContinuousMineWood : CAContinuousBase
  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. void CAContinuousMineWood(float time_between_drops)
  19. {
  20. m_TimeBetweenMaterialDrops = time_between_drops;
  21. m_CycleTimeOverride = -1.0;
  22. }
  23. override void Setup( ActionData action_data )
  24. {
  25. m_TimeElpased = 0;
  26. if ( !m_SpentUnits )
  27. {
  28. m_SpentUnits = new Param1<float>(0);
  29. }
  30. else
  31. {
  32. m_SpentUnits.param1 = 0;
  33. }
  34. m_MaterialAndQuantityMap = new map<string,int>;
  35. m_DataLoaded = GetMiningData(action_data);
  36. if (m_CycleTimeOverride > -1.0)
  37. {
  38. m_TimeBetweenMaterialDrops = m_CycleTimeOverride;
  39. if (!action_data.m_MainItem) //hand action
  40. m_TimeBetweenMaterialDrops = m_TimeBetweenMaterialDrops * 3;
  41. }
  42. m_AdjustedTimeBetweenMaterialDrops = m_TimeBetweenMaterialDrops;//removed softskills
  43. m_TimeToComplete = m_AmountOfDrops * m_AdjustedTimeBetweenMaterialDrops;
  44. }
  45. override int Execute( ActionData action_data )
  46. {
  47. Object targetObject;
  48. Class.CastTo(targetObject, action_data.m_Target.GetObject());
  49. if ( !action_data.m_Player || !m_DataLoaded )
  50. {
  51. return UA_ERROR;
  52. }
  53. if ( (action_data.m_MainItem && action_data.m_MainItem.IsDamageDestroyed()) || targetObject.IsDamageDestroyed() )
  54. {
  55. return UA_FINISHED;
  56. }
  57. else
  58. {
  59. if ( m_TimeElpased < m_AdjustedTimeBetweenMaterialDrops )
  60. {
  61. m_TimeElpased += action_data.m_Player.GetDeltaT();
  62. }
  63. else
  64. {
  65. if ( GetGame().IsServer() )
  66. {
  67. float damage = 0;
  68. if (m_AmountOfDrops > 0)
  69. damage = (1 / m_AmountOfDrops) * 100;
  70. targetObject.DecreaseHealth("", "", damage, targetObject.CanBeAutoDeleted());
  71. CreatePrimaryItems(action_data);
  72. if (action_data.m_MainItem)
  73. action_data.m_MainItem.DecreaseHealth( "", "", m_AdjustedDamageToMiningItemEachDrop );
  74. else
  75. {
  76. DamagePlayersHands(action_data.m_Player);
  77. }
  78. if ( targetObject.IsDamageDestroyed() ) //client does not know the target is destroyed yet, happens on the next Execute!
  79. {
  80. if ( m_SpentUnits )
  81. {
  82. m_SpentUnits.param1 = m_TimeElpased;
  83. SetACData(m_SpentUnits);
  84. }
  85. if ( WoodBase.Cast(targetObject) )
  86. {
  87. WoodBase target_woodbase = WoodBase.Cast(targetObject);
  88. if (target_woodbase.GetSecondaryOutput() != "")
  89. CreateSecondaryItems(action_data,target_woodbase.GetSecondaryOutput(),target_woodbase.GetSecondaryDropsAmount());
  90. }
  91. if (action_data.m_MainItem)
  92. {
  93. targetObject.OnTreeCutDown( action_data.m_MainItem );
  94. }
  95. else
  96. {
  97. targetObject.OnTreeCutDown( action_data.m_Player );
  98. }
  99. }
  100. }
  101. m_CurrentAssumedDrops++;
  102. if (m_AmountOfDrops > 0 && m_CurrentAssumedDrops >= m_AmountOfDrops) //assumed end, client does not know the target is destroyed yet
  103. {
  104. OnCompletePogress(action_data);
  105. return UA_FINISHED;
  106. }
  107. m_TimeElpased = m_TimeElpased - m_AdjustedTimeBetweenMaterialDrops;
  108. OnCompletePogress(action_data);
  109. }
  110. return UA_PROCESSING;
  111. }
  112. }
  113. override float GetProgress()
  114. {
  115. return m_TimeElpased/m_AdjustedTimeBetweenMaterialDrops;
  116. }
  117. //---------------------------------------------------------------------------
  118. bool GetMiningData(ActionData action_data )
  119. {
  120. MineActionData adata = MineActionData.Cast(action_data);
  121. WoodBase ntarget;
  122. if ( Class.CastTo(ntarget, action_data.m_Target.GetObject()) )
  123. {
  124. m_AmountOfDrops = ntarget.GetAmountOfDropsEx(action_data.m_MainItem,adata.m_HarvestType);
  125. m_CurrentAssumedDrops = 0;
  126. m_CycleTimeOverride = ntarget.GetCycleTimeOverride(); //TODO
  127. ntarget.GetMaterialAndQuantityMapEx(action_data.m_MainItem,m_MaterialAndQuantityMap, adata.m_HarvestType);
  128. m_DamageToMiningItemEachDrop = ntarget.GetDamageToMiningItemEachDropEx(action_data.m_MainItem, adata.m_HarvestType );
  129. m_AdjustedDamageToMiningItemEachDrop = m_DamageToMiningItemEachDrop;//removed softskills
  130. return true;
  131. }
  132. return false;
  133. }
  134. void CreatePrimaryItems(ActionData action_data)
  135. {
  136. string material;
  137. int increment;
  138. for (int i = 0; i < m_MaterialAndQuantityMap.Count(); i++)
  139. {
  140. material = m_MaterialAndQuantityMap.GetKey(i);
  141. if (material != "")
  142. {
  143. increment = m_MaterialAndQuantityMap.GetElement(i);
  144. if ( !m_MinedItem[i] )
  145. {
  146. m_MinedItem[i] = ItemBase.Cast(GetGame().CreateObjectEx(material,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
  147. m_MinedItem[i].SetQuantity(increment);
  148. }
  149. else if (m_MinedItem[i].HasQuantity())
  150. {
  151. if ( m_MinedItem[i].IsFullQuantity() )
  152. {
  153. int stack_max = m_MinedItem[i].GetQuantityMax();
  154. increment -= stack_max - m_MinedItem[i].GetQuantity();
  155. if (increment >= 1.0)
  156. {
  157. m_MinedItem[i] = ItemBase.Cast(GetGame().CreateObjectEx(material,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
  158. m_MinedItem[i].SetQuantity(increment,false);
  159. }
  160. }
  161. else
  162. {
  163. m_MinedItem[i].AddQuantity(increment,false);
  164. }
  165. }
  166. else
  167. {
  168. m_MinedItem[i] = ItemBase.Cast(GetGame().CreateObjectEx(material,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
  169. }
  170. }
  171. }
  172. }
  173. void CreateSecondaryItems(ActionData action_data, string material_secondary = "", int quantity_secondary = -1)
  174. {
  175. if (material_secondary == "" || quantity_secondary <= 0)
  176. {
  177. return;
  178. }
  179. m_SecondaryItem = ItemBase.Cast(GetGame().CreateObjectEx(material_secondary,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
  180. if ( !m_SecondaryItem.HasQuantity() )
  181. {
  182. CreateSecondaryItems(action_data,material_secondary,quantity_secondary - 1);
  183. return;
  184. }
  185. int increment = quantity_secondary;
  186. int stack_max = m_SecondaryItem.GetQuantityMax();
  187. int stacks_amount;
  188. stacks_amount = Math.Ceil(increment/stack_max);
  189. for (int i = 0; i < stacks_amount; i++)
  190. {
  191. if (increment > stack_max)
  192. {
  193. m_SecondaryItem.SetQuantity(stack_max);
  194. increment -= stack_max;
  195. m_SecondaryItem = ItemBase.Cast(GetGame().CreateObjectEx(material_secondary,action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
  196. }
  197. else
  198. {
  199. m_SecondaryItem.SetQuantity(increment);
  200. }
  201. }
  202. }
  203. void DamagePlayersHands(PlayerBase player)
  204. {
  205. ItemBase gloves = ItemBase.Cast(player.FindAttachmentBySlotName("Gloves"));
  206. if ( gloves && !gloves.IsDamageDestroyed() )
  207. {
  208. gloves.DecreaseHealth("","",m_AdjustedDamageToMiningItemEachDrop);
  209. }
  210. else
  211. {
  212. int rand = Math.RandomIntInclusive(0,9);
  213. if ( rand == 0 )
  214. {
  215. rand = Math.RandomIntInclusive(0,1);
  216. if ( rand == 0 && !player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll") )
  217. {
  218. player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("RightForeArmRoll");
  219. }
  220. else if ( rand == 1 && !player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("RightForeArmRoll") )
  221. {
  222. player.GetBleedingManagerServer().AttemptAddBleedingSourceBySelection("LeftForeArmRoll");
  223. }
  224. }
  225. }
  226. }
  227. };