]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Small anomaly behavior fix (#28290)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Tue, 28 May 2024 00:52:56 +0000 (20:52 -0400)
committerGitHub <noreply@github.com>
Tue, 28 May 2024 00:52:56 +0000 (17:52 -0700)
* Small anomaly behavior fix

* well put together code

Content.Server/Anomaly/AnomalySystem.cs
Content.Server/Anomaly/Effects/ShuffleParticlesAnomalySystem.cs
Content.Shared/Anomaly/Components/AnomalyComponent.cs

index 73658a0320eec8f3509bbe9c1a999a44f598e911..3e9760a056c022c409a44018b99f8cef4e36cad0 100644 (file)
@@ -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<AnomalyComponent> anomaly)
     {
         var particles = new List<AnomalousParticleType>
             { 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<AnomalyComponent> 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<AnomalyComponent> anomaly, ProtoId<AnomalyBehaviorPrototype> 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);
     }
index 7d4d9a2ee5d00a25cf88f05ad9920dfa353b7e23..925c826fb5a80b31aaef60b8a639b9f702d7b302 100644 (file)
@@ -15,26 +15,26 @@ public sealed class ShuffleParticlesAnomalySystem : EntitySystem
         SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, StartCollideEvent>(OnStartCollide);
     }
 
-    private void OnStartCollide(EntityUid uid, ShuffleParticlesAnomalyComponent shuffle, StartCollideEvent args)
+    private void OnStartCollide(Entity<ShuffleParticlesAnomalyComponent> ent, ref StartCollideEvent args)
     {
-        if (!TryComp<AnomalyComponent>(uid, out var anomaly))
+        if (!TryComp<AnomalyComponent>(ent, out var anomaly))
             return;
 
-        if (shuffle.ShuffleOnParticleHit && _random.Prob(shuffle.Prob))
-            _anomaly.ShuffleParticlesEffect(anomaly);
-
-        if (!TryComp<AnomalousParticleComponent>(args.OtherEntity, out var particle))
+        if (!HasComp<AnomalousParticleComponent>(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<ShuffleParticlesAnomalyComponent> ent, ref AnomalyPulseEvent args)
     {
-        if (!TryComp<AnomalyComponent>(uid, out var anomaly))
+        if (!TryComp<AnomalyComponent>(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));
         }
     }
 }
index 3878aeb81cba48923bbb5523593f928882470430..88e942ec507914696afd8cb2d5b4b3b1fbf64d12 100644 (file)
@@ -152,25 +152,25 @@ public sealed partial class AnomalyComponent : Component
     /// <summary>
     /// The particle type that increases the severity of the anomaly.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public AnomalousParticleType SeverityParticleType;
 
     /// <summary>
     /// The particle type that destabilizes the anomaly.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public AnomalousParticleType DestabilizingParticleType;
 
     /// <summary>
     /// The particle type that weakens the anomalys health.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public AnomalousParticleType WeakeningParticleType;
 
     /// <summary>
     /// The particle type that change anomaly behaviour.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public AnomalousParticleType TransformationParticleType;
 
     #region Points and Vessels
@@ -317,6 +317,7 @@ public readonly record struct AnomalyHealthChangedEvent(EntityUid Anomaly, float
 
 /// <summary>
 /// Event broadcast when an anomaly's behavior is changed.
+/// This is raised after the relevant components are applied
 /// </summary>
 [ByRefEvent]
 public readonly record struct AnomalyBehaviorChangedEvent(EntityUid Anomaly, ProtoId<AnomalyBehaviorPrototype>? Old, ProtoId<AnomalyBehaviorPrototype>? New);