actionrepairtentpart.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. class RepairTentPartActionReciveData : ActionReciveData
  2. {
  3. string m_DamageZoneRecived;
  4. }
  5. class RepairTentPartActionData : ActionData
  6. {
  7. string m_DamageZone;
  8. }
  9. class ActionRepairTentPartCB : ActionContinuousBaseCB
  10. {
  11. override void CreateActionComponent()
  12. {
  13. m_ActionData.m_ActionComponent = new CAContinuousRepeat(UATimeSpent.BASEBUILDING_REPAIR_FAST);
  14. }
  15. };
  16. class ActionRepairTentPart: ActionContinuousBase
  17. {
  18. typename m_LastValidType;
  19. string m_CurrentDamageZone = "";
  20. int m_LastValidComponentIndex = -1;
  21. void ActionRepairTentPart()
  22. {
  23. m_CallbackClass = ActionRepairTentPartCB;
  24. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  25. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
  26. m_FullBody = true;
  27. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  28. m_Text = "#repair";
  29. }
  30. override void CreateConditionComponents()
  31. {
  32. m_ConditionItem = new CCINonRuined; //To change?
  33. m_ConditionTarget = new CCTCursorParent(UAMaxDistances.DEFAULT);
  34. }
  35. override bool IsUsingProxies()
  36. {
  37. return true;
  38. }
  39. override bool HasTarget()
  40. {
  41. return true;
  42. }
  43. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  44. {
  45. //m_CurrentDamageZone = "";
  46. Object targetObject = target.GetObject();
  47. Object targetParent = target.GetParent();
  48. if ( !targetParent || !targetParent.IsInherited(TentBase) )
  49. return false;
  50. if ( player && targetObject && targetParent )
  51. {
  52. array<string> selections = new array<string>;
  53. PluginRepairing module_repairing;
  54. Class.CastTo(module_repairing, GetPlugin(PluginRepairing));
  55. targetObject.GetActionComponentNameList(target.GetComponentIndex(), selections, "view");
  56. TentBase tent = TentBase.Cast( targetParent );
  57. if (m_LastValidType != targetObject.Type() || m_LastValidComponentIndex != target.GetComponentIndex() || m_CurrentDamageZone == "" || m_CurrentDamageZone == "Body")
  58. {
  59. string damageZone = "";
  60. for (int s = 0; s < selections.Count(); s++)
  61. {
  62. if ( DamageSystem.GetDamageZoneFromComponentName(tent, selections[s], damageZone) ) //NOTE: relevant fire geometry and view geometry selection names MUST match in order to get a valid damage zone
  63. {
  64. //Print("#" + s + " damageZone: " + damageZone);
  65. if (tent.GetHealthLevel("" + damageZone) == GameConstants.STATE_RUINED )
  66. {
  67. m_CurrentDamageZone = damageZone;
  68. m_LastValidComponentIndex = target.GetComponentIndex();
  69. break;
  70. }else
  71. continue;
  72. }
  73. }
  74. if ( damageZone != "" && m_CurrentDamageZone != "Body" ) //This may seem like a duplicate but is required to work properly
  75. {
  76. m_CurrentDamageZone = damageZone;
  77. m_LastValidComponentIndex = target.GetComponentIndex();
  78. }
  79. }
  80. if ( m_CurrentDamageZone != "" && m_CurrentDamageZone != "Body" && tent.GetHealthLevel("" + damageZone) == GameConstants.STATE_RUINED )
  81. {
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87. override void OnFinishProgressServer( ActionData action_data )
  88. {
  89. Object targetParent = action_data.m_Target.GetParent();
  90. ItemBase usedItem = action_data.m_MainItem;
  91. string damageZone = RepairTentPartActionData.Cast(action_data).m_DamageZone;
  92. if (!GetGame().IsMultiplayer())
  93. damageZone = m_CurrentDamageZone;
  94. if ( targetParent && targetParent.IsInherited(TentBase) && damageZone != "" )
  95. {
  96. TentBase tent = TentBase.Cast( targetParent );
  97. float m_RepairedLevel = usedItem.GetHealthLevel();
  98. tent.SetAllowDamage(true);
  99. targetParent.SetHealth01("" + damageZone, "", targetParent.GetHealthLevelValue(m_RepairedLevel));
  100. tent.ProcessInvulnerabilityCheck(tent.GetInvulnerabilityTypeString());
  101. if (usedItem.GetQuantity() > 1)
  102. {
  103. //Not really clean, but will do for now
  104. int val = usedItem.GetQuantity();
  105. val--;
  106. usedItem.SetQuantity(val);
  107. }
  108. else
  109. usedItem.Delete();
  110. }
  111. }
  112. override ActionData CreateActionData()
  113. {
  114. RepairTentPartActionData action_data = new RepairTentPartActionData;
  115. return action_data;
  116. }
  117. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  118. {
  119. super.WriteToContext(ctx, action_data);
  120. RepairTentPartActionData repair_action_data;
  121. if( HasTarget() && Class.CastTo(repair_action_data,action_data) )
  122. {
  123. repair_action_data.m_DamageZone = m_CurrentDamageZone;
  124. ctx.Write(repair_action_data.m_DamageZone);
  125. }
  126. }
  127. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
  128. {
  129. if(!action_recive_data)
  130. {
  131. action_recive_data = new RepairTentPartActionReciveData;
  132. }
  133. super.ReadFromContext(ctx, action_recive_data);
  134. RepairTentPartActionReciveData recive_data_repair = RepairTentPartActionReciveData.Cast(action_recive_data);
  135. if( HasTarget() )
  136. {
  137. string zone;
  138. if ( !ctx.Read(zone) )
  139. return false;
  140. recive_data_repair.m_DamageZoneRecived = zone;
  141. }
  142. return true;
  143. }
  144. override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
  145. {
  146. super.HandleReciveData(action_recive_data, action_data);
  147. RepairTentPartActionReciveData recive_data_repair = RepairTentPartActionReciveData.Cast(action_recive_data);
  148. RepairTentPartActionData.Cast(action_data).m_DamageZone = recive_data_repair.m_DamageZoneRecived;
  149. }
  150. };