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,3 +1,5 @@
using System.Threading;
namespace Content.Server.Fluids.Components; namespace Content.Server.Fluids.Components;
[RegisterComponent] [RegisterComponent]
@@ -12,4 +14,9 @@ public sealed class SpillableComponent : Component
/// </summary> /// </summary>
[DataField("spillWorn")] [DataField("spillWorn")]
public bool SpillWorn = true; public bool SpillWorn = true;
[DataField("spillDelay")]
public float? SpillDelay;
public CancellationTokenSource? CancelToken;
} }

View File

@@ -1,8 +1,10 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Threading;
using Content.Server.Administration.Logs; using Content.Server.Administration.Logs;
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Clothing.Components; using Content.Server.Clothing.Components;
using Content.Server.DoAfter;
using Content.Server.Fluids.Components; using Content.Server.Fluids.Components;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems; using Content.Server.Nutrition.EntitySystems;
@@ -28,6 +30,7 @@ public sealed class SpillableSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!; [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!; [Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -36,6 +39,8 @@ public sealed class SpillableSystem : EntitySystem
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb); SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped); SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SpillableComponent, SolutionSpikeOverflowEvent>(OnSpikeOverflow); SubscribeLocalEvent<SpillableComponent, SolutionSpikeOverflowEvent>(OnSpikeOverflow);
SubscribeLocalEvent<SpillableComponent, SpillFinishedEvent>(OnSpillFinished);
SubscribeLocalEvent<SpillableComponent, SpillCancelledEvent>(OnSpillCancelled);
} }
private void OnSpikeOverflow(EntityUid uid, SpillableComponent component, SolutionSpikeOverflowEvent args) private void OnSpikeOverflow(EntityUid uid, SpillableComponent component, SolutionSpikeOverflowEvent args)
@@ -125,12 +130,35 @@ public sealed class SpillableSystem : EntitySystem
Verb verb = new(); Verb verb = new();
verb.Text = Loc.GetString("spill-target-verb-get-data-text"); verb.Text = Loc.GetString("spill-target-verb-get-data-text");
// TODO VERB ICONS spill icon? pouring out a glass/beaker? // TODO VERB ICONS spill icon? pouring out a glass/beaker?
if (component.SpillDelay == null)
{
verb.Act = () => verb.Act = () =>
{ {
var puddleSolution = _solutionContainerSystem.SplitSolution(args.Target, var puddleSolution = _solutionContainerSystem.SplitSolution(args.Target,
solution, solution.DrainAvailable); solution, solution.DrainAvailable);
SpillAt(puddleSolution, Transform(args.Target).Coordinates, "PuddleSmear"); 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. verb.Impact = LogImpact.Medium; // dangerous reagent reaction are logged separately.
args.Verbs.Add(verb); args.Verbs.Add(verb);
} }
@@ -234,4 +262,47 @@ public sealed class SpillableSystem : EntitySystem
return puddleComponent; 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;
}
}
} }

View File

@@ -46,6 +46,7 @@
- ReagentId: Water - ReagentId: Water
Quantity: 250 # half-full at roundstart to leave room for puddles Quantity: 250 # half-full at roundstart to leave room for puddles
- type: Spillable - type: Spillable
spillDelay: 3.0
- type: DrainableSolution - type: DrainableSolution
solution: bucket solution: bucket
- type: RefillableSolution - type: RefillableSolution
@@ -141,6 +142,7 @@
mask: mask:
- MobMask - MobMask
- type: Spillable - type: Spillable
spillDelay: 3.0
- type: SolutionContainerManager - type: SolutionContainerManager
solutions: solutions:
bucket: bucket: