Electric anomaly rework (#23173)
* add content * remove using * update * Update ElectricityAnomalyComponent.cs * 2-5 lightnings * tweaks * remove tesla comment (sorry)
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
using Content.Server.Electrocution;
|
using Content.Server.Electrocution;
|
||||||
using Content.Server.Emp;
|
using Content.Server.Emp;
|
||||||
using Content.Server.Lightning;
|
using Content.Server.Lightning;
|
||||||
using Content.Server.Power.Components;
|
|
||||||
using Content.Shared.Anomaly.Components;
|
using Content.Shared.Anomaly.Components;
|
||||||
using Content.Shared.Anomaly.Effects.Components;
|
using Content.Shared.Anomaly.Effects.Components;
|
||||||
using Content.Shared.Mobs.Components;
|
|
||||||
using Content.Shared.StatusEffect;
|
using Content.Shared.StatusEffect;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -14,6 +12,7 @@ namespace Content.Server.Anomaly.Effects;
|
|||||||
public sealed class ElectricityAnomalySystem : EntitySystem
|
public sealed class ElectricityAnomalySystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly LightningSystem _lightning = default!;
|
[Dependency] private readonly LightningSystem _lightning = default!;
|
||||||
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
|
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
|
||||||
@@ -27,38 +26,21 @@ public sealed class ElectricityAnomalySystem : EntitySystem
|
|||||||
SubscribeLocalEvent<ElectricityAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
|
SubscribeLocalEvent<ElectricityAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPulse(EntityUid uid, ElectricityAnomalyComponent component, ref AnomalyPulseEvent args)
|
private void OnPulse(Entity<ElectricityAnomalyComponent> anomaly, ref AnomalyPulseEvent args)
|
||||||
{
|
{
|
||||||
var range = component.MaxElectrocuteRange * args.Stability;
|
var range = anomaly.Comp.MaxElectrocuteRange * args.Stability;
|
||||||
var xform = Transform(uid);
|
|
||||||
foreach (var (ent, comp) in _lookup.GetEntitiesInRange<MobStateComponent>(xform.MapPosition, range))
|
int boltCount = (int)MathF.Floor(MathHelper.Lerp((float)anomaly.Comp.MinBoltCount, (float)anomaly.Comp.MaxBoltCount, args.Severity));
|
||||||
{
|
|
||||||
_lightning.ShootLightning(uid, ent);
|
_lightning.ShootRandomLightnings(anomaly, range, boltCount);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSupercritical(EntityUid uid, ElectricityAnomalyComponent component, ref AnomalySupercriticalEvent args)
|
private void OnSupercritical(Entity<ElectricityAnomalyComponent> anomaly, ref AnomalySupercriticalEvent args)
|
||||||
{
|
{
|
||||||
var poweredQuery = GetEntityQuery<ApcPowerReceiverComponent>();
|
var range = anomaly.Comp.MaxElectrocuteRange * 3;
|
||||||
var mobQuery = GetEntityQuery<MobThresholdsComponent>();
|
|
||||||
var validEnts = new HashSet<EntityUid>();
|
|
||||||
foreach (var ent in _lookup.GetEntitiesInRange(uid, component.MaxElectrocuteRange * 2))
|
|
||||||
{
|
|
||||||
if (mobQuery.HasComponent(ent))
|
|
||||||
validEnts.Add(ent);
|
|
||||||
|
|
||||||
if (_random.Prob(0.01f) && poweredQuery.HasComponent(ent))
|
_emp.EmpPulse(_transform.GetMapCoordinates(anomaly), range, anomaly.Comp.EmpEnergyConsumption, anomaly.Comp.EmpDisabledDuration);
|
||||||
validEnts.Add(ent);
|
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, arcDepth: 3);
|
||||||
}
|
|
||||||
|
|
||||||
// goodbye, sweet perf
|
|
||||||
foreach (var ent in validEnts)
|
|
||||||
{
|
|
||||||
_lightning.ShootLightning(uid, ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
var empRange = component.MaxElectrocuteRange * 3;
|
|
||||||
_emp.EmpPulse(Transform(uid).MapPosition, empRange, component.EmpEnergyConsumption, component.EmpDisabledDuration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ public sealed class LightningSystem : SharedLightningSystem
|
|||||||
var targets = _lookup.GetComponentsInRange<LightningTargetComponent>(Transform(user).MapPosition, range).ToList();
|
var targets = _lookup.GetComponentsInRange<LightningTargetComponent>(Transform(user).MapPosition, range).ToList();
|
||||||
_random.Shuffle(targets);
|
_random.Shuffle(targets);
|
||||||
targets.Sort((x, y) => y.Priority.CompareTo(x.Priority));
|
targets.Sort((x, y) => y.Priority.CompareTo(x.Priority));
|
||||||
//var realCount = Math.Min(targets.Count, boltCount);
|
|
||||||
|
|
||||||
int shootedCount = 0;
|
int shootedCount = 0;
|
||||||
int count = -1;
|
int count = -1;
|
||||||
|
|||||||
@@ -1,53 +1,65 @@
|
|||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
namespace Content.Shared.Anomaly.Effects.Components;
|
namespace Content.Shared.Anomaly.Effects.Components;
|
||||||
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed partial class ElectricityAnomalyComponent : Component
|
public sealed partial class ElectricityAnomalyComponent : Component
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// the minimum number of lightning strikes
|
||||||
|
/// </summary>
|
||||||
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public int MinBoltCount = 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the number of lightning strikes, at the maximum severity of the anomaly
|
||||||
|
/// </summary>
|
||||||
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public int MaxBoltCount = 5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum radius of the passive electrocution effect
|
/// The maximum radius of the passive electrocution effect
|
||||||
/// scales with stability
|
/// scales with stability
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("maxElectrocutionRange"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float MaxElectrocuteRange = 7f;
|
public float MaxElectrocuteRange = 7f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum amount of damage the electrocution can do
|
/// The maximum amount of damage the electrocution can do
|
||||||
/// scales with severity
|
/// scales with severity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("maxElectrocuteDamage"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float MaxElectrocuteDamage = 20f;
|
public float MaxElectrocuteDamage = 20f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum amount of time the electrocution lasts
|
/// The maximum amount of time the electrocution lasts
|
||||||
/// scales with severity
|
/// scales with severity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("maxElectrocuteDuration"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan MaxElectrocuteDuration = TimeSpan.FromSeconds(8);
|
public TimeSpan MaxElectrocuteDuration = TimeSpan.FromSeconds(8);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum chance that each second, when in range of the anomaly, you will be electrocuted.
|
/// The maximum chance that each second, when in range of the anomaly, you will be electrocuted.
|
||||||
/// scales with stability
|
/// scales with stability
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("passiveElectrocutionChance"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float PassiveElectrocutionChance = 0.05f;
|
public float PassiveElectrocutionChance = 0.05f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used for tracking seconds, so that we can shock people in a non-tick-dependent way.
|
/// Used for tracking seconds, so that we can shock people in a non-tick-dependent way.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("nextSecond", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan NextSecond = TimeSpan.Zero;
|
public TimeSpan NextSecond = TimeSpan.Zero;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Energy consumed from devices by the emp pulse upon going supercritical.
|
/// Energy consumed from devices by the emp pulse upon going supercritical.
|
||||||
/// <summary>
|
/// <summary>
|
||||||
[DataField("empEnergyConsumption"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float EmpEnergyConsumption = 100000f;
|
public float EmpEnergyConsumption = 100000f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Duration of devices being disabled by the emp pulse upon going supercritical.
|
/// Duration of devices being disabled by the emp pulse upon going supercritical.
|
||||||
/// <summary>
|
/// <summary>
|
||||||
[DataField("empDisabledDuration"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float EmpDisabledDuration = 60f;
|
public float EmpDisabledDuration = 60f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user