2021-03-05 01:08:38 +01:00
|
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Server.Cleanable;
|
|
|
|
|
|
using Content.Server.Coordinates.Helpers;
|
2021-12-03 15:35:57 +01:00
|
|
|
|
using Content.Server.Decals;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Chemistry.Reaction;
|
|
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-11-03 16:48:03 -07:00
|
|
|
|
using Content.Shared.FixedPoint;
|
2021-12-03 11:43:22 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-10-13 13:40:05 +02:00
|
|
|
|
using Robust.Shared.Map;
|
2021-12-03 15:35:57 +01:00
|
|
|
|
using Robust.Shared.Maths;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-13 13:40:05 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Chemistry.TileReactions
|
|
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataDefinition]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class CleanTileReaction : ITileReaction
|
2020-10-13 13:40:05 +02:00
|
|
|
|
{
|
2022-02-04 20:26:11 -06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Multiplier used in CleanTileReaction.
|
|
|
|
|
|
/// 1 (default) means normal consumption rate of the cleaning reagent.
|
|
|
|
|
|
/// 0 means no consumption of the cleaning reagent, i.e. the reagent is inexhaustible.
|
|
|
|
|
|
/// </summary>
|
2021-11-25 00:06:13 -06:00
|
|
|
|
[DataField("cleanAmountMultiplier")]
|
|
|
|
|
|
public float CleanAmountMultiplier { get; private set; } = 1.0f;
|
|
|
|
|
|
|
2021-11-03 16:48:03 -07:00
|
|
|
|
FixedPoint2 ITileReaction.TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
|
2020-10-13 13:40:05 +02:00
|
|
|
|
{
|
2022-01-09 23:47:01 +11:00
|
|
|
|
var entities = IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(tile).ToArray();
|
2021-11-03 16:48:03 -07:00
|
|
|
|
var amount = FixedPoint2.Zero;
|
2021-12-08 17:04:21 +01:00
|
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
2020-10-13 13:40:05 +02:00
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
|
if (entMan.TryGetComponent(entity, out CleanableComponent? cleanable))
|
2020-10-13 13:40:05 +02:00
|
|
|
|
{
|
2022-02-04 20:26:11 -06:00
|
|
|
|
var next = amount + (cleanable.CleanAmount * CleanAmountMultiplier);
|
2020-10-13 13:40:05 +02:00
|
|
|
|
// Nothing left?
|
|
|
|
|
|
if (reactVolume < next)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
amount = next;
|
2021-12-08 17:04:21 +01:00
|
|
|
|
entMan.QueueDeleteEntity(entity);
|
2020-10-13 13:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-03 15:35:57 +01:00
|
|
|
|
var decalSystem = EntitySystem.Get<DecalSystem>();
|
|
|
|
|
|
foreach (var uid in decalSystem.GetDecalsInRange(tile.GridIndex, tile.GridIndices+new Vector2(0.5f, 0.5f), validDelegate: x => x.Cleanable))
|
|
|
|
|
|
{
|
|
|
|
|
|
decalSystem.RemoveDecal(tile.GridIndex, uid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-13 13:40:05 +02:00
|
|
|
|
return amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|