Enable nullability in Content.Server (#3685)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
@@ -18,8 +18,6 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -48,7 +46,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
public override string Name => "Puddle";
|
||||
|
||||
private CancellationTokenSource _evaporationToken;
|
||||
private CancellationTokenSource? _evaporationToken;
|
||||
[DataField("evaporate_threshold")]
|
||||
private ReagentUnit _evaporateThreshold = ReagentUnit.New(20); // How few <Solution Quantity> we can hold prior to self-destructing
|
||||
public ReagentUnit EvaporateThreshold
|
||||
@@ -77,8 +75,8 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
/// </summary>
|
||||
private bool _overflown;
|
||||
|
||||
private SpriteComponent _spriteComponent;
|
||||
private SnapGridComponent _snapGrid;
|
||||
private SpriteComponent _spriteComponent = default!;
|
||||
private SnapGridComponent _snapGrid = default!;
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
@@ -97,7 +95,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
private ReagentUnit _overflowVolume = ReagentUnit.New(20);
|
||||
private ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
|
||||
private SolutionContainerComponent _contents;
|
||||
private SolutionContainerComponent _contents = default!;
|
||||
public bool EmptyHolder => _contents.ReagentList.Count == 0;
|
||||
[DataField("variants")]
|
||||
private int _spriteVariants = 1;
|
||||
@@ -105,21 +103,13 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
[DataField("recolor")]
|
||||
private bool _recolor = default;
|
||||
|
||||
private bool Slippery => Owner.TryGetComponent(out SlipperyComponent slippery) && slippery.Slippery;
|
||||
private bool Slippery => Owner.TryGetComponent(out SlipperyComponent? slippery) && slippery.Slippery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent solutionComponent))
|
||||
{
|
||||
_contents = solutionComponent;
|
||||
}
|
||||
else
|
||||
{
|
||||
_contents = Owner.AddComponent<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
_contents = Owner.EnsureComponentWarn<SolutionContainerComponent>();
|
||||
_snapGrid = Owner.EnsureComponent<SnapGridComponent>();
|
||||
|
||||
// Smaller than 1m^3 for now but realistically this shouldn't be hit
|
||||
@@ -253,7 +243,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
private void UpdateSlip()
|
||||
{
|
||||
if ((_slipThreshold == ReagentUnit.New(-1) || CurrentVolume < _slipThreshold) &&
|
||||
Owner.TryGetComponent(out SlipperyComponent oldSlippery))
|
||||
Owner.TryGetComponent(out SlipperyComponent? oldSlippery))
|
||||
{
|
||||
oldSlippery.Slippery = false;
|
||||
}
|
||||
@@ -351,7 +341,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
/// <param name="puddle">The puddle that was found or is to be created, or null if there
|
||||
/// is a wall in the way</param>
|
||||
/// <returns>true if a puddle was found or created, false otherwise</returns>
|
||||
private bool TryGetAdjacentOverflow(Direction direction, out Func<PuddleComponent> puddle)
|
||||
private bool TryGetAdjacentOverflow(Direction direction, [NotNullWhen(true)] out Func<PuddleComponent>? puddle)
|
||||
{
|
||||
puddle = default;
|
||||
|
||||
@@ -370,14 +360,14 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
|
||||
foreach (var entity in _snapGrid.GetInDir(direction))
|
||||
{
|
||||
if (entity.TryGetComponent(out IPhysBody physics) &&
|
||||
if (entity.TryGetComponent(out IPhysBody? physics) &&
|
||||
(physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
|
||||
{
|
||||
puddle = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out PuddleComponent existingPuddle))
|
||||
if (entity.TryGetComponent(out PuddleComponent? existingPuddle))
|
||||
{
|
||||
if (existingPuddle._overflown)
|
||||
{
|
||||
@@ -391,7 +381,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
if (puddle == default)
|
||||
{
|
||||
var grid = _snapGrid.DirectionToGrid(direction);
|
||||
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype.ID, grid).GetComponent<PuddleComponent>();
|
||||
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype?.ID, grid).GetComponent<PuddleComponent>();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
protected override void GetData(IEntity user, SpillableComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!component.Owner.TryGetComponent(out ISolutionInteractionsComponent solutionComponent) ||
|
||||
!component.Owner.TryGetComponent(out ISolutionInteractionsComponent? solutionComponent) ||
|
||||
!solutionComponent.CanDrain)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
@@ -59,7 +59,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
|
||||
void IDropped.Dropped(DroppedEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Intentional && Owner.TryGetComponent(out ISolutionInteractionsComponent solutionComponent))
|
||||
if (!eventArgs.Intentional && Owner.TryGetComponent(out ISolutionInteractionsComponent? solutionComponent))
|
||||
{
|
||||
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
|
||||
}
|
||||
|
||||
@@ -14,10 +14,8 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Fluids
|
||||
@@ -33,7 +31,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
[DataField("transferAmount")]
|
||||
private ReagentUnit _transferAmount = ReagentUnit.New(10);
|
||||
[DataField("spraySound")]
|
||||
private string _spraySound;
|
||||
private string? _spraySound;
|
||||
[DataField("sprayVelocity")]
|
||||
private float _sprayVelocity = 1.5f;
|
||||
[DataField("sprayAliveTime")]
|
||||
@@ -73,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
set => _sprayVelocity = value;
|
||||
}
|
||||
|
||||
public string SpraySound => _spraySound;
|
||||
public string? SpraySound => _spraySound;
|
||||
|
||||
public ReagentUnit CurrentVolume => Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
|
||||
@@ -115,7 +113,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
if (eventArgs.ClickLocation.GetGridId(_serverEntityManager) != playerPos.GetGridId(_serverEntityManager))
|
||||
return true;
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
|
||||
return true;
|
||||
|
||||
var direction = (eventArgs.ClickLocation.Position - playerPos.Position).Normalized;
|
||||
@@ -147,7 +145,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
var vapor = _serverEntityManager.SpawnEntity(_vaporPrototype, playerPos.Offset(distance < 1 ? quarter : threeQuarters));
|
||||
vapor.Transform.LocalRotation = rotation;
|
||||
|
||||
if (vapor.TryGetComponent(out AppearanceComponent appearance)) // Vapor sprite should face down.
|
||||
if (vapor.TryGetComponent(out AppearanceComponent? appearance)) // Vapor sprite should face down.
|
||||
{
|
||||
appearance.SetData(VaporVisuals.Rotation, -Angle.South + rotation);
|
||||
appearance.SetData(VaporVisuals.Color, contents.Color.WithAlpha(1f));
|
||||
@@ -162,12 +160,15 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
}
|
||||
|
||||
//Play sound
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(_spraySound, Owner, AudioHelpers.WithVariation(0.125f));
|
||||
if (!string.IsNullOrEmpty(_spraySound))
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(_spraySound, Owner, AudioHelpers.WithVariation(0.125f));
|
||||
}
|
||||
|
||||
_lastUseTime = curTime;
|
||||
_cooldownEnd = _lastUseTime + TimeSpan.FromSeconds(_cooldownTime);
|
||||
|
||||
if (Owner.TryGetComponent(out ItemCooldownComponent cooldown))
|
||||
if (Owner.TryGetComponent(out ItemCooldownComponent? cooldown))
|
||||
{
|
||||
cooldown.CooldownStart = _lastUseTime;
|
||||
cooldown.CooldownEnd = _cooldownEnd;
|
||||
@@ -199,13 +200,13 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
|
||||
_safety = state;
|
||||
|
||||
if(Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
if(Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
appearance.SetData(SprayVisuals.Safety, _safety);
|
||||
}
|
||||
|
||||
void IDropped.Dropped(DroppedEventArgs eventArgs)
|
||||
{
|
||||
if(_hasSafety && Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
if(_hasSafety && Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
appearance.SetData(SprayVisuals.Safety, _safety);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user