Enable nullability in Content.Server (#3685)

This commit is contained in:
DrSmugleaf
2021-03-16 15:50:20 +01:00
committed by GitHub
parent 90fec0ed24
commit a5ade526b7
306 changed files with 1616 additions and 1441 deletions

View File

@@ -26,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Research
/// </summary>
public void Sync()
{
if (!Owner.TryGetComponent(out TechnologyDatabaseComponent database)) return;
if (!Owner.TryGetComponent(out TechnologyDatabaseComponent? database)) return;
foreach (var technology in database.Technologies)
{

View File

@@ -1,8 +1,6 @@
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -18,7 +16,7 @@ namespace Content.Server.GameObjects.Components.Research
private int _pointsPerSecond;
[DataField("active")]
private bool _active;
private PowerReceiverComponent _powerReceiver;
private PowerReceiverComponent? _powerReceiver;
[ViewVariables(VVAccess.ReadWrite)]
public int PointsPerSecond

View File

@@ -20,7 +20,7 @@ namespace Content.Server.GameObjects.Components.Research
[DataField("servername")]
private string _serverName = "RDSERVER";
private float _timer = 0f;
public TechnologyDatabaseComponent Database { get; private set; }
public TechnologyDatabaseComponent? Database { get; private set; }
[ViewVariables(VVAccess.ReadWrite)] [DataField("points")] private int _points = 0;
@@ -28,7 +28,7 @@ namespace Content.Server.GameObjects.Components.Research
// You could optimize research by keeping a list of unlocked recipes too.
[ViewVariables(VVAccess.ReadOnly)]
public IReadOnlyList<TechnologyPrototype> UnlockedTechnologies => Database.Technologies;
public IReadOnlyList<TechnologyPrototype>? UnlockedTechnologies => Database?.Technologies;
[ViewVariables(VVAccess.ReadOnly)]
public List<ResearchPointSourceComponent> PointSources { get; } = new();
@@ -66,7 +66,7 @@ namespace Content.Server.GameObjects.Components.Research
[ViewVariables]
public bool CanRun => _powerReceiver is null || _powerReceiver.Powered;
private PowerReceiverComponent _powerReceiver;
private PowerReceiverComponent? _powerReceiver;
public override void Initialize()
{
@@ -86,8 +86,14 @@ namespace Content.Server.GameObjects.Components.Research
public bool CanUnlockTechnology(TechnologyPrototype technology)
{
if (!Database.CanUnlockTechnology(technology) || _points < technology.RequiredPoints ||
Database.IsTechnologyUnlocked(technology)) return false;
if (Database == null)
return false;
if (!Database.CanUnlockTechnology(technology) ||
_points < technology.RequiredPoints ||
Database.IsTechnologyUnlocked(technology))
return false;
return true;
}
@@ -100,7 +106,7 @@ namespace Content.Server.GameObjects.Components.Research
public bool UnlockTechnology(TechnologyPrototype technology)
{
if (!CanUnlockTechnology(technology)) return false;
var result = Database.UnlockTechnology(technology);
var result = Database?.UnlockTechnology(technology) ?? false;
if (result)
_points -= technology.RequiredPoints;
return result;
@@ -113,7 +119,7 @@ namespace Content.Server.GameObjects.Components.Research
/// <returns></returns>
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
{
return Database.IsTechnologyUnlocked(technology);
return Database?.IsTechnologyUnlocked(technology) ?? false;
}
/// <summary>

View File

@@ -27,7 +27,7 @@ namespace Content.Server.GameObjects.Components.Research
if (!IsTechnologyUnlocked(tech)) AddTechnology(tech);
}
if(twoway)
if (twoway)
otherDatabase.Sync(this, false);
Dirty();
@@ -41,8 +41,8 @@ namespace Content.Server.GameObjects.Components.Research
/// <returns>Whether it could sync or not</returns>
public bool SyncWithServer()
{
if (!Owner.TryGetComponent(out ResearchClientComponent client)) return false;
if (!client.ConnectedToServer) return false;
if (!Owner.TryGetComponent(out ResearchClientComponent? client)) return false;
if (client.Server?.Database == null) return false;
Sync(client.Server.Database);