]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow sound to play at the start of anomaly supercritical animation (#36260)
authorQuantum-cross <7065792+Quantum-cross@users.noreply.github.com>
Tue, 8 Apr 2025 09:11:32 +0000 (05:11 -0400)
committerGitHub <noreply@github.com>
Tue, 8 Apr 2025 09:11:32 +0000 (19:11 +1000)
* Add datafield to AnomalyComponent to play a sound when an anomaly enters supercriticality

* use Entity<T> pattern

* use implicit default for nullable

* don't forget to resolve the AnomalyComponent...

* Add comment for StartSupercriticalEvent "ent" parameter

* use implicit casts from Entity<T> to EntityUid

* StartSupercriticalEvent requires AnomalyComponent to resolve

Content.Server/Anomaly/AnomalySystem.Commands.cs
Content.Shared/Anomaly/Components/AnomalyComponent.cs
Content.Shared/Anomaly/SharedAnomalySystem.cs

index b1a7c4443976e718c05e58f31e58d48888a155f2..8b8206490dc2093689f39369f0931a25feb9404e 100644 (file)
@@ -44,10 +44,10 @@ public sealed partial class AnomalySystem
         if (!NetEntity.TryParse(args[0], out var uidNet) || !TryGetEntity(uidNet, out var uid))
             return;
 
-        if (!HasComp<AnomalyComponent>(uid))
+        if (!TryComp<AnomalyComponent>(uid, out var anomaly))
             return;
 
-        StartSupercriticalEvent(uid.Value);
+        StartSupercriticalEvent((uid.Value, anomaly));
     }
 
     private CompletionResult GetAnomalyCompletion(IConsoleShell shell, string[] args)
index e6228b5fb0d77a97ef8071a134bd1f730206e9d7..f58f9f1d07da4fb2f217a14cf19d5d2b2c1f3eca 100644 (file)
@@ -129,6 +129,12 @@ public sealed partial class AnomalyComponent : Component
     /// </summary>
     [DataField]
     public SoundSpecifier? SupercriticalSound = new SoundCollectionSpecifier("Explosion");
+
+    /// <summary>
+    /// The sound plays at the start of the animation when an anomaly goes supercritical
+    /// </summary>
+    [DataField]
+    public SoundSpecifier? SupercriticalSoundAtAnimationStart;
     #endregion
 
     /// <summary>
index f2afbe2f5180a3e0c06e9c39c777c549c23ba908..30a7cb04d0debb3d732b5b2da4f30ac309c976e9 100644 (file)
@@ -116,21 +116,26 @@ public abstract class SharedAnomalySystem : EntitySystem
     /// <summary>
     /// Begins the animation for going supercritical
     /// </summary>
-    /// <param name="uid"></param>
-    public void StartSupercriticalEvent(EntityUid uid)
+    /// <param name="ent">Entity to go supercritical</param>
+    public void StartSupercriticalEvent(Entity<AnomalyComponent?> ent)
     {
         // don't restart it if it's already begun
-        if (HasComp<AnomalySupercriticalComponent>(uid))
+        if (HasComp<AnomalySupercriticalComponent>(ent))
+            return;
+
+        if(!Resolve(ent, ref ent.Comp))
             return;
 
-        AdminLog.Add(LogType.Anomaly, LogImpact.High, $"Anomaly {ToPrettyString(uid)} began to go supercritical.");
+        AdminLog.Add(LogType.Anomaly, LogImpact.High, $"Anomaly {ToPrettyString(ent.Owner)} began to go supercritical.");
         if (_net.IsServer)
-            Log.Info($"Anomaly is going supercritical. Entity: {ToPrettyString(uid)}");
+            Log.Info($"Anomaly is going supercritical. Entity: {ToPrettyString(ent.Owner)}");
+
+        Audio.PlayPvs(ent.Comp.SupercriticalSoundAtAnimationStart, Transform(ent).Coordinates);
 
-        var super = AddComp<AnomalySupercriticalComponent>(uid);
+        var super = AddComp<AnomalySupercriticalComponent>(ent);
         super.EndTime = Timing.CurTime + super.SupercriticalDuration;
-        Appearance.SetData(uid, AnomalyVisuals.Supercritical, true);
-        Dirty(uid, super);
+        Appearance.SetData(ent, AnomalyVisuals.Supercritical, true);
+        Dirty(ent, super);
     }
 
     /// <summary>
@@ -240,7 +245,7 @@ public abstract class SharedAnomalySystem : EntitySystem
         var newVal = component.Severity + change;
 
         if (newVal >= 1)
-            StartSupercriticalEvent(uid);
+            StartSupercriticalEvent((uid, component));
 
         component.Severity = Math.Clamp(newVal, 0, 1);
         Dirty(uid, component);