From e08302370078110a1fdabe7905659d41e2c79485 Mon Sep 17 00:00:00 2001 From: Dvir Date: Wed, 13 Sep 2023 03:36:40 +0300 Subject: [PATCH 1/3] Anomaly Event --- .../StationEvents/Events/AnomalySpawnRule.cs | 57 ++++++++++++++++++- .../Objects/Specific/Research/anomaly.yml | 2 +- Resources/Prototypes/GameRules/events.yml | 22 +++---- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/Content.Server/StationEvents/Events/AnomalySpawnRule.cs b/Content.Server/StationEvents/Events/AnomalySpawnRule.cs index a59af52f6d5..4c377836782 100644 --- a/Content.Server/StationEvents/Events/AnomalySpawnRule.cs +++ b/Content.Server/StationEvents/Events/AnomalySpawnRule.cs @@ -1,13 +1,22 @@ -using Content.Server.Anomaly; +using Content.Server.Anomaly; using Content.Server.GameTicking.Rules.Components; using Content.Server.Station.Components; using Content.Server.StationEvents.Components; +using Content.Shared.CCVar; +using Content.Shared.Physics; +using Robust.Shared.Map.Components; +using Robust.Shared.Physics.Components; +using Robust.Shared.Physics; +using Robust.Shared.Configuration; +using Robust.Shared.Random; namespace Content.Server.StationEvents.Events; public sealed class AnomalySpawnRule : StationEventSystem { [Dependency] private readonly AnomalySystem _anomaly = default!; + [Dependency] private readonly IConfigurationManager _configuration = default!; + [Dependency] protected readonly IRobustRandom _random = default!; protected override void Added(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args) { @@ -22,7 +31,7 @@ protected override void Started(EntityUid uid, AnomalySpawnRuleComponent compone { base.Started(uid, component, gameRule, args); - if (!TryGetRandomStation(out var chosenStation)) + if (TryGetRandomStation(out var chosenStation, HasComp)) return; if (!TryComp(chosenStation, out var stationData)) @@ -36,7 +45,49 @@ protected override void Started(EntityUid uid, AnomalySpawnRuleComponent compone var amountToSpawn = Math.Max(1, (int) MathF.Round(GetSeverityModifier() / 2)); for (var i = 0; i < amountToSpawn; i++) { - _anomaly.SpawnOnRandomGridLocation(grid.Value, component.AnomalySpawnerPrototype); + SpawnOnRandomGridLocation(grid.Value, component.AnomalySpawnerPrototype); } } + + private void SpawnOnRandomGridLocation(EntityUid grid, string toSpawn) + { + if (!TryComp(grid, out var gridComp)) + return; + + var xform = Transform(grid); + + var targetCoords = xform.Coordinates; + var gridBounds = gridComp.LocalAABB.Scale(_configuration.GetCVar(CCVars.AnomalyGenerationGridBoundsScale)); + + for (var i = 0; i < 25; i++) + { + var randomX = _random.Next((int) gridBounds.Left, (int) gridBounds.Right); + var randomY = _random.Next((int) gridBounds.Bottom, (int) gridBounds.Top); + + var tile = new Vector2i(randomX, randomY); + + // don't spawn inside of solid objects + var physQuery = GetEntityQuery(); + var valid = true; + foreach (var ent in gridComp.GetAnchoredEntities(tile)) + { + if (!physQuery.TryGetComponent(ent, out var body)) + continue; + if (body.BodyType != BodyType.Static || + !body.Hard || + (body.CollisionLayer & (int) CollisionGroup.Impassable) == 0) + continue; + + valid = false; + break; + } + if (!valid) + continue; + + targetCoords = gridComp.GridTileToLocal(tile); + break; + } + + Spawn(toSpawn, targetCoords); + } } diff --git a/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml b/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml index b2c1f6cdcc7..7f8f185c205 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml @@ -44,7 +44,7 @@ False: { visible: false } - type: ProximityBeeper component: Anomaly - maximumDistance: 20 + maximumDistance: 2000 minBeepInterval: 0.15 maxBeepInterval: 1.00 beepSound: diff --git a/Resources/Prototypes/GameRules/events.yml b/Resources/Prototypes/GameRules/events.yml index 1bc23f5075e..02890b16a1c 100644 --- a/Resources/Prototypes/GameRules/events.yml +++ b/Resources/Prototypes/GameRules/events.yml @@ -1,14 +1,14 @@ -# - type: entity - # id: AnomalySpawn - # parent: BaseGameRule - # noSpawn: true - # components: - # - type: StationEvent - # weight: 10 - # minimumPlayers: 110 - # startDelay: 30 - # duration: 35 - # - type: AnomalySpawnRule +- type: entity + id: AnomalySpawn + parent: BaseGameRule + noSpawn: true + components: + - type: StationEvent + weight: 10 + minimumPlayers: 110 + startDelay: 30 + duration: 35 + - type: AnomalySpawnRule # - type: entity # id: BluespaceArtifact From a032b3ecf6703ebd342797439946fb8e98a51136 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:32:46 +0300 Subject: [PATCH 2/3] Update events.yml --- Resources/Prototypes/GameRules/events.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/Resources/Prototypes/GameRules/events.yml b/Resources/Prototypes/GameRules/events.yml index 02890b16a1c..579a293e49d 100644 --- a/Resources/Prototypes/GameRules/events.yml +++ b/Resources/Prototypes/GameRules/events.yml @@ -5,7 +5,6 @@ components: - type: StationEvent weight: 10 - minimumPlayers: 110 startDelay: 30 duration: 35 - type: AnomalySpawnRule From b925fd129daa8e85b8f1d0ce3db221cc422a5d70 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:34:18 +0300 Subject: [PATCH 3/3] Update events.yml --- Resources/Prototypes/GameRules/events.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/Prototypes/GameRules/events.yml b/Resources/Prototypes/GameRules/events.yml index 579a293e49d..f2ff5bca9c4 100644 --- a/Resources/Prototypes/GameRules/events.yml +++ b/Resources/Prototypes/GameRules/events.yml @@ -7,6 +7,7 @@ weight: 10 startDelay: 30 duration: 35 + minimumPlayers: 45 - type: AnomalySpawnRule # - type: entity