]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
big cardboard box improvements (#16418)
authorIlya246 <57039557+Ilya246@users.noreply.github.com>
Sun, 14 May 2023 12:46:19 +0000 (16:46 +0400)
committerGitHub <noreply@github.com>
Sun, 14 May 2023 12:46:19 +0000 (08:46 -0400)
Content.Server/CardboardBox/CardboardBoxSystem.cs
Content.Shared/CardboardBox/Components/CardboardBoxComponent.cs

index e7a0c8f973e42b6306e030b8051a9cd76c1440ef..c199c2473a7e591a8d447c50ba03b0eff8350229 100644 (file)
@@ -31,12 +31,28 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
         SubscribeLocalEvent<CardboardBoxComponent, StorageAfterOpenEvent>(AfterStorageOpen);
         SubscribeLocalEvent<CardboardBoxComponent, StorageBeforeOpenEvent>(BeforeStorageOpen);
         SubscribeLocalEvent<CardboardBoxComponent, StorageAfterCloseEvent>(AfterStorageClosed);
+               SubscribeLocalEvent<CardboardBoxComponent, ActivateInWorldEvent>(OnInteracted);
         SubscribeLocalEvent<CardboardBoxComponent, InteractedNoHandEvent>(OnNoHandInteracted);
         SubscribeLocalEvent<CardboardBoxComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
         SubscribeLocalEvent<CardboardBoxComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
 
         SubscribeLocalEvent<CardboardBoxComponent, DamageChangedEvent>(OnDamage);
     }
+       
+       private void OnInteracted(EntityUid uid, CardboardBoxComponent component, ActivateInWorldEvent args)
+    {
+               if (!TryComp<EntityStorageComponent>(uid, out var box))
+            return;
+
+        args.Handled = true;
+        _storage.ToggleOpen(args.User, uid, box);
+
+               if (box.Contents.Contains(args.User) && !box.Open)
+               {
+                       _mover.SetRelay(args.User, uid);
+                       component.Mover = args.User;
+               }
+    }
 
     private void OnNoHandInteracted(EntityUid uid, CardboardBoxComponent component, InteractedNoHandEvent args)
     {
@@ -49,6 +65,9 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
 
     private void BeforeStorageOpen(EntityUid uid, CardboardBoxComponent component, ref StorageBeforeOpenEvent args)
     {
+               if (component.Quiet)
+                       return;
+
         //Play effect & sound
         if (component.Mover != null)
         {
@@ -91,17 +110,11 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
         if (!TryComp(args.Entity, out MobMoverComponent? mover))
             return;
 
-        if (component.Mover != null)
+        if (component.Mover == null)
         {
-            // player movers take priority
-            if (HasComp<ActorComponent>(component.Mover) || !HasComp<ActorComponent>(args.Entity))
-                return;
-
-            RemComp<RelayInputMoverComponent>(component.Mover.Value);
+            _mover.SetRelay(args.Entity, uid);
+                       component.Mover = args.Entity;
         }
-
-        _mover.SetRelay(args.Entity, uid);
-        component.Mover = args.Entity;
     }
 
     /// <summary>
index fa4bb3b639a1bbdff18eff8ff66c84d80e23cac8..33db21593e61baf33470e3d8411437cf6b4e9be5 100644 (file)
@@ -30,6 +30,13 @@ public sealed class CardboardBoxComponent : Component
     [ViewVariables(VVAccess.ReadWrite)]
     [DataField("effectSound")]
     public SoundSpecifier? EffectSound;
+       
+       /// <summary>
+       /// Whether to prevent the box from making the sound and effect
+       /// </summary>
+    [ViewVariables(VVAccess.ReadWrite)]
+       [DataField("quiet")]
+       public bool Quiet = false;
 
     /// <summary>
     /// How far should the box opening effect go?