]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add MindPlaySound to role system (#21460)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Tue, 14 Nov 2023 12:52:40 +0000 (12:52 +0000)
committerGitHub <noreply@github.com>
Tue, 14 Nov 2023 12:52:40 +0000 (23:52 +1100)
Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Content.Server/Ninja/Systems/SpaceNinjaSystem.cs
Content.Shared/Roles/SharedRoleSystem.cs

index ef949d09fc98d5f1faf871970a796bdb50ad3aaf..52a588108371e513382b2740aacec17907951ad3 100644 (file)
@@ -268,21 +268,16 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
         _roleSystem.MindAddRole(mindId, new TraitorRoleComponent
         {
             PrototypeId = traitorRule.TraitorPrototypeId
-        });
-        // Assign briefing
+        }, mind);
+        // Assign briefing and greeting sound
         _roleSystem.MindAddRole(mindId, new RoleBriefingComponent
         {
             Briefing = briefing
-        });
+        }, mind);
+        _roleSystem.MindPlaySound(mindId, traitorRule.GreetSoundNotification, mind);
         SendTraitorBriefing(mindId, traitorRule.Codewords, code);
         traitorRule.TraitorMinds.Add(mindId);
 
-        if (_mindSystem.TryGetSession(mindId, out var session))
-        {
-            // Notificate player about new role assignment
-            _audioSystem.PlayGlobal(traitorRule.GreetSoundNotification, session);
-        }
-
         // Change the faction
         _npcFaction.RemoveFaction(entity, "NanoTrasen", false);
         _npcFaction.AddFaction(entity, "Syndicate");
index 6de2d7dee00314105181d0dcb63821585a2ef9ca..a5b78570db46ea8757591da33d2d8ffe919286f4 100644 (file)
@@ -167,6 +167,7 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem
             PrototypeId = "SpaceNinja"
         };
         _role.MindAddRole(mindId, role, mind);
+        _role.MindPlaySound(mindId, config.GreetingSound, mind);
 
         // choose spider charge detonation point
         var warps = new List<EntityUid>();
@@ -179,9 +180,7 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem
         if (warps.Count > 0)
             role.SpiderChargeTarget = _random.Pick(warps);
 
-        var session = mind.Session;
-        _audio.PlayGlobal(config.GreetingSound, Filter.Empty().AddPlayer(session), false, AudioParams.Default);
-        _chatMan.DispatchServerMessage(session, Loc.GetString("ninja-role-greeting"));
+        _chatMan.DispatchServerMessage(mind.Session, Loc.GetString("ninja-role-greeting"));
     }
 
     // TODO: PowerCellDraw, modify when cloak enabled
index 9ba625305cfa9cc03650700e974c631c6ec49658..ae49289eb8e5f9d13193611940810bda5d5ea035 100644 (file)
@@ -2,6 +2,7 @@
 using Content.Shared.Database;
 using Content.Shared.Mind;
 using Content.Shared.Roles.Jobs;
+using Robust.Shared.Audio;
 using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Roles;
@@ -10,6 +11,7 @@ public abstract class SharedRoleSystem : EntitySystem
 {
     [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
     [Dependency] private readonly IPrototypeManager _prototypes = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly SharedMindSystem _minds = default!;
 
     // TODO please lord make role entities
@@ -153,4 +155,14 @@ public abstract class SharedRoleSystem : EntitySystem
     {
         return _antagTypes.Contains(typeof(T));
     }
+
+    /// <summary>
+    /// Play a sound for the mind, if it has a session attached.
+    /// Use this for role greeting sounds.
+    /// </summary>
+    public void MindPlaySound(EntityUid mindId, SoundSpecifier? sound, MindComponent? mind = null)
+    {
+        if (Resolve(mindId, ref mind) && mind.Session != null)
+            _audio.PlayGlobal(sound, mind.Session);
+    }
 }