Fix contraband never getting added to vend inventory (#32431)

* fix contraband never getting added to vend inventory

* Revert "fix contraband never getting added to vend inventory"

This reverts commit e7fb3a60c3cb6fcbf41d7f015f13dbc7b1c1901d.

* readd setter method to system

* fix again without reparenting
This commit is contained in:
goet
2024-09-25 07:21:24 +02:00
committed by GitHub
parent 52e85fe726
commit d1812c11fd
3 changed files with 23 additions and 1 deletions

View File

@@ -7,11 +7,20 @@ namespace Content.Server.VendingMachines;
[DataDefinition] [DataDefinition]
public sealed partial class VendingMachineContrabandWireAction : BaseToggleWireAction public sealed partial class VendingMachineContrabandWireAction : BaseToggleWireAction
{ {
private VendingMachineSystem _vendingMachineSystem = default!;
public override Color Color { get; set; } = Color.Green; public override Color Color { get; set; } = Color.Green;
public override string Name { get; set; } = "wire-name-vending-contraband"; public override string Name { get; set; } = "wire-name-vending-contraband";
public override object? StatusKey { get; } = ContrabandWireKey.StatusKey; public override object? StatusKey { get; } = ContrabandWireKey.StatusKey;
public override object? TimeoutKey { get; } = ContrabandWireKey.TimeoutKey; public override object? TimeoutKey { get; } = ContrabandWireKey.TimeoutKey;
public override void Initialize()
{
base.Initialize();
_vendingMachineSystem = EntityManager.System<VendingMachineSystem>();
}
public override StatusLightState? GetLightState(Wire wire) public override StatusLightState? GetLightState(Wire wire)
{ {
if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending)) if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent? vending))
@@ -28,7 +37,7 @@ public sealed partial class VendingMachineContrabandWireAction : BaseToggleWireA
{ {
if (EntityManager.TryGetComponent(owner, out VendingMachineComponent? vending)) if (EntityManager.TryGetComponent(owner, out VendingMachineComponent? vending))
{ {
vending.Contraband = !setting; _vendingMachineSystem.SetContraband(owner, !vending.Contraband, vending);
} }
} }

View File

@@ -192,6 +192,18 @@ namespace Content.Server.VendingMachines
component.CanShoot = canShoot; component.CanShoot = canShoot;
} }
/// <summary>
/// Sets the <see cref="VendingMachineComponent.Contraband"/> property of the vending machine.
/// </summary>
public void SetContraband(EntityUid uid, bool contraband, VendingMachineComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.Contraband = contraband;
Dirty(uid, component);
}
public void Deny(EntityUid uid, VendingMachineComponent? vendComponent = null) public void Deny(EntityUid uid, VendingMachineComponent? vendComponent = null)
{ {
if (!Resolve(uid, ref vendComponent)) if (!Resolve(uid, ref vendComponent))

View File

@@ -41,6 +41,7 @@ namespace Content.Shared.VendingMachines
[DataField, AutoNetworkedField] [DataField, AutoNetworkedField]
public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new(); public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new();
[DataField, AutoNetworkedField]
public bool Contraband; public bool Contraband;
public bool Ejecting; public bool Ejecting;