* carpet

* reviews

* why tf i gotta fix integration tests in the carpet pr
This commit is contained in:
mirrorcult
2021-11-22 18:01:51 -07:00
committed by GitHub
parent 6c88a15c7e
commit 6fc397f801
11 changed files with 147 additions and 6 deletions

View File

@@ -29,6 +29,11 @@ namespace Content.Server.Chemistry.Components
public int Amount { get; set; }
public SolutionAreaEffectInceptionComponent? Inception { get; set; }
/// <summary>
/// Have we reacted with our tile yet?
/// </summary>
public bool ReactedTile = false;
/// <summary>
/// Adds an <see cref="SolutionAreaEffectInceptionComponent"/> to owner so the effect starts spreading and reacting.
/// </summary>
@@ -138,7 +143,12 @@ namespace Content.Server.Chemistry.Components
var reagent = PrototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
// React with the tile the effect is on
reagent.ReactionTile(tile, reagentQuantity.Quantity * solutionFraction);
// We don't multiply by solutionFraction here since the tile is only ever reacted once
if (!ReactedTile)
{
reagent.ReactionTile(tile, reagentQuantity.Quantity);
ReactedTile = true;
}
// Touch every entity on the tile
foreach (var entity in tile.GetEntitiesInTileFast().ToArray())

View File

@@ -0,0 +1,63 @@
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Maps;
using Content.Shared.Whitelist;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Chemistry.TileReactions;
[DataDefinition]
public class CreateEntityReaction : ITileReaction
{
[DataField("entity", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string Entity = default!;
[DataField("usage")]
public FixedPoint2 Usage = FixedPoint2.New(1);
/// <summary>
/// How many of the whitelisted entity can fit on one tile?
/// </summary>
[DataField("maxOnTile")]
public int MaxOnTile = 1;
/// <summary>
/// The whitelist to use when determining what counts as "max entities on a tile".0
/// </summary>
[DataField("maxOnTileWhitelist")]
public EntityWhitelist? Whitelist;
public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume)
{
if (reactVolume >= Usage)
{
// TODO probably pass this in args like reagenteffects do.
var entMan = IoCManager.Resolve<IEntityManager>();
if (Whitelist != null)
{
int acc = 0;
foreach (var ent in tile.GetEntitiesInTile())
{
if (Whitelist.IsValid(ent.Uid))
acc += 1;
if (acc >= MaxOnTile)
return FixedPoint2.Zero;
}
}
entMan.SpawnEntity(Entity, tile.GridPosition().Offset(new Vector2(0.5f, 0.5f)));
return Usage;
}
return FixedPoint2.Zero;
}
}

View File

@@ -10,6 +10,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.Fluids.Components
{
@@ -129,7 +130,7 @@ namespace Content.Server.Fluids.Components
if (solution.TotalVolume <= 0) return null;
var mapManager = IoCManager.Resolve<IMapManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
// If space return early, let that spill go out into the void
@@ -138,6 +139,17 @@ namespace Content.Server.Fluids.Components
var gridId = tileRef.GridIndex;
if (!mapManager.TryGetGrid(gridId, out var mapGrid)) return null; // Let's not spill to invalid grids.
// First, do all tile reactions
foreach (var reagent in solution.Contents.ToArray())
{
var proto = prototypeManager.Index<ReagentPrototype>(reagent.ReagentId);
proto.ReactionTile(tileRef, reagent.Quantity);
}
// Tile reactions used up everything.
if (solution.CurrentVolume == FixedPoint2.Zero)
return null;
// Get normalized co-ordinate for spill location and spill it in the centre
// TODO: Does SnapGrid or something else already do this?
var spillGridCoords = mapGrid.GridTileToLocal(tileRef.GridIndices);