From d53fe69b863a33b7146d6ec22154e8d1f9910649 Mon Sep 17 00:00:00 2001
From: Samuka <47865393+Samuka-C@users.noreply.github.com>
Date: Mon, 15 Dec 2025 09:15:22 -0300
Subject: [PATCH] Repairing borgs now takes multiple doafters (#41638)
* 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>
---
.../Repairable/RepairableComponent.cs | 19 ++++-
Content.Shared/Repairable/RepairableSystem.cs | 76 ++++++++++++++-----
.../en-US/repairable/repairable-component.ftl | 2 +-
.../Mobs/Cyborgs/base_borg_chassis.yml | 6 +-
.../Entities/Mobs/Cyborgs/xenoborgs.yml | 2 -
5 files changed, 81 insertions(+), 24 deletions(-)
diff --git a/Content.Shared/Repairable/RepairableComponent.cs b/Content.Shared/Repairable/RepairableComponent.cs
index bc1ccfb7bf..60eb57581a 100644
--- a/Content.Shared/Repairable/RepairableComponent.cs
+++ b/Content.Shared/Repairable/RepairableComponent.cs
@@ -17,15 +17,26 @@ public sealed partial class RepairableComponent : Component
///
/// 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 is not null.
+ /// If this is null and so is then all damage will be repaired at once.
///
[DataField, AutoNetworkedField]
public DamageSpecifier? Damage;
+ ///
+ /// Amount of damage to repair of the entity equaly distributed among the damage types the entity has.
+ ///
+ ///
+ /// in order to heal/repair the damage values have to be negative.
+ ///
+ [DataField, AutoNetworkedField]
+ public float? DamageValue;
+
///
/// Cost of fuel used to repair this device.
///
[DataField, AutoNetworkedField]
- public int FuelCost = 5;
+ public float FuelCost = 5f;
///
/// Tool quality necessary to repair this device.
@@ -39,6 +50,12 @@ public sealed partial class RepairableComponent : Component
[DataField, AutoNetworkedField]
public int DoAfterDelay = 1;
+ ///
+ /// If true and after the repair there still damage, a new doafter starts automatically
+ ///
+ [DataField, AutoNetworkedField]
+ public bool AutoDoAfter = true;
+
///
/// A multiplier that will be applied to the above if an entity is repairing themselves.
///
diff --git a/Content.Shared/Repairable/RepairableSystem.cs b/Content.Shared/Repairable/RepairableSystem.cs
index 7526faeb51..8fbdf90ee6 100644
--- a/Content.Shared/Repairable/RepairableSystem.cs
+++ b/Content.Shared/Repairable/RepairableSystem.cs
@@ -20,10 +20,10 @@ public sealed partial class RepairableSystem : EntitySystem
public override void Initialize()
{
SubscribeLocalEvent(Repair);
- SubscribeLocalEvent(OnRepairFinished);
+ SubscribeLocalEvent(OnRepairDoAfter);
}
- private void OnRepairFinished(Entity ent, ref RepairFinishedEvent args)
+ private void OnRepairDoAfter(Entity 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);
+ ///
+ /// 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
+ ///
+ /// entity to be repaired
+ /// how much damage to repair (value have to be negative to repair)
+ /// who is doing the repair
+ private void RepairSomeDamage(Entity 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);
+ ///
+ /// Repairs some damage of a entity
+ ///
+ /// entity to be repaired
+ /// how much damage to repair (values have to be negative to repair)
+ /// who is doing the repair
+ private void RepairSomeDamage(Entity 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()}");
+ }
+
+ ///
+ /// Repairs all damage of a entity
+ ///
+ /// entity to be repaired
+ /// who is doing the repair
+ private void RepairAllDamage(Entity 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 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 Ent, EntityUid User);
+///
+/// Do after event started when you try to fix a entity with RepairableComponent.
+/// This doafter is repeated if the entity has set to true and not all damage was fixed yet.
+///
[Serializable, NetSerializable]
-public sealed partial class RepairFinishedEvent : SimpleDoAfterEvent;
+public sealed partial class RepairDoAfterEvent : SimpleDoAfterEvent;
diff --git a/Resources/Locale/en-US/repairable/repairable-component.ftl b/Resources/Locale/en-US/repairable/repairable-component.ftl
index 039e4a1016..8e2e0e2ee1 100644
--- a/Resources/Locale/en-US/repairable/repairable-component.ftl
+++ b/Resources/Locale/en-US/repairable/repairable-component.ftl
@@ -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) ->
diff --git a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
index 3c74c007e0..adbfd560b4 100644
--- a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
+++ b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
@@ -103,7 +103,9 @@
- 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
@@ -453,8 +455,6 @@
- Mothership
- Xenoborg
- Binary
- - type: Repairable
- doAfterDelay: 13 # 25% more HP, so 30% more time to heal
- type: BorgChassis
maxModules: 0
hasMindState: robot_e
diff --git a/Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml b/Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml
index 272c80e0f1..991a03be96 100644
--- a/Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml
+++ b/Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml
@@ -129,8 +129,6 @@
- cell_slot
- !type:DoActsBehavior
acts: [ "Destruction" ]
- - type: Repairable
- doAfterDelay: 25 # more HP, more time to heal
- type: ContainerFill
containers:
borg_brain:
--
2.52.0