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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Access;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components.VendingMachines;
|
||||
@@ -16,6 +17,7 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Timers;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -146,7 +148,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
|
||||
switch (message)
|
||||
{
|
||||
case VendingMachineEjectMessage msg:
|
||||
TryEject(msg.ID);
|
||||
TryEject(msg.ID, serverMsg.Session.AttachedEntity);
|
||||
break;
|
||||
case InventorySyncRequestMessage _:
|
||||
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));
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
TrySetVisualState(VendingMachineVisualState.Deny);
|
||||
|
||||
@@ -68,6 +68,8 @@
|
||||
normalUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Bar"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -227,6 +229,8 @@
|
||||
ejectUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Kitchen"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -277,6 +281,8 @@
|
||||
denyUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Engineering"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -352,6 +358,8 @@
|
||||
denyUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Medical"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -403,6 +411,8 @@
|
||||
denyUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Hydroponics"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -428,6 +438,8 @@
|
||||
denyUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Research"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -479,6 +491,8 @@
|
||||
denyUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Security"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -505,6 +519,8 @@
|
||||
ejectUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Hydroponics"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
@@ -749,6 +765,8 @@
|
||||
denyUnshaded: true
|
||||
broken: true
|
||||
- type: WiresVisualizer
|
||||
- type: AccessReader
|
||||
access: [["Medical"]]
|
||||
|
||||
- type: entity
|
||||
parent: VendingMachine
|
||||
|
||||
Reference in New Issue
Block a user