actionmountbarbedwire.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. class BarbedWireActionReceiveData : ActionReciveData
  2. {
  3. string m_SlotName;
  4. }
  5. class BarbedWireActionData : ActionData
  6. {
  7. string m_SlotName;
  8. }
  9. class ActionMountBarbedWireCB : ActionContinuousBaseCB
  10. {
  11. override void CreateActionComponent()
  12. {
  13. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.DEFAULT_CONSTRUCT);
  14. }
  15. };
  16. class ActionMountBarbedWire: ActionContinuousBase
  17. {
  18. float m_DamageAmount; //DEPRECATED
  19. string m_SlotName; //DEPRECATED
  20. void ActionMountBarbedWire()
  21. {
  22. m_CallbackClass = ActionMountBarbedWireCB;
  23. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
  24. m_FullBody = true;
  25. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  26. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_HIGH;
  27. m_Text = "#mount";
  28. }
  29. override void CreateConditionComponents()
  30. {
  31. m_ConditionItem = new CCINonRuined;
  32. m_ConditionTarget = new CCTNonRuined(UAMaxDistances.BASEBUILDING);
  33. }
  34. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  35. {
  36. BaseBuildingBase base_building = BaseBuildingBase.Cast(target.GetObject());
  37. if (base_building && base_building.CanUseConstruction() && base_building.CanUseConstructionBuild())
  38. {
  39. if (!base_building.IsPlayerInside(player,""))
  40. return false;
  41. BarbedWire barbed_wire = GetBarbedWire(target);
  42. return (barbed_wire && !barbed_wire.IsMounted() && !barbed_wire.IsRuined());
  43. }
  44. return false;
  45. }
  46. override ActionData CreateActionData()
  47. {
  48. BarbedWireActionData action_data = new BarbedWireActionData();
  49. return action_data;
  50. }
  51. override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
  52. {
  53. if (super.SetupAction(player, target, item, action_data, extra_data))
  54. {
  55. #ifndef SERVER
  56. BarbedWireActionData actionDataBW = BarbedWireActionData.Cast(action_data);
  57. actionDataBW.m_SlotName = GetZoneSelection(target);
  58. #endif
  59. return true;
  60. }
  61. return false;
  62. }
  63. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  64. {
  65. super.WriteToContext(ctx, action_data);
  66. BarbedWireActionData actionDataBW
  67. if (Class.CastTo(actionDataBW,action_data))
  68. {
  69. ctx.Write(actionDataBW.m_SlotName);
  70. }
  71. }
  72. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
  73. {
  74. if (!action_recive_data)
  75. {
  76. action_recive_data = new BarbedWireActionReceiveData;
  77. }
  78. super.ReadFromContext(ctx, action_recive_data);
  79. BarbedWireActionReceiveData receiveDataBW = BarbedWireActionReceiveData.Cast(action_recive_data);
  80. string slotName;
  81. if (!ctx.Read(slotName))
  82. return false;
  83. receiveDataBW.m_SlotName = slotName;
  84. return true;
  85. }
  86. override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
  87. {
  88. super.HandleReciveData(action_recive_data, action_data);
  89. BarbedWireActionReceiveData receiveDataBW = BarbedWireActionReceiveData.Cast(action_recive_data);
  90. BarbedWireActionData.Cast(action_data).m_SlotName = receiveDataBW.m_SlotName;
  91. }
  92. override void OnFinishProgressServer(ActionData action_data)
  93. {
  94. BarbedWireActionData actionDataBW = BarbedWireActionData.Cast(action_data);
  95. BaseBuildingBase base_building = BaseBuildingBase.Cast(actionDataBW.m_Target.GetObject());
  96. //mount and refresh parent
  97. BarbedWire wire = BarbedWire.Cast(base_building.FindAttachmentBySlotName(actionDataBW.m_SlotName));
  98. wire.SetMountedState(true);
  99. //solution for DamageSystem's case sensitivity
  100. string zone = "invalid";
  101. array<string> zones = new array<string>;
  102. zones.Copy(base_building.GetEntityDamageZoneMap().GetKeyArray());
  103. string tmp = "";
  104. string test = "";
  105. for (int i = 0; i < zones.Count(); i++)
  106. {
  107. tmp = zones.Get(i);
  108. test = tmp;
  109. test.ToLower();
  110. if (test == actionDataBW.m_SlotName)
  111. {
  112. zone = tmp;
  113. break;
  114. }
  115. }
  116. base_building.SetHealth01(zone,"Health",wire.GetHealth01("","Health")); //attachment slot names and damagezone names must match
  117. }
  118. BarbedWire GetBarbedWire(ActionTarget target)
  119. {
  120. BaseBuildingBase base_building = BaseBuildingBase.Cast(target.GetObject());
  121. BarbedWire wire;
  122. if (Class.CastTo(wire,base_building.FindAttachmentBySlotName(GetZoneSelection(target))))
  123. {
  124. return wire;
  125. }
  126. return null;
  127. }
  128. string GetZoneSelection(ActionTarget target)
  129. {
  130. BaseBuildingBase base_building = BaseBuildingBase.Cast(target.GetObject());
  131. return base_building.GetActionComponentName(target.GetComponentIndex());
  132. }
  133. override string GetAdminLogMessage(ActionData action_data)
  134. {
  135. string message = string.Format("Player %1 Mounted BarbedWire on %2", action_data.m_Player, action_data.m_Target.GetObject().ClassName());
  136. return message;
  137. }
  138. }