diff --git a/Content.Client/AI/ClientPathfindingDebugSystem.cs b/Content.Client/AI/ClientPathfindingDebugSystem.cs index 8a36759486..1ea8bd4fe4 100644 --- a/Content.Client/AI/ClientPathfindingDebugSystem.cs +++ b/Content.Client/AI/ClientPathfindingDebugSystem.cs @@ -179,6 +179,7 @@ namespace Content.Client.AI { private readonly IEyeManager _eyeManager; private readonly IPlayerManager _playerManager; + private readonly IEntityManager _entities; // TODO: Add a box like the debug one and show the most recent path stuff public override OverlaySpace Space => OverlaySpace.ScreenSpace; @@ -214,6 +215,7 @@ namespace Content.Client.AI _shader = IoCManager.Resolve().Index("unshaded").Instance(); _eyeManager = IoCManager.Resolve(); _playerManager = IoCManager.Resolve(); + _entities = IoCManager.Resolve(); } #region Graph @@ -286,8 +288,8 @@ namespace Content.Client.AI private void DrawCachedRegions(DrawingHandleScreen screenHandle, Box2 viewport) { - var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (attachedEntity == default || !CachedRegions.TryGetValue(IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID, out var entityRegions)) + var transform = _entities.GetComponentOrNull(_playerManager.LocalPlayer?.ControlledEntity); + if (transform == null || !CachedRegions.TryGetValue(transform.GridID, out var entityRegions)) { return; } @@ -305,7 +307,7 @@ namespace Content.Client.AI screenTile.X + 15.0f, screenTile.Y + 15.0f); - screenHandle.DrawRect(box, _cachedRegionColors[IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID][region]); + screenHandle.DrawRect(box, _cachedRegionColors[transform.GridID][region]); } } } @@ -336,7 +338,8 @@ namespace Content.Client.AI private void DrawRegions(DrawingHandleScreen screenHandle, Box2 viewport) { var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (attachedEntity == default || !Regions.TryGetValue(IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID, out var entityRegions)) + if (!_entities.TryGetComponent(attachedEntity, out TransformComponent? transform) || + !Regions.TryGetValue(transform.GridID, out var entityRegions)) { return; } @@ -356,7 +359,7 @@ namespace Content.Client.AI screenTile.X + 15.0f, screenTile.Y + 15.0f); - screenHandle.DrawRect(box, _regionColors[IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID][chunk][region]); + screenHandle.DrawRect(box, _regionColors[_entities.GetComponent(attachedEntity.Value).GridID][chunk][region]); } } } diff --git a/Content.Client/Actions/ActionsSystem.cs b/Content.Client/Actions/ActionsSystem.cs index 51a62b0d64..e56112b2c5 100644 --- a/Content.Client/Actions/ActionsSystem.cs +++ b/Content.Client/Actions/ActionsSystem.cs @@ -84,7 +84,7 @@ namespace Content.Client.Actions return new((in PointerInputCmdHandler.PointerInputCmdArgs args) => { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == default || + if (playerEntity == null || !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return false; actionsComponent.HandleHotbarKeybind(slot, args); @@ -98,8 +98,7 @@ namespace Content.Client.Actions return new((in PointerInputCmdHandler.PointerInputCmdArgs args) => { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == default || - !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return false; + if (!EntityManager.TryGetComponent(playerEntity, out var actionsComponent)) return false; actionsComponent.HandleChangeHotbarKeybind(hotbar, args); return true; @@ -110,8 +109,7 @@ namespace Content.Client.Actions private bool TargetingOnUse(in PointerInputCmdHandler.PointerInputCmdArgs args) { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == default || - !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return false; + if (!EntityManager.TryGetComponent(playerEntity, out var actionsComponent)) return false; return actionsComponent.TargetingOnUse(args); } @@ -119,8 +117,7 @@ namespace Content.Client.Actions private void ToggleActionsMenu() { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == default || - !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return; + if (!EntityManager.TryGetComponent(playerEntity, out var actionsComponent)) return; actionsComponent.ToggleActionsMenu(); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs index 7bd4aedb00..b7ecf9704f 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs @@ -23,8 +23,8 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab _data = IoCManager.Resolve().GetAllGrids().Where(g => (int) g.Index != 0); foreach (var grid in _data) { - var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.GridID; + var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridID; GridOptions.AddItem($"{grid.Index} {(playerGrid == grid.Index ? " (Current)" : "")}"); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs index 1490897877..0549543d6e 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs @@ -27,8 +27,8 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab _gridData = IoCManager.Resolve().GetAllGrids().Where(g => (int) g.Index != 0); foreach (var grid in _gridData) { - var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.GridID; + var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridID; GridOptions.AddItem($"{grid.Index} {(playerGrid == grid.Index ? " (Current)" : "")}"); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs index a675818876..f89863dd7b 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs @@ -27,8 +27,8 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab _gridData = IoCManager.Resolve().GetAllGrids().Where(g => (int) g.Index != 0); foreach (var grid in _gridData) { - var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.GridID; + var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridID; GridOptions.AddItem($"{grid.Index} {(playerGrid == grid.Index ? " (Current)" : "")}"); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs index cfd19850f3..72458fefdd 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs @@ -23,8 +23,8 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab _data = IoCManager.Resolve().GetAllGrids().Where(g => (int) g.Index != 0); foreach (var grid in _data) { - var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.GridID; + var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridID; GridOptions.AddItem($"{grid.Index} {(playerGrid == grid.Index ? " (Current)" : "")}"); } diff --git a/Content.Client/Audio/AmbientSoundSystem.cs b/Content.Client/Audio/AmbientSoundSystem.cs index f4cff46979..f524b7b020 100644 --- a/Content.Client/Audio/AmbientSoundSystem.cs +++ b/Content.Client/Audio/AmbientSoundSystem.cs @@ -90,13 +90,13 @@ namespace Content.Client.Audio _accumulator -= _cooldown; var player = _playerManager.LocalPlayer?.ControlledEntity; - if (player == default) + if (!EntityManager.TryGetComponent(player, out TransformComponent? playerManager)) { ClearSounds(); return; } - var coordinates = EntityManager.GetComponent(player.Value).Coordinates; + var coordinates = playerManager.Coordinates; foreach (var (comp, (stream, _)) in _playingSounds.ToArray()) { diff --git a/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs b/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs index d304009e45..fdc533ed56 100644 --- a/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs +++ b/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs @@ -37,8 +37,7 @@ namespace Content.Client.CharacterInterface private void HandleOpenCharacterMenu() { - if (_playerManager.LocalPlayer?.ControlledEntity == default - || !EntityManager.TryGetComponent(_playerManager.LocalPlayer.ControlledEntity, out CharacterInterfaceComponent? characterInterface)) + if (!EntityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out CharacterInterfaceComponent? characterInterface)) { return; } diff --git a/Content.Client/CombatMode/CombatModeSystem.cs b/Content.Client/CombatMode/CombatModeSystem.cs index 2c1b19f65f..96a3d7da40 100644 --- a/Content.Client/CombatMode/CombatModeSystem.cs +++ b/Content.Client/CombatMode/CombatModeSystem.cs @@ -33,13 +33,8 @@ namespace Content.Client.CombatMode public bool IsInCombatMode() { - var entity = _playerManager.LocalPlayer?.ControlledEntity; - if (entity == default || !EntityManager.TryGetComponent(entity.Value, out CombatModeComponent? combatMode)) - { - return false; - } - - return combatMode.IsInCombatMode; + return EntityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out CombatModeComponent? combatMode) && + combatMode.IsInCombatMode; } private void OnTargetingZoneChanged(TargetingZone obj) @@ -47,4 +42,8 @@ namespace Content.Client.CombatMode EntityManager.RaisePredictiveEvent(new CombatModeSystemMessages.SetTargetZoneMessage(obj)); } } + + public static class A + { + } } diff --git a/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs b/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs index 1bd9093681..46f26dc9e7 100644 --- a/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs +++ b/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs @@ -135,7 +135,7 @@ namespace Content.Client.Instruments.UI var instrument = _owner.Instrument; // If either the entity or component are null, return. - if (instrumentEnt == default || instrument == default) + if (instrumentEnt == null || instrument == null) return false; // If we're a handheld instrument, we might be in a container. Get it just in case. diff --git a/Content.Client/Interactable/UnobstructedExtensions.cs b/Content.Client/Interactable/UnobstructedExtensions.cs index 5d0a3b6f4e..9d320c276a 100644 --- a/Content.Client/Interactable/UnobstructedExtensions.cs +++ b/Content.Client/Interactable/UnobstructedExtensions.cs @@ -78,13 +78,13 @@ namespace Content.Client.Interactable bool popup = false) { var originEntity = origin.ControlledEntity; - if (originEntity == default) + if (originEntity == null) { // TODO: Take into account the player's camera position? return false; } - return SharedInteractionSystem.InRangeUnobstructed(originEntity, other, range, collisionMask, predicate, + return SharedInteractionSystem.InRangeUnobstructed(originEntity.Value, other, range, collisionMask, predicate, ignoreInsideBlocker, popup); } } diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs index d5ed253eba..71e960c4fd 100644 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ b/Content.Client/Storage/ClientStorageComponent.cs @@ -256,7 +256,7 @@ namespace Content.Client.Storage { var controlledEntity = players.LocalPlayer?.ControlledEntity; - if (controlledEntity != default && entities.HasComponent(controlledEntity.Value)) + if (entities.HasComponent(controlledEntity)) { #pragma warning disable 618 StorageEntity.SendNetworkMessage(new InsertEntityMessage()); diff --git a/Content.Client/Suspicion/TraitorOverlay.cs b/Content.Client/Suspicion/TraitorOverlay.cs index a816da46e4..1666673da6 100644 --- a/Content.Client/Suspicion/TraitorOverlay.cs +++ b/Content.Client/Suspicion/TraitorOverlay.cs @@ -41,7 +41,7 @@ namespace Content.Client.Suspicion var viewport = _eyeManager.GetWorldViewport(); var ent = _playerManager.LocalPlayer?.ControlledEntity; - if (ent == default || _entityManager.TryGetComponent(ent.Value, out SuspicionRoleComponent? sus) != true) + if (_entityManager.TryGetComponent(ent, out SuspicionRoleComponent? sus) != true) { return; } diff --git a/Content.Client/Tabletop/TabletopSystem.cs b/Content.Client/Tabletop/TabletopSystem.cs index 2c10d80a93..a71d83e224 100644 --- a/Content.Client/Tabletop/TabletopSystem.cs +++ b/Content.Client/Tabletop/TabletopSystem.cs @@ -52,7 +52,7 @@ namespace Content.Client.Tabletop public override void Update(float frameTime) { // If there is no player entity, return - if (_playerManager.LocalPlayer is not {ControlledEntity: var playerEntity}) return; + if (_playerManager.LocalPlayer is not {ControlledEntity: { } playerEntity}) return; if (StunnedOrNoHands(playerEntity)) { @@ -167,7 +167,8 @@ namespace Content.Client.Tabletop private bool OnMouseDown(in PointerInputCmdArgs args) { // Return if no player entity - if (_playerManager.LocalPlayer is not { ControlledEntity: var playerEntity}) return false; + if (_playerManager.LocalPlayer is not {ControlledEntity: { } playerEntity}) + return false; // Return if can not see table or stunned/no hands if (!CanSeeTable(playerEntity, _table) || StunnedOrNoHands(playerEntity)) diff --git a/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs b/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs index a6bea89365..542ccadaae 100644 --- a/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs +++ b/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs @@ -47,7 +47,7 @@ namespace Content.Client.Weapons.Ranged } var entity = _playerManager.LocalPlayer?.ControlledEntity; - if (entity == default || !EntityManager.TryGetComponent(entity.Value, out SharedHandsComponent? hands)) + if (!EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands)) { return; } diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs b/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs index 447b2b0d73..9c4d8a8d1c 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs @@ -51,7 +51,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs Assert.NotNull(local); var controlled = local.ControlledEntity; Assert.NotNull(controlled); - var alertsComponent = IoCManager.Resolve().GetComponent(controlled); + var alertsComponent = IoCManager.Resolve().GetComponent(controlled.Value); Assert.NotNull(alertsComponent); // find the alertsui @@ -86,7 +86,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs Assert.NotNull(local); var controlled = local.ControlledEntity; Assert.NotNull(controlled); - var alertsComponent = IoCManager.Resolve().GetComponent(controlled); + var alertsComponent = IoCManager.Resolve().GetComponent(controlled.Value); Assert.NotNull(alertsComponent); // find the alertsui diff --git a/Content.Server/Chat/Commands/SayCommand.cs b/Content.Server/Chat/Commands/SayCommand.cs index 890e2d3581..5f658f25fb 100644 --- a/Content.Server/Chat/Commands/SayCommand.cs +++ b/Content.Server/Chat/Commands/SayCommand.cs @@ -56,17 +56,17 @@ namespace Content.Server.Chat.Commands return; } - if (mindComponent.OwnedEntity == default) + if (mindComponent.OwnedEntity is not {Valid: true} owned) { shell.WriteError("You don't have an entity!"); return; } - var emote = chatSanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity.Value, out var sanitized, out var emoteStr); + var emote = chatSanitizer.TrySanitizeOutSmilies(message, owned, out var sanitized, out var emoteStr); if (sanitized.Length != 0) - chat.EntitySay(mindComponent.OwnedEntity.Value, sanitized); + chat.EntitySay(owned, sanitized); if (emote) - chat.EntityMe(mindComponent.OwnedEntity.Value, emoteStr!); + chat.EntityMe(owned, emoteStr!); } } diff --git a/Content.Server/Chemistry/Components/HyposprayComponent.cs b/Content.Server/Chemistry/Components/HyposprayComponent.cs index 48ca60ff6f..4eb54373da 100644 --- a/Content.Server/Chemistry/Components/HyposprayComponent.cs +++ b/Content.Server/Chemistry/Components/HyposprayComponent.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Chemistry.EntitySystems; using Content.Server.Interaction.Components; @@ -42,7 +43,7 @@ namespace Content.Server.Chemistry.Components public bool TryDoInject(EntityUid? target, EntityUid user) { - if (target == default || !EligibleEntity(target.Value)) + if (!EligibleEntity(target)) return false; string? msgFormat = null; @@ -110,7 +111,7 @@ namespace Content.Server.Chemistry.Components EntitySystem.Get().TryAddSolution(target.Value, targetSolution, removedSolution); - static bool EligibleEntity(EntityUid entity) + static bool EligibleEntity([NotNullWhen(true)] EntityUid? entity) { // TODO: Does checking for BodyComponent make sense as a "can be hypospray'd" tag? // In SS13 the hypospray ONLY works on mobs, NOT beakers or anything else. diff --git a/Content.Server/GameTicking/Presets/GamePreset.cs b/Content.Server/GameTicking/Presets/GamePreset.cs index 55eb5b0b26..fa6ef63a06 100644 --- a/Content.Server/GameTicking/Presets/GamePreset.cs +++ b/Content.Server/GameTicking/Presets/GamePreset.cs @@ -41,7 +41,8 @@ namespace Content.Server.GameTicking.Presets { var playerEntity = mind.OwnedEntity; - if (playerEntity != default && IoCManager.Resolve().HasComponent(playerEntity.Value)) + var entities = IoCManager.Resolve(); + if (entities.HasComponent(playerEntity)) return false; if (mind.VisitingEntity != default) @@ -62,7 +63,7 @@ namespace Content.Server.GameTicking.Presets // (If the mob survives, that's a bug. Ghosting is kept regardless.) var canReturn = canReturnGlobal && mind.CharacterDeadPhysically; - if (playerEntity != default && canReturnGlobal && IoCManager.Resolve().TryGetComponent(playerEntity.Value, out MobStateComponent? mobState)) + if (canReturnGlobal && entities.TryGetComponent(playerEntity, out MobStateComponent? mobState)) { if (mobState.IsCritical()) { @@ -71,7 +72,7 @@ namespace Content.Server.GameTicking.Presets //todo: what if they dont breathe lol //cry deeply DamageSpecifier damage = new(IoCManager.Resolve().Index("Asphyxiation"), 200); - EntitySystem.Get().TryChangeDamage(playerEntity.Value, damage, true); + EntitySystem.Get().TryChangeDamage(playerEntity, damage, true); } } @@ -82,9 +83,9 @@ namespace Content.Server.GameTicking.Presets // If all else fails, it'll default to the default entity prototype name, "observer". // However, that should rarely happen. if(!string.IsNullOrWhiteSpace(mind.CharacterName)) - IoCManager.Resolve().GetComponent(ghost).EntityName = mind.CharacterName; + entities.GetComponent(ghost).EntityName = mind.CharacterName; else if (!string.IsNullOrWhiteSpace(mind.Session?.Name)) - IoCManager.Resolve().GetComponent(ghost).EntityName = mind.Session.Name; + entities.GetComponent(ghost).EntityName = mind.Session.Name; var ghostComponent = IoCManager.Resolve().GetComponent(ghost); diff --git a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs index 22df8b5b09..8e240b9bc8 100644 --- a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs +++ b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs @@ -121,7 +121,7 @@ namespace Content.Server.GameTicking.Presets } // Finally, it would be preferrable if they spawned as far away from other players as reasonably possible. - if (mind.OwnedEntity != default && FindAnyIsolatedSpawnLocation(mind, out var bestTarget)) + if (mind.OwnedEntity != null && FindAnyIsolatedSpawnLocation(mind, out var bestTarget)) { _entityManager.GetComponent(mind.OwnedEntity.Value).Coordinates = bestTarget; } diff --git a/Content.Server/Mind/Mind.cs b/Content.Server/Mind/Mind.cs index eb473652ed..e2981f8bcb 100644 --- a/Content.Server/Mind/Mind.cs +++ b/Content.Server/Mind/Mind.cs @@ -153,9 +153,7 @@ namespace Content.Server.Mind // (If being a borg or AI counts as dead, then this is highly likely, as it's still the same Mind for practical purposes.) // This can be null if they're deleted (spike / brain nom) - if (OwnedEntity == default) - return true; - var targetMobState = IoCManager.Resolve().GetComponentOrNull(OwnedEntity.Value); + var targetMobState = IoCManager.Resolve().GetComponentOrNull(OwnedEntity); // This can be null if it's a brain (this happens very often) // Brains are the result of gibbing so should definitely count as dead if (targetMobState == null) @@ -184,7 +182,7 @@ namespace Content.Server.Mind role.Greet(); var message = new RoleAddedEvent(role); - if (OwnedEntity != default) + if (OwnedEntity != null) { IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity.Value, message); } @@ -210,7 +208,7 @@ namespace Content.Server.Mind var message = new RoleRemovedEvent(role); - if (OwnedEntity != default) + if (OwnedEntity != null) { IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity.Value, message); } diff --git a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs index b6e1066808..f2ec0a8801 100644 --- a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs @@ -113,7 +113,7 @@ namespace Content.Server.Nutrition.EntitySystems private void AfterInteract(EntityUid uid, DrinkComponent component, AfterInteractEvent args) { - if (args.Handled || args.Target == default) + if (args.Handled || args.Target == null) return; if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User)) diff --git a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs index dd4aa14bc8..25565410fe 100644 --- a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs @@ -81,7 +81,7 @@ namespace Content.Server.Nutrition.EntitySystems /// private void OnFeedFood(EntityUid uid, FoodComponent foodComponent, AfterInteractEvent args) { - if (args.Handled || args.Target == default) + if (args.Handled || args.Target == null) return; if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User)) diff --git a/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs b/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs index 1a364d2a4c..af744699a8 100644 --- a/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs @@ -32,7 +32,7 @@ namespace Content.Server.Nutrition.EntitySystems /// private void OnAfterInteract(EntityUid uid, UtensilComponent component, AfterInteractEvent ev) { - if (ev.Target == default) + if (ev.Target == null) return; if (TryUseUtensil(ev.User, ev.Target.Value, component)) diff --git a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs index eb60a825f1..2d625a6b14 100644 --- a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs +++ b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs @@ -24,7 +24,9 @@ namespace Content.Server.Objectives.Conditions if (entity == default) return false; - return (IoCManager.Resolve().GetComponentOrNull(entity.Value)?.IsAlive() ?? false) && mc.Mind != mind; + return entityMgr.TryGetComponent(entity, out MobStateComponent mobState) && + mobState.IsAlive() && + mc.Mind != mind; }).Select(mc => mc.Mind).ToList(); return new KillRandomPersonCondition {Target = IoCManager.Resolve().Pick(allHumans)}; } diff --git a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs index 8b18f94646..6ca9c2e1bd 100644 --- a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs +++ b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs @@ -32,7 +32,7 @@ namespace Content.Server.Verbs.Commands EntityUid playerEntity = default; if (!int.TryParse(args[0], out var intPlayerUid)) { - if (args[0] == "self" && shell.Player?.AttachedEntity != default) + if (args[0] == "self" && shell.Player?.AttachedEntity != null) { playerEntity = shell.Player.AttachedEntity; } diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs index 080f2acd58..5e47ac28db 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs @@ -140,9 +140,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components { for (var i = 0; i < Math.Max(10, rangedMagazine.ShotsLeft); i++) { - var ammo = rangedMagazine.TakeAmmo(); - - if (!ammo.Valid) + if (rangedMagazine.TakeAmmo() is not {Valid: true} ammo) { continue; } diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs index 7ffde4d0c0..fca41f78d0 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs @@ -22,6 +22,8 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public class RangedMagazineComponent : Component, IMapInit, IInteractUsing, IUse, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "RangedMagazine"; private readonly Stack _spawnedAmmo = new(); @@ -77,7 +79,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { _appearanceComponent = appearanceComponent; } @@ -93,7 +95,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public bool TryInsertAmmo(EntityUid user, EntityUid ammo) { - if (!IoCManager.Resolve().TryGetComponent(ammo, out AmmoComponent? ammoComponent)) + if (!_entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent)) { return false; } @@ -116,7 +118,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return true; } - public EntityUid TakeAmmo() + public EntityUid? TakeAmmo() { EntityUid ammo = default; // If anything's spawned use that first, otherwise use the fill prototype as a fallback (if we have spawn count left) @@ -128,7 +130,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components else if (_unspawnedCount > 0) { _unspawnedCount--; - ammo = IoCManager.Resolve().SpawnEntity(_fillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + ammo = _entities.SpawnEntity(_fillPrototype, _entities.GetComponent(Owner).Coordinates); } UpdateAppearance(); @@ -142,21 +144,20 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components bool IUse.UseEntity(UseEntityEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out HandsComponent? handsComponent)) + if (!_entities.TryGetComponent(eventArgs.User, out HandsComponent? handsComponent)) { return false; } - var ammo = TakeAmmo(); - if (ammo == null) + if (TakeAmmo() is not {Valid: true} ammo) { return false; } - var itemComponent = IoCManager.Resolve().GetComponent(ammo); + var itemComponent = _entities.GetComponent(ammo); if (!handsComponent.CanPutInHand(itemComponent)) { - IoCManager.Resolve().GetComponent(ammo).Coordinates = IoCManager.Resolve().GetComponent(eventArgs.User).Coordinates; + _entities.GetComponent(ammo).Coordinates = _entities.GetComponent(eventArgs.User).Coordinates; ServerRangedBarrelComponent.EjectCasing(ammo); } else diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs index 9f9556de2b..ef7be5aa9d 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs @@ -58,7 +58,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (MagazineContainer.ContainedEntity is {Valid: true} magazine) { - count += IoCManager.Resolve().GetComponent(magazine).ShotsLeft; + count += _entities.GetComponent(magazine).ShotsLeft; } return count; @@ -73,7 +73,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components var count = 1; if (MagazineContainer.ContainedEntity is {Valid: true} magazine) { - count += IoCManager.Resolve().GetComponent(magazine).Capacity; + count += _entities.GetComponent(magazine).Capacity; } return count; @@ -153,7 +153,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { (int, int)? count = null; if (MagazineContainer.ContainedEntity is {Valid: true} magazine && - IoCManager.Resolve().TryGetComponent(magazine, out RangedMagazineComponent? rangedMagazineComponent)) + _entities.TryGetComponent(magazine, out RangedMagazineComponent? rangedMagazineComponent)) { count = (rangedMagazineComponent.ShotsLeft, rangedMagazineComponent.Capacity); } @@ -179,7 +179,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (!existing && _magFillPrototype != null) { - var magEntity = IoCManager.Resolve().SpawnEntity(_magFillPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var magEntity = _entities.SpawnEntity(_magFillPrototype, _entities.GetComponent(Owner).Coordinates); MagazineContainer.Insert(magEntity); } Dirty(); @@ -205,7 +205,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components var entity = _chamberContainer.ContainedEntity ?? default; Cycle(); - return entity != default ? IoCManager.Resolve().GetComponent(entity).TakeBullet(spawnAt) : null; + return entity != default ? _entities.GetComponent(entity).TakeBullet(spawnAt) : null; } private void Cycle(bool manual = false) @@ -272,17 +272,16 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public bool TryEjectChamber() { - var chamberEntity = _chamberContainer.ContainedEntity; - if (chamberEntity != null) + if (_chamberContainer.ContainedEntity is {Valid: true} chamberEntity) { - if (!_chamberContainer.Remove(chamberEntity.Value)) + if (!_chamberContainer.Remove(chamberEntity)) { return false; } - var ammoComponent = IoCManager.Resolve().GetComponent(chamberEntity.Value); + var ammoComponent = _entities.GetComponent(chamberEntity); if (!ammoComponent.Caseless) { - EjectCasing(chamberEntity.Value); + EjectCasing(chamberEntity); } return true; } @@ -298,16 +297,15 @@ 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 nextRound = magazine != default ? IoCManager.Resolve().GetComponent(magazine).TakeAmmo() : default; - if (nextRound == default) + if (_entities.GetComponentOrNull(magazine)?.TakeAmmo() is not {Valid: true} nextRound) { return false; } _chamberContainer.Insert(nextRound); - if (_autoEjectMag && magazine != null && IoCManager.Resolve().GetComponent(magazine).ShotsLeft == 0) + if (_autoEjectMag && magazine != null && _entities.GetComponent(magazine).ShotsLeft == 0) { SoundSystem.Play(Filter.Pvs(Owner), _soundAutoEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2)); @@ -337,9 +335,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components MagazineContainer.Remove(mag.Value); SoundSystem.Play(Filter.Pvs(Owner), _soundMagEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2)); - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent)) + if (_entities.TryGetComponent(user, out HandsComponent? handsComponent)) { - handsComponent.PutInHandOrDrop(IoCManager.Resolve().GetComponent(mag.Value)); + handsComponent.PutInHandOrDrop(_entities.GetComponent(mag.Value)); } Dirty(); @@ -348,7 +346,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public bool CanInsertMagazine(EntityUid user, EntityUid magazine, bool quiet = true) { - if (!IoCManager.Resolve().TryGetComponent(magazine, out RangedMagazineComponent? magazineComponent)) + if (!_entities.TryGetComponent(magazine, out RangedMagazineComponent? magazineComponent)) { return false; } @@ -402,7 +400,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components } // Insert 1 ammo - if (IoCManager.Resolve().TryGetComponent(eventArgs.Using, out AmmoComponent? ammoComponent)) + if (_entities.TryGetComponent(eventArgs.Using, out AmmoComponent? ammoComponent)) { if (!BoltOpen) { diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs index 599394c6d6..ac08b84681 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs @@ -223,8 +223,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components FireHitscan(shooter, hitscan, angle); } else if (_entities.HasComponent(projectile) && - ammo != default && - _entities.TryGetComponent(ammo.Value, out AmmoComponent? ammoComponent)) + _entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent)) { FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo.Value); diff --git a/Content.Shared/CombatMode/SharedCombatModeSystem.cs b/Content.Shared/CombatMode/SharedCombatModeSystem.cs index e16829c479..3cdb3231d0 100644 --- a/Content.Shared/CombatMode/SharedCombatModeSystem.cs +++ b/Content.Shared/CombatMode/SharedCombatModeSystem.cs @@ -16,7 +16,7 @@ namespace Content.Shared.CombatMode { var entity = eventArgs.SenderSession.AttachedEntity; - if (entity == null || !EntityManager.TryGetComponent(entity, out SharedCombatModeComponent? combatModeComponent)) + if (entity == default || !EntityManager.TryGetComponent(entity, out SharedCombatModeComponent? combatModeComponent)) { return; } diff --git a/Content.Shared/Damage/Systems/DamageableSystem.cs b/Content.Shared/Damage/Systems/DamageableSystem.cs index 74f6730101..927656abc5 100644 --- a/Content.Shared/Damage/Systems/DamageableSystem.cs +++ b/Content.Shared/Damage/Systems/DamageableSystem.cs @@ -145,7 +145,7 @@ namespace Content.Shared.Damage /// Returns a with information about the actual damage changes. This will be /// null if the user had no applicable components that can take damage. /// - public DamageSpecifier? TryChangeDamage(EntityUid uid, DamageSpecifier damage, bool ignoreResistances = false, + public DamageSpecifier? TryChangeDamage(EntityUid? uid, DamageSpecifier damage, bool ignoreResistances = false, bool interruptsDoAfters = true, bool logChange = false) { if (!EntityManager.TryGetComponent(uid, out var damageable)) @@ -175,7 +175,7 @@ namespace Content.Shared.Damage } var ev = new DamageModifyEvent(damage); - RaiseLocalEvent(uid, ev, false); + RaiseLocalEvent(uid.Value, ev, false); damage = ev.Damage; if (damage.Empty)