From ed1a96e536026046c4ad6c2c73f7968f09e1205c Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 20 Aug 2020 16:48:00 +0200 Subject: [PATCH] Nullability fixes. --- .../Components/Body/BodyManagerComponent.cs | 4 +- .../Components/ClickableComponent.cs | 2 +- .../Components/Items/HandsComponent.cs | 2 +- .../Components/Mobs/StunnableComponent.cs | 2 +- .../Components/Nutrition/HungerComponent.cs | 2 +- .../Components/Nutrition/ThirstComponent.cs | 2 +- .../EntitySystems/DoAfter/DoAfterGui.cs | 2 +- .../EntitySystems/DoAfter/DoAfterSystem.cs | 4 +- .../GameObjects/EntitySystems/MoverSystem.cs | 2 +- .../UserInterface/CooldownGraphic.cs | 1 + .../Tests/Disposal/DisposalUnitTest.cs | 12 ++-- .../Components/Movement/ClimbUnitTest.cs | 6 +- Content.Server/Body/BodyCommands.cs | 6 +- .../Mechanisms/Behaviors/HeartBehavior.cs | 2 +- .../Body/Mechanisms/Behaviors/LungBehavior.cs | 2 +- .../Mechanisms/Behaviors/StomachBehavior.cs | 2 +- .../Access/AccessReaderComponent.cs | 10 +-- .../Components/AnchorableComponent.cs | 4 +- .../Components/Atmos/GasAnalyzerComponent.cs | 18 ++--- .../Components/Body/BodyManagerComponent.cs | 2 +- .../Components/Buckle/BuckleComponent.cs | 16 ++--- .../Components/Cargo/CargoConsoleComponent.cs | 2 +- .../Components/Conveyor/ConveyorComponent.cs | 14 ++-- .../Conveyor/ConveyorSwitchComponent.cs | 10 +-- .../Components/Disposal/DisposalCommands.cs | 2 +- .../Disposal/DisposalHolderComponent.cs | 6 +- .../Disposal/DisposalTubeComponent.cs | 10 +-- .../Disposal/DisposalUnitComponent.cs | 24 +++---- .../Components/DoAfterComponent.cs | 2 +- .../Components/Fluids/SpillHelper.cs | 2 +- .../Components/GUI/HandsComponent.cs | 10 +-- .../Components/Interactable/ToolCommands.cs | 4 +- .../Items/Storage/ServerStorageComponent.cs | 14 ++-- .../Components/Mobs/MindComponent.cs | 2 +- .../Movement/ShuttleControllerComponent.cs | 12 ++-- .../Components/PDA/PDAComponent.cs | 4 +- .../Pointing/PointingArrowComponent.cs | 2 +- .../Pointing/RoguePointingArrowComponent.cs | 4 +- .../Rotatable/FlippableComponent.cs | 2 +- .../GameObjects/Components/WiresComponent.cs | 2 +- .../Atmos/GasTileOverlaySystem.cs | 66 +++++++++---------- .../EntitySystems/AtmosphereSystem.cs | 2 +- .../EntitySystems/DoAfter/DoAfter.cs | 6 +- .../GameObjects/EntitySystems/MoverSystem.cs | 2 +- .../EntitySystems/PointingSystem.cs | 2 +- .../SharedPlayerInputMoverComponent.cs | 4 +- .../EntitySystems/SharedMoverSystem.cs | 4 +- 47 files changed, 159 insertions(+), 158 deletions(-) diff --git a/Content.Client/GameObjects/Components/Body/BodyManagerComponent.cs b/Content.Client/GameObjects/Components/Body/BodyManagerComponent.cs index 2948c9191e..61049ec7a0 100644 --- a/Content.Client/GameObjects/Components/Body/BodyManagerComponent.cs +++ b/Content.Client/GameObjects/Components/Body/BodyManagerComponent.cs @@ -33,7 +33,7 @@ namespace Content.Client.GameObjects.Components.Body public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null) { - if (!Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } @@ -50,7 +50,7 @@ namespace Content.Client.GameObjects.Components.Body if (!partRemoved.Dropped.HasValue || !_entityManager.TryGetEntity(partRemoved.Dropped.Value, out var entity) || - !entity.TryGetComponent(out ISpriteComponent droppedSprite)) + !entity.TryGetComponent(out ISpriteComponent? droppedSprite)) { break; } diff --git a/Content.Client/GameObjects/Components/ClickableComponent.cs b/Content.Client/GameObjects/Components/ClickableComponent.cs index 57d9420167..a92af22451 100644 --- a/Content.Client/GameObjects/Components/ClickableComponent.cs +++ b/Content.Client/GameObjects/Components/ClickableComponent.cs @@ -37,7 +37,7 @@ namespace Content.Client.GameObjects.Components /// True if the click worked, false otherwise. public bool CheckClick(Vector2 worldPos, out int drawDepth, out uint renderOrder) { - if (!Owner.TryGetComponent(out ISpriteComponent sprite) || !sprite.Visible) + if (!Owner.TryGetComponent(out ISpriteComponent? sprite) || !sprite.Visible) { drawDepth = default; renderOrder = default; diff --git a/Content.Client/GameObjects/Components/Items/HandsComponent.cs b/Content.Client/GameObjects/Components/Items/HandsComponent.cs index daa03d74e1..30e32afad3 100644 --- a/Content.Client/GameObjects/Components/Items/HandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/HandsComponent.cs @@ -148,7 +148,7 @@ namespace Content.Client.GameObjects.Components.Items return; } - if (!entity.TryGetComponent(out ItemComponent item)) return; + if (!entity.TryGetComponent(out ItemComponent? item)) return; var maybeInHands = item.GetInHandStateInfo(hand.Location); diff --git a/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs b/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs index 4c02d343cb..9d6ce08f8f 100644 --- a/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs @@ -34,7 +34,7 @@ namespace Content.Client.GameObjects.Components.Mobs WalkModifierOverride = state.WalkModifierOverride; RunModifierOverride = state.RunModifierOverride; - if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement)) + if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement)) { movement.RefreshMovementSpeedModifiers(); } diff --git a/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs b/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs index 8323fb5e7a..6db62b1bb3 100644 --- a/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs +++ b/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs @@ -20,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Nutrition _currentHungerThreshold = hunger.CurrentThreshold; - if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement)) + if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement)) { movement.RefreshMovementSpeedModifiers(); } diff --git a/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs b/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs index b77d59a34a..a211afe239 100644 --- a/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs +++ b/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs @@ -20,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Nutrition _currentThirstThreshold = thirst.CurrentThreshold; - if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement)) + if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement)) { movement.RefreshMovementSpeedModifiers(); } diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs index b46b359ff4..a6724c0f6a 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs @@ -143,7 +143,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter { base.FrameUpdate(args); - if (AttachedEntity?.IsValid() != true || !AttachedEntity.TryGetComponent(out DoAfterComponent doAfterComponent)) + if (AttachedEntity?.IsValid() != true || !AttachedEntity.TryGetComponent(out DoAfterComponent? doAfterComponent)) { return; } diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs index 8aed094c7f..cc0337a941 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs @@ -67,7 +67,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter Gui ??= new DoAfterGui(); Gui.AttachedEntity = entity; - if (entity.TryGetComponent(out DoAfterComponent doAfterComponent)) + if (entity.TryGetComponent(out DoAfterComponent? doAfterComponent)) { foreach (var (_, doAfter) in doAfterComponent.DoAfters) { @@ -87,7 +87,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter return; } - if (!_player.TryGetComponent(out DoAfterComponent doAfterComponent)) + if (!_player.TryGetComponent(out DoAfterComponent? doAfterComponent)) { return; } diff --git a/Content.Client/GameObjects/EntitySystems/MoverSystem.cs b/Content.Client/GameObjects/EntitySystems/MoverSystem.cs index cdabb87d7c..db3ad9fc33 100644 --- a/Content.Client/GameObjects/EntitySystems/MoverSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/MoverSystem.cs @@ -25,7 +25,7 @@ namespace Content.Client.GameObjects.EntitySystems { var playerEnt = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEnt == null || !playerEnt.TryGetComponent(out IMoverComponent mover)) + if (playerEnt == null || !playerEnt.TryGetComponent(out IMoverComponent? mover)) { return; } diff --git a/Content.Client/UserInterface/CooldownGraphic.cs b/Content.Client/UserInterface/CooldownGraphic.cs index 777ec9e1d9..c659d2ce19 100644 --- a/Content.Client/UserInterface/CooldownGraphic.cs +++ b/Content.Client/UserInterface/CooldownGraphic.cs @@ -30,6 +30,7 @@ namespace Content.Client.UserInterface protected override void Draw(DrawingHandleScreen handle) { + Span x = stackalloc float[10]; Color color; var lerp = 1f - MathF.Abs(Progress); // for future bikeshedding purposes diff --git a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs index 4f6b309bf7..3eb3821634 100644 --- a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs +++ b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs @@ -81,8 +81,8 @@ namespace Content.IntegrationTests.Tests.Disposal var disposalTrunk = entityManager.SpawnEntity("DisposalTrunk", disposalUnit.Transform.MapPosition); // Test for components existing - Assert.True(disposalUnit.TryGetComponent(out unit)); - Assert.True(disposalTrunk.TryGetComponent(out entry)); + Assert.True(disposalUnit.TryGetComponent(out unit!)); + Assert.True(disposalTrunk.TryGetComponent(out entry!)); // Can't insert, unanchored and unpowered var disposalUnitAnchorable = disposalUnit.GetComponent(); @@ -92,8 +92,8 @@ namespace Content.IntegrationTests.Tests.Disposal // Anchor the disposal unit await disposalUnitAnchorable.TryAnchor(human, null, true); - Assert.True(disposalUnit.TryGetComponent(out AnchorableComponent anchorableUnit)); - Assert.True(await anchorableUnit.TryAnchor(human, wrench)); + Assert.True(disposalUnit.TryGetComponent(out AnchorableComponent? anchorableUnit)); + Assert.True(await anchorableUnit!.TryAnchor(human, wrench)); Assert.True(unit.Anchored); // No power @@ -118,8 +118,8 @@ namespace Content.IntegrationTests.Tests.Disposal Flush(unit, false, entry, human, wrench); // Remove power need - Assert.True(disposalUnit.TryGetComponent(out PowerReceiverComponent power)); - power.NeedsPower = false; + Assert.True(disposalUnit.TryGetComponent(out PowerReceiverComponent? power)); + power!.NeedsPower = false; Assert.True(unit.Powered); // Flush with a mob and an item diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs b/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs index 7ae95a83af..e55218ef09 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs @@ -41,13 +41,13 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement // Test for climb components existing // Players and tables should have these in their prototypes. - Assert.True(human.TryGetComponent(out climbing), "Human has no climbing"); - Assert.True(table.TryGetComponent(out climbable), "Table has no climbable"); + Assert.True(human.TryGetComponent(out climbing!), "Human has no climbing"); + Assert.True(table.TryGetComponent(out climbable!), "Table has no climbable"); // Now let's make the player enter a climbing transitioning state. climbing.IsClimbing = true; climbing.TryMoveTo(human.Transform.WorldPosition, table.Transform.WorldPosition); - human.TryGetComponent(out ICollidableComponent body); + var body = human.GetComponent(); Assert.True(body.HasController(), "Player has no ClimbController"); diff --git a/Content.Server/Body/BodyCommands.cs b/Content.Server/Body/BodyCommands.cs index 89d6355203..9809a5845f 100644 --- a/Content.Server/Body/BodyCommands.cs +++ b/Content.Server/Body/BodyCommands.cs @@ -32,7 +32,7 @@ namespace Content.Server.Body return; } - if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent body)) + if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent? body)) { var random = IoCManager.Resolve(); var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}"; @@ -72,7 +72,7 @@ namespace Content.Server.Body return; } - if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent body)) + if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent? body)) { var random = IoCManager.Resolve(); var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}"; @@ -119,7 +119,7 @@ namespace Content.Server.Body return; } - if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent body)) + if (!player.AttachedEntity.TryGetComponent(out BodyManagerComponent? body)) { var random = IoCManager.Resolve(); var text = $"You have no body{(random.Prob(0.2f) ? " and you must scream." : ".")}"; diff --git a/Content.Server/Body/Mechanisms/Behaviors/HeartBehavior.cs b/Content.Server/Body/Mechanisms/Behaviors/HeartBehavior.cs index 51366583bd..2229357bfc 100644 --- a/Content.Server/Body/Mechanisms/Behaviors/HeartBehavior.cs +++ b/Content.Server/Body/Mechanisms/Behaviors/HeartBehavior.cs @@ -19,7 +19,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors base.PreMetabolism(frameTime); if (Mechanism.Body == null || - !Mechanism.Body.Owner.TryGetComponent(out BloodstreamComponent bloodstream)) + !Mechanism.Body.Owner.TryGetComponent(out BloodstreamComponent? bloodstream)) { return; } diff --git a/Content.Server/Body/Mechanisms/Behaviors/LungBehavior.cs b/Content.Server/Body/Mechanisms/Behaviors/LungBehavior.cs index 675cc37e76..bc2591c387 100644 --- a/Content.Server/Body/Mechanisms/Behaviors/LungBehavior.cs +++ b/Content.Server/Body/Mechanisms/Behaviors/LungBehavior.cs @@ -16,7 +16,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors base.PreMetabolism(frameTime); if (Mechanism.Body == null || - !Mechanism.Body.Owner.TryGetComponent(out LungComponent lung)) + !Mechanism.Body.Owner.TryGetComponent(out LungComponent? lung)) { return; } diff --git a/Content.Server/Body/Mechanisms/Behaviors/StomachBehavior.cs b/Content.Server/Body/Mechanisms/Behaviors/StomachBehavior.cs index ae1e17b49b..ce6a2bcf43 100644 --- a/Content.Server/Body/Mechanisms/Behaviors/StomachBehavior.cs +++ b/Content.Server/Body/Mechanisms/Behaviors/StomachBehavior.cs @@ -18,7 +18,7 @@ namespace Content.Server.Body.Mechanisms.Behaviors base.PreMetabolism(frameTime); if (Mechanism.Body == null || - !Mechanism.Body.Owner.TryGetComponent(out StomachComponent stomach)) + !Mechanism.Body.Owner.TryGetComponent(out StomachComponent? stomach)) { return; } diff --git a/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs b/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs index 4ebfcd20bd..c861074d34 100644 --- a/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs +++ b/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs @@ -71,16 +71,16 @@ namespace Content.Server.GameObjects.Components.Access public static ICollection FindAccessTags(IEntity entity) { - if (entity.TryGetComponent(out IAccess accessComponent)) + if (entity.TryGetComponent(out IAccess? accessComponent)) { return accessComponent.Tags; } - if (entity.TryGetComponent(out IHandsComponent handsComponent)) + if (entity.TryGetComponent(out IHandsComponent? handsComponent)) { var activeHandEntity = handsComponent.GetActiveHand?.Owner; if (activeHandEntity != null && - activeHandEntity.TryGetComponent(out IAccess handAccessComponent)) + activeHandEntity.TryGetComponent(out IAccess? handAccessComponent)) { return handAccessComponent.Tags; } @@ -90,11 +90,11 @@ namespace Content.Server.GameObjects.Components.Access return Array.Empty(); } - if (entity.TryGetComponent(out InventoryComponent inventoryComponent)) + if (entity.TryGetComponent(out InventoryComponent? inventoryComponent)) { if (inventoryComponent.HasSlot(EquipmentSlotDefines.Slots.IDCARD) && inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent item) && - item.Owner.TryGetComponent(out IAccess idAccessComponent) + item.Owner.TryGetComponent(out IAccess? idAccessComponent) ) { return idAccessComponent.Tags; diff --git a/Content.Server/GameObjects/Components/AnchorableComponent.cs b/Content.Server/GameObjects/Components/AnchorableComponent.cs index 9837ac04cb..224ce59886 100644 --- a/Content.Server/GameObjects/Components/AnchorableComponent.cs +++ b/Content.Server/GameObjects/Components/AnchorableComponent.cs @@ -34,7 +34,7 @@ namespace Content.Server.GameObjects.Components if (!force) { if (utilizing == null || - !utilizing.TryGetComponent(out ToolComponent tool) || + !utilizing.TryGetComponent(out ToolComponent? tool) || !(await tool.UseTool(user, Owner, 0.5f, ToolQuality.Anchoring))) { return false; @@ -93,7 +93,7 @@ namespace Content.Server.GameObjects.Components /// true if toggled, false otherwise private async Task TryToggleAnchor(IEntity user, IEntity? utilizing = null, bool force = false) { - if (!Owner.TryGetComponent(out ICollidableComponent collidable)) + if (!Owner.TryGetComponent(out ICollidableComponent? collidable)) { return false; } diff --git a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 066bc0940a..2a6a2be135 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -116,7 +116,7 @@ namespace Content.Server.GameObjects.Components.Atmos { _pressureDanger = GasAnalyzerDanger.Nominal; } - + Dirty(); _timeSinceSync = 0f; } @@ -131,11 +131,11 @@ namespace Content.Server.GameObjects.Components.Atmos if (session.AttachedEntity == null) return; - if (!session.AttachedEntity.TryGetComponent(out IHandsComponent handsComponent)) + if (!session.AttachedEntity.TryGetComponent(out IHandsComponent? handsComponent)) return; var activeHandEntity = handsComponent?.GetActiveHand?.Owner; - if (activeHandEntity == null || !activeHandEntity.TryGetComponent(out GasAnalyzerComponent gasAnalyzer)) + if (activeHandEntity == null || !activeHandEntity.TryGetComponent(out GasAnalyzerComponent? gasAnalyzer)) { return; } @@ -147,7 +147,7 @@ namespace Content.Server.GameObjects.Components.Atmos // Check if position is out of range => don't update if (!_position.Value.InRange(_mapManager, pos, SharedInteractionSystem.InteractionRange)) return; - + pos = _position.Value; } @@ -195,7 +195,7 @@ namespace Content.Server.GameObjects.Components.Atmos return; } - if (!player.TryGetComponent(out IHandsComponent handsComponent)) + if (!player.TryGetComponent(out IHandsComponent? handsComponent)) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, Loc.GetString("You have no hands.")); @@ -203,7 +203,7 @@ namespace Content.Server.GameObjects.Components.Atmos } var activeHandEntity = handsComponent.GetActiveHand?.Owner; - if (activeHandEntity == null || !activeHandEntity.TryGetComponent(out GasAnalyzerComponent gasAnalyzer)) + if (activeHandEntity == null || !activeHandEntity.TryGetComponent(out GasAnalyzerComponent? gasAnalyzer)) { _notifyManager.PopupMessage(serverMsg.Session.AttachedEntity, serverMsg.Session.AttachedEntity, @@ -225,7 +225,7 @@ namespace Content.Server.GameObjects.Components.Atmos return; } - if (eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (eventArgs.User.TryGetComponent(out IActorComponent? actor)) { OpenInterface(actor.playerSession, eventArgs.ClickLocation); //TODO: show other sprite when ui open? @@ -236,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Atmos void IDropped.Dropped(DroppedEventArgs eventArgs) { - if (eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (eventArgs.User.TryGetComponent(out IActorComponent? actor)) { CloseInterface(actor.playerSession); //TODO: if other sprite is shown, change again @@ -245,7 +245,7 @@ namespace Content.Server.GameObjects.Components.Atmos bool IUse.UseEntity(UseEntityEventArgs eventArgs) { - if (eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (eventArgs.User.TryGetComponent(out IActorComponent? actor)) { OpenInterface(actor.playerSession); //TODO: show other sprite when ui open? diff --git a/Content.Server/GameObjects/Components/Body/BodyManagerComponent.cs b/Content.Server/GameObjects/Components/Body/BodyManagerComponent.cs index ac2f427299..5c14e4da0c 100644 --- a/Content.Server/GameObjects/Components/Body/BodyManagerComponent.cs +++ b/Content.Server/GameObjects/Components/Body/BodyManagerComponent.cs @@ -272,7 +272,7 @@ namespace Content.Server.GameObjects.Components.Body private void CalculateSpeed() { - if (!Owner.TryGetComponent(out MovementSpeedModifierComponent playerMover)) + if (!Owner.TryGetComponent(out MovementSpeedModifierComponent? playerMover)) { return; } diff --git a/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs b/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs index 877a0c2727..fcb1144b47 100644 --- a/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs +++ b/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs @@ -112,7 +112,7 @@ namespace Content.Server.GameObjects.Components.Buckle /// private void BuckleStatus() { - if (Owner.TryGetComponent(out ServerStatusEffectsComponent status)) + if (Owner.TryGetComponent(out ServerStatusEffectsComponent? status)) { status.ChangeStatusEffectIcon(StatusEffect.Buckled, Buckled @@ -291,7 +291,7 @@ namespace Content.Server.GameObjects.Components.Buckle return false; } - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(BuckleVisuals.Buckled, true); } @@ -359,12 +359,12 @@ namespace Content.Server.GameObjects.Components.Buckle Owner.Transform.WorldRotation = oldBuckledTo.Owner.Transform.WorldRotation; } - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(BuckleVisuals.Buckled, false); } - if (Owner.TryGetComponent(out StunnableComponent stunnable) && stunnable.KnockedDown) + if (Owner.TryGetComponent(out StunnableComponent? stunnable) && stunnable.KnockedDown) { StandingStateHelper.Down(Owner); } @@ -373,14 +373,14 @@ namespace Content.Server.GameObjects.Components.Buckle StandingStateHelper.Standing(Owner); } - if (Owner.TryGetComponent(out MobStateManagerComponent stateManager)) + if (Owner.TryGetComponent(out MobStateManagerComponent? stateManager)) { stateManager.CurrentMobState.EnterState(Owner); } BuckleStatus(); - if (oldBuckledTo.Owner.TryGetComponent(out StrapComponent strap)) + if (oldBuckledTo.Owner.TryGetComponent(out StrapComponent? strap)) { strap.Remove(this); _entitySystem.GetEntitySystem() @@ -535,7 +535,7 @@ namespace Content.Server.GameObjects.Components.Buckle _entityManager.EventBus.UnsubscribeEvents(this); if (BuckledTo != null && - BuckledTo.Owner.TryGetComponent(out StrapComponent strap)) + BuckledTo.Owner.TryGetComponent(out StrapComponent? strap)) { strap.Remove(this); } @@ -552,7 +552,7 @@ namespace Content.Server.GameObjects.Components.Buckle if (BuckledTo != null && Owner.Transform.WorldRotation.GetCardinalDir() == Direction.North && - BuckledTo.Owner.TryGetComponent(out SpriteComponent strapSprite)) + BuckledTo.Owner.TryGetComponent(out SpriteComponent? strapSprite)) { drawDepth = strapSprite.DrawDepth - 1; } diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index 9e263f5795..ca6445e5e6 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -159,7 +159,7 @@ namespace Content.Server.GameObjects.Components.Cargo void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (!eventArgs.User.TryGetComponent(out IActorComponent? actor)) { return; } diff --git a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs index ab636c4fe4..689e3f8bea 100644 --- a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs +++ b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs @@ -60,7 +60,7 @@ namespace Content.Server.GameObjects.Components.Conveyor { _state = value; - if (!Owner.TryGetComponent(out AppearanceComponent appearance)) + if (!Owner.TryGetComponent(out AppearanceComponent? appearance)) { return; } @@ -93,7 +93,7 @@ namespace Content.Server.GameObjects.Components.Conveyor return false; } - if (Owner.TryGetComponent(out PowerReceiverComponent receiver) && + if (Owner.TryGetComponent(out PowerReceiverComponent? receiver) && !receiver.Powered) { return false; @@ -114,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Conveyor return false; } - if (!entity.TryGetComponent(out ICollidableComponent collidable) || + if (!entity.TryGetComponent(out ICollidableComponent? collidable) || collidable.Anchored) { return false; @@ -155,7 +155,7 @@ namespace Content.Server.GameObjects.Components.Conveyor continue; } - if (entity.TryGetComponent(out ICollidableComponent collidable)) + if (entity.TryGetComponent(out ICollidableComponent? collidable)) { var controller = collidable.EnsureController(); controller.Move(direction, _speed * frameTime); @@ -225,7 +225,7 @@ namespace Content.Server.GameObjects.Components.Conveyor continue; } - if (!@switch.TryGetComponent(out ConveyorSwitchComponent component)) + if (!@switch.TryGetComponent(out ConveyorSwitchComponent? component)) { continue; } @@ -247,13 +247,13 @@ namespace Content.Server.GameObjects.Components.Conveyor async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (eventArgs.Using.TryGetComponent(out ConveyorSwitchComponent conveyorSwitch)) + if (eventArgs.Using.TryGetComponent(out ConveyorSwitchComponent? conveyorSwitch)) { conveyorSwitch.Connect(this, eventArgs.User); return true; } - if (eventArgs.Using.TryGetComponent(out ToolComponent tool)) + if (eventArgs.Using.TryGetComponent(out ToolComponent? tool)) { return await ToolUsed(eventArgs.User, tool); } diff --git a/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs b/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs index 3c06575fd2..ae5e2c3aa1 100644 --- a/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs +++ b/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs @@ -34,7 +34,7 @@ namespace Content.Server.GameObjects.Components.Conveyor { _state = value; - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(ConveyorVisuals.State, value); } @@ -145,7 +145,7 @@ namespace Content.Server.GameObjects.Components.Conveyor continue; } - if (!conveyor.TryGetComponent(out ConveyorComponent component)) + if (!conveyor.TryGetComponent(out ConveyorComponent? component)) { continue; } @@ -172,7 +172,7 @@ namespace Content.Server.GameObjects.Components.Conveyor continue; } - if (!@switch.TryGetComponent(out ConveyorSwitchComponent component)) + if (!@switch.TryGetComponent(out ConveyorSwitchComponent? component)) { continue; } @@ -196,13 +196,13 @@ namespace Content.Server.GameObjects.Components.Conveyor async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (eventArgs.Using.TryGetComponent(out ConveyorComponent conveyor)) + if (eventArgs.Using.TryGetComponent(out ConveyorComponent? conveyor)) { Connect(conveyor, eventArgs.User); return true; } - if (eventArgs.Using.TryGetComponent(out ConveyorSwitchComponent otherSwitch)) + if (eventArgs.Using.TryGetComponent(out ConveyorSwitchComponent? otherSwitch)) { SyncWith(otherSwitch, eventArgs.User); return true; diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalCommands.cs b/Content.Server/GameObjects/Components/Disposal/DisposalCommands.cs index 5401182b5b..238b31c737 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalCommands.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalCommands.cs @@ -41,7 +41,7 @@ namespace Content.Server.GameObjects.Components.Disposal return; } - if (!entity.TryGetComponent(out IDisposalTubeComponent tube)) + if (!entity.TryGetComponent(out IDisposalTubeComponent? tube)) { shell.SendText(player, Loc.GetString("Entity with uid {0} doesn't have a {1} component", id, nameof(IDisposalTubeComponent))); return; diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs index b07efbdef1..838cf933d2 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs @@ -56,7 +56,7 @@ namespace Content.Server.GameObjects.Components.Disposal return false; } - if (!entity.TryGetComponent(out ICollidableComponent collidable) || + if (!entity.TryGetComponent(out ICollidableComponent? collidable) || !collidable.CanCollide) { return false; @@ -73,7 +73,7 @@ namespace Content.Server.GameObjects.Components.Disposal return false; } - if (entity.TryGetComponent(out ICollidableComponent collidable)) + if (entity.TryGetComponent(out ICollidableComponent? collidable)) { collidable.CanCollide = false; } @@ -105,7 +105,7 @@ namespace Content.Server.GameObjects.Components.Disposal foreach (var entity in _contents.ContainedEntities.ToArray()) { - if (entity.TryGetComponent(out ICollidableComponent collidable)) + if (entity.TryGetComponent(out ICollidableComponent? collidable)) { collidable.CanCollide = true; } diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs index 37b2f2275e..94dccce0a7 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs @@ -44,7 +44,7 @@ namespace Content.Server.GameObjects.Components.Disposal [ViewVariables] private bool Anchored => - !Owner.TryGetComponent(out CollidableComponent collidable) || + !Owner.TryGetComponent(out CollidableComponent? collidable) || collidable.Anchored; /// @@ -71,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Disposal var snapGrid = Owner.GetComponent(); var tube = snapGrid .GetInDir(nextDirection) - .Select(x => x.TryGetComponent(out IDisposalTubeComponent c) ? c : null) + .Select(x => x.TryGetComponent(out IDisposalTubeComponent? c) ? c : null) .FirstOrDefault(x => x != null && x != this); if (tube == null) @@ -153,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Disposal foreach (var entity in Contents.ContainedEntities.ToArray()) { - if (!entity.TryGetComponent(out DisposalHolderComponent holder)) + if (!entity.TryGetComponent(out DisposalHolderComponent? holder)) { continue; } @@ -171,7 +171,7 @@ namespace Content.Server.GameObjects.Components.Disposal private void UpdateVisualState() { - if (!Owner.TryGetComponent(out AppearanceComponent appearance)) + if (!Owner.TryGetComponent(out AppearanceComponent? appearance)) { return; } @@ -187,7 +187,7 @@ namespace Content.Server.GameObjects.Components.Disposal private void AnchoredChanged() { - if (!Owner.TryGetComponent(out CollidableComponent collidable)) + if (!Owner.TryGetComponent(out CollidableComponent? collidable)) { return; } diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 2849bb3c16..2e420ef91e 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -86,12 +86,12 @@ namespace Content.Server.GameObjects.Components.Disposal [ViewVariables] public bool Powered => - !Owner.TryGetComponent(out PowerReceiverComponent receiver) || + !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] public bool Anchored => - !Owner.TryGetComponent(out CollidableComponent collidable) || + !Owner.TryGetComponent(out CollidableComponent? collidable) || collidable.Anchored; [ViewVariables] @@ -122,7 +122,7 @@ namespace Content.Server.GameObjects.Components.Disposal return false; } - if (!entity.TryGetComponent(out ICollidableComponent collidable) || + if (!entity.TryGetComponent(out ICollidableComponent? collidable) || !collidable.CanCollide) { return false; @@ -159,7 +159,7 @@ namespace Content.Server.GameObjects.Components.Disposal { TryQueueEngage(); - if (entity.TryGetComponent(out IActorComponent actor)) + if (entity.TryGetComponent(out IActorComponent? actor)) { _userInterface.Close(actor.playerSession); } @@ -181,7 +181,7 @@ namespace Content.Server.GameObjects.Components.Disposal private bool TryDrop(IEntity user, IEntity entity) { - if (!user.TryGetComponent(out HandsComponent hands)) + if (!user.TryGetComponent(out HandsComponent? hands)) { return false; } @@ -273,7 +273,7 @@ namespace Content.Server.GameObjects.Components.Disposal private void TogglePower() { - if (!Owner.TryGetComponent(out PowerReceiverComponent receiver)) + if (!Owner.TryGetComponent(out PowerReceiverComponent? receiver)) { return; } @@ -352,7 +352,7 @@ namespace Content.Server.GameObjects.Components.Disposal private void UpdateVisualState(bool flush) { - if (!Owner.TryGetComponent(out AppearanceComponent appearance)) + if (!Owner.TryGetComponent(out AppearanceComponent? appearance)) { return; } @@ -488,7 +488,7 @@ namespace Content.Server.GameObjects.Components.Disposal var collidable = Owner.EnsureComponent(); collidable.AnchoredChanged += UpdateVisualState; - if (Owner.TryGetComponent(out PowerReceiverComponent receiver)) + if (Owner.TryGetComponent(out PowerReceiverComponent? receiver)) { receiver.OnPowerStateChanged += PowerStateChanged; } @@ -498,12 +498,12 @@ namespace Content.Server.GameObjects.Components.Disposal public override void OnRemove() { - if (Owner.TryGetComponent(out ICollidableComponent collidable)) + if (Owner.TryGetComponent(out ICollidableComponent? collidable)) { collidable.AnchoredChanged -= UpdateVisualState; } - if (Owner.TryGetComponent(out PowerReceiverComponent receiver)) + if (Owner.TryGetComponent(out PowerReceiverComponent? receiver)) { receiver.OnPowerStateChanged -= PowerStateChanged; } @@ -530,7 +530,7 @@ namespace Content.Server.GameObjects.Components.Disposal switch (message) { case RelayMovementEntityMessage msg: - if (!msg.Entity.TryGetComponent(out HandsComponent hands) || + if (!msg.Entity.TryGetComponent(out HandsComponent? hands) || hands.Count == 0 || _gameTiming.CurTime < _lastExitAttempt + ExitAttemptDelay) { @@ -559,7 +559,7 @@ namespace Content.Server.GameObjects.Components.Disposal return false; } - if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (!eventArgs.User.TryGetComponent(out IActorComponent? actor)) { return false; } diff --git a/Content.Server/GameObjects/Components/DoAfterComponent.cs b/Content.Server/GameObjects/Components/DoAfterComponent.cs index d77fc080d0..2013028ae6 100644 --- a/Content.Server/GameObjects/Components/DoAfterComponent.cs +++ b/Content.Server/GameObjects/Components/DoAfterComponent.cs @@ -60,7 +60,7 @@ namespace Content.Server.GameObjects.Components { connectedClient = null; - if (!Owner.TryGetComponent(out IActorComponent actorComponent)) + if (!Owner.TryGetComponent(out IActorComponent? actorComponent)) { return false; } diff --git a/Content.Server/GameObjects/Components/Fluids/SpillHelper.cs b/Content.Server/GameObjects/Components/Fluids/SpillHelper.cs index 5b85924b8d..e616a7f5f0 100644 --- a/Content.Server/GameObjects/Components/Fluids/SpillHelper.cs +++ b/Content.Server/GameObjects/Components/Fluids/SpillHelper.cs @@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Fluids foreach (var spillEntity in entityManager.GetEntitiesAt(spillTileMapGrid.ParentMapId, spillGridCoords.Position)) { - if (!spillEntity.TryGetComponent(out PuddleComponent puddleComponent)) + if (!spillEntity.TryGetComponent(out PuddleComponent? puddleComponent)) { continue; } diff --git a/Content.Server/GameObjects/Components/GUI/HandsComponent.cs b/Content.Server/GameObjects/Components/GUI/HandsComponent.cs index 572e504f53..69fe0be734 100644 --- a/Content.Server/GameObjects/Components/GUI/HandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/HandsComponent.cs @@ -711,7 +711,7 @@ namespace Content.Server.GameObjects.Components.GUI Dirty(); - if (!message.Entity.TryGetComponent(out ICollidableComponent collidable)) + if (!message.Entity.TryGetComponent(out ICollidableComponent? collidable)) { return; } @@ -724,13 +724,13 @@ namespace Content.Server.GameObjects.Components.GUI private void AddPullingStatuses(IEntity pulled) { - if (pulled.TryGetComponent(out ServerStatusEffectsComponent pulledStatus)) + if (pulled.TryGetComponent(out ServerStatusEffectsComponent? pulledStatus)) { pulledStatus.ChangeStatusEffectIcon(StatusEffect.Pulled, "/Textures/Interface/StatusEffects/Pull/pulled.png"); } - if (Owner.TryGetComponent(out ServerStatusEffectsComponent ownerStatus)) + if (Owner.TryGetComponent(out ServerStatusEffectsComponent? ownerStatus)) { ownerStatus.ChangeStatusEffectIcon(StatusEffect.Pulling, "/Textures/Interface/StatusEffects/Pull/pulling.png"); @@ -739,12 +739,12 @@ namespace Content.Server.GameObjects.Components.GUI private void RemovePullingStatuses(IEntity pulled) { - if (pulled.TryGetComponent(out ServerStatusEffectsComponent pulledStatus)) + if (pulled.TryGetComponent(out ServerStatusEffectsComponent? pulledStatus)) { pulledStatus.RemoveStatusEffect(StatusEffect.Pulled); } - if (Owner.TryGetComponent(out ServerStatusEffectsComponent ownerStatus)) + if (Owner.TryGetComponent(out ServerStatusEffectsComponent? ownerStatus)) { ownerStatus.RemoveStatusEffect(StatusEffect.Pulling); } diff --git a/Content.Server/GameObjects/Components/Interactable/ToolCommands.cs b/Content.Server/GameObjects/Components/Interactable/ToolCommands.cs index 3008f11d44..9dd07ff951 100644 --- a/Content.Server/GameObjects/Components/Interactable/ToolCommands.cs +++ b/Content.Server/GameObjects/Components/Interactable/ToolCommands.cs @@ -106,7 +106,7 @@ namespace Content.Server.GameObjects.Components.Interactable foreach (var entity in entities) { - if (entity.TryGetComponent(out AnchorableComponent anchorable)) + if (entity.TryGetComponent(out AnchorableComponent? anchorable)) { anchorable.TryAnchor(player.AttachedEntity, force: true); } @@ -151,7 +151,7 @@ namespace Content.Server.GameObjects.Components.Interactable foreach (var entity in entities) { - if (entity.TryGetComponent(out AnchorableComponent anchorable)) + if (entity.TryGetComponent(out AnchorableComponent? anchorable)) { anchorable.TryUnAnchor(player.AttachedEntity, force: true); } diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs index 96aef95564..24272ed72c 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs @@ -101,13 +101,13 @@ namespace Content.Server.GameObjects.Components.Items.Storage { EnsureInitialCalculated(); - if (entity.TryGetComponent(out ServerStorageComponent storage) && + if (entity.TryGetComponent(out ServerStorageComponent? storage) && storage._storageCapacityMax >= _storageCapacityMax) { return false; } - if (entity.TryGetComponent(out StorableComponent store) && + if (entity.TryGetComponent(out StorableComponent? store) && store.ObjectSize > _storageCapacityMax - _storageUsed) { return false; @@ -164,7 +164,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage Logger.DebugS(LoggerName, $"Storage (UID {Owner.Uid}) had entity (UID {message.Entity.Uid}) removed from it."); - if (!message.Entity.TryGetComponent(out StorableComponent storable)) + if (!message.Entity.TryGetComponent(out StorableComponent? storable)) { Logger.WarningS(LoggerName, $"Removed entity {message.Entity.Uid} without a StorableComponent from storage {Owner.Uid} at {Owner.Transform.MapPosition}"); @@ -186,7 +186,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage { EnsureInitialCalculated(); - if (!player.TryGetComponent(out IHandsComponent hands) || + if (!player.TryGetComponent(out IHandsComponent? hands) || hands.GetActiveHand == null) { return false; @@ -317,7 +317,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage private void UpdateDoorState() { - if (Owner.TryGetComponent(out AppearanceComponent appearance)) + if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(StorageVisuals.Open, SubscribedSessions.Count != 0); } @@ -382,7 +382,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage var item = entity.GetComponent(); if (item == null || - !player.TryGetComponent(out HandsComponent hands)) + !player.TryGetComponent(out HandsComponent? hands)) { break; } @@ -506,7 +506,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage bool IDragDrop.CanDragDrop(DragDropEventArgs eventArgs) { - return eventArgs.Target.TryGetComponent(out PlaceableSurfaceComponent placeable) && + return eventArgs.Target.TryGetComponent(out PlaceableSurfaceComponent? placeable) && placeable.IsPlaceable; } diff --git a/Content.Server/GameObjects/Components/Mobs/MindComponent.cs b/Content.Server/GameObjects/Components/Mobs/MindComponent.cs index fd2fed7f5f..b5f9eba7e1 100644 --- a/Content.Server/GameObjects/Components/Mobs/MindComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/MindComponent.cs @@ -79,7 +79,7 @@ namespace Content.Server.GameObjects.Components.Mobs var visiting = Mind?.VisitingEntity; if (visiting != null) { - if (visiting.TryGetComponent(out GhostComponent ghost)) + if (visiting.TryGetComponent(out GhostComponent? ghost)) { ghost.CanReturnToBody = false; } diff --git a/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs b/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs index 85bb04b84b..1b39598c2f 100644 --- a/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs @@ -71,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Movement _entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity)) { //TODO: Switch to shuttle component - if (!gridEntity.TryGetComponent(out ICollidableComponent collidable)) + if (!gridEntity.TryGetComponent(out ICollidableComponent? collidable)) { collidable = gridEntity.AddComponent(); collidable.Mass = 1; @@ -137,9 +137,9 @@ namespace Content.Server.GameObjects.Components.Movement private void SetController(IEntity entity) { if (_controller != null || - !entity.TryGetComponent(out MindComponent mind) || + !entity.TryGetComponent(out MindComponent? mind) || mind.Mind == null || - !Owner.TryGetComponent(out ServerStatusEffectsComponent status)) + !Owner.TryGetComponent(out ServerStatusEffectsComponent? status)) { return; } @@ -179,17 +179,17 @@ namespace Content.Server.GameObjects.Components.Movement /// The entity to update private void UpdateRemovedEntity(IEntity entity) { - if (Owner.TryGetComponent(out ServerStatusEffectsComponent status)) + if (Owner.TryGetComponent(out ServerStatusEffectsComponent? status)) { status.RemoveStatusEffect(StatusEffect.Piloting); } - if (entity.TryGetComponent(out MindComponent mind)) + if (entity.TryGetComponent(out MindComponent? mind)) { mind.Mind?.UnVisit(); } - if (entity.TryGetComponent(out BuckleComponent buckle)) + if (entity.TryGetComponent(out BuckleComponent? buckle)) { buckle.TryUnbuckle(entity, true); } diff --git a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs index 91bc92bb3c..1aa9f2f776 100644 --- a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs +++ b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs @@ -164,7 +164,7 @@ namespace Content.Server.GameObjects.Components.PDA void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (!eventArgs.User.TryGetComponent(out IActorComponent? actor)) { return; } @@ -175,7 +175,7 @@ namespace Content.Server.GameObjects.Components.PDA public bool UseEntity(UseEntityEventArgs eventArgs) { - if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + if (!eventArgs.User.TryGetComponent(out IActorComponent? actor)) { return false; } diff --git a/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs b/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs index 0c95a3d69f..caff655173 100644 --- a/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs +++ b/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs @@ -64,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Pointing { base.Startup(); - if (Owner.TryGetComponent(out SpriteComponent sprite)) + if (Owner.TryGetComponent(out SpriteComponent? sprite)) { sprite.DrawDepth = (int) DrawDepth.Overlays; } diff --git a/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs b/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs index 35706da030..f20f1305d5 100644 --- a/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs +++ b/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs @@ -57,7 +57,7 @@ namespace Content.Server.GameObjects.Components.Pointing private void UpdateAppearance() { if (_chasing == null || - !Owner.TryGetComponent(out AppearanceComponent appearance)) + !Owner.TryGetComponent(out AppearanceComponent? appearance)) { return; } @@ -69,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Pointing { base.Startup(); - if (Owner.TryGetComponent(out SpriteComponent sprite)) + if (Owner.TryGetComponent(out SpriteComponent? sprite)) { sprite.DrawDepth = (int) DrawDepth.Overlays; } diff --git a/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs b/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs index c986fe04dd..ad524e517c 100644 --- a/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs +++ b/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs @@ -24,7 +24,7 @@ namespace Content.Server.GameObjects.Components.Rotatable private void TryFlip(IEntity user) { - if (Owner.TryGetComponent(out ICollidableComponent collidable) && + if (Owner.TryGetComponent(out ICollidableComponent? collidable) && collidable.Anchored) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, user, Loc.GetString("It's stuck.")); diff --git a/Content.Server/GameObjects/Components/WiresComponent.cs b/Content.Server/GameObjects/Components/WiresComponent.cs index d8abb14bc7..6867052599 100644 --- a/Content.Server/GameObjects/Components/WiresComponent.cs +++ b/Content.Server/GameObjects/Components/WiresComponent.cs @@ -373,7 +373,7 @@ namespace Content.Server.GameObjects.Components return; } - if (!player.TryGetComponent(out IHandsComponent handsComponent)) + if (!player.TryGetComponent(out IHandsComponent? handsComponent)) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, Loc.GetString("You have no hands.")); diff --git a/Content.Server/GameObjects/EntitySystems/Atmos/GasTileOverlaySystem.cs b/Content.Server/GameObjects/EntitySystems/Atmos/GasTileOverlaySystem.cs index 456bb14293..f1cb864dbd 100644 --- a/Content.Server/GameObjects/EntitySystems/Atmos/GasTileOverlaySystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Atmos/GasTileOverlaySystem.cs @@ -30,19 +30,19 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos [Robust.Shared.IoC.Dependency] private readonly IPlayerManager _playerManager = default!; [Robust.Shared.IoC.Dependency] private readonly IMapManager _mapManager = default!; [Robust.Shared.IoC.Dependency] private readonly IConfigurationManager _configManager = default!; - + /// /// The tiles that have had their atmos data updated since last tick /// private Dictionary> _invalidTiles = new Dictionary>(); - - private Dictionary _knownPlayerChunks = + + private Dictionary _knownPlayerChunks = new Dictionary(); - + /// /// Gas data stored in chunks to make PVS / bubbling easier. /// - private Dictionary> _overlay = + private Dictionary> _overlay = new Dictionary>(); /// @@ -52,7 +52,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos // Because the gas overlay updates aren't run every tick we need to avoid the pop-in that might occur with // the regular PVS range. private const float RangeOffset = 6.0f; - + /// /// Overlay update ticks per second. /// @@ -164,7 +164,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos var moles = tile.Air.Gases[i]; if (moles < gas.GasMolesVisible) continue; - + var data = new GasData(i, (byte) (FloatMath.Clamp01(moles / gas.GasMolesVisibleMax) * 255)); tileData.Add(data); } @@ -175,7 +175,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { return false; } - + return true; } @@ -187,10 +187,10 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos private List GetChunksInRange(IEntity entity) { var inRange = new List(); - + // This is the max in any direction that we can get a chunk (e.g. max 2 chunks away of data). var (maxXDiff, maxYDiff) = ((int) (_updateRange / ChunkSize) + 1, (int) (_updateRange / ChunkSize) + 1); - + var worldBounds = Box2.CenteredAround(entity.Transform.WorldPosition, new Vector2(_updateRange, _updateRange)); @@ -202,7 +202,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos } var entityTile = grid.GetTileRef(entity.Transform.GridPosition).GridIndices; - + for (var x = -maxXDiff; x <= maxXDiff; x++) { for (var y = -maxYDiff; y <= maxYDiff; y++) @@ -210,7 +210,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos var chunkIndices = GetGasChunkIndices(new MapIndices(entityTile.X + x * ChunkSize, entityTile.Y + y * ChunkSize)); if (!chunks.TryGetValue(chunkIndices, out var chunk)) continue; - + // Now we'll check if it's in range and relevant for us // (e.g. if we're on the very edge of a chunk we may need more chunks). @@ -219,7 +219,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos yDiff > 0 && yDiff > _updateRange || xDiff < 0 && Math.Abs(xDiff + ChunkSize) > _updateRange || yDiff < 0 && Math.Abs(yDiff + ChunkSize) > _updateRange) continue; - + inRange.Add(chunk); } } @@ -237,25 +237,25 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { return; } - + _updateRange = _configManager.GetCVar("net.maxupdaterange") + RangeOffset; - + // TODO: So in the worst case scenario we still have to send a LOT of tile data per tick if there's a fire. // If we go with say 15 tile radius then we have up to 900 tiles to update per tick. // In a saltern fire the worst you'll normally see is around 650 at the moment. // Need a way to fake this more because sending almost 2,000 tile updates per second to even 50 players is... yikes // I mean that's as big as it gets so larger maps will have the same but still, that's a lot of data. - + // Some ways to do this are potentially: splitting fire and gas update data so they don't update at the same time // (gives the illusion of more updates happening), e.g. if gas updates are 3 times a second and fires are 1.6 times a second or something. // Could also look at updating tiles close to us more frequently (e.g. within 1 chunk every tick). // Stuff just out of our viewport we need so when we move it doesn't pop in but it doesn't mean we need to update it every tick. - + AccumulatedFrameTime -= _updateCooldown; var gridAtmosComponents = new Dictionary(); var updatedTiles = new Dictionary>(); - + // So up to this point we've been caching the updated tiles for multiple ticks. // Now we'll go through and check whether the update actually matters for the overlay or not, // and if not then we won't bother sending the data. @@ -263,7 +263,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { var gridEntityId = _mapManager.GetGrid(gridId).GridEntityId; - if (!EntityManager.GetEntity(gridEntityId).TryGetComponent(out GridAtmosphereComponent gam)) + if (!EntityManager.GetEntity(gridEntityId).TryGetComponent(out GridAtmosphereComponent? gam)) { continue; } @@ -286,7 +286,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos tiles = new HashSet(); updatedTiles[chunk] = tiles; } - + updatedTiles[chunk].Add(invalid); chunk.Update(data, invalid); } @@ -306,13 +306,13 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos foreach (var (session, overlay) in _knownPlayerChunks) { if (session.AttachedEntity == null) continue; - + // Get chunks in range and update if we've moved around or the chunks have new overlay data var chunksInRange = GetChunksInRange(session.AttachedEntity); var knownChunks = overlay.GetKnownChunks(); var chunksToRemove = new List(); var chunksToAdd = new List(); - + foreach (var chunk in chunksInRange) { if (!knownChunks.Contains(chunk)) @@ -328,7 +328,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos chunksToRemove.Add(chunk); } } - + foreach (var chunk in chunksToAdd) { var message = overlay.AddChunk(currentTick, chunk); @@ -342,7 +342,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { overlay.RemoveChunk(chunk); } - + var clientInvalids = new Dictionary>(); // Check for any dirty chunks in range and bundle the data to send to the client. @@ -355,7 +355,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos existingData = new List<(MapIndices, GasOverlayData)>(); clientInvalids[chunk.GridIndices] = existingData; } - + chunk.GetData(existingData, invalids); } @@ -370,10 +370,10 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos } private sealed class PlayerGasOverlay { - private readonly Dictionary> _data = + private readonly Dictionary> _data = new Dictionary>(); - - private readonly Dictionary _lastSent = + + private readonly Dictionary _lastSent = new Dictionary(); public GasOverlayMessage UpdateClient(GridId grid, List<(MapIndices, GasOverlayData)> data) @@ -386,11 +386,11 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos _data.Clear(); _lastSent.Clear(); } - + public List GetKnownChunks() { var known = new List(); - + foreach (var (_, chunks) in _data) { foreach (var (_, chunk) in chunks) @@ -414,7 +414,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { return null; } - + _lastSent[chunk] = currentTick; var message = ChunkToMessage(chunk); @@ -444,7 +444,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { // Chunk data should already be up to date. // Only send relevant tiles to client. - + var tileData = new List<(MapIndices, GasOverlayData)>(); for (var x = 0; x < ChunkSize; x++) @@ -467,7 +467,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos { return null; } - + return new GasOverlayMessage(chunk.GridIndices, tileData); } } diff --git a/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs b/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs index 327104a148..a5ffa6e9ce 100644 --- a/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.GameObjects.EntitySystems if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) return null; - return gridEnt.TryGetComponent(out IGridAtmosphereComponent atmos) ? atmos : null; + return gridEnt.TryGetComponent(out IGridAtmosphereComponent? atmos) ? atmos : null; } public override void Update(float frameTime) diff --git a/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfter.cs b/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfter.cs index 3e00f334fd..2f45195624 100644 --- a/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfter.cs +++ b/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfter.cs @@ -54,7 +54,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter // For this we need to stay on the same hand slot and need the same item in that hand slot // (or if there is no item there we need to keep it free). - if (eventArgs.NeedHand && eventArgs.User.TryGetComponent(out HandsComponent handsComponent)) + if (eventArgs.NeedHand && eventArgs.User.TryGetComponent(out HandsComponent? handsComponent)) { _activeHand = handsComponent.ActiveHand; _activeItem = handsComponent.GetActiveHand; @@ -126,7 +126,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter } if (EventArgs.BreakOnStun && - EventArgs.User.TryGetComponent(out StunnableComponent stunnableComponent) && + EventArgs.User.TryGetComponent(out StunnableComponent? stunnableComponent) && stunnableComponent.Stunned) { return true; @@ -134,7 +134,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter if (EventArgs.NeedHand) { - if (!EventArgs.User.TryGetComponent(out HandsComponent handsComponent)) + if (!EventArgs.User.TryGetComponent(out HandsComponent? handsComponent)) { // If we had a hand but no longer have it that's still a paddlin' if (_activeHand != null) diff --git a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs index 84250d4e91..41ded38a03 100644 --- a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs @@ -83,7 +83,7 @@ namespace Content.Server.GameObjects.EntitySystems ev.Entity.RemoveComponent(); } - if (ev.Entity.TryGetComponent(out ICollidableComponent physics) && + if (ev.Entity.TryGetComponent(out ICollidableComponent? physics) && physics.TryGetController(out MoverController controller)) { controller.StopMoving(); diff --git a/Content.Server/GameObjects/EntitySystems/PointingSystem.cs b/Content.Server/GameObjects/EntitySystems/PointingSystem.cs index d27857954f..28efbd4f8a 100644 --- a/Content.Server/GameObjects/EntitySystems/PointingSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/PointingSystem.cs @@ -116,7 +116,7 @@ namespace Content.Server.GameObjects.EntitySystems var arrow = EntityManager.SpawnEntity("pointingarrow", coords); - if (player.TryGetComponent(out VisibilityComponent playerVisibility)) + if (player.TryGetComponent(out VisibilityComponent? playerVisibility)) { var arrowVisibility = arrow.EnsureComponent(); arrowVisibility.Layer = playerVisibility.Layer; diff --git a/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs b/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs index 6d47299c4d..a3b3794d3e 100644 --- a/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs @@ -56,7 +56,7 @@ namespace Content.Shared.GameObjects.Components.Movement { get { - if (Owner.TryGetComponent(out MovementSpeedModifierComponent component)) + if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component)) { return component.CurrentWalkSpeed; } @@ -69,7 +69,7 @@ namespace Content.Shared.GameObjects.Components.Movement { get { - if (Owner.TryGetComponent(out MovementSpeedModifierComponent component)) + if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component)) { return component.CurrentSprintSpeed; } diff --git a/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs b/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs index 49f77ad735..57c66cb3f5 100644 --- a/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs @@ -179,7 +179,7 @@ namespace Content.Shared.GameObjects.EntitySystems } private static bool TryGetAttachedComponent(ICommonSession? session, [MaybeNullWhen(false)] out T component) - where T : IComponent + where T : class, IComponent { component = default; @@ -188,7 +188,7 @@ namespace Content.Shared.GameObjects.EntitySystems if (ent == null || !ent.IsValid()) return false; - if (!ent.TryGetComponent(out T comp)) + if (!ent.TryGetComponent(out T? comp)) return false; component = comp;