* Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
197 lines
7.4 KiB
C#
197 lines
7.4 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Content.Server.UserInterface;
|
|
using Content.Shared.Chemistry;
|
|
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Chemistry.Reagent;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Interaction.Helpers;
|
|
using Content.Shared.Popups;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.Chemistry.Components
|
|
{
|
|
/// <summary>
|
|
/// Gives click behavior for transferring to/from other reagent containers.
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public sealed class SolutionTransferComponent : Component, IAfterInteract
|
|
{
|
|
// Behavior is as such:
|
|
// If it's a reagent tank, TAKE reagent.
|
|
// If it's anything else, GIVE reagent.
|
|
// Of course, only if possible.
|
|
|
|
public override string Name => "SolutionTransfer";
|
|
|
|
/// <summary>
|
|
/// The amount of solution to be transferred from this solution when clicking on other solutions with it.
|
|
/// </summary>
|
|
[DataField("transferAmount")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5);
|
|
|
|
/// <summary>
|
|
/// The minimum amount of solution that can be transferred at once from this solution.
|
|
/// </summary>
|
|
[DataField("minTransferAmount")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public ReagentUnit MinimumTransferAmount { get; set; } = ReagentUnit.New(5);
|
|
|
|
/// <summary>
|
|
/// The maximum amount of solution that can be transferred at once from this solution.
|
|
/// </summary>
|
|
[DataField("maxTransferAmount")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public ReagentUnit MaximumTransferAmount { get; set; } = ReagentUnit.New(50);
|
|
|
|
/// <summary>
|
|
/// Can this entity take reagent from reagent tanks?
|
|
/// </summary>
|
|
[DataField("canReceive")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool CanReceive { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Can this entity give reagent to other reagent containers?
|
|
/// </summary>
|
|
[DataField("canSend")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool CanSend { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Whether you're allowed to change the transfer amount.
|
|
/// </summary>
|
|
[DataField("canChangeTransferAmount")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool CanChangeTransferAmount { get; set; } = false;
|
|
|
|
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(TransferAmountUiKey.Key);
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
if (UserInterface != null)
|
|
{
|
|
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
|
}
|
|
}
|
|
|
|
public void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
|
|
{
|
|
switch (serverMsg.Message)
|
|
{
|
|
case TransferAmountSetValueMessage svm:
|
|
var sval = svm.Value.Float();
|
|
var amount = Math.Clamp(sval, MinimumTransferAmount.Float(),
|
|
MaximumTransferAmount.Float());
|
|
|
|
serverMsg.Session.AttachedEntity?.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount",
|
|
("amount", amount)));
|
|
SetTransferAmount(ReagentUnit.New(amount));
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void SetTransferAmount(ReagentUnit amount)
|
|
{
|
|
amount = ReagentUnit.New(Math.Clamp(amount.Int(), MinimumTransferAmount.Int(),
|
|
MaximumTransferAmount.Int()));
|
|
TransferAmount = amount;
|
|
}
|
|
|
|
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
|
{
|
|
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
|
|
|
if (!eventArgs.InRangeUnobstructed() || eventArgs.Target == null)
|
|
return false;
|
|
|
|
if (!Owner.HasComponent<SolutionContainerManagerComponent>())
|
|
return false;
|
|
|
|
var target = eventArgs.Target!;
|
|
if (!target.HasComponent<SolutionContainerManagerComponent>())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
if (CanReceive && target.TryGetComponent(out ReagentTankComponent? tank)
|
|
&& solutionsSys.TryGetRefillableSolution(Owner.Uid, out var ownerRefill)
|
|
&& solutionsSys.TryGetDrainableSolution(eventArgs.Target.Uid, out var targetDrain))
|
|
{
|
|
var transferred = DoTransfer(eventArgs.User, eventArgs.Target, targetDrain, Owner, ownerRefill, tank.TransferAmount);
|
|
if (transferred > 0)
|
|
{
|
|
var toTheBrim = ownerRefill.AvailableVolume == 0;
|
|
var msg = toTheBrim
|
|
? "comp-solution-transfer-fill-fully"
|
|
: "comp-solution-transfer-fill-normal";
|
|
|
|
target.PopupMessage(eventArgs.User,
|
|
Loc.GetString(msg, ("owner", eventArgs.Target), ("amount", transferred), ("target", Owner)));
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (CanSend && solutionsSys.TryGetRefillableSolution(eventArgs.Target.Uid, out var targetRefill)
|
|
&& solutionsSys.TryGetDrainableSolution(Owner.Uid, out var ownerDrain))
|
|
{
|
|
var transferred = DoTransfer(eventArgs.User, Owner, ownerDrain, target, targetRefill, TransferAmount);
|
|
|
|
if (transferred > 0)
|
|
{
|
|
Owner.PopupMessage(eventArgs.User,
|
|
Loc.GetString("comp-solution-transfer-transfer-solution",
|
|
("amount", transferred),
|
|
("target", target)));
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <returns>The actual amount transferred.</returns>
|
|
private static ReagentUnit DoTransfer(IEntity user,
|
|
IEntity sourceEntity,
|
|
Solution source,
|
|
IEntity targetEntity,
|
|
Solution target,
|
|
ReagentUnit amount)
|
|
{
|
|
|
|
if (source.DrainAvailable == 0)
|
|
{
|
|
sourceEntity.PopupMessage(user,
|
|
Loc.GetString("comp-solution-transfer-is-empty", ("target", sourceEntity)));
|
|
return ReagentUnit.Zero;
|
|
}
|
|
|
|
if (target.AvailableVolume == 0)
|
|
{
|
|
targetEntity.PopupMessage(user,
|
|
Loc.GetString("comp-solution-transfer-is-full", ("target", targetEntity)));
|
|
return ReagentUnit.Zero;
|
|
}
|
|
|
|
var actualAmount =
|
|
ReagentUnit.Min(amount, ReagentUnit.Min(source.DrainAvailable, target.AvailableVolume));
|
|
|
|
var solution = EntitySystem.Get<SolutionContainerSystem>().Drain(sourceEntity.Uid, source, actualAmount);
|
|
EntitySystem.Get<SolutionContainerSystem>().Refill(targetEntity.Uid, target, solution);
|
|
|
|
return actualAmount;
|
|
}
|
|
}
|
|
}
|