]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Split FleshAnomaly into two components #16001 (#16110)
authorTom Leys <tom@crump-leys.com>
Fri, 5 May 2023 13:08:37 +0000 (01:08 +1200)
committerGitHub <noreply@github.com>
Fri, 5 May 2023 13:08:37 +0000 (23:08 +1000)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Content.Server/Anomaly/Effects/EntityAnomalySystem.cs [moved from Content.Server/Anomaly/Effects/FleshAnomalySystem.cs with 63% similarity]
Content.Server/Anomaly/Effects/TileAnomalySystem.cs [new file with mode: 0644]
Content.Shared/Anomaly/Effects/Components/EntitySpawnAnomalyComponent.cs [moved from Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs with 90% similarity]
Content.Shared/Anomaly/Effects/Components/TileSpawnAnomaly.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Structures/Specific/anomalies.yml

similarity index 63%
rename from Content.Server/Anomaly/Effects/FleshAnomalySystem.cs
rename to Content.Server/Anomaly/Effects/EntityAnomalySystem.cs
index faa2cde7c30e8387002713dc869ac14da46db7f1..6a035779287523a2f784bef343773a34fe5292e4 100644 (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;
diff --git a/Content.Server/Anomaly/Effects/TileAnomalySystem.cs b/Content.Server/Anomaly/Effects/TileAnomalySystem.cs
new file mode 100644 (file)
index 0000000..e70204b
--- /dev/null
@@ -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);
+        }
+    }
+}
similarity index 90%
rename from Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs
rename to Content.Shared/Anomaly/Effects/Components/EntitySpawnAnomalyComponent.cs
index 88b3ff061cd44100d820b42bd60d6b7c211f777e..ce1024d5efbbd30bcbcf8c3f0e30bb1eb33be8ef 100644 (file)
@@ -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
 {
     /// <summary>
     /// A list of entities that are random picked to be spawned on each pulse
@@ -32,8 +32,8 @@ public sealed class FleshAnomalyComponent : Component
     /// <summary>
     /// The tile that is spawned by the anomaly's effect
     /// </summary>
-    [DataField("fleshTileId", customTypeSerializer: typeof(PrototypeIdSerializer<ContentTileDefinition>)), ViewVariables(VVAccess.ReadWrite)]
-    public string FleshTileId = "FloorFlesh";
+    [DataField("floorTileId", customTypeSerializer: typeof(PrototypeIdSerializer<ContentTileDefinition>)), ViewVariables(VVAccess.ReadWrite)]
+    public string FloorTileId = "FloorFlesh";
 
     /// <summary>
     /// 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 (file)
index 0000000..5403225
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// The maximum radius of tiles scales with stability
+    /// </summary>
+    [DataField("spawnRange"), ViewVariables(VVAccess.ReadWrite)]
+    public float SpawnRange = 5f;
+
+    /// <summary>
+    /// The tile that is spawned by the anomaly's effect
+    /// </summary>
+    [DataField("floorTileId", customTypeSerializer: typeof(PrototypeIdSerializer<ContentTileDefinition>)), ViewVariables(VVAccess.ReadWrite)]
+    public string FloorTileId = "FloorFlesh";
+}
index 09bb2e60617c3973b57b3ef38b8e3d6e7067bf63..4e613ddc4a283694b9d326d42a3d6eea2cc1594f 100644 (file)
     energy: 7.5
     color: "#cb5b7e"
     castShadows: false
-  - type: FleshAnomaly
+  - type: TileSpawnAnomaly
+    floorTileId: FloorFlesh
+  - type: EntitySpawnAnomaly
+    superCriticalSpawn: FleshKudzu
     spawns:
     - MobFleshJared
     - MobFleshGolem