Files
wwdpublic/Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs
Nemanja d02af23a32 Small anomaly behavior fix (#28290)
* Small anomaly behavior fix

* well put together code

(cherry picked from commit a269f9bb9e722b3eaad0689fab4ba1600aeb76f0)
2025-07-12 02:28:44 +10: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));
}
}
}