Skip to content

Commit

Permalink
Merge pull request #308
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dvir001 committed Sep 19, 2023
1 parent de8c7a3 commit 565e243
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
57 changes: 54 additions & 3 deletions Content.Server/StationEvents/Events/AnomalySpawnRule.cs
Original file line number Diff line number Diff line change
@@ -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<AnomalySpawnRuleComponent>
{
[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)
{
Expand All @@ -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<StationJobsComponent>))
return;

if (!TryComp<StationDataComponent>(chosenStation, out var stationData))
Expand All @@ -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<MapGridComponent>(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<PhysicsComponent>();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
False: { visible: false }
- type: ProximityBeeper
component: Anomaly
maximumDistance: 20
maximumDistance: 2000
minBeepInterval: 0.15
maxBeepInterval: 1.00
beepSound:
Expand Down
22 changes: 11 additions & 11 deletions Resources/Prototypes/GameRules/events.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 565e243

Please sign in to comment.