Add light to lit welders (#1282)

* Add light to lit welders

* Fix null errors

* Make the welder light orange
This commit is contained in:
DrSmugleaf
2020-07-08 13:41:32 +02:00
committed by GitHub
parent 2d2385032a
commit d20e4969e2
2 changed files with 25 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
using System; #nullable enable
using System;
using System.Runtime.Remoting; using System.Runtime.Remoting;
using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.EntitySystems.Click; using Content.Server.GameObjects.EntitySystems.Click;
@@ -27,8 +28,8 @@ namespace Content.Server.GameObjects.Components.Interactable
public class WelderComponent : ToolComponent, IExamine, IUse, ISuicideAct, ISolutionChange public class WelderComponent : ToolComponent, IExamine, IUse, ISuicideAct, ISolutionChange
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private IServerNotifyManager _notifyManager; [Dependency] private readonly IServerNotifyManager _notifyManager = default!;
#pragma warning restore 649 #pragma warning restore 649
public override string Name => "Welder"; public override string Name => "Welder";
@@ -44,10 +45,11 @@ namespace Content.Server.GameObjects.Components.Interactable
/// </summary> /// </summary>
public const float FuelLossRate = 0.5f; public const float FuelLossRate = 0.5f;
private bool _welderLit = false; private bool _welderLit;
private WelderSystem _welderSystem; private WelderSystem _welderSystem = default!;
private SpriteComponent _spriteComponent; private SpriteComponent? _spriteComponent;
private SolutionComponent _solutionComponent; private SolutionComponent? _solutionComponent;
private PointLightComponent? _pointLightComponent;
[ViewVariables] [ViewVariables]
public float Fuel => _solutionComponent?.Solution.GetReagentQuantity("chem.WeldingFuel").Float() ?? 0f; 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 _solutionComponent);
Owner.TryGetComponent(out _spriteComponent); Owner.TryGetComponent(out _spriteComponent);
Owner.TryGetComponent(out _pointLightComponent);
} }
public override ComponentState GetComponentState() public override ComponentState GetComponentState()
@@ -98,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Interactable
return base.UseTool(user, target, toolQualityNeeded) && TryWeld(fuelConsumed, user); 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) if (!WelderLit)
{ {
@@ -131,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Interactable
/// <summary> /// <summary>
/// Deactivates welding tool if active, activates welding tool if possible /// Deactivates welding tool if active, activates welding tool if possible
/// </summary> /// </summary>
private bool ToggleWelderStatus(IEntity user = null) private bool ToggleWelderStatus(IEntity? user = null)
{ {
var item = Owner.GetComponent<ItemComponent>(); var item = Owner.GetComponent<ItemComponent>();
@@ -140,7 +143,10 @@ namespace Content.Server.GameObjects.Components.Interactable
WelderLit = false; WelderLit = false;
// Layer 1 is the flame. // Layer 1 is the flame.
item.EquippedPrefix = "off"; item.EquippedPrefix = "off";
_spriteComponent.LayerSetVisible(1, false); _spriteComponent?.LayerSetVisible(1, false);
if (_pointLightComponent != null) _pointLightComponent.Enabled = false;
PlaySoundCollection("WelderOff", -5); PlaySoundCollection("WelderOff", -5);
_welderSystem.Unsubscribe(this); _welderSystem.Unsubscribe(this);
return true; return true;
@@ -154,7 +160,10 @@ namespace Content.Server.GameObjects.Components.Interactable
WelderLit = true; WelderLit = true;
item.EquippedPrefix = "on"; item.EquippedPrefix = "on";
_spriteComponent.LayerSetVisible(1, true); _spriteComponent?.LayerSetVisible(1, true);
if (_pointLightComponent != null) _pointLightComponent.Enabled = true;
PlaySoundCollection("WelderOn", -5); PlaySoundCollection("WelderOn", -5);
_welderSystem.Subscribe(this); _welderSystem.Subscribe(this);
return true; return true;
@@ -188,7 +197,7 @@ namespace Content.Server.GameObjects.Components.Interactable
if (!HasQuality(ToolQuality.Welding) || !WelderLit) if (!HasQuality(ToolQuality.Welding) || !WelderLit)
return; return;
_solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime)); _solutionComponent?.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime));
if (Fuel == 0) if (Fuel == 0)
ToggleWelderStatus(); ToggleWelderStatus();

View File

@@ -96,9 +96,12 @@
reagents: reagents:
- ReagentId: chem.WeldingFuel - ReagentId: chem.WeldingFuel
Quantity: 100 Quantity: 100
- type: Welder - type: Welder
useSoundCollection: Welder useSoundCollection: Welder
- type: PointLight
enabled: false
radius: 1.5
color: orange
- type: entity - type: entity
name: wrench name: wrench