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

@@ -37,9 +37,9 @@ namespace Content.Server.GameObjects.Components.Items.Clothing
public int HeatResistance => _heatResistance;
[DataField("ClothingPrefix")]
private string _clothingEquippedPrefix;
private string? _clothingEquippedPrefix;
[ViewVariables(VVAccess.ReadWrite)]
public string ClothingEquippedPrefix
public string? ClothingEquippedPrefix
{
get => _clothingEquippedPrefix;
set
@@ -57,15 +57,15 @@ namespace Content.Server.GameObjects.Components.Items.Clothing
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
if (!_quickEquipEnabled) return false;
if (!eventArgs.User.TryGetComponent(out InventoryComponent inv)
|| !eventArgs.User.TryGetComponent(out HandsComponent hands)) return false;
if (!eventArgs.User.TryGetComponent(out InventoryComponent? inv)
|| !eventArgs.User.TryGetComponent(out HandsComponent? hands)) return false;
foreach (var (slot, flag) in SlotMasks)
{
// We check if the clothing can be equipped in this slot.
if ((SlotFlags & flag) == 0) continue;
if (inv.TryGetSlotItem(slot, out ItemComponent item))
if (inv.TryGetSlotItem(slot, out ItemComponent? item))
{
if (!inv.CanUnequip(slot)) continue;
hands.Drop(Owner);

View File

@@ -8,7 +8,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -50,7 +49,7 @@ namespace Content.Server.GameObjects.Components.Items
public void Roll()
{
_currentSide = _random.Next(1, (_sides/_step)+1) * _step;
if (!Owner.TryGetComponent(out SpriteComponent sprite)) return;
if (!Owner.TryGetComponent(out SpriteComponent? sprite)) return;
sprite.LayerSetState(0, $"d{_sides}{_currentSide}");
PlayDiceEffect();
}

View File

@@ -1,17 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.Audio;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Maps;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using System.Collections.Generic;
using System.Threading.Tasks;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.GameObjects.Components.Items
@@ -23,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Items
public override string Name => "FloorTile";
[DataField("outputs")]
private List<string> _outputTiles;
private List<string>? _outputTiles;
public override void Initialize()
{
@@ -55,7 +53,7 @@ namespace Content.Server.GameObjects.Components.Items
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
return true;
if (!Owner.TryGetComponent(out StackComponent stack))
if (!Owner.TryGetComponent(out StackComponent? stack))
return true;
var mapManager = IoCManager.Resolve<IMapManager>();
@@ -65,6 +63,10 @@ namespace Content.Server.GameObjects.Components.Items
if (locationMap.MapId == MapId.Nullspace)
return true;
mapManager.TryGetGrid(location.GetGridId(Owner.EntityManager), out var mapGrid);
if (_outputTiles == null)
return true;
foreach (var currentTile in _outputTiles)
{
var currentTileDefinition = (ContentTileDefinition) _tileDefinitionManager[currentTile];

View File

@@ -6,8 +6,6 @@ using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -29,7 +27,9 @@ namespace Content.Server.GameObjects.Components.Items.RCD
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (eventArgs.Target == null || !eventArgs.Target.TryGetComponent(out RCDComponent rcdComponent) || !eventArgs.User.TryGetComponent(out IHandsComponent hands))
if (eventArgs.Target == null ||
!eventArgs.Target.TryGetComponent(out RCDComponent? rcdComponent) ||
!eventArgs.User.TryGetComponent(out IHandsComponent? hands))
{
return false;
}

View File

@@ -13,8 +13,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -35,8 +33,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
[ViewVariables(VVAccess.ReadWrite)] [DataField("maxAmmo")] public int maxAmmo = 5;
public int _ammo; //How much "ammo" we have left. You can refill this with RCD ammo.
[ViewVariables(VVAccess.ReadWrite)] [DataField("delay")] private float _delay = 2f;
private DoAfterSystem doAfterSystem;
private DoAfterSystem doAfterSystem = default!;
///Enum to store the different mode states for clarity.
private enum RcdMode
@@ -135,7 +132,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
}
else //Delete what the user targeted
{
eventArgs.Target.Delete();
eventArgs.Target?.Delete();
}
break;
//Walls are a special behaviour, and require us to build a new object with a transform rather than setting a grid tile, thus we early return to avoid the tile set code.
@@ -201,7 +198,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
return false;
}
//They tried to decon a non-turf but it's not in the whitelist
if (eventArgs.Target != null && !eventArgs.Target.TryGetComponent(out RCDDeconstructWhitelist rcd_decon))
if (eventArgs.Target != null && !eventArgs.Target.TryGetComponent(out RCDDeconstructWhitelist? deCon))
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("You can't deconstruct that!"));
return false;

View File

@@ -12,8 +12,8 @@ using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Players;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.GameObjects.Components.Items.Storage
@@ -28,14 +28,11 @@ namespace Content.Server.GameObjects.Components.Items.Storage
public override uint? NetID => ContentNetIDs.ITEM;
[DataField("HeldPrefix")]
private string _equippedPrefix;
private string? _equippedPrefix;
public string EquippedPrefix
public string? EquippedPrefix
{
get
{
return _equippedPrefix;
}
get => _equippedPrefix;
set
{
_equippedPrefix = value;
@@ -81,7 +78,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
return false;
}
if (Owner.TryGetComponent(out IPhysBody physics) &&
if (Owner.TryGetComponent(out IPhysBody? physics) &&
physics.BodyType == BodyType.Static)
{
return false;
@@ -92,9 +89,10 @@ namespace Content.Server.GameObjects.Components.Items.Storage
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
if (!CanPickup(eventArgs.User)) return false;
if (!CanPickup(eventArgs.User) ||
!eventArgs.User.TryGetComponent(out IHandsComponent? hands) ||
hands.ActiveHand == null) return false;
var hands = eventArgs.User.GetComponent<IHandsComponent>();
hands.PutInHand(this, hands.ActiveHand, false);
return true;
}
@@ -117,7 +115,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
protected override void Activate(IEntity user, ItemComponent component)
{
if (user.TryGetComponent(out HandsComponent hands) && !hands.IsHolding(component.Owner))
if (user.TryGetComponent(out HandsComponent? hands) && !hands.IsHolding(component.Owner))
{
hands.PutInHand(component);
}

View File

@@ -8,9 +8,6 @@ using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -34,7 +31,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
{
_locked = value;
if (Owner.TryGetComponent(out AppearanceComponent appearance))
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(StorageVisuals.Locked, _locked);
}
@@ -45,7 +42,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
{
base.Startup();
if (Owner.TryGetComponent(out AppearanceComponent appearance))
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(StorageVisuals.CanLock, true);
}
@@ -114,7 +111,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
private bool CheckAccess(IEntity user)
{
if (Owner.TryGetComponent(out AccessReader reader))
if (Owner.TryGetComponent(out AccessReader? reader))
{
if (!reader.IsAllowed(user))
{