CatStation/Content.Server/Anomaly/Effects/EntityAnomalySystem.cs
Eveloop 22a547c7c8
Use dependency injection for EntityQuery<T>s in Content.Server (#43566)
* Replace usages of EntityQuery with dependency injected ones in Content.Server

* Remove unused EntityQuery dependencies

* Restore CheckPressureAndFire override method

* Revert EntityQuery refactor changes to DisposalTubeSystem.cs & DisposableSystem.cs

* Infer Transform/Metadata directly instead of passing (#43479)

* Resolve RA0049, RA0051 errors (#43479)

* Resolve RA0049, RA0051 errors (#43479)

* Apply suggestions from code review

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2026-05-17 15:59:37 +00:00

96 lines
3.4 KiB
C#

using Content.Shared.Anomaly;
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Effects;
using Content.Shared.Anomaly.Effects.Components;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;
namespace Content.Server.Anomaly.Effects;
public sealed partial class EntityAnomalySystem : SharedEntityAnomalySystem
{
[Dependency] private SharedAnomalySystem _anomaly = default!;
[Dependency] private IRobustRandom _random = default!;
[Dependency] private SharedMapSystem _mapSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalyPulseEvent>(OnPulse);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalyStabilityChangedEvent>(OnStabilityChanged);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalySeverityChangedEvent>(OnSeverityChanged);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalyShutdownEvent>(OnShutdown);
}
private void OnPulse(Entity<EntitySpawnAnomalyComponent> component, ref AnomalyPulseEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.Settings.SpawnOnPulse)
continue;
SpawnEntities(component, entry, args.Stability, args.Severity, args.PowerModifier);
}
}
private void OnSupercritical(Entity<EntitySpawnAnomalyComponent> component, ref AnomalySupercriticalEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.Settings.SpawnOnSuperCritical)
continue;
SpawnEntities(component, entry, 1, 1, args.PowerModifier);
}
}
private void OnShutdown(Entity<EntitySpawnAnomalyComponent> component, ref AnomalyShutdownEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.Settings.SpawnOnShutdown || args.Supercritical)
continue;
SpawnEntities(component, entry, 1, 1, 1);
}
}
private void OnStabilityChanged(Entity<EntitySpawnAnomalyComponent> component, ref AnomalyStabilityChangedEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.Settings.SpawnOnStabilityChanged)
continue;
SpawnEntities(component, entry, args.Stability, args.Severity, 1);
}
}
private void OnSeverityChanged(Entity<EntitySpawnAnomalyComponent> component, ref AnomalySeverityChangedEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.Settings.SpawnOnSeverityChanged)
continue;
SpawnEntities(component, entry, args.Stability, args.Severity, 1);
}
}
private void SpawnEntities(Entity<EntitySpawnAnomalyComponent> anomaly, EntitySpawnSettingsEntry entry, float stability, float severity, float powerMod)
{
var xform = Transform(anomaly);
if (!TryComp(xform.GridUid, out MapGridComponent? grid))
return;
var tiles = _anomaly.GetSpawningPoints(anomaly, stability, severity, entry.Settings, powerMod);
if (tiles == null)
return;
foreach (var tileref in tiles)
{
Spawn(_random.Pick(entry.Spawns), _mapSystem.ToCenterCoordinates(tileref, grid));
}
}
}