More power nullability (#3070)

This commit is contained in:
collinlunn
2021-02-02 05:20:24 -06:00
committed by GitHub
parent d0d2434fba
commit a5492bc943
20 changed files with 73 additions and 56 deletions

View File

@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Server.GameObjects.Components.NodeContainer.Nodes;
@@ -50,7 +51,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer
} }
} }
public override void HandleMessage(ComponentMessage message, IComponent component) public override void HandleMessage(ComponentMessage message, IComponent? component)
{ {
base.HandleMessage(message, component); base.HandleMessage(message, component);
switch (message) switch (message)

View File

@@ -1,4 +1,5 @@
using System; #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Explosions; using Content.Server.Explosions;
@@ -24,12 +25,12 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
/// since any part connected to the node group can easily find the master. /// since any part connected to the node group can easily find the master.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
private AMEControllerComponent _masterController; private AMEControllerComponent? _masterController;
[Dependency] [Dependency]
private readonly IRobustRandom _random = default!; private readonly IRobustRandom _random = default!;
public AMEControllerComponent MasterController => _masterController; public AMEControllerComponent? MasterController => _masterController;
private readonly List<AMEShieldComponent> _cores = new(); private readonly List<AMEShieldComponent> _cores = new();
@@ -52,20 +53,18 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
if (_masterController != null && _masterController?.Owner == node.Owner) { _masterController = null; } if (_masterController != null && _masterController?.Owner == node.Owner) { _masterController = null; }
} }
public void RefreshAMENodes(AMEControllerComponent controller) public void RefreshAMENodes(AMEControllerComponent? controller)
{ {
if(_masterController == null && controller != null) if(_masterController == null && controller != null)
{ {
_masterController = controller; _masterController = controller;
} }
if (_cores != null) { foreach (AMEShieldComponent core in _cores)
foreach (AMEShieldComponent core in _cores) {
{ core.UnsetCore();
core.UnsetCore();
}
_cores.Clear();
} }
_cores.Clear();
//Check each shield node to see if it meets core criteria //Check each shield node to see if it meets core criteria
foreach (Node node in Nodes) foreach (Node node in Nodes)
@@ -79,11 +78,12 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
.Select(entity => entity.TryGetComponent<AMEShieldComponent>(out var adjshield) ? adjshield : null) .Select(entity => entity.TryGetComponent<AMEShieldComponent>(out var adjshield) ? adjshield : null)
.Where(adjshield => adjshield != null); .Where(adjshield => adjshield != null);
if (nodeNeighbors.Count() >= 8) { _cores.Add(shield); } if (nodeNeighbors.Count() >= 8)
{
_cores.Add(shield);
}
} }
if (_cores == null) { return; }
foreach (AMEShieldComponent core in _cores) foreach (AMEShieldComponent core in _cores)
{ {
core.SetCore(); core.SetCore();

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; #nullable enable
using System.Collections.Generic;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{ {

View File

@@ -1,4 +1,5 @@
using System; #nullable enable
using System;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{ {

View File

@@ -1,4 +1,5 @@
using System; #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Server.GameObjects.Components.NodeContainer.Nodes;

View File

@@ -1,3 +1,4 @@
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
@@ -63,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
/// </summary> /// </summary>
public void UpdateState() public void UpdateState()
{ {
if (!Owner.TryGetComponent(out PowerReceiverComponent receiver)) if (!Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{ {
return; return;
} }
@@ -83,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
public void OnUpdate(float frameTime) public void OnUpdate(float frameTime)
{ {
if (Owner.Deleted || !Owner.TryGetComponent(out BatteryComponent battery)) if (Owner.Deleted || !Owner.TryGetComponent(out BatteryComponent? battery))
{ {
return; return;
} }
@@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
battery.CurrentCharge += _chargingWattage * frameTime * _chargingEfficiency; battery.CurrentCharge += _chargingWattage * frameTime * _chargingEfficiency;
if (battery.BatteryState == BatteryState.Full) if (battery.BatteryState == BatteryState.Full)
{ {
if (Owner.TryGetComponent(out PowerReceiverComponent receiver)) if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{ {
receiver.Load = 1; receiver.Load = 1;
} }
@@ -113,12 +114,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private void TurnOff() private void TurnOff()
{ {
if (Owner.TryGetComponent(out SpriteComponent sprite)) if (Owner.TryGetComponent(out SpriteComponent? sprite))
{ {
sprite.LayerSetState(0, "emergency_light_off"); sprite.LayerSetState(0, "emergency_light_off");
} }
if (Owner.TryGetComponent(out PointLightComponent light)) if (Owner.TryGetComponent(out PointLightComponent? light))
{ {
light.Enabled = false; light.Enabled = false;
} }
@@ -126,18 +127,18 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private void TurnOn() private void TurnOn()
{ {
if (Owner.TryGetComponent(out SpriteComponent sprite)) if (Owner.TryGetComponent(out SpriteComponent? sprite))
{ {
sprite.LayerSetState(0, "emergency_light_on"); sprite.LayerSetState(0, "emergency_light_on");
} }
if (Owner.TryGetComponent(out PointLightComponent light)) if (Owner.TryGetComponent(out PointLightComponent? light))
{ {
light.Enabled = true; light.Enabled = true;
} }
} }
public override void HandleMessage(ComponentMessage message, IComponent component) public override void HandleMessage(ComponentMessage message, IComponent? component)
{ {
base.HandleMessage(message, component); base.HandleMessage(message, component);
switch (message) switch (message)

View File

@@ -1,3 +1,4 @@
#nullable enable
using System; using System;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
@@ -41,8 +42,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
/// <summary> /// <summary>
/// Invoked whenever the state of the light bulb changes. /// Invoked whenever the state of the light bulb changes.
/// </summary> /// </summary>
public event EventHandler<EventArgs> OnLightBulbStateChange; public event EventHandler<EventArgs>? OnLightBulbStateChange;
public event EventHandler<EventArgs> OnLightColorChange; public event EventHandler<EventArgs?>? OnLightColorChange;
private Color _color = Color.White; private Color _color = Color.White;
@@ -106,7 +107,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
public void UpdateColor() public void UpdateColor()
{ {
if (!Owner.TryGetComponent(out SpriteComponent sprite)) if (!Owner.TryGetComponent(out SpriteComponent? sprite))
{ {
return; return;
} }

View File

@@ -1,4 +1,5 @@
using Content.Shared.Interfaces.GameObjects.Components; #nullable enable
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;

View File

@@ -1,3 +1,4 @@
#nullable enable
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.GUI;
@@ -41,16 +42,16 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
[ViewVariables] private bool _on; [ViewVariables] private bool _on;
private LightBulbType BulbType = LightBulbType.Tube; private LightBulbType BulbType = LightBulbType.Tube;
[ViewVariables] private ContainerSlot _lightBulbContainer; [ViewVariables] private ContainerSlot _lightBulbContainer = default!;
[ViewVariables] [ViewVariables]
private LightBulbComponent LightBulb private LightBulbComponent? LightBulb
{ {
get get
{ {
if (_lightBulbContainer.ContainedEntity == null) return null; if (_lightBulbContainer.ContainedEntity == null) return null;
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent bulb); _lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent? bulb);
return bulb; return bulb;
} }
@@ -65,12 +66,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
public bool InteractHand(InteractHandEventArgs eventArgs) public bool InteractHand(InteractHandEventArgs eventArgs)
{ {
if (!eventArgs.User.TryGetComponent(out IDamageableComponent damageableComponent)) if (!eventArgs.User.TryGetComponent(out IDamageableComponent? damageableComponent))
{ {
Eject(); Eject();
return false; return false;
} }
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent heatResistanceComponent)) if(eventArgs.User.TryGetComponent(out HeatResistanceComponent? heatResistanceComponent))
{ {
if(CanBurn(heatResistanceComponent.GetHeatResistance())) if(CanBurn(heatResistanceComponent.GetHeatResistance()))
{ {
@@ -83,6 +84,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
bool CanBurn(int heatResistance) bool CanBurn(int heatResistance)
{ {
if (LightBulb == null)
return false;
return _lightState && heatResistance < LightBulb.BurningTemperature; return _lightState && heatResistance < LightBulb.BurningTemperature;
} }
@@ -108,7 +112,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private bool InsertBulb(IEntity bulb) private bool InsertBulb(IEntity bulb)
{ {
if (LightBulb != null) return false; if (LightBulb != null) return false;
if (!bulb.TryGetComponent(out LightBulbComponent lightBulb)) return false; if (!bulb.TryGetComponent(out LightBulbComponent? lightBulb)) return false;
if (lightBulb.Type != BulbType) return false; if (lightBulb.Type != BulbType) return false;
var inserted = _lightBulbContainer.Insert(bulb); var inserted = _lightBulbContainer.Insert(bulb);
@@ -135,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
if (!_lightBulbContainer.Remove(bulb.Owner)) return; if (!_lightBulbContainer.Remove(bulb.Owner)) return;
if (!user.TryGetComponent(out HandsComponent hands) if (!user.TryGetComponent(out HandsComponent? hands)
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>())) || !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
bulb.Owner.Transform.Coordinates = user.Transform.Coordinates; bulb.Owner.Transform.Coordinates = user.Transform.Coordinates;
} }
@@ -149,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
/// <summary> /// <summary>
/// For attaching UpdateLight() to events. /// For attaching UpdateLight() to events.
/// </summary> /// </summary>
public void UpdateLight(object sender, EventArgs e) public void UpdateLight(object? sender, EventArgs? e)
{ {
UpdateLight(); UpdateLight();
} }
@@ -212,7 +216,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner); _lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner);
} }
public override void HandleMessage(ComponentMessage message, IComponent component) public override void HandleMessage(ComponentMessage message, IComponent? component)
{ {
base.HandleMessage(message, component); base.HandleMessage(message, component);
switch (message) switch (message)

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels; #nullable enable
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;

View File

@@ -1,3 +1,5 @@
#nullable enable
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
@@ -15,7 +17,7 @@ namespace Content.Server.GameObjects.Components.Power
[ViewVariables] [ViewVariables]
public TNetType Net { get => _net; set => SetNet(value); } public TNetType Net { get => _net; set => SetNet(value); }
private TNetType _net; private TNetType _net = default!; //set in OnAdd()
protected abstract TNetType NullNet { get; } protected abstract TNetType NullNet { get; }
@@ -68,7 +70,7 @@ namespace Content.Server.GameObjects.Components.Power
protected abstract void RemoveSelfFromNet(TNetType net); protected abstract void RemoveSelfFromNet(TNetType net);
private bool TryFindNet(out TNetType foundNet) private bool TryFindNet([NotNullWhen(true)] out TNetType? foundNet)
{ {
if (Owner.TryGetComponent<NodeContainerComponent>(out var container)) if (Owner.TryGetComponent<NodeContainerComponent>(out var container))
{ {

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers; #nullable enable
using Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;

View File

@@ -1,8 +1,7 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents; #nullable enable
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
{ {

View File

@@ -1,8 +1,7 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents; #nullable enable
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
{ {

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Power; #nullable enable
using Content.Server.GameObjects.Components.Power;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;

View File

@@ -1,10 +1,9 @@
using System.Collections.Generic; #nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
{ {

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents; #nullable enable
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC; using Robust.Shared.IoC;

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents; #nullable enable
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents; #nullable enable
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;

View File

@@ -1,4 +1,5 @@
using System; #nullable enable
using System;
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Power.PowerNetComponents; using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using Content.Shared.Physics; using Content.Shared.Physics;