Mopping enhancements (#3298)

* Bucket starts with water
* Mop has do_after
* Bucket has do_after (user allowed to move while using it as long as they're in range at the end for maximum jannie skill)
* Random cleanup

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-02-25 11:32:08 +11:00
committed by GitHub
parent 48b1336e3c
commit adbcfbb951
3 changed files with 115 additions and 77 deletions

View File

@@ -1,13 +1,17 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Shared.Chemistry;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Fluids
@@ -20,6 +24,8 @@ namespace Content.Server.GameObjects.Components.Fluids
{
public override string Name => "Bucket";
private List<EntityUid> _currentlyUsing = new();
public ReagentUnit MaxVolume
{
get => Owner.TryGetComponent(out SolutionContainerComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
@@ -51,64 +57,50 @@ namespace Content.Server.GameObjects.Components.Fluids
Owner.EnsureComponentWarn<SolutionContainerComponent>();
}
private bool TryGiveToMop(MopComponent mopComponent)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
{
return false;
}
var mopContents = mopComponent.Contents;
if (mopContents == null)
{
return false;
}
// Let's fill 'er up
// If this is called the mop should be empty but just in case we'll do Max - Current
var transferAmount = ReagentUnit.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
var solution = contents.SplitSolution(transferAmount);
if (!mopContents.TryAddSolution(solution) || mopComponent.CurrentVolume == 0)
{
return false;
}
if (_sound == null)
{
return true;
}
EntitySystem.Get<AudioSystem>().PlayFromEntity(_sound, Owner);
return true;
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents) ||
_currentlyUsing.Contains(eventArgs.Using.Uid) ||
!eventArgs.Using.TryGetComponent(out MopComponent? mopComponent) ||
mopComponent.Mopping)
{
return false;
}
if (!eventArgs.Using.TryGetComponent(out MopComponent? mopComponent))
if (CurrentVolume <= 0)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("Bucket is empty"));
return false;
}
// Give to the mop if it's empty
if (mopComponent.CurrentVolume == 0)
if (mopComponent.CurrentVolume == mopComponent.MaxVolume)
{
if (!TryGiveToMop(mopComponent))
{
return false;
}
Owner.PopupMessage(eventArgs.User, Loc.GetString("Splish"));
return true;
Owner.PopupMessage(eventArgs.User, Loc.GetString("Mop is full"));
return false;
}
var transferAmount = ReagentUnit.Min(mopComponent.CurrentVolume, MaxVolume - CurrentVolume);
_currentlyUsing.Add(eventArgs.Using.Uid);
// 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>().DoAfter(doAfterArgs);
_currentlyUsing.Remove(eventArgs.Using.Uid);
if (result == DoAfterStatus.Cancelled ||
Owner.Deleted ||
mopComponent.Deleted ||
CurrentVolume <= 0 ||
!Owner.InRangeUnobstructed(mopComponent.Owner))
return false;
// Top up mops solution given it needs it to annihilate puddles I guess
var transferAmount = ReagentUnit.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
if (transferAmount == 0)
{
return false;
@@ -121,23 +113,17 @@ namespace Content.Server.GameObjects.Components.Fluids
return false;
}
var solution = mopContents.SplitSolution(transferAmount);
if (!contents.TryAddSolution(solution))
var solution = contents.SplitSolution(transferAmount);
if (!mopContents.TryAddSolution(solution))
{
//This really shouldn't happen
throw new InvalidOperationException();
return false;
}
// Give some visual feedback shit's happening (for anyone who can't hear sound)
Owner.PopupMessage(eventArgs.User, Loc.GetString("Sploosh"));
if (_sound == null)
if (_sound != null)
{
return true;
EntitySystem.Get<AudioSystem>().PlayFromEntity(_sound, Owner);
}
EntitySystem.Get<AudioSystem>().PlayFromEntity(_sound, Owner);
return true;
}
}