]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add water cups to water coolers (#22073)
authorTom Richardson <tgrkzus@gmail.com>
Tue, 5 Dec 2023 21:47:20 +0000 (08:47 +1100)
committerGitHub <noreply@github.com>
Tue, 5 Dec 2023 21:47:20 +0000 (14:47 -0700)
* add water cup bin to water cooler

* Fix punctuation, and add proper components/tags on init

* I forgor and refactoring event construction

Content.Shared/Storage/EntitySystems/BinSystem.cs
Resources/Locale/en-US/entity-systems/bin/bin-system.ftl [new file with mode: 0644]
Resources/Locale/en-US/prototypes/entities/structures/storage/tanks/tanks.ftl
Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml
Resources/Prototypes/Entities/Structures/Storage/Tanks/tanks.yml

index 86726587f01f1e277d480088b6ce52bdf9d26453..90bca4d9335e242dc4bb3c5192c8fabe667c3acb 100644 (file)
@@ -1,10 +1,13 @@
 using System.Linq;
 using Content.Shared.Administration.Logs;
 using Content.Shared.Database;
+using Content.Shared.Examine;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction;
 using Content.Shared.Storage.Components;
+using Content.Shared.Verbs;
 using Robust.Shared.Containers;
+using Robust.Shared.Map;
 using Robust.Shared.Network;
 using Robust.Shared.Timing;
 
@@ -31,6 +34,13 @@ public sealed class BinSystem : EntitySystem
         SubscribeLocalEvent<BinComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
         SubscribeLocalEvent<BinComponent, InteractHandEvent>(OnInteractHand);
         SubscribeLocalEvent<BinComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
+        SubscribeLocalEvent<BinComponent, GetVerbsEvent<AlternativeVerb>>(OnAltInteractHand);
+        SubscribeLocalEvent<BinComponent, ExaminedEvent>(OnExamined);
+    }
+
+    private void OnExamined(EntityUid uid, BinComponent component, ExaminedEvent args)
+    {
+        args.PushText(Loc.GetString("bin-component-on-examine-text", ("count", component.Items.Count)));
     }
 
     private void OnStartup(EntityUid uid, BinComponent component, ComponentStartup args)
@@ -76,19 +86,38 @@ public sealed class BinSystem : EntitySystem
         args.Handled = true;
     }
 
+    /// <summary>
+    /// Alt interact acts the same as interacting with your hands normally, but allows fallback interaction if the item
+    /// has priority. E.g. a water cup on a water cooler fills itself on a normal click,
+    /// but you can use alternative interactions to restock the cup bin
+    /// </summary>
+    private void OnAltInteractHand(EntityUid uid, BinComponent component, GetVerbsEvent<AlternativeVerb> args)
+    {
+        if (args.Using != null)
+        {
+            var canReach = args.CanAccess && args.CanInteract;
+            InsertIntoBin(args.User, args.Target, (EntityUid) args.Using, component, false, canReach);
+        }
+    }
+
     private void OnAfterInteractUsing(EntityUid uid, BinComponent component, AfterInteractUsingEvent args)
     {
-        if (args.Handled || !args.CanReach)
+        InsertIntoBin(args.User, uid, args.Used, component, args.Handled, args.CanReach);
+        args.Handled = true;
+    }
+
+    private void InsertIntoBin(EntityUid user, EntityUid target, EntityUid itemInHand, BinComponent component, bool handled, bool canReach)
+    {
+        if (handled || !canReach)
             return;
 
         if (!_timing.IsFirstTimePredicted)
             return;
 
-        if (!TryInsertIntoBin(uid, args.Used, component))
+        if (!TryInsertIntoBin(target, itemInHand, component))
             return;
 
-        _admin.Add(LogType.Pickup, LogImpact.Low, $"{ToPrettyString(uid):player} inserted {ToPrettyString(args.User)} into bin {ToPrettyString(uid)}.");
-        args.Handled = true;
+        _admin.Add(LogType.Pickup, LogImpact.Low, $"{ToPrettyString(target):player} inserted {ToPrettyString(user)} into bin {ToPrettyString(target)}.");
     }
 
     /// <summary>
diff --git a/Resources/Locale/en-US/entity-systems/bin/bin-system.ftl b/Resources/Locale/en-US/entity-systems/bin/bin-system.ftl
new file mode 100644 (file)
index 0000000..eb0f6a3
--- /dev/null
@@ -0,0 +1 @@
+bin-component-on-examine-text = Looks like there's {$count} items left.
index 49ffcdae55adf65360099c37ea442b48aab25179..309d29ca43729e0c19731f92cbe9748e7536d96e 100644 (file)
@@ -14,7 +14,7 @@ ent-WaterTankFull = { ent-WaterTank }
     .desc = { ent-WaterTank.desc }
 
 ent-WaterCooler = water cooler
-    .desc = Seems like a good place to stand and waste time.
+    .desc = Seems like a good place to stand and waste time. It has a stock of paper cups on the side.
 
 ent-WaterTankHighCapacity = high-capacity water tank
     .desc = A highly pressurized water tank made to hold gargantuan amounts of water.
index 144a36dafa6d0079fefe15569ccd02f5b86de15a..793383ae5c8d660a8ea41d1a44a8fae7e512acfc 100644 (file)
   name: water cup
   description: A paper water cup.
   components:
-  - type: SolutionContainerManager
-    solutions:
-      drink:
-        reagents:
-        - ReagentId: Water
-          Quantity: 20
   - type: Drink
   - type: Sprite
     sprite: Objects/Consumable/Drinks/water_cup.rsi
   - type: SolutionContainerVisuals
     maxFillLevels: 1
     fillBaseName: icon-
+  - type: Tag
+    tags:
+    - Trash
   - type: TrashOnSolutionEmpty
     solution: drink
index 8a7965fdd777526b7406d704e979a4012390c1e5..15504fe0d7898c5e610c78de6a0f5381ebb90afa 100644 (file)
         reagents:
         - ReagentId: Water
           Quantity: 500
+  - type: ContainerContainer
+    containers:
+      bin-container: !type:Container
+  - type: Bin
+    initialContents:
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    - DrinkWaterCup
+    whitelist:
+      requireAll: true
+      components:
+      - FitsInDispenser
+      tags:
+      - Trash
 
 - type: entity
   parent: StorageTank