Rock and Meat anom rework (try 2) (#24449)
* rework * bruh * all fixed * balance * bb * Update TileAnomalySystem.cs * Update EntityAnomalySystem.cs * spawn on shutdown variant * fix entites, fix DataRecord * fix some review * god forgive me * oh fuck wrong brench * Revert "oh fuck wrong brench" This reverts commit c81f57f7830c8e55fd47982500c57281af40b0dc.
This commit is contained in:
@@ -3,10 +3,13 @@ using Content.Shared.Anomaly.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Weapons.Melee.Components;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
@@ -14,6 +17,8 @@ using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Content.Shared.Anomaly;
|
||||
|
||||
@@ -28,6 +33,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] protected readonly SharedPopupSystem Popup = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
@@ -227,7 +233,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
component.Stability = Math.Clamp(newVal, 0, 1);
|
||||
Dirty(component);
|
||||
|
||||
var ev = new AnomalyStabilityChangedEvent(uid, component.Stability);
|
||||
var ev = new AnomalyStabilityChangedEvent(uid, component.Stability, component.Severity);
|
||||
RaiseLocalEvent(uid, ref ev, true);
|
||||
}
|
||||
|
||||
@@ -250,7 +256,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
component.Severity = Math.Clamp(newVal, 0, 1);
|
||||
Dirty(component);
|
||||
|
||||
var ev = new AnomalySeverityChangedEvent(uid, component.Severity);
|
||||
var ev = new AnomalySeverityChangedEvent(uid, component.Stability, component.Severity);
|
||||
RaiseLocalEvent(uid, ref ev, true);
|
||||
}
|
||||
|
||||
@@ -349,4 +355,122 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
RemComp(ent, super);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets random points around the anomaly based on the given parameters.
|
||||
/// </summary>
|
||||
public List<TileRef>? GetSpawningPoints(EntityUid uid, float stability, float severity, AnomalySpawnSettings settings)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
|
||||
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
|
||||
return null;
|
||||
|
||||
var amount = (int) (MathHelper.Lerp(settings.MinAmount, settings.MaxAmount, severity * stability) + 0.5f);
|
||||
|
||||
var localpos = xform.Coordinates.Position;
|
||||
var tilerefs = grid.GetLocalTilesIntersecting(
|
||||
new Box2(localpos + new Vector2(-settings.MaxRange, -settings.MaxRange), localpos + new Vector2(settings.MaxRange, settings.MaxRange))).ToList();
|
||||
|
||||
if (tilerefs.Count == 0)
|
||||
return null;
|
||||
|
||||
var physQuery = GetEntityQuery<PhysicsComponent>();
|
||||
var resultList = new List<TileRef>();
|
||||
while (resultList.Count() < amount)
|
||||
{
|
||||
if (tilerefs.Count() == 0)
|
||||
break;
|
||||
|
||||
var tileref = _random.Pick(tilerefs);
|
||||
var distance = MathF.Sqrt(MathF.Pow(tileref.X - xform.LocalPosition.X, 2) + MathF.Pow(tileref.Y - xform.LocalPosition.Y, 2));
|
||||
|
||||
//cut outer & inner circle
|
||||
if (distance > settings.MaxRange || distance < settings.MinRange)
|
||||
{
|
||||
tilerefs.Remove(tileref);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!settings.CanSpawnOnEntities)
|
||||
{
|
||||
var valid = true;
|
||||
foreach (var ent in grid.GetAnchoredEntities(tileref.GridIndices))
|
||||
{
|
||||
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)
|
||||
{
|
||||
tilerefs.Remove(tileref);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
resultList.Add(tileref);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
[DataRecord]
|
||||
public partial record struct AnomalySpawnSettings()
|
||||
{
|
||||
/// <summary>
|
||||
/// should entities block spawning?
|
||||
/// </summary>
|
||||
public bool CanSpawnOnEntities { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum number of entities that spawn per pulse
|
||||
/// </summary>
|
||||
public int MinAmount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of entities that spawn per pulse
|
||||
/// scales with severity.
|
||||
/// </summary>
|
||||
public int MaxAmount { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The distance from the anomaly in which the entities will not appear
|
||||
/// </summary>
|
||||
public float MinRange { get; set; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum radius the entities will spawn in.
|
||||
/// </summary>
|
||||
public float MaxRange { get; set; } = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not anomaly spawns entities on Pulse
|
||||
/// </summary>
|
||||
public bool SpawnOnPulse { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not anomaly spawns entities on SuperCritical
|
||||
/// </summary>
|
||||
public bool SpawnOnSuperCritical { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not anomaly spawns entities when destroyed
|
||||
/// </summary>
|
||||
public bool SpawnOnShutdown { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not anomaly spawns entities on StabilityChanged
|
||||
/// </summary>
|
||||
public bool SpawnOnStabilityChanged { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not anomaly spawns entities on SeverityChanged
|
||||
/// </summary>
|
||||
public bool SpawnOnSeverityChanged { get; set; } = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user