]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Advanced Mop is now More Advanced + SolutionPurge Component (#15532)
authorEnDecc <33369477+Endecc@users.noreply.github.com>
Sun, 23 Apr 2023 10:17:21 +0000 (06:17 -0400)
committerGitHub <noreply@github.com>
Sun, 23 Apr 2023 10:17:21 +0000 (20:17 +1000)
Co-authored-by: Arimah <arimah42@gmail.com>
Content.Server/Chemistry/Components/SolutionPurgeComponent.cs [new file with mode: 0644]
Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs
Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs [new file with mode: 0644]
Content.Shared/Chemistry/Components/Solution.cs
Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml
Resources/Prototypes/Recipes/Lathes/janitorial.yml

diff --git a/Content.Server/Chemistry/Components/SolutionPurgeComponent.cs b/Content.Server/Chemistry/Components/SolutionPurgeComponent.cs
new file mode 100644 (file)
index 0000000..d4a71b9
--- /dev/null
@@ -0,0 +1,46 @@
+using Content.Server.Chemistry.EntitySystems;
+using Content.Shared.Chemistry.Reagent;
+using Content.Shared.FixedPoint;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
+
+namespace Content.Server.Chemistry.Components;
+
+/// <summary>
+/// Passively decreases a solution's quantity of reagent(s).
+/// </summary>
+[RegisterComponent]
+[Access(typeof(SolutionPurgeSystem))]
+public sealed class SolutionPurgeComponent : Component
+{
+    /// <summary>
+    /// The name of the solution to detract from.
+    /// </summary>
+    [DataField("solution", required: true), ViewVariables(VVAccess.ReadWrite)]
+    public string Solution = string.Empty;
+
+    /// <summary>
+    /// The reagent(s) to be ignored when purging the solution
+    /// </summary>
+    [DataField("preserve", customTypeSerializer: typeof(PrototypeIdListSerializer<ReagentPrototype>))]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public List<string> Preserve = new();
+
+    /// <summary>
+    /// Amount of reagent(s) that are purged
+    /// </summary>
+    [DataField("quantity", required: true), ViewVariables(VVAccess.ReadWrite)]
+    public FixedPoint2 Quantity = default!;
+
+    /// <summary>
+    /// How long it takes to purge once.
+    /// </summary>
+    [DataField("duration"), ViewVariables(VVAccess.ReadWrite)]
+    public TimeSpan Duration = TimeSpan.FromSeconds(1);
+
+    /// <summary>
+    /// The time when the next purge will occur.
+    /// </summary>
+    [DataField("nextPurgeTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
+    public TimeSpan NextPurgeTime = TimeSpan.FromSeconds(0);
+}
index 2166b9c7f3ef6dc41f5637238b5bb37111ca5964..e84271981e36256c0573b3dd767bdef9b782fb7a 100644 (file)
@@ -129,12 +129,12 @@ public sealed partial class SolutionContainerSystem : EntitySystem
     }
 
     /// <summary>
-    /// Splits a solution without the specified reagent.
+    /// Splits a solution without the specified reagent(s).
     /// </summary>
     public Solution SplitSolutionWithout(EntityUid targetUid, Solution solutionHolder, FixedPoint2 quantity,
-        string reagent)
+        params string[] reagents)
     {
-        var splitSol = solutionHolder.SplitSolutionWithout(quantity, reagent);
+        var splitSol = solutionHolder.SplitSolutionWithout(quantity, reagents);
         UpdateChemicals(targetUid, solutionHolder);
         return splitSol;
     }
diff --git a/Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs
new file mode 100644 (file)
index 0000000..41bde84
--- /dev/null
@@ -0,0 +1,48 @@
+using Content.Server.Chemistry.Components;
+using Content.Server.Chemistry.Components.SolutionManager;
+using Content.Shared.FixedPoint;
+using Robust.Shared.Timing;
+
+namespace Content.Server.Chemistry.EntitySystems;
+
+public sealed class SolutionPurgeSystem : EntitySystem
+{
+    [Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<SolutionPurgeComponent, EntityUnpausedEvent>(OnUnpaused);
+        SubscribeLocalEvent<SolutionPurgeComponent, MapInitEvent>(OnMapInit);
+    }
+
+    public override void Update(float frameTime)
+    {
+        base.Update(frameTime);
+
+        var query = EntityQueryEnumerator<SolutionPurgeComponent, SolutionContainerManagerComponent>();
+        while (query.MoveNext(out var uid, out var purge, out var manager))
+        {
+            if (_timing.CurTime < purge.NextPurgeTime)
+                continue;
+
+            // timer ignores if it's empty, it's just a fixed cycle
+            purge.NextPurgeTime += purge.Duration;
+            if (_solutionContainer.TryGetSolution(uid, purge.Solution, out var solution, manager))
+                _solutionContainer.SplitSolutionWithout(uid, solution, purge.Quantity, purge.Preserve.ToArray());
+        }
+    }
+
+    private void OnUnpaused(EntityUid uid, SolutionPurgeComponent comp, ref EntityUnpausedEvent args)
+    {
+        comp.NextPurgeTime += args.PausedTime;
+    }
+
+    private void OnMapInit(EntityUid uid, SolutionPurgeComponent comp, MapInitEvent args)
+    {
+        if (comp.NextPurgeTime < _timing.CurTime)
+            comp.NextPurgeTime = _timing.CurTime;
+    }
+}
index 353733e715f974f0e4140d256ff42e7e8b63410f..8aaf9582fff75202d4d4b318ee7ced6302659837 100644 (file)
@@ -435,12 +435,20 @@ namespace Content.Shared.Chemistry.Components
         /// <summary>
         /// Splits a solution without the specified reagent.
         /// </summary>
-        public Solution SplitSolutionWithout(FixedPoint2 toTake, string without)
+        public Solution SplitSolutionWithout(FixedPoint2 toTake, params string[] without)
         {
-            TryGetReagent(without, out var existing);
-            RemoveReagent(without, toTake);
+            var existing = new FixedPoint2[without.Length];
+            for (var i = 0; i < without.Length; i++)
+            {
+                TryGetReagent(without[i], out existing[i]);
+                RemoveReagent(without[i], existing[i]);
+            }
+
             var sol = SplitSolution(toTake);
-            AddReagent(without, existing);
+
+            for (var i = 0; i < without.Length; i++)
+                AddReagent(without[i], existing[i]);
+
             return sol;
         }
 
index 2f058caa28500523f506dc8fb0e9ddd36dd423a9..4e4d1b57efea6460c2e657909c7e4c16140b3d24 100644 (file)
@@ -38,7 +38,7 @@
   parent: BaseItem
   name: advanced mop
   id: AdvMopItem
-  description: Motorized mop that have a bigger reservoir and can mop multiple puddles at once. Automatic Clown Countermeasure no included.
+  description: Motorized mop that has a bigger reservoir and quickly replaces reagents inside with water. Automatic Clown Countermeasure not included.
   components:
     - type: Sprite
       sprite: Objects/Specific/Janitorial/advmop.rsi
       pickupAmount: 100
     - type: UseDelay
       delay: 1.0
+    - type: SolutionRegeneration
+      solution: absorbed
+      generated:
+        reagents:
+        - ReagentId: Water
+          Quantity: 5
+    - type: SolutionPurge
+      solution: absorbed
+      preserve:
+      - Water
+      quantity: 10
     - type: SolutionContainerManager
       solutions:
         absorbed:
index f05b0604471576035c7be787ab8a208c0bb92613..a9a2866c1df2a1411bf129a57d8c9034c86bdb89 100644 (file)
@@ -61,6 +61,6 @@
   result: AdvMopItem
   completetime: 2
   materials:
-    Plastic: 100
+    Plastic: 400
     Steel: 100
     Glass: 100