diff --git a/Content.Server/Anomaly/AnomalySystem.cs b/Content.Server/Anomaly/AnomalySystem.cs index 73658a0320..3e9760a056 100644 --- a/Content.Server/Anomaly/AnomalySystem.cs +++ b/Content.Server/Anomaly/AnomalySystem.cs @@ -18,8 +18,6 @@ using Robust.Shared.Configuration; using Robust.Shared.Physics.Events; using Robust.Shared.Prototypes; using Robust.Shared.Random; -using Robust.Shared.Serialization.Manager; -using System.Linq; namespace Content.Server.Anomaly; @@ -69,20 +67,21 @@ public sealed partial class AnomalySystem : SharedAnomalySystem ChangeAnomalyStability(anomaly, Random.NextFloat(anomaly.Comp.InitialStabilityRange.Item1 , anomaly.Comp.InitialStabilityRange.Item2), anomaly.Comp); ChangeAnomalySeverity(anomaly, Random.NextFloat(anomaly.Comp.InitialSeverityRange.Item1, anomaly.Comp.InitialSeverityRange.Item2), anomaly.Comp); - ShuffleParticlesEffect(anomaly.Comp); + ShuffleParticlesEffect(anomaly); anomaly.Comp.Continuity = _random.NextFloat(anomaly.Comp.MinContituty, anomaly.Comp.MaxContituty); SetBehavior(anomaly, GetRandomBehavior()); } - public void ShuffleParticlesEffect(AnomalyComponent anomaly) + public void ShuffleParticlesEffect(Entity anomaly) { var particles = new List { AnomalousParticleType.Delta, AnomalousParticleType.Epsilon, AnomalousParticleType.Zeta, AnomalousParticleType.Sigma }; - anomaly.SeverityParticleType = Random.PickAndTake(particles); - anomaly.DestabilizingParticleType = Random.PickAndTake(particles); - anomaly.WeakeningParticleType = Random.PickAndTake(particles); - anomaly.TransformationParticleType = Random.PickAndTake(particles); + anomaly.Comp.SeverityParticleType = Random.PickAndTake(particles); + anomaly.Comp.DestabilizingParticleType = Random.PickAndTake(particles); + anomaly.Comp.WeakeningParticleType = Random.PickAndTake(particles); + anomaly.Comp.TransformationParticleType = Random.PickAndTake(particles); + Dirty(anomaly); } private void OnShutdown(Entity anomaly, ref ComponentShutdown args) @@ -198,14 +197,12 @@ public sealed partial class AnomalySystem : SharedAnomalySystem if (anomaly.Comp.CurrentBehavior != null) RemoveBehavior(anomaly, anomaly.Comp.CurrentBehavior.Value); - //event broadcast - var ev = new AnomalyBehaviorChangedEvent(anomaly, anomaly.Comp.CurrentBehavior, behaviorProto); anomaly.Comp.CurrentBehavior = behaviorProto; - RaiseLocalEvent(anomaly, ref ev, true); - var behavior = _prototype.Index(behaviorProto); - EntityManager.AddComponents(anomaly, behavior.Components); + + var ev = new AnomalyBehaviorChangedEvent(anomaly, anomaly.Comp.CurrentBehavior, behaviorProto); + RaiseLocalEvent(anomaly, ref ev, true); } private void RemoveBehavior(Entity anomaly, ProtoId behaviorProto) @@ -213,7 +210,7 @@ public sealed partial class AnomalySystem : SharedAnomalySystem if (anomaly.Comp.CurrentBehavior == null) return; - var behavior = _prototype.Index(anomaly.Comp.CurrentBehavior.Value); + var behavior = _prototype.Index(behaviorProto); EntityManager.RemoveComponents(anomaly, behavior.Components); } diff --git a/Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs b/Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs index 7d4d9a2ee5..925c826fb5 100644 --- a/Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs +++ b/Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs @@ -15,26 +15,26 @@ public sealed class ShuffleParticlesAnomalySystem : EntitySystem SubscribeLocalEvent(OnStartCollide); } - private void OnStartCollide(EntityUid uid, ShuffleParticlesAnomalyComponent shuffle, StartCollideEvent args) + private void OnStartCollide(Entity ent, ref StartCollideEvent args) { - if (!TryComp(uid, out var anomaly)) + if (!TryComp(ent, out var anomaly)) return; - if (shuffle.ShuffleOnParticleHit && _random.Prob(shuffle.Prob)) - _anomaly.ShuffleParticlesEffect(anomaly); - - if (!TryComp(args.OtherEntity, out var particle)) + if (!HasComp(args.OtherEntity)) return; + + if (ent.Comp.ShuffleOnParticleHit && _random.Prob(ent.Comp.Prob)) + _anomaly.ShuffleParticlesEffect((ent, anomaly)); } - private void OnPulse(EntityUid uid, ShuffleParticlesAnomalyComponent shuffle, AnomalyPulseEvent args) + private void OnPulse(Entity ent, ref AnomalyPulseEvent args) { - if (!TryComp(uid, out var anomaly)) + if (!TryComp(ent, out var anomaly)) return; - if (shuffle.ShuffleOnPulse && _random.Prob(shuffle.Prob)) + if (ent.Comp.ShuffleOnPulse && _random.Prob(ent.Comp.Prob)) { - _anomaly.ShuffleParticlesEffect(anomaly); + _anomaly.ShuffleParticlesEffect((ent, anomaly)); } } } diff --git a/Content.Shared/Anomaly/Components/AnomalyComponent.cs b/Content.Shared/Anomaly/Components/AnomalyComponent.cs index 3878aeb81c..88e942ec50 100644 --- a/Content.Shared/Anomaly/Components/AnomalyComponent.cs +++ b/Content.Shared/Anomaly/Components/AnomalyComponent.cs @@ -152,25 +152,25 @@ public sealed partial class AnomalyComponent : Component /// /// The particle type that increases the severity of the anomaly. /// - [DataField] + [DataField, AutoNetworkedField] public AnomalousParticleType SeverityParticleType; /// /// The particle type that destabilizes the anomaly. /// - [DataField] + [DataField, AutoNetworkedField] public AnomalousParticleType DestabilizingParticleType; /// /// The particle type that weakens the anomalys health. /// - [DataField] + [DataField, AutoNetworkedField] public AnomalousParticleType WeakeningParticleType; /// /// The particle type that change anomaly behaviour. /// - [DataField] + [DataField, AutoNetworkedField] public AnomalousParticleType TransformationParticleType; #region Points and Vessels @@ -317,6 +317,7 @@ public readonly record struct AnomalyHealthChangedEvent(EntityUid Anomaly, float /// /// Event broadcast when an anomaly's behavior is changed. +/// This is raised after the relevant components are applied /// [ByRefEvent] public readonly record struct AnomalyBehaviorChangedEvent(EntityUid Anomaly, ProtoId? Old, ProtoId? New);