Refactor AME to use ItemSlot for Fuel (#25558)
* Using wrench on AME doesn't first try to put it in. * Refactor AME to use ItemSlot for fuel. * Apparently these names want to match.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using Content.Shared.Ame;
|
||||
using Content.Shared.Ame.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Ame.UI
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.Ame;
|
||||
using Content.Shared.Ame.Components;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
@@ -21,7 +21,7 @@ using Content.Client.Singularity;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Client.Voting;
|
||||
using Content.Shared.Ame;
|
||||
using Content.Shared.Ame.Components;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Localizations;
|
||||
using Robust.Client;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Ame.EntitySystems;
|
||||
using Content.Shared.Ame;
|
||||
using Content.Shared.Ame.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Server.Ame.Components;
|
||||
@@ -15,15 +15,11 @@ namespace Content.Server.Ame.Components;
|
||||
public sealed partial class AmeControllerComponent : SharedAmeControllerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// The id of the container used to store the current fuel container for the AME.
|
||||
/// Antimatter fuel slot.
|
||||
/// </summary>
|
||||
public const string FuelContainerId = "AmeFuel";
|
||||
|
||||
/// <summary>
|
||||
/// The container for the fuel canisters used by the AME.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ContainerSlot JarSlot = default!;
|
||||
[DataField("fuelSlot")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ItemSlot FuelSlot = new();
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the AME controller is currently injecting animatter into the reactor.
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace Content.Server.Ame.Components;
|
||||
|
||||
/// <summary>
|
||||
/// An antimatter containment cell used to handle the fuel for the AME.
|
||||
/// TODO: network and put in shared
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class AmeFuelContainerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of fuel in the jar.
|
||||
/// </summary>
|
||||
[DataField("fuelAmount")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int FuelAmount = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum fuel capacity of the jar.
|
||||
/// </summary>
|
||||
[DataField("fuelCapacity")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int FuelCapacity = 1000;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Ame.EntitySystems;
|
||||
using Content.Shared.Ame;
|
||||
using Content.Server.Ame.EntitySystems;
|
||||
using Content.Shared.Ame.Components;
|
||||
|
||||
namespace Content.Server.Ame.Components;
|
||||
|
||||
|
||||
@@ -6,14 +6,10 @@ using Content.Server.Ame.Components;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.NodeContainer;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Ame;
|
||||
using Content.Shared.Ame.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
@@ -30,22 +26,29 @@ public sealed class AmeControllerSystem : EntitySystem
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly ContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<AmeControllerComponent, ComponentStartup>(OnComponentStartup);
|
||||
SubscribeLocalEvent<AmeControllerComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<AmeControllerComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<AmeControllerComponent, ComponentRemove>(OnRemove);
|
||||
SubscribeLocalEvent<AmeControllerComponent, EntInsertedIntoContainerMessage>(OnItemSlotChanged);
|
||||
SubscribeLocalEvent<AmeControllerComponent, EntRemovedFromContainerMessage>(OnItemSlotChanged);
|
||||
SubscribeLocalEvent<AmeControllerComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<AmeControllerComponent, UiButtonPressedMessage>(OnUiButtonPressed);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, AmeControllerComponent component, ComponentInit args)
|
||||
{
|
||||
_itemSlots.AddItemSlot(uid, SharedAmeControllerComponent.FuelSlotId, component.FuelSlot);
|
||||
|
||||
UpdateUi(uid, component);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var curTime = _gameTiming.CurTime;
|
||||
@@ -59,6 +62,22 @@ public sealed class AmeControllerSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, AmeControllerComponent component, ComponentRemove args)
|
||||
{
|
||||
_itemSlots.RemoveItemSlot(uid, component.FuelSlot);
|
||||
}
|
||||
|
||||
private void OnItemSlotChanged(EntityUid uid, AmeControllerComponent component, ContainerModifiedMessage args)
|
||||
{
|
||||
if (!component.Initialized)
|
||||
return;
|
||||
|
||||
if (args.Container.ID != component.FuelSlot.ID)
|
||||
return;
|
||||
|
||||
UpdateUi(uid, component);
|
||||
}
|
||||
|
||||
private void UpdateController(EntityUid uid, TimeSpan curTime, AmeControllerComponent? controller = null, NodeContainerComponent? nodes = null)
|
||||
{
|
||||
if (!Resolve(uid, ref controller))
|
||||
@@ -71,23 +90,24 @@ public sealed class AmeControllerSystem : EntitySystem
|
||||
|
||||
if (!controller.Injecting)
|
||||
return;
|
||||
|
||||
if (!TryGetAMENodeGroup(uid, out var group, nodes))
|
||||
return;
|
||||
|
||||
if (TryComp<AmeFuelContainerComponent>(controller.JarSlot.ContainedEntity, out var fuelJar))
|
||||
if (TryComp<AmeFuelContainerComponent>(controller.FuelSlot.Item, out var fuelContainer))
|
||||
{
|
||||
// if the jar is empty shut down the AME
|
||||
if (fuelJar.FuelAmount <= 0)
|
||||
if (fuelContainer.FuelAmount <= 0)
|
||||
{
|
||||
SetInjecting(uid, false, null, controller);
|
||||
}
|
||||
else
|
||||
{
|
||||
var availableInject = Math.Min(controller.InjectionAmount, fuelJar.FuelAmount);
|
||||
var availableInject = Math.Min(controller.InjectionAmount, fuelContainer.FuelAmount);
|
||||
var powerOutput = group.InjectFuel(availableInject, out var overloading);
|
||||
if (TryComp<PowerSupplierComponent>(uid, out var powerOutlet))
|
||||
powerOutlet.MaxSupply = powerOutput;
|
||||
fuelJar.FuelAmount -= availableInject;
|
||||
fuelContainer.FuelAmount -= availableInject;
|
||||
// only play audio if we actually had an injection
|
||||
if (availableInject > 0)
|
||||
_audioSystem.PlayPvs(controller.InjectSound, uid, AudioParams.Default.WithVolume(overloading ? 10f : 0f));
|
||||
@@ -138,11 +158,28 @@ public sealed class AmeControllerSystem : EntitySystem
|
||||
currentPowerSupply = powerOutlet.CurrentSupply / 1000;
|
||||
}
|
||||
|
||||
var hasJar = Exists(controller.JarSlot.ContainedEntity);
|
||||
if (!hasJar || !TryComp<AmeFuelContainerComponent>(controller.JarSlot.ContainedEntity, out var jar))
|
||||
return new AmeControllerBoundUserInterfaceState(powered, IsMasterController(uid), false, hasJar, 0, controller.InjectionAmount, coreCount, currentPowerSupply, targetedPowerSupply);
|
||||
var fuelContainerInSlot = controller.FuelSlot.Item;
|
||||
var hasFuelContainerInSlot = Exists(fuelContainerInSlot);
|
||||
if (!hasFuelContainerInSlot || !TryComp<AmeFuelContainerComponent>(fuelContainerInSlot, out var fuelContainer))
|
||||
return new AmeControllerBoundUserInterfaceState(powered,
|
||||
IsMasterController(uid),
|
||||
false,
|
||||
hasFuelContainerInSlot,
|
||||
0,
|
||||
controller.InjectionAmount,
|
||||
coreCount,
|
||||
currentPowerSupply,
|
||||
targetedPowerSupply);
|
||||
|
||||
return new AmeControllerBoundUserInterfaceState(powered, IsMasterController(uid), controller.Injecting, hasJar, jar.FuelAmount, controller.InjectionAmount, coreCount, currentPowerSupply, targetedPowerSupply);
|
||||
return new AmeControllerBoundUserInterfaceState(powered,
|
||||
IsMasterController(uid),
|
||||
controller.Injecting,
|
||||
hasFuelContainerInSlot,
|
||||
fuelContainer.FuelAmount,
|
||||
controller.InjectionAmount,
|
||||
coreCount,
|
||||
currentPowerSupply,
|
||||
targetedPowerSupply);
|
||||
}
|
||||
|
||||
private bool IsMasterController(EntityUid uid)
|
||||
@@ -170,23 +207,23 @@ public sealed class AmeControllerSystem : EntitySystem
|
||||
{
|
||||
if (!Resolve(uid, ref controller))
|
||||
return;
|
||||
|
||||
if (controller.Injecting)
|
||||
return;
|
||||
|
||||
var jar = controller.JarSlot.ContainedEntity;
|
||||
if (!Exists(jar))
|
||||
if (!Exists(controller.FuelSlot.Item))
|
||||
return;
|
||||
|
||||
_containerSystem.Remove(jar!.Value, controller.JarSlot);
|
||||
_itemSlots.TryEjectToHands(uid, controller.FuelSlot, user);
|
||||
|
||||
UpdateUi(uid, controller);
|
||||
if (Exists(user))
|
||||
_handsSystem.PickupOrDrop(user, jar!.Value);
|
||||
}
|
||||
|
||||
public void SetInjecting(EntityUid uid, bool value, EntityUid? user = null, AmeControllerComponent? controller = null)
|
||||
{
|
||||
if (!Resolve(uid, ref controller))
|
||||
return;
|
||||
|
||||
if (controller.Injecting == value)
|
||||
return;
|
||||
|
||||
@@ -278,38 +315,6 @@ public sealed class AmeControllerSystem : EntitySystem
|
||||
);
|
||||
}
|
||||
|
||||
private void OnComponentStartup(EntityUid uid, AmeControllerComponent comp, ComponentStartup args)
|
||||
{
|
||||
// TODO: Fix this bad name. I'd update maps but then people get mad.
|
||||
comp.JarSlot = _containerSystem.EnsureContainer<ContainerSlot>(uid, AmeControllerComponent.FuelContainerId);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, AmeControllerComponent comp, InteractUsingEvent args)
|
||||
{
|
||||
if (!HasComp<HandsComponent>(args.User))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-no-hands-text"), uid, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasComp<AmeFuelContainerComponent>(args.Used))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-fail"), uid, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Exists(comp.JarSlot.ContainedEntity))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-already-has-jar"), uid, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
_containerSystem.Insert(args.Used, comp.JarSlot);
|
||||
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-success"), uid, args.User, PopupType.Medium);
|
||||
|
||||
UpdateUi(uid, comp);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(EntityUid uid, AmeControllerComponent comp, ref PowerChangedEvent args)
|
||||
{
|
||||
UpdateUi(uid, comp);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Ame.Components;
|
||||
using Content.Shared.Ame;
|
||||
using Content.Shared.Ame.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Ame.EntitySystems;
|
||||
|
||||
19
Content.Shared/Ame/Components/AmeFuelContainerComponent.cs
Normal file
19
Content.Shared/Ame/Components/AmeFuelContainerComponent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Ame.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class AmeFuelContainerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of fuel in the container.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public int FuelAmount = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum fuel capacity of the container.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public int FuelCapacity = 1000;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Ame;
|
||||
namespace Content.Shared.Ame.Components;
|
||||
|
||||
[Virtual]
|
||||
public partial class SharedAmeControllerComponent : Component
|
||||
{
|
||||
public const string FuelSlotId = "fuelSlot";
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -1,6 +1,6 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Ame;
|
||||
namespace Content.Shared.Ame.Components;
|
||||
|
||||
[Virtual]
|
||||
public partial class SharedAmeShieldComponent : Component
|
||||
@@ -1,12 +1,12 @@
|
||||
using Content.Server.Ame.Components;
|
||||
using Content.Shared.Ame.Components;
|
||||
using Content.Shared.Examine;
|
||||
|
||||
namespace Content.Server.Ame.EntitySystems;
|
||||
namespace Content.Shared.Ame.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// Adds fuel level info to examine on fuel jars and handles network state.
|
||||
/// Adds details about fuel level when examining antimatter engine fuel containers.
|
||||
/// </summary>
|
||||
public sealed class AmeFuelSystem : EntitySystem
|
||||
public sealed class AmeFuelContainerSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -1,8 +1,4 @@
|
||||
ame-controller-component-interact-no-hands-text = You have no hands.
|
||||
ame-controller-component-interact-using-no-hands-text = You have no hands.
|
||||
ame-controller-component-interact-using-already-has-jar = The controller already has a jar loaded.
|
||||
ame-controller-component-interact-using-success = You insert the jar into the fuel slot.
|
||||
ame-controller-component-interact-using-fail = You can't put that in the controller...
|
||||
ame-controller-component-interact-using-whitelist-fail = You can't put that in the controller...
|
||||
|
||||
## UI
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@
|
||||
- type: Anchorable
|
||||
- type: Pullable
|
||||
- type: AmeController
|
||||
fuelSlot:
|
||||
whitelist:
|
||||
components:
|
||||
- AmeFuelContainer
|
||||
whitelistFailPopup: ame-controller-component-interact-using-whitelist-fail
|
||||
swap: false
|
||||
- type: Explosive
|
||||
explosionType: Default
|
||||
intensitySlope: 5
|
||||
@@ -86,9 +92,10 @@
|
||||
state: static
|
||||
- type: PowerSupplier
|
||||
supplyRate: 0
|
||||
- type: ItemSlots
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
AmeFuel: !type:ContainerSlot {}
|
||||
fuelSlot: !type:ContainerSlot
|
||||
- type: GuideHelp
|
||||
guides: [ AME, Power ]
|
||||
- type: Electrified
|
||||
|
||||
Reference in New Issue
Block a user