diff --git a/Content.Server/Anomaly/Effects/FleshAnomalySystem.cs b/Content.Server/Anomaly/Effects/EntityAnomalySystem.cs similarity index 63% rename from Content.Server/Anomaly/Effects/FleshAnomalySystem.cs rename to Content.Server/Anomaly/Effects/EntityAnomalySystem.cs index faa2cde7c3..6a03577928 100644 --- a/Content.Server/Anomaly/Effects/FleshAnomalySystem.cs +++ b/Content.Server/Anomaly/Effects/EntityAnomalySystem.cs @@ -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 /// public override void Initialize() { - SubscribeLocalEvent(OnPulse); - SubscribeLocalEvent(OnSupercritical); - SubscribeLocalEvent(OnSeverityChanged); + SubscribeLocalEvent(OnPulse); + SubscribeLocalEvent(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; diff --git a/Content.Server/Anomaly/Effects/TileAnomalySystem.cs b/Content.Server/Anomaly/Effects/TileAnomalySystem.cs new file mode 100644 index 0000000000..e70204be74 --- /dev/null +++ b/Content.Server/Anomaly/Effects/TileAnomalySystem.cs @@ -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!; + + /// + public override void Initialize() + { + SubscribeLocalEvent(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); + } + } +} diff --git a/Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs b/Content.Shared/Anomaly/Effects/Components/EntitySpawnAnomalyComponent.cs similarity index 90% rename from Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs rename to Content.Shared/Anomaly/Effects/Components/EntitySpawnAnomalyComponent.cs index 88b3ff061c..ce1024d5ef 100644 --- a/Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs +++ b/Content.Shared/Anomaly/Effects/Components/EntitySpawnAnomalyComponent.cs @@ -6,7 +6,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy namespace Content.Shared.Anomaly.Effects.Components; [RegisterComponent] -public sealed class FleshAnomalyComponent : Component +public sealed class EntitySpawnAnomalyComponent : Component { /// /// A list of entities that are random picked to be spawned on each pulse @@ -32,8 +32,8 @@ public sealed class FleshAnomalyComponent : Component /// /// The tile that is spawned by the anomaly's effect /// - [DataField("fleshTileId", customTypeSerializer: typeof(PrototypeIdSerializer)), ViewVariables(VVAccess.ReadWrite)] - public string FleshTileId = "FloorFlesh"; + [DataField("floorTileId", customTypeSerializer: typeof(PrototypeIdSerializer)), ViewVariables(VVAccess.ReadWrite)] + public string FloorTileId = "FloorFlesh"; /// /// The entity spawned when the anomaly goes supercritical diff --git a/Content.Shared/Anomaly/Effects/Components/TileSpawnAnomaly.cs b/Content.Shared/Anomaly/Effects/Components/TileSpawnAnomaly.cs new file mode 100644 index 0000000000..5403225bae --- /dev/null +++ b/Content.Shared/Anomaly/Effects/Components/TileSpawnAnomaly.cs @@ -0,0 +1,22 @@ +using Content.Shared.Maps; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; + +namespace Content.Shared.Anomaly.Effects.Components; + +[RegisterComponent] +public sealed class TileSpawnAnomalyComponent : Component +{ + /// + /// The maximum radius of tiles scales with stability + /// + [DataField("spawnRange"), ViewVariables(VVAccess.ReadWrite)] + public float SpawnRange = 5f; + + /// + /// The tile that is spawned by the anomaly's effect + /// + [DataField("floorTileId", customTypeSerializer: typeof(PrototypeIdSerializer)), ViewVariables(VVAccess.ReadWrite)] + public string FloorTileId = "FloorFlesh"; +} diff --git a/Resources/Prototypes/Entities/Structures/Specific/anomalies.yml b/Resources/Prototypes/Entities/Structures/Specific/anomalies.yml index 09bb2e6061..4e613ddc4a 100644 --- a/Resources/Prototypes/Entities/Structures/Specific/anomalies.yml +++ b/Resources/Prototypes/Entities/Structures/Specific/anomalies.yml @@ -131,7 +131,10 @@ energy: 7.5 color: "#cb5b7e" castShadows: false - - type: FleshAnomaly + - type: TileSpawnAnomaly + floorTileId: FloorFlesh + - type: EntitySpawnAnomaly + superCriticalSpawn: FleshKudzu spawns: - MobFleshJared - MobFleshGolem