More anomalies (#13766)
This commit is contained in:
@@ -6,11 +6,13 @@ using Content.Shared.Anomaly.Effects.Components;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Anomaly.Effects;
|
||||
|
||||
public sealed class ElectricityAnomalySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly LightningSystem _lightning = default!;
|
||||
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
|
||||
@@ -25,16 +27,12 @@ public sealed class ElectricityAnomalySystem : EntitySystem
|
||||
|
||||
private void OnPulse(EntityUid uid, ElectricityAnomalyComponent component, ref AnomalyPulseEvent args)
|
||||
{
|
||||
var range = component.MaxElectrocuteRange * args.Stabiltiy;
|
||||
var damage = (int) (component.MaxElectrocuteDamage * args.Severity);
|
||||
var duration = component.MaxElectrocuteDuration * args.Severity;
|
||||
|
||||
var range = component.MaxElectrocuteRange * args.Stability;
|
||||
var xform = Transform(uid);
|
||||
foreach (var comp in _lookup.GetComponentsInRange<StatusEffectsComponent>(xform.MapPosition, range))
|
||||
foreach (var comp in _lookup.GetComponentsInRange<MobStateComponent>(xform.MapPosition, range))
|
||||
{
|
||||
var ent = comp.Owner;
|
||||
|
||||
_electrocution.TryDoElectrocution(ent, uid, damage, duration, true, statusEffects: comp, ignoreInsulation: true);
|
||||
_lightning.ShootLightning(uid, ent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +46,7 @@ public sealed class ElectricityAnomalySystem : EntitySystem
|
||||
if (mobQuery.HasComponent(ent))
|
||||
validEnts.Add(ent);
|
||||
|
||||
if (_random.Prob(0.1f) && poweredQuery.HasComponent(ent))
|
||||
if (_random.Prob(0.2f) && poweredQuery.HasComponent(ent))
|
||||
validEnts.Add(ent);
|
||||
}
|
||||
|
||||
@@ -58,4 +56,32 @@ public sealed class ElectricityAnomalySystem : EntitySystem
|
||||
_lightning.ShootLightning(uid, ent);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var (elec, anom, xform) in EntityQuery<ElectricityAnomalyComponent, AnomalyComponent, TransformComponent>())
|
||||
{
|
||||
if (_timing.CurTime < elec.NextSecond)
|
||||
continue;
|
||||
elec.NextSecond = _timing.CurTime + TimeSpan.FromSeconds(1);
|
||||
|
||||
var owner = xform.Owner;
|
||||
|
||||
if (!_random.Prob(elec.PassiveElectrocutionChance * anom.Stability))
|
||||
continue;
|
||||
|
||||
var range = elec.MaxElectrocuteRange * anom.Stability;
|
||||
var damage = (int) (elec.MaxElectrocuteDamage * anom.Severity);
|
||||
var duration = elec.MaxElectrocuteDuration * anom.Severity;
|
||||
|
||||
foreach (var comp in _lookup.GetComponentsInRange<StatusEffectsComponent>(xform.MapPosition, range))
|
||||
{
|
||||
var ent = comp.Owner;
|
||||
|
||||
_electrocution.TryDoElectrocution(ent, owner, damage, duration, true, statusEffects: comp, ignoreInsulation: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
97
Content.Server/Anomaly/Effects/FleshAnomalySystem.cs
Normal file
97
Content.Server/Anomaly/Effects/FleshAnomalySystem.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Maps;
|
||||
using Content.Shared.Anomaly.Components;
|
||||
using Content.Shared.Anomaly.Effects.Components;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Anomaly.Effects;
|
||||
|
||||
public sealed class FleshAnomalySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tiledef = default!;
|
||||
[Dependency] private readonly TileSystem _tile = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<FleshAnomalyComponent, AnomalyPulseEvent>(OnPulse);
|
||||
SubscribeLocalEvent<FleshAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
|
||||
SubscribeLocalEvent<FleshAnomalyComponent, AnomalyStabilityChangedEvent>(OnSeverityChanged);
|
||||
}
|
||||
|
||||
private void OnPulse(EntityUid uid, FleshAnomalyComponent component, ref AnomalyPulseEvent args)
|
||||
{
|
||||
var range = component.SpawnRange * args.Stability;
|
||||
var amount = (int) (component.MaxSpawnAmount * args.Severity + 0.5f);
|
||||
|
||||
var xform = Transform(uid);
|
||||
SpawnMonstersOnOpenTiles(component, xform, amount, range);
|
||||
}
|
||||
|
||||
private void OnSupercritical(EntityUid uid, FleshAnomalyComponent component, ref AnomalySupercriticalEvent args)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
SpawnMonstersOnOpenTiles(component, xform, component.MaxSpawnAmount, component.SpawnRange);
|
||||
Spawn(component.SupercriticalSpawn, xform.Coordinates);
|
||||
}
|
||||
|
||||
private void OnSeverityChanged(EntityUid uid, FleshAnomalyComponent component, ref AnomalyStabilityChangedEvent args)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
if (!_map.TryGetGrid(xform.GridUid, out var grid))
|
||||
return;
|
||||
|
||||
var radius = component.SpawnRange * args.Stability;
|
||||
var fleshTile = (ContentTileDefinition) _tiledef[component.FleshTileId];
|
||||
var localpos = xform.Coordinates.Position;
|
||||
var tilerefs = grid.GetLocalTilesIntersecting(
|
||||
new Box2(localpos + (-radius, -radius), localpos + (radius, radius)));
|
||||
foreach (var tileref in tilerefs)
|
||||
{
|
||||
if (!_random.Prob(0.33f))
|
||||
continue;
|
||||
_tile.ReplaceTile(tileref, fleshTile);
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnMonstersOnOpenTiles(FleshAnomalyComponent component, TransformComponent xform, int amount, float radius)
|
||||
{
|
||||
if (!_map.TryGetGrid(xform.GridUid, out var grid))
|
||||
return;
|
||||
|
||||
var localpos = xform.Coordinates.Position;
|
||||
var tilerefs = grid.GetLocalTilesIntersecting(
|
||||
new Box2(localpos + (-radius, -radius), localpos + (radius, radius))).ToArray();
|
||||
_random.Shuffle(tilerefs);
|
||||
var physQuery = GetEntityQuery<PhysicsComponent>();
|
||||
var amountCounter = 0;
|
||||
foreach (var tileref in tilerefs)
|
||||
{
|
||||
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)
|
||||
continue;
|
||||
amountCounter++;
|
||||
Spawn(_random.Pick(component.Spawns), tileref.GridIndices.ToEntityCoordinates(xform.GridUid.Value, _map));
|
||||
if (amountCounter >= amount)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public sealed class PyroclasticAnomalySystem : EntitySystem
|
||||
private void OnPulse(EntityUid uid, PyroclasticAnomalyComponent component, ref AnomalyPulseEvent args)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
var ignitionRadius = component.MaximumIgnitionRadius * args.Stabiltiy;
|
||||
var ignitionRadius = component.MaximumIgnitionRadius * args.Stability;
|
||||
IgniteNearby(xform.Coordinates, args.Severity, ignitionRadius);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user