actionminetree.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. class MineActionData : ActionData
  2. {
  3. EHarvestType m_HarvestType = EHarvestType.NORMAL;
  4. int m_EffecterID = -1;
  5. }
  6. class ActionMineTreeCB : ActionContinuousBaseCB
  7. {
  8. private const float TIME_BETWEEN_MATERIAL_DROPS_DEFAULT = 4;
  9. override void CreateActionComponent()
  10. {
  11. m_ActionData.m_ActionComponent = new CAContinuousMineWood(TIME_BETWEEN_MATERIAL_DROPS_DEFAULT);
  12. }
  13. };
  14. class ActionMineBase : ActionContinuousBase
  15. {
  16. EHarvestType m_HarvestType = EHarvestType.NORMAL;
  17. override ActionData CreateActionData()
  18. {
  19. MineActionData data = new MineActionData;
  20. data.m_HarvestType = m_HarvestType;
  21. return data;
  22. }
  23. override bool CanBeUsedInFreelook()
  24. {
  25. return false;
  26. }
  27. override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
  28. {
  29. m_Text = "#harvest" + " " + GetYieldName(player, target, item);
  30. }
  31. string GetYieldName( PlayerBase player, ActionTarget target, ItemBase item )
  32. {
  33. //given the circumstances, the implementation bellow is the path of least resistance
  34. Object targetObject = target.GetObject();
  35. WoodBase wood = WoodBase.Cast(targetObject);
  36. RockBase rock = RockBase.Cast(targetObject);
  37. string yieldName;
  38. if (wood || rock)
  39. {
  40. map<string,int> output_map = new map<string,int>;
  41. if (wood)
  42. {
  43. wood.GetMaterialAndQuantityMapEx(item, output_map, m_HarvestType);
  44. }
  45. else
  46. {
  47. rock.GetMaterialAndQuantityMap(item, output_map);
  48. }
  49. if (output_map.Count() > 0)
  50. {
  51. yieldName = MiscGameplayFunctions.GetItemDisplayName(output_map.GetKey(0));
  52. }
  53. }
  54. return yieldName;
  55. }
  56. }
  57. class ActionMineTree : ActionMineBase
  58. {
  59. void ActionMineTree()
  60. {
  61. m_CallbackClass = ActionMineTreeCB;
  62. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_HACKTREE;
  63. m_FullBody = true;
  64. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  65. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_HIGH;
  66. }
  67. override void CreateConditionComponents()
  68. {
  69. m_ConditionTarget = new CCTCursor(UAMaxDistances.SMALL);
  70. m_ConditionItem = new CCINonRuined;
  71. }
  72. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  73. {
  74. //Action not allowed if player has broken legs
  75. if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  76. return false;
  77. Object targetObject = target.GetObject();
  78. return targetObject.IsTree() && targetObject.IsCuttable();
  79. }
  80. //! not checking target damage anymore, callback takes care of that
  81. override bool CanContinue(ActionData action_data)
  82. {
  83. if (!action_data.m_Player.IsPlayerInStance(action_data.m_PossibleStanceMask) || !m_ConditionItem || !m_ConditionItem.CanContinue(action_data.m_Player,action_data.m_MainItem))
  84. return false;
  85. return ActionConditionContinue(action_data);
  86. }
  87. override void OnExecuteServer(ActionData action_data)
  88. {
  89. MineActionData mad = MineActionData.Cast(action_data);
  90. if (mad.m_EffecterID == -1)
  91. {
  92. mad.m_EffecterID = SEffectManager.CreateParticleServer(action_data.m_Target.GetObject().GetPosition(), new TreeEffecterParameters("TreeEffecter", EffecterBase.NOT_DEFINED_LIFESPAN, 0.1));
  93. }
  94. else
  95. {
  96. SEffectManager.ReactivateParticleServer(mad.m_EffecterID);
  97. }
  98. }
  99. override bool HasMultipleExecution(ActionData action_data)
  100. {
  101. return true;
  102. }
  103. override void OnEndServer(ActionData action_data)
  104. {
  105. super.OnEndServer(action_data);
  106. MineActionData mad = MineActionData.Cast(action_data);
  107. SEffectManager.DestroyEffecterParticleServer(mad.m_EffecterID);
  108. }
  109. };