Prevent area-effect-reactions in space. (#7455)

This commit is contained in:
Leon Friedrich
2022-04-08 19:21:06 +12:00
committed by GitHub
parent c5bcd70b07
commit 44649e7fed

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Chemistry.Components namespace Content.Server.Chemistry.Components
{ {
@@ -27,6 +28,7 @@ namespace Content.Server.Chemistry.Components
[Dependency] protected readonly IMapManager MapManager = default!; [Dependency] protected readonly IMapManager MapManager = default!;
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!; [Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
[Dependency] private readonly IEntityManager _entities = default!; [Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IEntitySystemManager _systems = default!;
public int Amount { get; set; } public int Amount { get; set; }
public SolutionAreaEffectInceptionComponent? Inception { get; set; } public SolutionAreaEffectInceptionComponent? Inception { get; set; }
@@ -64,30 +66,43 @@ namespace Content.Server.Chemistry.Components
/// </summary> /// </summary>
public void Spread() public void Spread()
{ {
if (_entities.GetComponent<MetaDataComponent>(Owner).EntityPrototype == null) var meta = _entities.GetComponent<MetaDataComponent>(Owner);
if (meta.EntityPrototype == null)
{ {
Logger.Error("AreaEffectComponent needs its owner to be spawned by a prototype."); Logger.Error("AreaEffectComponent needs its owner to be spawned by a prototype.");
return; return;
} }
var xform = _entities.GetComponent<TransformComponent>(Owner);
var solSys = _systems.GetEntitySystem<SolutionContainerSystem>();
var grid = MapManager.GetGrid(xform.GridID);
var origin = grid.TileIndicesFor(xform.Coordinates);
DebugTools.Assert(xform.Anchored, "Area effect entity prototypes must be anchored.");
void SpreadToDir(Direction dir) void SpreadToDir(Direction dir)
{ {
var grid = MapManager.GetGrid(_entities.GetComponent<TransformComponent>(Owner).GridID); // Currently no support for spreading off or across grids.
var coords = _entities.GetComponent<TransformComponent>(Owner).Coordinates; var index = origin + dir.ToIntVec();
foreach (var neighbor in grid.GetInDir(coords, dir)) if (!grid.TryGetTileRef(index, out var tile) || tile.Tile.IsEmpty)
return;
foreach (var neighbor in grid.GetAnchoredEntities(index))
{ {
if (_entities.TryGetComponent(neighbor, if (_entities.TryGetComponent(neighbor,
out SolutionAreaEffectComponent? comp) && comp.Inception == Inception) out SolutionAreaEffectComponent? comp) && comp.Inception == Inception)
return; return;
// TODO for thindows and the like, need to check the directions that are being blocked.
// --> would then also mean you need to check for blockers on the origin tile.
if (_entities.TryGetComponent(neighbor, if (_entities.TryGetComponent(neighbor,
out AirtightComponent? airtight) && airtight.AirBlocked) out AirtightComponent? airtight) && airtight.AirBlocked)
return; return;
} }
var newEffect = _entities.SpawnEntity( var newEffect = _entities.SpawnEntity(
_entities.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID, meta.EntityPrototype.ID,
grid.DirectionToGrid(coords, dir)); grid.GridTileToLocal(index));
if (!_entities.TryGetComponent(newEffect, out SolutionAreaEffectComponent? effectComponent)) if (!_entities.TryGetComponent(newEffect, out SolutionAreaEffectComponent? effectComponent))
{ {
@@ -95,7 +110,7 @@ namespace Content.Server.Chemistry.Components
return; return;
} }
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)) if (solSys.TryGetSolution(Owner, SolutionName, out var solution))
{ {
effectComponent.TryAddSolution(solution.Clone()); effectComponent.TryAddSolution(solution.Clone());
} }