From d645b1470e483620e84bd4c332a870da52024687 Mon Sep 17 00:00:00 2001 From: JiimBob <44332255+JiimBob@users.noreply.github.com> Date: Sat, 21 Mar 2020 15:37:22 -0400 Subject: [PATCH 1/3] 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 --- .../Chemistry/ReagentDispenserComponent.cs | 13 ++++ .../Medical/MedicalScannerComponent.cs | 10 ++++ .../Components/Research/LatheComponent.cs | 60 ++++++++++--------- .../Research/ResearchConsoleComponent.cs | 2 + .../VendingMachineComponent.cs | 5 ++ .../Entities/buildings/chem_dispenser.yml | 1 + .../Entities/buildings/medical_scanner.yml | 2 +- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs index fa3a65e6c5..6fb12aa337 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs @@ -2,6 +2,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.GameObjects.Components.Power; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects; using Content.Shared.Chemistry; @@ -46,6 +47,11 @@ namespace Content.Server.GameObjects.Components.Chemistry [ViewVariables] private SolutionComponent Solution => _beakerContainer.ContainedEntity.GetComponent(); + ///implementing PowerDeviceComponent + private PowerDeviceComponent _powerDevice; + private bool Powered => _powerDevice.Powered; + + /// /// Shows the serializer how to save/load this components yaml prototype. /// @@ -70,6 +76,7 @@ namespace Content.Server.GameObjects.Components.Chemistry _beakerContainer = ContainerManagerComponent.Ensure($"{Name}-reagentContainerContainer", Owner); + _powerDevice = Owner.GetComponent(); InitializeFromPrototype(); UpdateUserInterface(); @@ -159,6 +166,9 @@ namespace Content.Server.GameObjects.Components.Chemistry //Check if player can interact in their current state if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity)) return false; + //Check if device is powered + if (!Powered) + return false; return true; } @@ -251,6 +261,9 @@ namespace Content.Server.GameObjects.Components.Chemistry return; } + if (!Powered) + return; + var activeHandEntity = hands.GetActiveHand?.Owner; if (activeHandEntity == null) { diff --git a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs index f27144bb0b..2ea653ff69 100644 --- a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Medical; +using Content.Server.GameObjects.Components.Power; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.Container; 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); public bool IsOccupied => _bodyContainer.ContainedEntity != null; + ///implementing PowerDeviceComponent + private PowerDeviceComponent _powerDevice; + private bool Powered => _powerDevice.Powered; + public override void Initialize() { base.Initialize(); @@ -31,6 +36,7 @@ namespace Content.Server.GameObjects.Components.Medical _userInterface = Owner.GetComponent() .GetBoundUserInterface(MedicalScannerUiKey.Key); _bodyContainer = ContainerManagerComponent.Ensure($"{Name}-bodyContainer", Owner); + _powerDevice = Owner.GetComponent(); UpdateUserInterface(); } @@ -79,6 +85,8 @@ namespace Content.Server.GameObjects.Components.Medical private void UpdateUserInterface() { + if (!Powered) + return; var newState = GetUserInterfaceState(); _userInterface.SetState(newState); } @@ -112,6 +120,8 @@ namespace Content.Server.GameObjects.Components.Medical { return; } + if (!Powered) + return; _userInterface.Open(actor.playerSession); } diff --git a/Content.Server/GameObjects/Components/Research/LatheComponent.cs b/Content.Server/GameObjects/Components/Research/LatheComponent.cs index f1020eb091..f06967b592 100644 --- a/Content.Server/GameObjects/Components/Research/LatheComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheComponent.cs @@ -62,38 +62,42 @@ namespace Content.Server.GameObjects.Components.Research private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message) { - switch (message.Message) - { - case LatheQueueRecipeMessage msg: - _prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe); - if (recipe != null) - for (var i = 0; i < msg.Quantity; i++) - { - Queue.Enqueue(recipe); - _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); - } - break; - case LatheSyncRequestMessage msg: - if (!Owner.TryGetComponent(out MaterialStorageComponent storage)) return; - _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); - if (_producingRecipe != null) - _userInterface.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID)); - break; + if (!Powered) + return; + switch (message.Message) + { + case LatheQueueRecipeMessage msg: + _prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe); + if (recipe != null) + for (var i = 0; i < msg.Quantity; i++) + { + Queue.Enqueue(recipe); + _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); + } + break; + case LatheSyncRequestMessage msg: + if (!Owner.TryGetComponent(out MaterialStorageComponent storage)) return; + _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); + if (_producingRecipe != null) + _userInterface.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID)); + break; - case LatheServerSelectionMessage msg: - if (!Owner.TryGetComponent(out ResearchClientComponent researchClient)) return; - researchClient.OpenUserInterface(message.Session); - break; + case LatheServerSelectionMessage msg: + if (!Owner.TryGetComponent(out ResearchClientComponent researchClient)) return; + researchClient.OpenUserInterface(message.Session); + break; - case LatheServerSyncMessage msg: - if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database) - || !Owner.TryGetComponent(out ProtolatheDatabaseComponent protoDatabase)) return; + case LatheServerSyncMessage msg: + if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database) + || !Owner.TryGetComponent(out ProtolatheDatabaseComponent protoDatabase)) return; - if(database.SyncWithServer()) - protoDatabase.Sync(); + if (database.SyncWithServer()) + protoDatabase.Sync(); + + break; + } + - break; - } } internal bool Produce(LatheRecipePrototype recipe) diff --git a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs index e3a2d4be72..9b10ad832a 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs @@ -46,6 +46,8 @@ namespace Content.Server.GameObjects.Components.Research private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message) { if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return; + if (!Powered) + return; switch (message.Message) { diff --git a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs index 2284d14596..1a9823d8ae 100644 --- a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs @@ -47,6 +47,8 @@ namespace Content.Server.GameObjects.Components.VendingMachines { return; } + if (!Powered) + return; var wires = Owner.GetComponent(); if (wires.IsPanelOpen) @@ -121,6 +123,9 @@ namespace Content.Server.GameObjects.Components.VendingMachines private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg) { + if (!Powered) + return; + var message = serverMsg.Message; switch (message) { diff --git a/Resources/Prototypes/Entities/buildings/chem_dispenser.yml b/Resources/Prototypes/Entities/buildings/chem_dispenser.yml index da79842a68..a72263b277 100644 --- a/Resources/Prototypes/Entities/buildings/chem_dispenser.yml +++ b/Resources/Prototypes/Entities/buildings/chem_dispenser.yml @@ -10,6 +10,7 @@ texture: Buildings/chemicals.rsi/industrial_dispenser.png - type: ReagentDispenser pack: ChemDispenserStandardInventory + - type: PowerDevice - type: reagentDispenserInventory id: ChemDispenserStandardInventory diff --git a/Resources/Prototypes/Entities/buildings/medical_scanner.yml b/Resources/Prototypes/Entities/buildings/medical_scanner.yml index c583a1a12a..9ad614ce7b 100644 --- a/Resources/Prototypes/Entities/buildings/medical_scanner.yml +++ b/Resources/Prototypes/Entities/buildings/medical_scanner.yml @@ -11,7 +11,7 @@ map: ["enum.MedicalScannerVisualLayers.Machine"] - state: scanner_terminal_blue map: ["enum.MedicalScannerVisualLayers.Terminal"] - + - type: PowerDevice - type: Icon sprite: Buildings/medical_scanner.rsi state: scanner_open From 5536ef2d2b7bdd1f34e39e4647db4d4dbc1af4a8 Mon Sep 17 00:00:00 2001 From: JiimBob <44332255+JiimBob@users.noreply.github.com> Date: Sun, 22 Mar 2020 19:34:38 -0400 Subject: [PATCH 2/3] Update CargoConsoleComponent.cs --- .../Components/Cargo/CargoConsoleComponent.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index b5e3fd4564..3b555c725f 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -1,6 +1,7 @@ using Content.Server.Cargo; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Cargo; +using Content.Server.GameObjects.Components.Power; using Content.Shared.Prototypes.Cargo; using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; @@ -40,6 +41,9 @@ namespace Content.Server.GameObjects.Components.Cargo private bool _requestOnly = false; + private PowerDeviceComponent _powerDevice; + private bool Powered => _powerDevice.Powered; + public override void Initialize() { base.Initialize(); @@ -47,6 +51,7 @@ namespace Content.Server.GameObjects.Components.Cargo Orders = Owner.GetComponent(); _userInterface = Owner.GetComponent().GetBoundUserInterface(CargoConsoleUiKey.Key); _userInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage; + _powerDevice = Owner.GetComponent(); _galacticBankManager.AddComponent(this); BankId = 0; } @@ -66,6 +71,8 @@ namespace Content.Server.GameObjects.Components.Cargo var message = serverMsg.Message; if (!Orders.ConnectedToDatabase) return; + if (!Powered) + return; switch (message) { case CargoConsoleAddOrderMessage msg: @@ -119,6 +126,8 @@ namespace Content.Server.GameObjects.Components.Cargo { return; } + if (!Powered) + return; _userInterface.Open(actor.playerSession); } From 006d0685ac6ddb0f1c101d2fde6133c6ee692588 Mon Sep 17 00:00:00 2001 From: JiimBob <44332255+JiimBob@users.noreply.github.com> Date: Wed, 25 Mar 2020 19:58:59 -0400 Subject: [PATCH 3/3] LatheComponent indentation fix Corrected indentation for the switch case. --- .../Components/Research/LatheComponent.cs | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/Content.Server/GameObjects/Components/Research/LatheComponent.cs b/Content.Server/GameObjects/Components/Research/LatheComponent.cs index f06967b592..b97cc3a7cb 100644 --- a/Content.Server/GameObjects/Components/Research/LatheComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheComponent.cs @@ -64,38 +64,39 @@ namespace Content.Server.GameObjects.Components.Research { if (!Powered) return; - switch (message.Message) - { - case LatheQueueRecipeMessage msg: - _prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe); - if (recipe != null) - for (var i = 0; i < msg.Quantity; i++) - { - Queue.Enqueue(recipe); - _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); - } - break; - case LatheSyncRequestMessage msg: - if (!Owner.TryGetComponent(out MaterialStorageComponent storage)) return; - _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); - if (_producingRecipe != null) - _userInterface.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID)); - break; - case LatheServerSelectionMessage msg: - if (!Owner.TryGetComponent(out ResearchClientComponent researchClient)) return; - researchClient.OpenUserInterface(message.Session); - break; + switch (message.Message) + { + case LatheQueueRecipeMessage msg: + _prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe); + if (recipe != null) + for (var i = 0; i < msg.Quantity; i++) + { + Queue.Enqueue(recipe); + _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); + } + break; + case LatheSyncRequestMessage msg: + if (!Owner.TryGetComponent(out MaterialStorageComponent storage)) return; + _userInterface.SendMessage(new LatheFullQueueMessage(GetIDQueue())); + if (_producingRecipe != null) + _userInterface.SendMessage(new LatheProducingRecipeMessage(_producingRecipe.ID)); + break; - case LatheServerSyncMessage msg: - if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database) - || !Owner.TryGetComponent(out ProtolatheDatabaseComponent protoDatabase)) return; + case LatheServerSelectionMessage msg: + if (!Owner.TryGetComponent(out ResearchClientComponent researchClient)) return; + researchClient.OpenUserInterface(message.Session); + break; - if (database.SyncWithServer()) - protoDatabase.Sync(); + case LatheServerSyncMessage msg: + if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database) + || !Owner.TryGetComponent(out ProtolatheDatabaseComponent protoDatabase)) return; - break; - } + if (database.SyncWithServer()) + protoDatabase.Sync(); + + break; + } }