Add access restrictions to vending machines (#2471)
* Add vending machine access restrictions * oops * Handle null * Flick deny upon access denied Co-authored-by: zionnBE <zionn@tfwno.gf>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Server.GameObjects.Components.Access;
|
||||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||||
using Content.Server.Utility;
|
using Content.Server.Utility;
|
||||||
using Content.Shared.GameObjects.Components.VendingMachines;
|
using Content.Shared.GameObjects.Components.VendingMachines;
|
||||||
@@ -16,6 +17,7 @@ using Robust.Shared.Audio;
|
|||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components.Timers;
|
using Robust.Shared.GameObjects.Components.Timers;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Random;
|
using Robust.Shared.Interfaces.Random;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -146,7 +148,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
|
|||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case VendingMachineEjectMessage msg:
|
case VendingMachineEjectMessage msg:
|
||||||
TryEject(msg.ID);
|
TryEject(msg.ID, serverMsg.Session.AttachedEntity);
|
||||||
break;
|
break;
|
||||||
case InventorySyncRequestMessage _:
|
case InventorySyncRequestMessage _:
|
||||||
UserInterface?.SendMessage(new VendingMachineInventoryMessage(Inventory));
|
UserInterface?.SendMessage(new VendingMachineInventoryMessage(Inventory));
|
||||||
@@ -195,6 +197,19 @@ namespace Content.Server.GameObjects.Components.VendingMachines
|
|||||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(_soundVend, Owner, AudioParams.Default.WithVolume(-2f));
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_soundVend, Owner, AudioParams.Default.WithVolume(-2f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TryEject(string id, IEntity? sender)
|
||||||
|
{
|
||||||
|
if (Owner.TryGetComponent<AccessReader>(out var accessReader))
|
||||||
|
{
|
||||||
|
if (sender == null || !accessReader.IsAllowed(sender))
|
||||||
|
{
|
||||||
|
FlickDenyAnimation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TryEject(id);
|
||||||
|
}
|
||||||
|
|
||||||
private void FlickDenyAnimation()
|
private void FlickDenyAnimation()
|
||||||
{
|
{
|
||||||
TrySetVisualState(VendingMachineVisualState.Deny);
|
TrySetVisualState(VendingMachineVisualState.Deny);
|
||||||
|
|||||||
@@ -68,6 +68,8 @@
|
|||||||
normalUnshaded: true
|
normalUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Bar"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -227,6 +229,8 @@
|
|||||||
ejectUnshaded: true
|
ejectUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Kitchen"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -277,6 +281,8 @@
|
|||||||
denyUnshaded: true
|
denyUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Engineering"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -352,6 +358,8 @@
|
|||||||
denyUnshaded: true
|
denyUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Medical"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -403,6 +411,8 @@
|
|||||||
denyUnshaded: true
|
denyUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Hydroponics"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -428,6 +438,8 @@
|
|||||||
denyUnshaded: true
|
denyUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Research"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -479,6 +491,8 @@
|
|||||||
denyUnshaded: true
|
denyUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Security"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -505,6 +519,8 @@
|
|||||||
ejectUnshaded: true
|
ejectUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Hydroponics"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
@@ -749,6 +765,8 @@
|
|||||||
denyUnshaded: true
|
denyUnshaded: true
|
||||||
broken: true
|
broken: true
|
||||||
- type: WiresVisualizer
|
- type: WiresVisualizer
|
||||||
|
- type: AccessReader
|
||||||
|
access: [["Medical"]]
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: VendingMachine
|
parent: VendingMachine
|
||||||
|
|||||||
Reference in New Issue
Block a user