2023-12-29 04:47:43 -08:00
|
|
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
using Content.Server.Fluids.Components;
|
2023-09-23 03:10:04 +01:00
|
|
|
|
using Content.Server.Nutrition.EntitySystems;
|
2023-04-10 18:56:21 -07:00
|
|
|
|
using Content.Shared.Chemistry.Components;
|
2023-10-14 09:45:28 -07:00
|
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2023-04-10 18:56:21 -07:00
|
|
|
|
using Content.Shared.Chemistry.Reaction;
|
|
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
using Content.Shared.Clothing.Components;
|
2023-12-11 15:40:22 -08:00
|
|
|
|
using Content.Shared.CombatMode.Pacification;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
using Content.Shared.Database;
|
|
|
|
|
|
using Content.Shared.DoAfter;
|
|
|
|
|
|
using Content.Shared.FixedPoint;
|
2024-03-03 00:36:36 -05:00
|
|
|
|
using Content.Shared.Fluids.Components;
|
2023-04-10 18:56:21 -07:00
|
|
|
|
using Content.Shared.IdentityManagement;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
using Content.Shared.Inventory.Events;
|
2023-04-10 18:56:21 -07:00
|
|
|
|
using Content.Shared.Popups;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
using Content.Shared.Spillable;
|
|
|
|
|
|
using Content.Shared.Throwing;
|
|
|
|
|
|
using Content.Shared.Verbs;
|
2023-04-10 18:56:21 -07:00
|
|
|
|
using Content.Shared.Weapons.Melee.Events;
|
|
|
|
|
|
using Robust.Shared.Player;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Fluids.EntitySystems;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed partial class PuddleSystem
|
|
|
|
|
|
{
|
2023-09-23 03:10:04 +01:00
|
|
|
|
[Dependency] private readonly OpenableSystem _openable = default!;
|
2023-12-21 23:23:01 +13:00
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
2023-09-23 03:10:04 +01:00
|
|
|
|
|
2024-03-03 00:36:36 -05:00
|
|
|
|
protected override void InitializeSpillable()
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
2024-03-03 00:36:36 -05:00
|
|
|
|
base.InitializeSpillable();
|
|
|
|
|
|
|
2023-04-10 15:37:03 +10:00
|
|
|
|
SubscribeLocalEvent<SpillableComponent, LandEvent>(SpillOnLand);
|
2024-03-03 00:36:36 -05:00
|
|
|
|
// Openable handles the event if it's closed
|
|
|
|
|
|
SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: [typeof(OpenableSystem)]);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
|
|
|
|
|
|
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
|
2023-12-29 04:47:43 -08:00
|
|
|
|
SubscribeLocalEvent<SpillableComponent, SolutionContainerOverflowEvent>(OnOverflow);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
SubscribeLocalEvent<SpillableComponent, SpillDoAfterEvent>(OnDoAfter);
|
2023-12-11 15:40:22 -08:00
|
|
|
|
SubscribeLocalEvent<SpillableComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
private void OnOverflow(Entity<SpillableComponent> entity, ref SolutionContainerOverflowEvent args)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
2023-10-28 09:46:59 -07:00
|
|
|
|
if (args.Handled)
|
|
|
|
|
|
return;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
TrySpillAt(Transform(entity).Coordinates, args.Overflow, out _);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
args.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
private void SplashOnMeleeHit(Entity<SpillableComponent> entity, ref MeleeHitEvent args)
|
2023-04-10 18:56:21 -07:00
|
|
|
|
{
|
2023-09-23 03:10:04 +01:00
|
|
|
|
if (args.Handled)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-04-10 18:56:21 -07:00
|
|
|
|
// When attacking someone reactive with a spillable entity,
|
|
|
|
|
|
// splash a little on them (touch react)
|
|
|
|
|
|
// If this also has solution transfer, then assume the transfer amount is how much we want to spill.
|
|
|
|
|
|
// Otherwise let's say they want to spill a quarter of its max volume.
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!_solutionContainerSystem.TryGetDrainableSolution(entity.Owner, out var soln, out var solution))
|
2023-04-10 18:56:21 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var hitCount = args.HitEntities.Count;
|
|
|
|
|
|
|
|
|
|
|
|
var totalSplit = FixedPoint2.Min(solution.MaxVolume * 0.25, solution.Volume);
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (TryComp<SolutionTransferComponent>(entity, out var transfer))
|
2023-04-10 18:56:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
totalSplit = FixedPoint2.Min(transfer.TransferAmount, solution.Volume);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// a little lame, but reagent quantity is not very balanced and we don't want people
|
|
|
|
|
|
// spilling like 100u of reagent on someone at once!
|
2023-12-29 04:47:43 -08:00
|
|
|
|
totalSplit = FixedPoint2.Min(totalSplit, entity.Comp.MaxMeleeSpillAmount);
|
2023-04-10 18:56:21 -07:00
|
|
|
|
|
2023-08-13 10:08:54 +03:00
|
|
|
|
if (totalSplit == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-09-23 03:10:04 +01:00
|
|
|
|
args.Handled = true;
|
2023-04-10 18:56:21 -07:00
|
|
|
|
foreach (var hit in args.HitEntities)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!HasComp<ReactiveComponent>(hit))
|
|
|
|
|
|
{
|
|
|
|
|
|
hitCount -= 1; // so we don't undershoot solution calculation for actual reactive entities
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var splitSolution = _solutionContainerSystem.SplitSolution(soln.Value, totalSplit / hitCount);
|
2023-04-10 18:56:21 -07:00
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
_adminLogger.Add(LogType.MeleeHit, $"{ToPrettyString(args.User)} splashed {SolutionContainerSystem.ToPrettyString(splitSolution):solution} from {ToPrettyString(entity.Owner):entity} onto {ToPrettyString(hit):target}");
|
2023-04-10 18:56:21 -07:00
|
|
|
|
_reactive.DoEntityReaction(hit, splitSolution, ReactionMethod.Touch);
|
|
|
|
|
|
|
|
|
|
|
|
_popups.PopupEntity(
|
2023-12-29 04:47:43 -08:00
|
|
|
|
Loc.GetString("spill-melee-hit-attacker", ("amount", totalSplit / hitCount), ("spillable", entity.Owner),
|
2023-04-10 18:56:21 -07:00
|
|
|
|
("target", Identity.Entity(hit, EntityManager))),
|
|
|
|
|
|
hit, args.User);
|
|
|
|
|
|
|
|
|
|
|
|
_popups.PopupEntity(
|
2023-12-29 04:47:43 -08:00
|
|
|
|
Loc.GetString("spill-melee-hit-others", ("attacker", args.User), ("spillable", entity.Owner),
|
2023-04-10 18:56:21 -07:00
|
|
|
|
("target", Identity.Entity(hit, EntityManager))),
|
|
|
|
|
|
hit, Filter.PvsExcept(args.User), true, PopupType.SmallCaution);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
private void OnGotEquipped(Entity<SpillableComponent> entity, ref GotEquippedEvent args)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!entity.Comp.SpillWorn)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!TryComp(entity, out ClothingComponent? clothing))
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// check if entity was actually used as clothing
|
|
|
|
|
|
// not just taken in pockets or something
|
|
|
|
|
|
var isCorrectSlot = clothing.Slots.HasFlag(args.SlotFlags);
|
|
|
|
|
|
if (!isCorrectSlot)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution))
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (solution.Volume == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// spill all solution on the player
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var drainedSolution = _solutionContainerSystem.Drain(entity.Owner, soln.Value, solution.Volume);
|
|
|
|
|
|
TrySplashSpillAt(entity.Owner, Transform(args.Equipee).Coordinates, drainedSolution, out _);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
private void SpillOnLand(Entity<SpillableComponent> entity, ref LandEvent args)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution))
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (_openable.IsClosed(entity.Owner))
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (args.User != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_adminLogger.Add(LogType.Landed,
|
2023-12-29 04:47:43 -08:00
|
|
|
|
$"{ToPrettyString(entity.Owner):entity} spilled a solution {SolutionContainerSystem.ToPrettyString(solution):solution} on landing");
|
2023-04-10 15:37:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var drainedSolution = _solutionContainerSystem.Drain(entity.Owner, soln.Value, solution.Volume);
|
|
|
|
|
|
TrySplashSpillAt(entity.Owner, Transform(entity).Coordinates, drainedSolution, out _);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-11 15:40:22 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Prevent Pacified entities from throwing items that can spill liquids.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnAttemptPacifiedThrow(Entity<SpillableComponent> ent, ref AttemptPacifiedThrowEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Don’t care about closed containers.
|
|
|
|
|
|
if (_openable.IsClosed(ent))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Don’t care about empty containers.
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(ent.Owner, ent.Comp.SolutionName, out _, out var solution) || solution.Volume <= 0)
|
2023-12-11 15:40:22 -08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
args.Cancel("pacified-cannot-throw-spill");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
private void AddSpillVerb(Entity<SpillableComponent> entity, ref GetVerbsEvent<Verb> args)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
|
|
|
|
|
if (!args.CanAccess || !args.CanInteract)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(args.Target, entity.Comp.SolutionName, out var soln, out var solution))
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
2023-09-23 03:10:04 +01:00
|
|
|
|
if (_openable.IsClosed(args.Target))
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (solution.Volume == FixedPoint2.Zero)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-12-21 23:23:01 +13:00
|
|
|
|
if (_entityManager.HasComponent<PreventSpillerComponent>(args.User))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-10 15:37:03 +10:00
|
|
|
|
Verb verb = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Loc.GetString("spill-target-verb-get-data-text")
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO VERB ICONS spill icon? pouring out a glass/beaker?
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (entity.Comp.SpillDelay == null)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var target = args.Target;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
verb.Act = () =>
|
|
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var puddleSolution = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
|
|
|
|
|
|
TrySpillAt(Transform(target).Coordinates, puddleSolution, out _);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var user = args.User;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
verb.Act = () =>
|
|
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, entity.Comp.SpillDelay ?? 0, new SpillDoAfterEvent(), entity.Owner, target: entity.Owner)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
|
|
|
|
|
BreakOnTargetMove = true,
|
|
|
|
|
|
BreakOnUserMove = true,
|
|
|
|
|
|
BreakOnDamage = true,
|
|
|
|
|
|
NeedHand = true,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
verb.Impact = LogImpact.Medium; // dangerous reagent reaction are logged separately.
|
|
|
|
|
|
verb.DoContactInteraction = true;
|
|
|
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
private void OnDoAfter(Entity<SpillableComponent> entity, ref SpillDoAfterEvent args)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
{
|
|
|
|
|
|
if (args.Handled || args.Cancelled || args.Args.Target == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
//solution gone by other means before doafter completes
|
2023-12-29 04:47:43 -08:00
|
|
|
|
if (!_solutionContainerSystem.TryGetDrainableSolution(entity.Owner, out var soln, out var solution) || solution.Volume == 0)
|
2023-04-10 15:37:03 +10:00
|
|
|
|
return;
|
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
|
var puddleSolution = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
|
|
|
|
|
|
TrySpillAt(Transform(entity).Coordinates, puddleSolution, out _);
|
2023-04-10 15:37:03 +10:00
|
|
|
|
args.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|