2021-06-21 02:13:54 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
|
|
|
|
using Content.Shared.Chemistry.Solution.Components;
|
|
|
|
|
using Content.Shared.DragDrop;
|
2021-06-19 10:03:24 +02:00
|
|
|
using Content.Shared.Interaction.Events;
|
2021-06-13 14:52:40 +02:00
|
|
|
using Content.Shared.Notification.Managers;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Verbs;
|
2020-09-09 18:32:31 -04:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Fluids.Components
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-02-18 21:43:46 +01:00
|
|
|
public class SpillableComponent : Component, IDropped
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
|
|
|
|
public override string Name => "Spillable";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Transfers solution from the held container to the floor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Verb]
|
|
|
|
|
private sealed class SpillTargetVerb : Verb<SpillableComponent>
|
|
|
|
|
{
|
|
|
|
|
protected override void GetData(IEntity user, SpillableComponent component, VerbData data)
|
|
|
|
|
{
|
2021-06-19 10:03:24 +02:00
|
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) ||
|
2021-03-16 15:50:20 +01:00
|
|
|
!component.Owner.TryGetComponent(out ISolutionInteractionsComponent? solutionComponent) ||
|
2021-02-03 14:05:31 +01:00
|
|
|
!solutionComponent.CanDrain)
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
|
|
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
data.Text = Loc.GetString("spill-target-verb-get-data-text");
|
2021-02-03 14:05:31 +01:00
|
|
|
data.Visibility = solutionComponent.DrainAvailable > ReagentUnit.Zero
|
|
|
|
|
? VerbVisibility.Visible
|
|
|
|
|
: VerbVisibility.Disabled;
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Activate(IEntity user, SpillableComponent component)
|
|
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
if (component.Owner.TryGetComponent<ISolutionInteractionsComponent>(out var solutionComponent))
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
if (!solutionComponent.CanDrain)
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
user.PopupMessage(user,
|
2021-06-21 02:13:54 +02:00
|
|
|
Loc.GetString("spill-target-verb-activate-cannot-drain-message",("owner", component.Owner)));
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-03 14:05:31 +01:00
|
|
|
if (solutionComponent.DrainAvailable <= 0)
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
user.PopupMessage(user, Loc.GetString("spill-target-verb-activate-is-empty-message",("owner", component.Owner)));
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Need this as when we split the component's owner may be deleted
|
2021-02-18 21:43:46 +01:00
|
|
|
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(component.Owner.Transform.Coordinates, "PuddleSmear");
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-18 21:43:46 +01:00
|
|
|
|
|
|
|
|
void IDropped.Dropped(DroppedEventArgs eventArgs)
|
|
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
if (!eventArgs.Intentional && Owner.TryGetComponent(out ISolutionInteractionsComponent? solutionComponent))
|
2021-02-18 21:43:46 +01:00
|
|
|
{
|
|
|
|
|
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
}
|