From c3d11fb3e15655373c3279c3b93b1dfa846e1d29 Mon Sep 17 00:00:00 2001 From: Ygg01 Date: Wed, 15 Sep 2021 12:46:43 +0200 Subject: [PATCH] Fix throwable solution (#4590) * Fix throwable solution * Revert previous commit * Change Spillable and SpillBehavior * Fix sloth's suggestion. Add more documents --- .../Thresholds/Behaviors/SpillBehavior.cs | 27 ++++++++++++++++--- .../Fluids/Components/SpillableComponent.cs | 5 +++- .../Consumable/Food/Containers/bowl.yml | 1 + .../Objects/Consumable/Food/ingredients.yml | 1 + .../Entities/Objects/Consumable/Food/soup.yml | 1 + .../Entities/Objects/Consumable/drinks.yml | 1 + .../Objects/Consumable/drinks_bottles.yml | 1 + .../Objects/Consumable/drinks_cans.yml | 2 +- .../Objects/Consumable/drinks_cups.yml | 1 + .../Objects/Consumable/trash_drinks.yml | 1 + .../Objects/Specific/Hydroponics/sprays.yml | 1 + .../Objects/Specific/Janitorial/spray.yml | 1 + .../Objects/Specific/chemistry-bottles.yml | 1 + .../Entities/Objects/Specific/chemistry.yml | 3 +++ .../Entities/Objects/Tools/bucket.yml | 1 + 15 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs index 4d6eeca695..bdeb012770 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs @@ -10,13 +10,32 @@ namespace Content.Server.Destructible.Thresholds.Behaviors [DataDefinition] public class SpillBehavior : IThresholdBehavior { + [DataField("solution")] + public string? Solution; + + /// + /// If there is a SpillableComponent on IEntity owner use it to create a puddle/smear. + /// Or whatever solution is specified in the behavior itself. + /// If none are available do nothing. + /// + /// Entity on which behavior is executed + /// system calling the behavior public void Execute(IEntity owner, DestructibleSystem system) { - // TODO see if this is correct - if (!EntitySystem.Get().TryGetSolution(owner, SpillableComponent.SolutionName, out var solution)) - return; + var solutionContainerSystem = EntitySystem.Get(); - solution.SpillAt(owner.Transform.Coordinates, "PuddleSmear", false); + + if (owner.TryGetComponent(out SpillableComponent? spillableComponent) && + solutionContainerSystem.TryGetSolution(owner.Uid, spillableComponent.SolutionName, + out var compSolution)) + { + compSolution.SpillAt(owner.Transform.Coordinates, "PuddleSmear", false); + } + else if (Solution != null && + solutionContainerSystem.TryGetSolution(owner.Uid, Solution, out var behaviorSolution)) + { + behaviorSolution.SpillAt(owner.Transform.Coordinates, "PuddleSmear", false); + } } } } diff --git a/Content.Server/Fluids/Components/SpillableComponent.cs b/Content.Server/Fluids/Components/SpillableComponent.cs index 678fecaa4c..e026c171bf 100644 --- a/Content.Server/Fluids/Components/SpillableComponent.cs +++ b/Content.Server/Fluids/Components/SpillableComponent.cs @@ -7,6 +7,7 @@ using Content.Shared.Notification.Managers; using Content.Shared.Verbs; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Fluids.Components { @@ -14,7 +15,9 @@ namespace Content.Server.Fluids.Components public class SpillableComponent : Component, IDropped { public override string Name => "Spillable"; - public const string SolutionName = "puddle"; + + [DataField("solution")] + public string SolutionName = "puddle"; /// /// Transfers solution from the held container to the floor. diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/bowl.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/bowl.yml index bf050b497a..4ad135e002 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/bowl.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/bowl.yml @@ -23,6 +23,7 @@ types: Blunt: 5 - type: Spillable + solution: food - type: Damageable damageContainer: Inorganic - type: Destructible diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/ingredients.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/ingredients.yml index 4b9a52bf7c..a89a807223 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/ingredients.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/ingredients.yml @@ -36,6 +36,7 @@ useSound: path: /Audio/Items/eating_1.ogg - type: Spillable + solution: food - type: entity parent: ReagentContainerBase diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/soup.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/soup.yml index 3297ace1c6..e36bd347e0 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/soup.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/soup.yml @@ -24,6 +24,7 @@ types: Blunt: 5 - type: Spillable + solution: food - type: Damageable damageContainer: Inorganic - type: Destructible diff --git a/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml b/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml index f620308048..09e59f8359 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml @@ -16,6 +16,7 @@ - type: Sprite state: icon - type: Spillable + solution: drink - type: UserInterface interfaces: - key: enum.TransferAmountUiKey.Key diff --git a/Resources/Prototypes/Entities/Objects/Consumable/drinks_bottles.yml b/Resources/Prototypes/Entities/Objects/Consumable/drinks_bottles.yml index 662697f9ad..da9af2fb01 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/drinks_bottles.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/drinks_bottles.yml @@ -27,6 +27,7 @@ types: Blunt: 10 - type: Spillable + solution: drink - type: Damageable damageContainer: Inorganic - type: Destructible diff --git a/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml b/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml index 670e74b7f2..b6c4f89641 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml @@ -23,8 +23,8 @@ type: TransferAmountBoundUserInterface - type: Sprite state: icon - - type: Spillable + solution: drink - type: entity parent: DrinkCanBaseFull diff --git a/Resources/Prototypes/Entities/Objects/Consumable/drinks_cups.yml b/Resources/Prototypes/Entities/Objects/Consumable/drinks_cups.yml index 34f246e8c3..3b74483882 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/drinks_cups.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/drinks_cups.yml @@ -21,6 +21,7 @@ - type: Sprite state: icon - type: Spillable + solution: drink - type: entity parent: DrinkBaseCup diff --git a/Resources/Prototypes/Entities/Objects/Consumable/trash_drinks.yml b/Resources/Prototypes/Entities/Objects/Consumable/trash_drinks.yml index 5b9941c1cb..580264f84e 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/trash_drinks.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/trash_drinks.yml @@ -18,6 +18,7 @@ - type: Drink isOpen: true - type: Spillable + solution: drink - type: UserInterface interfaces: - key: enum.TransferAmountUiKey.Key diff --git a/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/sprays.yml b/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/sprays.yml index 84c8d1f4dd..5c13bf85a7 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/sprays.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/sprays.yml @@ -44,6 +44,7 @@ - type: DrainableSolution solution: spray - type: Spillable + solution: spray - type: ItemCooldown - type: Spray transferAmount: 1 diff --git a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/spray.yml b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/spray.yml index 53fa57e758..73f9a5bb93 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/spray.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/spray.yml @@ -24,6 +24,7 @@ solution: spray - type: SolutionTransfer - type: Spillable + solution: spray - type: ItemCooldown - type: Spray transferAmount: 10 diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml index 11314a3754..5090f8297c 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml @@ -34,6 +34,7 @@ - type: Item sprite: Objects/Specific/Chemistry/beaker.rsi - type: Spillable + solution: drink - type: entity name: bottle diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml index 5861c91861..dd9919a7af 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml @@ -36,6 +36,7 @@ - key: enum.TransferAmountUiKey.Key type: TransferAmountBoundUserInterface - type: Spillable + solution: beaker - type: Drink isOpen: true - type: Appearance @@ -167,6 +168,7 @@ - key: enum.TransferAmountUiKey.Key type: TransferAmountBoundUserInterface - type: Spillable + solution: dropper - type: Item sprite: Objects/Specific/Chemistry/dropper.rsi - type: Appearance @@ -200,6 +202,7 @@ - type: Injector injectOnly: false - type: Spillable + solution: injector - type: Appearance visuals: # this visualizer used for reagent inside diff --git a/Resources/Prototypes/Entities/Objects/Tools/bucket.yml b/Resources/Prototypes/Entities/Objects/Tools/bucket.yml index ba2aeea44d..f6558274d3 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/bucket.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/bucket.yml @@ -40,3 +40,4 @@ mask: - Impassable - type: Spillable + solution: bucket