More anomalies (#13766)

This commit is contained in:
Nemanja
2023-02-06 00:03:53 -05:00
committed by GitHub
parent 3656d3cc21
commit f450398df7
41 changed files with 855 additions and 47 deletions

View File

@@ -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);
}
}
}
}