actionmountbarbedwire.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 OnStartServer(ActionData action_data)
  93. {
  94. super.OnStartServer(action_data);
  95. BarbedWire wire = GetBarbedWire(action_data.m_Target);
  96. if (wire && wire.GetLoopDeploySoundset() != string.Empty)
  97. wire.StartItemSoundServer(SoundConstants.ITEM_DEPLOY_LOOP);
  98. }
  99. override void OnEndServer(ActionData action_data)
  100. {
  101. BarbedWire wire = GetBarbedWire(action_data.m_Target);
  102. if (wire && wire.GetLoopDeploySoundset() != string.Empty)
  103. wire.StopItemSoundServer(SoundConstants.ITEM_DEPLOY_LOOP);
  104. super.OnEndServer(action_data);
  105. }
  106. override void OnFinishProgressServer(ActionData action_data)
  107. {
  108. BarbedWireActionData actionDataBW = BarbedWireActionData.Cast(action_data);
  109. BaseBuildingBase base_building = BaseBuildingBase.Cast(actionDataBW.m_Target.GetObject());
  110. //mount and refresh parent
  111. BarbedWire wire = BarbedWire.Cast(base_building.FindAttachmentBySlotName(actionDataBW.m_SlotName));
  112. wire.SetMountedState(true);
  113. if (wire.GetDeploySoundset() != string.Empty)
  114. wire.StartItemSoundServer(SoundConstants.ITEM_DEPLOY);
  115. //solution for DamageSystem's case sensitivity
  116. string zone = "invalid";
  117. array<string> zones = new array<string>;
  118. zones.Copy(base_building.GetEntityDamageZoneMap().GetKeyArray());
  119. string tmp = "";
  120. string test = "";
  121. for (int i = 0; i < zones.Count(); i++)
  122. {
  123. tmp = zones.Get(i);
  124. test = tmp;
  125. test.ToLower();
  126. if (test == actionDataBW.m_SlotName)
  127. {
  128. zone = tmp;
  129. break;
  130. }
  131. }
  132. base_building.SetHealth01(zone,"Health",wire.GetHealth01("","Health")); //attachment slot names and damagezone names must match
  133. }
  134. BarbedWire GetBarbedWire(ActionTarget target)
  135. {
  136. BaseBuildingBase base_building = BaseBuildingBase.Cast(target.GetObject());
  137. BarbedWire wire;
  138. if (Class.CastTo(wire,base_building.FindAttachmentBySlotName(GetZoneSelection(target))))
  139. {
  140. return wire;
  141. }
  142. return null;
  143. }
  144. string GetZoneSelection(ActionTarget target)
  145. {
  146. BaseBuildingBase base_building = BaseBuildingBase.Cast(target.GetObject());
  147. return base_building.GetActionComponentName(target.GetComponentIndex());
  148. }
  149. override string GetAdminLogMessage(ActionData action_data)
  150. {
  151. string message = string.Format("Player %1 Mounted BarbedWire on %2", action_data.m_Player, action_data.m_Target.GetObject().ClassName());
  152. return message;
  153. }
  154. }