From d20e4969e2d7075abb7fe854356ace90579e2505 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Wed, 8 Jul 2020 13:41:32 +0200 Subject: [PATCH] Add light to lit welders (#1282) * Add light to lit welders * Fix null errors * Make the welder light orange --- .../Interactable/WelderComponent.cs | 33 ++++++++++++------- Resources/Prototypes/Entities/Items/tools.yml | 5 ++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs index 8be75e5e18..26d1498946 100644 --- a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using System.Runtime.Remoting; using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.EntitySystems.Click; @@ -27,8 +28,8 @@ namespace Content.Server.GameObjects.Components.Interactable public class WelderComponent : ToolComponent, IExamine, IUse, ISuicideAct, ISolutionChange { #pragma warning disable 649 - [Dependency] private IEntitySystemManager _entitySystemManager; - [Dependency] private IServerNotifyManager _notifyManager; + [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; + [Dependency] private readonly IServerNotifyManager _notifyManager = default!; #pragma warning restore 649 public override string Name => "Welder"; @@ -44,10 +45,11 @@ namespace Content.Server.GameObjects.Components.Interactable /// public const float FuelLossRate = 0.5f; - private bool _welderLit = false; - private WelderSystem _welderSystem; - private SpriteComponent _spriteComponent; - private SolutionComponent _solutionComponent; + private bool _welderLit; + private WelderSystem _welderSystem = default!; + private SpriteComponent? _spriteComponent; + private SolutionComponent? _solutionComponent; + private PointLightComponent? _pointLightComponent; [ViewVariables] public float Fuel => _solutionComponent?.Solution.GetReagentQuantity("chem.WeldingFuel").Float() ?? 0f; @@ -79,6 +81,7 @@ namespace Content.Server.GameObjects.Components.Interactable Owner.TryGetComponent(out _solutionComponent); Owner.TryGetComponent(out _spriteComponent); + Owner.TryGetComponent(out _pointLightComponent); } public override ComponentState GetComponentState() @@ -98,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Interactable return base.UseTool(user, target, toolQualityNeeded) && TryWeld(fuelConsumed, user); } - private bool TryWeld(float value, IEntity user = null, bool silent = false) + private bool TryWeld(float value, IEntity? user = null, bool silent = false) { if (!WelderLit) { @@ -131,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Interactable /// /// Deactivates welding tool if active, activates welding tool if possible /// - private bool ToggleWelderStatus(IEntity user = null) + private bool ToggleWelderStatus(IEntity? user = null) { var item = Owner.GetComponent(); @@ -140,7 +143,10 @@ namespace Content.Server.GameObjects.Components.Interactable WelderLit = false; // Layer 1 is the flame. item.EquippedPrefix = "off"; - _spriteComponent.LayerSetVisible(1, false); + _spriteComponent?.LayerSetVisible(1, false); + + if (_pointLightComponent != null) _pointLightComponent.Enabled = false; + PlaySoundCollection("WelderOff", -5); _welderSystem.Unsubscribe(this); return true; @@ -154,7 +160,10 @@ namespace Content.Server.GameObjects.Components.Interactable WelderLit = true; item.EquippedPrefix = "on"; - _spriteComponent.LayerSetVisible(1, true); + _spriteComponent?.LayerSetVisible(1, true); + + if (_pointLightComponent != null) _pointLightComponent.Enabled = true; + PlaySoundCollection("WelderOn", -5); _welderSystem.Subscribe(this); return true; @@ -188,7 +197,7 @@ namespace Content.Server.GameObjects.Components.Interactable if (!HasQuality(ToolQuality.Welding) || !WelderLit) return; - _solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime)); + _solutionComponent?.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime)); if (Fuel == 0) ToggleWelderStatus(); diff --git a/Resources/Prototypes/Entities/Items/tools.yml b/Resources/Prototypes/Entities/Items/tools.yml index 12ff44c951..b7be1f5173 100644 --- a/Resources/Prototypes/Entities/Items/tools.yml +++ b/Resources/Prototypes/Entities/Items/tools.yml @@ -96,9 +96,12 @@ reagents: - ReagentId: chem.WeldingFuel Quantity: 100 - - type: Welder useSoundCollection: Welder + - type: PointLight + enabled: false + radius: 1.5 + color: orange - type: entity name: wrench