Advanced Mop is now More Advanced + SolutionPurge Component (#15532)

Co-authored-by: Arimah <arimah42@gmail.com>
This commit is contained in:
EnDecc
2023-04-23 06:17:21 -04:00
committed by GitHub
parent 8709676f10
commit 0f90548600
6 changed files with 122 additions and 9 deletions

View File

@@ -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);
}

View 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;
}

View File

@@ -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;
}
}