Fix & extend add reagent verb (#4954)
* AddReagentWindow * addReagent command * functional UI * fix networking * add comments & docstrings * Remove unecesary system * cleanup & close-eui * tweak default window size * fix EUI closing error * fix merge issues * fix merge
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Content.Server.Administration.Commands;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Administration.UI;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Configurable;
|
||||
using Content.Server.Disposal.Tube.Components;
|
||||
using Content.Server.EUI;
|
||||
@@ -12,14 +14,15 @@ using Content.Server.Inventory.Components;
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Verbs;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -39,9 +42,13 @@ namespace Content.Server.Administration
|
||||
[Dependency] private readonly EuiManager _euiManager = default!;
|
||||
[Dependency] private readonly GhostRoleSystem _ghostRoleSystem = default!;
|
||||
|
||||
private readonly Dictionary<IPlayerSession, EditSolutionsEui> _openSolutionUis = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<GetOtherVerbsEvent>(AddDebugVerbs);
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
SubscribeLocalEvent<SolutionContainerManagerComponent, SolutionChangedEvent>(OnSolutionChanged);
|
||||
}
|
||||
|
||||
private void AddDebugVerbs(GetOtherVerbsEvent args)
|
||||
@@ -186,24 +193,51 @@ namespace Content.Server.Administration
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
// Add reagent verb
|
||||
if (_adminManager.HasAdminFlag(player, AdminFlags.Fun) &&
|
||||
// Add verb to open Solution Editor
|
||||
if (_groupController.CanCommand(player, "addreagent") &&
|
||||
args.Target.HasComponent<SolutionContainerManagerComponent>())
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("admin-add-reagent-verb-get-data-text");
|
||||
verb.Text = Loc.GetString("edit-solutions-verb-get-data-text");
|
||||
verb.Category = VerbCategory.Debug;
|
||||
verb.IconTexture = "/Textures/Interface/VerbIcons/spill.svg.192dpi.png";
|
||||
verb.Act = () => _euiManager.OpenEui(new AdminAddReagentEui(args.Target), player);
|
||||
|
||||
// TODO CHEMISTRY
|
||||
// Add reagent ui broke after solution refactor. Needs fixing
|
||||
verb.Disabled = true;
|
||||
verb.Message = "Currently non functional after solution refactor.";
|
||||
verb.Priority = -2;
|
||||
|
||||
verb.Act = () => OpenEditSolutionsEui(player, args.Target.Uid);
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
|
||||
#region SolutionsEui
|
||||
private void OnSolutionChanged(EntityUid uid, SolutionContainerManagerComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
foreach (var eui in _openSolutionUis.Values)
|
||||
{
|
||||
if (eui.Target == uid)
|
||||
eui.StateDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenEditSolutionsEui(IPlayerSession session, EntityUid uid)
|
||||
{
|
||||
if (session.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
if (_openSolutionUis.ContainsKey(session))
|
||||
_openSolutionUis[session].Close();
|
||||
|
||||
var eui = _openSolutionUis[session] = new EditSolutionsEui(uid);
|
||||
_euiManager.OpenEui(eui, session);
|
||||
eui.StateDirty();
|
||||
}
|
||||
|
||||
public void OnEditSolutionsEuiClosed(IPlayerSession session)
|
||||
{
|
||||
_openSolutionUis.Remove(session, out var eui);
|
||||
}
|
||||
|
||||
private void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
_openSolutionUis.Clear();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
71
Content.Server/Administration/Commands/AddReagent.cs
Normal file
71
Content.Server/Administration/Commands/AddReagent.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Command that allows you to edit an existing solution by adding (or removing) reagents.
|
||||
/// </summary>
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public class AddReagent : IConsoleCommand
|
||||
{
|
||||
public string Command => "addreagent";
|
||||
public string Description => "Add (or remove) some amount of reagent from some solution.";
|
||||
public string Help => $"Usage: {Command} <target> <solution> <reagent> <quantity>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 4)
|
||||
{
|
||||
shell.WriteLine($"Not enough arguments.\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntityUid.TryParse(args[0], out var uid))
|
||||
{
|
||||
shell.WriteLine($"Invalid entity id.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(uid, out SolutionContainerManagerComponent man))
|
||||
{
|
||||
shell.WriteLine($"Entity does not have any solutions.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!man.Solutions.ContainsKey(args[1]))
|
||||
{
|
||||
var validSolutions = string.Join(", ", man.Solutions.Keys);
|
||||
shell.WriteLine($"Entity does not have a \"{args[1]}\" solution. Valid solutions are:\n{validSolutions}");
|
||||
return;
|
||||
}
|
||||
var solution = man.Solutions[args[1]];
|
||||
|
||||
if (!IoCManager.Resolve<IPrototypeManager>().HasIndex<ReagentPrototype>(args[2]))
|
||||
{
|
||||
shell.WriteLine($"Unknown reagent prototype");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!float.TryParse(args[3], out var quantityFloat))
|
||||
{
|
||||
shell.WriteLine($"Failed to parse quantity");
|
||||
return;
|
||||
}
|
||||
var quantity = FixedPoint2.New(MathF.Abs(quantityFloat));
|
||||
|
||||
if (quantityFloat > 0)
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddReagent(uid, solution, args[2], quantity, out var _);
|
||||
else
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryRemoveReagent(uid, solution, args[2], quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.UI
|
||||
{
|
||||
public sealed class AdminAddReagentEui : BaseEui
|
||||
{
|
||||
private readonly IEntity _target;
|
||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
||||
|
||||
public AdminAddReagentEui(IEntity target)
|
||||
{
|
||||
_target = target;
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
if (EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(_target.Uid, "default", out var container))
|
||||
{
|
||||
return new AdminAddReagentEuiState
|
||||
{
|
||||
CurVolume = container.CurrentVolume,
|
||||
MaxVolume = container.MaxVolume
|
||||
};
|
||||
}
|
||||
|
||||
return new AdminAddReagentEuiState
|
||||
{
|
||||
CurVolume = FixedPoint2.Zero,
|
||||
MaxVolume = FixedPoint2.Zero
|
||||
};
|
||||
}
|
||||
|
||||
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, AdminFlags.Fun) || _target.Deleted)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var id = doAdd.ReagentId;
|
||||
var amount = doAdd.Amount;
|
||||
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
|
||||
if (_target.TryGetComponent(out InjectableSolutionComponent? injectable)
|
||||
&& solutionsSys.TryGetSolution(_target.Uid, injectable.Name, out var targetSolution))
|
||||
{
|
||||
var solution = new Solution(id, amount);
|
||||
solutionsSys.Inject(_target.Uid, targetSolution, solution);
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO decide how to find the solution
|
||||
if (solutionsSys.TryGetSolution(_target.Uid, "default", out var solution))
|
||||
{
|
||||
solutionsSys.TryAddReagent(_target.Uid,solution, id, amount, out _);
|
||||
}
|
||||
}
|
||||
|
||||
StateDirty();
|
||||
|
||||
if (doAdd.CloseAfter)
|
||||
Close();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Content.Server/Administration/UI/EditSolutionsEui.cs
Normal file
54
Content.Server/Administration/UI/EditSolutionsEui.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Eui;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Admin Eui for displaying and editing the reagents in a solution.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed class EditSolutionsEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
public readonly EntityUid Target;
|
||||
|
||||
public EditSolutionsEui(EntityUid entity)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
Target = entity;
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public override void Closed()
|
||||
{
|
||||
base.Closed();
|
||||
EntitySystem.Get<AdminVerbSystem>().OnEditSolutionsEuiClosed(Player);
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
var solutions = _entityManager.GetComponentOrNull<SolutionContainerManagerComponent>(Target)?.Solutions;
|
||||
return new EditSolutionsEuiState(Target, solutions);
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case EditSolutionsEuiMsg.Close:
|
||||
Close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,6 @@ namespace Content.Server.Body.Metabolism
|
||||
IReadOnlyList<Solution.ReagentQuantity> reagentList = new List<Solution.ReagentQuantity>();
|
||||
Solution? solution = null;
|
||||
SharedBodyComponent? body = null;
|
||||
var solutionsSys = Get<SolutionContainerSystem>();
|
||||
|
||||
// if this field is passed we should try and take from the bloodstream over anything else
|
||||
if (owner.TryGetComponent<SharedMechanismComponent>(out var mech))
|
||||
@@ -64,7 +63,7 @@ namespace Content.Server.Body.Metabolism
|
||||
if (body != null)
|
||||
{
|
||||
if (body.Owner.HasComponent<BloodstreamComponent>()
|
||||
&& solutionsSys.TryGetSolution(body.Owner.Uid, comp.SolutionName, out solution)
|
||||
&& _solutionContainerSystem.TryGetSolution(body.OwnerUid, comp.SolutionName, out solution)
|
||||
&& solution.CurrentVolume >= FixedPoint2.Zero)
|
||||
{
|
||||
reagentList = solution.Contents;
|
||||
@@ -79,6 +78,7 @@ namespace Content.Server.Body.Metabolism
|
||||
}
|
||||
|
||||
List<Solution.ReagentQuantity> removeReagents = new(5);
|
||||
var ent = body?.Owner ?? owner;
|
||||
|
||||
// Run metabolism for each reagent, remove metabolized reagents
|
||||
foreach (var reagent in reagentList)
|
||||
@@ -90,7 +90,6 @@ namespace Content.Server.Body.Metabolism
|
||||
// Run metabolism code for each reagent
|
||||
foreach (var effect in metabolism.Effects)
|
||||
{
|
||||
var ent = body != null ? body.Owner : owner;
|
||||
var conditionsMet = true;
|
||||
if (effect.Conditions != null)
|
||||
{
|
||||
@@ -117,7 +116,7 @@ namespace Content.Server.Body.Metabolism
|
||||
removeReagents.Add(new Solution.ReagentQuantity(reagent.ReagentId, metabolism.MetabolismRate));
|
||||
}
|
||||
|
||||
solutionsSys.TryRemoveAllReagents(solution, removeReagents);
|
||||
_solutionContainerSystem.TryRemoveAllReagents(ent.Uid, solution, removeReagents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ namespace Content.Server.Botany.Components
|
||||
else
|
||||
{
|
||||
var one = FixedPoint2.New(1);
|
||||
foreach (var reagent in solutionSystem.RemoveEachReagent(solution, one))
|
||||
foreach (var reagent in solutionSystem.RemoveEachReagent(Owner.Uid, solution, one))
|
||||
{
|
||||
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent);
|
||||
reagentProto.ReactionPlant(Owner);
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return solutionsMgr.Solutions[name];
|
||||
}
|
||||
|
||||
public string[] RemoveEachReagent(Solution solution, FixedPoint2 quantity)
|
||||
public string[] RemoveEachReagent(EntityUid uid, Solution solution, FixedPoint2 quantity)
|
||||
{
|
||||
var removedReagent = new string[solution.Contents.Count];
|
||||
if (quantity <= 0)
|
||||
@@ -274,15 +274,21 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
UpdateChemicals(uid, solution);
|
||||
return removedReagent;
|
||||
}
|
||||
|
||||
public void TryRemoveAllReagents(Solution solution, List<Solution.ReagentQuantity> removeReagents)
|
||||
public void TryRemoveAllReagents(EntityUid uid, Solution solution, List<Solution.ReagentQuantity> removeReagents)
|
||||
{
|
||||
if (removeReagents.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var reagent in removeReagents)
|
||||
{
|
||||
solution.RemoveReagent(reagent.ReagentId, reagent.Quantity);
|
||||
}
|
||||
|
||||
UpdateChemicals(uid, solution);
|
||||
}
|
||||
|
||||
public FixedPoint2 GetReagentQuantity(EntityUid ownerUid, string reagentId)
|
||||
|
||||
Reference in New Issue
Block a user