Make chemistry machines and IdCardConsole use item slots (#5428)
* chemistry item slots * item slots id card console
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -21,26 +16,18 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Server.Access.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class IdCardConsoleComponent : SharedIdCardConsoleComponent, IInteractUsing, IBreakAct
|
||||
[ComponentReference(typeof(SharedIdCardConsoleComponent))]
|
||||
public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public ContainerSlot PrivilegedIdContainer = default!;
|
||||
public ContainerSlot TargetIdContainer = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key);
|
||||
[ViewVariables] private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
public bool PrivilegedIDEmpty => PrivilegedIdContainer.ContainedEntities.Count < 1;
|
||||
public bool TargetIDEmpty => TargetIdContainer.ContainedEntities.Count < 1;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
PrivilegedIdContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-privilegedId");
|
||||
TargetIdContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-targetId");
|
||||
|
||||
Owner.EnsureComponentWarn<AccessReader>();
|
||||
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
|
||||
|
||||
@@ -48,8 +35,6 @@ namespace Content.Server.Access.Components
|
||||
{
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
@@ -65,23 +50,22 @@ namespace Content.Server.Access.Components
|
||||
switch (msg.Button)
|
||||
{
|
||||
case UiButton.PrivilegedId:
|
||||
HandleId(obj.Session.AttachedEntity, PrivilegedIdContainer);
|
||||
HandleIdButton(obj.Session.AttachedEntity, PrivilegedIdSlot);
|
||||
break;
|
||||
case UiButton.TargetId:
|
||||
HandleId(obj.Session.AttachedEntity, TargetIdContainer);
|
||||
HandleIdButton(obj.Session.AttachedEntity, TargetIdSlot);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WriteToTargetIdMessage msg:
|
||||
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList);
|
||||
UpdateUserInterface();
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there is an ID in <see cref="PrivilegedIdContainer"/> and said ID satisfies the requirements of <see cref="AccessReader"/>.
|
||||
/// Returns true if there is an ID in <see cref="PrivilegedIdSlot"/> and said ID satisfies the requirements of <see cref="AccessReader"/>.
|
||||
/// </summary>
|
||||
private bool PrivilegedIdIsAuthorized()
|
||||
{
|
||||
@@ -90,23 +74,20 @@ namespace Content.Server.Access.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
var privilegedIdEntity = PrivilegedIdContainer.ContainedEntity;
|
||||
var privilegedIdEntity = PrivilegedIdSlot.Item;
|
||||
var accessSystem = EntitySystem.Get<AccessReaderSystem>();
|
||||
return privilegedIdEntity != null && accessSystem.IsAllowed(reader, privilegedIdEntity.Uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the "Submit" button in the UI gets pressed.
|
||||
/// Writes data passed from the UI into the ID stored in <see cref="TargetIdContainer"/>, if present.
|
||||
/// Writes data passed from the UI into the ID stored in <see cref="TargetIdSlot"/>, if present.
|
||||
/// </summary>
|
||||
private void TryWriteToTargetId(string newFullName, string newJobTitle, List<string> newAccessList)
|
||||
{
|
||||
if (!PrivilegedIdIsAuthorized() || TargetIdContainer.ContainedEntity == null)
|
||||
{
|
||||
var targetIdEntity = TargetIdSlot.Item;
|
||||
if (targetIdEntity == null || !PrivilegedIdIsAuthorized())
|
||||
return;
|
||||
}
|
||||
|
||||
var targetIdEntity = TargetIdContainer.ContainedEntity;
|
||||
|
||||
var cardSystem = EntitySystem.Get<IdCardSystem>();
|
||||
cardSystem.TryChangeFullName(targetIdEntity.Uid, newFullName);
|
||||
@@ -125,125 +106,46 @@ namespace Content.Server.Access.Components
|
||||
/// <summary>
|
||||
/// Called when one of the insert/remove ID buttons gets pressed.
|
||||
/// </summary>
|
||||
private void HandleId(IEntity user, ContainerSlot container)
|
||||
private void HandleIdButton(IEntity user, ItemSlot slot)
|
||||
{
|
||||
if (!user.TryGetComponent(out SharedHandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("access-id-card-console-component-no-hands-error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (container.ContainedEntity == null)
|
||||
{
|
||||
InsertIdFromHand(user, container, hands);
|
||||
}
|
||||
if (slot.HasItem)
|
||||
EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(OwnerUid, slot, user.Uid);
|
||||
else
|
||||
{
|
||||
PutIdInHand(container, hands);
|
||||
}
|
||||
EntitySystem.Get<ItemSlotsSystem>().TryInsertFromHand(OwnerUid, slot, user.Uid);
|
||||
}
|
||||
|
||||
public void InsertIdFromHand(IEntity user, ContainerSlot container, SharedHandsComponent hands)
|
||||
public void UpdateUserInterface()
|
||||
{
|
||||
if (!hands.TryGetActiveHeldEntity(out var heldEntity))
|
||||
return;
|
||||
|
||||
if (!heldEntity.HasComponent<IdCardComponent>())
|
||||
return;
|
||||
|
||||
if (!hands.TryPutHandIntoContainer(hands.ActiveHand!, container))
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("access-id-card-console-component-cannot-let-go-error"));
|
||||
return;
|
||||
}
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
public void PutIdInHand(ContainerSlot container, SharedHandsComponent hands)
|
||||
{
|
||||
var idEntity = container.ContainedEntity;
|
||||
if (idEntity == null || !container.Remove(idEntity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdateUserInterface();
|
||||
|
||||
hands.TryPutInActiveHandOrAny(idEntity);
|
||||
}
|
||||
|
||||
private void UpdateUserInterface()
|
||||
{
|
||||
var isPrivilegedIdPresent = PrivilegedIdContainer.ContainedEntity != null;
|
||||
var targetIdEntity = TargetIdContainer.ContainedEntity;
|
||||
var targetIdEntity = TargetIdSlot.Item;
|
||||
IdCardConsoleBoundUserInterfaceState newState;
|
||||
// this could be prettier
|
||||
if (targetIdEntity == null)
|
||||
{
|
||||
newState = new IdCardConsoleBoundUserInterfaceState(
|
||||
isPrivilegedIdPresent,
|
||||
PrivilegedIdSlot.HasItem,
|
||||
PrivilegedIdIsAuthorized(),
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
PrivilegedIdContainer.ContainedEntity?.Name ?? string.Empty,
|
||||
TargetIdContainer.ContainedEntity?.Name ?? string.Empty);
|
||||
PrivilegedIdSlot.Item?.Name ?? string.Empty,
|
||||
string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var targetIdComponent = targetIdEntity.GetComponent<IdCardComponent>();
|
||||
var targetAccessComponent = targetIdEntity.GetComponent<AccessComponent>();
|
||||
newState = new IdCardConsoleBoundUserInterfaceState(
|
||||
isPrivilegedIdPresent,
|
||||
PrivilegedIdSlot.HasItem,
|
||||
PrivilegedIdIsAuthorized(),
|
||||
true,
|
||||
targetIdComponent.FullName,
|
||||
targetIdComponent.JobTitle,
|
||||
targetAccessComponent.Tags.ToArray(),
|
||||
PrivilegedIdContainer.ContainedEntity?.Name ?? string.Empty,
|
||||
TargetIdContainer.ContainedEntity?.Name ?? string.Empty);
|
||||
PrivilegedIdSlot.Item?.Name ?? string.Empty,
|
||||
targetIdEntity.Name);
|
||||
}
|
||||
UserInterface?.SetState(newState);
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
var item = eventArgs.Using;
|
||||
var user = eventArgs.User;
|
||||
|
||||
if (!PrivilegedIDEmpty && !TargetIDEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!item.HasComponent<IdCardComponent>() || !user.TryGetComponent(out SharedHandsComponent? hand))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PrivilegedIDEmpty)
|
||||
{
|
||||
InsertIdFromHand(user, PrivilegedIdContainer, hand);
|
||||
}
|
||||
|
||||
else if (TargetIDEmpty)
|
||||
{
|
||||
InsertIdFromHand(user, TargetIdContainer, hand);
|
||||
}
|
||||
|
||||
UpdateUserInterface();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnBreak(BreakageEventArgs eventArgs)
|
||||
{
|
||||
var privileged = PrivilegedIdContainer.ContainedEntity;
|
||||
if (privileged != null)
|
||||
PrivilegedIdContainer.Remove(privileged);
|
||||
|
||||
var target = TargetIdContainer.ContainedEntity;
|
||||
if (target != null)
|
||||
TargetIdContainer.Remove(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Access
|
||||
{
|
||||
public class IdCardConsoleSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<IdCardConsoleComponent, GetInteractionVerbsEvent>(AddInsertVerbs);
|
||||
SubscribeLocalEvent<IdCardConsoleComponent, GetAlternativeVerbsEvent>(AddEjectVerbs);
|
||||
}
|
||||
|
||||
private void AddInsertVerbs(EntityUid uid, IdCardConsoleComponent component, GetInteractionVerbsEvent args)
|
||||
{
|
||||
if (args.Using == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
!args.Using.HasComponent<IdCardComponent>() ||
|
||||
!_actionBlockerSystem.CanDrop(args.User.Uid))
|
||||
return;
|
||||
|
||||
// Can we insert a privileged ID?
|
||||
if (component.PrivilegedIDEmpty)
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Act = () => component.InsertIdFromHand(args.User, component.PrivilegedIdContainer, args.Hands!);
|
||||
verb.Category = VerbCategory.Insert;
|
||||
verb.Text = Loc.GetString("id-card-console-privileged-id");
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
// Can we insert a target ID?
|
||||
if (component.TargetIDEmpty)
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Act = () => component.InsertIdFromHand(args.User, component.TargetIdContainer, args.Hands!);
|
||||
verb.Category = VerbCategory.Insert;
|
||||
verb.Text = Loc.GetString("id-card-console-target-id");
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddEjectVerbs(EntityUid uid, IdCardConsoleComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
!_actionBlockerSystem.CanPickup(args.User.Uid))
|
||||
return;
|
||||
|
||||
// Can we eject a privileged ID?
|
||||
if (!component.PrivilegedIDEmpty)
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Act = () => component.PutIdInHand(component.PrivilegedIdContainer, args.Hands);
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Text = Loc.GetString("id-card-console-privileged-id");
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
// Can we eject a target ID?
|
||||
if (!component.TargetIDEmpty)
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Act = () => component.PutIdInHand(component.TargetIdContainer, args.Hands);
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Text = Loc.GetString("id-card-console-target-id");
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Content.Server/Access/Systems/IdCardConsoleSystem.cs
Normal file
22
Content.Server/Access/Systems/IdCardConsoleSystem.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Shared.Access;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Access.Systems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// one day, maybe bound user interfaces can be shared too.
|
||||
SubscribeLocalEvent<IdCardConsoleComponent, ComponentStartup>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<IdCardConsoleComponent, EntInsertedIntoContainerMessage>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<IdCardConsoleComponent, EntRemovedFromContainerMessage>((_, comp, _) => comp.UpdateUserInterface());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
@@ -33,15 +34,9 @@ namespace Content.Server.Chemistry.Components
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IInteractUsing))]
|
||||
public class ChemMasterComponent : SharedChemMasterComponent, IActivate, IInteractUsing
|
||||
[ComponentReference(typeof(SharedChemMasterComponent))]
|
||||
public class ChemMasterComponent : SharedChemMasterComponent, IActivate
|
||||
{
|
||||
[ViewVariables]
|
||||
public ContainerSlot BeakerContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
public bool HasBeaker => BeakerContainer.ContainedEntity != null;
|
||||
|
||||
[ViewVariables]
|
||||
private bool _bufferModeTransfer = true;
|
||||
|
||||
@@ -73,13 +68,7 @@ namespace Content.Server.Chemistry.Components
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
// Name relied upon by construction graph machine.yml to ensure beaker doesn't get deleted
|
||||
BeakerContainer =
|
||||
ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-reagentContainerContainer");
|
||||
|
||||
_bufferSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner.Uid, SolutionName);
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
@@ -126,7 +115,7 @@ namespace Content.Server.Chemistry.Components
|
||||
switch (msg.action)
|
||||
{
|
||||
case UiAction.Eject:
|
||||
TryEject(obj.Session.AttachedEntity);
|
||||
EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(OwnerUid, BeakerSlot, obj.Session.AttachedEntityUid);
|
||||
break;
|
||||
case UiAction.ChemButton:
|
||||
TransferReagent(msg.id, msg.amount, msg.isBuffer);
|
||||
@@ -180,7 +169,7 @@ namespace Content.Server.Chemistry.Components
|
||||
/// <returns>Returns a <see cref="SharedChemMasterComponent.ChemMasterBoundUserInterfaceState"/></returns>
|
||||
private ChemMasterBoundUserInterfaceState GetUserInterfaceState()
|
||||
{
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
var beaker = BeakerSlot.Item;
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
{
|
||||
@@ -201,34 +190,10 @@ namespace Content.Server.Chemistry.Components
|
||||
UserInterface?.SetState(state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="Solution"/>, eject it.
|
||||
/// Tries to eject into user's hands first, then ejects onto chem master if both hands are full.
|
||||
/// </summary>
|
||||
public void TryEject(IEntity user)
|
||||
{
|
||||
if (!HasBeaker)
|
||||
return;
|
||||
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
|
||||
if (beaker is null)
|
||||
return;
|
||||
|
||||
BeakerContainer.Remove(beaker);
|
||||
UpdateUserInterface();
|
||||
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
!beaker.TryGetComponent<ItemComponent>(out var item))
|
||||
return;
|
||||
if (hands.CanPutInHand(item))
|
||||
hands.PutInHand(item);
|
||||
}
|
||||
|
||||
private void TransferReagent(string id, FixedPoint2 amount, bool isBuffer)
|
||||
{
|
||||
if (!HasBeaker && _bufferModeTransfer) return;
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
if (!BeakerSlot.HasItem && _bufferModeTransfer) return;
|
||||
var beaker = BeakerSlot.Item;
|
||||
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
@@ -390,61 +355,6 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when you click the owner entity with something in your active hand. If the entity in your hand
|
||||
/// contains a <see cref="Solution"/>, if you have hands, and if the chem master doesn't already
|
||||
/// hold a container, it will be added to the chem master.
|
||||
/// </summary>
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
/// <returns></returns>
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
|
||||
{
|
||||
if (!args.User.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("chem-master-component-interact-using-no-hands"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hands.GetActiveHand == null)
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("chem-master-component-interact-using-nothing-in-hands"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var activeHandEntity = hands.GetActiveHand.Owner;
|
||||
if (activeHandEntity.HasComponent<SolutionContainerManagerComponent>())
|
||||
{
|
||||
if (HasBeaker)
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("chem-master-component-has-beaker-already-message"));
|
||||
}
|
||||
else if (!activeHandEntity.HasComponent<FitsInDispenserComponent>())
|
||||
{
|
||||
//If it can't fit in the chem master, don't put it in. For example, buckets and mop buckets can't fit.
|
||||
Owner.PopupMessage(args.User,
|
||||
Loc.GetString("chem-master-component-container-too-large-message",
|
||||
("container", activeHandEntity)));
|
||||
}
|
||||
else
|
||||
{
|
||||
BeakerContainer.Insert(activeHandEntity);
|
||||
UpdateUserInterface();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(args.User,
|
||||
Loc.GetString("chem-master-component-cannot-put-entity-message", ("entity", activeHandEntity)));
|
||||
// TBD: This is very definitely hax so that Construction & Wires get a chance to handle things.
|
||||
// When this is ECS'd, drop this in favour of proper prioritization.
|
||||
// Since this is a catch-all handler, that means do this last!
|
||||
// Also note ReagentDispenserComponent did something similar before I got here.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ClickSound()
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _clickSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2f));
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Dispenser;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
@@ -18,7 +17,6 @@ using Content.Shared.Sound;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -38,21 +36,19 @@ namespace Content.Server.Chemistry.Components
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IInteractUsing))]
|
||||
public class ReagentDispenserComponent : SharedReagentDispenserComponent, IActivate, IInteractUsing
|
||||
[ComponentReference(typeof(SharedReagentDispenserComponent))]
|
||||
public class ReagentDispenserComponent : SharedReagentDispenserComponent, IActivate
|
||||
{
|
||||
private static ReagentInventoryComparer _comparer = new();
|
||||
public static string SolutionName = "reagent";
|
||||
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
[ViewVariables] public ContainerSlot BeakerContainer = default!;
|
||||
[ViewVariables] [DataField("pack")] private string _packPrototypeId = "";
|
||||
|
||||
[DataField("clickSound")]
|
||||
private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
||||
|
||||
[ViewVariables] public bool HasBeaker => BeakerContainer.ContainedEntity != null;
|
||||
[ViewVariables] private FixedPoint2 _dispenseAmount = FixedPoint2.New(10);
|
||||
|
||||
[UsedImplicitly]
|
||||
@@ -84,12 +80,7 @@ namespace Content.Server.Chemistry.Components
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
// Name relied upon by construction graph machine.yml to ensure beaker doesn't get deleted
|
||||
BeakerContainer =
|
||||
ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-reagentContainerContainer");
|
||||
|
||||
InitializeFromPrototype();
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
@@ -157,7 +148,7 @@ namespace Content.Server.Chemistry.Components
|
||||
switch (msg.Button)
|
||||
{
|
||||
case UiButton.Eject:
|
||||
TryEject(obj.Session.AttachedEntity);
|
||||
EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(OwnerUid, BeakerSlot, obj.Session.AttachedEntityUid);
|
||||
break;
|
||||
case UiButton.Clear:
|
||||
TryClear();
|
||||
@@ -190,7 +181,7 @@ namespace Content.Server.Chemistry.Components
|
||||
_dispenseAmount = FixedPoint2.New(100);
|
||||
break;
|
||||
case UiButton.Dispense:
|
||||
if (HasBeaker)
|
||||
if (BeakerSlot.HasItem)
|
||||
{
|
||||
TryDispense(msg.DispenseIndex);
|
||||
}
|
||||
@@ -233,7 +224,7 @@ namespace Content.Server.Chemistry.Components
|
||||
/// <returns>Returns a <see cref="SharedReagentDispenserComponent.ReagentDispenserBoundUserInterfaceState"/></returns>
|
||||
private ReagentDispenserBoundUserInterfaceState GetUserInterfaceState()
|
||||
{
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
var beaker = BeakerSlot.Item;
|
||||
if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var solution))
|
||||
{
|
||||
@@ -253,40 +244,19 @@ namespace Content.Server.Chemistry.Components
|
||||
UserInterface?.SetState(state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="SolutionHolder"/>, eject it.
|
||||
/// Tries to eject into user's hands first, then ejects onto dispenser if both hands are full.
|
||||
/// </summary>
|
||||
public void TryEject(IEntity user)
|
||||
{
|
||||
if (!HasBeaker)
|
||||
return;
|
||||
|
||||
var beaker = BeakerContainer.ContainedEntity;
|
||||
if (beaker is null)
|
||||
return;
|
||||
|
||||
BeakerContainer.Remove(beaker);
|
||||
UpdateUserInterface();
|
||||
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
!beaker.TryGetComponent<ItemComponent>(out var item))
|
||||
return;
|
||||
if (hands.CanPutInHand(item))
|
||||
hands.PutInHand(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="SolutionHolder"/>, remove all of it's reagents / solutions.
|
||||
/// </summary>
|
||||
private void TryClear()
|
||||
{
|
||||
if (!HasBeaker || !BeakerContainer.ContainedEntity!.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
var beaker = BeakerSlot.Item;
|
||||
|
||||
if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(BeakerContainer.ContainedEntity.Uid, fits.Solution, out var solution))
|
||||
.TryGetSolution(beaker.Uid, fits.Solution, out var solution))
|
||||
return;
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>().RemoveAllSolution(BeakerContainer.ContainedEntity!.Uid, solution);
|
||||
EntitySystem.Get<SolutionContainerSystem>().RemoveAllSolution(beaker.Uid, solution);
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
@@ -297,14 +267,14 @@ namespace Content.Server.Chemistry.Components
|
||||
/// <param name="dispenseIndex">The index of the reagent in <c>Inventory</c>.</param>
|
||||
private void TryDispense(int dispenseIndex)
|
||||
{
|
||||
if (!HasBeaker) return;
|
||||
var beaker = BeakerSlot.Item;
|
||||
|
||||
if (BeakerContainer.ContainedEntity is not {} contained || !contained.TryGetComponent(out FitsInDispenserComponent? fits)
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits)
|
||||
|| !EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(BeakerContainer.ContainedEntity.Uid, fits.Solution, out var solution)) return;
|
||||
.TryGetSolution(beaker.Uid, fits.Solution, out var solution)) return;
|
||||
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryAddReagent(BeakerContainer.ContainedEntity.Uid, solution, Inventory[dispenseIndex].ID, _dispenseAmount, out _);
|
||||
.TryAddReagent(beaker.Uid, solution, Inventory[dispenseIndex].ID, _dispenseAmount, out _);
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
@@ -333,51 +303,6 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when you click the owner entity with something in your active hand. If the entity in your hand
|
||||
/// contains a <see cref="SolutionHolder"/>, if you have hands, and if the dispenser doesn't already
|
||||
/// hold a container, it will be added to the dispenser.
|
||||
/// </summary>
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
/// <returns></returns>
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
|
||||
{
|
||||
if (!args.User.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("reagent-dispenser-component-interact-using-no-hands"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hands.GetActiveHand == null)
|
||||
{
|
||||
Owner.PopupMessage(args.User,
|
||||
Loc.GetString("reagent-dispenser-component-interact-using-nothing-in-hands"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var activeHandEntity = hands.GetActiveHand.Owner;
|
||||
if (activeHandEntity.HasComponent<FitsInDispenserComponent>())
|
||||
{
|
||||
if (HasBeaker)
|
||||
{
|
||||
Owner.PopupMessage(args.User,
|
||||
Loc.GetString("reagent-dispenser-component-has-container-already-message"));
|
||||
return false;
|
||||
}
|
||||
|
||||
BeakerContainer.Insert(activeHandEntity);
|
||||
UpdateUserInterface();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(args.User,
|
||||
Loc.GetString("reagent-dispenser-component-cannot-put-entity-message",
|
||||
("entity", activeHandEntity)));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ClickSound()
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _clickSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2f));
|
||||
|
||||
@@ -1,76 +1,21 @@
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Content.Shared.ActionBlocker;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ChemMasterSystem : EntitySystem
|
||||
public sealed class ChemMasterSystem : SharedChemMasterSystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ChemMasterComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<ChemMasterComponent, GetInteractionVerbsEvent>(AddInsertVerb);
|
||||
SubscribeLocalEvent<ChemMasterComponent, GetAlternativeVerbsEvent>(AddEjectVerb);
|
||||
}
|
||||
|
||||
// TODO VERBS EJECTABLES Standardize eject/insert verbs into a single system? Maybe using something like the
|
||||
// system mentioned in #4538? The code here is basically identical to the stuff in ChemDispenserSystem
|
||||
private void AddEjectVerb(EntityUid uid, ChemMasterComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
!component.HasBeaker ||
|
||||
!_actionBlockerSystem.CanPickup(args.User.Uid))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.TryEject(args.User);
|
||||
component.UpdateUserInterface();
|
||||
};
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Text = component.BeakerContainer.ContainedEntity!.Name;
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AddInsertVerb(EntityUid uid, ChemMasterComponent component, GetInteractionVerbsEvent args)
|
||||
{
|
||||
if (args.Using == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
component.HasBeaker ||
|
||||
!args.Using.HasComponent<FitsInDispenserComponent>() ||
|
||||
!_actionBlockerSystem.CanDrop(args.User.Uid))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.BeakerContainer.Insert(args.Using);
|
||||
component.UpdateUserInterface();
|
||||
};
|
||||
verb.Category = VerbCategory.Insert;
|
||||
verb.Text = args.Using.Name;
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, ChemMasterComponent component,
|
||||
SolutionChangedEvent solutionChanged)
|
||||
{
|
||||
component.UpdateUserInterface();
|
||||
SubscribeLocalEvent<ChemMasterComponent, ComponentStartup>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<ChemMasterComponent, SolutionChangedEvent>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<ChemMasterComponent, EntInsertedIntoContainerMessage>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<ChemMasterComponent, EntRemovedFromContainerMessage>((_, comp, _) => comp.UpdateUserInterface());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,21 @@
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Content.Shared.ActionBlocker;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ReagentDispenserSystem : EntitySystem
|
||||
public sealed class ReagentDispenserSystem : SharedReagentDispenserSystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, GetAlternativeVerbsEvent>(AddEjectVerb);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, GetInteractionVerbsEvent>(AddInsertVerb);
|
||||
}
|
||||
|
||||
// TODO VERBS EJECTABLES Standardize eject/insert verbs into a single system? Maybe using something like the
|
||||
// system mentioned in #4538? The code here is basically identical to the stuff in ChemDispenserSystem.
|
||||
private void AddEjectVerb(EntityUid uid, ReagentDispenserComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
!component.HasBeaker ||
|
||||
!_actionBlockerSystem.CanPickup(args.User.Uid))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.TryEject(args.User);
|
||||
component.UpdateUserInterface();
|
||||
};
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Text = component.BeakerContainer.ContainedEntity!.Name;
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AddInsertVerb(EntityUid uid, ReagentDispenserComponent component, GetInteractionVerbsEvent args)
|
||||
{
|
||||
if (args.Using == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
component.HasBeaker ||
|
||||
!args.Using.HasComponent<FitsInDispenserComponent>() ||
|
||||
!_actionBlockerSystem.CanDrop(args.User.Uid))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.BeakerContainer.Insert(args.Using);
|
||||
component.UpdateUserInterface();
|
||||
};
|
||||
verb.Category = VerbCategory.Insert;
|
||||
verb.Text = args.Using.Name;
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, ReagentDispenserComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
component.UpdateUserInterface();
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ComponentStartup>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, SolutionChangedEvent>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntInsertedIntoContainerMessage>((_, comp, _) => comp.UpdateUserInterface());
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntRemovedFromContainerMessage>((_, comp, _) => comp.UpdateUserInterface());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Server.Construction.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
|
||||
namespace Content.Server.Containers
|
||||
{
|
||||
@@ -18,6 +17,17 @@ namespace Content.Server.Containers
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EmptyOnMachineDeconstructComponent, MachineDeconstructedEvent>(OnDeconstruct);
|
||||
SubscribeLocalEvent<ItemSlotsComponent, MachineDeconstructedEvent>(OnSlotsDeconstruct);
|
||||
}
|
||||
|
||||
// really this should be handled by ItemSlotsSystem, but for whatever reason MachineDeconstructedEvent is server-side? So eh.
|
||||
private void OnSlotsDeconstruct(EntityUid uid, ItemSlotsComponent component, MachineDeconstructedEvent args)
|
||||
{
|
||||
foreach (var slot in component.Slots.Values)
|
||||
{
|
||||
if (slot.EjectOnDeconstruct && slot.Item != null)
|
||||
slot.ContainerSlot.Remove(slot.Item);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDeconstruct(EntityUid uid, EmptyOnMachineDeconstructComponent component, MachineDeconstructedEvent ev)
|
||||
|
||||
Reference in New Issue
Block a user