From 4257e8e731569e578ccab33bca11a7dc81b86222 Mon Sep 17 00:00:00 2001 From: Mariner102 Date: Tue, 21 Dec 2021 19:52:59 -0700 Subject: [PATCH] Custom transfer amount to hydroponic trays (#5833) --- .../Botany/Components/PlantHolderComponent.cs | 23 ++++++++----------- .../RefillableSolutionComponent.cs | 11 ++++++++- .../Components/SolutionTransferComponent.cs | 21 +++++++++++++---- .../Prototypes/Entities/Structures/soil.yml | 1 + 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Content.Server/Botany/Components/PlantHolderComponent.cs b/Content.Server/Botany/Components/PlantHolderComponent.cs index 9c15a5e5ab..b0c2e0c0c8 100644 --- a/Content.Server/Botany/Components/PlantHolderComponent.cs +++ b/Content.Server/Botany/Components/PlantHolderComponent.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Content.Server.Atmos; using Content.Server.Atmos.EntitySystems; using Content.Server.Chemistry.EntitySystems; +using Content.Server.Chemistry.Components; using Content.Server.Fluids.Components; using Content.Server.Hands.Components; using Content.Server.Plants; @@ -727,23 +728,20 @@ namespace Content.Server.Botany.Components var solutionSystem = EntitySystem.Get(); if (solutionSystem.TryGetDrainableSolution(usingItem, out var solution) - && solutionSystem.TryGetSolution(Owner, SoilSolutionName, out var targetSolution)) + && solutionSystem.TryGetSolution(Owner, SoilSolutionName, out var targetSolution) && _entMan.TryGetComponent(usingItem, out SprayComponent? spray)) { - var amount = FixedPoint2.New(5); - var sprayed = false; + var amount = FixedPoint2.New(1); + var targetEntity = Owner; var solutionEntity = usingItem; - if (_entMan.TryGetComponent(usingItem, out SprayComponent? spray)) - { - sprayed = true; - amount = FixedPoint2.New(1); - - SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem, - AudioHelpers.WithVariation(0.125f)); - } + + SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem, + AudioHelpers.WithVariation(0.125f)); + var split = solutionSystem.Drain(solutionEntity, solution, amount); + if (split.TotalVolume == 0) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-message", @@ -751,8 +749,7 @@ namespace Content.Server.Botany.Components return true; } - user.PopupMessageCursor(Loc.GetString( - sprayed ? "plant-holder-component-spray-message" : "plant-holder-component-transfer-message", + user.PopupMessageCursor(Loc.GetString("plant-holder-component-spray-message", ("owner", Owner), ("amount", split.TotalVolume))); diff --git a/Content.Server/Chemistry/Components/SolutionManager/RefillableSolutionComponent.cs b/Content.Server/Chemistry/Components/SolutionManager/RefillableSolutionComponent.cs index 7465aef7ed..46c285c6c3 100644 --- a/Content.Server/Chemistry/Components/SolutionManager/RefillableSolutionComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionManager/RefillableSolutionComponent.cs @@ -1,6 +1,7 @@ -using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; +using Content.Shared.FixedPoint; namespace Content.Server.Chemistry.Components.SolutionManager { @@ -21,5 +22,13 @@ namespace Content.Server.Chemistry.Components.SolutionManager [DataField("solution")] public string Solution { get; set; } = "default"; + /// + /// The maximum amount that can be transferred to the solution at once + /// + [DataField("maxRefill")] + [ViewVariables(VVAccess.ReadWrite)] + public FixedPoint2? MaxRefill { get; set; } = null; + + } } diff --git a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs index 0bb22eb62e..e008f58f04 100644 --- a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs @@ -134,7 +134,14 @@ namespace Content.Server.Chemistry.Components && solutionsSys.TryGetRefillableSolution(Owner, out var ownerRefill) && solutionsSys.TryGetDrainableSolution(target, out var targetDrain)) { - var transferred = DoTransfer(eventArgs.User, target, targetDrain, Owner, ownerRefill, tank.TransferAmount); + var tankTransferAmount = tank.TransferAmount; + + if (_entities.TryGetComponent(Owner, out RefillableSolutionComponent? refill) && refill.MaxRefill != null) + { + tankTransferAmount = FixedPoint2.Min(tankTransferAmount, (FixedPoint2) refill.MaxRefill); + } + + var transferred = DoTransfer(eventArgs.User, target, targetDrain, Owner, ownerRefill, tankTransferAmount); if (transferred > 0) { var toTheBrim = ownerRefill.AvailableVolume == 0; @@ -151,7 +158,14 @@ namespace Content.Server.Chemistry.Components if (CanSend && solutionsSys.TryGetRefillableSolution(target, out var targetRefill) && solutionsSys.TryGetDrainableSolution(Owner, out var ownerDrain)) { - var transferred = DoTransfer(eventArgs.User, Owner, ownerDrain, target, targetRefill, TransferAmount); + var transferAmount = TransferAmount; + + if (_entities.TryGetComponent(target, out RefillableSolutionComponent? refill) && refill.MaxRefill != null) + { + transferAmount = FixedPoint2.Min(transferAmount, (FixedPoint2) refill.MaxRefill); + } + + var transferred = DoTransfer(eventArgs.User, Owner, ownerDrain, target, targetRefill, transferAmount); if (transferred > 0) { @@ -190,8 +204,7 @@ namespace Content.Server.Chemistry.Components return FixedPoint2.Zero; } - var actualAmount = - FixedPoint2.Min(amount, FixedPoint2.Min(source.DrainAvailable, target.AvailableVolume)); + var actualAmount = FixedPoint2.Min(amount, FixedPoint2.Min(source.DrainAvailable, target.AvailableVolume)); var solution = EntitySystem.Get().Drain(sourceEntity, source, actualAmount); EntitySystem.Get().Refill(targetEntity, target, solution); diff --git a/Resources/Prototypes/Entities/Structures/soil.yml b/Resources/Prototypes/Entities/Structures/soil.yml index 4c5a9e9ada..7cadbccac8 100644 --- a/Resources/Prototypes/Entities/Structures/soil.yml +++ b/Resources/Prototypes/Entities/Structures/soil.yml @@ -47,6 +47,7 @@ maxVol: 200 - type: RefillableSolution solution: soil + maxRefill: 50 - type: Transform anchored: true - type: Reactive