Add static "IsPowered" method (#8434)

* Add static "IsPowered" method

* Use IsPowered in more places

Co-authored-by: wrexbe <wrexbe@protonmail.com>
This commit is contained in:
metalgearsloth
2022-05-27 10:36:12 +10:00
committed by GitHub
parent 33c03fa0a0
commit 2d873a2cf2
20 changed files with 104 additions and 141 deletions

View File

@@ -1,20 +1,21 @@
using Robust.Shared.Audio;
using Robust.Shared.Player;
using System.Linq;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.VendingMachines;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.Destructible;
using Content.Shared.Emag.Systems;
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
using Content.Shared.Throwing;
using Content.Shared.VendingMachines;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
namespace Content.Server.VendingMachines.Systems
namespace Content.Server.VendingMachines
{
public sealed class VendingMachineSystem : EntitySystem
{
@@ -49,7 +50,7 @@ namespace Content.Server.VendingMachines.Systems
private void OnInventoryRequestMessage(EntityUid uid, VendingMachineComponent component, InventorySyncRequestMessage args)
{
if (!IsPowered(uid, component))
if (!this.IsPowered(uid, EntityManager))
return;
var inventory = new List<VendingMachineInventoryEntry>(component.Inventory);
@@ -62,7 +63,7 @@ namespace Content.Server.VendingMachines.Systems
private void OnInventoryEjectMessage(EntityUid uid, VendingMachineComponent component, VendingMachineEjectMessage args)
{
if (!IsPowered(uid, component))
if (!this.IsPowered(uid, EntityManager))
return;
if (args.Session.AttachedEntity is not { Valid: true } entity || Deleted(entity))
@@ -91,18 +92,6 @@ namespace Content.Server.VendingMachines.Systems
args.Handled = true;
}
public bool IsPowered(EntityUid uid, VendingMachineComponent? vendComponent = null)
{
if (!Resolve(uid, ref vendComponent))
return false;
if (!TryComp<ApcPowerReceiverComponent>(vendComponent.Owner, out var receiver))
{
return false;
}
return receiver.Powered;
}
public void InitializeFromPrototype(EntityUid uid, VendingMachineComponent? vendComponent = null)
{
if (!Resolve(uid, ref vendComponent))
@@ -201,7 +190,7 @@ namespace Content.Server.VendingMachines.Systems
if (!Resolve(uid, ref vendComponent))
return;
if (vendComponent.Ejecting || vendComponent.Broken || !IsPowered(uid, vendComponent))
if (vendComponent.Ejecting || vendComponent.Broken || !this.IsPowered(uid, EntityManager))
{
return;
}
@@ -276,7 +265,7 @@ namespace Content.Server.VendingMachines.Systems
{
finalState = VendingMachineVisualState.Eject;
}
else if (!IsPowered(uid, vendComponent))
else if (!this.IsPowered(uid, EntityManager))
{
finalState = VendingMachineVisualState.Off;
}