Split FleshAnomaly into two components #16001 (#16110)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Tom Leys
2023-05-06 01:08:37 +12:00
committed by GitHub
parent ff2e3c5cdb
commit cbaf61ad5e
5 changed files with 80 additions and 30 deletions

View File

@@ -11,7 +11,7 @@ using Robust.Shared.Random;
namespace Content.Server.Anomaly.Effects;
public sealed class FleshAnomalySystem : EntitySystem
public sealed class EntityAnomalySystem : EntitySystem
{
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IRobustRandom _random = default!;
@@ -21,12 +21,11 @@ public sealed class FleshAnomalySystem : EntitySystem
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<FleshAnomalyComponent, AnomalyPulseEvent>(OnPulse);
SubscribeLocalEvent<FleshAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
SubscribeLocalEvent<FleshAnomalyComponent, AnomalyStabilityChangedEvent>(OnSeverityChanged);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalyPulseEvent>(OnPulse);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
}
private void OnPulse(EntityUid uid, FleshAnomalyComponent component, ref AnomalyPulseEvent args)
private void OnPulse(EntityUid uid, EntitySpawnAnomalyComponent component, ref AnomalyPulseEvent args)
{
var range = component.SpawnRange * args.Stability;
var amount = (int) (component.MaxSpawnAmount * args.Severity + 0.5f);
@@ -35,33 +34,14 @@ public sealed class FleshAnomalySystem : EntitySystem
SpawnMonstersOnOpenTiles(component, xform, amount, range);
}
private void OnSupercritical(EntityUid uid, FleshAnomalyComponent component, ref AnomalySupercriticalEvent args)
private void OnSupercritical(EntityUid uid, EntitySpawnAnomalyComponent component, ref AnomalySupercriticalEvent args)
{
var xform = Transform(uid);
SpawnMonstersOnOpenTiles(component, xform, component.MaxSpawnAmount, component.SpawnRange);
Spawn(component.SupercriticalSpawn, xform.Coordinates);
}
private void OnSeverityChanged(EntityUid uid, FleshAnomalyComponent component, ref AnomalyStabilityChangedEvent args)
{
var xform = Transform(uid);
if (!_map.TryGetGrid(xform.GridUid, out var grid))
return;
var radius = component.SpawnRange * args.Stability;
var fleshTile = (ContentTileDefinition) _tiledef[component.FleshTileId];
var localpos = xform.Coordinates.Position;
var tilerefs = grid.GetLocalTilesIntersecting(
new Box2(localpos + (-radius, -radius), localpos + (radius, radius)));
foreach (var tileref in tilerefs)
{
if (!_random.Prob(0.33f))
continue;
_tile.ReplaceTile(tileref, fleshTile);
}
}
private void SpawnMonstersOnOpenTiles(FleshAnomalyComponent component, TransformComponent xform, int amount, float radius)
private void SpawnMonstersOnOpenTiles(EntitySpawnAnomalyComponent component, TransformComponent xform, int amount, float radius)
{
if (!component.Spawns.Any())
return;

View File

@@ -0,0 +1,45 @@
using System.Linq;
using Content.Server.Maps;
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Effects.Components;
using Content.Shared.Maps;
using Content.Shared.Physics;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;
namespace Content.Server.Anomaly.Effects;
public sealed class TileAnomalySystem : EntitySystem
{
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ITileDefinitionManager _tiledef = default!;
[Dependency] private readonly TileSystem _tile = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<TileSpawnAnomalyComponent, AnomalyStabilityChangedEvent>(OnSeverityChanged);
}
private void OnSeverityChanged(EntityUid uid, TileSpawnAnomalyComponent component, ref AnomalyStabilityChangedEvent args)
{
var xform = Transform(uid);
if (!_map.TryGetGrid(xform.GridUid, out var grid))
return;
var radius = component.SpawnRange * args.Stability;
var fleshTile = (ContentTileDefinition) _tiledef[component.FloorTileId];
var localpos = xform.Coordinates.Position;
var tilerefs = grid.GetLocalTilesIntersecting(
new Box2(localpos + (-radius, -radius), localpos + (radius, radius)));
foreach (var tileref in tilerefs)
{
if (!_random.Prob(0.33f))
continue;
_tile.ReplaceTile(tileref, fleshTile);
}
}
}