Revert "Add limited-reagent dispensers (#23907)"
This reverts commit 9394a26245.
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Server.Labels.Components;
|
||||
using Content.Server.Chemistry;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.Dispenser;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Emag.Components;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -32,13 +28,10 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
[Dependency] private readonly AudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly SolutionTransferSystem _solutionTransferSystem = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly OpenableSystem _openable = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -48,12 +41,11 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntInsertedIntoContainerMessage>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, EntRemovedFromContainerMessage>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, GotEmaggedEvent>(OnEmagged);
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserSetDispenseAmountMessage>(OnSetDispenseAmountMessage);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserDispenseReagentMessage>(OnDispenseReagentMessage);
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserClearContainerSolutionMessage>(OnClearContainerSolutionMessage);
|
||||
|
||||
SubscribeLocalEvent<ReagentDispenserComponent, MapInitEvent>(OnMapInit, before: new []{typeof(ItemSlotsSystem)});
|
||||
}
|
||||
|
||||
private void SubscribeUpdateUiState<T>(Entity<ReagentDispenserComponent> ent, ref T ev)
|
||||
@@ -88,38 +80,35 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<KeyValuePair<string, KeyValuePair<string, string>>> GetInventory(ReagentDispenserComponent reagentDispenser)
|
||||
private List<ReagentId> GetInventory(Entity<ReagentDispenserComponent> ent)
|
||||
{
|
||||
var inventory = new List<KeyValuePair<string, KeyValuePair<string, string>>>();
|
||||
var reagentDispenser = ent.Comp;
|
||||
var inventory = new List<ReagentId>();
|
||||
|
||||
for (var i = 0; i < reagentDispenser.NumSlots; i++)
|
||||
if (reagentDispenser.PackPrototypeId is not null
|
||||
&& _prototypeManager.TryIndex(reagentDispenser.PackPrototypeId, out ReagentDispenserInventoryPrototype? packPrototype))
|
||||
{
|
||||
var storageSlotId = ReagentDispenserComponent.BaseStorageSlotId + i;
|
||||
var storedContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser.Owner, storageSlotId);
|
||||
inventory.AddRange(packPrototype.Inventory.Select(x => new ReagentId(x, null)));
|
||||
}
|
||||
|
||||
// Set label from manually-applied label, or metadata if unavailable
|
||||
string reagentLabel;
|
||||
if (TryComp<LabelComponent>(storedContainer, out var label) && !string.IsNullOrEmpty(label.CurrentLabel))
|
||||
reagentLabel = label.CurrentLabel;
|
||||
else if (storedContainer != null)
|
||||
reagentLabel = Name(storedContainer.Value);
|
||||
else
|
||||
continue;
|
||||
|
||||
// Add volume remaining label
|
||||
FixedPoint2 quantity = 0f;
|
||||
if (storedContainer != null && _solutionContainerSystem.TryGetDrainableSolution(storedContainer.Value, out _, out var sol))
|
||||
{
|
||||
quantity = sol.Volume;
|
||||
}
|
||||
var storedAmount = Loc.GetString("reagent-dispenser-window-quantity-label-text", ("quantity", quantity));
|
||||
|
||||
inventory.Add(new KeyValuePair<string, KeyValuePair<string, string>>(storageSlotId, new KeyValuePair<string, string>(reagentLabel, storedAmount)));
|
||||
if (HasComp<EmaggedComponent>(ent)
|
||||
&& reagentDispenser.EmagPackPrototypeId is not null
|
||||
&& _prototypeManager.TryIndex(reagentDispenser.EmagPackPrototypeId, out ReagentDispenserInventoryPrototype? emagPackPrototype))
|
||||
{
|
||||
inventory.AddRange(emagPackPrototype.Inventory.Select(x => new ReagentId(x, null)));
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
private void OnEmagged(Entity<ReagentDispenserComponent> reagentDispenser, ref GotEmaggedEvent args)
|
||||
{
|
||||
// adding component manually to have correct state
|
||||
EntityManager.AddComponent<EmaggedComponent>(reagentDispenser);
|
||||
UpdateUiState(reagentDispenser);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnSetDispenseAmountMessage(Entity<ReagentDispenserComponent> reagentDispenser, ref ReagentDispenserSetDispenseAmountMessage message)
|
||||
{
|
||||
reagentDispenser.Comp.DispenseAmount = message.ReagentDispenserDispenseAmount;
|
||||
@@ -130,23 +119,18 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
private void OnDispenseReagentMessage(Entity<ReagentDispenserComponent> reagentDispenser, ref ReagentDispenserDispenseReagentMessage message)
|
||||
{
|
||||
// Ensure that the reagent is something this reagent dispenser can dispense.
|
||||
var storedContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser, message.SlotId);
|
||||
if (storedContainer == null)
|
||||
if (!GetInventory(reagentDispenser).Contains(message.ReagentId))
|
||||
return;
|
||||
|
||||
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser, SharedReagentDispenser.OutputSlotName);
|
||||
if (outputContainer is not { Valid: true } || !_solutionContainerSystem.TryGetFitsInDispenser(outputContainer.Value, out var solution, out _))
|
||||
return;
|
||||
|
||||
if (_solutionContainerSystem.TryGetDrainableSolution(storedContainer.Value, out var src, out _) &&
|
||||
_solutionContainerSystem.TryGetRefillableSolution(outputContainer.Value, out var dst, out _))
|
||||
if (_solutionContainerSystem.TryAddReagent(solution.Value, message.ReagentId, (int) reagentDispenser.Comp.DispenseAmount, out var dispensedAmount)
|
||||
&& message.Session.AttachedEntity is not null)
|
||||
{
|
||||
// force open container, if applicable, to avoid confusing people on why it doesn't dispense
|
||||
_openable.SetOpen(storedContainer.Value, true);
|
||||
_solutionTransferSystem.Transfer(reagentDispenser,
|
||||
storedContainer.Value, src.Value,
|
||||
outputContainer.Value, dst.Value,
|
||||
(int)reagentDispenser.Comp.DispenseAmount);
|
||||
_adminLogger.Add(LogType.ChemicalReaction, LogImpact.Medium,
|
||||
$"{ToPrettyString(message.Session.AttachedEntity.Value):player} dispensed {dispensedAmount}u of {message.ReagentId} into {ToPrettyString(outputContainer.Value):entity}");
|
||||
}
|
||||
|
||||
UpdateUiState(reagentDispenser);
|
||||
@@ -168,41 +152,5 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
_audioSystem.PlayPvs(reagentDispenser.Comp.ClickSound, reagentDispenser, AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automatically generate storage slots for all NumSlots, and fill them with their initial chemicals.
|
||||
/// The actual spawning of entities happens in ItemSlotsSystem's MapInit.
|
||||
/// </summary>
|
||||
private void OnMapInit(EntityUid uid, ReagentDispenserComponent component, MapInitEvent args)
|
||||
{
|
||||
// Get list of pre-loaded containers
|
||||
List<string> preLoad = new List<string>();
|
||||
if (component.PackPrototypeId is not null
|
||||
&& _prototypeManager.TryIndex(component.PackPrototypeId, out ReagentDispenserInventoryPrototype? packPrototype))
|
||||
{
|
||||
preLoad.AddRange(packPrototype.Inventory);
|
||||
}
|
||||
|
||||
// Populate storage slots with base storage slot whitelist
|
||||
for (var i = 0; i < component.NumSlots; i++)
|
||||
{
|
||||
var storageSlotId = ReagentDispenserComponent.BaseStorageSlotId + i;
|
||||
ItemSlot storageComponent = new();
|
||||
storageComponent.Whitelist = component.StorageWhitelist;
|
||||
storageComponent.Swap = false;
|
||||
storageComponent.EjectOnBreak = true;
|
||||
|
||||
// Check corresponding index in pre-loaded container (if exists) and set starting item
|
||||
if (i < preLoad.Count)
|
||||
storageComponent.StartingItem = preLoad[i];
|
||||
|
||||
component.StorageSlotIds.Add(storageSlotId);
|
||||
component.StorageSlots.Add(storageComponent);
|
||||
component.StorageSlots[i].Name = "Storage Slot " + (i+1);
|
||||
_itemSlotsSystem.AddItemSlot(uid, component.StorageSlotIds[i], component.StorageSlots[i]);
|
||||
}
|
||||
|
||||
_itemSlotsSystem.AddItemSlot(uid, ReagentDispenserComponent.BeakerSlotId, component.BeakerSlot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user