From 8b09d55b106c5001386b621ffe65a2bad2fe9ecc Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Thu, 9 Dec 2021 12:29:27 +0100 Subject: [PATCH] Fix weird lifestage autorefactors. --- Content.Client/AI/ClientAiDebugSystem.cs | 2 +- Content.Client/Chat/UI/SpeechBubble.cs | 2 +- Content.Client/ContextMenu/UI/EntityMenuPresenter.cs | 4 ++-- Content.Client/DoAfter/DoAfterSystem.cs | 3 +-- Content.Client/DragDrop/DragDropSystem.cs | 10 ++++------ Content.Client/HealthOverlay/HealthOverlaySystem.cs | 4 ++-- Content.Client/HealthOverlay/UI/HealthOverlayGui.cs | 5 ++--- Content.Client/Items/Managers/ItemSlotManager.cs | 3 +-- .../Kitchen/UI/MicrowaveBoundUserInterface.cs | 7 +------ Content.Client/Viewport/GameScreenBase.cs | 2 +- Content.Client/Weapons/Melee/MeleeWeaponSystem.cs | 2 +- .../Operators/Nutrition/UseDrinkInInventoryOperator.cs | 2 +- .../Operators/Nutrition/UseFoodInInventoryOperator.cs | 2 +- Content.Server/AI/Pathfinding/PathfindingSystem.cs | 2 +- Content.Server/AI/Steering/AiSteeringSystem.cs | 4 ++-- .../Considerations/Movement/TargetDistanceCon.cs | 3 +-- Content.Server/Atmos/Components/GasTankComponent.cs | 2 +- .../Botany/Components/PlantHolderComponent.cs | 2 +- .../Cargo/Components/CargoTelepadComponent.cs | 2 +- .../Components/FoamSolutionAreaEffectComponent.cs | 2 +- .../Components/SmokeSolutionAreaEffectComponent.cs | 2 +- Content.Server/Conveyor/ConveyorSystem.cs | 2 +- .../EntitySystems/DisassembleOnActivateSystem.cs | 2 +- .../EntitySystems/SpawnAfterInteractSystem.cs | 2 +- .../Explosion/Components/ClusterFlashComponent.cs | 2 +- .../Explosion/EntitySystems/ExplosionSystem.cs | 2 +- Content.Server/Fluids/Components/BucketComponent.cs | 7 ++----- Content.Server/Fluids/Components/MopComponent.cs | 2 +- Content.Server/Fluids/EntitySystems/PuddleSystem.cs | 2 +- Content.Server/Ghost/GhostSystem.cs | 6 ++---- Content.Server/Inventory/InventoryHelpers.cs | 2 +- .../Components/CrematoriumEntityStorageComponent.cs | 2 +- .../Morgue/Components/MorgueTrayComponent.cs | 4 +++- .../PneumaticCannon/PneumaticCannonSystem.cs | 4 ++-- .../Projectiles/Components/HitscanComponent.cs | 2 +- Content.Server/Radiation/RadiationPulseComponent.cs | 2 +- Content.Server/Radiation/RadiationPulseSystem.cs | 2 +- .../Spawners/Components/RandomSpawnerComponent.cs | 2 +- Content.Server/StationEvents/Events/GasLeak.cs | 2 +- Content.Server/Weapon/Melee/MeleeWeaponSystem.cs | 2 +- .../Systems/SharedPullingStateManagementSystem.cs | 2 +- Content.Shared/Pulling/Systems/SharedPullingSystem.cs | 2 +- Content.Shared/Throwing/ThrownItemSystem.cs | 2 +- 43 files changed, 55 insertions(+), 69 deletions(-) diff --git a/Content.Client/AI/ClientAiDebugSystem.cs b/Content.Client/AI/ClientAiDebugSystem.cs index eb7501ee82..81a81b4fe9 100644 --- a/Content.Client/AI/ClientAiDebugSystem.cs +++ b/Content.Client/AI/ClientAiDebugSystem.cs @@ -40,7 +40,7 @@ namespace Content.Client.AI var deletedEntities = new List(0); foreach (var (entity, panel) in _aiBoxes) { - if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (Deleted(entity)) { deletedEntities.Add(entity); continue; diff --git a/Content.Client/Chat/UI/SpeechBubble.cs b/Content.Client/Chat/UI/SpeechBubble.cs index ead441ceef..2d0c8c8ad2 100644 --- a/Content.Client/Chat/UI/SpeechBubble.cs +++ b/Content.Client/Chat/UI/SpeechBubble.cs @@ -118,7 +118,7 @@ namespace Content.Client.Chat.UI Modulate = Color.White; } - if ((!_entityManager.EntityExists(_senderEntity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_senderEntity).EntityLifeStage) >= EntityLifeStage.Deleted || _timeLeft <= 0) + if (_entityManager.Deleted(_senderEntity) || _timeLeft <= 0) { // Timer spawn to prevent concurrent modification exception. Timer.Spawn(0, Die); diff --git a/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs b/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs index 5c32919c5c..033e23b333 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs @@ -187,7 +187,7 @@ namespace Content.Client.ContextMenu.UI foreach (var entity in Elements.Keys.ToList()) { - if ((!_entityManager.EntityExists(entity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || !ignoreFov && !_examineSystem.CanExamine(player, entity)) + if (_entityManager.Deleted(entity) || !ignoreFov && !_examineSystem.CanExamine(player, entity)) RemoveEntity(entity); } } @@ -338,7 +338,7 @@ namespace Content.Client.ContextMenu.UI if (entityElement.Entity != default) { - if (!((!_entityManager.EntityExists(entityElement.Entity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(entityElement.Entity).EntityLifeStage) >= EntityLifeStage.Deleted)) + if (!_entityManager.Deleted(entityElement.Entity)) return entityElement.Entity; continue; } diff --git a/Content.Client/DoAfter/DoAfterSystem.cs b/Content.Client/DoAfter/DoAfterSystem.cs index 0ae04263fe..7f0be712bd 100644 --- a/Content.Client/DoAfter/DoAfterSystem.cs +++ b/Content.Client/DoAfter/DoAfterSystem.cs @@ -51,8 +51,7 @@ namespace Content.Client.DoAfter var currentTime = _gameTiming.CurTime; // Can't see any I guess? - if (_attachedEntity is not {Valid: true} entity || - (!EntityManager.EntityExists(_attachedEntity.Value) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_attachedEntity is not {Valid: true} entity || Deleted(entity)) return; var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f); diff --git a/Content.Client/DragDrop/DragDropSystem.cs b/Content.Client/DragDrop/DragDropSystem.cs index f803ea78a4..3ebef14401 100644 --- a/Content.Client/DragDrop/DragDropSystem.cs +++ b/Content.Client/DragDrop/DragDropSystem.cs @@ -175,7 +175,7 @@ namespace Content.Client.DragDrop private bool OnBeginDrag() { - if (_dragDropHelper.Dragged == default || (!EntityManager.EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_dragDropHelper.Dragged == default || Deleted(_dragDropHelper.Dragged)) { // something happened to the clicked entity or we moved the mouse off the target so // we shouldn't replay the original click @@ -212,7 +212,7 @@ namespace Content.Client.DragDrop private bool OnContinueDrag(float frameTime) { - if (_dragDropHelper.Dragged == default || (!EntityManager.EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_dragDropHelper.Dragged == default || Deleted(_dragDropHelper.Dragged)) { return false; } @@ -352,10 +352,8 @@ namespace Content.Client.DragDrop private void HighlightTargets() { - if (_dragDropHelper.Dragged == default || - (!EntityManager.EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted || - _dragShadow == default || - (!EntityManager.EntityExists(_dragShadow) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_dragShadow).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_dragDropHelper.Dragged == default || Deleted(_dragDropHelper.Dragged) || + _dragShadow == default || Deleted(_dragShadow)) { Logger.Warning("Programming error. Can't highlight drag and drop targets, not currently " + "dragging anything or dragged entity / shadow was deleted."); diff --git a/Content.Client/HealthOverlay/HealthOverlaySystem.cs b/Content.Client/HealthOverlay/HealthOverlaySystem.cs index d7106ae05e..b04d47f77c 100644 --- a/Content.Client/HealthOverlay/HealthOverlaySystem.cs +++ b/Content.Client/HealthOverlay/HealthOverlaySystem.cs @@ -73,7 +73,7 @@ namespace Content.Client.HealthOverlay return; } - if (_attachedEntity == null || (!_entities.EntityExists(_attachedEntity.Value) ? EntityLifeStage.Deleted : _entities.GetComponent(_attachedEntity.Value).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_attachedEntity is not {} ent || Deleted(ent)) { return; } @@ -84,7 +84,7 @@ namespace Content.Client.HealthOverlay { var entity = mobState.Owner; - if (_entities.GetComponent(_attachedEntity.Value).MapID != _entities.GetComponent(entity).MapID || + if (_entities.GetComponent(ent).MapID != _entities.GetComponent(entity).MapID || !viewBox.Contains(_entities.GetComponent(entity).WorldPosition)) { if (_guis.TryGetValue(entity, out var oldGui)) diff --git a/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs b/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs index 3ada93fd88..9d81acac07 100644 --- a/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs +++ b/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs @@ -73,7 +73,7 @@ namespace Content.Client.HealthOverlay.UI private void MoreFrameUpdate(FrameEventArgs args) { - if ((!_entities.EntityExists(Entity) ? EntityLifeStage.Deleted : _entities.GetComponent(Entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_entities.Deleted(Entity)) { return; } @@ -139,8 +139,7 @@ namespace Content.Client.HealthOverlay.UI MoreFrameUpdate(args); - if ((!_entities.EntityExists(Entity) ? EntityLifeStage.Deleted : _entities.GetComponent(Entity).EntityLifeStage) >= EntityLifeStage.Deleted || - _eyeManager.CurrentMap != _entities.GetComponent(Entity).MapID) + if (_entities.Deleted(Entity) || _eyeManager.CurrentMap != _entities.GetComponent(Entity).MapID) { Visible = false; return; diff --git a/Content.Client/Items/Managers/ItemSlotManager.cs b/Content.Client/Items/Managers/ItemSlotManager.cs index e0f708fb68..c8a6171225 100644 --- a/Content.Client/Items/Managers/ItemSlotManager.cs +++ b/Content.Client/Items/Managers/ItemSlotManager.cs @@ -99,8 +99,7 @@ namespace Content.Client.Items.Managers return; } - if (entity == default || - (!_entityManager.EntityExists(entity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || + if (entity == default || _entityManager.Deleted(entity) || !_entityManager.TryGetComponent(entity, out ItemCooldownComponent? cooldown) || !cooldown.CooldownStart.HasValue || !cooldown.CooldownEnd.HasValue) diff --git a/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs b/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs index 85857b6c6f..a92176faa0 100644 --- a/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs +++ b/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs @@ -110,16 +110,11 @@ namespace Content.Client.Kitchen.UI _menu.IngredientsList.Clear(); foreach (var entity in containedSolids) { - if (!_entityManager.EntityExists(entity)) + if (_entityManager.Deleted(entity)) { return; } - if ((!_entityManager.EntityExists(entity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) - { - continue; - } - Texture? texture; if (_entityManager.TryGetComponent(entity, out IconComponent? iconComponent)) { diff --git a/Content.Client/Viewport/GameScreenBase.cs b/Content.Client/Viewport/GameScreenBase.cs index 0dca62e76f..fffcbed06c 100644 --- a/Content.Client/Viewport/GameScreenBase.cs +++ b/Content.Client/Viewport/GameScreenBase.cs @@ -131,7 +131,7 @@ namespace Content.Client.Viewport return; } - if (_lastHoveredEntity != default && !((!_entityManager.EntityExists(_lastHoveredEntity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_lastHoveredEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && + if (_lastHoveredEntity != default && !_entityManager.Deleted(_lastHoveredEntity) && _entityManager.TryGetComponent(_lastHoveredEntity, out outline)) { outline.OnMouseLeave(); diff --git a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs index 7cdc05cba2..c697b87926 100644 --- a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs +++ b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs @@ -52,7 +52,7 @@ namespace Content.Client.Weapons.Melee return; } - if (!((!EntityManager.EntityExists(attacker) ? EntityLifeStage.Deleted : EntityManager.GetComponent(attacker).EntityLifeStage) >= EntityLifeStage.Deleted)) + if (!Deleted(attacker)) { var lunge = attacker.EnsureComponent(); lunge.SetData(msg.Angle); diff --git a/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs b/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs index 6261c9df60..6c3100b4f8 100644 --- a/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs +++ b/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs @@ -32,7 +32,7 @@ namespace Content.Server.AI.Operators.Nutrition var entities = IoCManager.Resolve(); // TODO: Also have this check storage a la backpack etc. - if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || + if (entities.Deleted(_target) || !entities.TryGetComponent(_owner, out HandsComponent? handsComponent) || !entities.TryGetComponent(_target, out ItemComponent? itemComponent)) { diff --git a/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs b/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs index e4912ec3b5..41c940477e 100644 --- a/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs +++ b/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs @@ -31,7 +31,7 @@ namespace Content.Server.AI.Operators.Nutrition var entities = IoCManager.Resolve(); // TODO: Also have this check storage a la backpack etc. - if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || + if (entities.Deleted(_target) || !entities.TryGetComponent(_owner, out HandsComponent? handsComponent) || !entities.TryGetComponent(_target, out ItemComponent? itemComponent)) { diff --git a/Content.Server/AI/Pathfinding/PathfindingSystem.cs b/Content.Server/AI/Pathfinding/PathfindingSystem.cs index f7165e6aec..ba08f2dedb 100644 --- a/Content.Server/AI/Pathfinding/PathfindingSystem.cs +++ b/Content.Server/AI/Pathfinding/PathfindingSystem.cs @@ -264,7 +264,7 @@ namespace Content.Server.AI.Pathfinding /// private void HandleEntityAdd(EntityUid entity) { - if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || + if (Deleted(entity) || _lastKnownPositions.ContainsKey(entity) || !EntityManager.TryGetComponent(entity, out IPhysBody? physics) || !PathfindingNode.IsRelevant(entity, physics)) diff --git a/Content.Server/AI/Steering/AiSteeringSystem.cs b/Content.Server/AI/Steering/AiSteeringSystem.cs index cc46521f09..8941d7cc3a 100644 --- a/Content.Server/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/AI/Steering/AiSteeringSystem.cs @@ -246,7 +246,7 @@ namespace Content.Server.AI.Steering private SteeringStatus Steer(EntityUid entity, IAiSteeringRequest steeringRequest, float frameTime) { // Main optimisation to be done below is the redundant calls and adding more variables - if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || + if (Deleted(entity) || !EntityManager.TryGetComponent(entity, out AiControllerComponent? controller) || !EntitySystem.Get().CanMove(entity) || !EntityManager.GetComponent(entity).GridID.IsValid()) @@ -658,7 +658,7 @@ namespace Content.Server.AI.Steering // err for now we'll just assume the first entity is the center and just add a vector for it //Pathfinding updates are deferred so this may not be done yet. - if ((!EntityManager.EntityExists(physicsEntity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(physicsEntity).EntityLifeStage) >= EntityLifeStage.Deleted) continue; + if (Deleted(physicsEntity)) continue; // if we're moving in the same direction then ignore // So if 2 entities are moving towards each other and both detect a collision they'll both move in the same direction diff --git a/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs index 26c3f83f59..db4bcc0263 100644 --- a/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs +++ b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs @@ -12,8 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Movement var self = context.GetState().GetValue(); var entities = IoCManager.Resolve(); - if (context.GetState().GetValue() is not {Valid: true} target || - (!entities.EntityExists(target) ? EntityLifeStage.Deleted : entities.GetComponent(target).EntityLifeStage) >= EntityLifeStage.Deleted || + if (context.GetState().GetValue() is not {Valid: true} target || entities.Deleted(target) || entities.GetComponent(target).GridID != entities.GetComponent(self).GridID) { return 0.0f; diff --git a/Content.Server/Atmos/Components/GasTankComponent.cs b/Content.Server/Atmos/Components/GasTankComponent.cs index 7f5a81fa2b..b9d5d1a6b6 100644 --- a/Content.Server/Atmos/Components/GasTankComponent.cs +++ b/Content.Server/Atmos/Components/GasTankComponent.cs @@ -232,7 +232,7 @@ namespace Content.Server.Atmos.Components private InternalsComponent? GetInternalsComponent(EntityUid? owner = null) { - if ((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) return null; + if (_entMan.Deleted(Owner)) return null; if (owner != null) return _entMan.GetComponentOrNull(owner.Value); return Owner.TryGetContainer(out var container) ? _entMan.GetComponentOrNull(container.Owner) diff --git a/Content.Server/Botany/Components/PlantHolderComponent.cs b/Content.Server/Botany/Components/PlantHolderComponent.cs index c4bfd821c5..9c15a5e5ab 100644 --- a/Content.Server/Botany/Components/PlantHolderComponent.cs +++ b/Content.Server/Botany/Components/PlantHolderComponent.cs @@ -421,7 +421,7 @@ namespace Content.Server.Botany.Components public bool DoHarvest(EntityUid user) { - if (Seed == null || (!_entMan.EntityExists(user) ? EntityLifeStage.Deleted : _entMan.GetComponent(user).EntityLifeStage) >= EntityLifeStage.Deleted || !EntitySystem.Get().CanInteract(user)) + if (Seed == null || _entMan.Deleted(user) || !EntitySystem.Get().CanInteract(user)) return false; if (Harvest && !Dead) diff --git a/Content.Server/Cargo/Components/CargoTelepadComponent.cs b/Content.Server/Cargo/Components/CargoTelepadComponent.cs index 5efeace76e..b43937af93 100644 --- a/Content.Server/Cargo/Components/CargoTelepadComponent.cs +++ b/Content.Server/Cargo/Components/CargoTelepadComponent.cs @@ -88,7 +88,7 @@ namespace Content.Server.Cargo.Components spriteComponent.LayerSetState(0, "idle"); Owner.SpawnTimer((int) (TeleportDelay * 1000), () => { - if (!Deleted && !((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) && _currentState == CargoTelepadState.Charging && _teleportQueue.Count > 0) + if (!Deleted && !_entMan.Deleted(Owner) && _currentState == CargoTelepadState.Charging && _teleportQueue.Count > 0) { _currentState = CargoTelepadState.Teleporting; if (_entMan.TryGetComponent(Owner, out var spriteComponent) && spriteComponent.LayerCount > 0) diff --git a/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs index 84ae7b91fa..8599d5d773 100644 --- a/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs @@ -70,7 +70,7 @@ namespace Content.Server.Chemistry.Components protected override void OnKill() { - if ((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_entMan.Deleted(Owner)) return; if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { diff --git a/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs index 2220984256..02bdc920c3 100644 --- a/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs @@ -58,7 +58,7 @@ namespace Content.Server.Chemistry.Components protected override void OnKill() { - if ((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_entMan.Deleted(Owner)) return; _entMan.DeleteEntity(Owner); } diff --git a/Content.Server/Conveyor/ConveyorSystem.cs b/Content.Server/Conveyor/ConveyorSystem.cs index 95a3f378fb..91668d58c9 100644 --- a/Content.Server/Conveyor/ConveyorSystem.cs +++ b/Content.Server/Conveyor/ConveyorSystem.cs @@ -132,7 +132,7 @@ namespace Content.Server.Conveyor //todo uuuhhh cache this foreach (var entity in _entityLookup.GetEntitiesIntersecting(comp.Owner, flags: LookupFlags.Approximate)) { - if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (Deleted(entity)) { continue; } diff --git a/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs b/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs index cd12f721ad..28684dc9ca 100644 --- a/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs +++ b/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs @@ -41,7 +41,7 @@ namespace Content.Server.Engineering.EntitySystems component.TokenSource.Cancel(); } - if (component.Deleted || (!EntityManager.EntityExists(component.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(component.Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (component.Deleted || Deleted(component.Owner)) return; var entity = EntityManager.SpawnEntity(component.Prototype, EntityManager.GetComponent(component.Owner).Coordinates); diff --git a/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs b/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs index 5434edf4c1..b7f4037eaf 100644 --- a/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs +++ b/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs @@ -57,7 +57,7 @@ namespace Content.Server.Engineering.EntitySystems return; } - if (component.Deleted || (!EntityManager.EntityExists(component.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(component.Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (component.Deleted || Deleted(component.Owner)) return; if (EntityManager.TryGetComponent(component.Owner, out var stackComp) diff --git a/Content.Server/Explosion/Components/ClusterFlashComponent.cs b/Content.Server/Explosion/Components/ClusterFlashComponent.cs index 1635880c7d..f05d88fa43 100644 --- a/Content.Server/Explosion/Components/ClusterFlashComponent.cs +++ b/Content.Server/Explosion/Components/ClusterFlashComponent.cs @@ -94,7 +94,7 @@ namespace Content.Server.Explosion.Components return false; Owner.SpawnTimer((int) (_delay * 1000), () => { - if ((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_entMan.Deleted(Owner)) return; _countDown = true; var random = IoCManager.Resolve(); diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index f01701a824..0d7e7a76fd 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -130,7 +130,7 @@ namespace Content.Server.Explosion.EntitySystems // and splitted into two lists based on if they are Impassable or not foreach (var entity in entitiesInRange) { - if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || entity.IsInContainer()) + if (Deleted(entity) || entity.IsInContainer()) { continue; } diff --git a/Content.Server/Fluids/Components/BucketComponent.cs b/Content.Server/Fluids/Components/BucketComponent.cs index 90fc0677b4..df8d832091 100644 --- a/Content.Server/Fluids/Components/BucketComponent.cs +++ b/Content.Server/Fluids/Components/BucketComponent.cs @@ -88,11 +88,8 @@ namespace Content.Server.Fluids.Components _currentlyUsing.Remove(eventArgs.Using); - if (result == DoAfterStatus.Cancelled || - (!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted || - mopComponent.Deleted || - CurrentVolume <= 0 || - !Owner.InRangeUnobstructed(mopComponent.Owner)) + if (result == DoAfterStatus.Cancelled || _entMan.Deleted(Owner) || mopComponent.Deleted || + CurrentVolume <= 0 || !Owner.InRangeUnobstructed(mopComponent.Owner)) return false; // Top up mops solution given it needs it to annihilate puddles I guess diff --git a/Content.Server/Fluids/Components/MopComponent.cs b/Content.Server/Fluids/Components/MopComponent.cs index 94463897ba..aae996a535 100644 --- a/Content.Server/Fluids/Components/MopComponent.cs +++ b/Content.Server/Fluids/Components/MopComponent.cs @@ -130,7 +130,7 @@ namespace Content.Server.Fluids.Components Mopping = false; if (result == DoAfterStatus.Cancelled || - (!_entities.EntityExists(Owner) ? EntityLifeStage.Deleted : _entities.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted || + _entities.Deleted(Owner) || puddleComponent.Deleted) return false; diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs index f1cc0c1583..8c24dbbd91 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs @@ -57,7 +57,7 @@ namespace Content.Server.Fluids.EntitySystems private void UpdateVisuals(EntityUid uid, PuddleComponent puddleComponent) { - if ((!EntityManager.EntityExists(puddleComponent.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(puddleComponent.Owner).EntityLifeStage) >= EntityLifeStage.Deleted || EmptyHolder(uid, puddleComponent) || + if (Deleted(puddleComponent.Owner) || EmptyHolder(uid, puddleComponent) || !EntityManager.TryGetComponent(uid, out var appearanceComponent)) { return; diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index 758fb7e864..8c959bc39a 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -75,7 +75,7 @@ namespace Content.Server.Ghost private void OnGhostShutdown(EntityUid uid, GhostComponent component, ComponentShutdown args) { // Perf: If the entity is deleting itself, no reason to change these back. - if ((!EntityManager.EntityExists(component.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(component.Owner).EntityLifeStage) < EntityLifeStage.Terminating) + if (!Terminating(uid)) { // Entity can't be seen by ghosts anymore. if (EntityManager.TryGetComponent(component.Owner, out VisibilityComponent? visibility)) @@ -176,9 +176,7 @@ namespace Content.Server.Ghost private void DeleteEntity(EntityUid uid) { - if (!EntityManager.EntityExists(uid) - || (!EntityManager.EntityExists(uid) ? EntityLifeStage.Deleted : EntityManager.GetComponent(uid).EntityLifeStage) >= EntityLifeStage.Deleted - || (!EntityManager.EntityExists(uid) ? EntityLifeStage.Deleted : EntityManager.GetComponent(uid).EntityLifeStage) == EntityLifeStage.Terminating) + if (Deleted(uid) || Terminating(uid)) return; if (EntityManager.TryGetComponent(uid, out var mind)) diff --git a/Content.Server/Inventory/InventoryHelpers.cs b/Content.Server/Inventory/InventoryHelpers.cs index 72434e4476..821fdfdd51 100644 --- a/Content.Server/Inventory/InventoryHelpers.cs +++ b/Content.Server/Inventory/InventoryHelpers.cs @@ -16,7 +16,7 @@ namespace Content.Server.Inventory var user = inventory.Owner; // Let's do nothing if the owner of the inventory has been deleted. - if ((!entityManager.EntityExists(user) ? EntityLifeStage.Deleted : entityManager.GetComponent(user).EntityLifeStage) >= EntityLifeStage.Deleted) + if (entityManager.Deleted(user)) return false; // If we don't have that slot or there's already an item there, we do nothing. diff --git a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs index 1cb455bff7..807d6e54e8 100644 --- a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs @@ -106,7 +106,7 @@ namespace Content.Server.Morgue.Components _cremateCancelToken = new CancellationTokenSource(); Owner.SpawnTimer(_burnMilis, () => { - if ((!_entities.EntityExists(Owner) ? EntityLifeStage.Deleted : _entities.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_entities.Deleted(Owner)) return; Appearance?.SetData(CrematoriumVisuals.Burning, false); diff --git a/Content.Server/Morgue/Components/MorgueTrayComponent.cs b/Content.Server/Morgue/Components/MorgueTrayComponent.cs index aef91523d4..9e808adf9e 100644 --- a/Content.Server/Morgue/Components/MorgueTrayComponent.cs +++ b/Content.Server/Morgue/Components/MorgueTrayComponent.cs @@ -16,7 +16,9 @@ namespace Content.Server.Morgue.Components void IActivate.Activate(ActivateEventArgs eventArgs) { - if (Morgue != null && !((!IoCManager.Resolve().EntityExists(Morgue) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Morgue).EntityLifeStage) >= EntityLifeStage.Deleted) && IoCManager.Resolve().TryGetComponent(Morgue, out var comp)) + var entMan = IoCManager.Resolve(); + + if (Morgue != default && !entMan.Deleted(Morgue) && entMan.TryGetComponent(Morgue, out var comp)) { comp.Activate(new ActivateEventArgs(eventArgs.User, Morgue)); } diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index 0fa7407afe..6784c555eb 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -219,7 +219,7 @@ namespace Content.Server.PneumaticCannon if (!EntityManager.TryGetComponent(comp.Owner, out var storage)) return; - if ((!EntityManager.EntityExists(data.User) ? EntityLifeStage.Deleted : EntityManager.GetComponent(data.User).EntityLifeStage) >= EntityLifeStage.Deleted) + if (Deleted(data.User)) return; if (storage.StoredEntities == null) return; @@ -243,7 +243,7 @@ namespace Content.Server.PneumaticCannon && comp.Power == PneumaticCannonPower.High) { _stun.TryParalyze(data.User, TimeSpan.FromSeconds(comp.HighPowerStunTime), true, status); - + data.User.PopupMessage(Loc.GetString("pneumatic-cannon-component-power-stun", ("cannon", comp.Owner))); } diff --git a/Content.Server/Projectiles/Components/HitscanComponent.cs b/Content.Server/Projectiles/Components/HitscanComponent.cs index 5364ef0656..b6aae157ef 100644 --- a/Content.Server/Projectiles/Components/HitscanComponent.cs +++ b/Content.Server/Projectiles/Components/HitscanComponent.cs @@ -97,7 +97,7 @@ namespace Content.Server.Projectiles.Components Owner.SpawnTimer((int) _deathTime.TotalMilliseconds, () => { - if (!((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) + if (!_entMan.Deleted(Owner)) { _entMan.DeleteEntity(Owner); } diff --git a/Content.Server/Radiation/RadiationPulseComponent.cs b/Content.Server/Radiation/RadiationPulseComponent.cs index 85dc0a33ca..58ba2c6cef 100644 --- a/Content.Server/Radiation/RadiationPulseComponent.cs +++ b/Content.Server/Radiation/RadiationPulseComponent.cs @@ -108,7 +108,7 @@ namespace Content.Server.Radiation public void Update(float frameTime) { - if (!Decay || (!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) + if (!Decay || _entMan.Deleted(Owner)) return; if (_duration <= 0f) diff --git a/Content.Server/Radiation/RadiationPulseSystem.cs b/Content.Server/Radiation/RadiationPulseSystem.cs index b42f923b28..e7a2ba599a 100644 --- a/Content.Server/Radiation/RadiationPulseSystem.cs +++ b/Content.Server/Radiation/RadiationPulseSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Radiation comp.Update(RadiationCooldown); var ent = comp.Owner; - if ((!_entMan.EntityExists(ent) ? EntityLifeStage.Deleted : _entMan.GetComponent(ent).EntityLifeStage) >= EntityLifeStage.Deleted) continue; + if (Deleted(ent)) continue; foreach (var entity in _lookup.GetEntitiesInRange(_entMan.GetComponent(ent).Coordinates, comp.Range)) { diff --git a/Content.Server/Spawners/Components/RandomSpawnerComponent.cs b/Content.Server/Spawners/Components/RandomSpawnerComponent.cs index 5c1ac36e25..bae54820e9 100644 --- a/Content.Server/Spawners/Components/RandomSpawnerComponent.cs +++ b/Content.Server/Spawners/Components/RandomSpawnerComponent.cs @@ -48,7 +48,7 @@ namespace Content.Server.Spawners.Components return; } - if(!((!_entMan.EntityExists(Owner) ? EntityLifeStage.Deleted : _entMan.GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) + if(!_entMan.Deleted(Owner)) { var random = IoCManager.Resolve(); diff --git a/Content.Server/StationEvents/Events/GasLeak.cs b/Content.Server/StationEvents/Events/GasLeak.cs index 00f48583e6..56151e4692 100644 --- a/Content.Server/StationEvents/Events/GasLeak.cs +++ b/Content.Server/StationEvents/Events/GasLeak.cs @@ -121,7 +121,7 @@ namespace Content.Server.StationEvents.Events if (!_foundTile || _targetGrid == default || - (!_entityManager.EntityExists(_targetGrid) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted || + _entityManager.Deleted(_targetGrid) || !atmosphereSystem.IsSimulatedGrid(_entityManager.GetComponent(_targetGrid).GridID)) { Running = false; diff --git a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs index 131070c14e..c4e8c8d996 100644 --- a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs @@ -260,7 +260,7 @@ namespace Content.Server.Weapon.Melee var hitBloodstreams = new List(); foreach (var entity in args.HitEntities) { - if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (Deleted(entity)) continue; if (EntityManager.TryGetComponent(entity, out var bloodstream)) diff --git a/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs index 54726c7fac..3d0d76be35 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs @@ -61,7 +61,7 @@ namespace Content.Shared.Pulling RaiseLocalEvent(puller.Owner, message, broadcast: false); - if ((!EntityManager.EntityExists(pullable.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(pullable.Owner).EntityLifeStage) <= EntityLifeStage.MapInitialized) + if (Initialized(pullable.Owner)) RaiseLocalEvent(pullable.Owner, message); // Networking diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs index 256f3bb918..1ed7422f75 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs @@ -164,7 +164,7 @@ namespace Content.Shared.Pulling // The pulled object may have already been deleted. // TODO: Work out why. Monkey + meat spike is a good test for this, // assuming you're still pulling the monkey when it gets gibbed. - if ((!EntityManager.EntityExists(pulled.Value) ? EntityLifeStage.Deleted : EntityManager.GetComponent(pulled.Value).EntityLifeStage) >= EntityLifeStage.Deleted) + if (Deleted(pulled.Value)) { return; } diff --git a/Content.Shared/Throwing/ThrownItemSystem.cs b/Content.Shared/Throwing/ThrownItemSystem.cs index ea23a03576..f31f02f70d 100644 --- a/Content.Shared/Throwing/ThrownItemSystem.cs +++ b/Content.Shared/Throwing/ThrownItemSystem.cs @@ -114,7 +114,7 @@ namespace Content.Shared.Throwing public void LandComponent(ThrownItemComponent thrownItem) { - if (thrownItem.Deleted || (!EntityManager.EntityExists(thrownItem.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(thrownItem.Owner).EntityLifeStage) >= EntityLifeStage.Deleted || _containerSystem.IsEntityInContainer(thrownItem.Owner)) return; + if (thrownItem.Deleted || Deleted(thrownItem.Owner) || _containerSystem.IsEntityInContainer(thrownItem.Owner)) return; var landing = thrownItem.Owner;