Mop & Bucket Behaviour Change (#6193)
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using Content.Server.Chemistry.EntitySystems;
|
using Content.Server.Chemistry.EntitySystems;
|
||||||
using Content.Server.DoAfter;
|
using Content.Server.DoAfter;
|
||||||
using Content.Shared.Chemistry.Reagent;
|
using Content.Shared.Chemistry.Reagent;
|
||||||
|
using Content.Shared.Chemistry.Components;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Helpers;
|
using Content.Shared.Interaction.Helpers;
|
||||||
@@ -70,11 +71,7 @@ namespace Content.Server.Fluids.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mopComponent.CurrentVolume == mopComponent.MaxVolume)
|
|
||||||
{
|
|
||||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("bucket-component-mop-is-full-message"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentlyUsing.Add(eventArgs.Using);
|
_currentlyUsing.Add(eventArgs.Using);
|
||||||
|
|
||||||
@@ -92,25 +89,49 @@ namespace Content.Server.Fluids.Components
|
|||||||
CurrentVolume <= 0 || !Owner.InRangeUnobstructed(mopComponent.Owner))
|
CurrentVolume <= 0 || !Owner.InRangeUnobstructed(mopComponent.Owner))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Top up mops solution given it needs it to annihilate puddles I guess
|
//Checks if the mop is empty
|
||||||
|
if(mopComponent.CurrentVolume == 0)
|
||||||
var transferAmount = FixedPoint2.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
|
|
||||||
if (transferAmount == 0)
|
|
||||||
{
|
{
|
||||||
return false;
|
// 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
|
||||||
var mopContents = mopComponent.MopSolution;
|
|
||||||
|
|
||||||
if (mopContents == null)
|
|
||||||
{
|
{
|
||||||
return false;
|
//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"));
|
||||||
|
|
||||||
var solution = solutionsSys.SplitSolution(Owner, contents, transferAmount);
|
|
||||||
if (!solutionsSys.TryAddSolution(mopComponent.Owner, mopContents, solution))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(Owner), _sound.GetSound(), Owner);
|
SoundSystem.Play(Filter.Pvs(Owner), _sound.GetSound(), Owner);
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace Content.Server.Fluids.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Mopping { get; private set; }
|
public bool Mopping { get; private set; }
|
||||||
|
|
||||||
|
// MopSolution Object stores whatever solution the mop has absorbed.
|
||||||
public Solution? MopSolution
|
public Solution? MopSolution
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -43,6 +44,7 @@ namespace Content.Server.Fluids.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaxVolume is the Maximum volume the mop can absorb (however, this is defined in janitor.yml)
|
||||||
public FixedPoint2 MaxVolume
|
public FixedPoint2 MaxVolume
|
||||||
{
|
{
|
||||||
get => MopSolution?.MaxVolume ?? FixedPoint2.Zero;
|
get => MopSolution?.MaxVolume ?? FixedPoint2.Zero;
|
||||||
@@ -56,8 +58,12 @@ namespace Content.Server.Fluids.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CurrentVolume is the volume the mop has absorbed.
|
||||||
public FixedPoint2 CurrentVolume => MopSolution?.CurrentVolume ?? FixedPoint2.Zero;
|
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
|
// Currently there's a separate amount for pickup and dropoff so
|
||||||
// Picking up a puddle requires multiple clicks
|
// Picking up a puddle requires multiple clicks
|
||||||
// Dumping in a bucket requires 1 click
|
// Dumping in a bucket requires 1 click
|
||||||
@@ -99,11 +105,6 @@ namespace Content.Server.Fluids.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CurrentVolume <= 0)
|
|
||||||
{
|
|
||||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("mop-component-mop-is-dry-message"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eventArgs.Target is not {Valid: true} target)
|
if (eventArgs.Target is not {Valid: true} target)
|
||||||
{
|
{
|
||||||
@@ -117,8 +118,15 @@ namespace Content.Server.Fluids.Components
|
|||||||
!solutionSystem.TryGetSolution((puddleComponent).Owner, puddleComponent.SolutionName, out var puddleSolution))
|
!solutionSystem.TryGetSolution((puddleComponent).Owner, puddleComponent.SolutionName, out var puddleSolution))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// So if the puddle has 20 units we mop in 2 seconds. Don't just store CurrentVolume given it can change so need to re-calc it anyway.
|
// if the mop is full
|
||||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleSolution.CurrentVolume.Float() / 10.0f,
|
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)
|
target: target)
|
||||||
{
|
{
|
||||||
BreakOnUserMove = true,
|
BreakOnUserMove = true,
|
||||||
@@ -138,30 +146,22 @@ namespace Content.Server.Fluids.Components
|
|||||||
FixedPoint2 transferAmount;
|
FixedPoint2 transferAmount;
|
||||||
// does the puddle actually have reagents? it might not if its a weird cosmetic entity.
|
// does the puddle actually have reagents? it might not if its a weird cosmetic entity.
|
||||||
if (puddleSolution.TotalVolume == 0)
|
if (puddleSolution.TotalVolume == 0)
|
||||||
transferAmount = FixedPoint2.Min(PickupAmount, CurrentVolume);
|
transferAmount = FixedPoint2.Min(PickupAmount, AvailableVolume);
|
||||||
else
|
else
|
||||||
transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, CurrentVolume);
|
transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, AvailableVolume);
|
||||||
|
|
||||||
|
|
||||||
// is the puddle cleaned?
|
// is the puddle cleaned?
|
||||||
if (puddleSolution.TotalVolume - transferAmount <= 0)
|
bool isCleaned = (puddleSolution.TotalVolume - transferAmount <= 0);
|
||||||
|
|
||||||
|
// Transfers solution from the puddle to the mop
|
||||||
|
solutionSystem.TryAddSolution(Owner, contents, solutionSystem.SplitSolution(target, puddleSolution, transferAmount));
|
||||||
|
|
||||||
|
if (isCleaned)
|
||||||
{
|
{
|
||||||
|
// deletes the puddle
|
||||||
_entities.DeleteEntity(puddleComponent.Owner);
|
_entities.DeleteEntity(puddleComponent.Owner);
|
||||||
|
|
||||||
// After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly.
|
|
||||||
// we do this WITHOUT adding to the existing puddle. Otherwise we have might have water puddles with the vomit sprite.
|
|
||||||
var splitSolution = solutionSystem.SplitSolution(Owner, contents, transferAmount)
|
|
||||||
.SplitSolution(ResidueAmount);
|
|
||||||
spillableSystem.SpillAt(splitSolution, eventArgs.ClickLocation, "PuddleSmear", combine: false);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// remove solution from the puddle
|
|
||||||
solutionSystem.SplitSolution(target, puddleSolution, transferAmount);
|
|
||||||
|
|
||||||
// and from the mop
|
|
||||||
solutionSystem.SplitSolution(Owner, contents, transferAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(Owner), _pickupSound.GetSound(), Owner);
|
SoundSystem.Play(Filter.Pvs(Owner), _pickupSound.GetSound(), Owner);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
bucket-component-bucket-is-empty-message = Bucket is empty
|
bucket-component-bucket-is-empty-message = Bucket is empty
|
||||||
bucket-component-mop-is-full-message = Bucket is full
|
bucket-component-mop-is-now-wet-message = Mop is now wet
|
||||||
|
bucket-component-mop-is-now-dry-message = Mop is now dry
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
mop-component-mop-is-dry-message = Mop needs to be wet!
|
mop-component-mop-is-dry-message = Mop needs to be wet!
|
||||||
|
mop-component-mop-is-full-message = Mop is full!
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
- type: SolutionContainerManager
|
- type: SolutionContainerManager
|
||||||
solutions:
|
solutions:
|
||||||
mop:
|
mop:
|
||||||
maxVol: 10
|
maxVol: 50
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
name: mop bucket
|
name: mop bucket
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
maxVol: 500
|
maxVol: 500
|
||||||
reagents:
|
reagents:
|
||||||
- ReagentId: Water
|
- ReagentId: Water
|
||||||
Quantity: 500
|
Quantity: 250 # half-full at roundstart to leave room for puddles
|
||||||
- type: Physics
|
- type: Physics
|
||||||
bodyType: Dynamic
|
bodyType: Dynamic
|
||||||
- type: Fixtures
|
- type: Fixtures
|
||||||
|
|||||||
Reference in New Issue
Block a user