Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anomaly Event #308

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading