* A big hecking chemistry-related refactor. Changed SolutionContainerCaps. It now describes "stock" behavior for interacting with solutions that is pre-implemented by SolutionContainerComponent. As such things like syringes do not check it anymore (on themselves) to see "can we remove reagent from ourselves". That's assumed by it... being a syringe. SolutionContainerCaps now has different flags more accurately describing possible reagent interaction behaviors. ISolutionInteractionsComponent is the interface that describes the common behaviors like "what happens when injected with a syringe". This is implemented by SolutionContainerComponent but could be implemented by other classes. One notable example that drove me to making this interface was the /vg/station circuit imprinter which splits reagent poured in into its two reservoir beakers. Having this interface allows us to do this "proxying" behavior hack-free. (the hacks in /vg/ code were somewhat dirty...). PourableComponent has been replaced SolutionTransferComponent. It now describes both give-and-take behavior for the common reagent containers. This is in line with /vg/'s /obj/item/weapon/reagent_containers architecture. "Taking" in this context is ONLY from reagent tanks like fuel tanks. Oh, should I mention that fuel tanks and such have a proper component now? They do. Because of this behavioral change, reagent tanks DO NOT have Pourable anymore. Removing from reagent tanks is now in the hands of the item used on them. Welders and fire extinguishers now have code for removing from them. This sounds bad at first but remember that all have quite unique behavior related to this: Welders cause explosions if lit and can ONLY be fueled at fuel tanks. Extinguishers can be filled at any tank, etc... The code for this is also simpler due to ISolutionInteractionsComponent now so... IAfterInteract now works like IInteractUsing with the Priority levels and "return true to block further handlers" behavior. This was necessary to make extinguishers prioritize taking from tanks over spraying. Explicitly coded interactions like welders refueling also means they refuse instantly to full now, which they didn't before. And it plays the sound. Etc... Probably more stuff I'm forgetting. * Review improvements.
135 lines
4.8 KiB
C#
135 lines
4.8 KiB
C#
#nullable enable
|
|
using Content.Server.GameObjects.Components.Chemistry;
|
|
using Content.Shared.Chemistry;
|
|
using Content.Shared.Interfaces;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Content.Shared.Utility;
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Serialization;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Content.Server.GameObjects.Components.Fluids
|
|
{
|
|
/// <summary>
|
|
/// For cleaning up puddles
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public class MopComponent : Component, IAfterInteract
|
|
{
|
|
public override string Name => "Mop";
|
|
|
|
public SolutionContainerComponent? Contents => Owner.GetComponentOrNull<SolutionContainerComponent>();
|
|
|
|
public ReagentUnit MaxVolume
|
|
{
|
|
get => Owner.GetComponentOrNull<SolutionContainerComponent>()?.MaxVolume ?? ReagentUnit.Zero;
|
|
set
|
|
{
|
|
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
|
{
|
|
solution.MaxVolume = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public ReagentUnit CurrentVolume =>
|
|
Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.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
|
|
public ReagentUnit PickupAmount => _pickupAmount;
|
|
private ReagentUnit _pickupAmount;
|
|
|
|
private string _pickupSound = "";
|
|
|
|
/// <inheritdoc />
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
serializer.DataFieldCached(ref _pickupSound, "pickup_sound", "/Audio/Effects/Fluids/slosh.ogg");
|
|
// The turbo mop will pickup more
|
|
serializer.DataFieldCached(ref _pickupAmount, "pickup_amount", ReagentUnit.New(5));
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
|
|
}
|
|
|
|
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
|
{
|
|
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
|
|
return false;
|
|
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
|
return false;
|
|
|
|
if (CurrentVolume <= 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (eventArgs.Target == null)
|
|
{
|
|
// Drop the liquid on the mop on to the ground
|
|
contents.SplitSolution(CurrentVolume).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
|
|
|
return true;
|
|
}
|
|
|
|
if (!eventArgs.Target.TryGetComponent(out PuddleComponent? puddleComponent))
|
|
{
|
|
return true;
|
|
}
|
|
// Essentially pickup either:
|
|
// - _pickupAmount,
|
|
// - whatever's left in the puddle, or
|
|
// - whatever we can still hold (whichever's smallest)
|
|
var transferAmount = ReagentUnit.Min(ReagentUnit.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
|
bool puddleCleaned = puddleComponent.CurrentVolume - transferAmount <= 0;
|
|
|
|
if (transferAmount == 0)
|
|
{
|
|
if (puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
|
{
|
|
puddleComponent.Owner.Delete();
|
|
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
|
|
puddleCleaned = true;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
puddleComponent.SplitSolution(transferAmount);
|
|
}
|
|
|
|
if (puddleCleaned) //After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly.
|
|
{
|
|
contents.SplitSolution(transferAmount).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
|
}
|
|
else
|
|
{
|
|
contents.SplitSolution(transferAmount);
|
|
}
|
|
|
|
// Give some visual feedback shit's happening (for anyone who can't hear sound)
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("Swish"));
|
|
|
|
if (!string.IsNullOrWhiteSpace(_pickupSound))
|
|
{
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_pickupSound, Owner);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|