Revert "Solution Entities" (#23160)
Revert "Solution Entities (#21916)"
This reverts commit d75e743dd7.
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
@@ -24,7 +24,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
/// <summary>
|
||||
/// Default transfer amounts for the set-transfer verb.
|
||||
/// </summary>
|
||||
public static readonly List<int> DefaultTransferAmounts = new() { 1, 5, 10, 25, 50, 100, 250, 500, 1000 };
|
||||
public static readonly List<int> DefaultTransferAmounts = new() { 1, 5, 10, 25, 50, 100, 250, 500, 1000};
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -35,19 +35,17 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
SubscribeLocalEvent<SolutionTransferComponent, TransferAmountSetValueMessage>(OnTransferAmountSetValueMessage);
|
||||
}
|
||||
|
||||
private void OnTransferAmountSetValueMessage(Entity<SolutionTransferComponent> entity, ref TransferAmountSetValueMessage message)
|
||||
private void OnTransferAmountSetValueMessage(EntityUid uid, SolutionTransferComponent solutionTransfer, TransferAmountSetValueMessage message)
|
||||
{
|
||||
var newTransferAmount = FixedPoint2.Clamp(message.Value, entity.Comp.MinimumTransferAmount, entity.Comp.MaximumTransferAmount);
|
||||
entity.Comp.TransferAmount = newTransferAmount;
|
||||
var newTransferAmount = FixedPoint2.Clamp(message.Value, solutionTransfer.MinimumTransferAmount, solutionTransfer.MaximumTransferAmount);
|
||||
solutionTransfer.TransferAmount = newTransferAmount;
|
||||
|
||||
if (message.Session.AttachedEntity is { Valid: true } user)
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", newTransferAmount)), entity.Owner, user);
|
||||
if (message.Session.AttachedEntity is {Valid: true} user)
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", newTransferAmount)), uid, user);
|
||||
}
|
||||
|
||||
private void AddSetTransferVerbs(Entity<SolutionTransferComponent> entity, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
private void AddSetTransferVerbs(EntityUid uid, SolutionTransferComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
var (uid, component) = entity;
|
||||
|
||||
if (!args.CanAccess || !args.CanInteract || !component.CanChangeTransferAmount || args.Hands == null)
|
||||
return;
|
||||
|
||||
@@ -58,16 +56,15 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
AlternativeVerb custom = new();
|
||||
custom.Text = Loc.GetString("comp-solution-transfer-verb-custom-amount");
|
||||
custom.Category = VerbCategory.SetTransferAmount;
|
||||
custom.Act = () => _userInterfaceSystem.TryOpen(uid, TransferAmountUiKey.Key, actor.PlayerSession);
|
||||
custom.Act = () => _userInterfaceSystem.TryOpen(args.Target, TransferAmountUiKey.Key, actor.PlayerSession);
|
||||
custom.Priority = 1;
|
||||
args.Verbs.Add(custom);
|
||||
|
||||
// Add specific transfer verbs according to the container's size
|
||||
var priority = 0;
|
||||
var user = args.User;
|
||||
foreach (var amount in DefaultTransferAmounts)
|
||||
{
|
||||
if (amount < component.MinimumTransferAmount.Int() || amount > component.MaximumTransferAmount.Int())
|
||||
if ( amount < component.MinimumTransferAmount.Int() || amount > component.MaximumTransferAmount.Int())
|
||||
continue;
|
||||
|
||||
AlternativeVerb verb = new();
|
||||
@@ -76,7 +73,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.TransferAmount = FixedPoint2.New(amount);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)), uid, user);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)), uid, args.User);
|
||||
};
|
||||
|
||||
// we want to sort by size, not alphabetically by the verb text.
|
||||
@@ -87,19 +84,18 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAfterInteract(Entity<SolutionTransferComponent> entity, ref AfterInteractEvent args)
|
||||
private void OnAfterInteract(EntityUid uid, SolutionTransferComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
var target = args.Target!.Value;
|
||||
var (uid, component) = entity;
|
||||
|
||||
//Special case for reagent tanks, because normally clicking another container will give solution, not take it.
|
||||
if (component.CanReceive && !EntityManager.HasComponent<RefillableSolutionComponent>(target) // target must not be refillable (e.g. Reagent Tanks)
|
||||
&& _solutionContainerSystem.TryGetDrainableSolution(target, out var targetSoln, out _) // target must be drainable
|
||||
&& EntityManager.TryGetComponent(uid, out RefillableSolutionComponent? refillComp)
|
||||
&& _solutionContainerSystem.TryGetRefillableSolution((uid, refillComp, null), out var ownerSoln, out var ownerRefill))
|
||||
if (component.CanReceive && !EntityManager.HasComponent<RefillableSolutionComponent>(target) // target must not be refillable (e.g. Reagent Tanks)
|
||||
&& _solutionContainerSystem.TryGetDrainableSolution(target, out var targetDrain) // target must be drainable
|
||||
&& EntityManager.TryGetComponent(uid, out RefillableSolutionComponent? refillComp)
|
||||
&& _solutionContainerSystem.TryGetRefillableSolution(uid, out var ownerRefill, refillable: refillComp))
|
||||
|
||||
{
|
||||
|
||||
@@ -110,7 +106,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill); // if the receiver has a smaller transfer limit, use that instead
|
||||
}
|
||||
|
||||
var transferred = Transfer(args.User, target, targetSoln.Value, uid, ownerSoln.Value, transferAmount);
|
||||
var transferred = Transfer(args.User, target, targetDrain, uid, ownerRefill, transferAmount);
|
||||
if (transferred > 0)
|
||||
{
|
||||
var toTheBrim = ownerRefill.AvailableVolume == 0;
|
||||
@@ -126,8 +122,8 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
|
||||
// if target is refillable, and owner is drainable
|
||||
if (component.CanSend && _solutionContainerSystem.TryGetRefillableSolution(target, out targetSoln, out var targetRefill)
|
||||
&& _solutionContainerSystem.TryGetDrainableSolution(uid, out ownerSoln, out var ownerDrain))
|
||||
if (component.CanSend && _solutionContainerSystem.TryGetRefillableSolution(target, out var targetRefill)
|
||||
&& _solutionContainerSystem.TryGetDrainableSolution(uid, out var ownerDrain))
|
||||
{
|
||||
var transferAmount = component.TransferAmount;
|
||||
|
||||
@@ -136,7 +132,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill);
|
||||
}
|
||||
|
||||
var transferred = Transfer(args.User, uid, ownerSoln.Value, target, targetSoln.Value, transferAmount);
|
||||
var transferred = Transfer(args.User, uid, ownerDrain, target, targetRefill, transferAmount);
|
||||
|
||||
if (transferred > 0)
|
||||
{
|
||||
@@ -154,9 +150,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
/// <returns>The actual amount transferred.</returns>
|
||||
public FixedPoint2 Transfer(EntityUid user,
|
||||
EntityUid sourceEntity,
|
||||
Entity<SolutionComponent> source,
|
||||
Solution source,
|
||||
EntityUid targetEntity,
|
||||
Entity<SolutionComponent> target,
|
||||
Solution target,
|
||||
FixedPoint2 amount)
|
||||
{
|
||||
var transferAttempt = new SolutionTransferAttemptEvent(sourceEntity, targetEntity);
|
||||
@@ -169,8 +165,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
var sourceSolution = source.Comp.Solution;
|
||||
if (sourceSolution.Volume == 0)
|
||||
if (source.Volume == 0)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-is-empty", ("target", sourceEntity)), sourceEntity, user);
|
||||
return FixedPoint2.Zero;
|
||||
@@ -184,20 +179,19 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
var targetSolution = target.Comp.Solution;
|
||||
if (targetSolution.AvailableVolume == 0)
|
||||
if (target.AvailableVolume == 0)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-solution-transfer-is-full", ("target", targetEntity)), targetEntity, user);
|
||||
return FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
var actualAmount = FixedPoint2.Min(amount, FixedPoint2.Min(sourceSolution.Volume, targetSolution.AvailableVolume));
|
||||
var actualAmount = FixedPoint2.Min(amount, FixedPoint2.Min(source.Volume, target.AvailableVolume));
|
||||
|
||||
var solution = _solutionContainerSystem.Drain(sourceEntity, source, actualAmount);
|
||||
_solutionContainerSystem.Refill(targetEntity, target, solution);
|
||||
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium,
|
||||
$"{EntityManager.ToPrettyString(user):player} transferred {string.Join(", ", solution.Contents)} to {EntityManager.ToPrettyString(targetEntity):entity}, which now contains {SolutionContainerSystem.ToPrettyString(targetSolution)}");
|
||||
$"{EntityManager.ToPrettyString(user):player} transferred {string.Join(", ", solution.Contents)} to {EntityManager.ToPrettyString(targetEntity):entity}, which now contains {string.Join(", ", target.Contents)}");
|
||||
|
||||
return actualAmount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user