From 565e243390809303bf78af2c4899fe4df6473b40 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:10:24 +0300 Subject: [PATCH] Merge pull request #308 * Anomaly Event * Update events.yml * Update events.yml * Merge branch 'new-frontiers-14:master' into Event-Anomaly * Merge branch 'new-frontiers-14:master' into Event-Anomaly --- .../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 9e59bcce5e7..4935746ec0b 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 + startDelay: 30 + duration: 35 + minimumPlayers: 45 + - type: AnomalySpawnRule # - type: entity # id: BluespaceArtifact