Files
crystall-punk-14/Content.Server/GameObjects/Components/Fluids/MopComponent.cs

133 lines
4.8 KiB
C#
Raw Normal View History

#nullable enable
using Content.Server.GameObjects.Components.Chemistry;
2020-04-22 04:23:12 +10:00
using Content.Shared.Chemistry;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using Robust.Server.GameObjects.EntitySystems;
2020-04-22 04:23:12 +10:00
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
2020-04-22 04:23:12 +10:00
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
Async Interface IAfterInteract() (#2735) * Async Interface * Update Content.Server/GameObjects/Components/Fluids/MopComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Changed the glassbeaker * Update Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Interaction system fix * Removed I from the interface * Changed all implementations of the interface I could find * all public void implementation fixed * All built, no errors should remain * Update Resources/Prototypes/Entities/Objects/Specific/chemistry.yml Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Commit based off Sloth's commentary * Removed the Rag file from the PR * Reverted sloth's commentary changes on the publcity of the function * Injector component properly implemented interface * Update Content.Server/GameObjects/Components/Fluids/MopComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/Fluids/SprayComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: BlueberryShortcake <rubetskoy234@mail.ru> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-12-17 10:45:04 +03:00
using System.Threading.Tasks;
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";
public SolutionContainerComponent? Contents => Owner.GetComponentOrNull<SolutionContainerComponent>();
2020-04-22 04:23:12 +10:00
public ReagentUnit MaxVolume
{
get => Owner.GetComponentOrNull<SolutionContainerComponent>()?.MaxVolume ?? ReagentUnit.Zero;
set
{
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
{
solution.MaxVolume = value;
}
}
2020-04-22 04:23:12 +10:00
}
public ReagentUnit CurrentVolume =>
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;
private string _pickupSound = "";
2020-04-22 04:23:12 +10:00
/// <inheritdoc />
public override void ExposeData(ObjectSerializer serializer)
{
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();
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
2020-04-22 04:23:12 +10:00
}
Async Interface IAfterInteract() (#2735) * Async Interface * Update Content.Server/GameObjects/Components/Fluids/MopComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Changed the glassbeaker * Update Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Interaction system fix * Removed I from the interface * Changed all implementations of the interface I could find * all public void implementation fixed * All built, no errors should remain * Update Resources/Prototypes/Entities/Objects/Specific/chemistry.yml Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Commit based off Sloth's commentary * Removed the Rag file from the PR * Reverted sloth's commentary changes on the publcity of the function * Injector component properly implemented interface * Update Content.Server/GameObjects/Components/Fluids/MopComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/Fluids/SprayComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: BlueberryShortcake <rubetskoy234@mail.ru> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-12-17 10:45:04 +03:00
async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
2020-04-22 04:23:12 +10:00
{
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents)) return;
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
if (CurrentVolume <= 0)
{
return;
}
2020-05-23 17:23:25 +02:00
if (eventArgs.Target == null)
2020-04-22 04:23:12 +10:00
{
// Drop the liquid on the mop on to the ground
contents.SplitSolution(CurrentVolume).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
2020-04-22 04:23:12 +10:00
return;
}
if (!eventArgs.Target.TryGetComponent(out PuddleComponent? puddleComponent))
2020-04-22 04:23:12 +10:00
{
return;
}
// 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;
2020-04-22 04:23:12 +10:00
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;
}
}
else
{
puddleComponent.SplitSolution(transferAmount);
2020-04-22 04:23:12 +10:00
}
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
2020-04-22 04:23:12 +10: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)
Owner.PopupMessage(eventArgs.User, Loc.GetString("Swish"));
2020-04-22 04:23:12 +10:00
if (string.IsNullOrWhiteSpace(_pickupSound))
2020-04-22 04:23:12 +10:00
{
return;
}
EntitySystem.Get<AudioSystem>().PlayFromEntity(_pickupSound, Owner);
2020-04-22 04:23:12 +10:00
}
}
}