actioncraftboltsfeather.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. class ActionCraftBoltsFeatherCB : ActionContinuousBaseCB
  2. {
  3. private const float TIME_TO_CRAFT = 3.0;
  4. override void CreateActionComponent()
  5. {
  6. m_ActionData.m_ActionComponent = new CAContinuousRepeat(TIME_TO_CRAFT);
  7. }
  8. };
  9. class ActionCraftBoltsFeather: ActionContinuousBase
  10. {
  11. protected bool m_IsFeatherInHands;
  12. protected Ammunition_Base m_ResultEntity;
  13. void ActionCraftBoltsFeather()
  14. {
  15. m_CallbackClass = ActionCraftBoltsFeatherCB;
  16. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_CRAFTING;
  17. m_FullBody = true;
  18. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
  19. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_HIGH;
  20. m_Text = "#STR_CraftBolt1";
  21. }
  22. override void CreateConditionComponents()
  23. {
  24. m_ConditionItem = new CCINonRuined();
  25. m_ConditionTarget = new CCTNonRuined();
  26. }
  27. protected bool IsFeatherType(string itemInHandsType)
  28. {
  29. return itemInHandsType == "ChickenFeather";
  30. }
  31. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  32. {
  33. if (IsFeatherType(item.ClassName()))
  34. {
  35. //feather in hands
  36. if (target.GetObject())
  37. return (target.GetObject().ClassName() == "Ammo_ImprovisedBolt_1");
  38. }
  39. else if (target.GetObject())
  40. {
  41. // bolt in hands
  42. return IsFeatherType(target.GetObject().ClassName());
  43. }
  44. return false;
  45. }
  46. override void OnStartServer(ActionData action_data)
  47. {
  48. super.OnStartServer(action_data);
  49. m_IsFeatherInHands = IsFeatherType(action_data.m_MainItem.ClassName());
  50. m_ResultEntity = null;
  51. }
  52. override void OnFinishProgressServer(ActionData action_data)
  53. {
  54. ItemBase feather;
  55. Ammunition_Base bolt;
  56. bool added = false;
  57. if (m_IsFeatherInHands)
  58. {
  59. //feather in hands
  60. feather = action_data.m_MainItem;
  61. bolt = Ammunition_Base.Cast(action_data.m_Target.GetObject());
  62. }
  63. else
  64. {
  65. // bolt in hands
  66. bolt = Ammunition_Base.Cast(action_data.m_MainItem);
  67. feather = ItemBase.Cast(action_data.m_Target.GetObject());
  68. }
  69. if (!bolt || !feather)
  70. return;
  71. float dmg;
  72. string type;
  73. bolt.ServerAcquireCartridge(dmg, type);
  74. if (m_ResultEntity)
  75. {
  76. type = m_ResultEntity.ConfigGetString("Ammo");
  77. if (m_ResultEntity.GetAmmoCount() < m_ResultEntity.GetAmmoMax())
  78. {
  79. m_ResultEntity.ServerStoreCartridge(dmg, type);
  80. added = true;
  81. }
  82. }
  83. if (!added)
  84. {
  85. m_ResultEntity = Ammunition_Base.Cast(action_data.m_Player.SpawnEntityOnGroundRaycastDispersed("Ammo_ImprovisedBolt_2"));
  86. type = m_ResultEntity.ConfigGetString("Ammo");
  87. m_ResultEntity.ServerSetAmmoCount(0);
  88. m_ResultEntity.ServerStoreCartridge(dmg, type);
  89. m_ResultEntity.SetHealth01("", "", bolt.GetHealth01("", ""));
  90. }
  91. feather.AddQuantity(-1);
  92. }
  93. };