From 39a6c8afb380e8d6f0f485d58342d5dd152472fb Mon Sep 17 00:00:00 2001 From: Jessica M Date: Thu, 4 Aug 2022 01:52:08 -0700 Subject: [PATCH] Adds trash tag to more items. New component "TrashOnEmpty" (#10166) --- .../Components/TrashOnEmptyComponent.cs | 16 ++++++ .../EntitySystems/TrashOnEmptySystem.cs | 53 +++++++++++++++++++ .../Objects/Consumable/Drinks/drinks_cans.yml | 5 +- .../Objects/Consumable/Drinks/drinks_cups.yml | 8 +++ .../Consumable/Food/Containers/condiments.yml | 6 +++ .../Consumable/Food/Containers/tin.yml | 4 +- .../Objects/Consumable/Food/produce.yml | 3 ++ .../Objects/Specific/chemistry-bottles.yml | 6 ++- .../Entities/Objects/Specific/chemistry.yml | 2 + 9 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 Content.Server/Nutrition/Components/TrashOnEmptyComponent.cs create mode 100644 Content.Server/Nutrition/EntitySystems/TrashOnEmptySystem.cs diff --git a/Content.Server/Nutrition/Components/TrashOnEmptyComponent.cs b/Content.Server/Nutrition/Components/TrashOnEmptyComponent.cs new file mode 100644 index 0000000000..26510e6090 --- /dev/null +++ b/Content.Server/Nutrition/Components/TrashOnEmptyComponent.cs @@ -0,0 +1,16 @@ +namespace Content.Server.Nutrition.Components +{ + /// + /// Component that tags solution containers as trash when their contents have been emptied. + /// Used for things like used ketchup packets or used syringes. + /// + [RegisterComponent] + public sealed class TrashOnEmptyComponent : Component + { + /// + /// The name of the solution of which to check emptiness + /// + [ViewVariables] [DataField("solution")] + public string Solution { get; set; } = string.Empty; + } +} diff --git a/Content.Server/Nutrition/EntitySystems/TrashOnEmptySystem.cs b/Content.Server/Nutrition/EntitySystems/TrashOnEmptySystem.cs new file mode 100644 index 0000000000..b58a2185dd --- /dev/null +++ b/Content.Server/Nutrition/EntitySystems/TrashOnEmptySystem.cs @@ -0,0 +1,53 @@ +using Content.Server.Chemistry.Components.SolutionManager; +using Content.Server.Chemistry.EntitySystems; +using Content.Server.Nutrition.Components; +using Content.Shared.Chemistry.Components; +using Content.Shared.Tag; + +namespace Content.Server.Nutrition.EntitySystems +{ + public sealed class TrashOnEmptySystem : EntitySystem + { + [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; + [Dependency] private readonly TagSystem _tagSystem = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnSolutionChange); + } + + public void OnStartup(EntityUid uid, TrashOnEmptyComponent component, ComponentStartup args) + { + CheckSolutions(component); + } + + public void OnSolutionChange(EntityUid uid, TrashOnEmptyComponent component, SolutionChangedEvent args) + { + CheckSolutions(component); + } + + public void CheckSolutions(TrashOnEmptyComponent component) + { + EntityManager.EnsureComponent(component.Owner); + + if (!EntityManager.HasComponent((component).Owner)) + return; + + if (_solutionContainerSystem.TryGetSolution(component.Owner, component.Solution, out var solution)) + UpdateTags(component, solution); + } + + public void UpdateTags(TrashOnEmptyComponent component, Solution solution) + { + if (solution.DrainAvailable <= 0) + { + _tagSystem.AddTag(component.Owner, "Trash"); + return; + } + if (_tagSystem.HasTag(component.Owner, "Trash")) + _tagSystem.RemoveTag(component.Owner, "Trash"); + } + } +} diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml index 64f501a09a..1063457725 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml @@ -34,12 +34,11 @@ - type: DrinkCanVisualizer stateClosed: icon stateOpen: icon_open - - type: Tag - tags: - - Trash - type: ItemCooldown - type: Recyclable - type: SpaceGarbage + - type: TrashOnEmpty + solution: drink - type: entity parent: DrinkCanBaseFull diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml index 3d49e426f5..187e83f14c 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml @@ -174,6 +174,8 @@ maxVol: 20 - type: Sprite sprite: Objects/Consumable/Drinks/hot_coffee.rsi + - type: TrashOnEmpty + solution: drink - type: entity parent: DrinkBaseCup @@ -191,6 +193,8 @@ - type: Sprite sprite: Objects/Consumable/Drinks/teacup.rsi state: icon-1 + - type: TrashOnEmpty + solution: drink - type: entity parent: DrinkBaseCup @@ -210,6 +214,8 @@ state: icon - type: Item sprite: Objects/Consumable/Drinks/lean.rsi + - type: TrashOnEmpty + solution: drink - type: entity parent: DrinkBaseCup @@ -228,3 +234,5 @@ - type: Sprite sprite: Objects/Consumable/Drinks/water_cup.rsi state: icon-1 + - type: TrashOnEmpty + solution: drink diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/condiments.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/condiments.yml index 4d9cac8f15..33ec7899bc 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/condiments.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/condiments.yml @@ -33,6 +33,8 @@ - type: Icon sprite: Objects/Consumable/Food/condiments.rsi state: packet-empty + - type: TrashOnEmpty + solution: food - type: entity parent: FoodCondimentPacket @@ -357,6 +359,8 @@ - type: SolutionContainerVisualizer maxFillLevels: 6 fillBaseName: bottle-alpha- + - type: TrashOnEmpty + solution: food - type: entity parent: FoodCondimentBottle @@ -501,6 +505,8 @@ - type: SolutionContainerVisualizer maxFillLevels: 3 fillBaseName: bottle-s-alpha- + - type: TrashOnEmpty + solution: food - type: entity parent: FoodCondimentBottleSmall diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/tin.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/tin.yml index 292e75877c..f98cf1ca1a 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/tin.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/tin.yml @@ -43,7 +43,9 @@ sprite: Objects/Consumable/Food/snacks.rsi heldPrefix: packet size: 3 - + - type: Tag + tags: + - Trash # Tins # Need something that you can open these tins with. I suggest a prying or cutting tool. diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/produce.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/produce.yml index c5b26c2aa3..2f72fa6ff7 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/produce.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/produce.yml @@ -489,6 +489,9 @@ netsync: false - type: Item size: 1 + - type: Tag + tags: + - Trash - type: entity name: onion diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml index 1b1a1c5eec..7933ab2d8c 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml @@ -40,6 +40,8 @@ sprite: Objects/Specific/Chemistry/beaker.rsi - type: Spillable solution: drink + - type: TrashOnEmpty + solution: drink - type: entity name: bottle @@ -161,7 +163,7 @@ components: - type: SolutionContainerManager solutions: - drink: + drink: maxVol: 30 reagents: - ReagentId: Ephedrine @@ -174,7 +176,7 @@ components: - type: SolutionContainerManager solutions: - drink: + drink: maxVol: 30 reagents: - ReagentId: Omnizine diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml index f80a81b5e8..5f9a07e2a1 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml @@ -235,6 +235,8 @@ injectOnly: false - type: Spillable solution: injector + - type: TrashOnEmpty + solution: injector - type: Appearance visuals: # this visualizer used for reagent inside