Revert "Start rebalancing anomalies - Rock and Flesh anomaly reworked" (#24448)

This commit is contained in:
Ed
2024-01-23 15:40:37 +03:00
committed by GitHub
parent a68d0eefe6
commit 05a7eb07c2
17 changed files with 216 additions and 671 deletions

View File

@@ -1,18 +1,17 @@
using System.Linq;
using System.Numerics;
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Effects;
using Content.Shared.Anomaly.Effects.Components;
using Content.Shared.Physics;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Anomaly.Effects;
public sealed class EntityAnomalySystem : SharedEntityAnomalySystem
public sealed class EntityAnomalySystem : EntitySystem
{
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IRobustRandom _random = default!;
@@ -23,70 +22,55 @@ public sealed class EntityAnomalySystem : SharedEntityAnomalySystem
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalyPulseEvent>(OnPulse);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalyStabilityChangedEvent>(OnStabilityChanged);
SubscribeLocalEvent<EntitySpawnAnomalyComponent, AnomalySeverityChangedEvent>(OnSeverityChanged);
}
private void OnPulse(Entity<EntitySpawnAnomalyComponent> component, ref AnomalyPulseEvent args)
private void OnPulse(EntityUid uid, EntitySpawnAnomalyComponent component, ref AnomalyPulseEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.SpawnOnPulse)
continue;
SpawnEntitesOnOpenTiles(component, entry, args.Stability, args.Severity);
}
}
private void OnSupercritical(Entity<EntitySpawnAnomalyComponent> component, ref AnomalySupercriticalEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.SpawnOnSuperCritical)
continue;
SpawnEntitesOnOpenTiles(component, entry, 1, 1);
}
}
private void OnStabilityChanged(Entity<EntitySpawnAnomalyComponent> component, ref AnomalyStabilityChangedEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.SpawnOnStabilityChanged)
continue;
SpawnEntitesOnOpenTiles(component, entry, args.Stability, args.Severity);
}
}
private void OnSeverityChanged(Entity<EntitySpawnAnomalyComponent> component, ref AnomalySeverityChangedEvent args)
{
foreach (var entry in component.Comp.Entries)
{
if (!entry.SpawnOnSeverityChanged)
continue;
SpawnEntitesOnOpenTiles(component, entry, args.Stability, args.Severity);
}
}
//TheShuEd:
//I know it's a shitcode! I didn't write it! I just restructured the functions
// To Do: make it reusable with TileAnomalySystem
private void SpawnEntitesOnOpenTiles(Entity<EntitySpawnAnomalyComponent> component, EntitySpawnSettingsEntry entry, float stability, float severity)
{
if (entry.Spawns.Count == 0)
if (!component.SpawnOnPulse)
return;
var xform = Transform(component.Owner);
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
var range = component.SpawnRange * args.Stability;
var amount = (int) (component.MaxSpawnAmount * args.Severity + 0.5f);
var xform = Transform(uid);
SpawnEntitesOnOpenTiles(component, xform, amount, range, component.Spawns);
}
private void OnSupercritical(EntityUid uid, EntitySpawnAnomalyComponent component, ref AnomalySupercriticalEvent args)
{
if (!component.SpawnOnSuperCritical)
return;
var amount = (int) (MathHelper.Lerp(entry.MinAmount, entry.MaxAmount, severity * stability) + 0.5f);
var xform = Transform(uid);
// A cluster of entities
SpawnEntitesOnOpenTiles(component, xform, component.MaxSpawnAmount, component.SpawnRange, component.Spawns);
// And so much meat (for the meat anomaly at least)
SpawnEntitesOnOpenTiles(component, xform, component.MaxSpawnAmount, component.SpawnRange, component.SuperCriticalSpawns);
}
private void OnStabilityChanged(EntityUid uid, EntitySpawnAnomalyComponent component, ref AnomalyStabilityChangedEvent args)
{
if (!component.SpawnOnStabilityChanged)
return;
var range = component.SpawnRange * args.Stability;
var amount = (int) (component.MaxSpawnAmount * args.Stability + 0.5f);
var xform = Transform(uid);
SpawnEntitesOnOpenTiles(component, xform, amount, range, component.Spawns);
}
private void SpawnEntitesOnOpenTiles(EntitySpawnAnomalyComponent component, TransformComponent xform, int amount, float radius, List<EntProtoId> spawns)
{
if (!component.Spawns.Any())
return;
if (!_map.TryGetGrid(xform.GridUid, out var grid))
return;
var localpos = xform.Coordinates.Position;
var tilerefs = grid.GetLocalTilesIntersecting(
new Box2(localpos + new Vector2(-entry.MaxRange, -entry.MaxRange), localpos + new Vector2(entry.MaxRange, entry.MaxRange))).ToArray();
new Box2(localpos + new Vector2(-radius, -radius), localpos + new Vector2(radius, radius))).ToArray();
if (tilerefs.Length == 0)
return;
@@ -96,14 +80,6 @@ public sealed class EntityAnomalySystem : SharedEntityAnomalySystem
var amountCounter = 0;
foreach (var tileref in tilerefs)
{
//cut outer circle
if (MathF.Sqrt(MathF.Pow(tileref.X - xform.LocalPosition.X, 2) + MathF.Pow(tileref.Y - xform.LocalPosition.Y, 2)) > entry.MaxRange)
continue;
//cut inner circle
if (MathF.Sqrt(MathF.Pow(tileref.X - xform.LocalPosition.X, 2) + MathF.Pow(tileref.Y - xform.LocalPosition.Y, 2)) < entry.MinRange)
continue;
var valid = true;
foreach (var ent in grid.GetAnchoredEntities(tileref.GridIndices))
{
@@ -121,7 +97,7 @@ public sealed class EntityAnomalySystem : SharedEntityAnomalySystem
if (!valid)
continue;
amountCounter++;
Spawn(_random.Pick(entry.Spawns), tileref.GridIndices.ToEntityCoordinates(xform.GridUid.Value, _map));
Spawn(_random.Pick(spawns), tileref.GridIndices.ToEntityCoordinates(xform.GridUid.Value, _map));
if (amountCounter >= amount)
return;
}