From 206d7c119eb1bfd0e6bf3c55c93786dc77b2852e Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Thu, 13 Jan 2022 17:22:19 +0300 Subject: [PATCH] Filled bucket will spill player when it is worn on their head (#6114) --- .../Fluids/Components/SpillableComponent.cs | 7 +++++ .../Fluids/EntitySystems/SpillableSystem.cs | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Content.Server/Fluids/Components/SpillableComponent.cs b/Content.Server/Fluids/Components/SpillableComponent.cs index 21c5e8a3a2..61fe1d4f5e 100644 --- a/Content.Server/Fluids/Components/SpillableComponent.cs +++ b/Content.Server/Fluids/Components/SpillableComponent.cs @@ -12,4 +12,11 @@ public class SpillableComponent : Component [DataField("solution")] public string SolutionName = "puddle"; + + /// + /// Should this item be spilled when worn as clothing? + /// Doesn't count for pockets or hands. + /// + [DataField("spillWorn")] + public bool SpillWorn = true; } diff --git a/Content.Server/Fluids/EntitySystems/SpillableSystem.cs b/Content.Server/Fluids/EntitySystems/SpillableSystem.cs index 1a99c6240e..d24716406c 100644 --- a/Content.Server/Fluids/EntitySystems/SpillableSystem.cs +++ b/Content.Server/Fluids/EntitySystems/SpillableSystem.cs @@ -2,12 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Server.Administration.Logs; using Content.Server.Chemistry.EntitySystems; +using Content.Server.Clothing.Components; using Content.Server.Coordinates.Helpers; using Content.Server.Fluids.Components; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.Database; using Content.Shared.FixedPoint; +using Content.Shared.Inventory.Events; using Content.Shared.Throwing; using Content.Shared.Verbs; using JetBrains.Annotations; @@ -35,6 +37,31 @@ public class SpillableSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(SpillOnLand); SubscribeLocalEvent(AddSpillVerb); + SubscribeLocalEvent(OnGotEquipped); + } + + private void OnGotEquipped(EntityUid uid, SpillableComponent component, GotEquippedEvent args) + { + if (!component.SpillWorn) + return; + + if (!TryComp(uid, out ClothingComponent? clothing)) + return; + + // check if entity was actually used as clothing + // not just taken in pockets or something + var isCorrectSlot = clothing.SlotFlags.HasFlag(args.SlotFlags); + if (!isCorrectSlot) return; + + if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution)) + return; + if (solution.TotalVolume == 0) + return; + + // spill all solution on the player + var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.DrainAvailable); + SpillAt(args.Equipee, drainedSolution, "PuddleSmear"); + } ///