2021-06-21 02:13:54 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-07-31 03:14:00 +02:00
|
|
|
using Content.Shared.Interaction;
|
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-09-15 12:46:43 +02:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
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";
|
2021-09-15 12:46:43 +02:00
|
|
|
|
|
|
|
|
[DataField("solution")]
|
|
|
|
|
public string SolutionName = "puddle";
|
2020-09-09 18:32:31 -04:00
|
|
|
|
|
|
|
|
/// <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-09-06 15:49:44 +02:00
|
|
|
!EntitySystem.Get<SolutionContainerSystem>()
|
|
|
|
|
.TryGetDrainableSolution(component.Owner.Uid, out var solutionComponent))
|
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-09-06 15:49:44 +02:00
|
|
|
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
|
|
|
|
if (component.Owner.HasComponent<SolutionContainerManagerComponent>())
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
if (solutionsSys.TryGetDrainableSolution(component.Owner.Uid, out var solutionComponent))
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
if (solutionComponent.DrainAvailable <= 0)
|
|
|
|
|
{
|
|
|
|
|
user.PopupMessage(user,
|
|
|
|
|
Loc.GetString("spill-target-verb-activate-is-empty-message", ("owner", component.Owner)));
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
// Need this as when we split the component's owner may be deleted
|
|
|
|
|
EntitySystem.Get<SolutionContainerSystem>()
|
|
|
|
|
.Drain(component.Owner.Uid, solutionComponent, solutionComponent.DrainAvailable)
|
|
|
|
|
.SpillAt(component.Owner.Transform.Coordinates, "PuddleSmear");
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-09-09 18:32:31 -04:00
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
user.PopupMessage(user,
|
|
|
|
|
Loc.GetString("spill-target-verb-activate-cannot-drain-message",
|
|
|
|
|
("owner", component.Owner)));
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-18 21:43:46 +01:00
|
|
|
|
|
|
|
|
void IDropped.Dropped(DroppedEventArgs eventArgs)
|
|
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
if (!eventArgs.Intentional
|
|
|
|
|
&& EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solutionComponent))
|
2021-02-18 21:43:46 +01:00
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
EntitySystem.Get<SolutionContainerSystem>()
|
|
|
|
|
.Drain(Owner.Uid, solutionComponent, solutionComponent.DrainAvailable)
|
|
|
|
|
.SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
|
2021-02-18 21:43:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
}
|
|
|
|
|
}
|