A big hecking chemistry-related refactor. (#3055)
* A big hecking chemistry-related refactor. Changed SolutionContainerCaps. It now describes "stock" behavior for interacting with solutions that is pre-implemented by SolutionContainerComponent. As such things like syringes do not check it anymore (on themselves) to see "can we remove reagent from ourselves". That's assumed by it... being a syringe. SolutionContainerCaps now has different flags more accurately describing possible reagent interaction behaviors. ISolutionInteractionsComponent is the interface that describes the common behaviors like "what happens when injected with a syringe". This is implemented by SolutionContainerComponent but could be implemented by other classes. One notable example that drove me to making this interface was the /vg/station circuit imprinter which splits reagent poured in into its two reservoir beakers. Having this interface allows us to do this "proxying" behavior hack-free. (the hacks in /vg/ code were somewhat dirty...). PourableComponent has been replaced SolutionTransferComponent. It now describes both give-and-take behavior for the common reagent containers. This is in line with /vg/'s /obj/item/weapon/reagent_containers architecture. "Taking" in this context is ONLY from reagent tanks like fuel tanks. Oh, should I mention that fuel tanks and such have a proper component now? They do. Because of this behavioral change, reagent tanks DO NOT have Pourable anymore. Removing from reagent tanks is now in the hands of the item used on them. Welders and fire extinguishers now have code for removing from them. This sounds bad at first but remember that all have quite unique behavior related to this: Welders cause explosions if lit and can ONLY be fueled at fuel tanks. Extinguishers can be filled at any tank, etc... The code for this is also simpler due to ISolutionInteractionsComponent now so... IAfterInteract now works like IInteractUsing with the Priority levels and "return true to block further handlers" behavior. This was necessary to make extinguishers prioritize taking from tanks over spraying. Explicitly coded interactions like welders refueling also means they refuse instantly to full now, which they didn't before. And it plays the sound. Etc... Probably more stuff I'm forgetting. * Review improvements.
This commit is contained in:
committed by
GitHub
parent
b284c82668
commit
c40ac26ced
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Eui;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
@@ -19,213 +20,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedSolutionContainerComponent))]
|
||||
[ComponentReference(typeof(ISolutionInteractionsComponent))]
|
||||
public class SolutionContainerComponent : SharedSolutionContainerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Transfers solution from the held container to the target container.
|
||||
/// </summary>
|
||||
[Verb]
|
||||
private sealed class FillTargetVerb : Verb<SolutionContainerComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
hands.GetActiveHand == null ||
|
||||
hands.GetActiveHand.Owner == component.Owner ||
|
||||
!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var solution) ||
|
||||
!solution.CanRemoveSolutions ||
|
||||
!component.CanAddSolutions)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
||||
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
||||
|
||||
var locHeldEntityName = Loc.GetString(heldEntityName);
|
||||
var locMyName = Loc.GetString(myName);
|
||||
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locHeldEntityName, locMyName);
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
||||
{
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands) || hands.GetActiveHand == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var handSolutionComp) ||
|
||||
!handSolutionComp.CanRemoveSolutions ||
|
||||
!component.CanAddSolutions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferQuantity = ReagentUnit.Min(component.MaxVolume - component.CurrentVolume,
|
||||
handSolutionComp.CurrentVolume, ReagentUnit.New(10));
|
||||
|
||||
if (transferQuantity <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferSolution = handSolutionComp.SplitSolution(transferQuantity);
|
||||
component.TryAddSolution(transferSolution);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transfers solution from a target container to the held container.
|
||||
/// </summary>
|
||||
[Verb]
|
||||
private sealed class EmptyTargetVerb : Verb<SolutionContainerComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
hands.GetActiveHand == null ||
|
||||
hands.GetActiveHand.Owner == component.Owner ||
|
||||
!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var solution) ||
|
||||
!solution.CanAddSolutions ||
|
||||
!component.CanRemoveSolutions)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
||||
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
||||
|
||||
var locHeldEntityName = Loc.GetString(heldEntityName);
|
||||
var locMyName = Loc.GetString(myName);
|
||||
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locMyName, locHeldEntityName);
|
||||
return;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
||||
{
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands) || hands.GetActiveHand == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var handSolutionComp) ||
|
||||
!handSolutionComp.CanAddSolutions ||
|
||||
!component.CanRemoveSolutions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferQuantity = ReagentUnit.Min(handSolutionComp.MaxVolume - handSolutionComp.CurrentVolume,
|
||||
component.CurrentVolume, ReagentUnit.New(10));
|
||||
|
||||
if (transferQuantity <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferSolution = component.SplitSolution(transferQuantity);
|
||||
handSolutionComp.TryAddSolution(transferSolution);
|
||||
}
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class AdminAddReagentVerb : Verb<SolutionContainerComponent>
|
||||
{
|
||||
private const AdminFlags ReqFlags = AdminFlags.Fun;
|
||||
|
||||
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
||||
{
|
||||
data.Text = Loc.GetString("Add Reagent...");
|
||||
data.CategoryData = VerbCategories.Debug;
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
|
||||
var adminManager = IoCManager.Resolve<IAdminManager>();
|
||||
|
||||
if (user.TryGetComponent<IActorComponent>(out var player))
|
||||
{
|
||||
if (adminManager.HasAdminFlag(player.playerSession, ReqFlags))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
||||
{
|
||||
var groupController = IoCManager.Resolve<IAdminManager>();
|
||||
if (user.TryGetComponent<IActorComponent>(out var player))
|
||||
{
|
||||
if (groupController.HasAdminFlag(player.playerSession, ReqFlags))
|
||||
OpenAddReagentMenu(player.playerSession, component);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenAddReagentMenu(IPlayerSession player, SolutionContainerComponent comp)
|
||||
{
|
||||
var euiMgr = IoCManager.Resolve<EuiManager>();
|
||||
euiMgr.OpenEui(new AdminAddReagentEui(comp), player);
|
||||
}
|
||||
|
||||
private sealed class AdminAddReagentEui : BaseEui
|
||||
{
|
||||
private readonly SolutionContainerComponent _target;
|
||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
||||
|
||||
public AdminAddReagentEui(SolutionContainerComponent target)
|
||||
{
|
||||
_target = target;
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
return new AdminAddReagentEuiState
|
||||
{
|
||||
CurVolume = _target.CurrentVolume,
|
||||
MaxVolume = _target.MaxVolume
|
||||
};
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case AdminAddReagentEuiMsg.Close:
|
||||
Close();
|
||||
break;
|
||||
case AdminAddReagentEuiMsg.DoAdd doAdd:
|
||||
// Double check that user wasn't de-adminned in the mean time...
|
||||
// Or the target was deleted.
|
||||
if (!_adminManager.HasAdminFlag(Player, ReqFlags) || _target.Deleted)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
_target.TryAddReagent(doAdd.ReagentId, doAdd.Amount, out _);
|
||||
StateDirty();
|
||||
|
||||
if (doAdd.CloseAfter)
|
||||
Close();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user