Mopping ECS (No BucketComponents allowed!) (#6718)

Co-authored-by: mirrorcult <lunarautomaton6@gmail.com>
This commit is contained in:
Willhelm53
2022-03-14 16:02:26 -05:00
committed by GitHub
parent 84225dde3d
commit 65178bccc4
10 changed files with 449 additions and 332 deletions

View File

@@ -71,8 +71,7 @@ namespace Content.Client.Entry
"Mind",
"DiseaseCarrier",
"StorageFill",
"Mop",
"Bucket",
"Absorbent",
"CableVis",
"BatterySelfRecharger",
"Puddle",

View File

@@ -0,0 +1,54 @@
using Content.Server.Fluids.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.Sound;
namespace Content.Server.Fluids.Components;
/// <summary>
/// For entities that can clean up puddles
/// </summary>
[RegisterComponent, Friend(typeof(MoppingSystem))]
public sealed class AbsorbentComponent : Component
{
public const string SolutionName = "absorbed";
[DataField("pickupAmount")]
public FixedPoint2 PickupAmount = FixedPoint2.New(10);
/// <summary>
/// When using this tool on an empty floor tile, leave this much reagent as a new puddle.
/// </summary>
[DataField("residueAmount")]
public FixedPoint2 ResidueAmount = FixedPoint2.New(10); // Should be higher than MopLowerLimit
/// <summary>
/// To leave behind a wet floor, this tool will be unable to take from puddles with a volume less than this amount.
/// </summary>
[DataField("mopLowerLimit")]
public FixedPoint2 MopLowerLimit = FixedPoint2.New(5);
[DataField("pickupSound")]
public SoundSpecifier PickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
[DataField("transferSound")]
public SoundSpecifier TransferSound = new SoundPathSpecifier("/Audio/Effects/Fluids/watersplash.ogg");
/// <summary>
/// Multiplier for the do_after delay for how quickly the mopping happens.
/// </summary>
[ViewVariables]
[DataField("mopSpeed")] public float MopSpeed = 1;
/// <summary>
/// How many entities can this tool interact with at once?
/// </summary>
[DataField("maxEntities")]
public int MaxInteractingEntities = 1;
/// <summary>
/// What entities is this tool interacting with right now?
/// </summary>
[ViewVariables]
public HashSet<EntityUid> InteractingEntities = new();
}

View File

@@ -1,141 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.DoAfter;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Popups;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Fluids.Components
{
/// <summary>
/// Can a mop click on this entity and dump its fluids
/// </summary>
[RegisterComponent]
public sealed class BucketComponent : Component, IInteractUsing
{
[Dependency] private readonly IEntityManager _entMan = default!;
public const string SolutionName = "bucket";
private List<EntityUid> _currentlyUsing = new();
public FixedPoint2 MaxVolume
{
get =>
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
? solution.MaxVolume
: FixedPoint2.Zero;
set
{
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
{
solution.MaxVolume = value;
}
}
}
public FixedPoint2 CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
? solution.CurrentVolume
: FixedPoint2.Zero;
[DataField("sound")]
private SoundSpecifier _sound = new SoundPathSpecifier("/Audio/Effects/Fluids/watersplash.ogg");
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
if (!solutionsSys.TryGetSolution(Owner, SolutionName, out var contents) ||
_currentlyUsing.Contains(eventArgs.Using) ||
!_entMan.TryGetComponent(eventArgs.Using, out MopComponent? mopComponent) ||
mopComponent.Mopping)
{
return false;
}
if (CurrentVolume <= 0)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("bucket-component-bucket-is-empty-message"));
return false;
}
_currentlyUsing.Add(eventArgs.Using);
// IMO let em move while doing it.
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, 1.0f, target: eventArgs.Target)
{
BreakOnStun = true,
BreakOnDamage = true,
};
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterArgs);
_currentlyUsing.Remove(eventArgs.Using);
if (result == DoAfterStatus.Cancelled || _entMan.Deleted(Owner) || mopComponent.Deleted ||
CurrentVolume <= 0 || !EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner, mopComponent.Owner))
return false;
//Checks if the mop is empty
if(mopComponent.CurrentVolume == 0)
{
// Transfers up to half the mop's available capacity to the mop
// Takes the lower of the mop's available volume and the bucket's current volume.
var transferAmount = FixedPoint2.Min(0.5*mopComponent.AvailableVolume, CurrentVolume);
if (transferAmount == 0)
{
return false;
}
var mopContents = mopComponent.MopSolution;
if (mopContents == null)
{
return false;
}
// Transfer solution from the bucket to the mop
// Owner is the bucket being interacted with. contents is the Solution contained by said bucket.
var solution = solutionsSys.SplitSolution(Owner, contents, transferAmount);
if (!solutionsSys.TryAddSolution(mopComponent.Owner, mopComponent.MopSolution, solution))
{
return false; //if the attempt fails
}
Owner.PopupMessage(eventArgs.User, Loc.GetString("bucket-component-mop-is-now-wet-message"));
}
else //if mop is not empty
{
//Transfer the mop solution to the bucket
if (mopComponent.MopSolution == null)
return false;
var solutionFromMop = solutionsSys.SplitSolution(mopComponent.Owner, mopComponent.MopSolution, mopComponent.CurrentVolume);
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution);
if (!solutionsSys.TryAddSolution(Owner, solution, solutionFromMop))
{
return false; //if the attempt fails
}
Owner.PopupMessage(eventArgs.User, Loc.GetString("bucket-component-mop-is-now-dry-message"));
}
SoundSystem.Play(Filter.Pvs(Owner), _sound.GetSound(), Owner);
return true;
}
}
}

View File

@@ -1,182 +0,0 @@
using System.Threading.Tasks;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.DoAfter;
using Content.Server.Fluids.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Popups;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Fluids.Components
{
/// <summary>
/// For cleaning up puddles
/// </summary>
[RegisterComponent]
public sealed class MopComponent : Component, IAfterInteract
{
[Dependency] private readonly IEntityManager _entities = default!;
public const string SolutionName = "mop";
/// <summary>
/// Used to prevent do_after spam if we're currently mopping.
/// </summary>
public bool Mopping { get; private set; }
// MopSolution Object stores whatever solution the mop has absorbed.
public Solution? MopSolution
{
get
{
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution);
return solution;
}
}
// MaxVolume is the Maximum volume the mop can absorb (however, this is defined in janitor.yml)
public FixedPoint2 MaxVolume
{
get => MopSolution?.MaxVolume ?? FixedPoint2.Zero;
set
{
var solution = MopSolution;
if (solution != null)
{
solution.MaxVolume = value;
}
}
}
// CurrentVolume is the volume the mop has absorbed.
public FixedPoint2 CurrentVolume => MopSolution?.CurrentVolume ?? FixedPoint2.Zero;
// AvailableVolume is the remaining volume capacity of the mop.
public FixedPoint2 AvailableVolume => MopSolution?.AvailableVolume ?? FixedPoint2.Zero;
// Currently there's a separate amount for pickup and dropoff so
// Picking up a puddle requires multiple clicks
// Dumping in a bucket requires 1 click
// Long-term you'd probably use a cooldown and start the pickup once we have some form of global cooldown
[DataField("pickup_amount")]
public FixedPoint2 PickupAmount { get; } = FixedPoint2.New(10);
/// <summary>
/// When using the mop on an empty floor tile, leave this much reagent as a new puddle.
/// </summary>
[DataField("residueAmount")]
public FixedPoint2 ResidueAmount { get; } = FixedPoint2.New(10); // Should be higher than MopLowerLimit
/// <summary>
/// To leave behind a wet floor, the mop will be unable to take from puddles with a volume less than this amount.
/// </summary>
[DataField("mopLowerLimit")]
public FixedPoint2 MopLowerLimit { get; } = FixedPoint2.New(5);
[DataField("pickup_sound")]
private SoundSpecifier _pickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
/// <summary>
/// Multiplier for the do_after delay for how fast the mop works.
/// </summary>
[ViewVariables]
[DataField("speed")] private float _mopSpeed = 1;
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
/*
* Functionality:
* Essentially if we click on an empty tile spill our contents there
* Otherwise, try to mop up the puddle (if it is a puddle).
* It will try to destroy solution on the mop to do so, and if it is successful
* will spill some of the mop's solution onto the puddle which will evaporate eventually.
*/
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
var spillableSystem = EntitySystem.Get<SpillableSystem>();
if (!eventArgs.CanReach ||
!solutionSystem.TryGetSolution(Owner, SolutionName, out var contents ) ||
Mopping)
{
return false;
}
if (eventArgs.Target is not {Valid: true} target)
{
// Drop the liquid on the mop on to the ground
var solution = solutionSystem.SplitSolution(Owner, contents, FixedPoint2.Min(ResidueAmount, CurrentVolume));
spillableSystem.SpillAt(solution, eventArgs.ClickLocation, "PuddleSmear");
return true;
}
if (!_entities.TryGetComponent(target, out PuddleComponent? puddleComponent) ||
!solutionSystem.TryGetSolution((puddleComponent).Owner, puddleComponent.SolutionName, out var puddleSolution))
return false;
// if the puddle is too small for the mop to effectively take any more solution
if (puddleSolution.TotalVolume <= MopLowerLimit)
{
// Transfers solution from the mop to the puddle
solutionSystem.TryAddSolution(target, puddleSolution, solutionSystem.SplitSolution(Owner, contents, FixedPoint2.Min(ResidueAmount,CurrentVolume)));
return true;
}
// if the mop is full
if(AvailableVolume <= 0)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("mop-component-mop-is-full-message"));
return false;
}
// Mopping duration (aka delay) should scale with PickupAmount and not puddle volume, because we are picking up a constant volume of solution with each click.
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * PickupAmount.Float() / 10.0f,
target: target)
{
BreakOnUserMove = true,
BreakOnStun = true,
BreakOnDamage = true,
};
Mopping = true;
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterArgs);
Mopping = false;
if (result == DoAfterStatus.Cancelled ||
_entities.Deleted(Owner) ||
puddleComponent.Deleted)
return false;
// The volume the mop will take from the puddle
FixedPoint2 transferAmount;
// does the puddle actually have reagents? it might not if its a weird cosmetic entity.
if (puddleSolution.TotalVolume == 0)
transferAmount = FixedPoint2.Min(PickupAmount, AvailableVolume);
else
{
transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, AvailableVolume);
if ((puddleSolution.TotalVolume - transferAmount) < MopLowerLimit) // If the transferAmount would bring the puddle below the MopLowerLimit
transferAmount = puddleSolution.TotalVolume - MopLowerLimit; // Then the transferAmount should bring the puddle down to the MopLowerLimit exactly
}
// Transfers solution from the puddle to the mop
solutionSystem.TryAddSolution(Owner, contents, solutionSystem.SplitSolution(target, puddleSolution, transferAmount));
SoundSystem.Play(Filter.Pvs(Owner), _pickupSound.GetSound(), Owner);
// if the mop became full after that puddle, let the player know.
if(AvailableVolume <= 0)
Owner.PopupMessage(eventArgs.User, Loc.GetString("mop-component-mop-is-now-full-message"));
return true;
}
}
}

View File

@@ -0,0 +1,361 @@
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.DoAfter;
using Content.Server.Fluids.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Sound;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Map;
using JetBrains.Annotations;
namespace Content.Server.Fluids.EntitySystems;
[UsedImplicitly]
public sealed class MoppingSystem : EntitySystem
{
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SpillableSystem _spillableSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
const string puddlePrototypeId = "PuddleSmear"; // The puddle prototype to use when releasing liquid to the floor, making a new puddle
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AbsorbentComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<TransferCancelledEvent>(OnTransferCancelled);
SubscribeLocalEvent<TransferCompleteEvent>(OnTransferComplete);
}
private void OnAfterInteract(EntityUid uid, AbsorbentComponent component, AfterInteractEvent args)
{
if (!args.CanReach) // if user cannot reach the target
{
return;
}
if (args.Handled) // if the event was already handled
{
return;
}
_solutionSystem.TryGetSolution(args.Used, AbsorbentComponent.SolutionName, out var absorbedSolution);
if (absorbedSolution is null)
{
return;
}
var toolAvailableVolume = absorbedSolution.AvailableVolume;
var toolCurrentVolume = absorbedSolution.CurrentVolume;
// For adding liquid to an empty floor tile
if (args.Target is null) // if a tile is clicked
{
ReleaseToFloor(args.ClickLocation, component, absorbedSolution);
args.Handled = true;
args.User.PopupMessage(args.User, Loc.GetString("mopping-system-release-to-floor"));
return;
}
else if (args.Target is not null)
{
// Handle our do_after logic
HandleDoAfter(args.User, args.Used, args.Target.Value, component, toolCurrentVolume, toolAvailableVolume);
}
args.Handled = true;
return;
}
private void ReleaseToFloor(EntityCoordinates clickLocation, AbsorbentComponent absorbent, Solution? absorbedSolution)
{
if ((_mapManager.TryGetGrid(clickLocation.GetGridId(EntityManager), out var mapGrid)) // needs valid grid
&& absorbedSolution is not null) // needs a solution to place on the tile
{
TileRef tile = mapGrid.GetTileRef(clickLocation);
// Drop some of the absorbed liquid onto the ground
var releaseAmount = FixedPoint2.Min(absorbent.ResidueAmount, absorbedSolution.CurrentVolume); // The release amount specified on the absorbent component, or the amount currently absorbed (whichever is less).
var releasedSolution = _solutionSystem.SplitSolution(absorbent.Owner, absorbedSolution, releaseAmount); // Remove releaseAmount of solution from the absorbent component
_spillableSystem.SpillAt(tile, releasedSolution, puddlePrototypeId); // And spill it onto the tile.
}
}
// Handles logic for our different types of valid target.
// Checks for conditions that would prevent a doAfter from starting.
private void HandleDoAfter(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent component, FixedPoint2 currentVolume, FixedPoint2 availableVolume)
{
// Below variables will be set within this function depending on what kind of target was clicked.
// They will be passed to the OnTransferComplete if the doAfter succeeds.
EntityUid donor;
EntityUid acceptor;
string donorSolutionName;
string acceptorSolutionName;
FixedPoint2 transferAmount;
var delay = 1.0f; //default do_after delay in seconds.
string msg;
SoundSpecifier sfx;
// For our purposes, if our target has a PuddleComponent, treat it as a puddle above all else.
if (TryComp<PuddleComponent>(target, out var puddle))
{
// These return conditions will abort BEFORE the do_after is called:
if(!_solutionSystem.TryGetSolution(target, puddle.SolutionName, out var puddleSolution) // puddle Solution is null
|| (puddleSolution.TotalVolume <= 0)) // puddle is completely empty
{
return;
}
else if (availableVolume < 0) // mop is completely full
{
msg = "mopping-system-tool-full";
user.PopupMessage(user, Loc.GetString(msg, ("used", used))); // play message now because we are aborting.
return;
}
// adding to puddles
else if (puddleSolution.TotalVolume < component.MopLowerLimit // if the puddle is too small for the tool to effectively absorb any more solution from it
&& currentVolume > 0) // tool needs a solution to dilute the puddle with.
{
// Dilutes the puddle with some solution from the tool
transferAmount = FixedPoint2.Max(component.ResidueAmount, currentVolume);
TryTransfer(used, target, "absorbed", puddle.SolutionName, transferAmount); // Complete the transfer right away, with no doAfter.
sfx = component.TransferSound;
SoundSystem.Play(Filter.Pvs(user), sfx.GetSound(), used); // Give instant feedback for diluting puddle, so that it's clear that the player is adding to the puddle (as opposed to other behaviours, which have a doAfter).
msg = "mopping-system-puddle-diluted";
user.PopupMessage(user, Loc.GetString(msg)); // play message now because we are aborting.
return; // Do not begin a doAfter.
}
else
{
// Taking from puddles:
// Determine transferAmount:
transferAmount = FixedPoint2.Min(component.PickupAmount, puddleSolution.TotalVolume, availableVolume);
// TODO: consider onelining this with the above, using additional args on Min()?
if ((puddleSolution.TotalVolume - transferAmount) < component.MopLowerLimit) // If the transferAmount would bring the puddle below the MopLowerLimit
{
transferAmount = puddleSolution.TotalVolume - component.MopLowerLimit; // Then the transferAmount should bring the puddle down to the MopLowerLimit exactly
}
donor = target; // the puddle Uid
donorSolutionName = puddle.SolutionName;
acceptor = used; // the mop/tool Uid
acceptorSolutionName = "absorbed"; // by definition on AbsorbentComponent
// Set delay/popup/sound if nondefault. Popup and sound will only play on a successful doAfter.
delay = (component.PickupAmount.Float() / 10.0f) * component.MopSpeed; // Delay should scale with PickupAmount, which represents the maximum we can pick up per click.
msg = "mopping-system-puddle-success";
sfx = component.PickupSound;
DoMopInteraction(user, used, target, donor, acceptor, component, donorSolutionName, acceptorSolutionName, transferAmount, delay, msg, sfx);
}
}
else if ((TryComp<RefillableSolutionComponent>(target, out var refillable)) // We can put solution from the tool into the target
&& (currentVolume > 0)) // And the tool is wet
{
// These return conditions will abort BEFORE the do_after is called:
if (!_solutionSystem.TryGetRefillableSolution(target, out var refillableSolution)) // refillable Solution is null
{
return;
}
else if (refillableSolution.AvailableVolume <= 0) // target container is full (liquid destination)
{
msg = "mopping-system-target-container-full";
user.PopupMessage(user, Loc.GetString(msg, ("target", target))); // play message now because we are aborting.
return;
}
else if (refillableSolution.MaxVolume <= FixedPoint2.New(20)) // target container is too small (e.g. syringe)
{
msg = "mopping-system-target-container-too-small";
user.PopupMessage(user, Loc.GetString(msg, ("target", target))); // play message now because we are aborting.
return;
}
else
{
// Determine transferAmount
if (_tagSystem.HasTag(used, "Mop") // if the tool used is a literal mop (and not a sponge, rag, etc.)
&& !_tagSystem.HasTag(target, "Wringer")) // and if the target does not have a wringer for properly drying the mop
{
delay = 5.0f; // Should take much longer if you don't have a wringer
if ((currentVolume / (currentVolume + availableVolume) ) > 0.25) // mop is more than one-quarter full
{
transferAmount = FixedPoint2.Min(refillableSolution.AvailableVolume, currentVolume * 0.6); // squeeze up to 60% of the solution from the mop.
msg = "mopping-system-hand-squeeze-little-wet";
if ((currentVolume / (currentVolume + availableVolume) ) > 0.5) // if the mop is more than half full
msg = "mopping-system-hand-squeeze-still-wet"; // overwrites the above
}
else // mop is less than one-quarter full
{
transferAmount = FixedPoint2.Min(refillableSolution.AvailableVolume, currentVolume); // squeeze remainder of solution from the mop.
msg = "mopping-system-hand-squeeze-dry";
}
}
else
{
transferAmount = FixedPoint2.Min(refillableSolution.AvailableVolume, currentVolume); //Transfer all liquid from the tool to the container, but only if it will fit.
msg = "mopping-system-refillable-success";
delay = 1.0f;
}
donor = used; // the mop/tool Uid
donorSolutionName = "absorbed"; // by definition on AbsorbentComponent
acceptor = target; // the refillable container's Uid
acceptorSolutionName = refillable.Solution;
// Set delay/popup/sound if nondefault. Popup and sound will only play on a successful doAfter.
sfx = component.TransferSound;
DoMopInteraction(user, used, target, donor, acceptor, component, donorSolutionName, acceptorSolutionName, transferAmount, delay, msg, sfx);
}
}
else if (TryComp<DrainableSolutionComponent>(target, out var drainable) // We can take solution from the target
&& currentVolume <= 0 ) // tool is dry
{
// These return conditions will abort BEFORE the do_after is called:
if (!_solutionSystem.TryGetDrainableSolution(target, out var drainableSolution))
{
return;
}
else if (drainableSolution.CurrentVolume <= 0) // target container is empty (liquid source)
{
msg = "mopping-system-target-container-empty";
user.PopupMessage(user, Loc.GetString(msg, ("target", target))); // play message now because we are returning.
return;
}
else
{
// Determine transferAmount
transferAmount = FixedPoint2.Min(availableVolume * 0.5, drainableSolution.CurrentVolume); // Let's transfer up to to half the tool's available capacity to the tool.
donor = target; // the drainable container's Uid
donorSolutionName = drainable.Solution;
acceptor = used; // the mop/tool Uid
acceptorSolutionName = "absorbed"; // by definition on AbsorbentComponent
// Set delay/popup/sound if nondefault. Popup and sound will only play on a successful doAfter.
// default delay is fine for this case.
msg = "mopping-system-drainable-success";
sfx = component.TransferSound;
DoMopInteraction(user, used, target, donor, acceptor, component, donorSolutionName, acceptorSolutionName, transferAmount, delay, msg, sfx);
}
}
}
private void DoMopInteraction(EntityUid user, EntityUid used, EntityUid target, EntityUid donor, EntityUid acceptor,
AbsorbentComponent component, string donorSolutionName, string acceptorSolutionName,
FixedPoint2 transferAmount, float delay, string msg, SoundSpecifier sfx)
{
var doAfterArgs = new DoAfterEventArgs(user, delay, target: target)
{
BreakOnUserMove = true,
BreakOnStun = true,
BreakOnDamage = true,
MovementThreshold = 0.2f,
BroadcastCancelledEvent = new TransferCancelledEvent()
{
Target = target,
Component = component // (the AbsorbentComponent)
},
BroadcastFinishedEvent = new TransferCompleteEvent()
{
User = user,
Tool = used,
Target = target,
Donor = donor,
Acceptor = acceptor,
Component = component,
DonorSolutionName = donorSolutionName,
AcceptorSolutionName = acceptorSolutionName,
Message = msg,
Sound = sfx,
TransferAmount = transferAmount
}
};
// Can't interact with too many entities at once.
if (component.MaxInteractingEntities < component.InteractingEntities.Count + 1)
return;
// Can't interact with the same container multiple times at once.
if (!component.InteractingEntities.Add(target))
return;
var result = _doAfterSystem.WaitDoAfter(doAfterArgs);
}
private void OnTransferComplete(TransferCompleteEvent ev)
{
SoundSystem.Play(Filter.Pvs(ev.User), ev.Sound.GetSound(), ev.Tool); // Play the After SFX
ev.User.PopupMessage(ev.User, Loc.GetString(ev.Message, ("target", ev.Target), ("used", ev.Tool))); // Play the After popup message
TryTransfer(ev.Donor, ev.Acceptor, ev.DonorSolutionName, ev.AcceptorSolutionName, ev.TransferAmount);
ev.Component.InteractingEntities.Remove(ev.Target); // Tell the absorbentComponent that we have stopped interacting with the target.
return;
}
private void OnTransferCancelled(TransferCancelledEvent ev)
{
if (!ev.Component.Deleted)
ev.Component.InteractingEntities.Remove(ev.Target); // Tell the absorbentComponent that we have stopped interacting with the target.
return;
}
private void TryTransfer(EntityUid donor, EntityUid acceptor, string donorSolutionName, string acceptorSolutionName, FixedPoint2 transferAmount)
{
if (_solutionSystem.TryGetSolution(donor, donorSolutionName, out var donorSolution) // If the donor solution is valid
&& _solutionSystem.TryGetSolution(acceptor, acceptorSolutionName, out var acceptorSolution)) // And the acceptor solution is valid
{
var solutionToTransfer = _solutionSystem.SplitSolution(donor, donorSolution, transferAmount); // Split a portion of the donor solution
_solutionSystem.TryAddSolution(acceptor, acceptorSolution, solutionToTransfer); // And add it to the acceptor solution
}
}
}
public sealed class TransferCompleteEvent : EntityEventArgs
{
public EntityUid User;
public EntityUid Tool;
public EntityUid Target;
public EntityUid Donor;
public EntityUid Acceptor;
public AbsorbentComponent Component { get; init; } = default!;
public string DonorSolutionName = "";
public string AcceptorSolutionName = "";
public string Message = "";
public SoundSpecifier Sound { get; init; } = default!;
public FixedPoint2 TransferAmount;
}
public sealed class TransferCancelledEvent : EntityEventArgs
{
public EntityUid Target;
public AbsorbentComponent Component { get; init; } = default!;
}

View File

@@ -0,0 +1,15 @@
mopping-system-tool-full = { CAPITALIZE(THE($used)) } is full!
mopping-system-puddle-diluted = You dilute the puddle.
mopping-system-puddle-success = You mop the puddle.
mopping-system-release-to-floor = You squeeze some liquid onto the floor.
mopping-system-target-container-full = { CAPITALIZE(THE($target)) } is full!
mopping-system-target-container-empty = { CAPITALIZE(THE($target)) } is empty!
mopping-system-target-container-too-small = { CAPITALIZE(THE($target)) } is too small for that!
mopping-system-refillable-success = You wring { THE($used) } into { THE($target) }.
mopping-system-drainable-success = You wet { THE($used) } from { THE($target) }.
mopping-system-hand-squeeze-still-wet = You wring { THE($used) } with your hands. It's still wet.
mopping-system-hand-squeeze-little-wet = You wring { THE($used) } with your hands. It's still a little wet.
mopping-system-hand-squeeze-dry = You wring { THE($used) } with your hands. It's pretty much dry.

View File

@@ -1,3 +0,0 @@
mop-component-mop-is-dry-message = Mop needs to be wet!
mop-component-mop-is-full-message = Mop is full!
mop-component-mop-is-now-full-message = Mop is now full

View File

@@ -11,10 +11,13 @@
- type: Item
size: 10
sprite: Objects/Specific/Janitorial/mop.rsi
- type: Mop
- type: Absorbent
- type: Tag
tags:
- Mop
- type: SolutionContainerManager
solutions:
mop:
absorbed:
maxVol: 50
- type: Tag
tags:
@@ -34,7 +37,6 @@
- state: mopbucket_water
drawdepth: Objects
- type: InteractionOutline
- type: Bucket
- type: SolutionContainerManager
solutions:
bucket:
@@ -42,6 +44,13 @@
reagents:
- ReagentId: Water
Quantity: 250 # half-full at roundstart to leave room for puddles
- type: DrainableSolution
solution: bucket
- type: RefillableSolution
solution: bucket
- type: Tag
tags:
- Wringer
- type: Physics
bodyType: Dynamic
- type: Fixtures

View File

@@ -16,7 +16,6 @@
sprite: Objects/Tools/bucket.rsi
Slots:
- HEAD
- type: Bucket
- type: SolutionContainerManager
solutions:
bucket:

View File

@@ -204,6 +204,9 @@
- type: Tag
id: MonkeyCube
- type: Tag
id: Mop
- type: Tag
id: NoSpinOnThrow
@@ -310,5 +313,8 @@
- type: Tag
id: Wrench
- type: Tag
id: Wringer
- type: Tag
id: Write