Add delay to dumping mop bucket (#11631)

This commit is contained in:
themias
2022-10-09 15:46:08 -04:00
committed by GitHub
parent d75ac467e8
commit 5ac7b63fb4
3 changed files with 85 additions and 5 deletions

View File

@@ -1,8 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Content.Server.Administration.Logs;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Clothing.Components;
using Content.Server.DoAfter;
using Content.Server.Fluids.Components;
using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems;
@@ -28,6 +30,7 @@ public sealed class SpillableSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
public override void Initialize()
{
@@ -36,6 +39,8 @@ public sealed class SpillableSystem : EntitySystem
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SpillableComponent, SolutionSpikeOverflowEvent>(OnSpikeOverflow);
SubscribeLocalEvent<SpillableComponent, SpillFinishedEvent>(OnSpillFinished);
SubscribeLocalEvent<SpillableComponent, SpillCancelledEvent>(OnSpillCancelled);
}
private void OnSpikeOverflow(EntityUid uid, SpillableComponent component, SolutionSpikeOverflowEvent args)
@@ -125,12 +130,35 @@ public sealed class SpillableSystem : EntitySystem
Verb verb = new();
verb.Text = Loc.GetString("spill-target-verb-get-data-text");
// TODO VERB ICONS spill icon? pouring out a glass/beaker?
verb.Act = () =>
if (component.SpillDelay == null)
{
var puddleSolution = _solutionContainerSystem.SplitSolution(args.Target,
solution, solution.DrainAvailable);
SpillAt(puddleSolution, Transform(args.Target).Coordinates, "PuddleSmear");
};
verb.Act = () =>
{
var puddleSolution = _solutionContainerSystem.SplitSolution(args.Target,
solution, solution.DrainAvailable);
SpillAt(puddleSolution, Transform(args.Target).Coordinates, "PuddleSmear");
};
}
else
{
verb.Act = () =>
{
if (component.CancelToken == null)
{
component.CancelToken = new CancellationTokenSource();
_doAfterSystem.DoAfter(new DoAfterEventArgs(args.User, component.SpillDelay.Value, component.CancelToken.Token, component.Owner)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnStun = true,
NeedHand = true,
TargetFinishedEvent = new SpillFinishedEvent(args.User, component.Owner, solution),
TargetCancelledEvent = new SpillCancelledEvent(component.Owner)
});
}
};
}
verb.Impact = LogImpact.Medium; // dangerous reagent reaction are logged separately.
args.Verbs.Add(verb);
}
@@ -234,4 +262,47 @@ public sealed class SpillableSystem : EntitySystem
return puddleComponent;
}
private void OnSpillFinished(EntityUid uid, SpillableComponent component, SpillFinishedEvent ev)
{
component.CancelToken = null;
//solution gone by other means before doafter completes
if (ev.Solution == null || ev.Solution.CurrentVolume == 0)
return;
var puddleSolution = _solutionContainerSystem.SplitSolution(uid,
ev.Solution, ev.Solution.DrainAvailable);
SpillAt(puddleSolution, Transform(component.Owner).Coordinates, "PuddleSmear");
}
private void OnSpillCancelled(EntityUid uid, SpillableComponent component, SpillCancelledEvent ev)
{
component.CancelToken = null;
}
internal sealed class SpillFinishedEvent : EntityEventArgs
{
public SpillFinishedEvent(EntityUid user, EntityUid spillable, Solution solution)
{
User = user;
Spillable = spillable;
Solution = solution;
}
public EntityUid User { get; }
public EntityUid Spillable { get; }
public Solution Solution { get; }
}
private sealed class SpillCancelledEvent : EntityEventArgs
{
public EntityUid Spillable;
public SpillCancelledEvent(EntityUid spillable)
{
Spillable = spillable;
}
}
}