From afc3ae63351dd73b95f26cc42f7761b73d3d043c Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sun, 26 Dec 2021 15:32:45 +1300 Subject: [PATCH] Make more uids nullable (#5794) --- .../Body/UI/BodyScannerBoundUserInterface.cs | 5 +--- Content.Client/Body/UI/BodyScannerDisplay.cs | 12 ++------- .../ContextMenu/UI/EntityMenuElement.cs | 22 +++++++++------- .../ContextMenu/UI/EntityMenuPresenter.cs | 26 +++++++++---------- Content.Client/DoAfter/DoAfterSystem.cs | 4 +-- Content.Client/Popups/PopupSystem.cs | 8 +++--- Content.Client/Viewport/GameScreenBase.cs | 24 ++++++++--------- .../Wall/Components/LowWallComponent.cs | 7 ++--- .../AI/LoadBalancer/AiActionRequestJob.cs | 2 +- .../ActionBlocker/CanMoveCon.cs | 2 +- .../Containers/TargetAccessibleCon.cs | 9 ++----- .../Nutrition/Drink/DrinkValueCon.cs | 2 +- .../Nutrition/Drink/ThirstCon.cs | 2 +- .../Nutrition/Food/FoodValueCon.cs | 4 +-- .../Nutrition/Food/HungerCon.cs | 2 +- .../States/Combat/WeaponEntityState.cs | 4 +-- .../States/Inventory/EquippedEntityState.cs | 11 +++----- .../States/Movement/MoveTargetState.cs | 4 +-- .../AI/WorldState/States/TargetEntityState.cs | 4 +-- .../Body/Components/InternalsComponent.cs | 24 ++++++++--------- Content.Server/Botany/Seed.cs | 3 --- .../Climbing/Components/ClimbableComponent.cs | 2 +- Content.Server/Clothing/MagbootsSystem.cs | 2 +- .../Unit/Components/DisposalUnitComponent.cs | 5 ---- .../Doors/Components/ServerDoorComponent.cs | 10 +++---- .../Hands/Components/HandsComponent.cs | 26 +++++++------------ .../EntitySystems/LightReplacerSystem.cs | 19 ++++++-------- Content.Server/PAI/PAISystem.cs | 2 +- .../Components/PowerCellSlotComponent.cs | 4 +-- Content.Server/RCD/Systems/RCDSystem.cs | 7 ++--- Content.Server/Stack/StackSystem.cs | 4 +-- .../CursedEntityStorageComponent.cs | 4 +-- .../EntitySystems/SpawnItemsOnUseSystem.cs | 6 ++--- Content.Server/Stunnable/StunSystem.cs | 16 ++++-------- .../Verbs/Commands/InvokeVerbCommand.cs | 10 +++---- .../Components/RangedMagazineComponent.cs | 2 +- .../ServerBatteryBarrelComponent.cs | 6 ++--- .../ServerMagazineBarrelComponent.cs | 15 ++++++----- Content.Server/Wieldable/WieldableSystem.cs | 23 ++++++++-------- .../DoAfter/SharedDoAfterComponent.cs | 7 ++--- .../Interaction/SharedInteractionSystem.cs | 4 +-- Content.Shared/Verbs/SharedVerbSystem.cs | 10 ++++--- 42 files changed, 161 insertions(+), 204 deletions(-) diff --git a/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs b/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs index 247ce80b95..417059745a 100644 --- a/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs +++ b/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs @@ -14,9 +14,6 @@ namespace Content.Client.Body.UI [ViewVariables] private BodyScannerDisplay? _display; - [ViewVariables] - private EntityUid _entity; - public BodyScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } protected override void Open() @@ -43,7 +40,7 @@ namespace Content.Client.Body.UI throw new ArgumentException($"Received an invalid entity with id {scannerState.Uid} for body scanner with id {Owner.Owner} at {entMan.GetComponent(Owner.Owner).MapPosition}"); } - _display?.UpdateDisplay(_entity); + _display?.UpdateDisplay(scannerState.Uid); } protected override void Dispose(bool disposing) diff --git a/Content.Client/Body/UI/BodyScannerDisplay.cs b/Content.Client/Body/UI/BodyScannerDisplay.cs index 852527014e..921419d5f8 100644 --- a/Content.Client/Body/UI/BodyScannerDisplay.cs +++ b/Content.Client/Body/UI/BodyScannerDisplay.cs @@ -13,7 +13,7 @@ namespace Content.Client.Body.UI { public sealed class BodyScannerDisplay : SS14Window { - private EntityUid _currentEntity; + private EntityUid? _currentEntity; private SharedBodyPartComponent? _currentBodyPart; public BodyScannerDisplay(BodyScannerBoundUserInterface owner) @@ -104,9 +104,6 @@ namespace Content.Client.Body.UI public void UpdateDisplay(EntityUid entity) { - if(entity == null) - return; - _currentEntity = entity; BodyPartList.Clear(); @@ -125,12 +122,7 @@ namespace Content.Client.Body.UI public void BodyPartOnItemSelected(ItemListSelectedEventArgs args) { - if (_currentEntity == null) - return; - - var body = IoCManager.Resolve().GetComponentOrNull(_currentEntity); - - if (body == null) + if (IoCManager.Resolve().TryGetComponent(_currentEntity, out var body)) { return; } diff --git a/Content.Client/ContextMenu/UI/EntityMenuElement.cs b/Content.Client/ContextMenu/UI/EntityMenuElement.cs index 824aeafbf4..ba96a9522a 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuElement.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuElement.cs @@ -15,7 +15,7 @@ namespace Content.Client.ContextMenu.UI /// /// The entity that can be accessed by interacting with this element. /// - public EntityUid Entity; + public EntityUid? Entity; /// /// How many entities are accessible through this element's sub-menus. @@ -28,7 +28,7 @@ namespace Content.Client.ContextMenu.UI public readonly Label CountLabel; public readonly SpriteView EntityIcon = new() { OverrideDirection = Direction.South}; - public EntityMenuElement(EntityUid entity = default) + public EntityMenuElement(EntityUid? entity = null) { IoCManager.InjectDependencies(this); @@ -40,7 +40,7 @@ namespace Content.Client.ContextMenu.UI LayoutContainer.SetGrowVertical(CountLabel, LayoutContainer.GrowDirection.Begin); Entity = entity; - if (Entity != default) + if (Entity != null) { Count = 1; CountLabel.Visible = false; @@ -51,7 +51,7 @@ namespace Content.Client.ContextMenu.UI protected override void Dispose(bool disposing) { base.Dispose(disposing); - Entity = default; + Entity = null; Count = 0; } @@ -59,23 +59,25 @@ namespace Content.Client.ContextMenu.UI /// Update the icon and text of this element based on the given entity or this element's own entity if none /// is provided. /// - public void UpdateEntity(EntityUid entity = default) + public void UpdateEntity(EntityUid? entity = null) { - if (Entity != default && _entityManager.EntityExists(Entity) && !entity.Valid) - entity = Entity; + entity ??= Entity; - if (entity == default) + // check whether entity is null, invalid, or has been deleted. + // _entityManager.Deleted() implicitly checks all of these. + if (_entityManager.Deleted(entity)) { Text = string.Empty; + EntityIcon.Sprite = null; return; } EntityIcon.Sprite = _entityManager.GetComponentOrNull(entity); if (UserInterfaceManager.DebugMonitors.Visible) - Text = $"{_entityManager.GetComponent(entity!).EntityName} ({entity})"; + Text = _entityManager.ToPrettyString(entity.Value); else - Text = _entityManager.GetComponent(entity!).EntityName; + Text = _entityManager.GetComponent(entity.Value).EntityName; } } } diff --git a/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs b/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs index 033e23b333..f3cf7c3e88 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs @@ -101,18 +101,16 @@ namespace Content.Client.ContextMenu.UI // get an entity associated with this element var entity = entityElement.Entity; - if (!entity.Valid) - { - entity = GetFirstEntityOrNull(element.SubMenu); - } + entity ??= GetFirstEntityOrNull(element.SubMenu); - if (!entity.Valid) + // Deleted() automatically checks for null & existence. + if (_entityManager.Deleted(entity)) return; // open verb menu? if (args.Function == ContentKeyFunctions.OpenContextMenu) { - _verbSystem.VerbMenu.OpenVerbMenu(entity); + _verbSystem.VerbMenu.OpenVerbMenu(entity.Value); args.Handle(); return; } @@ -120,7 +118,7 @@ namespace Content.Client.ContextMenu.UI // do examination? if (args.Function == ContentKeyFunctions.ExamineEntity) { - _systemManager.GetEntitySystem().DoExamine(entity); + _systemManager.GetEntitySystem().DoExamine(entity.Value); args.Handle(); return; } @@ -139,7 +137,7 @@ namespace Content.Client.ContextMenu.UI var funcId = _inputManager.NetworkBindMap.KeyFunctionID(func); var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId, - BoundKeyState.Down, _entityManager.GetComponent(entity).Coordinates, args.PointerLocation, entity); + BoundKeyState.Down, _entityManager.GetComponent(entity.Value).Coordinates, args.PointerLocation, entity.Value); var session = _playerManager.LocalPlayer?.Session; if (session != null) @@ -314,7 +312,7 @@ namespace Content.Client.ContextMenu.UI element.SubMenu.Dispose(); element.SubMenu = null; element.CountLabel.Visible = false; - Elements[entity] = element; + Elements[entity.Value] = element; } // update the parent element, so that it's count and entity icon gets updated. @@ -326,17 +324,17 @@ namespace Content.Client.ContextMenu.UI /// /// Recursively look through a sub-menu and return the first entity. /// - private EntityUid GetFirstEntityOrNull(ContextMenuPopup? menu) + private EntityUid? GetFirstEntityOrNull(ContextMenuPopup? menu) { if (menu == null) - return default; + return null; foreach (var element in menu.MenuBody.Children) { if (element is not EntityMenuElement entityElement) continue; - if (entityElement.Entity != default) + if (entityElement.Entity != null) { if (!_entityManager.Deleted(entityElement.Entity)) return entityElement.Entity; @@ -345,11 +343,11 @@ namespace Content.Client.ContextMenu.UI // if the element has no entity, its a group of entities with another attached sub-menu. var entity = GetFirstEntityOrNull(entityElement.SubMenu); - if (entity != default) + if (entity != null) return entity; } - return default; + return null; } public override void OpenSubMenu(ContextMenuElement element) diff --git a/Content.Client/DoAfter/DoAfterSystem.cs b/Content.Client/DoAfter/DoAfterSystem.cs index 29aef68fb1..f8c4156aef 100644 --- a/Content.Client/DoAfter/DoAfterSystem.cs +++ b/Content.Client/DoAfter/DoAfterSystem.cs @@ -118,8 +118,8 @@ namespace Content.Client.DoAfter if (doAfter.BreakOnTargetMove) { - if (EntityManager.EntityExists(doAfter.TargetUid) && - !Transform(doAfter.TargetUid).Coordinates.InRange(EntityManager, doAfter.TargetGrid, + if (!EntityManager.Deleted(doAfter.Target) && + !Transform(doAfter.Target.Value).Coordinates.InRange(EntityManager, doAfter.TargetGrid, doAfter.MovementThreshold)) { comp.Cancel(id, currentTime); diff --git a/Content.Client/Popups/PopupSystem.cs b/Content.Client/Popups/PopupSystem.cs index eb4e447917..ae312343e3 100644 --- a/Content.Client/Popups/PopupSystem.cs +++ b/Content.Client/Popups/PopupSystem.cs @@ -51,7 +51,7 @@ namespace Content.Client.Popups PopupMessage(message, _eyeManager.CoordinatesToScreen(transform.Coordinates)); } - public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid entity = default) + public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid? entity = null) { var label = new PopupLabel(_eyeManager, EntityManager) { @@ -146,7 +146,7 @@ namespace Content.Client.Popups public float TimeLeft { get; private set; } public Vector2 InitialPos { get; set; } - public EntityUid Entity { get; set; } + public EntityUid? Entity { get; set; } public PopupLabel(IEyeManager eyeManager, IEntityManager entityManager) { @@ -161,9 +161,9 @@ namespace Content.Client.Popups { TimeLeft += eventArgs.DeltaSeconds; - var position = Entity == default + var position = Entity == null ? InitialPos - : (_eyeManager.CoordinatesToScreen(_entityManager.GetComponent(Entity).Coordinates).Position / UIScale) - DesiredSize / 2; + : (_eyeManager.CoordinatesToScreen(_entityManager.GetComponent(Entity.Value).Coordinates).Position / UIScale) - DesiredSize / 2; LayoutContainer.SetPosition(this, position - (0, 20 * (TimeLeft * TimeLeft + TimeLeft))); diff --git a/Content.Client/Viewport/GameScreenBase.cs b/Content.Client/Viewport/GameScreenBase.cs index 965334232f..3bc5762564 100644 --- a/Content.Client/Viewport/GameScreenBase.cs +++ b/Content.Client/Viewport/GameScreenBase.cs @@ -44,7 +44,7 @@ namespace Content.Client.Viewport private IEventBus _eventBus => _entityManager.EventBus; - private EntityUid _lastHoveredEntity; + private EntityUid? _lastHoveredEntity; private bool _outlineEnabled = true; @@ -84,7 +84,7 @@ namespace Content.Client.Viewport // lead to extremely thick outlines in the other viewports. Fixing this probably requires changing how the // hover outline works, so that it only highlights the entity in a single viewport. - EntityUid entityToClick = default; + EntityUid? entityToClick = null; var renderScale = 1; if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp) { @@ -107,15 +107,15 @@ namespace Content.Client.Viewport } var inRange = false; - if (localPlayer.ControlledEntity != default && entityToClick != default) + if (localPlayer.ControlledEntity != null && entityToClick != null) { - inRange = localPlayer.InRangeUnobstructed(entityToClick, ignoreInsideBlocker: true); + inRange = localPlayer.InRangeUnobstructed(entityToClick.Value, ignoreInsideBlocker: true); } InteractionOutlineComponent? outline; if(!_outlineEnabled || !ConfigurationManager.GetCVar(CCVars.OutlineEnabled)) { - if(entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline)) + if(entityToClick != null && _entityManager.TryGetComponent(entityToClick, out outline)) { outline.OnMouseLeave(); //Prevent outline remains from persisting post command. } @@ -124,7 +124,7 @@ namespace Content.Client.Viewport if (entityToClick == _lastHoveredEntity) { - if (entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline)) + if (entityToClick != null && _entityManager.TryGetComponent(entityToClick, out outline)) { outline.UpdateInRange(inRange, renderScale); } @@ -132,7 +132,7 @@ namespace Content.Client.Viewport return; } - if (_lastHoveredEntity != default && !_entityManager.Deleted(_lastHoveredEntity) && + if (_lastHoveredEntity != null && !_entityManager.Deleted(_lastHoveredEntity) && _entityManager.TryGetComponent(_lastHoveredEntity, out outline)) { outline.OnMouseLeave(); @@ -140,16 +140,16 @@ namespace Content.Client.Viewport _lastHoveredEntity = entityToClick; - if (_lastHoveredEntity != default && _entityManager.TryGetComponent(_lastHoveredEntity, out outline)) + if (_lastHoveredEntity != null && _entityManager.TryGetComponent(_lastHoveredEntity, out outline)) { outline.OnMouseEnter(inRange, renderScale); } } - public EntityUid GetEntityUnderPosition(MapCoordinates coordinates) + public EntityUid? GetEntityUnderPosition(MapCoordinates coordinates) { var entitiesUnderPosition = GetEntitiesUnderPosition(coordinates); - return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : default; + return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : null; } public IList GetEntitiesUnderPosition(EntityCoordinates coordinates) @@ -257,7 +257,7 @@ namespace Content.Client.Viewport var funcId = InputManager.NetworkBindMap.KeyFunctionID(func); EntityCoordinates coordinates = default; - EntityUid entityToClick = default; + EntityUid? entityToClick = null; if (args.Viewport is IViewportControl vp) { var mousePosWorld = vp.ScreenToMap(kArgs.PointerLocation.Position); @@ -269,7 +269,7 @@ namespace Content.Client.Viewport var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, kArgs.State, coordinates , kArgs.PointerLocation, - entityToClick); + entityToClick ?? default); // TODO make entityUid nullable // client side command handlers will always be sent the local player session. var session = PlayerManager.LocalPlayer?.Session; diff --git a/Content.Client/Wall/Components/LowWallComponent.cs b/Content.Client/Wall/Components/LowWallComponent.cs index 8c92261847..8d3d5a92a1 100644 --- a/Content.Client/Wall/Components/LowWallComponent.cs +++ b/Content.Client/Wall/Components/LowWallComponent.cs @@ -64,10 +64,11 @@ namespace Content.Client.Wall.Components { base.Shutdown(); - EntityUid tempQualifier = _overlayEntity; - if (tempQualifier != null) + // _overlayEntity is non-nullable as it is set on startup. + // Should also never be default but might as well check. + if (_overlayEntity.Valid) { - _entMan.DeleteEntity(tempQualifier); + _entMan.DeleteEntity(_overlayEntity); } } diff --git a/Content.Server/AI/LoadBalancer/AiActionRequestJob.cs b/Content.Server/AI/LoadBalancer/AiActionRequestJob.cs index 8594dc5eb7..2550656763 100644 --- a/Content.Server/AI/LoadBalancer/AiActionRequestJob.cs +++ b/Content.Server/AI/LoadBalancer/AiActionRequestJob.cs @@ -39,7 +39,7 @@ namespace Content.Server.AI.LoadBalancer var entity = _request.Context.GetState().GetValue(); - if (entity == null || !IoCManager.Resolve().HasComponent(entity)) + if (!IoCManager.Resolve().HasComponent(entity)) { return null; } diff --git a/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs b/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs index 18ffa4ac79..1d4baad450 100644 --- a/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs +++ b/Content.Server/AI/Utility/Considerations/ActionBlocker/CanMoveCon.cs @@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.ActionBlocker { var self = context.GetState().GetValue(); - if (self == null || !EntitySystem.Get().CanMove(self)) + if (!EntitySystem.Get().CanMove(self)) { return 0.0f; } diff --git a/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs b/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs index ebed8d3c34..ab6b76806b 100644 --- a/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs +++ b/Content.Server/AI/Utility/Considerations/Containers/TargetAccessibleCon.cs @@ -24,7 +24,7 @@ namespace Content.Server.AI.Utility.Considerations.Containers return 0.0f; } - if (target.TryGetContainer(out var container)) + if (target!.Value.TryGetContainer(out var container)) { if (entMan.TryGetComponent(container.Owner, out EntityStorageComponent? storageComponent)) { @@ -43,12 +43,7 @@ namespace Content.Server.AI.Utility.Considerations.Containers var owner = context.GetState().GetValue(); - if (owner == null) - { - return 0; - } - - return EntitySystem.Get().CanAccess(owner, target, SharedInteractionSystem.InteractionRange) ? 1.0f : 0.0f; + return EntitySystem.Get().CanAccess(owner, target.Value, SharedInteractionSystem.InteractionRange) ? 1.0f : 0.0f; } } } diff --git a/Content.Server/AI/Utility/Considerations/Nutrition/Drink/DrinkValueCon.cs b/Content.Server/AI/Utility/Considerations/Nutrition/Drink/DrinkValueCon.cs index e7a7fbc5ca..12e3d7172b 100644 --- a/Content.Server/AI/Utility/Considerations/Nutrition/Drink/DrinkValueCon.cs +++ b/Content.Server/AI/Utility/Considerations/Nutrition/Drink/DrinkValueCon.cs @@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink if (target == null || IoCManager.Resolve().Deleted(target) - || !EntitySystem.Get().TryGetSolution(target, DrinkComponent.DefaultSolutionName, out var drink)) + || !EntitySystem.Get().TryGetSolution(target.Value, DrinkComponent.DefaultSolutionName, out var drink)) { return 0.0f; } diff --git a/Content.Server/AI/Utility/Considerations/Nutrition/Drink/ThirstCon.cs b/Content.Server/AI/Utility/Considerations/Nutrition/Drink/ThirstCon.cs index 6ea21c75db..b90f80bdae 100644 --- a/Content.Server/AI/Utility/Considerations/Nutrition/Drink/ThirstCon.cs +++ b/Content.Server/AI/Utility/Considerations/Nutrition/Drink/ThirstCon.cs @@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink { var owner = context.GetState().GetValue(); - if (owner == null || !IoCManager.Resolve().TryGetComponent(owner, out ThirstComponent? thirst)) + if (!IoCManager.Resolve().TryGetComponent(owner, out ThirstComponent? thirst)) { return 0.0f; } diff --git a/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs b/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs index 3341d8a193..d37b71823c 100644 --- a/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs +++ b/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs @@ -13,8 +13,8 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food { var target = context.GetState().GetValue(); - if (target == null || !IoCManager.Resolve().TryGetComponent(target, out var foodComp) - || !EntitySystem.Get().TryGetSolution(target, foodComp.SolutionName, out var food)) + if (target == null || !IoCManager.Resolve().TryGetComponent(target.Value, out var foodComp) + || !EntitySystem.Get().TryGetSolution(target.Value, foodComp.SolutionName, out var food)) { return 0.0f; } diff --git a/Content.Server/AI/Utility/Considerations/Nutrition/Food/HungerCon.cs b/Content.Server/AI/Utility/Considerations/Nutrition/Food/HungerCon.cs index 33cc9dca90..29a0157683 100644 --- a/Content.Server/AI/Utility/Considerations/Nutrition/Food/HungerCon.cs +++ b/Content.Server/AI/Utility/Considerations/Nutrition/Food/HungerCon.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food { var owner = context.GetState().GetValue(); - if (owner == null || !IoCManager.Resolve().TryGetComponent(owner, out HungerComponent? hunger)) + if (!IoCManager.Resolve().TryGetComponent(owner, out HungerComponent? hunger)) { return 0.0f; } diff --git a/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs b/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs index 4ed2c20cc0..136065587b 100644 --- a/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs +++ b/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs @@ -4,13 +4,13 @@ using Robust.Shared.GameObjects; namespace Content.Server.AI.WorldState.States.Combat { [UsedImplicitly] - public sealed class WeaponEntityState : PlanningStateData + public sealed class WeaponEntityState : PlanningStateData { // Similar to TargetEntity public override string Name => "WeaponEntity"; public override void Reset() { - Value = default; + Value = null; } } } diff --git a/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs b/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs index fb2c55b130..374bed44ac 100644 --- a/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs +++ b/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs @@ -9,18 +9,13 @@ namespace Content.Server.AI.WorldState.States.Inventory /// AKA what's in active hand /// [UsedImplicitly] - public sealed class EquippedEntityState : StateData + public sealed class EquippedEntityState : StateData { public override string Name => "EquippedEntity"; - public override EntityUid GetValue() + public override EntityUid? GetValue() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? handsComponent)) - { - return default; - } - - return handsComponent.GetActiveHand?.Owner ?? default; + return IoCManager.Resolve().GetComponentOrNull(Owner)?.GetActiveHand?.Owner; } } } diff --git a/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs b/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs index 48e8172ef3..ad40860f68 100644 --- a/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs +++ b/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs @@ -4,12 +4,12 @@ using Robust.Shared.GameObjects; namespace Content.Server.AI.WorldState.States.Movement { [UsedImplicitly] - public sealed class MoveTargetState : PlanningStateData + public sealed class MoveTargetState : PlanningStateData { public override string Name => "MoveTarget"; public override void Reset() { - Value = default; + Value = null; } } } diff --git a/Content.Server/AI/WorldState/States/TargetEntityState.cs b/Content.Server/AI/WorldState/States/TargetEntityState.cs index dea4c554fe..b6a2c857c7 100644 --- a/Content.Server/AI/WorldState/States/TargetEntityState.cs +++ b/Content.Server/AI/WorldState/States/TargetEntityState.cs @@ -7,13 +7,13 @@ namespace Content.Server.AI.WorldState.States /// Could be target item to equip, target to attack, etc. /// [UsedImplicitly] - public sealed class TargetEntityState : PlanningStateData + public sealed class TargetEntityState : PlanningStateData { public override string Name => "TargetEntity"; public override void Reset() { - Value = default; + Value = null; } } } diff --git a/Content.Server/Body/Components/InternalsComponent.cs b/Content.Server/Body/Components/InternalsComponent.cs index f2214e9fb9..26f6774d89 100644 --- a/Content.Server/Body/Components/InternalsComponent.cs +++ b/Content.Server/Body/Components/InternalsComponent.cs @@ -11,15 +11,15 @@ namespace Content.Server.Body.Components [Dependency] private readonly IEntityManager _entMan = default!; public override string Name => "Internals"; - [ViewVariables] public EntityUid GasTankEntity { get; set; } - [ViewVariables] public EntityUid BreathToolEntity { get; set; } + [ViewVariables] public EntityUid? GasTankEntity { get; set; } + [ViewVariables] public EntityUid? BreathToolEntity { get; set; } public void DisconnectBreathTool() { var old = BreathToolEntity; - BreathToolEntity = default; + BreathToolEntity = null; - if (old != default && _entMan.TryGetComponent(old, out BreathToolComponent? breathTool) ) + if (_entMan.TryGetComponent(old, out BreathToolComponent? breathTool) ) { breathTool.DisconnectInternals(); DisconnectTank(); @@ -28,7 +28,7 @@ namespace Content.Server.Body.Components public void ConnectBreathTool(EntityUid toolEntity) { - if (BreathToolEntity != default && _entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? tool)) + if (_entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? tool)) { tool.DisconnectInternals(); } @@ -38,20 +38,20 @@ namespace Content.Server.Body.Components public void DisconnectTank() { - if (GasTankEntity != default && _entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank)) + if (_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank)) { tank.DisconnectFromInternals(Owner); } - GasTankEntity = default; + GasTankEntity = null; } public bool TryConnectTank(EntityUid tankEntity) { - if (BreathToolEntity == default) + if (BreathToolEntity == null) return false; - if (GasTankEntity != default && _entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank)) + if (_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank)) { tank.DisconnectFromInternals(Owner); } @@ -62,12 +62,10 @@ namespace Content.Server.Body.Components public bool AreInternalsWorking() { - return BreathToolEntity != default && - GasTankEntity != default && - _entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? breathTool) && + return _entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? breathTool) && breathTool.IsFunctional && _entMan.TryGetComponent(GasTankEntity, out GasTankComponent? gasTank) && - gasTank.Air != default; + gasTank.Air != null; } } diff --git a/Content.Server/Botany/Seed.cs b/Content.Server/Botany/Seed.cs index c9123aac14..ae41446d44 100644 --- a/Content.Server/Botany/Seed.cs +++ b/Content.Server/Botany/Seed.cs @@ -291,9 +291,6 @@ namespace Content.Server.Botany { AddToDatabase(); - if (user == null) - return Enumerable.Empty(); - if (ProductPrototypes == null || ProductPrototypes.Count == 0 || Yield <= 0) { user.PopupMessageCursor(Loc.GetString("botany-harvest-fail-message")); diff --git a/Content.Server/Climbing/Components/ClimbableComponent.cs b/Content.Server/Climbing/Components/ClimbableComponent.cs index 4dcb0c58cc..84db4dba7c 100644 --- a/Content.Server/Climbing/Components/ClimbableComponent.cs +++ b/Content.Server/Climbing/Components/ClimbableComponent.cs @@ -115,7 +115,7 @@ namespace Content.Server.Climbing.Components return false; } - if (target == null || !_entities.HasComponent(dragged)) + if (!_entities.HasComponent(dragged)) { reason = Loc.GetString("comp-climbable-cant-climb"); return false; diff --git a/Content.Server/Clothing/MagbootsSystem.cs b/Content.Server/Clothing/MagbootsSystem.cs index 89d795852d..89d1fedcab 100644 --- a/Content.Server/Clothing/MagbootsSystem.cs +++ b/Content.Server/Clothing/MagbootsSystem.cs @@ -25,7 +25,7 @@ namespace Content.Server.Clothing private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetActivationVerbsEvent args) { - if (args.User == null || !args.CanAccess || !args.CanInteract) + if (!args.CanAccess || !args.CanInteract) return; Verb verb = new(); diff --git a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs index 54c63038c8..d450081d1e 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs @@ -90,11 +90,6 @@ namespace Content.Server.Disposal.Unit.Components private bool PlayerCanUse(EntityUid player) { - if (player == null) - { - return false; - } - var actionBlocker = EntitySystem.Get(); if (!actionBlocker.CanInteract(player) || diff --git a/Content.Server/Doors/Components/ServerDoorComponent.cs b/Content.Server/Doors/Components/ServerDoorComponent.cs index fa1ab5503c..8f76be66e7 100644 --- a/Content.Server/Doors/Components/ServerDoorComponent.cs +++ b/Content.Server/Doors/Components/ServerDoorComponent.cs @@ -275,19 +275,19 @@ namespace Content.Server.Doors.Components #region Opening - public void TryOpen(EntityUid user = default) + public void TryOpen(EntityUid? user = null) { var msg = new DoorOpenAttemptEvent(); _entMan.EventBus.RaiseLocalEvent(Owner, msg); if (msg.Cancelled) return; - if (!user.Valid) + if (user == null) { // a machine opened it or something, idk Open(); } - else if (CanOpenByEntity(user)) + else if (CanOpenByEntity(user.Value)) { Open(); @@ -422,14 +422,14 @@ namespace Content.Server.Doors.Components #region Closing - public void TryClose(EntityUid user = default) + public void TryClose(EntityUid? user = null) { var msg = new DoorCloseAttemptEvent(); _entMan.EventBus.RaiseLocalEvent(Owner, msg); if (msg.Cancelled) return; - if (user != default && !CanCloseByEntity(user)) + if (user != null && !CanCloseByEntity(user.Value)) { Deny(); return; diff --git a/Content.Server/Hands/Components/HandsComponent.cs b/Content.Server/Hands/Components/HandsComponent.cs index ba07419840..a3c973b8de 100644 --- a/Content.Server/Hands/Components/HandsComponent.cs +++ b/Content.Server/Hands/Components/HandsComponent.cs @@ -99,23 +99,17 @@ namespace Content.Server.Hands.Components var source = @event.Source; var target = @event.Target; - if (source != null) - { - SoundSystem.Play(Filter.Pvs(source), _disarmedSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); + SoundSystem.Play(Filter.Pvs(source), _disarmedSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); - if (target != null) - { - if (ActiveHand != null && Drop(ActiveHand, false)) - { - source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent(source).EntityName), ("disarmed", Name: _entities.GetComponent(target).EntityName))); - source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent(target).EntityName))); - } - else - { - source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent(source).EntityName), ("shoved", Name: _entities.GetComponent(target).EntityName))); - source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent(target).EntityName))); - } - } + if (ActiveHand != null && Drop(ActiveHand, false)) + { + source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent(source).EntityName), ("disarmed", Name: _entities.GetComponent(target).EntityName))); + source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent(target).EntityName))); + } + else + { + source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent(source).EntityName), ("shoved", Name: _entities.GetComponent(target).EntityName))); + source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent(target).EntityName))); } return true; diff --git a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs index 77a00db063..ab361124a1 100644 --- a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs +++ b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs @@ -67,17 +67,14 @@ namespace Content.Server.Light.EntitySystems // standard interaction checks if (!_blocker.CanInteract(eventArgs.User)) return; - if (eventArgs.Used != null) - { - var usedUid = eventArgs.Used; + var usedUid = eventArgs.Used; - // want to insert a new light bulb? - if (EntityManager.TryGetComponent(usedUid, out LightBulbComponent ? bulb)) - eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb); - // add bulbs from storage? - else if (EntityManager.TryGetComponent(usedUid, out ServerStorageComponent? storage)) - eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage); - } + // want to insert a new light bulb? + if (EntityManager.TryGetComponent(usedUid, out LightBulbComponent? bulb)) + eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb); + // add bulbs from storage? + else if (EntityManager.TryGetComponent(usedUid, out ServerStorageComponent? storage)) + eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage); } /// @@ -108,7 +105,7 @@ namespace Content.Server.Light.EntitySystems (e) => EntityManager.GetComponentOrNull(e)?.Type == fixture.BulbType); // found bulb in inserted storage - if (bulb != null) + if (bulb.Valid) // FirstOrDefault can return default/invalid uid. { // try to remove it var hasRemoved = replacer.InsertedBulbs.Remove(bulb); diff --git a/Content.Server/PAI/PAISystem.cs b/Content.Server/PAI/PAISystem.cs index 0908fa117e..2d16a96533 100644 --- a/Content.Server/PAI/PAISystem.cs +++ b/Content.Server/PAI/PAISystem.cs @@ -129,7 +129,7 @@ namespace Content.Server.PAI private void AddWipeVerb(EntityUid uid, PAIComponent pai, GetActivationVerbsEvent args) { - if (args.User == null || !args.CanAccess || !args.CanInteract) + if (!args.CanAccess || !args.CanInteract) return; if (EntityManager.TryGetComponent(uid, out var mind) && mind.HasMind) diff --git a/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs b/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs index d5138ef1bc..e84d0b46ad 100644 --- a/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs +++ b/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs @@ -128,7 +128,7 @@ namespace Content.Server.PowerCell.Components /// (optional) the user to give the removed cell to. /// Should be played upon removal? /// The cell component of the entity that was removed, or null if removal failed. - public PowerCellComponent? EjectCell(EntityUid user, bool playSound = true) + public PowerCellComponent? EjectCell(EntityUid? user = null, bool playSound = true) { var cell = Cell; if (cell == null || !CanRemoveCell) return null; @@ -138,7 +138,7 @@ namespace Content.Server.PowerCell.Components { if (!_entities.TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(_entities.GetComponent(cell.Owner))) { - _entities.GetComponent(cell.Owner).Coordinates = _entities.GetComponent(user).Coordinates; + _entities.GetComponent(cell.Owner).Coordinates = _entities.GetComponent(user.Value).Coordinates; } } else diff --git a/Content.Server/RCD/Systems/RCDSystem.cs b/Content.Server/RCD/Systems/RCDSystem.cs index a26afd0556..d81db4b99c 100644 --- a/Content.Server/RCD/Systems/RCDSystem.cs +++ b/Content.Server/RCD/Systems/RCDSystem.cs @@ -235,11 +235,8 @@ namespace Content.Server.RCD.Systems mode = (++mode) % _modes.Length; //Then, do a rollover on the value so it doesnt hit an invalid state rcd.Mode = (RcdMode) mode; //Finally, cast the newly acquired int mode to an RCDmode so we can use it. - if (user != null) - { - var msg = Loc.GetString("rcd-component-change-mode", ("mode", rcd.Mode.ToString())); - rcd.Owner.PopupMessage(user, msg); //Prints an overhead message above the RCD - } + var msg = Loc.GetString("rcd-component-change-mode", ("mode", rcd.Mode.ToString())); + rcd.Owner.PopupMessage(user, msg); //Prints an overhead message above the RCD } } } diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index f849c79b9e..c4e9817e16 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -42,7 +42,7 @@ namespace Content.Server.Stack public EntityUid? Split(EntityUid uid, int amount, EntityCoordinates spawnPosition, SharedStackComponent? stack = null) { if (!Resolve(uid, ref stack)) - return default; + return null; // Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked... var prototype = _prototypeManager.TryIndex(stack.StackTypeId, out var stackType) @@ -51,7 +51,7 @@ namespace Content.Server.Stack // Try to remove the amount of things we want to split from the original stack... if (!Use(uid, amount, stack)) - return default; + return null; // Set the output parameter in the event instance to the newly split stack. var entity = Spawn(prototype, spawnPosition); diff --git a/Content.Server/Storage/Components/CursedEntityStorageComponent.cs b/Content.Server/Storage/Components/CursedEntityStorageComponent.cs index 061e471b28..ca60b33fd6 100644 --- a/Content.Server/Storage/Components/CursedEntityStorageComponent.cs +++ b/Content.Server/Storage/Components/CursedEntityStorageComponent.cs @@ -37,9 +37,9 @@ namespace Content.Server.Storage.Components if (lockers.Contains(Owner)) lockers.Remove(Owner); - var lockerEnt = _robustRandom.Pick(lockers); + if (lockers.Count == 0) return; - if (lockerEnt == null) return; // No valid lockers anywhere. + var lockerEnt = _robustRandom.Pick(lockers); var locker = _entMan.GetComponent(lockerEnt); diff --git a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs index 929d9bd084..4671a99813 100644 --- a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs +++ b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs @@ -27,7 +27,7 @@ namespace Content.Server.Storage.EntitySystems return; var alreadySpawnedGroups = new List(); - EntityUid entityToPlaceInHands = default; + EntityUid? entityToPlaceInHands = null; foreach (var storageItem in component.Items) { if (!string.IsNullOrEmpty(storageItem.GroupId) && @@ -57,10 +57,10 @@ namespace Content.Server.Storage.EntitySystems EntityManager.DeleteEntity(uid); } - if (entityToPlaceInHands != default + if (entityToPlaceInHands != null && EntityManager.TryGetComponent(args.User, out var hands)) { - hands.TryPutInAnyHand(entityToPlaceInHands); + hands.TryPutInAnyHand(entityToPlaceInHands.Value); } } } diff --git a/Content.Server/Stunnable/StunSystem.cs b/Content.Server/Stunnable/StunSystem.cs index c7c0a47baf..a9cc74eea2 100644 --- a/Content.Server/Stunnable/StunSystem.cs +++ b/Content.Server/Stunnable/StunSystem.cs @@ -40,18 +40,12 @@ namespace Content.Server.Stunnable var source = args.Source; var target = args.Target; - if (source != null) - { - var knock = EntityManager.GetComponent(uid); - SoundSystem.Play(Filter.Pvs(source), knock.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); + var knock = EntityManager.GetComponent(uid); + SoundSystem.Play(Filter.Pvs(source), knock.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); - if (target != null) - { - // TODO: Use PopupSystem - source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", Name: EntityManager.GetComponent(source).EntityName), ("target", Name: EntityManager.GetComponent(target).EntityName))); - source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", Name: EntityManager.GetComponent(target).EntityName))); - } - } + // TODO: Use PopupSystem + source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", Name(source)), ("target", Name(target)))); + source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", Name(target)))); _adminLogSystem.Add(LogType.DisarmedKnockdown, LogImpact.Medium, $"{ToPrettyString(args.Source):user} knocked down {ToPrettyString(args.Target):target}"); diff --git a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs index cc98d71d22..ec30a335de 100644 --- a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs +++ b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs @@ -29,7 +29,7 @@ namespace Content.Server.Verbs.Commands var verbSystem = EntitySystem.Get(); // get the 'player' entity (defaulting to command user, otherwise uses a uid) - EntityUid playerEntity = default; + EntityUid? playerEntity = null; if (!int.TryParse(args[0], out var intPlayerUid)) { if (args[0] == "self" && shell.Player?.AttachedEntity != null) @@ -54,7 +54,7 @@ namespace Content.Server.Verbs.Commands return; } - if (playerEntity == default) + if (playerEntity == null) { shell.WriteError(Loc.GetString("invoke-verb-command-invalid-player-entity")); return; @@ -68,14 +68,14 @@ namespace Content.Server.Verbs.Commands } var verbName = args[2].ToLowerInvariant(); - var verbs = verbSystem.GetLocalVerbs(target, playerEntity, VerbType.All, true); + var verbs = verbSystem.GetLocalVerbs(target, playerEntity.Value, VerbType.All, true); if ((Enum.TryParse(typeof(VerbType), verbName, ignoreCase: true, out var vtype) && vtype is VerbType key) && verbs.TryGetValue(key, out var vset) && vset.Any()) { - verbSystem.ExecuteVerb(vset.First(), playerEntity, target, forced: true); + verbSystem.ExecuteVerb(vset.First(), playerEntity.Value, target, forced: true); shell.WriteLine(Loc.GetString("invoke-verb-command-success", ("verb", verbName), ("target", target), ("player", playerEntity))); return; } @@ -86,7 +86,7 @@ namespace Content.Server.Verbs.Commands { if (verb.Text.ToLowerInvariant() == verbName) { - verbSystem.ExecuteVerb(verb, playerEntity, target, forced: true); + verbSystem.ExecuteVerb(verb, playerEntity.Value, target, forced: true); shell.WriteLine(Loc.GetString("invoke-verb-command-success", ("verb", verb.Text), ("target", target), ("player", playerEntity))); return; } diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs index fca41f78d0..7c349f2d38 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs @@ -120,7 +120,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public EntityUid? TakeAmmo() { - EntityUid ammo = default; + EntityUid? ammo = null; // If anything's spawned use that first, otherwise use the fill prototype as a fallback (if we have spawn count left) if (_spawnedAmmo.TryPop(out var entity)) { diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs index c0c9445540..daed92910a 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs @@ -133,13 +133,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (powerCellEntity == null) { - return default; + return null; } var capacitor = _entities.GetComponent(powerCellEntity.Value); if (capacitor.CurrentCharge < _lowerChargeLimit) { - return default; + return null; } // Can fire confirmed @@ -149,7 +149,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (capacitor.UseCharge(chargeChange) < _lowerChargeLimit) { // Handling of funny exploding cells. - return default; + return null; } var energyRatio = chargeChange / _baseFireCost; diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs index 243d3b1ad6..99edf0b64d 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs @@ -193,19 +193,20 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public override EntityUid? PeekAmmo() { - return BoltOpen ? default : _chamberContainer.ContainedEntity; + return BoltOpen ? null : _chamberContainer.ContainedEntity; } public override EntityUid? TakeProjectile(EntityCoordinates spawnAt) { if (BoltOpen) { - return default; + return null; } - var entity = _chamberContainer.ContainedEntity ?? default; + var entity = _chamberContainer.ContainedEntity; Cycle(); - return entity != default ? EntitySystem.Get().TakeBullet(_entities.GetComponent(entity), spawnAt) : null; + + return entity != null ? EntitySystem.Get().TakeBullet(_entities.GetComponent(entity.Value), spawnAt) : null; } private void Cycle(bool manual = false) @@ -296,7 +297,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components } // Try and pull a round from the magazine to replace the chamber if possible - var magazine = MagazineContainer.ContainedEntity ?? default; + var magazine = MagazineContainer.ContainedEntity; if (_entities.GetComponentOrNull(magazine)?.TakeAmmo() is not {Valid: true} nextRound) { @@ -305,11 +306,11 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _chamberContainer.Insert(nextRound); - if (_autoEjectMag && magazine != null && _entities.GetComponent(magazine).ShotsLeft == 0) + if (_autoEjectMag && magazine != null && _entities.GetComponent(magazine.Value).ShotsLeft == 0) { SoundSystem.Play(Filter.Pvs(Owner), _soundAutoEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2)); - MagazineContainer.Remove(magazine); + MagazineContainer.Remove(magazine.Value); #pragma warning disable 618 SendNetworkMessage(new MagazineAutoEjectMessage()); #pragma warning restore 618 diff --git a/Content.Server/Wieldable/WieldableSystem.cs b/Content.Server/Wieldable/WieldableSystem.cs index 1095095be7..4e3a395645 100644 --- a/Content.Server/Wieldable/WieldableSystem.cs +++ b/Content.Server/Wieldable/WieldableSystem.cs @@ -151,9 +151,10 @@ namespace Content.Server.Wieldable private void OnItemWielded(EntityUid uid, WieldableComponent component, ItemWieldedEvent args) { - if (args.User == default) + if (args.User == null) return; - if (!CanWield(uid, component, args.User) || component.Wielded) + + if (!CanWield(uid, component, args.User.Value) || component.Wielded) return; if (EntityManager.TryGetComponent(uid, out var item)) @@ -171,16 +172,16 @@ namespace Content.Server.Wieldable for (var i = 0; i < component.FreeHandsRequired; i++) { - _virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User); + _virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User.Value); } - args.User.PopupMessage(Loc.GetString("wieldable-component-successful-wield", + args.User.Value.PopupMessage(Loc.GetString("wieldable-component-successful-wield", ("item", uid))); } private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args) { - if (args.User == default) + if (args.User == null) return; if (!component.Wielded) return; @@ -200,11 +201,11 @@ namespace Content.Server.Wieldable component.UnwieldSound.GetSound()); } - args.User.PopupMessage(Loc.GetString("wieldable-component-failed-wield", + args.User.Value.PopupMessage(Loc.GetString("wieldable-component-failed-wield", ("item", uid))); } - _virtualItemSystem.DeleteInHandsMatching(args.User, uid); + _virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid); } private void OnItemLeaveHand(EntityUid uid, WieldableComponent component, UnequippedHandEvent args) @@ -245,9 +246,9 @@ namespace Content.Server.Wieldable /// public class ItemWieldedEvent : EntityEventArgs { - public EntityUid User; + public EntityUid? User; - public ItemWieldedEvent(EntityUid user = default) + public ItemWieldedEvent(EntityUid? user = null) { User = user; } @@ -275,13 +276,13 @@ namespace Content.Server.Wieldable /// public class ItemUnwieldedEvent : EntityEventArgs { - public EntityUid User; + public EntityUid? User; /// /// Whether the item is being forced to be unwielded, or if the player chose to unwield it themselves. /// public bool Force; - public ItemUnwieldedEvent(EntityUid user = default, bool force=false) + public ItemUnwieldedEvent(EntityUid? user = null, bool force=false) { User = user; Force = force; diff --git a/Content.Shared/DoAfter/SharedDoAfterComponent.cs b/Content.Shared/DoAfter/SharedDoAfterComponent.cs index 603a686dd2..be1acc2858 100644 --- a/Content.Shared/DoAfter/SharedDoAfterComponent.cs +++ b/Content.Shared/DoAfter/SharedDoAfterComponent.cs @@ -52,7 +52,7 @@ namespace Content.Shared.DoAfter public EntityCoordinates TargetGrid { get; } - public EntityUid TargetUid { get; } + public EntityUid? Target { get; } public float Delay { get; } @@ -63,7 +63,8 @@ namespace Content.Shared.DoAfter public float MovementThreshold { get; } - public ClientDoAfter(byte id, EntityCoordinates userGrid, EntityCoordinates targetGrid, TimeSpan startTime, float delay, bool breakOnUserMove, bool breakOnTargetMove, float movementThreshold, EntityUid targetUid = default) + public ClientDoAfter(byte id, EntityCoordinates userGrid, EntityCoordinates targetGrid, TimeSpan startTime, + float delay, bool breakOnUserMove, bool breakOnTargetMove, float movementThreshold, EntityUid? target = null) { ID = id; UserGrid = userGrid; @@ -73,7 +74,7 @@ namespace Content.Shared.DoAfter BreakOnUserMove = breakOnUserMove; BreakOnTargetMove = breakOnTargetMove; MovementThreshold = movementThreshold; - TargetUid = targetUid; + Target = target; } } } diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 3b64493d67..a5eb620a4e 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -650,7 +650,7 @@ namespace Content.Shared.Interaction /// public void TryUseInteraction(EntityUid user, EntityUid used, bool altInteract = false) { - if (user != null && used != null && _actionBlockerSystem.CanUse(user)) + if (_actionBlockerSystem.CanUse(user)) { if (altInteract) AltInteract(user, used); @@ -820,7 +820,7 @@ namespace Content.Shared.Interaction /// public bool TryDroppedInteraction(EntityUid user, EntityUid item) { - if (user == null || item == null || !_actionBlockerSystem.CanDrop(user)) return false; + if (!_actionBlockerSystem.CanDrop(user)) return false; DroppedInteraction(user, item); return true; diff --git a/Content.Shared/Verbs/SharedVerbSystem.cs b/Content.Shared/Verbs/SharedVerbSystem.cs index 64c1a52afc..fbae16c1b2 100644 --- a/Content.Shared/Verbs/SharedVerbSystem.cs +++ b/Content.Shared/Verbs/SharedVerbSystem.cs @@ -64,15 +64,17 @@ namespace Content.Shared.Verbs // call ActionBlocker checks, just cache it for the verb request. var canInteract = force || _actionBlockerSystem.CanInteract(user); - EntityUid @using = default; - if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands) && (force || _actionBlockerSystem.CanUse(user))) + EntityUid? @using = null; + if (TryComp(user, out SharedHandsComponent? hands) && (force || _actionBlockerSystem.CanUse(user))) { - hands.TryGetActiveHeldEntity(out @using); + // TODO Hands remove nullable (#5634) + hands.TryGetActiveHeldEntity(out var nonNullableUsing); + @using = nonNullableUsing; // Check whether the "Held" entity is a virtual pull entity. If yes, set that as the entity being "Used". // This allows you to do things like buckle a dragged person onto a surgery table, without click-dragging // their sprite. - if (@using != default && EntityManager.TryGetComponent(@using, out var pull)) + if (@using != null && TryComp(@using, out HandVirtualItemComponent? pull)) { @using = pull.BlockingEntity; }