actionrepairvehiclepartbase.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. class RepairVehiclePartActionReciveData : ActionReciveData
  2. {
  3. string m_DamageZoneRecived;
  4. }
  5. class RepairVehiclePartActionData : ActionData
  6. {
  7. string m_DamageZone;
  8. }
  9. class ActionRepairVehiclePartCB : ActionContinuousBaseCB
  10. {
  11. override void CreateActionComponent()
  12. {
  13. m_ActionData.m_ActionComponent = new CAContinuousRepeat(UATimeSpent.BASEBUILDING_REPAIR_FAST);
  14. }
  15. };
  16. class ActionRepairVehiclePartBase : ActionContinuousBase
  17. {
  18. protected string m_CurrentDamageZone; // needs to be assigned in action condition so it can be properly written to context
  19. override void CreateConditionComponents()
  20. {
  21. m_ConditionItem = new CCINonRuined();
  22. m_ConditionTarget = new CCTCursor(UAMaxDistances.REPAIR);
  23. }
  24. override void OnFinishProgressServer(ActionData action_data)
  25. {
  26. AdjustVehicleHealthServer(action_data);
  27. AdjustItemQuantityServer(action_data);
  28. }
  29. protected void AdjustVehicleHealthServer(ActionData action_data)
  30. {
  31. Object tgObject = action_data.m_Target.GetObject();
  32. string damageZone = RepairVehiclePartActionData.Cast(action_data).m_DamageZone;
  33. if (!GetGame().IsMultiplayer())
  34. damageZone = m_CurrentDamageZone;
  35. if (tgObject && damageZone != "")
  36. {
  37. Transport vehicle = Transport.Cast(tgObject);
  38. if (vehicle)
  39. {
  40. int newDmgLevel = Math.Clamp(vehicle.GetHealthLevel(damageZone) - 1, GameConstants.STATE_WORN, GameConstants.STATE_RUINED);
  41. float zoneMax = vehicle.GetMaxHealth(damageZone, "");
  42. float randomValue = Math.RandomFloatInclusive(zoneMax * 0.05, zoneMax * 0.15);
  43. switch (newDmgLevel)
  44. {
  45. case GameConstants.STATE_BADLY_DAMAGED:
  46. vehicle.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_RUINED_VALUE) + randomValue);
  47. break;
  48. case GameConstants.STATE_DAMAGED:
  49. vehicle.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE) + randomValue);
  50. break;
  51. case GameConstants.STATE_WORN:
  52. vehicle.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_DAMAGED_VALUE) + randomValue);
  53. break;
  54. }
  55. }
  56. }
  57. }
  58. protected void AdjustItemQuantityServer(ActionData action_data)
  59. {
  60. if (action_data.m_MainItem.HasQuantity())
  61. {
  62. if (action_data.m_MainItem.GetQuantity() > 1)
  63. {
  64. int qnt = action_data.m_MainItem.GetQuantity() - action_data.m_MainItem.GetQuantityMax() * 0.25;
  65. action_data.m_MainItem.SetQuantity(qnt);
  66. }
  67. else
  68. {
  69. action_data.m_MainItem.Delete();
  70. }
  71. }
  72. }
  73. override ActionData CreateActionData()
  74. {
  75. RepairVehiclePartActionData actionData = new RepairVehiclePartActionData();
  76. return actionData;
  77. }
  78. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  79. {
  80. super.WriteToContext(ctx, action_data);
  81. RepairVehiclePartActionData repairActionData;
  82. if (HasTarget() && Class.CastTo(repairActionData, action_data))
  83. {
  84. repairActionData.m_DamageZone = m_CurrentDamageZone;
  85. ctx.Write(repairActionData.m_DamageZone);
  86. }
  87. }
  88. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
  89. {
  90. if (!action_recive_data)
  91. {
  92. action_recive_data = new RepairVehiclePartActionReciveData();
  93. }
  94. super.ReadFromContext(ctx, action_recive_data);
  95. RepairVehiclePartActionReciveData recieveDataRepair = RepairVehiclePartActionReciveData.Cast(action_recive_data);
  96. if (HasTarget())
  97. {
  98. string zone;
  99. if (!ctx.Read(zone))
  100. {
  101. return false;
  102. }
  103. recieveDataRepair.m_DamageZoneRecived = zone;
  104. }
  105. return true;
  106. }
  107. override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
  108. {
  109. super.HandleReciveData(action_recive_data, action_data);
  110. RepairVehiclePartActionReciveData recieveDataRepair = RepairVehiclePartActionReciveData.Cast(action_recive_data);
  111. RepairVehiclePartActionData.Cast(action_data).m_DamageZone = recieveDataRepair.m_DamageZoneRecived;
  112. }
  113. };