Fix spill crash (#5480)
* fix spill * clean up mop component * remove unecessary code
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Content.Server.Chemistry.TileReactions
|
|||||||
{
|
{
|
||||||
if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return FixedPoint2.Zero;
|
if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return FixedPoint2.Zero;
|
||||||
|
|
||||||
return tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", true, false) != null ? reactVolume : FixedPoint2.Zero;
|
return tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", true, false, true) != null ? reactVolume : FixedPoint2.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,13 @@ namespace Content.Server.Fluids.Components
|
|||||||
// Dumping in a bucket requires 1 click
|
// 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
|
// Long-term you'd probably use a cooldown and start the pickup once we have some form of global cooldown
|
||||||
[DataField("pickup_amount")]
|
[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")]
|
[DataField("pickup_sound")]
|
||||||
private SoundSpecifier _pickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
|
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
|
* 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.
|
* 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 ||
|
Mopping ||
|
||||||
!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentVolume = CurrentVolume;
|
if (CurrentVolume <= 0)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("mop-component-mop-is-dry-message"));
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("mop-component-mop-is-dry-message"));
|
||||||
return false;
|
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.
|
// 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)
|
target: eventArgs.Target)
|
||||||
{
|
{
|
||||||
BreakOnUserMove = true,
|
BreakOnUserMove = true,
|
||||||
BreakOnStun = true,
|
BreakOnStun = true,
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
};
|
};
|
||||||
|
Mopping = true;
|
||||||
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterArgs);
|
var result = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(doAfterArgs);
|
||||||
|
|
||||||
Mopping = false;
|
Mopping = false;
|
||||||
|
|
||||||
if (result == DoAfterStatus.Cancelled ||
|
if (result == DoAfterStatus.Cancelled ||
|
||||||
@@ -136,39 +131,32 @@ namespace Content.Server.Fluids.Components
|
|||||||
puddleComponent.Deleted)
|
puddleComponent.Deleted)
|
||||||
return false;
|
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>();
|
FixedPoint2 transferAmount;
|
||||||
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
|
// does the puddle actually have reagents? it might not if its a weird cosmetic entity.
|
||||||
if (transferAmount == 0)
|
if (puddleSolution.TotalVolume == 0)
|
||||||
{
|
transferAmount = FixedPoint2.Min(PickupAmount, CurrentVolume);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
transferAmount = FixedPoint2.Min(PickupAmount, puddleSolution.TotalVolume, CurrentVolume);
|
||||||
if (solutionSystem.TryGetSolution(eventArgs.Target.Uid, puddleComponent.SolutionName, out var puddleSolution))
|
|
||||||
solutionSystem.SplitSolution(eventArgs.Target.Uid, puddleSolution, transferAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
solutionSystem.SplitSolution(Owner.Uid, contents, transferAmount)
|
||||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
.SplitSolution(ResidueAmount)
|
||||||
|
.SpillAt(eventArgs.ClickLocation, "PuddleSmear", combine: false);
|
||||||
}
|
}
|
||||||
else
|
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);
|
SoundSystem.Play(Filter.Pvs(Owner), _pickupSound.GetSound(), Owner);
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ namespace Content.Server.Fluids.Components
|
|||||||
/// <param name="prototype">The prototype to use.</param>
|
/// <param name="prototype">The prototype to use.</param>
|
||||||
/// <param name="sound">Play the spill sound.</param>
|
/// <param name="sound">Play the spill sound.</param>
|
||||||
/// <returns>The puddle if one was created, null otherwise.</returns>
|
/// <returns>The puddle if one was created, null otherwise.</returns>
|
||||||
|
/// <param name="combine">Whether to attempt to merge with existing puddles</param>
|
||||||
public static PuddleComponent? SpillAt(this Solution solution, IEntity entity, string prototype,
|
public static PuddleComponent? SpillAt(this Solution solution, IEntity entity, string prototype,
|
||||||
bool sound = true)
|
bool sound = true, bool combine = true)
|
||||||
{
|
{
|
||||||
return solution.SpillAt(entity.Transform.Coordinates, prototype, sound);
|
return solution.SpillAt(entity.Transform.Coordinates, prototype, sound, combine: combine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -43,13 +44,14 @@ namespace Content.Server.Fluids.Components
|
|||||||
/// <param name="prototype">The prototype to use.</param>
|
/// <param name="prototype">The prototype to use.</param>
|
||||||
/// <param name="sound">Play the spill sound.</param>
|
/// <param name="sound">Play the spill sound.</param>
|
||||||
/// <param name="entityManager"></param>
|
/// <param name="entityManager"></param>
|
||||||
|
/// <param name="combine">Whether to attempt to merge with existing puddles</param>
|
||||||
/// <returns>The puddle if one was created, null otherwise.</returns>
|
/// <returns>The puddle if one was created, null otherwise.</returns>
|
||||||
public static PuddleComponent? SpillAt(this Solution solution, EntityUid entity, string prototype,
|
public static PuddleComponent? SpillAt(this Solution solution, EntityUid entity, string prototype,
|
||||||
bool sound = true, IEntityManager? entityManager = null)
|
bool sound = true, IEntityManager? entityManager = null, bool combine = true)
|
||||||
{
|
{
|
||||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
return solution.SpillAt(entityManager.GetComponent<TransformComponent>(entity).Coordinates, prototype, sound);
|
return solution.SpillAt(entityManager.GetComponent<TransformComponent>(entity).Coordinates, prototype, sound, combine: combine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -62,11 +64,12 @@ namespace Content.Server.Fluids.Components
|
|||||||
/// <param name="prototype">The prototype to use.</param>
|
/// <param name="prototype">The prototype to use.</param>
|
||||||
/// <param name="puddle">The puddle if one was created, null otherwise.</param>
|
/// <param name="puddle">The puddle if one was created, null otherwise.</param>
|
||||||
/// <param name="sound">Play the spill sound.</param>
|
/// <param name="sound">Play the spill sound.</param>
|
||||||
|
/// <param name="combine">Whether to attempt to merge with existing puddles</param>
|
||||||
/// <returns>True if a puddle was created, false otherwise.</returns>
|
/// <returns>True if a puddle was created, false otherwise.</returns>
|
||||||
public static bool TrySpillAt(this Solution solution, IEntity entity, string prototype,
|
public static bool TrySpillAt(this Solution solution, IEntity entity, string prototype,
|
||||||
[NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true)
|
[NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true, bool combine = true)
|
||||||
{
|
{
|
||||||
puddle = solution.SpillAt(entity, prototype, sound);
|
puddle = solution.SpillAt(entity, prototype, sound, combine: combine);
|
||||||
return puddle != null;
|
return puddle != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +80,10 @@ namespace Content.Server.Fluids.Components
|
|||||||
/// <param name="coordinates">The coordinates to spill the solution at.</param>
|
/// <param name="coordinates">The coordinates to spill the solution at.</param>
|
||||||
/// <param name="prototype">The prototype to use.</param>
|
/// <param name="prototype">The prototype to use.</param>
|
||||||
/// <param name="sound">Whether or not to play the spill sound.</param>
|
/// <param name="sound">Whether or not to play the spill sound.</param>
|
||||||
|
/// <param name="combine">Whether to attempt to merge with existing puddles</param>
|
||||||
/// <returns>The puddle if one was created, null otherwise.</returns>
|
/// <returns>The puddle if one was created, null otherwise.</returns>
|
||||||
public static PuddleComponent? SpillAt(this Solution solution, EntityCoordinates coordinates, string prototype,
|
public static PuddleComponent? SpillAt(this Solution solution, EntityCoordinates coordinates, string prototype,
|
||||||
bool overflow = true, bool sound = true)
|
bool overflow = true, bool sound = true, bool combine = true)
|
||||||
{
|
{
|
||||||
if (solution.TotalVolume == 0) return null;
|
if (solution.TotalVolume == 0) return null;
|
||||||
|
|
||||||
@@ -89,7 +93,7 @@ namespace Content.Server.Fluids.Components
|
|||||||
if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var mapGrid))
|
if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var mapGrid))
|
||||||
return null; // Let's not spill to space.
|
return null; // Let's not spill to space.
|
||||||
|
|
||||||
return SpillAt(mapGrid.GetTileRef(coordinates), solution, prototype, overflow, sound);
|
return SpillAt(mapGrid.GetTileRef(coordinates), solution, prototype, overflow, sound, combine: combine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -100,11 +104,12 @@ namespace Content.Server.Fluids.Components
|
|||||||
/// <param name="prototype">The prototype to use.</param>
|
/// <param name="prototype">The prototype to use.</param>
|
||||||
/// <param name="puddle">The puddle if one was created, null otherwise.</param>
|
/// <param name="puddle">The puddle if one was created, null otherwise.</param>
|
||||||
/// <param name="sound">Play the spill sound.</param>
|
/// <param name="sound">Play the spill sound.</param>
|
||||||
|
/// <param name="combine">Whether to attempt to merge with existing puddles</param>
|
||||||
/// <returns>True if a puddle was created, false otherwise.</returns>
|
/// <returns>True if a puddle was created, false otherwise.</returns>
|
||||||
public static bool TrySpillAt(this Solution solution, EntityCoordinates coordinates, string prototype,
|
public static bool TrySpillAt(this Solution solution, EntityCoordinates coordinates, string prototype,
|
||||||
[NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true)
|
[NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true, bool combine = true)
|
||||||
{
|
{
|
||||||
puddle = solution.SpillAt(coordinates, prototype, sound);
|
puddle = solution.SpillAt(coordinates, prototype, sound, combine: combine);
|
||||||
return puddle != null;
|
return puddle != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,17 +130,17 @@ namespace Content.Server.Fluids.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PuddleComponent? SpillAt(this TileRef tileRef, Solution solution, string prototype,
|
public static PuddleComponent? SpillAt(this TileRef tileRef, Solution solution, string prototype,
|
||||||
bool overflow = true, bool sound = true, bool noTileReact = false)
|
bool overflow = true, bool sound = true, bool noTileReact = false, bool combine = true)
|
||||||
{
|
{
|
||||||
if (solution.TotalVolume <= 0) return null;
|
if (solution.TotalVolume <= 0) return null;
|
||||||
|
|
||||||
|
// If space return early, let that spill go out into the void
|
||||||
|
if (tileRef.Tile.IsEmpty) return null;
|
||||||
|
|
||||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||||
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
||||||
|
|
||||||
// If space return early, let that spill go out into the void
|
|
||||||
if (tileRef.Tile.IsEmpty) return null;
|
|
||||||
|
|
||||||
var gridId = tileRef.GridIndex;
|
var gridId = tileRef.GridIndex;
|
||||||
if (!mapManager.TryGetGrid(gridId, out var mapGrid)) return null; // Let's not spill to invalid grids.
|
if (!mapManager.TryGetGrid(gridId, out var mapGrid)) return null; // Let's not spill to invalid grids.
|
||||||
|
|
||||||
@@ -155,10 +160,7 @@ namespace Content.Server.Fluids.Components
|
|||||||
|
|
||||||
// Get normalized co-ordinate for spill location and spill it in the centre
|
// Get normalized co-ordinate for spill location and spill it in the centre
|
||||||
// TODO: Does SnapGrid or something else already do this?
|
// TODO: Does SnapGrid or something else already do this?
|
||||||
var spillGridCoords = mapGrid.GridTileToLocal(tileRef.GridIndices);
|
var spillGridCoords = mapGrid.GridTileToWorld(tileRef.GridIndices);
|
||||||
|
|
||||||
PuddleComponent? puddle = null;
|
|
||||||
var spilt = false;
|
|
||||||
|
|
||||||
var spillEntities = IoCManager.Resolve<IEntityLookup>()
|
var spillEntities = IoCManager.Resolve<IEntityLookup>()
|
||||||
.GetEntitiesIntersecting(mapGrid.ParentMapId, spillGridCoords.Position).ToArray();
|
.GetEntitiesIntersecting(mapGrid.ParentMapId, spillGridCoords.Position).ToArray();
|
||||||
@@ -177,22 +179,20 @@ namespace Content.Server.Fluids.Components
|
|||||||
|
|
||||||
var puddleSystem = EntitySystem.Get<PuddleSystem>();
|
var puddleSystem = EntitySystem.Get<PuddleSystem>();
|
||||||
|
|
||||||
foreach (var spillEntity in spillEntities)
|
if (combine)
|
||||||
{
|
{
|
||||||
if (!spillEntity.TryGetComponent(out PuddleComponent? puddleComponent)) continue;
|
foreach (var spillEntity in spillEntities)
|
||||||
|
{
|
||||||
|
if (!spillEntity.TryGetComponent(out PuddleComponent? puddleComponent)) continue;
|
||||||
|
|
||||||
if (!overflow && puddleSystem.WouldOverflow(puddleComponent.Owner.Uid, solution, puddleComponent)) return null;
|
if (!overflow && puddleSystem.WouldOverflow(puddleComponent.Owner.Uid, solution, puddleComponent)) return null;
|
||||||
|
|
||||||
if (!puddleSystem.TryAddSolution(puddleComponent.Owner.Uid, solution, sound)) continue;
|
if (!puddleSystem.TryAddSolution(puddleComponent.Owner.Uid, solution, sound)) continue;
|
||||||
|
|
||||||
puddle = puddleComponent;
|
return puddleComponent;
|
||||||
spilt = true;
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Did we add to an existing puddle
|
|
||||||
if (spilt) return puddle;
|
|
||||||
|
|
||||||
var puddleEnt = serverEntityManager.SpawnEntity(prototype, spillGridCoords);
|
var puddleEnt = serverEntityManager.SpawnEntity(prototype, spillGridCoords);
|
||||||
var newPuddleComponent = puddleEnt.GetComponent<PuddleComponent>();
|
var newPuddleComponent = puddleEnt.GetComponent<PuddleComponent>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user