]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict RepairableSystem (#38886)
authorKyle Tyo <36606155+VerinSenpai@users.noreply.github.com>
Thu, 10 Jul 2025 02:39:34 +0000 (22:39 -0400)
committerGitHub <noreply@github.com>
Thu, 10 Jul 2025 02:39:34 +0000 (04:39 +0200)
* commit

* Update SharedRepairableSystem.cs

* compo

* final touches.

* Update RepairableComponent.cs

* Update RepairableSystem.cs

* Update Content.Shared/Repairable/RepairableSystem.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Server/Materials/MaterialReclaimerSystem.cs
Content.Server/Repairable/RepairableComponent.cs [deleted file]
Content.Server/Repairable/RepairableSystem.cs [deleted file]
Content.Server/Turrets/DeployableTurretSystem.cs
Content.Shared/Repairable/RepairableComponent.cs [new file with mode: 0644]
Content.Shared/Repairable/RepairableSystem.cs [new file with mode: 0644]
Content.Shared/Repairable/SharedRepairableSystem.cs [deleted file]

index 1e9acbd56811c44c8284350ab62d6756586ecf07..7de0d630e0bc6731d19a98b5d195704efb2a0319 100644 (file)
@@ -2,7 +2,6 @@ using Content.Server.Administration.Logs;
 using Content.Server.Fluids.EntitySystems;
 using Content.Server.Ghost;
 using Content.Server.Popups;
-using Content.Server.Repairable;
 using Content.Server.Stack;
 using Content.Server.Wires;
 using Content.Shared.Body.Systems;
@@ -19,6 +18,7 @@ using Content.Shared.Materials;
 using Content.Shared.Mind;
 using Content.Shared.Nutrition.EntitySystems;
 using Content.Shared.Power;
+using Content.Shared.Repairable;
 using Content.Shared.Stacks;
 using Robust.Server.GameObjects;
 using Robust.Shared.Player;
diff --git a/Content.Server/Repairable/RepairableComponent.cs b/Content.Server/Repairable/RepairableComponent.cs
deleted file mode 100644 (file)
index bab70f6..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-using Content.Shared.Damage;
-using Content.Shared.Tools;
-using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-
-namespace Content.Server.Repairable
-{
-    [RegisterComponent]
-    public sealed partial class RepairableComponent : Component
-    {
-        /// <summary>
-        ///     All the damage to change information is stored in this <see cref="DamageSpecifier"/>.
-        /// </summary>
-        /// <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.
-        /// </remarks>
-        [DataField]
-        public DamageSpecifier? Damage;
-
-        [DataField]
-        public int FuelCost = 5;
-
-        [DataField]
-        public ProtoId<ToolQualityPrototype> QualityNeeded = "Welding";
-
-        [DataField]
-        public int DoAfterDelay = 1;
-
-        /// <summary>
-        /// A multiplier that will be applied to the above if an entity is repairing themselves.
-        /// </summary>
-        [DataField]
-        public float SelfRepairPenalty = 3f;
-
-        /// <summary>
-        /// Whether or not an entity is allowed to repair itself.
-        /// </summary>
-        [DataField]
-        public bool AllowSelfRepair = true;
-    }
-}
diff --git a/Content.Server/Repairable/RepairableSystem.cs b/Content.Server/Repairable/RepairableSystem.cs
deleted file mode 100644 (file)
index c05a13c..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-using Content.Server.Administration.Logs;
-using Content.Shared.Damage;
-using Content.Shared.Database;
-using Content.Shared.Interaction;
-using Content.Shared.Popups;
-using Content.Shared.Repairable;
-using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
-
-namespace Content.Server.Repairable
-{
-    public sealed class RepairableSystem : SharedRepairableSystem
-    {
-        [Dependency] private readonly SharedToolSystem _toolSystem = default!;
-        [Dependency] private readonly DamageableSystem _damageableSystem = default!;
-        [Dependency] private readonly SharedPopupSystem _popup = default!;
-        [Dependency] private readonly IAdminLogManager _adminLogger= default!;
-
-        public override void Initialize()
-        {
-            SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
-            SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
-        }
-
-        private void OnRepairFinished(EntityUid uid, RepairableComponent component, RepairFinishedEvent args)
-        {
-            if (args.Cancelled)
-                return;
-
-            if (!TryComp(uid, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
-                return;
-
-            if (component.Damage != null)
-            {
-                var damageChanged = _damageableSystem.TryChangeDamage(uid, component.Damage, true, false, origin: args.User);
-                _adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} by {damageChanged?.GetTotal()}");
-            }
-
-            else
-            {
-                // Repair all damage
-                _damageableSystem.SetAllDamage(uid, damageable, 0);
-                _adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} back to full health");
-            }
-
-            var str = Loc.GetString("comp-repairable-repair",
-                ("target", uid),
-                ("tool", args.Used!));
-            _popup.PopupEntity(str, uid, args.User);
-
-            var ev = new RepairedEvent((uid, component), args.User);
-            RaiseLocalEvent(uid, ref ev);
-        }
-
-        public async void Repair(EntityUid uid, RepairableComponent component, InteractUsingEvent args)
-        {
-            if (args.Handled)
-                return;
-
-            // Only try repair the target if it is damaged
-            if (!TryComp<DamageableComponent>(uid, out var damageable) || damageable.TotalDamage == 0)
-                return;
-
-            float delay = component.DoAfterDelay;
-
-            // Add a penalty to how long it takes if the user is repairing itself
-            if (args.User == args.Target)
-            {
-                if (!component.AllowSelfRepair)
-                    return;
-
-                delay *= component.SelfRepairPenalty;
-            }
-
-            // Run the repairing doafter
-            args.Handled = _toolSystem.UseTool(args.Used, args.User, uid, delay, component.QualityNeeded, new RepairFinishedEvent(), component.FuelCost);
-        }
-    }
-
-    /// <summary>
-    /// Event raised on an entity when its successfully repaired.
-    /// </summary>
-    /// <param name="Ent"></param>
-    /// <param name="User"></param>
-    [ByRefEvent]
-    public readonly record struct RepairedEvent(Entity<RepairableComponent> Ent, EntityUid User);
-
-}
index 9bb382badf00e80a0c076716fc4a42ccccaeac6d..2599285bdc47ef102ba0b6c7c86a1d25cd9bc9d9 100644 (file)
@@ -3,7 +3,6 @@ using Content.Server.DeviceNetwork.Systems;
 using Content.Server.NPC.HTN;
 using Content.Server.NPC.HTN.PrimitiveTasks.Operators.Combat.Ranged;
 using Content.Server.Power.Components;
-using Content.Server.Repairable;
 using Content.Server.TurretController;
 using Content.Shared.Access;
 using Content.Shared.Destructible;
@@ -11,6 +10,7 @@ using Content.Shared.DeviceNetwork;
 using Content.Shared.DeviceNetwork.Components;
 using Content.Shared.DeviceNetwork.Events;
 using Content.Shared.Power;
+using Content.Shared.Repairable;
 using Content.Shared.Turrets;
 using Content.Shared.Weapons.Ranged.Components;
 using Content.Shared.Weapons.Ranged.Events;
diff --git a/Content.Shared/Repairable/RepairableComponent.cs b/Content.Shared/Repairable/RepairableComponent.cs
new file mode 100644 (file)
index 0000000..bc1ccfb
--- /dev/null
@@ -0,0 +1,53 @@
+using Content.Shared.Damage;
+using Content.Shared.Tools;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Repairable;
+
+/// <summary>
+/// Use this component to mark a device as repairable.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class RepairableComponent : Component
+{
+    /// <summary>
+    ///     All the damage to change information is stored in this <see cref="DamageSpecifier"/>.
+    /// </summary>
+    /// <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.
+    /// </remarks>
+    [DataField, AutoNetworkedField]
+    public DamageSpecifier? Damage;
+
+    /// <summary>
+    /// Cost of fuel used to repair this device.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public int FuelCost = 5;
+
+    /// <summary>
+    /// Tool quality necessary to repair this device.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public ProtoId<ToolQualityPrototype> QualityNeeded = "Welding";
+
+    /// <summary>
+    /// The base tool use delay (seconds). This will be modified by the tool's quality
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public int DoAfterDelay = 1;
+
+    /// <summary>
+    /// A multiplier that will be applied to the above if an entity is repairing themselves.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float SelfRepairPenalty = 3f;
+
+    /// <summary>
+    /// Whether an entity is allowed to repair itself.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool AllowSelfRepair = true;
+}
diff --git a/Content.Shared/Repairable/RepairableSystem.cs b/Content.Shared/Repairable/RepairableSystem.cs
new file mode 100644 (file)
index 0000000..7a0f01b
--- /dev/null
@@ -0,0 +1,87 @@
+using Content.Shared.Administration.Logs;
+using Content.Shared.Damage;
+using Content.Shared.Database;
+using Content.Shared.DoAfter;
+using Content.Shared.Interaction;
+using Content.Shared.Popups;
+using Content.Shared.Tools.Systems;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.Repairable;
+
+public sealed partial class RepairableSystem : EntitySystem
+{
+    [Dependency] private readonly SharedToolSystem _toolSystem = default!;
+    [Dependency] private readonly DamageableSystem _damageableSystem = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
+        SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
+    }
+
+    private void OnRepairFinished(Entity<RepairableComponent> ent,  ref RepairFinishedEvent args)
+    {
+        if (args.Cancelled)
+            return;
+
+        if (!TryComp(ent.Owner, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
+            return;
+
+        if (ent.Comp.Damage != null)
+        {
+            var damageChanged = _damageableSystem.TryChangeDamage(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()}");
+        }
+
+        else
+        {
+            // 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);
+    }
+
+    private void Repair(Entity<RepairableComponent> ent, ref InteractUsingEvent args)
+    {
+        if (args.Handled)
+            return;
+
+        // Only try repair the target if it is damaged
+        if (!TryComp<DamageableComponent>(ent.Owner, out var damageable) || damageable.TotalDamage == 0)
+            return;
+
+        float delay = ent.Comp.DoAfterDelay;
+
+        // Add a penalty to how long it takes if the user is repairing itself
+        if (args.User == args.Target)
+        {
+            if (!ent.Comp.AllowSelfRepair)
+                return;
+
+            delay *= ent.Comp.SelfRepairPenalty;
+        }
+
+        // Run the repairing doafter
+        args.Handled = _toolSystem.UseTool(args.Used, args.User, ent.Owner, delay, ent.Comp.QualityNeeded, new RepairFinishedEvent(), ent.Comp.FuelCost);
+    }
+}
+
+/// <summary>
+/// Event raised on an entity when its successfully repaired.
+/// </summary>
+/// <param name="Ent"></param>
+/// <param name="User"></param>
+[ByRefEvent]
+public readonly record struct RepairedEvent(Entity<RepairableComponent> Ent, EntityUid User);
+
+[Serializable, NetSerializable]
+public sealed partial class RepairFinishedEvent : SimpleDoAfterEvent;
diff --git a/Content.Shared/Repairable/SharedRepairableSystem.cs b/Content.Shared/Repairable/SharedRepairableSystem.cs
deleted file mode 100644 (file)
index 2b0cb67..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-using Content.Shared.DoAfter;
-using Robust.Shared.Serialization;
-
-namespace Content.Shared.Repairable;
-
-public abstract partial class SharedRepairableSystem : EntitySystem
-{
-    [Serializable, NetSerializable]
-    protected sealed partial class RepairFinishedEvent : SimpleDoAfterEvent
-    {
-    }
-}
-