]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Repairing borgs now takes multiple doafters (#41638)
authorSamuka <47865393+Samuka-C@users.noreply.github.com>
Mon, 15 Dec 2025 12:15:22 +0000 (09:15 -0300)
committerGitHub <noreply@github.com>
Mon, 15 Dec 2025 12:15:22 +0000 (12:15 +0000)
* borg repair is now multiple doafters

* is a float now

* use else

* remove random new line i added for some reason

* add new line at the end of the file

* add documentation

* made repair system super robust

* borg heal faster from crit

* forgot to make it a datafield

* less overpower

* cant repair futher than the threshold for alive if not alive or dead

* fix math

* more math

* fixes

* some comentary

* more accurate

* simple solution

* new solution

* better numbers

* more accurate

* use helper function

* fine tunning the number

* better way to restart the doafter

* update AutoDoAfter

* not used

* more clear

* remove inline if

* improve helper methods

* updare pop up message

* another unused

* nuke consecutive repair bonus

* increase the repair (so it doesn't take ages to fix a borg)

* back to 10 per repair

* heal evenly

* fix for edge case

* fix

* fix

* it works now

* add / fix comments

* small clean up

* make easier to understand

* use FixedPoint2.Zero

* make it smaller

* add support for group even heal

* ops

* easier to read

* typo

* make the HealEvenly better

* rename to GetDamage

* negative value

* Update Content.Shared/Repairable/RepairableSystem.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Repairable/RepairableComponent.cs
Content.Shared/Repairable/RepairableSystem.cs
Resources/Locale/en-US/repairable/repairable-component.ftl
Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml

index bc1ccfb7bf0bbe1d685396c7b4816b68a1a4fc7a..60eb57581aab2f76c08c6f58d72b888711923760 100644 (file)
@@ -17,15 +17,26 @@ public sealed partial class RepairableComponent : Component
     /// <remarks>
     ///     If this data-field is specified, it will change damage by this amount instead of setting all damage to 0.
     ///     in order to heal/repair the damage values have to be negative.
+    ///     This will only be used if <see cref="DamageValue"/> is not null.
+    ///     If this is null and so is <see cref="DamageValue"/> then all damage will be repaired at once.
     /// </remarks>
     [DataField, AutoNetworkedField]
     public DamageSpecifier? Damage;
 
+    /// <summary>
+    /// Amount of damage to repair of the entity equaly distributed among the damage types the entity has.
+    /// </summary>
+    /// <remarks>
+    /// in order to heal/repair the damage values have to be negative.
+    /// </remarks>
+    [DataField, AutoNetworkedField]
+    public float? DamageValue;
+
     /// <summary>
     /// Cost of fuel used to repair this device.
     /// </summary>
     [DataField, AutoNetworkedField]
-    public int FuelCost = 5;
+    public float FuelCost = 5f;
 
     /// <summary>
     /// Tool quality necessary to repair this device.
@@ -39,6 +50,12 @@ public sealed partial class RepairableComponent : Component
     [DataField, AutoNetworkedField]
     public int DoAfterDelay = 1;
 
+    /// <summary>
+    /// If true and after the repair there still damage, a new doafter starts automatically
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool AutoDoAfter = true;
+
     /// <summary>
     /// A multiplier that will be applied to the above if an entity is repairing themselves.
     /// </summary>
index 7526faeb51fb59f8cc885298d81f9c5d78d8b9c5..8fbdf90ee67a4d409a9d065ff6d335308005ff8c 100644 (file)
@@ -20,10 +20,10 @@ public sealed partial class RepairableSystem : EntitySystem
     public override void Initialize()
     {
         SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
-        SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
+        SubscribeLocalEvent<RepairableComponent, RepairDoAfterEvent>(OnRepairDoAfter);
     }
 
-    private void OnRepairFinished(Entity<RepairableComponent> ent,  ref RepairFinishedEvent args)
+    private void OnRepairDoAfter(Entity<RepairableComponent> ent, ref RepairDoAfterEvent args)
     {
         if (args.Cancelled)
             return;
@@ -31,24 +31,62 @@ public sealed partial class RepairableSystem : EntitySystem
         if (!TryComp(ent.Owner, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
             return;
 
-        if (ent.Comp.Damage != null)
-        {
-            var damageChanged = _damageableSystem.ChangeDamage(ent.Owner, ent.Comp.Damage, true, false, origin: args.User);
-            _adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
-        }
-
+        if (ent.Comp.DamageValue != null)
+            RepairSomeDamage((ent, damageable), ent.Comp.DamageValue.Value, args.User);
+        else if (ent.Comp.Damage != null)
+            RepairSomeDamage((ent, damageable), ent.Comp.Damage, args.User);
         else
+            RepairAllDamage((ent, damageable), args.User);
+
+        args.Repeat = ent.Comp.AutoDoAfter && damageable.TotalDamage > 0;
+        args.Args.Event.Repeat = args.Repeat;
+        args.Handled = true;
+
+        if (!args.Repeat)
         {
-            // Repair all damage
-            _damageableSystem.SetAllDamage((ent.Owner, damageable), 0);
-            _adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} back to full health");
+            var str = Loc.GetString("comp-repairable-repair", ("target", ent.Owner), ("tool", args.Used!));
+            _popup.PopupClient(str, ent.Owner, args.User);
+
+            var ev = new RepairedEvent(ent, args.User);
+            RaiseLocalEvent(ent.Owner, ref ev);
         }
+    }
 
-        var str = Loc.GetString("comp-repairable-repair", ("target", ent.Owner), ("tool", args.Used!));
-        _popup.PopupClient(str, ent.Owner, args.User);
+    /// <summary>
+    /// Repairs some damage of a entity.
+    /// The healed amount will be evenly distributed among all damage types the entity has.
+    /// If one of the damage types of the entity is too low. it will heal that completly and distribute the excess healing among the other damage types
+    /// </summary>
+    /// <param name="ent">entity to be repaired</param>
+    /// <param name="damageAmount">how much damage to repair (value have to be negative to repair)</param>
+    /// <param name="user">who is doing the repair</param>
+    private void RepairSomeDamage(Entity<DamageableComponent?> ent, float damageAmount, EntityUid user)
+    {
+        var damageChanged = _damageableSystem.HealEvenly(ent.Owner, damageAmount, origin: user);
+        _adminLogger.Add(LogType.Healed, $"{ToPrettyString(user):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
+    }
 
-        var ev = new RepairedEvent(ent, args.User);
-        RaiseLocalEvent(ent.Owner, ref ev);
+    /// <summary>
+    /// Repairs some damage of a entity
+    /// </summary>
+    /// <param name="ent">entity to be repaired</param>
+    /// <param name="damageAmount">how much damage to repair (values have to be negative to repair)</param>
+    /// <param name="user">who is doing the repair</param>
+    private void RepairSomeDamage(Entity<DamageableComponent?> ent, Damage.DamageSpecifier damageAmount, EntityUid user)
+    {
+        var damageChanged = _damageableSystem.ChangeDamage(ent.Owner, damageAmount, true, false, origin: user);
+        _adminLogger.Add(LogType.Healed, $"{ToPrettyString(user):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
+    }
+
+    /// <summary>
+    /// Repairs all damage of a entity
+    /// </summary>
+    /// <param name="ent">entity to be repaired</param>
+    /// <param name="user">who is doing the repair</param>
+    private void RepairAllDamage(Entity<DamageableComponent?> ent, EntityUid user)
+    {
+        _damageableSystem.ClearAllDamage(ent);
+        _adminLogger.Add(LogType.Healed, $"{ToPrettyString(user):user} repaired {ToPrettyString(ent.Owner):target} back to full health");
     }
 
     private void Repair(Entity<RepairableComponent> ent, ref InteractUsingEvent args)
@@ -72,7 +110,7 @@ public sealed partial class RepairableSystem : EntitySystem
         }
 
         // Run the repairing doafter
-        args.Handled = _toolSystem.UseTool(args.Used, args.User, ent.Owner, delay, ent.Comp.QualityNeeded, new RepairFinishedEvent(), ent.Comp.FuelCost);
+        args.Handled = _toolSystem.UseTool(args.Used, args.User, ent.Owner, delay, ent.Comp.QualityNeeded, new RepairDoAfterEvent(), ent.Comp.FuelCost);
     }
 }
 
@@ -84,5 +122,9 @@ public sealed partial class RepairableSystem : EntitySystem
 [ByRefEvent]
 public readonly record struct RepairedEvent(Entity<RepairableComponent> Ent, EntityUid User);
 
+/// <summary>
+/// Do after event started when you try to fix a entity with RepairableComponent.
+/// This doafter is repeated if the entity has <see cref="AutoDoAfter"> set to true and not all damage was fixed yet.
+/// </summary>
 [Serializable, NetSerializable]
-public sealed partial class RepairFinishedEvent : SimpleDoAfterEvent;
+public sealed partial class RepairDoAfterEvent : SimpleDoAfterEvent;
index 039e4a1016fc2529c00fd3cf37206848c07a6c51..8e2e0e2ee1103cdf3ec1f50a55e6e30c02b0280a 100644 (file)
@@ -1,7 +1,7 @@
 ### Interaction Messages
 
 # Shown when repairing something
-comp-repairable-repair = You repair {PROPER($target) ->
+comp-repairable-repair = You finish repairing {PROPER($target) ->
   [true] {""}
   *[false] the{" "}
 }{$target} with {PROPER($tool) ->
index 3c74c007e0cd7b20642dd6f7d8190708dfb3026d..adbfd560b445ab9fdd96fe1088e48b77b59bd99f 100644 (file)
     - Science
   - type: ZombieImmune
   - type: Repairable
-    doAfterDelay: 10
+    damageValue: -10 # 10 seconds to repair from crit
+    doAfterDelay: 1
+    fuelCost: 0.5
     allowSelfRepair: false
   - type: BorgChassis
   - type: LockingWhitelist
     - Mothership
     - Xenoborg
     - Binary
-  - type: Repairable
-    doAfterDelay: 13 # 25% more HP, so 30% more time to heal
   - type: BorgChassis
     maxModules: 0
     hasMindState: robot_e
index 272c80e0f1bc903fc1b7cde4baae79a635e4e924..991a03be962c04c36d705d6a1decdc3928f16bfe 100644 (file)
         - cell_slot
       - !type:DoActsBehavior
         acts: [ "Destruction" ]
-  - type: Repairable
-    doAfterDelay: 25 # more HP, more time to heal
   - type: ContainerFill
     containers:
       borg_brain: