From f11d94eb8497d75302a3166f7647793f2de7bbe9 Mon Sep 17 00:00:00 2001 From: Tom Richardson Date: Wed, 6 Dec 2023 08:47:20 +1100 Subject: [PATCH] Add water cups to water coolers (#22073) * add water cup bin to water cooler * Fix punctuation, and add proper components/tags on init * I forgor and refactoring event construction --- .../Storage/EntitySystems/BinSystem.cs | 37 +++++++++++++++++-- .../en-US/entity-systems/bin/bin-system.ftl | 1 + .../structures/storage/tanks/tanks.ftl | 2 +- .../Objects/Consumable/Drinks/drinks_cups.yml | 9 ++--- .../Structures/Storage/Tanks/tanks.yml | 21 +++++++++++ 5 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 Resources/Locale/en-US/entity-systems/bin/bin-system.ftl diff --git a/Content.Shared/Storage/EntitySystems/BinSystem.cs b/Content.Shared/Storage/EntitySystems/BinSystem.cs index 86726587f0..90bca4d933 100644 --- a/Content.Shared/Storage/EntitySystems/BinSystem.cs +++ b/Content.Shared/Storage/EntitySystems/BinSystem.cs @@ -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(OnEntRemoved); SubscribeLocalEvent(OnInteractHand); SubscribeLocalEvent(OnAfterInteractUsing); + SubscribeLocalEvent>(OnAltInteractHand); + SubscribeLocalEvent(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; } + /// + /// 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 + /// + private void OnAltInteractHand(EntityUid uid, BinComponent component, GetVerbsEvent 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)}."); } /// 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 index 0000000000..eb0f6a35b0 --- /dev/null +++ b/Resources/Locale/en-US/entity-systems/bin/bin-system.ftl @@ -0,0 +1 @@ +bin-component-on-examine-text = Looks like there's {$count} items left. diff --git a/Resources/Locale/en-US/prototypes/entities/structures/storage/tanks/tanks.ftl b/Resources/Locale/en-US/prototypes/entities/structures/storage/tanks/tanks.ftl index 49ffcdae55..309d29ca43 100644 --- a/Resources/Locale/en-US/prototypes/entities/structures/storage/tanks/tanks.ftl +++ b/Resources/Locale/en-US/prototypes/entities/structures/storage/tanks/tanks.ftl @@ -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. diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml index 144a36dafa..793383ae5c 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml @@ -309,12 +309,6 @@ 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 @@ -326,5 +320,8 @@ - type: SolutionContainerVisuals maxFillLevels: 1 fillBaseName: icon- + - type: Tag + tags: + - Trash - type: TrashOnSolutionEmpty solution: drink diff --git a/Resources/Prototypes/Entities/Structures/Storage/Tanks/tanks.yml b/Resources/Prototypes/Entities/Structures/Storage/Tanks/tanks.yml index 8a7965fdd7..15504fe0d7 100644 --- a/Resources/Prototypes/Entities/Structures/Storage/Tanks/tanks.yml +++ b/Resources/Prototypes/Entities/Structures/Storage/Tanks/tanks.yml @@ -127,6 +127,27 @@ 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