]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Desk bells can be rung with activate (#24047)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Sun, 14 Jan 2024 01:43:59 +0000 (02:43 +0100)
committerGitHub <noreply@github.com>
Sun, 14 Jan 2024 01:43:59 +0000 (12:43 +1100)
* Desk bells can be rung with activate

Important

* Remove obsoletions too while I'm at it.

Content.Server/Interaction/Components/InteractionPopupComponent.cs
Content.Server/Interaction/InteractionPopupSystem.cs
Resources/Prototypes/Entities/Objects/Misc/desk_bell.yml

index f41f57dd099ca22eb0efa39f14cf831a7f881b0a..000344e61c610839fc7619aed478687606af21dd 100644 (file)
@@ -76,4 +76,10 @@ public sealed partial class InteractionPopupComponent : Component
 
     [ViewVariables(VVAccess.ReadWrite)]
     public TimeSpan LastInteractTime;
+
+    /// <summary>
+    /// If set to true, activate interactions will also trigger the component.
+    /// </summary>
+    [DataField]
+    public bool OnActivate;
 }
index 474284cf8066712731e8699e331a02177d644c23..77b76f898a7a05d0f23a6e33049d14b754bb54dd 100644 (file)
@@ -20,16 +20,36 @@ public sealed class InteractionPopupSystem : EntitySystem
     [Dependency] private readonly MobStateSystem _mobStateSystem = default!;
     [Dependency] private readonly PopupSystem _popupSystem = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly SharedTransformSystem _transform = default!;
 
     public override void Initialize()
     {
         base.Initialize();
         SubscribeLocalEvent<InteractionPopupComponent, InteractHandEvent>(OnInteractHand);
+        SubscribeLocalEvent<InteractionPopupComponent, ActivateInWorldEvent>(OnActivateInWorld);
+    }
+
+    private void OnActivateInWorld(EntityUid uid, InteractionPopupComponent component, ActivateInWorldEvent args)
+    {
+        if (!component.OnActivate)
+            return;
+
+        SharedInteract(uid, component, args, args.Target, args.User);
     }
 
     private void OnInteractHand(EntityUid uid, InteractionPopupComponent component, InteractHandEvent args)
     {
-        if (args.Handled || args.User == args.Target)
+        SharedInteract(uid, component, args, args.Target, args.User);
+    }
+
+    private void SharedInteract(
+        EntityUid uid,
+        InteractionPopupComponent component,
+        HandledEntityEventArgs args,
+        EntityUid target,
+        EntityUid user)
+    {
+        if (args.Handled || user == target)
             return;
 
         //Handling does nothing and this thing annoyingly plays way too often.
@@ -64,7 +84,7 @@ public sealed class InteractionPopupSystem : EntitySystem
                 sfx = component.InteractSuccessSound;
 
             if (component.InteractSuccessSpawn != null)
-                Spawn(component.InteractSuccessSpawn, Transform(uid).MapPosition);
+                Spawn(component.InteractSuccessSpawn, _transform.GetMapCoordinates(uid));
         }
         else
         {
@@ -75,25 +95,25 @@ public sealed class InteractionPopupSystem : EntitySystem
                 sfx = component.InteractFailureSound;
 
             if (component.InteractFailureSpawn != null)
-                Spawn(component.InteractFailureSpawn, Transform(uid).MapPosition);
+                Spawn(component.InteractFailureSpawn, _transform.GetMapCoordinates(uid));
         }
 
         if (component.MessagePerceivedByOthers != null)
         {
             var msgOthers = Loc.GetString(component.MessagePerceivedByOthers,
-                ("user", Identity.Entity(args.User, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
-            _popupSystem.PopupEntity(msg, uid, args.User);
-            _popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(args.User, entityManager: EntityManager), true);
+                ("user", Identity.Entity(user, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
+            _popupSystem.PopupEntity(msg, uid, user);
+            _popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
         }
         else
-            _popupSystem.PopupEntity(msg, uid, args.User); //play only for the initiating entity.
+            _popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity.
 
         if (sfx is not null) //not all cases will have sound.
         {
             if (component.SoundPerceivedByOthers)
-                _audio.PlayPvs(sfx, args.Target); //play for everyone in range
+                _audio.PlayPvs(sfx, target); //play for everyone in range
             else
-                _audio.PlayEntity(sfx, Filter.Entities(args.User, args.Target), args.Target, true); //play only for the initiating entity and its target.
+                _audio.PlayEntity(sfx, Filter.Entities(user, target), target, true); //play only for the initiating entity and its target.
         }
 
         component.LastInteractTime = curTime;
index 092722ec1701ca491303866c6cd84e1de46b88c2..cef406ea50b86b346195959c1745a41cde462b07 100644 (file)
@@ -14,6 +14,7 @@
     params:
       variation: 0.03
       volume: 3
+    onActivate: true
   - type: EmitSoundOnUse
     sound:
       collection: DeskBell