Added power checks

Added power checks to:
Reagent Dispenser
Medical Scanner
Lathes
Research Console
Vending Machines

Added power device component to:
chem dispenser prototype
medical scanner prototype

Fixes for #706
This commit is contained in:
JiimBob
2020-03-21 15:37:22 -04:00
parent a1357a1ff3
commit d645b1470e
7 changed files with 64 additions and 29 deletions

View File

@@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.Components.Sound;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.Components.Power;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Server.Interfaces.GameObjects; using Content.Server.Interfaces.GameObjects;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
@@ -46,6 +47,11 @@ namespace Content.Server.GameObjects.Components.Chemistry
[ViewVariables] [ViewVariables]
private SolutionComponent Solution => _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>(); private SolutionComponent Solution => _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>();
///implementing PowerDeviceComponent
private PowerDeviceComponent _powerDevice;
private bool Powered => _powerDevice.Powered;
/// <summary> /// <summary>
/// Shows the serializer how to save/load this components yaml prototype. /// Shows the serializer how to save/load this components yaml prototype.
/// </summary> /// </summary>
@@ -70,6 +76,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
_beakerContainer = _beakerContainer =
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-reagentContainerContainer", Owner); ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-reagentContainerContainer", Owner);
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
InitializeFromPrototype(); InitializeFromPrototype();
UpdateUserInterface(); UpdateUserInterface();
@@ -159,6 +166,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
//Check if player can interact in their current state //Check if player can interact in their current state
if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity)) if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity))
return false; return false;
//Check if device is powered
if (!Powered)
return false;
return true; return true;
} }
@@ -251,6 +261,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
return; return;
} }
if (!Powered)
return;
var activeHandEntity = hands.GetActiveHand?.Owner; var activeHandEntity = hands.GetActiveHand?.Owner;
if (activeHandEntity == null) if (activeHandEntity == null)
{ {

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Medical; using Content.Shared.GameObjects.Components.Medical;
using Content.Server.GameObjects.Components.Power;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container; using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.Components.UserInterface;
@@ -24,6 +25,10 @@ namespace Content.Server.GameObjects.Components.Medical
private readonly Vector2 _ejectOffset = new Vector2(-0.5f, 0f); private readonly Vector2 _ejectOffset = new Vector2(-0.5f, 0f);
public bool IsOccupied => _bodyContainer.ContainedEntity != null; public bool IsOccupied => _bodyContainer.ContainedEntity != null;
///implementing PowerDeviceComponent
private PowerDeviceComponent _powerDevice;
private bool Powered => _powerDevice.Powered;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -31,6 +36,7 @@ namespace Content.Server.GameObjects.Components.Medical
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>() _userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
.GetBoundUserInterface(MedicalScannerUiKey.Key); .GetBoundUserInterface(MedicalScannerUiKey.Key);
_bodyContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-bodyContainer", Owner); _bodyContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-bodyContainer", Owner);
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
UpdateUserInterface(); UpdateUserInterface();
} }
@@ -79,6 +85,8 @@ namespace Content.Server.GameObjects.Components.Medical
private void UpdateUserInterface() private void UpdateUserInterface()
{ {
if (!Powered)
return;
var newState = GetUserInterfaceState(); var newState = GetUserInterfaceState();
_userInterface.SetState(newState); _userInterface.SetState(newState);
} }
@@ -112,6 +120,8 @@ namespace Content.Server.GameObjects.Components.Medical
{ {
return; return;
} }
if (!Powered)
return;
_userInterface.Open(actor.playerSession); _userInterface.Open(actor.playerSession);
} }

View File

@@ -62,38 +62,42 @@ namespace Content.Server.GameObjects.Components.Research
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message) private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)
{ {
switch (message.Message) if (!Powered)
{ return;
case LatheQueueRecipeMessage msg: switch (message.Message)
_prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe); {
if (recipe != null) case LatheQueueRecipeMessage msg:
for (var i = 0; i < msg.Quantity; i++) _prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe);
{ if (recipe != null)
Queue.Enqueue(recipe); for (var i = 0; i < msg.Quantity; i++)
_userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); {
} Queue.Enqueue(recipe);
break; _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue()));
case LatheSyncRequestMessage msg: }
if (!Owner.TryGetComponent(out MaterialStorageComponent storage)) return; break;
_userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); case LatheSyncRequestMessage msg:
if (_producingRecipe != null) if (!Owner.TryGetComponent(out MaterialStorageComponent storage)) return;
_userInterface.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID)); _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue()));
break; if (_producingRecipe != null)
_userInterface.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID));
break;
case LatheServerSelectionMessage msg: case LatheServerSelectionMessage msg:
if (!Owner.TryGetComponent(out ResearchClientComponent researchClient)) return; if (!Owner.TryGetComponent(out ResearchClientComponent researchClient)) return;
researchClient.OpenUserInterface(message.Session); researchClient.OpenUserInterface(message.Session);
break; break;
case LatheServerSyncMessage msg: case LatheServerSyncMessage msg:
if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database) if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)
|| !Owner.TryGetComponent(out ProtolatheDatabaseComponent protoDatabase)) return; || !Owner.TryGetComponent(out ProtolatheDatabaseComponent protoDatabase)) return;
if (database.SyncWithServer())
protoDatabase.Sync();
break;
}
if(database.SyncWithServer())
protoDatabase.Sync();
break;
}
} }
internal bool Produce(LatheRecipePrototype recipe) internal bool Produce(LatheRecipePrototype recipe)

View File

@@ -46,6 +46,8 @@ namespace Content.Server.GameObjects.Components.Research
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message) private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)
{ {
if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return; if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return;
if (!Powered)
return;
switch (message.Message) switch (message.Message)
{ {

View File

@@ -47,6 +47,8 @@ namespace Content.Server.GameObjects.Components.VendingMachines
{ {
return; return;
} }
if (!Powered)
return;
var wires = Owner.GetComponent<WiresComponent>(); var wires = Owner.GetComponent<WiresComponent>();
if (wires.IsPanelOpen) if (wires.IsPanelOpen)
@@ -121,6 +123,9 @@ namespace Content.Server.GameObjects.Components.VendingMachines
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg) private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
{ {
if (!Powered)
return;
var message = serverMsg.Message; var message = serverMsg.Message;
switch (message) switch (message)
{ {

View File

@@ -10,6 +10,7 @@
texture: Buildings/chemicals.rsi/industrial_dispenser.png texture: Buildings/chemicals.rsi/industrial_dispenser.png
- type: ReagentDispenser - type: ReagentDispenser
pack: ChemDispenserStandardInventory pack: ChemDispenserStandardInventory
- type: PowerDevice
- type: reagentDispenserInventory - type: reagentDispenserInventory
id: ChemDispenserStandardInventory id: ChemDispenserStandardInventory

View File

@@ -11,7 +11,7 @@
map: ["enum.MedicalScannerVisualLayers.Machine"] map: ["enum.MedicalScannerVisualLayers.Machine"]
- state: scanner_terminal_blue - state: scanner_terminal_blue
map: ["enum.MedicalScannerVisualLayers.Terminal"] map: ["enum.MedicalScannerVisualLayers.Terminal"]
- type: PowerDevice
- type: Icon - type: Icon
sprite: Buildings/medical_scanner.rsi sprite: Buildings/medical_scanner.rsi
state: scanner_open state: scanner_open