mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Prevent area-effect-reactions in space. (#7455)
This commit is contained in:
parent
c5bcd70b07
commit
44649e7fed
1 changed files with 22 additions and 7 deletions
|
|
@ -13,6 +13,7 @@ using Robust.Shared.Log;
|
|||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
|
|
@ -27,6 +28,7 @@ namespace Content.Server.Chemistry.Components
|
|||
[Dependency] protected readonly IMapManager MapManager = default!;
|
||||
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _systems = default!;
|
||||
|
||||
public int Amount { get; set; }
|
||||
public SolutionAreaEffectInceptionComponent? Inception { get; set; }
|
||||
|
|
@ -64,30 +66,43 @@ namespace Content.Server.Chemistry.Components
|
|||
/// </summary>
|
||||
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.");
|
||||
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)
|
||||
{
|
||||
var grid = MapManager.GetGrid(_entities.GetComponent<TransformComponent>(Owner).GridID);
|
||||
var coords = _entities.GetComponent<TransformComponent>(Owner).Coordinates;
|
||||
foreach (var neighbor in grid.GetInDir(coords, dir))
|
||||
// Currently no support for spreading off or across grids.
|
||||
var index = origin + dir.ToIntVec();
|
||||
if (!grid.TryGetTileRef(index, out var tile) || tile.Tile.IsEmpty)
|
||||
return;
|
||||
|
||||
foreach (var neighbor in grid.GetAnchoredEntities(index))
|
||||
{
|
||||
if (_entities.TryGetComponent(neighbor,
|
||||
out SolutionAreaEffectComponent? comp) && comp.Inception == Inception)
|
||||
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,
|
||||
out AirtightComponent? airtight) && airtight.AirBlocked)
|
||||
return;
|
||||
}
|
||||
|
||||
var newEffect = _entities.SpawnEntity(
|
||||
_entities.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID,
|
||||
grid.DirectionToGrid(coords, dir));
|
||||
meta.EntityPrototype.ID,
|
||||
grid.GridTileToLocal(index));
|
||||
|
||||
if (!_entities.TryGetComponent(newEffect, out SolutionAreaEffectComponent? effectComponent))
|
||||
{
|
||||
|
|
@ -95,7 +110,7 @@ namespace Content.Server.Chemistry.Components
|
|||
return;
|
||||
}
|
||||
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
if (solSys.TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
effectComponent.TryAddSolution(solution.Clone());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue