Fix spill crash (#5480)
* fix spill * clean up mop component * remove unecessary code
This commit is contained in:
@@ -61,7 +61,13 @@ namespace Content.Server.Fluids.Components
|
||||
// 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
|
||||
[DataField("pickup_amount")]
|
||||
public FixedPoint2 PickupAmount { get; } = FixedPoint2.New(5);
|
||||
public FixedPoint2 PickupAmount { get; } = FixedPoint2.New(10);
|
||||
|
||||
/// <summary>
|
||||
/// After cleaning a floor tile, leave this much reagent as a puddle. I.e., leave behind a wet floor.
|
||||
/// </summary>
|
||||
[DataField("residueAmount")]
|
||||
public FixedPoint2 ResidueAmount { get; } = FixedPoint2.New(5);
|
||||
|
||||
[DataField("pickup_sound")]
|
||||
private SoundSpecifier _pickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
|
||||
@@ -81,54 +87,43 @@ namespace Content.Server.Fluids.Components
|
||||
* It will try to destroy solution on the mop to do so, and if it is successful
|
||||
* will spill some of the mop's solution onto the puddle which will evaporate eventually.
|
||||
*/
|
||||
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var contents ) ||
|
||||
if (!solutionSystem.TryGetSolution(Owner.Uid, SolutionName, out var contents ) ||
|
||||
Mopping ||
|
||||
!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var currentVolume = CurrentVolume;
|
||||
|
||||
if (eventArgs.Target == null)
|
||||
{
|
||||
if (currentVolume > 0)
|
||||
{
|
||||
// Drop the liquid on the mop on to the ground
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, CurrentVolume)
|
||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!eventArgs.Target.TryGetComponent(out PuddleComponent? puddleComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var puddleVolume = puddleComponent.CurrentVolume;
|
||||
|
||||
if (currentVolume <= 0)
|
||||
if (CurrentVolume <= 0)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("mop-component-mop-is-dry-message"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Mopping = true;
|
||||
if (eventArgs.Target == null)
|
||||
{
|
||||
// Drop the liquid on the mop on to the ground
|
||||
solutionSystem.SplitSolution(Owner.Uid, contents, FixedPoint2.Min(ResidueAmount, CurrentVolume))
|
||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!eventArgs.Target.TryGetComponent(out PuddleComponent? puddleComponent) ||
|
||||
!solutionSystem.TryGetSolution(puddleComponent.OwnerUid, puddleComponent.SolutionName, out var puddleSolution))
|
||||
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.
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleVolume.Float() / 10.0f,
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleSolution.CurrentVolume.Float() / 10.0f,
|
||||
target: eventArgs.Target)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
};
|
||||
Mopping = true;
|
||||
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterArgs);
|
||||
|
||||
Mopping = false;
|
||||
|
||||
if (result == DoAfterStatus.Cancelled ||
|
||||
@@ -136,39 +131,32 @@ namespace Content.Server.Fluids.Components
|
||||
puddleComponent.Deleted)
|
||||
return false;
|
||||
|
||||
// Annihilate the puddle
|
||||
var transferAmount = FixedPoint2.Min(FixedPoint2.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
||||
var puddleCleaned = puddleComponent.CurrentVolume - transferAmount <= 0;
|
||||
|
||||
var puddleSystem = EntitySystem.Get<PuddleSystem>();
|
||||
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
if (transferAmount == 0)
|
||||
{
|
||||
if (puddleSystem.EmptyHolder(puddleComponent.Owner.Uid, puddleComponent)) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
{
|
||||
puddleComponent.Owner.Delete();
|
||||
transferAmount = FixedPoint2.Min(FixedPoint2.New(5), CurrentVolume);
|
||||
puddleCleaned = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
FixedPoint2 transferAmount;
|
||||
// does the puddle actually have reagents? it might not if its a weird cosmetic entity.
|
||||
if (puddleSolution.TotalVolume == 0)
|
||||
transferAmount = FixedPoint2.Min(PickupAmount, CurrentVolume);
|
||||
else
|
||||
{
|
||||
if (solutionSystem.TryGetSolution(eventArgs.Target.Uid, puddleComponent.SolutionName, out var puddleSolution))
|
||||
solutionSystem.SplitSolution(eventArgs.Target.Uid, puddleSolution, transferAmount);
|
||||
}
|
||||
transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, CurrentVolume);
|
||||
|
||||
if (puddleCleaned) //After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly.
|
||||
// is the puddle cleaned?
|
||||
if (puddleSolution.TotalVolume - transferAmount <= 0)
|
||||
{
|
||||
puddleComponent.Owner.Delete();
|
||||
|
||||
// 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.
|
||||
solutionSystem.SplitSolution(Owner.Uid, contents, transferAmount)
|
||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
.SplitSolution(ResidueAmount)
|
||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear", combine: false);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, transferAmount);
|
||||
// remove solution from the puddle
|
||||
solutionSystem.SplitSolution(eventArgs.Target.Uid, puddleSolution, transferAmount);
|
||||
|
||||
// and from the mop
|
||||
solutionSystem.SplitSolution(Owner.Uid, contents, transferAmount);
|
||||
}
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _pickupSound.GetSound(), Owner);
|
||||
|
||||
Reference in New Issue
Block a user