mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 22:18:52 +03:00
Uses the following Cherry-Picks: https://github.com/space-wizards/space-station-14/pull/26994 https://github.com/space-wizards/space-station-14/pull/26518 https://github.com/space-wizards/space-station-14/pull/26279 https://github.com/space-wizards/space-station-14/pull/24946 https://github.com/space-wizards/space-station-14/pull/27188 Requires: https://github.com/Simple-Station/Einstein-Engines/pull/535 https://github.com/Simple-Station/Einstein-Engines/pull/534 --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: Jake Huxell <JakeHuxell@pm.me> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: 0x6273 <0x40@keemail.me> Co-authored-by: DEATHB4DEFEAT <zachcaffee@outlook.com>
102 lines
3.5 KiB
C#
102 lines
3.5 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.Physics.Components;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Anomaly.Effects;
|
|
|
|
public sealed class EntityAnomalySystem : SharedEntityAnomalySystem
|
|
{
|
|
[Dependency] private readonly SharedAnomalySystem _anomaly = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
|
|
|
private EntityQuery<PhysicsComponent> _physicsQuery;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void SpawnEntities(Entity<EntitySpawnAnomalyComponent> anomaly, EntitySpawnSettingsEntry entry, float stability, float severity)
|
|
{
|
|
var xform = Transform(anomaly);
|
|
if (!TryComp(xform.GridUid, out MapGridComponent? grid))
|
|
return;
|
|
|
|
var tiles = _anomaly.GetSpawningPoints(anomaly, stability, severity, entry.Settings);
|
|
if (tiles == null)
|
|
return;
|
|
|
|
foreach (var tileref in tiles)
|
|
{
|
|
Spawn(_random.Pick(entry.Spawns), _mapSystem.ToCenterCoordinates(tileref, grid));
|
|
}
|
|
}
|
|
}
|