Files
tbd-station-14/Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs
Nemanja a269f9bb9e Small anomaly behavior fix (#28290)
* Small anomaly behavior fix

* well put together code
2024-05-27 17:52:56 -07:00

42 lines
1.4 KiB
C#

using Content.Server.Anomaly.Components;
using Content.Shared.Anomaly.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Random;
namespace Content.Server.Anomaly.Effects;
public sealed class ShuffleParticlesAnomalySystem : EntitySystem
{
[Dependency] private readonly AnomalySystem _anomaly = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, AnomalyPulseEvent>(OnPulse);
SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, StartCollideEvent>(OnStartCollide);
}
private void OnStartCollide(Entity<ShuffleParticlesAnomalyComponent> ent, ref StartCollideEvent args)
{
if (!TryComp<AnomalyComponent>(ent, out var anomaly))
return;
if (!HasComp<AnomalousParticleComponent>(args.OtherEntity))
return;
if (ent.Comp.ShuffleOnParticleHit && _random.Prob(ent.Comp.Prob))
_anomaly.ShuffleParticlesEffect((ent, anomaly));
}
private void OnPulse(Entity<ShuffleParticlesAnomalyComponent> ent, ref AnomalyPulseEvent args)
{
if (!TryComp<AnomalyComponent>(ent, out var anomaly))
return;
if (ent.Comp.ShuffleOnPulse && _random.Prob(ent.Comp.Prob))
{
_anomaly.ShuffleParticlesEffect((ent, anomaly));
}
}
}