Filled bucket will spill player when it is worn on their head (#6114)

This commit is contained in:
Alex Evgrashin
2022-01-13 17:22:19 +03:00
committed by GitHub
parent a95ddcbdd0
commit 206d7c119e
2 changed files with 34 additions and 0 deletions

View File

@@ -12,4 +12,11 @@ public class SpillableComponent : Component
[DataField("solution")]
public string SolutionName = "puddle";
/// <summary>
/// Should this item be spilled when worn as clothing?
/// Doesn't count for pockets or hands.
/// </summary>
[DataField("spillWorn")]
public bool SpillWorn = true;
}

View File

@@ -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<SpillableComponent, LandEvent>(SpillOnLand);
SubscribeLocalEvent<SpillableComponent, GetOtherVerbsEvent>(AddSpillVerb);
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(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");
}
/// <summary>