2020-08-24 13:39:00 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using Content.Server.GameObjects.Components.Chemistry;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
using Content.Shared.Chemistry;
|
|
|
|
|
|
using Content.Shared.Interfaces;
|
2020-07-18 22:51:56 -07:00
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
using Content.Shared.Utility;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
2020-12-17 10:45:04 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Server.GameObjects;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Fluids
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// For cleaning up puddles
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RegisterComponent]
|
2020-05-23 17:23:25 +02:00
|
|
|
|
public class MopComponent : Component, IAfterInteract
|
2020-04-22 04:23:12 +10:00
|
|
|
|
{
|
|
|
|
|
|
public override string Name => "Mop";
|
2020-08-24 13:39:00 +02:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
public SolutionContainerComponent? Contents => Owner.GetComponentOrNull<SolutionContainerComponent>();
|
2020-04-22 04:23:12 +10:00
|
|
|
|
|
|
|
|
|
|
public ReagentUnit MaxVolume
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
get => Owner.GetComponentOrNull<SolutionContainerComponent>()?.MaxVolume ?? ReagentUnit.Zero;
|
2020-08-24 13:39:00 +02:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-08-24 13:39:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
solution.MaxVolume = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 13:39:00 +02:00
|
|
|
|
public ReagentUnit CurrentVolume =>
|
2020-09-09 18:32:31 -04:00
|
|
|
|
Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
2020-08-24 13:39:00 +02:00
|
|
|
|
private string _pickupSound = "";
|
2020-04-22 04:23:12 +10:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
|
{
|
2020-07-07 13:19:00 -04:00
|
|
|
|
serializer.DataFieldCached(ref _pickupSound, "pickup_sound", "/Audio/Effects/Fluids/slosh.ogg");
|
2020-04-22 04:23:12 +10:00
|
|
|
|
// The turbo mop will pickup more
|
|
|
|
|
|
serializer.DataFieldCached(ref _pickupAmount, "pickup_amount", ReagentUnit.New(5));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2020-12-04 13:26:54 +01:00
|
|
|
|
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-03 14:05:31 +01:00
|
|
|
|
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
2020-04-22 04:23:12 +10:00
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
|
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
|
|
|
|
|
return false;
|
2020-05-23 02:27:31 -07:00
|
|
|
|
|
2020-07-11 16:49:54 -05:00
|
|
|
|
if (CurrentVolume <= 0)
|
|
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
|
return true;
|
2020-07-11 16:49:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-23 17:23:25 +02:00
|
|
|
|
if (eventArgs.Target == null)
|
2020-04-22 04:23:12 +10:00
|
|
|
|
{
|
2020-07-11 16:49:54 -05:00
|
|
|
|
// Drop the liquid on the mop on to the ground
|
2020-09-02 01:16:25 +02:00
|
|
|
|
contents.SplitSolution(CurrentVolume).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
2020-04-22 04:23:12 +10:00
|
|
|
|
|
2021-02-03 14:05:31 +01:00
|
|
|
|
return true;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 13:39:00 +02:00
|
|
|
|
if (!eventArgs.Target.TryGetComponent(out PuddleComponent? puddleComponent))
|
2020-04-22 04:23:12 +10:00
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
|
return true;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
// Essentially pickup either:
|
|
|
|
|
|
// - _pickupAmount,
|
|
|
|
|
|
// - whatever's left in the puddle, or
|
|
|
|
|
|
// - whatever we can still hold (whichever's smallest)
|
2020-07-11 16:49:54 -05:00
|
|
|
|
var transferAmount = ReagentUnit.Min(ReagentUnit.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
|
|
|
|
|
bool puddleCleaned = puddleComponent.CurrentVolume - transferAmount <= 0;
|
|
|
|
|
|
|
2020-04-22 04:23:12 +10:00
|
|
|
|
if (transferAmount == 0)
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
2020-07-11 16:49:54 -05:00
|
|
|
|
{
|
|
|
|
|
|
puddleComponent.Owner.Delete();
|
|
|
|
|
|
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
|
|
|
|
|
|
puddleCleaned = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
|
return true;
|
2020-07-11 16:49:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
puddleComponent.SplitSolution(transferAmount);
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-11 16:49:54 -05:00
|
|
|
|
if (puddleCleaned) //After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly.
|
|
|
|
|
|
{
|
2020-09-02 01:16:25 +02:00
|
|
|
|
contents.SplitSolution(transferAmount).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
2020-07-11 16:49:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2020-04-22 04:23:12 +10:00
|
|
|
|
{
|
2020-08-24 13:39:00 +02:00
|
|
|
|
contents.SplitSolution(transferAmount);
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Give some visual feedback shit's happening (for anyone who can't hear sound)
|
2020-08-23 12:53:09 +02:00
|
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("Swish"));
|
2020-04-22 04:23:12 +10:00
|
|
|
|
|
2021-02-03 14:05:31 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(_pickupSound))
|
2020-04-22 04:23:12 +10:00
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_pickupSound, Owner);
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-03 14:05:31 +01:00
|
|
|
|
return true;
|
2020-04-22 04:23:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|