From 2a3b7d809d0730540929b04594fa34fe73c1c5ef Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sun, 5 Dec 2021 18:09:01 +0100 Subject: [PATCH] Fix 3000 errors --- Content.Client/AI/ClientAiDebugSystem.cs | 15 +- .../AI/ClientPathfindingDebugSystem.cs | 8 +- .../Visualizers/AMEControllerVisualizer.cs | 2 +- .../AME/Visualizers/AMEVisualizer.cs | 2 +- Content.Client/Actions/ActionsSystem.cs | 8 +- .../Actions/ClientActionsComponent.cs | 6 +- Content.Client/Actions/UI/ActionSlot.cs | 18 +- Content.Client/Actions/UI/ActionsUI.cs | 6 +- .../Administration/AdminNameOverlay.cs | 7 +- .../EditSolutionsWindow.xaml.cs | 8 +- .../UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs | 4 +- .../UI/Tabs/AtmosTab/AddGasWindow.xaml.cs | 5 +- .../UI/Tabs/AtmosTab/FillGasWindow.xaml.cs | 5 +- .../AtmosTab/SetTemperatureWindow.xaml.cs | 4 +- .../Animations/ReusableAnimations.cs | 4 +- .../Visualizers/AtmosPlaqueVisualizer.cs | 2 +- .../EnabledAtmosDeviceVisualizer.cs | 4 +- .../Atmos/Visualizers/FireVisualizer.cs | 3 +- .../Visualizers/GasAnalyzerVisualizer.cs | 4 +- .../Visualizers/GasCanisterVisualizer.cs | 5 +- .../Visualizers/GasPortableVisualizer.cs | 5 +- .../Visualizers/PipeConnectorVisualizer.cs | 12 +- .../Atmos/Visualizers/ScrubberVisualizer.cs | 4 +- .../Atmos/Visualizers/VentPumpVisualizer.cs | 4 +- Content.Client/Audio/AmbientSoundSystem.cs | 10 +- .../Body/UI/BodyScannerBoundUserInterface.cs | 4 +- Content.Client/Body/UI/BodyScannerDisplay.cs | 5 +- .../Botany/PlantHolderVisualizer.cs | 2 +- Content.Client/Buckle/BuckleComponent.cs | 2 +- .../Cabinet/ItemCabinetVisualizer.cs | 4 +- .../Systems/HumanoidAppearanceSystem.cs | 6 +- .../CharacterInterfaceSystem.cs | 4 +- Content.Client/Chat/Managers/ChatManager.cs | 20 ++- Content.Client/Chat/UI/SpeechBubble.cs | 10 +- .../Chemistry/Visualizers/FoamVisualizer.cs | 6 +- .../Chemistry/Visualizers/SmokeVisualizer.cs | 4 +- .../SolutionContainerVisualizer.cs | 4 +- Content.Client/CombatMode/CombatModeSystem.cs | 3 +- Content.Client/Computer/ComputerVisualizer.cs | 2 +- .../Construction/ConstructionSystem.cs | 23 +-- .../ContextMenu/UI/EntityMenuElement.cs | 21 ++- .../ContextMenu/UI/EntityMenuPresenter.cs | 35 ++-- .../UI/EntityMenuPresenterGrouping.cs | 19 +-- .../Visualizers/ConveyorVisualizer.cs | 6 +- .../Visualizers/TwoWayLeverVisualizer.cs | 6 +- Content.Client/Damage/DamageVisualizer.cs | 14 +- .../Visualizers/DisposalUnitVisualizer.cs | 5 +- .../Visualizers/DisposalVisualizer.cs | 5 +- Content.Client/DoAfter/DoAfterSystem.cs | 20 +-- Content.Client/DoAfter/UI/DoAfterGui.cs | 12 +- Content.Client/Doors/AirlockVisualizer.cs | 4 +- Content.Client/DragDrop/DragDropSystem.cs | 75 ++++---- Content.Client/Examine/ExamineSystem.cs | 21 ++- .../Explosion/ClusterFlashVisualizer.cs | 4 +- Content.Client/Flash/FlashSystem.cs | 2 +- Content.Client/Fluids/PuddleVisualizer.cs | 6 +- Content.Client/Ghost/GhostSystem.cs | 7 +- .../Gravity/GravityGeneratorVisualizer.cs | 2 +- Content.Client/Hands/HandsGui.xaml.cs | 4 +- Content.Client/Hands/HandsVisualizer.cs | 8 +- Content.Client/Hands/ShowHandItemOverlay.cs | 2 +- Content.Client/Hands/Systems/HandsSystem.cs | 18 +- .../HealthOverlay/HealthOverlaySystem.cs | 4 +- .../HealthOverlay/UI/HealthOverlayGui.cs | 17 +- .../IconSmoothing/IconSmoothSystem.cs | 12 +- .../Instruments/UI/InstrumentMenu.xaml.cs | 6 +- .../Interactable/InteractionSystem.cs | 4 +- .../Interactable/UnobstructedExtensions.cs | 4 +- .../Inventory/ClientInventoryComponent.cs | 26 ++- .../Inventory/ClientInventorySystem.cs | 5 +- .../HumanInventoryInterfaceController.cs | 9 +- .../Inventory/InventoryInterfaceController.cs | 4 +- .../Items/Managers/IItemSlotManager.cs | 8 +- .../Items/Managers/ItemSlotManager.cs | 38 ++--- Content.Client/Items/UI/ItemSlotButton.cs | 2 +- Content.Client/Items/UI/ItemStatusPanel.cs | 22 +-- Content.Client/Kitchen/UI/GrinderMenu.xaml.cs | 8 +- .../Kitchen/UI/MicrowaveBoundUserInterface.cs | 14 +- Content.Client/Kudzu/KudzuVisualizer.cs | 4 +- .../Lathe/Visualizers/AutolatheVisualizer.cs | 2 +- .../Lathe/Visualizers/ProtolatheVisualizer.cs | 2 +- .../Components/LightBehaviourComponent.cs | 10 +- .../Visualizers/EmergencyLightVisualizer.cs | 4 +- .../Visualizers/ExpendableLightVisualizer.cs | 11 +- .../Light/Visualizers/LightBulbVisualizer.cs | 4 +- .../Visualizers/PoweredLightVisualizer.cs | 4 +- .../Lobby/UI/LobbyCharacterPreviewPanel.cs | 13 +- .../MachineLinking/SignalSwitchVisualizer.cs | 5 +- .../UI/MedicalScannerWindow.xaml.cs | 23 ++- .../Mining/AsteroidRockVisualizer.cs | 2 +- .../MobState/Overlays/CritOverlay.cs | 12 +- .../Morgue/Visualizers/BodyBagVisualizer.cs | 4 +- .../Visualizers/CrematoriumVisualizer.cs | 7 +- .../Morgue/Visualizers/MorgueVisualizer.cs | 7 +- .../Movement/Components/ClimbableComponent.cs | 2 +- .../NodeContainer/NodeVisualizationOverlay.cs | 14 +- .../Visualizers/CreamPiedVisualizer.cs | 2 +- .../Visualizers/DrinkCanVisualizer.cs | 4 +- Content.Client/PDA/PDAVisualizer.cs | 2 +- Content.Client/Parallax/ParallaxGenerator.cs | 4 +- .../ParticleAcceleratorPartVisualizer.cs | 6 +- .../UI/ParticleAcceleratorControlMenu.cs | 2 +- .../Physics/Controllers/MoverController.cs | 26 +-- .../Pinpointer/PinpointerVisualizer.cs | 4 +- .../PneumaticCannonVisualizer.cs | 4 +- Content.Client/Popups/PopupSystem.cs | 7 +- Content.Client/Power/APC/ApcVisualizer.cs | 2 +- Content.Client/Power/SMES/SmesVisualizer.cs | 2 +- .../Power/Visualizers/CableVisualizer.cs | 4 +- .../PowerCell/PowerCellVisualizer.cs | 2 +- .../PowerCell/PowerChargerVisualizer.cs | 2 +- .../Preferences/UI/CharacterSetupGui.xaml.cs | 6 +- .../UI/HumanoidProfileEditor.xaml.cs | 3 +- .../Recycling/RecyclerVisualizer.cs | 5 +- .../Security/DeployableBarrierVisualizer.cs | 4 +- Content.Client/Shuttles/ThrusterVisualizer.cs | 4 +- .../Singularity/SingularityOverlay.cs | 26 +-- .../Visualizers/EmitterVisualizer.cs | 4 +- .../RadiationCollectorVisualizer.cs | 7 +- .../Visualizers/SingularityVisualizer.cs | 2 +- Content.Client/Smoking/BurnStateVisualizer.cs | 7 +- .../Spawners/ClientEntitySpawnerComponent.cs | 2 +- Content.Client/Stack/StackVisualizer.cs | 5 +- .../StationEvents/RadiationPulseOverlay.cs | 22 +-- .../Storage/ClientStorageComponent.cs | 64 +++---- .../Visualizers/BagOpenCloseVisualizer.cs | 42 ++--- .../Visualizers/MappedItemVisualizer.cs | 8 +- .../Storage/Visualizers/StorageVisualizer.cs | 5 +- .../SubFloor/SubFloorShowLayerVisualizer.cs | 4 +- Content.Client/Suspicion/TraitorOverlay.cs | 14 +- Content.Client/Tabletop/TabletopSystem.cs | 13 +- .../Visualizers/TabletopItemVisualizer.cs | 4 +- Content.Client/Toilet/ToiletVisualizer.cs | 8 +- .../Trigger/TimerTriggerVisualizer.cs | 2 +- .../UI/VendingMachineVisualizer.cs | 2 +- Content.Client/Verbs/UI/VerbMenuPresenter.cs | 7 +- Content.Client/Verbs/VerbSystem.cs | 14 +- Content.Client/Viewport/GameScreenBase.cs | 56 +++--- .../Visualizer/GenericEnumVisualizer.cs | 5 +- .../Wall/Components/LowWallComponent.cs | 6 +- .../Wall/ReinforcedWallVisualizer.cs | 4 +- .../MeleeWeaponArcAnimationComponent.cs | 4 +- .../Weapons/Melee/MeleeWeaponSystem.cs | 29 ++-- .../Visualizers/BarrelBoltVisualizer.cs | 2 +- .../Barrels/Visualizers/MagVisualizer.cs | 2 +- .../Weapons/Ranged/RangedWeaponSystem.cs | 5 +- .../Tests/Administration/Logs/AddTests.cs | 3 +- .../Tests/Body/LungTest.cs | 2 +- .../Tests/Buckle/BuckleTest.cs | 65 ++++--- .../Tests/Chemistry/TryAllReactionsTest.cs | 4 +- .../Tests/ClickableTest.cs | 6 +- .../Tests/ContainerOcclusionTest.cs | 42 +++-- .../Tests/Damageable/DamageableTest.cs | 2 +- .../Tests/DeleteInventoryTest.cs | 6 +- .../DestructibleDamageGroupTest.cs | 2 +- .../DestructibleDamageTypeTest.cs | 2 +- .../DestructibleDestructionTest.cs | 8 +- .../DestructibleThresholdActivationTest.cs | 2 +- .../Tests/DeviceNetwork/DeviceNetworkTest.cs | 12 +- .../Tests/Disposal/DisposalUnitTest.cs | 16 +- .../Tests/Doors/AirlockTest.cs | 8 +- Content.IntegrationTests/Tests/EntityTest.cs | 8 +- .../Tests/Fluids/PuddleTest.cs | 5 +- .../Components/ActionBlocking/HandCuffTest.cs | 24 ++- .../Components/Mobs/ActionsComponentTests.cs | 41 +++-- .../Components/Mobs/AlertsComponentTests.cs | 4 +- .../Components/Movement/ClimbUnitTest.cs | 12 +- .../Tests/Gravity/WeightlessStatusTests.cs | 3 +- .../Tests/GravityGridTest.cs | 10 +- .../Tests/GridTileLookupTest.cs | 2 +- .../Tests/HumanInventoryUniformSlotsTest.cs | 10 +- .../Click/InteractionSystemTests.cs | 138 +++++++-------- .../Tests/Interaction/InRangeUnobstructed.cs | 18 +- .../Tests/InventoryHelpersTest.cs | 27 +-- .../Tests/MindEntityDeletionTest.cs | 14 +- .../Tests/Networking/ConnectTest.cs | 3 +- .../Networking/SimplePredictReconcileTest.cs | 9 +- .../Tests/PDA/PDAExtensionsTests.cs | 29 ++-- .../Tests/SaveLoadMapTest.cs | 11 +- Content.IntegrationTests/Tests/ShuttleTest.cs | 19 +-- Content.IntegrationTests/Tests/Tag/TagTest.cs | 2 +- .../Utility/EntitySystemExtensionsTest.cs | 2 +- .../Tests/Utility/EntityWhitelistTest.cs | 19 +-- Content.Server/AI/Commands/AddAiCommand.cs | 12 +- .../AI/EntitySystems/AiFactionTagSystem.cs | 4 +- .../Combat/Melee/SwingMeleeWeaponOperator.cs | 6 +- .../Combat/Melee/UnarmedCombatOperator.cs | 6 +- .../Inventory/CloseStorageOperator.cs | 12 +- .../Operators/Inventory/DropEntityOperator.cs | 6 +- .../Inventory/DropHandItemsOperator.cs | 4 +- .../Inventory/EquipEntityOperator.cs | 6 +- .../Inventory/InteractWithEntityOperator.cs | 6 +- .../Inventory/OpenStorageOperator.cs | 6 +- .../Inventory/PickupEntityOperator.cs | 6 +- .../Inventory/UseItemInInventoryOperator.cs | 6 +- .../Movement/MoveToEntityOperator.cs | 8 +- .../Operators/Movement/MoveToGridOperator.cs | 4 +- .../Nutrition/UseDrinkInInventoryOperator.cs | 18 +- .../Nutrition/UseFoodInInventoryOperator.cs | 20 ++- .../Sequences/GoPickupEntitySequence.cs | 4 +- .../Accessible/AiReachableSystem.cs | 7 +- .../Pathfinding/Accessible/ReachableArgs.cs | 3 +- .../AI/Pathfinding/PathfindingNode.cs | 14 +- .../AI/Pathfinding/PathfindingSystem.cs | 19 +-- .../AI/Steering/AiSteeringSystem.cs | 106 ++++++------ .../Steering/EntityTargetSteeringRequest.cs | 6 +- .../Actions/Clothing/Gloves/EquipGloves.cs | 2 +- .../Actions/Clothing/Gloves/PickUpGloves.cs | 2 +- .../Actions/Clothing/Head/EquipHead.cs | 2 +- .../Actions/Clothing/Head/PickUpHead.cs | 2 +- .../OuterClothing/EquipOuterClothing.cs | 2 +- .../OuterClothing/PickUpOuterClothing.cs | 2 +- .../Actions/Clothing/Shoes/EquipShoes.cs | 2 +- .../Actions/Clothing/Shoes/PickUpShoes.cs | 2 +- .../Actions/Combat/Melee/EquipMelee.cs | 2 +- .../Combat/Melee/MeleeWeaponAttackEntity.cs | 4 +- .../Actions/Combat/Melee/PickUpMeleeWeapon.cs | 2 +- .../Combat/Melee/UnarmedAttackEntity.cs | 2 +- .../AI/Utility/Actions/IAiUtility.cs | 2 +- .../Actions/Nutrition/Drink/PickUpDrink.cs | 2 +- .../Nutrition/Drink/UseDrinkInInventory.cs | 2 +- .../Actions/Nutrition/Food/PickUpFood.cs | 2 +- .../Nutrition/Food/UseFoodInInventory.cs | 2 +- .../AI/Utility/Actions/UtilityAction.cs | 2 +- .../Combat/Melee/CanUnarmedCombatCon.cs | 10 +- .../Movement/TargetDistanceCon.cs | 9 +- .../State/StoredStateEntityIsNullCon.cs | 2 +- .../ExpandableUtilityAction.cs | 2 +- Content.Server/AI/Utility/UtilityAiHelpers.cs | 2 +- Content.Server/AI/Utils/Visibility.cs | 9 +- Content.Server/AI/WorldState/Blackboard.cs | 6 +- Content.Server/AI/WorldState/StateData.cs | 18 +- .../States/Clothing/EquippedClothingState.cs | 6 +- .../States/Clothing/NearbyClothingState.cs | 6 +- .../Combat/Nearby/NearbyMeleeWeapons.cs | 6 +- .../States/Combat/WeaponEntityState.cs | 4 +- .../WorldState/States/Hands/HandItemsState.cs | 6 +- .../States/Inventory/EquippedEntityState.cs | 8 +- .../States/Inventory/InventoryState.cs | 4 +- .../Inventory/LastOpenedStorageState.cs | 6 +- .../States/Mobs/NearbyBodiesState.cs | 6 +- .../States/Mobs/NearbyPlayersState.cs | 15 +- .../States/Movement/MoveTargetState.cs | 4 +- .../States/Nutrition/NearbyDrinkState.cs | 6 +- .../States/Nutrition/NearbyFoodState.cs | 6 +- .../AI/WorldState/States/SelfState.cs | 4 +- .../AI/WorldState/States/TargetEntityState.cs | 4 +- Content.Server/AME/AMENodeGroup.cs | 1 - .../AME/Components/AMEControllerComponent.cs | 47 +++-- .../AME/Components/AMEPartComponent.cs | 2 +- .../Access/AccessReaderChangeMessage.cs | 4 +- .../Components/IdCardConsoleComponent.cs | 42 ++--- .../Access/Systems/AccessReaderSystem.cs | 21 +-- Content.Server/Act/IDisarmedAct.cs | 4 +- Content.Server/Act/ISuicideAct.cs | 2 +- .../Actions/Actions/DisarmAction.cs | 16 +- .../Actions/Commands/CooldownAction.cs | 2 +- .../Actions/Commands/GrantAction.cs | 2 +- .../Actions/Commands/RevokeAction.cs | 2 +- .../Actions/ServerActionsComponent.cs | 52 +++--- .../Actions/Spells/GiveItemSpell.cs | 2 +- Content.Server/Administration/AdminSystem.cs | 7 +- .../Administration/AdminVerbSystem.cs | 25 ++- .../Administration/Commands/AGhost.cs | 22 +-- .../Commands/AddEntityStorageCommand.cs | 2 +- .../Administration/Commands/ControlMob.cs | 15 +- .../Commands/DeleteComponent.cs | 2 +- .../Commands/DeleteEntitiesWithComponent.cs | 4 +- .../Commands/DeleteEntitiesWithId.cs | 5 +- .../Commands/DeleteEntityCommand.cs | 4 +- .../Commands/ExplosionCommand.cs | 4 +- .../Commands/FindEntitiesWithComponents.cs | 9 +- .../Commands/RejuvenateCommand.cs | 23 ++- .../Commands/RemoveEntityStorageCommand.cs | 2 +- .../Commands/RemoveExtraComponents.cs | 10 +- .../Administration/Commands/SetMindCommand.cs | 8 +- .../Commands/SetOutfitCommand.cs | 18 +- .../Administration/Commands/WarpCommand.cs | 12 +- .../Logs/AdminLogSystem.Json.cs | 3 +- .../Logs/Converters/PlayerSessionConverter.cs | 8 +- .../Administration/UI/SetOutfitEui.cs | 5 +- Content.Server/Alert/Click/StopPulling.cs | 2 +- Content.Server/Alert/Commands/ClearAlert.cs | 2 +- Content.Server/Alert/Commands/ShowAlert.cs | 4 +- Content.Server/Alert/ServerAlertsComponent.cs | 4 +- Content.Server/Animals/Systems/UdderSystem.cs | 34 ++-- .../Components/BlockGameArcadeComponent.cs | 4 +- .../Atmos/Commands/AddAtmosCommand.cs | 10 +- .../Commands/AddUnsimulatedAtmosCommand.cs | 6 +- .../Atmos/Commands/DeleteGasCommand.cs | 10 +- .../Atmos/Components/BreathToolComponent.cs | 10 +- .../Atmos/Components/GasAnalyzerComponent.cs | 34 ++-- .../Atmos/Components/GasTankComponent.cs | 14 +- .../EntitySystems/AtmosDebugOverlaySystem.cs | 11 +- .../AtmosphereSystem.HighPressureDelta.cs | 3 +- .../Atmos/EntitySystems/BarotraumaSystem.cs | 4 +- .../Atmos/EntitySystems/FlammableSystem.cs | 5 +- .../EntitySystems/GasTileOverlaySystem.cs | 15 +- .../Unary/EntitySystems/GasCanisterSystem.cs | 28 ++- .../Body/Commands/AddHandCommand.cs | 9 +- .../Body/Commands/AttachBodyPartCommand.cs | 22 +-- .../Body/Commands/DestroyMechanismCommand.cs | 2 +- .../Body/Commands/RemoveHandCommand.cs | 2 +- .../Body/Components/BodyComponent.cs | 3 +- .../Body/Components/BodyPartComponent.cs | 13 +- .../Body/Components/BodyScannerComponent.cs | 2 +- .../Body/Components/InternalsComponent.cs | 28 +-- .../Body/Components/MechanismComponent.cs | 21 +-- .../Surgery/BiologicalSurgeryDataComponent.cs | 22 +-- .../Components/SurgeryToolComponent.cs | 33 ++-- .../Surgery/Components/SurgeryToolSystem.cs | 5 +- .../Body/Systems/MetabolizerSystem.cs | 4 +- .../Body/Systems/RespiratorSystem.cs | 4 +- .../Botany/Components/LogComponent.cs | 3 +- .../Botany/Components/PlantHolderComponent.cs | 13 +- .../Components/SeedExtractorComponent.cs | 2 +- Content.Server/Botany/Seed.cs | 20 +-- Content.Server/Bql/QuerySelectors.cs | 13 +- .../Buckle/Components/BuckleComponent.cs | 58 +++---- .../Buckle/Components/StrapComponent.cs | 6 +- Content.Server/Buckle/Systems/StrapSystem.cs | 23 ++- .../Cargo/Components/CargoConsoleComponent.cs | 14 +- .../Components/MagicMirrorComponent.cs | 11 +- Content.Server/Chat/Commands/MeCommand.cs | 2 +- Content.Server/Chat/Commands/SayCommand.cs | 10 +- .../Chat/Commands/SuicideCommand.cs | 17 +- Content.Server/Chat/Managers/ChatManager.cs | 42 +++-- .../Chat/Managers/ChatSanitizationManager.cs | 3 +- Content.Server/Chat/Managers/IChatManager.cs | 4 +- .../Chat/Managers/IChatSanitizationManager.cs | 2 +- .../Components/ChemMasterComponent.cs | 75 ++++---- .../FoamSolutionAreaEffectComponent.cs | 4 +- .../Components/HyposprayComponent.cs | 17 +- .../Chemistry/Components/InjectorComponent.cs | 38 ++--- .../Components/ReagentDispenserComponent.cs | 39 ++--- .../SmokeSolutionAreaEffectComponent.cs | 4 +- .../Components/SolutionAreaEffectComponent.cs | 30 ++-- .../Components/SolutionTransferComponent.cs | 23 +-- .../EntitySystems/ChemicalReactionSystem.cs | 13 +- .../EntitySystems/RehydratableSystem.cs | 3 +- .../EntitySystems/SolutionContainerSystem.cs | 6 +- .../TransformableContainerSystem.cs | 2 +- .../Chemistry/EntitySystems/VaporSystem.cs | 2 +- .../ReactionEffects/AreaReactionEffect.cs | 7 +- .../ReactionEffects/FoamAreaReactionEffect.cs | 2 +- .../SmokeAreaReactionEffect.cs | 2 +- .../Chemistry/ReagentEffects/DoAction.cs | 4 +- .../TileReactions/CleanTileReaction.cs | 3 +- .../Climbing/Components/ClimbableComponent.cs | 11 +- Content.Server/Cloning/CloningSystem.cs | 4 +- .../Cloning/Components/CloningPodComponent.cs | 4 +- .../Clothing/Components/ClothingComponent.cs | 3 +- .../Clothing/Components/MagbootsComponent.cs | 6 +- Content.Server/Commands/CommandUtils.cs | 7 +- .../CommunicationsConsoleComponent.cs | 11 +- .../Construction/AnchorableSystem.cs | 4 +- .../Commands/FixRotationsCommand.cs | 28 ++- .../Construction/Commands/TileWallsCommand.cs | 22 +-- .../Construction/Completions/BuildComputer.cs | 3 +- .../Completions/DeleteEntitiesInContainer.cs | 3 +- .../Components/MachineComponent.cs | 3 +- .../Components/MachineFrameComponent.cs | 5 +- .../Components/WelderRefinableComponent.cs | 5 +- .../Construction/ConstructionSystem.Graph.cs | 5 +- .../ConstructionSystem.Initial.cs | 79 +++++---- .../ConstructionSystem.Interactions.cs | 7 +- Content.Server/Conveyor/ConveyorSystem.cs | 4 +- .../Helpers/GridTileLookupHelpers.cs | 4 +- .../Cuffs/Components/CuffableComponent.cs | 11 +- .../Cuffs/Components/HandcuffComponent.cs | 4 +- Content.Server/Cuffs/CuffableSystem.cs | 2 +- .../Damage/Commands/GodModeCommand.cs | 4 +- Content.Server/Damage/Commands/HurtCommand.cs | 11 +- .../Thresholds/Behaviors/SpillBehavior.cs | 2 +- .../Systems/WiredNetworkSystem.cs | 8 +- .../Systems/WirelessNetworkSystem.cs | 2 +- .../Components/DisposalRouterComponent.cs | 2 +- .../Components/DisposalTaggerComponent.cs | 2 +- .../Tube/Components/DisposalTubeComponent.cs | 5 +- .../Tube/Components/IDisposalTubeComponent.cs | 2 +- .../Disposal/Tube/DisposalTubeSystem.cs | 4 +- .../Disposal/TubeConnectionsCommand.cs | 2 +- .../Components/DisposalHolderComponent.cs | 9 +- .../Unit/Components/DisposalUnitComponent.cs | 4 +- .../Unit/EntitySystems/DisposalUnitSystem.cs | 8 +- Content.Server/DoAfter/DoAfterEventArgs.cs | 12 -- .../Doors/Components/ServerDoorComponent.cs | 18 +- .../Electrocution/ElectrocutionSystem.cs | 13 +- .../DisassembleOnActivateSystem.cs | 2 +- .../EntitySystems/SpawnAfterInteractSystem.cs | 2 +- Content.Server/Examine/ExamineSystem.cs | 8 +- .../Components/ClusterFlashComponent.cs | 9 +- .../Components/OnUseTimerTriggerComponent.cs | 2 +- .../EntitySystems/ExplosionSystem.cs | 19 +-- .../Explosion/EntitySystems/TriggerSystem.cs | 10 +- .../Extinguisher/FireExtinguisherComponent.cs | 45 +++-- Content.Server/Flash/FlashSystem.cs | 12 +- .../Fluids/Components/MopComponent.cs | 4 +- .../Fluids/Components/SpillExtensions.cs | 24 +-- .../Fluids/EntitySystems/EvaporationSystem.cs | 3 +- .../Fluids/EntitySystems/PuddleSystem.cs | 24 ++- .../GameTicking/Commands/MappingCommand.cs | 2 +- .../GameTicking/GameTicker.RoundFlow.cs | 8 +- .../GameTicking/Presets/GamePreset.cs | 6 +- .../Presets/PresetTraitorDeathMatch.cs | 4 +- .../Ghost/Components/GhostRadioComponent.cs | 5 +- Content.Server/Ghost/GhostSystem.cs | 4 +- .../GhostRoleMobSpawnerComponent.cs | 4 +- .../EntitySystems/GravityGeneratorSystem.cs | 2 +- .../Gravity/EntitySystems/WeightlessSystem.cs | 2 +- .../Hands/Components/HandsComponent.cs | 4 +- .../Hands/Systems/HandVirtualItemSystem.cs | 39 ++--- Content.Server/Hands/Systems/HandsSystem.cs | 50 +++--- Content.Server/Headset/HeadsetComponent.cs | 8 +- .../Interaction/Components/ClumsyComponent.cs | 3 +- .../Interaction/InteractionSystem.cs | 36 ++-- .../HumanInventoryControllerComponent.cs | 3 +- .../Components/IInventoryController.cs | 4 +- .../Components/InventoryComponent.cs | 19 +-- Content.Server/Inventory/InventoryHelpers.cs | 2 +- Content.Server/Jobs/AddComponentSpecial.cs | 3 +- .../Jobs/GiveItemOnHolidaySpecial.cs | 3 +- .../Components/KitchenSpikeComponent.cs | 6 +- .../Kitchen/Components/MicrowaveComponent.cs | 14 +- .../EntitySystems/ReagentGrinderSystem.cs | 26 ++- .../Labels/Label/HandLabelerSystem.cs | 14 +- .../Lathe/Components/LatheComponent.cs | 2 +- .../Components/HandheldLightComponent.cs | 6 +- .../EntitySystems/LightReplacerSystem.cs | 6 +- .../Light/EntitySystems/MatchstickSystem.cs | 2 +- .../Light/EntitySystems/PoweredLightSystem.cs | 30 ++-- Content.Server/Lock/LockSystem.cs | 8 +- .../MachineLinking/Events/LinkAttemptEvent.cs | 4 +- .../System/SignalLinkerSystem.cs | 4 +- .../System/TriggerOnSignalReceivedSystem.cs | 2 +- .../Components/MedicalScannerComponent.cs | 3 +- Content.Server/Mind/Mind.cs | 48 +++--- .../BodyBagEntityStorageComponent.cs | 16 +- .../CrematoriumEntityStorageComponent.cs | 17 +- .../MorgueEntityStorageComponent.cs | 10 +- .../Morgue/Components/MorgueTrayComponent.cs | 2 +- Content.Server/NodeContainer/Nodes/Node.cs | 4 +- .../Nuke/Commands/ToggleNukeCommand.cs | 4 +- Content.Server/Nuke/NukeSystem.cs | 18 +- .../Nutrition/EntitySystems/DrinkSystem.cs | 62 +++---- .../Nutrition/EntitySystems/FoodSystem.cs | 160 +++++++++--------- .../EntitySystems/SliceableFoodSystem.cs | 8 +- .../Nutrition/EntitySystems/SmokingSystem.cs | 4 +- .../Nutrition/EntitySystems/UtensilSystem.cs | 16 +- .../Conditions/KillRandomPersonCondition.cs | 4 +- Content.Server/PDA/PDASystem.cs | 4 +- .../ParticleAcceleratorControlBoxComponent.cs | 5 +- .../ParticleAcceleratorEmitterComponent.cs | 7 +- .../Components/ParticleProjectileComponent.cs | 6 +- .../Physics/Controllers/MoverController.cs | 3 +- .../PneumaticCannonComponent.cs | 4 +- .../PneumaticCannon/PneumaticCannonSystem.cs | 26 ++- .../Components/PointingArrowComponent.cs | 2 +- .../Components/RoguePointingArrowComponent.cs | 2 +- .../Pointing/EntitySystems/PointingSystem.cs | 12 +- .../EntitySystems/RoguePointingSystem.cs | 4 +- .../Power/Components/BaseCharger.cs | 8 +- .../Power/Components/CableComponent.cs | 4 +- .../EntitySystems/ExtensionCableSystem.cs | 4 +- .../EntitySystems/PowerReceiverSystem.cs | 2 +- .../Components/PowerCellChargerComponent.cs | 4 +- .../Components/PowerCellComponent.cs | 2 +- .../Components/PowerCellSlotComponent.cs | 4 +- .../Components/HitscanComponent.cs | 4 +- .../Components/ProjectileComponent.cs | 4 +- .../Projectiles/ProjectileSystem.cs | 5 +- Content.Server/RCD/Systems/RCDSystem.cs | 11 +- .../Radiation/RadiationPulseComponent.cs | 3 +- .../Components/HandheldRadioComponent.cs | 10 +- Content.Server/Radio/Components/IListen.cs | 4 +- Content.Server/Radio/Components/IRadio.cs | 5 +- .../Radio/EntitySystems/ListeningSystem.cs | 2 +- .../Radio/EntitySystems/RadioSystem.cs | 2 +- .../Components/RecyclableComponent.cs | 2 +- .../Recycling/Components/RecyclerComponent.cs | 4 +- Content.Server/Recycling/RecyclerSystem.cs | 7 +- Content.Server/Rotatable/RotatableSystem.cs | 4 +- Content.Server/RoundEnd/RoundEndSystem.cs | 12 +- .../Sandbox/Commands/ColorNetworkCommand.cs | 4 +- Content.Server/Sandbox/SandboxManager.cs | 8 +- .../Shuttles/EntitySystems/DockingSystem.cs | 6 +- .../EntitySystems/ShuttleConsoleSystem.cs | 6 +- .../Shuttles/EntitySystems/ShuttleSystem.cs | 2 +- .../Components/ContainmentFieldConnection.cs | 9 +- .../ContainmentFieldGeneratorComponent.cs | 3 +- .../Components/ServerSingularityComponent.cs | 7 +- .../EntitySystems/EmitterSystem.cs | 2 +- .../EntitySystems/SingularitySystem.cs | 8 +- .../Solar/EntitySystems/PowerSolarSystem.cs | 4 +- .../Components/RandomSpawnerComponent.cs | 2 +- Content.Server/Stack/StackSystem.cs | 18 +- .../Standing/StandingStateSystem.cs | 25 ++- .../StationEvents/Events/GasLeak.cs | 32 ++-- .../StationEvents/Events/KudzuGrowth.cs | 3 +- .../StationEvents/Events/PowerGridCheck.cs | 2 +- .../StationEvents/Events/StationEvent.cs | 5 +- .../Components/EntityStorageComponent.cs | 26 ++- .../Storage/Components/IStorageComponent.cs | 6 +- .../Components/SecretStashComponent.cs | 4 +- .../Components/ServerStorageComponent.cs | 92 +++++----- .../Storage/EntitySystems/ItemMapperSystem.cs | 3 +- .../EntitySystems/SpawnItemsOnUseSystem.cs | 13 +- .../Storage/EntitySystems/StorageSystem.cs | 22 +-- Content.Server/Strip/StrippableComponent.cs | 10 +- .../Stunnable/StunOnCollideSystem.cs | 5 +- Content.Server/Stunnable/StunbatonSystem.cs | 8 +- Content.Server/Tabletop/TabletopChessSetup.cs | 16 +- .../Tabletop/TabletopParchisSetup.cs | 32 ++-- .../Tabletop/TabletopSystem.Draggable.cs | 6 +- Content.Server/Toilet/ToiletComponent.cs | 3 +- .../Tools/Components/TilePryingComponent.cs | 3 +- .../Uplink/Account/UplinkAccountsSystem.cs | 4 +- .../Uplink/Commands/AddUplinkCommand.cs | 4 +- Content.Server/Traitor/Uplink/UplinkSystem.cs | 6 +- .../TraitorDeathMatchRedemptionComponent.cs | 3 +- .../UserInterface/ActivatableUISystem.cs | 22 +-- .../VendingMachineComponent.cs | 5 +- .../Verbs/Commands/InvokeVerbCommand.cs | 7 +- .../Verbs/Commands/ListVerbsCommand.cs | 6 +- Content.Server/Verbs/VerbSystem.cs | 5 +- .../Weapon/Melee/MeleeWeaponSystem.cs | 61 +++---- .../Ammunition/Components/AmmoBoxComponent.cs | 14 +- .../Ammunition/Components/AmmoComponent.cs | 4 +- .../Components/RangedMagazineComponent.cs | 8 +- .../Components/SpeedLoaderComponent.cs | 20 ++- .../Weapon/Ranged/Barrels/BarrelSystem.cs | 10 +- .../Components/BoltActionBarrelComponent.cs | 11 +- .../Barrels/Components/PumpBarrelComponent.cs | 9 +- .../Components/RevolverBarrelComponent.cs | 11 +- .../ServerBatteryBarrelComponent.cs | 95 +++++------ .../ServerMagazineBarrelComponent.cs | 33 ++-- .../Components/ServerRangedBarrelComponent.cs | 71 ++++---- .../Ranged/ServerRangedWeaponComponent.cs | 12 +- .../Weapon/WeaponCapacitorChargerComponent.cs | 4 +- Content.Server/Wieldable/WieldableSystem.cs | 70 ++++---- Content.Server/Window/WindowComponent.cs | 3 +- Content.Server/WireHacking/WiresComponent.cs | 36 ++-- .../Body/Components/SharedBodyComponent.cs | 6 +- .../Components/SharedBodyPartComponent.cs | 7 +- .../Reaction/SharedChemicalReactionSystem.cs | 28 +-- Content.Shared/Chemistry/ReactiveSystem.cs | 8 +- .../Chemistry/Reagent/ReagentPrototype.cs | 4 +- .../CombatMode/SharedCombatModeSystem.cs | 3 +- Content.Shared/Cuffs/SharedCuffableSystem.cs | 2 +- Content.Shared/Flash/SharedFlashSystem.cs | 2 +- Content.Shared/Gravity/SharedGravitySystem.cs | 2 +- .../Hands/Components/SharedHandsComponent.cs | 21 ++- Content.Shared/Hands/SharedHandsSystem.cs | 7 +- .../Helpers/SharedUnobstructedExtensions.cs | 5 +- .../Interaction/SharedInteractionSystem.cs | 36 ++-- .../MovementIgnoreGravityComponent.cs | 17 +- .../EntitySystems/SharedMoverSystem.cs | 4 +- .../Pulling/Components/PullableComponent.cs | 18 +- .../Components/SharedPullerComponent.cs | 15 +- .../Pulling/Systems/SharedPullableSystem.cs | 4 +- .../Pulling/Systems/SharedPullerSystem.cs | 5 +- .../Pulling/Systems/SharedPullingSystem.cs | 14 +- .../Shuttles/Components/PilotComponent.cs | 9 +- .../Slippery/SharedSlipperySystem.cs | 5 +- .../StatusEffect/StatusEffectsSystem.cs | 2 +- Content.Shared/Throwing/ThrownItemSystem.cs | 9 +- Content.Shared/Verbs/SharedVerbSystem.cs | 17 +- Content.Shared/Weapons/Melee/AttackEvent.cs | 3 +- .../Shared/Chemistry/FixedPoint2_Tests.cs | 4 +- 569 files changed, 2979 insertions(+), 3280 deletions(-) diff --git a/Content.Client/AI/ClientAiDebugSystem.cs b/Content.Client/AI/ClientAiDebugSystem.cs index c774e32aa3..3abfee6e36 100644 --- a/Content.Client/AI/ClientAiDebugSystem.cs +++ b/Content.Client/AI/ClientAiDebugSystem.cs @@ -18,7 +18,7 @@ namespace Content.Client.AI [Dependency] private readonly IEyeManager _eyeManager = default!; private AiDebugMode _tooltips = AiDebugMode.None; - private readonly Dictionary _aiBoxes = new(); + private readonly Dictionary _aiBoxes = new(); public override void Update(float frameTime) { @@ -37,7 +37,7 @@ namespace Content.Client.AI return; } - var deletedEntities = new List(0); + var deletedEntities = new List(0); foreach (var (entity, panel) in _aiBoxes) { if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) @@ -78,8 +78,7 @@ namespace Content.Client.AI if ((_tooltips & AiDebugMode.Thonk) != 0) { // I guess if it's out of range we don't know about it? - var entityManager = IoCManager.Resolve(); - var entity = entityManager.GetEntity(message.EntityUid); + var entity = message.EntityUid; TryCreatePanel(entity); // Probably shouldn't access by index but it's a debugging tool so eh @@ -95,8 +94,7 @@ namespace Content.Client.AI { if ((_tooltips & AiDebugMode.Paths) != 0) { - var entityManager = IoCManager.Resolve(); - var entity = entityManager.GetEntity(message.EntityUid); + var entity = message.EntityUid; TryCreatePanel(entity); var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(1); @@ -110,8 +108,7 @@ namespace Content.Client.AI { if ((_tooltips & AiDebugMode.Paths) != 0) { - var entityManager = IoCManager.Resolve(); - var entity = entityManager.GetEntity(message.EntityUid); + var entity = message.EntityUid; TryCreatePanel(entity); var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(1); @@ -154,7 +151,7 @@ namespace Content.Client.AI } } - private bool TryCreatePanel(IEntity entity) + private bool TryCreatePanel(EntityUid entity) { if (!_aiBoxes.ContainsKey(entity)) { diff --git a/Content.Client/AI/ClientPathfindingDebugSystem.cs b/Content.Client/AI/ClientPathfindingDebugSystem.cs index aea3a130b7..8a36759486 100644 --- a/Content.Client/AI/ClientPathfindingDebugSystem.cs +++ b/Content.Client/AI/ClientPathfindingDebugSystem.cs @@ -287,7 +287,7 @@ namespace Content.Client.AI private void DrawCachedRegions(DrawingHandleScreen screenHandle, Box2 viewport) { var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (attachedEntity == null || !CachedRegions.TryGetValue(IoCManager.Resolve().GetComponent(attachedEntity).GridID, out var entityRegions)) + if (attachedEntity == default || !CachedRegions.TryGetValue(IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID, out var entityRegions)) { return; } @@ -305,7 +305,7 @@ namespace Content.Client.AI screenTile.X + 15.0f, screenTile.Y + 15.0f); - screenHandle.DrawRect(box, _cachedRegionColors[IoCManager.Resolve().GetComponent(attachedEntity).GridID][region]); + screenHandle.DrawRect(box, _cachedRegionColors[IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID][region]); } } } @@ -336,7 +336,7 @@ namespace Content.Client.AI private void DrawRegions(DrawingHandleScreen screenHandle, Box2 viewport) { var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (attachedEntity == null || !Regions.TryGetValue(IoCManager.Resolve().GetComponent(attachedEntity).GridID, out var entityRegions)) + if (attachedEntity == default || !Regions.TryGetValue(IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID, out var entityRegions)) { return; } @@ -356,7 +356,7 @@ namespace Content.Client.AI screenTile.X + 15.0f, screenTile.Y + 15.0f); - screenHandle.DrawRect(box, _regionColors[IoCManager.Resolve().GetComponent(attachedEntity).GridID][chunk][region]); + screenHandle.DrawRect(box, _regionColors[IoCManager.Resolve().GetComponent(attachedEntity.Value).GridID][chunk][region]); } } } diff --git a/Content.Client/AME/Visualizers/AMEControllerVisualizer.cs b/Content.Client/AME/Visualizers/AMEControllerVisualizer.cs index 81d38f4582..d4c1a19427 100644 --- a/Content.Client/AME/Visualizers/AMEControllerVisualizer.cs +++ b/Content.Client/AME/Visualizers/AMEControllerVisualizer.cs @@ -9,7 +9,7 @@ namespace Content.Client.AME.Visualizers [UsedImplicitly] public class AMEControllerVisualizer : AppearanceVisualizer { - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); var sprite = IoCManager.Resolve().GetComponent(entity); diff --git a/Content.Client/AME/Visualizers/AMEVisualizer.cs b/Content.Client/AME/Visualizers/AMEVisualizer.cs index 96ae206db2..98910b0b6d 100644 --- a/Content.Client/AME/Visualizers/AMEVisualizer.cs +++ b/Content.Client/AME/Visualizers/AMEVisualizer.cs @@ -9,7 +9,7 @@ namespace Content.Client.AME.Visualizers [UsedImplicitly] public class AMEVisualizer : AppearanceVisualizer { - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); var sprite = IoCManager.Resolve().GetComponent(entity); diff --git a/Content.Client/Actions/ActionsSystem.cs b/Content.Client/Actions/ActionsSystem.cs index 37ef385d60..51a62b0d64 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 == null || + if (playerEntity == default || !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return false; actionsComponent.HandleHotbarKeybind(slot, args); @@ -98,7 +98,7 @@ namespace Content.Client.Actions return new((in PointerInputCmdHandler.PointerInputCmdArgs args) => { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == null || + if (playerEntity == default || !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return false; actionsComponent.HandleChangeHotbarKeybind(hotbar, args); @@ -110,7 +110,7 @@ namespace Content.Client.Actions private bool TargetingOnUse(in PointerInputCmdHandler.PointerInputCmdArgs args) { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == null || + if (playerEntity == default || !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return false; return actionsComponent.TargetingOnUse(args); @@ -119,7 +119,7 @@ namespace Content.Client.Actions private void ToggleActionsMenu() { var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; - if (playerEntity == null || + if (playerEntity == default || !EntityManager.TryGetComponent(playerEntity.Value, out var actionsComponent)) return; actionsComponent.ToggleActionsMenu(); diff --git a/Content.Client/Actions/ClientActionsComponent.cs b/Content.Client/Actions/ClientActionsComponent.cs index 6010505811..1032a63ae4 100644 --- a/Content.Client/Actions/ClientActionsComponent.cs +++ b/Content.Client/Actions/ClientActionsComponent.cs @@ -1,7 +1,5 @@ using Content.Client.Actions.Assignments; using Content.Client.Actions.UI; -using Content.Client.Hands; -using Content.Client.Inventory; using Content.Client.Items.Managers; using Content.Shared.Actions.Components; using Content.Shared.Actions.Prototypes; @@ -226,7 +224,7 @@ namespace Content.Client.Actions /// Highlights the item slot (inventory or hand) that contains this item /// /// - public void HighlightItemSlot(IEntity item) + public void HighlightItemSlot(EntityUid item) { StopHighlightingItemSlots(); @@ -236,7 +234,7 @@ namespace Content.Client.Actions /// /// Stops highlighting any item slots we are currently highlighting. - /// + /// H public void StopHighlightingItemSlots() { if (_highlightedEntity == default) diff --git a/Content.Client/Actions/UI/ActionSlot.cs b/Content.Client/Actions/UI/ActionSlot.cs index 169851e9bd..f363c1f067 100644 --- a/Content.Client/Actions/UI/ActionSlot.cs +++ b/Content.Client/Actions/UI/ActionSlot.cs @@ -62,7 +62,7 @@ namespace Content.Client.Actions.UI /// Item the action is provided by, only valid if Action is an ItemActionPrototype. May be null /// if the item action is not yet tied to an item. /// - public IEntity? Item { get; private set; } + public EntityUid Item { get; private set; } /// /// Whether the action in this slot should be shown as toggled on. Separate from Depressed. @@ -231,7 +231,7 @@ namespace Content.Client.Actions.UI { ActionPrototype actionPrototype => new ActionAttempt(actionPrototype), ItemActionPrototype itemActionPrototype => - (Item != null && IoCManager.Resolve().TryGetComponent(Item, out var itemActions)) ? + (Item != default && IoCManager.Resolve().TryGetComponent(Item, out var itemActions)) ? new ItemActionAttempt(itemActionPrototype, Item, itemActions) : null, _ => null }; @@ -245,7 +245,7 @@ namespace Content.Client.Actions.UI _beingHovered = true; DrawModeChanged(); if (Action is not ItemActionPrototype) return; - if (Item == null) return; + if (Item == default) return; _actionsComponent.HighlightItemSlot(Item); } @@ -376,7 +376,7 @@ namespace Content.Client.Actions.UI if (Action != null && Action == action) return; Action = action; - Item = null; + Item = default; _depressed = false; ToggledOn = false; ActionEnabled = actionEnabled; @@ -395,10 +395,10 @@ namespace Content.Client.Actions.UI public void Assign(ItemActionPrototype action) { // already assigned - if (Action != null && Action == action && Item == null) return; + if (Action != null && Action == action && Item == default) return; Action = action; - Item = null; + Item = default; _depressed = false; ToggledOn = false; ActionEnabled = false; @@ -415,7 +415,7 @@ namespace Content.Client.Actions.UI /// action to assign /// item the action is provided by /// whether action should initially appear enable or disabled - public void Assign(ItemActionPrototype action, IEntity item, bool actionEnabled) + public void Assign(ItemActionPrototype action, EntityUid item, bool actionEnabled) { // already assigned if (Action != null && Action == action && Item == item) return; @@ -439,7 +439,7 @@ namespace Content.Client.Actions.UI { if (!HasAssignment) return; Action = null; - Item = null; + Item = default; ToggledOn = false; _depressed = false; Cooldown = null; @@ -502,7 +502,7 @@ namespace Content.Client.Actions.UI SetActionIcon(Action.Icon.Frame0()); } - if (Item != null) + if (Item != default) { SetItemIcon(IoCManager.Resolve().TryGetComponent(Item, out var spriteComponent) ? spriteComponent : null); } diff --git a/Content.Client/Actions/UI/ActionsUI.cs b/Content.Client/Actions/UI/ActionsUI.cs index 7544bece52..260a6656d0 100644 --- a/Content.Client/Actions/UI/ActionsUI.cs +++ b/Content.Client/Actions/UI/ActionsUI.cs @@ -378,10 +378,10 @@ namespace Content.Client.Actions.UI private void UpdateActionSlot(EntityUid item, ItemActionType itemActionType, ActionSlot actionSlot, ActionAssignment? assignedActionType) { - if (!_entityManager.TryGetEntity(item, out var itemEntity)) return; + if (!_entityManager.EntityExists(item)) return; if (_actionManager.TryGet(itemActionType, out var action)) { - actionSlot.Assign(action, itemEntity, true); + actionSlot.Assign(action, item, true); } else { @@ -420,7 +420,7 @@ namespace Content.Client.Actions.UI // if we are targeting with an action now on cooldown, stop targeting if we should if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action && - SelectingTargetFor.Item == itemEntity && + SelectingTargetFor.Item == item && actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown) { StopTargeting(); diff --git a/Content.Client/Administration/AdminNameOverlay.cs b/Content.Client/Administration/AdminNameOverlay.cs index 1f42e57d16..6cc37a3028 100644 --- a/Content.Client/Administration/AdminNameOverlay.cs +++ b/Content.Client/Administration/AdminNameOverlay.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using Content.Shared.Administration.Events; -using Robust.Client.Graphics; +using Robust.Client.Graphics; using Robust.Client.ResourceManagement; using Robust.Shared.Enums; using Robust.Shared.GameObjects; @@ -36,7 +34,8 @@ namespace Content.Client.Administration foreach (var playerInfo in _system.PlayerList) { // Otherwise the entity can not exist yet - if (!_entityManager.TryGetEntity(playerInfo.EntityUid, out var entity)) + var entity = playerInfo.EntityUid; + if (!_entityManager.EntityExists(entity)) { continue; } diff --git a/Content.Client/Administration/UI/ManageSolutions/EditSolutionsWindow.xaml.cs b/Content.Client/Administration/UI/ManageSolutions/EditSolutionsWindow.xaml.cs index c443c1d6c4..4264eda0b0 100644 --- a/Content.Client/Administration/UI/ManageSolutions/EditSolutionsWindow.xaml.cs +++ b/Content.Client/Administration/UI/ManageSolutions/EditSolutionsWindow.xaml.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using Content.Shared.Chemistry.Components; using Robust.Client.AutoGenerated; using Robust.Client.Console; @@ -7,8 +9,6 @@ using Robust.Client.UserInterface.XAML; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using System; -using System.Collections.Generic; namespace Content.Client.Administration.UI.ManageSolutions { @@ -46,8 +46,8 @@ namespace Content.Client.Administration.UI.ManageSolutions { _target = target; - var targetName = _entityManager.TryGetEntity(target, out var entity) - ? IoCManager.Resolve().GetComponent(entity).EntityName + var targetName = _entityManager.EntityExists(target) + ? IoCManager.Resolve().GetComponent(target).EntityName : string.Empty; Title = Loc.GetString("admin-solutions-window-title", ("targetName", targetName)); diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs index b4282c04e9..7bd4aedb00 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) { - IEntity? tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier) : null).GridID; + var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.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 7d2ebf9356..1490897877 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using Content.Client.Atmos.EntitySystems; -using Content.Shared.Atmos; using Content.Shared.Atmos.Prototypes; using JetBrains.Annotations; using Robust.Client.AutoGenerated; @@ -28,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) { - IEntity? tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier) : null).GridID; + var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.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 df931a36d3..a675818876 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using Content.Client.Atmos.EntitySystems; -using Content.Shared.Atmos; using Content.Shared.Atmos.Prototypes; using JetBrains.Annotations; using Robust.Client.AutoGenerated; @@ -28,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) { - IEntity? tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier) : null).GridID; + var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.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 14d2be159c..cfd19850f3 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) { - IEntity? tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = (tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier) : null).GridID; + var tempQualifier = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var playerGrid = (tempQualifier != default ? IoCManager.Resolve().GetComponent(tempQualifier.Value) : null)?.GridID; GridOptions.AddItem($"{grid.Index} {(playerGrid == grid.Index ? " (Current)" : "")}"); } diff --git a/Content.Client/Animations/ReusableAnimations.cs b/Content.Client/Animations/ReusableAnimations.cs index 98c7096db5..5afd1124c8 100644 --- a/Content.Client/Animations/ReusableAnimations.cs +++ b/Content.Client/Animations/ReusableAnimations.cs @@ -12,7 +12,7 @@ namespace Content.Client.Animations { public static class ReusableAnimations { - public static void AnimateEntityPickup(IEntity entity, EntityCoordinates initialPosition, Vector2 finalPosition) + public static void AnimateEntityPickup(EntityUid entity, EntityCoordinates initialPosition, Vector2 finalPosition) { var animatableClone = IoCManager.Resolve().SpawnEntity("clientsideclone", initialPosition); string val = IoCManager.Resolve().GetComponent(entity).EntityName; @@ -28,7 +28,7 @@ namespace Content.Client.Animations var animations = IoCManager.Resolve().GetComponent(animatableClone); animations.AnimationCompleted += (_) => { - IoCManager.Resolve().DeleteEntity((EntityUid) animatableClone); + IoCManager.Resolve().DeleteEntity(animatableClone); }; animations.Play(new Animation diff --git a/Content.Client/Atmos/Visualizers/AtmosPlaqueVisualizer.cs b/Content.Client/Atmos/Visualizers/AtmosPlaqueVisualizer.cs index 5a5b1f30cc..c007b465f0 100644 --- a/Content.Client/Atmos/Visualizers/AtmosPlaqueVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/AtmosPlaqueVisualizer.cs @@ -13,7 +13,7 @@ namespace Content.Client.Atmos.Visualizers [DataField("layer")] private int Layer { get; } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Atmos/Visualizers/EnabledAtmosDeviceVisualizer.cs b/Content.Client/Atmos/Visualizers/EnabledAtmosDeviceVisualizer.cs index 24af950e1e..754358c84f 100644 --- a/Content.Client/Atmos/Visualizers/EnabledAtmosDeviceVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/EnabledAtmosDeviceVisualizer.cs @@ -2,6 +2,7 @@ using System; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Atmos.Visualizers @@ -20,7 +21,8 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if(component.TryGetData(DataKey, out bool enabled) && sprite.LayerMapTryGet(LayerMap, out var layer)) diff --git a/Content.Client/Atmos/Visualizers/FireVisualizer.cs b/Content.Client/Atmos/Visualizers/FireVisualizer.cs index 7e6e0b7835..bac26efaa7 100644 --- a/Content.Client/Atmos/Visualizers/FireVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/FireVisualizer.cs @@ -1,5 +1,4 @@ using Content.Shared.Atmos; -using Content.Shared.Atmos.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -23,7 +22,7 @@ namespace Content.Client.Atmos.Visualizers [DataField("sprite")] private string? _sprite; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Atmos/Visualizers/GasAnalyzerVisualizer.cs b/Content.Client/Atmos/Visualizers/GasAnalyzerVisualizer.cs index b57d3fb7c7..ca5eca40a6 100644 --- a/Content.Client/Atmos/Visualizers/GasAnalyzerVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/GasAnalyzerVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Atmos.Visualizers @@ -18,7 +19,8 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Atmos/Visualizers/GasCanisterVisualizer.cs b/Content.Client/Atmos/Visualizers/GasCanisterVisualizer.cs index 1bc4c268b3..99ba7c2539 100644 --- a/Content.Client/Atmos/Visualizers/GasCanisterVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/GasCanisterVisualizer.cs @@ -16,7 +16,7 @@ namespace Content.Client.Atmos.Visualizers [DataField("insertedTankState")] private readonly string _insertedTankState = string.Empty; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -32,7 +32,8 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Atmos/Visualizers/GasPortableVisualizer.cs b/Content.Client/Atmos/Visualizers/GasPortableVisualizer.cs index e66cfab97c..42251edaaf 100644 --- a/Content.Client/Atmos/Visualizers/GasPortableVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/GasPortableVisualizer.cs @@ -13,7 +13,7 @@ namespace Content.Client.Atmos.Visualizers [DataField("stateConnected")] private string? _stateConnected; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -30,7 +30,8 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Atmos/Visualizers/PipeConnectorVisualizer.cs b/Content.Client/Atmos/Visualizers/PipeConnectorVisualizer.cs index 13d10be7f6..bab0d8134c 100644 --- a/Content.Client/Atmos/Visualizers/PipeConnectorVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/PipeConnectorVisualizer.cs @@ -37,11 +37,12 @@ namespace Content.Client.Atmos.Visualizers Logger.Error($"{nameof(PipeConnectorVisualizer)} could not load to load RSI {rsiString}."); } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); - if (!IoCManager.Resolve().TryGetComponent(entity, out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(entity, out var sprite)) return; if (_connectorRsi == null) @@ -52,7 +53,7 @@ namespace Content.Client.Atmos.Visualizers sprite.LayerMapReserveBlank(layerKey); var layer = sprite.LayerMapGet(layerKey); sprite.LayerSetRSI(layer, _connectorRsi); - var layerState = _baseState + ((PipeDirection) layerKey).ToString(); + var layerState = _baseState + ((PipeDirection) layerKey); sprite.LayerSetState(layer, layerState); } } @@ -61,10 +62,11 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var xform)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out var xform)) return; - if (!component.Owner.TryGetComponent(out var sprite)) + if (!entities.TryGetComponent(component.Owner, out var sprite)) return; if (!component.TryGetData(PipeColorVisuals.Color, out Color color)) diff --git a/Content.Client/Atmos/Visualizers/ScrubberVisualizer.cs b/Content.Client/Atmos/Visualizers/ScrubberVisualizer.cs index 7c5906bafc..295633cc35 100644 --- a/Content.Client/Atmos/Visualizers/ScrubberVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/ScrubberVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Atmos.Piping.Unary.Visuals; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Atmos.Visualizers { @@ -18,7 +19,8 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if (!component.TryGetData(ScrubberVisuals.State, out ScrubberState state)) diff --git a/Content.Client/Atmos/Visualizers/VentPumpVisualizer.cs b/Content.Client/Atmos/Visualizers/VentPumpVisualizer.cs index e1d3d51196..15bf0938de 100644 --- a/Content.Client/Atmos/Visualizers/VentPumpVisualizer.cs +++ b/Content.Client/Atmos/Visualizers/VentPumpVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Atmos.Visuals; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Atmos.Visualizers { @@ -17,7 +18,8 @@ namespace Content.Client.Atmos.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if (!component.TryGetData(VentPumpVisuals.State, out VentPumpState state)) diff --git a/Content.Client/Audio/AmbientSoundSystem.cs b/Content.Client/Audio/AmbientSoundSystem.cs index 5017890886..f4cff46979 100644 --- a/Content.Client/Audio/AmbientSoundSystem.cs +++ b/Content.Client/Audio/AmbientSoundSystem.cs @@ -90,17 +90,17 @@ namespace Content.Client.Audio _accumulator -= _cooldown; var player = _playerManager.LocalPlayer?.ControlledEntity; - if (player == null) + if (player == default) { ClearSounds(); return; } - var coordinates = IoCManager.Resolve().GetComponent(player).Coordinates; + var coordinates = EntityManager.GetComponent(player.Value).Coordinates; foreach (var (comp, (stream, _)) in _playingSounds.ToArray()) { - if (!comp.Deleted && comp.Enabled && IoCManager.Resolve().GetComponent(comp.Owner).Coordinates.TryDistance(EntityManager, coordinates, out var range) && + if (!comp.Deleted && comp.Enabled && EntityManager.GetComponent(comp.Owner).Coordinates.TryDistance(EntityManager, coordinates, out var range) && range <= comp.Range) { continue; @@ -136,11 +136,11 @@ namespace Content.Client.Audio foreach (var entity in _lookup.GetEntitiesInRange(coordinates, _maxAmbientRange, LookupFlags.Approximate | LookupFlags.IncludeAnchored)) { - if (!IoCManager.Resolve().TryGetComponent(entity, out AmbientSoundComponent? ambientComp) || + if (!EntityManager.TryGetComponent(entity, out AmbientSoundComponent? ambientComp) || _playingSounds.ContainsKey(ambientComp) || !ambientComp.Enabled || // We'll also do this crude distance check because it's what we're doing in the active loop above. - !IoCManager.Resolve().GetComponent(entity).Coordinates.TryDistance(EntityManager, coordinates, out var range) || + !EntityManager.GetComponent(entity).Coordinates.TryDistance(EntityManager, coordinates, out var range) || range > ambientComp.Range - RangeBuffer) { continue; diff --git a/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs b/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs index a2a96ca937..46615f7a3b 100644 --- a/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs +++ b/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs @@ -15,7 +15,7 @@ namespace Content.Client.Body.UI private BodyScannerDisplay? _display; [ViewVariables] - private IEntity? _entity; + private EntityUid _entity; public BodyScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } @@ -36,7 +36,7 @@ namespace Content.Client.Body.UI return; } - if (!IoCManager.Resolve().TryGetEntity(scannerState.Uid, out _entity)) + if (!IoCManager.Resolve().EntityExists(scannerState.Uid)) { throw new ArgumentException($"Received an invalid entity with id {scannerState.Uid} for body scanner with id {Owner.Owner} at {IoCManager.Resolve().GetComponent(Owner.Owner).MapPosition}"); } diff --git a/Content.Client/Body/UI/BodyScannerDisplay.cs b/Content.Client/Body/UI/BodyScannerDisplay.cs index 8932f7df27..e2212b4a6a 100644 --- a/Content.Client/Body/UI/BodyScannerDisplay.cs +++ b/Content.Client/Body/UI/BodyScannerDisplay.cs @@ -1,6 +1,5 @@ using System.Linq; using Content.Shared.Body.Components; -using Content.Shared.Body.Part; using Content.Shared.Damage; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; @@ -14,7 +13,7 @@ namespace Content.Client.Body.UI { public sealed class BodyScannerDisplay : SS14Window { - private IEntity? _currentEntity; + private EntityUid _currentEntity; private SharedBodyPartComponent? _currentBodyPart; public BodyScannerDisplay(BodyScannerBoundUserInterface owner) @@ -103,7 +102,7 @@ namespace Content.Client.Body.UI private RichTextLabel MechanismInfoLabel { get; } - public void UpdateDisplay(IEntity entity) + public void UpdateDisplay(EntityUid entity) { if(entity == null) return; diff --git a/Content.Client/Botany/PlantHolderVisualizer.cs b/Content.Client/Botany/PlantHolderVisualizer.cs index 0a5acd3ebe..e9be155804 100644 --- a/Content.Client/Botany/PlantHolderVisualizer.cs +++ b/Content.Client/Botany/PlantHolderVisualizer.cs @@ -10,7 +10,7 @@ namespace Content.Client.Botany [UsedImplicitly] public class PlantHolderVisualizer : AppearanceVisualizer { - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Buckle/BuckleComponent.cs b/Content.Client/Buckle/BuckleComponent.cs index ec4ed91c81..0842d56402 100644 --- a/Content.Client/Buckle/BuckleComponent.cs +++ b/Content.Client/Buckle/BuckleComponent.cs @@ -30,7 +30,7 @@ namespace Content.Client.Buckle _buckled = buckle.Buckled; LastEntityBuckledTo = buckle.LastEntityBuckledTo; DontCollide = buckle.DontCollide; - if (!IoCManager.Resolve().TryGetComponent(OwnerUid, out SpriteComponent? ownerSprite)) + if (!IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? ownerSprite)) { return; } diff --git a/Content.Client/Cabinet/ItemCabinetVisualizer.cs b/Content.Client/Cabinet/ItemCabinetVisualizer.cs index d3f3d5bc57..79e173665a 100644 --- a/Content.Client/Cabinet/ItemCabinetVisualizer.cs +++ b/Content.Client/Cabinet/ItemCabinetVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Cabinet; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Cabinet @@ -19,7 +20,8 @@ namespace Content.Client.Cabinet { base.OnChangeData(component); - if (component.Owner.TryGetComponent(out var sprite) + var entities = IoCManager.Resolve(); + if (entities.TryGetComponent(component.Owner, out SpriteComponent sprite) && component.TryGetData(ItemCabinetVisuals.IsOpen, out bool isOpen) && component.TryGetData(ItemCabinetVisuals.ContainsItem, out bool contains)) { diff --git a/Content.Client/CharacterAppearance/Systems/HumanoidAppearanceSystem.cs b/Content.Client/CharacterAppearance/Systems/HumanoidAppearanceSystem.cs index cd99376fdf..ba26c62db0 100644 --- a/Content.Client/CharacterAppearance/Systems/HumanoidAppearanceSystem.cs +++ b/Content.Client/CharacterAppearance/Systems/HumanoidAppearanceSystem.cs @@ -50,7 +50,7 @@ namespace Content.Client.CharacterAppearance.Systems { foreach (var (part, _) in body.Parts) { - if (EntityManager.TryGetComponent(part.OwnerUid, out SpriteComponent? partSprite)) + if (EntityManager.TryGetComponent(part.Owner, out SpriteComponent? partSprite)) { partSprite!.Color = component.Appearance.SkinColor; } @@ -113,7 +113,7 @@ namespace Content.Client.CharacterAppearance.Systems return; } - if (!entityManager.HasComponent(args.Args.Part.OwnerUid)) + if (!entityManager.HasComponent(args.Args.Part.Owner)) { return; } @@ -136,7 +136,7 @@ namespace Content.Client.CharacterAppearance.Systems return; } - if (!EntityManager.HasComponent(args.Args.Part.OwnerUid)) + if (!EntityManager.HasComponent(args.Args.Part.Owner)) { return; } diff --git a/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs b/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs index d8897a8e5b..d304009e45 100644 --- a/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs +++ b/Content.Client/CharacterInterface/CharacterInterfaceSystem.cs @@ -37,8 +37,8 @@ namespace Content.Client.CharacterInterface private void HandleOpenCharacterMenu() { - if (_playerManager.LocalPlayer?.ControlledEntity == null - || !IoCManager.Resolve().TryGetComponent(_playerManager.LocalPlayer.ControlledEntity, out CharacterInterfaceComponent? characterInterface)) + if (_playerManager.LocalPlayer?.ControlledEntity == default + || !EntityManager.TryGetComponent(_playerManager.LocalPlayer.ControlledEntity, out CharacterInterfaceComponent? characterInterface)) { return; } diff --git a/Content.Client/Chat/Managers/ChatManager.cs b/Content.Client/Chat/Managers/ChatManager.cs index 2111b460a2..3a87ae195c 100644 --- a/Content.Client/Chat/Managers/ChatManager.cs +++ b/Content.Client/Chat/Managers/ChatManager.cs @@ -231,7 +231,9 @@ namespace Content.Client.Chat.Managers ChatPermissionsUpdated?.Invoke(new ChatPermissionsUpdatedEventArgs {OldSelectableChannels = oldSelectable}); } - public bool IsGhost => _playerManager.LocalPlayer?.ControlledEntity is {} uid && _entityManager.HasComponent(uid); + public bool IsGhost => _playerManager.LocalPlayer?.ControlledEntity is {} uid && + uid.IsValid() && + _entityManager.HasComponent(uid); public void FrameUpdate(FrameEventArgs delta) { @@ -241,11 +243,11 @@ namespace Content.Client.Chat.Managers return; } - foreach (var (entityUid, queueData) in _queuedSpeechBubbles.ShallowClone()) + foreach (var (entity, queueData) in _queuedSpeechBubbles.ShallowClone()) { - if (!_entityManager.TryGetEntity(entityUid, out var entity)) + if (!_entityManager.EntityExists(entity)) { - _queuedSpeechBubbles.Remove(entityUid); + _queuedSpeechBubbles.Remove(entity); continue; } @@ -257,7 +259,7 @@ namespace Content.Client.Chat.Managers if (queueData.MessageQueue.Count == 0) { - _queuedSpeechBubbles.Remove(entityUid); + _queuedSpeechBubbles.Remove(entity); continue; } @@ -412,7 +414,7 @@ namespace Content.Client.Chat.Managers private void AddSpeechBubble(MsgChatMessage msg, SpeechBubble.SpeechType speechType) { - if (!_entityManager.TryGetEntity(msg.SenderEntity, out var entity)) + if (!_entityManager.EntityExists(msg.SenderEntity)) { Logger.WarningS("chat", "Got local chat message with invalid sender entity: {0}", msg.SenderEntity); return; @@ -422,7 +424,7 @@ namespace Content.Client.Chat.Managers foreach (var message in messages) { - EnqueueSpeechBubble(entity, message, speechType); + EnqueueSpeechBubble(msg.SenderEntity, message, speechType); } } @@ -472,7 +474,7 @@ namespace Content.Client.Chat.Managers return messages; } - private void EnqueueSpeechBubble(IEntity entity, string contents, SpeechBubble.SpeechType speechType) + private void EnqueueSpeechBubble(EntityUid entity, string contents, SpeechBubble.SpeechType speechType) { // Don't enqueue speech bubbles for other maps. TODO: Support multiple viewports/maps? if (IoCManager.Resolve().GetComponent(entity).MapID != _eyeManager.CurrentMap) @@ -491,7 +493,7 @@ namespace Content.Client.Chat.Managers }); } - private void CreateSpeechBubble(IEntity entity, SpeechBubbleData speechData) + private void CreateSpeechBubble(EntityUid entity, SpeechBubbleData speechData) { var bubble = SpeechBubble.CreateSpeechBubble(speechData.Type, speechData.Message, entity, _eyeManager, this); diff --git a/Content.Client/Chat/UI/SpeechBubble.cs b/Content.Client/Chat/UI/SpeechBubble.cs index 2ac75d3a0c..db2ad57d4f 100644 --- a/Content.Client/Chat/UI/SpeechBubble.cs +++ b/Content.Client/Chat/UI/SpeechBubble.cs @@ -36,7 +36,7 @@ namespace Content.Client.Chat.UI private const float EntityVerticalOffset = 0.5f; private readonly IEyeManager _eyeManager; - private readonly IEntity _senderEntity; + private readonly EntityUid _senderEntity; private readonly IChatManager _chatManager; private float _timeLeft = TotalTime; @@ -46,7 +46,7 @@ namespace Content.Client.Chat.UI public float ContentHeight { get; private set; } - public static SpeechBubble CreateSpeechBubble(SpeechType type, string text, IEntity senderEntity, IEyeManager eyeManager, IChatManager chatManager) + public static SpeechBubble CreateSpeechBubble(SpeechType type, string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager) { switch (type) { @@ -61,7 +61,7 @@ namespace Content.Client.Chat.UI } } - public SpeechBubble(string text, IEntity senderEntity, IEyeManager eyeManager, IChatManager chatManager) + public SpeechBubble(string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager) { _chatManager = chatManager; _senderEntity = senderEntity; @@ -162,7 +162,7 @@ namespace Content.Client.Chat.UI public class EmoteSpeechBubble : SpeechBubble { - public EmoteSpeechBubble(string text, IEntity senderEntity, IEyeManager eyeManager, IChatManager chatManager) + public EmoteSpeechBubble(string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager) : base(text, senderEntity, eyeManager, chatManager) { } @@ -188,7 +188,7 @@ namespace Content.Client.Chat.UI public class SaySpeechBubble : SpeechBubble { - public SaySpeechBubble(string text, IEntity senderEntity, IEyeManager eyeManager, IChatManager chatManager) + public SaySpeechBubble(string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager) : base(text, senderEntity, eyeManager, chatManager) { } diff --git a/Content.Client/Chemistry/Visualizers/FoamVisualizer.cs b/Content.Client/Chemistry/Visualizers/FoamVisualizer.cs index 99a2dd3d80..2cb7a4bef5 100644 --- a/Content.Client/Chemistry/Visualizers/FoamVisualizer.cs +++ b/Content.Client/Chemistry/Visualizers/FoamVisualizer.cs @@ -4,6 +4,7 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; @@ -36,11 +37,12 @@ namespace Content.Client.Chemistry.Visualizers { base.OnChangeData(component); + var entities = IoCManager.Resolve(); if (component.TryGetData(FoamVisuals.State, out var state)) { if (state) { - if (component.Owner.TryGetComponent(out AnimationPlayerComponent? animPlayer)) + if (entities.TryGetComponent(component.Owner, out AnimationPlayerComponent? animPlayer)) { if (!animPlayer.HasRunningAnimation(AnimationKey)) animPlayer.Play(_foamDissolve, AnimationKey); @@ -50,7 +52,7 @@ namespace Content.Client.Chemistry.Visualizers if (component.TryGetData(FoamVisuals.Color, out var color)) { - if (component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + if (entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { sprite.Color = color; } diff --git a/Content.Client/Chemistry/Visualizers/SmokeVisualizer.cs b/Content.Client/Chemistry/Visualizers/SmokeVisualizer.cs index 89c2d2fd18..666afaa4f6 100644 --- a/Content.Client/Chemistry/Visualizers/SmokeVisualizer.cs +++ b/Content.Client/Chemistry/Visualizers/SmokeVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; namespace Content.Client.Chemistry.Visualizers @@ -13,9 +14,10 @@ namespace Content.Client.Chemistry.Visualizers { base.OnChangeData(component); + var entities = IoCManager.Resolve(); if (component.TryGetData(SmokeVisuals.Color, out var color)) { - if (component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + if (entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { sprite.Color = color; } diff --git a/Content.Client/Chemistry/Visualizers/SolutionContainerVisualizer.cs b/Content.Client/Chemistry/Visualizers/SolutionContainerVisualizer.cs index 1911fe6bae..945aa03c73 100644 --- a/Content.Client/Chemistry/Visualizers/SolutionContainerVisualizer.cs +++ b/Content.Client/Chemistry/Visualizers/SolutionContainerVisualizer.cs @@ -3,6 +3,7 @@ using Content.Shared.Chemistry; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Serialization.Manager.Attributes; @@ -25,7 +26,8 @@ namespace Content.Client.Chemistry.Visualizers if (!component.TryGetData(SolutionContainerVisuals.VisualState, out SolutionContainerVisualState state)) return; - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if (!sprite.LayerMapTryGet(_layer, out var fillLayer)) return; var fillPercent = state.FilledVolumePercent; diff --git a/Content.Client/CombatMode/CombatModeSystem.cs b/Content.Client/CombatMode/CombatModeSystem.cs index 36122127c6..2c1b19f65f 100644 --- a/Content.Client/CombatMode/CombatModeSystem.cs +++ b/Content.Client/CombatMode/CombatModeSystem.cs @@ -4,7 +4,6 @@ using Content.Shared.Targeting; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.Player; -using Robust.Shared.GameObjects; using Robust.Shared.Input.Binding; using Robust.Shared.IoC; @@ -35,7 +34,7 @@ namespace Content.Client.CombatMode public bool IsInCombatMode() { var entity = _playerManager.LocalPlayer?.ControlledEntity; - if (entity == null || !IoCManager.Resolve().TryGetComponent(entity, out CombatModeComponent? combatMode)) + if (entity == default || !EntityManager.TryGetComponent(entity.Value, out CombatModeComponent? combatMode)) { return false; } diff --git a/Content.Client/Computer/ComputerVisualizer.cs b/Content.Client/Computer/ComputerVisualizer.cs index fc1bb76124..d2c65dfd70 100644 --- a/Content.Client/Computer/ComputerVisualizer.cs +++ b/Content.Client/Computer/ComputerVisualizer.cs @@ -20,7 +20,7 @@ namespace Content.Client.Computer private string BodyBrokenState = "broken"; private string ScreenBroken = "computer_broken"; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Construction/ConstructionSystem.cs b/Content.Client/Construction/ConstructionSystem.cs index 5c0c40e62c..9822517c98 100644 --- a/Content.Client/Construction/ConstructionSystem.cs +++ b/Content.Client/Construction/ConstructionSystem.cs @@ -17,7 +17,6 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; - namespace Content.Client.Construction { /// @@ -111,7 +110,7 @@ namespace Content.Client.Construction private void HandlePlayerAttached(PlayerAttachSysMessage msg) { - var available = IsCrafingAvailable(msg.AttachedEntity); + var available = IsCraftingAvailable(msg.AttachedEntity); UpdateCraftingAvailability(available); } @@ -131,9 +130,9 @@ namespace Content.Client.Construction CraftingEnabled = available; } - private static bool IsCrafingAvailable(IEntity? entity) + private static bool IsCraftingAvailable(EntityUid? entity) { - if (entity == null) + if (entity == default) return false; // TODO: Decide if entity can craft, using capabilities or something @@ -145,9 +144,7 @@ namespace Content.Client.Construction if (!args.EntityUid.IsValid() || !args.EntityUid.IsClientSide()) return false; - var entity = EntityManager.GetEntity(args.EntityUid); - - if (!IoCManager.Resolve().TryGetComponent(entity, out var ghostComp)) + if (!IoCManager.Resolve().TryGetComponent(args.EntityUid, out var ghostComp)) return false; TryStartConstruction(ghostComp.GhostId); @@ -159,10 +156,14 @@ namespace Content.Client.Construction /// public void SpawnGhost(ConstructionPrototype prototype, EntityCoordinates loc, Direction dir) { - var user = _playerManager.LocalPlayer?.ControlledEntity; + if (_playerManager.LocalPlayer?.ControlledEntity is not { } user || + !user.IsValid()) + { + return; + } // This InRangeUnobstructed should probably be replaced with "is there something blocking us in that tile?" - if (user == null || GhostPresent(loc) || !user.InRangeUnobstructed(loc, 20f, ignoreInsideBlocker: prototype.CanBuildInImpassable)) return; + if (GhostPresent(loc) || !user.InRangeUnobstructed(loc, 20f, ignoreInsideBlocker: prototype.CanBuildInImpassable)) return; foreach (var condition in prototype.Conditions) { @@ -226,7 +227,7 @@ namespace Content.Client.Construction { if (_ghosts.TryGetValue(ghostId, out var ghost)) { - IoCManager.Resolve().QueueDeleteEntity((EntityUid) ghost.Owner); + IoCManager.Resolve().QueueDeleteEntity(ghost.Owner); _ghosts.Remove(ghostId); } } @@ -238,7 +239,7 @@ namespace Content.Client.Construction { foreach (var (_, ghost) in _ghosts) { - IoCManager.Resolve().QueueDeleteEntity((EntityUid) ghost.Owner); + IoCManager.Resolve().QueueDeleteEntity(ghost.Owner); } _ghosts.Clear(); diff --git a/Content.Client/ContextMenu/UI/EntityMenuElement.cs b/Content.Client/ContextMenu/UI/EntityMenuElement.cs index 70b381a282..01005b9b20 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuElement.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuElement.cs @@ -1,4 +1,3 @@ -using Content.Client.Stylesheets; using Robust.Client.GameObjects; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; @@ -14,7 +13,7 @@ namespace Content.Client.ContextMenu.UI /// /// The entity that can be accessed by interacting with this element. /// - public IEntity? Entity; + public EntityUid Entity; /// /// How many entities are accessible through this element's sub-menus. @@ -24,10 +23,10 @@ namespace Content.Client.ContextMenu.UI /// public int Count; - public Label CountLabel; - public SpriteView EntityIcon = new SpriteView { OverrideDirection = Direction.South}; + public readonly Label CountLabel; + public readonly SpriteView EntityIcon = new() { OverrideDirection = Direction.South}; - public EntityMenuElement(IEntity? entity = null) : base() + public EntityMenuElement(EntityUid entity = default) { CountLabel = new Label { StyleClasses = { StyleClassEntityMenuCountText } }; Icon.AddChild(new LayoutContainer() { Children = { EntityIcon, CountLabel } }); @@ -37,7 +36,7 @@ namespace Content.Client.ContextMenu.UI LayoutContainer.SetGrowVertical(CountLabel, LayoutContainer.GrowDirection.Begin); Entity = entity; - if (Entity != null) + if (Entity != default) { Count = 1; CountLabel.Visible = false; @@ -48,7 +47,7 @@ namespace Content.Client.ContextMenu.UI protected override void Dispose(bool disposing) { base.Dispose(disposing); - Entity = null; + Entity = default; Count = 0; } @@ -56,12 +55,12 @@ namespace Content.Client.ContextMenu.UI /// Update the icon and text of this element based on the given entity or this element's own entity if none /// is provided. /// - public void UpdateEntity(IEntity? entity = null) + public void UpdateEntity(EntityUid entity = default) { - if (Entity != null && IoCManager.Resolve().EntityExists(Entity)) - entity ??= Entity; + if (Entity != default && IoCManager.Resolve().EntityExists(Entity) && !entity.Valid) + entity = Entity; - if (entity == null) + if (entity == default) { Text = string.Empty; return; diff --git a/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs b/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs index 3a2d17b105..1fc6bf1d90 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuPresenter.cs @@ -18,8 +18,8 @@ using Robust.Shared.Input.Binding; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; -using Robust.Shared.Prototypes; using Robust.Shared.Timing; + namespace Content.Client.ContextMenu.UI { /// @@ -51,7 +51,7 @@ namespace Content.Client.ContextMenu.UI /// /// This is used remove GUI elements when the entities are deleted. or leave the LOS. /// - public Dictionary Elements = new(); + public Dictionary Elements = new(); public EntityMenuPresenter(VerbSystem verbSystem) : base() { @@ -77,7 +77,7 @@ namespace Content.Client.ContextMenu.UI /// /// Given a list of entities, sort them into groups and them to a new entity menu. /// - public void OpenRootMenu(List entities) + public void OpenRootMenu(List entities) { // close any old menus first. if (RootMenu.Visible) @@ -101,8 +101,12 @@ namespace Content.Client.ContextMenu.UI // get an entity associated with this element var entity = entityElement.Entity; - entity ??= GetFirstEntityOrNull(element.SubMenu); - if (entity == null) + if (!entity.Valid) + { + entity = GetFirstEntityOrNull(element.SubMenu); + } + + if (!entity.Valid) return; // open verb menu? @@ -173,9 +177,8 @@ namespace Content.Client.ContextMenu.UI if (!RootMenu.Visible) return; - var player = _playerManager.LocalPlayer?.ControlledEntity; - - if (player == null) + if (_playerManager.LocalPlayer?.ControlledEntity is not { } player || + !player.IsValid()) return; // Do we need to do in-range unOccluded checks? @@ -193,7 +196,7 @@ namespace Content.Client.ContextMenu.UI /// Add menu elements for a list of grouped entities; /// /// A list of entity groups. Entities are grouped together based on prototype. - private void AddToUI(List> entityGroups) + private void AddToUI(List> entityGroups) { // If there is only a single group. We will just directly list individual entities if (entityGroups.Count == 1) @@ -226,7 +229,7 @@ namespace Content.Client.ContextMenu.UI /// /// Given a group of entities, add a menu element that has a pop-up sub-menu listing group members /// - private void AddGroupToUI(List group) + private void AddGroupToUI(List group) { EntityMenuElement element = new(); ContextMenuPopup subMenu = new(this, element); @@ -245,7 +248,7 @@ namespace Content.Client.ContextMenu.UI /// /// Remove an entity from the entity context menu. /// - private void RemoveEntity(IEntity entity) + private void RemoveEntity(EntityUid entity) { // find the element associated with this entity if (!Elements.TryGetValue(entity, out var element)) @@ -323,17 +326,17 @@ namespace Content.Client.ContextMenu.UI /// /// Recursively look through a sub-menu and return the first entity. /// - private IEntity? GetFirstEntityOrNull(ContextMenuPopup? menu) + private EntityUid GetFirstEntityOrNull(ContextMenuPopup? menu) { if (menu == null) - return null; + return default; foreach (var element in menu.MenuBody.Children) { if (element is not EntityMenuElement entityElement) continue; - if (entityElement.Entity != null) + if (entityElement.Entity != default) { if (!((!IoCManager.Resolve().EntityExists(entityElement.Entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entityElement.Entity).EntityLifeStage) >= EntityLifeStage.Deleted)) return entityElement.Entity; @@ -342,11 +345,11 @@ namespace Content.Client.ContextMenu.UI // if the element has no entity, its a group of entities with another attached sub-menu. var entity = GetFirstEntityOrNull(entityElement.SubMenu); - if (entity != null) + if (entity != default) return entity; } - return null; + return default; } public override void OpenSubMenu(ContextMenuElement element) diff --git a/Content.Client/ContextMenu/UI/EntityMenuPresenterGrouping.cs b/Content.Client/ContextMenu/UI/EntityMenuPresenterGrouping.cs index 905c8a2f92..7c5884dce3 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuPresenterGrouping.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuPresenterGrouping.cs @@ -4,7 +4,6 @@ using System.Linq; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Prototypes; namespace Content.Client.ContextMenu.UI { @@ -18,7 +17,7 @@ namespace Content.Client.ContextMenu.UI GroupingContextMenuType = obj; } - private List> GroupEntities(IEnumerable entities, int depth = 0) + private List> GroupEntities(IEnumerable entities, int depth = 0) { if (GroupingContextMenuType == 0) { @@ -32,9 +31,9 @@ namespace Content.Client.ContextMenu.UI } } - private sealed class PrototypeAndStatesContextMenuComparer : IEqualityComparer + private sealed class PrototypeAndStatesContextMenuComparer : IEqualityComparer { - private static readonly List> EqualsList = new() + private static readonly List> EqualsList = new() { (a, b) => IoCManager.Resolve().GetComponent(a).EntityPrototype!.ID == IoCManager.Resolve().GetComponent(b).EntityPrototype!.ID, (a, b) => @@ -51,7 +50,7 @@ namespace Content.Client.ContextMenu.UI return xStates.OrderBy(t => t).SequenceEqual(yStates.OrderBy(t => t)); }, }; - private static readonly List> GetHashCodeList = new() + private static readonly List> GetHashCodeList = new() { e => EqualityComparer.Default.GetHashCode(IoCManager.Resolve().GetComponent(e).EntityPrototype!.ID), e => @@ -73,17 +72,17 @@ namespace Content.Client.ContextMenu.UI _depth = step > Count ? Count : step; } - public bool Equals(IEntity? x, IEntity? y) + public bool Equals(EntityUid x, EntityUid y) { - if (x == null) + if (x == default) { - return y == null; + return y == default; } - return y != null && EqualsList[_depth](x, y); + return y != default && EqualsList[_depth](x, y); } - public int GetHashCode(IEntity e) + public int GetHashCode(EntityUid e) { return GetHashCodeList[_depth](e); } diff --git a/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs b/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs index 6f025b6395..7afcbe687a 100644 --- a/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs +++ b/Content.Client/Conveyor/Visualizers/ConveyorVisualizer.cs @@ -3,6 +3,7 @@ using Content.Shared.Conveyor; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Conveyor.Visualizers @@ -21,7 +22,8 @@ namespace Content.Client.Conveyor.Visualizers private void ChangeState(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } @@ -40,7 +42,7 @@ namespace Content.Client.Conveyor.Visualizers } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs b/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs index bea07cbcc6..7006dedcc3 100644 --- a/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs +++ b/Content.Client/Conveyor/Visualizers/TwoWayLeverVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.MachineLinking; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Conveyor.Visualizers @@ -20,7 +21,8 @@ namespace Content.Client.Conveyor.Visualizers private void ChangeState(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } @@ -38,7 +40,7 @@ namespace Content.Client.Conveyor.Visualizers sprite.LayerSetState(0, texture); } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Damage/DamageVisualizer.cs b/Content.Client/Damage/DamageVisualizer.cs index 4b61ab7654..6a2ccbc029 100644 --- a/Content.Client/Damage/DamageVisualizer.cs +++ b/Content.Client/Damage/DamageVisualizer.cs @@ -195,7 +195,7 @@ namespace Content.Client.Damage public readonly string? Color; } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -207,7 +207,7 @@ namespace Content.Client.Damage InitializeVisualizer(entity, damageData); } - private void VerifyVisualizerSetup(IEntity entity, DamageVisualizerDataComponent damageData) + private void VerifyVisualizerSetup(EntityUid entity, DamageVisualizerDataComponent damageData) { if (_thresholds.Count < 1) { @@ -289,7 +289,7 @@ namespace Content.Client.Damage } } - private void InitializeVisualizer(IEntity entity, DamageVisualizerDataComponent damageData) + private void InitializeVisualizer(EntityUid entity, DamageVisualizerDataComponent damageData) { if (!IoCManager.Resolve().TryGetComponent(entity, out SpriteComponent? spriteComponent) || !IoCManager.Resolve().TryGetComponent(entity, out var damageComponent) @@ -504,7 +504,8 @@ namespace Content.Client.Damage public override void OnChangeData(AppearanceComponent component) { - if (!component.Owner.TryGetComponent(out var damageData)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out DamageVisualizerDataComponent damageData)) return; if (!damageData.Valid) @@ -525,8 +526,9 @@ namespace Content.Client.Damage private void HandleDamage(AppearanceComponent component, DamageVisualizerDataComponent damageData) { - if (!component.Owner.TryGetComponent(out var spriteComponent) - || !component.Owner.TryGetComponent(out var damageComponent)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent spriteComponent) + || !entities.TryGetComponent(component.Owner, out DamageableComponent damageComponent)) return; if (_targetLayers != null && _damageOverlayGroups != null) diff --git a/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs b/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs index 3153e671f1..78ff4bb4e7 100644 --- a/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs +++ b/Content.Client/Disposal/Visualizers/DisposalUnitVisualizer.cs @@ -70,7 +70,8 @@ namespace Content.Client.Disposal.Visualizers return; } - if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } @@ -144,7 +145,7 @@ namespace Content.Client.Disposal.Visualizers } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs b/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs index d4f53834ff..a8b865982e 100644 --- a/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs +++ b/Content.Client/Disposal/Visualizers/DisposalVisualizer.cs @@ -23,7 +23,8 @@ namespace Content.Client.Disposal.Visualizers private void ChangeState(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite)) { return; } @@ -53,7 +54,7 @@ namespace Content.Client.Disposal.Visualizers } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/DoAfter/DoAfterSystem.cs b/Content.Client/DoAfter/DoAfterSystem.cs index 31e0384939..62828c3bd6 100644 --- a/Content.Client/DoAfter/DoAfterSystem.cs +++ b/Content.Client/DoAfter/DoAfterSystem.cs @@ -31,7 +31,7 @@ namespace Content.Client.DoAfter /// public const float ExcessTime = 0.5f; - private IEntity? _attachedEntity; + private EntityUid _attachedEntity; public override void Initialize() { @@ -51,7 +51,7 @@ namespace Content.Client.DoAfter var currentTime = _gameTiming.CurTime; // Can't see any I guess? - if (_attachedEntity == null || (!IoCManager.Resolve().EntityExists(_attachedEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_attachedEntity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_attachedEntity == default || (!EntityManager.EntityExists(_attachedEntity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_attachedEntity).EntityLifeStage) >= EntityLifeStage.Deleted) return; var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f); @@ -59,23 +59,23 @@ namespace Content.Client.DoAfter foreach (var comp in EntityManager.EntityQuery(true)) { var doAfters = comp.DoAfters.ToList(); - var compPos = IoCManager.Resolve().GetComponent(comp.Owner).WorldPosition; + var compPos = EntityManager.GetComponent(comp.Owner).WorldPosition; if (doAfters.Count == 0 || - IoCManager.Resolve().GetComponent(comp.Owner).MapID != IoCManager.Resolve().GetComponent(_attachedEntity).MapID || + EntityManager.GetComponent(comp.Owner).MapID != EntityManager.GetComponent(_attachedEntity).MapID || !viewbox.Contains(compPos)) { comp.Disable(); continue; } - var range = (compPos - IoCManager.Resolve().GetComponent(_attachedEntity).WorldPosition).Length + + var range = (compPos - EntityManager.GetComponent(_attachedEntity).WorldPosition).Length + 0.01f; if (comp.Owner != _attachedEntity && !ExamineSystemShared.InRangeUnOccluded( - IoCManager.Resolve().GetComponent(_attachedEntity).MapPosition, - IoCManager.Resolve().GetComponent(comp.Owner).MapPosition, range, + EntityManager.GetComponent(_attachedEntity).MapPosition, + EntityManager.GetComponent(comp.Owner).MapPosition, range, entity => entity == comp.Owner || entity == _attachedEntity)) { comp.Disable(); @@ -84,7 +84,7 @@ namespace Content.Client.DoAfter comp.Enable(); - var userGrid = IoCManager.Resolve().GetComponent(comp.Owner).Coordinates; + var userGrid = EntityManager.GetComponent(comp.Owner).Coordinates; // Check cancellations / finishes foreach (var (id, doAfter) in doAfters) @@ -116,8 +116,8 @@ namespace Content.Client.DoAfter if (doAfter.BreakOnTargetMove) { - if (EntityManager.TryGetEntity(doAfter.TargetUid, out var targetEntity) && - !IoCManager.Resolve().GetComponent(targetEntity).Coordinates.InRange(EntityManager, doAfter.TargetGrid, + if (EntityManager.EntityExists(doAfter.TargetUid) && + !EntityManager.GetComponent(doAfter.TargetUid).Coordinates.InRange(EntityManager, doAfter.TargetGrid, doAfter.MovementThreshold)) { comp.Cancel(id, currentTime); diff --git a/Content.Client/DoAfter/UI/DoAfterGui.cs b/Content.Client/DoAfter/UI/DoAfterGui.cs index c07a919526..cab251d318 100644 --- a/Content.Client/DoAfter/UI/DoAfterGui.cs +++ b/Content.Client/DoAfter/UI/DoAfterGui.cs @@ -27,7 +27,7 @@ namespace Content.Client.DoAfter.UI // We'll store cancellations for a little bit just so we can flash the graphic to indicate it's cancelled private readonly Dictionary _cancelledDoAfters = new(); - public IEntity? AttachedEntity { get; set; } + public EntityUid AttachedEntity { get; set; } private ScreenCoordinates _playerPosition; public DoAfterGui() @@ -146,14 +146,8 @@ namespace Content.Client.DoAfter.UI { base.FrameUpdate(args); - IEntity? tempQualifier = AttachedEntity; - if (tempQualifier != null) - { - IoCManager.Resolve().EntityExists(tempQualifier); - } - - if (RETURNED_VALUE != true || - !IoCManager.Resolve().TryGetComponent(AttachedEntity, out DoAfterComponent? doAfterComponent)) + if (!AttachedEntity.IsValid() || + !_entityManager.TryGetComponent(AttachedEntity, out DoAfterComponent? doAfterComponent)) { Visible = false; return; diff --git a/Content.Client/Doors/AirlockVisualizer.cs b/Content.Client/Doors/AirlockVisualizer.cs index 2d44f9b42a..d8fcdafb8e 100644 --- a/Content.Client/Doors/AirlockVisualizer.cs +++ b/Content.Client/Doors/AirlockVisualizer.cs @@ -1,8 +1,6 @@ using System; using Content.Client.Wires.Visualizers; -using Content.Shared.Audio; using Content.Shared.Doors; -using Content.Shared.Sound; using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; @@ -110,7 +108,7 @@ namespace Content.Client.Doors } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { if (!IoCManager.Resolve().HasComponent(entity)) { diff --git a/Content.Client/DragDrop/DragDropSystem.cs b/Content.Client/DragDrop/DragDropSystem.cs index 840693aef4..f803ea78a4 100644 --- a/Content.Client/DragDrop/DragDropSystem.cs +++ b/Content.Client/DragDrop/DragDropSystem.cs @@ -54,9 +54,9 @@ namespace Content.Client.DragDrop // entity performing the drag action - private IEntity? _dragger; + private EntityUid _dragger; private readonly List _draggables = new(); - private IEntity? _dragShadow; + private EntityUid _dragShadow; // time since mouse down over the dragged entity private float _mouseDownTime; @@ -68,7 +68,7 @@ namespace Content.Client.DragDrop // can ignore any events sent to this system private bool _isReplaying; - private DragDropHelper _dragDropHelper = default!; + private DragDropHelper _dragDropHelper = default!; private ShaderInstance? _dropTargetInRangeShader; private ShaderInstance? _dropTargetOutOfRangeShader; @@ -77,7 +77,7 @@ namespace Content.Client.DragDrop public override void Initialize() { - _dragDropHelper = new DragDropHelper(OnBeginDrag, OnContinueDrag, OnEndDrag); + _dragDropHelper = new DragDropHelper(OnBeginDrag, OnContinueDrag, OnEndDrag); _dropTargetInRangeShader = _prototypeManager.Index(ShaderDropTargetInRange).Instance(); _dropTargetOutOfRangeShader = _prototypeManager.Index(ShaderDropTargetOutOfRange).Instance(); @@ -118,33 +118,32 @@ namespace Content.Client.DragDrop private bool OnUseMouseDown(in PointerInputCmdHandler.PointerInputCmdArgs args) { - if (args.Session?.AttachedEntity == null) + if (args.Session?.AttachedEntity is not {Valid: true} dragger) { return false; } - var dragger = args.Session.AttachedEntity; // cancel any current dragging if there is one (shouldn't be because they would've had to have lifted // the mouse, canceling the drag, but just being cautious) _dragDropHelper.EndDrag(); // possibly initiating a drag // check if the clicked entity is draggable - if (!EntityManager.TryGetEntity(args.EntityUid, out var entity)) + if (!EntityManager.EntityExists(args.EntityUid)) { return false; } // check if the entity is reachable - if (!_interactionSystem.InRangeUnobstructed(dragger, entity)) + if (!_interactionSystem.InRangeUnobstructed(dragger, args.EntityUid)) { return false; } var canDrag = false; - foreach (var draggable in IoCManager.Resolve().GetComponents(entity)) + foreach (var draggable in EntityManager.GetComponents(args.EntityUid)) { - var dragEventArgs = new StartDragDropEvent(dragger, entity); + var dragEventArgs = new StartDragDropEvent(dragger, args.EntityUid); if (!draggable.CanStartDrag(dragEventArgs)) { @@ -161,7 +160,7 @@ namespace Content.Client.DragDrop } // wait to initiate a drag - _dragDropHelper.MouseDown(entity); + _dragDropHelper.MouseDown(args.EntityUid); _dragger = dragger; _mouseDownTime = 0; @@ -176,19 +175,19 @@ namespace Content.Client.DragDrop private bool OnBeginDrag() { - if (_dragDropHelper.Dragged == null || (!IoCManager.Resolve().EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_dragDropHelper.Dragged == default || (!EntityManager.EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted) { // something happened to the clicked entity or we moved the mouse off the target so // we shouldn't replay the original click return false; } - if (IoCManager.Resolve().TryGetComponent(_dragDropHelper.Dragged, out var draggedSprite)) + if (EntityManager.TryGetComponent(_dragDropHelper.Dragged, out var draggedSprite)) { // pop up drag shadow under mouse var mousePos = _eyeManager.ScreenToMap(_dragDropHelper.MouseScreenPosition); _dragShadow = EntityManager.SpawnEntity("dragshadow", mousePos); - var dragSprite = IoCManager.Resolve().GetComponent(_dragShadow); + var dragSprite = EntityManager.GetComponent(_dragShadow); dragSprite.CopyFrom(draggedSprite); dragSprite.RenderOrder = EntityManager.CurrentTick.Value; dragSprite.Color = dragSprite.Color.WithAlpha(0.7f); @@ -196,7 +195,7 @@ namespace Content.Client.DragDrop dragSprite.DrawDepth = (int) DrawDepth.Overlays; if (!dragSprite.NoRotation) { - IoCManager.Resolve().GetComponent(_dragShadow).WorldRotation = IoCManager.Resolve().GetComponent(_dragDropHelper.Dragged).WorldRotation; + EntityManager.GetComponent(_dragShadow).WorldRotation = EntityManager.GetComponent(_dragDropHelper.Dragged).WorldRotation; } HighlightTargets(); @@ -207,13 +206,13 @@ namespace Content.Client.DragDrop } Logger.Warning("Unable to display drag shadow for {0} because it" + - " has no sprite component.", IoCManager.Resolve().GetComponent(_dragDropHelper.Dragged).EntityName); + " has no sprite component.", EntityManager.GetComponent(_dragDropHelper.Dragged).EntityName); return false; } private bool OnContinueDrag(float frameTime) { - if (_dragDropHelper.Dragged == null || (!IoCManager.Resolve().EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted) + if (_dragDropHelper.Dragged == default || (!EntityManager.EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : EntityManager.GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted) { return false; } @@ -221,7 +220,7 @@ namespace Content.Client.DragDrop DebugTools.AssertNotNull(_dragger); // still in range of the thing we are dragging? - if (!_interactionSystem.InRangeUnobstructed(_dragger!, _dragDropHelper.Dragged)) + if (!_interactionSystem.InRangeUnobstructed(_dragger, _dragDropHelper.Dragged)) { return false; } @@ -230,10 +229,10 @@ namespace Content.Client.DragDrop var mousePos = _eyeManager.ScreenToMap(_dragDropHelper.MouseScreenPosition); // TODO: would use MapPosition instead if it had a setter, but it has no setter. // is that intentional, or should we add a setter for Transform.MapPosition? - if (_dragShadow == null) + if (_dragShadow == default) return false; - IoCManager.Resolve().GetComponent(_dragShadow).WorldPosition = mousePos.Position; + EntityManager.GetComponent(_dragShadow).WorldPosition = mousePos.Position; _targetRecheckTime += frameTime; if (_targetRecheckTime > TargetRecheckInterval) @@ -248,22 +247,22 @@ namespace Content.Client.DragDrop private void OnEndDrag() { RemoveHighlights(); - if (_dragShadow != null) + if (_dragShadow != default) { EntityManager.DeleteEntity(_dragShadow); } EntityManager.EventBus.RaiseEvent(EventSource.Local, new OutlineToggleMessage(true)); - _dragShadow = null; + _dragShadow = default; _draggables.Clear(); - _dragger = null; + _dragger = default; _mouseDownTime = 0; _savedMouseDown = null; } private bool OnUseMouseUp(in PointerInputCmdHandler.PointerInputCmdArgs args) { - if (_dragDropHelper.IsDragging == false || _dragDropHelper.Dragged == null) + if (_dragDropHelper.IsDragging == false || _dragDropHelper.Dragged == default) { // haven't started the drag yet, quick mouseup, definitely treat it as a normal click by // replaying the original cmd @@ -287,7 +286,7 @@ namespace Content.Client.DragDrop return false; } - if (_dragger == null) + if (_dragger == default) { _dragDropHelper.EndDrag(); return false; @@ -295,7 +294,7 @@ namespace Content.Client.DragDrop // now when ending the drag, we will not replay the click because // by this time we've determined the input was actually a drag attempt - var range = (args.Coordinates.ToMapPos(EntityManager) - IoCManager.Resolve().GetComponent(_dragger).MapPosition.Position).Length + 0.01f; + var range = (args.Coordinates.ToMapPos(EntityManager) - EntityManager.GetComponent(_dragger).MapPosition.Position).Length + 0.01f; // tell the server we are dropping if we are over a valid drop target in range. // We don't use args.EntityUid here because drag interactions generally should // work even if there's something "on top" of the drop target @@ -330,7 +329,7 @@ namespace Content.Client.DragDrop if (!draggable.CanDrop(dropArgs)) continue; // tell the server about the drop attempt - RaiseNetworkEvent(new DragDropRequestEvent(args.Coordinates, _dragDropHelper.Dragged!, + RaiseNetworkEvent(new DragDropRequestEvent(args.Coordinates, _dragDropHelper.Dragged, entity)); draggable.Drop(dropArgs); @@ -340,9 +339,11 @@ namespace Content.Client.DragDrop } } - if (outOfRange) + if (outOfRange && + _playerManager.LocalPlayer?.ControlledEntity is { } player && + player.IsValid()) { - _playerManager.LocalPlayer?.ControlledEntity?.PopupMessage(Loc.GetString("drag-drop-system-out-of-range-text")); + player.PopupMessage(Loc.GetString("drag-drop-system-out-of-range-text")); } _dragDropHelper.EndDrag(); @@ -351,10 +352,10 @@ namespace Content.Client.DragDrop private void HighlightTargets() { - if (_dragDropHelper.Dragged == null || - (!IoCManager.Resolve().EntityExists(_dragDropHelper.Dragged) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_dragDropHelper.Dragged).EntityLifeStage) >= EntityLifeStage.Deleted || - _dragShadow == null || - (!IoCManager.Resolve().EntityExists(_dragShadow) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_dragShadow).EntityLifeStage) >= EntityLifeStage.Deleted) + 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) { Logger.Warning("Programming error. Can't highlight drag and drop targets, not currently " + "dragging anything or dragged entity / shadow was deleted."); @@ -374,12 +375,12 @@ namespace Content.Client.DragDrop var pvsEntities = IoCManager.Resolve().GetEntitiesIntersecting(_eyeManager.CurrentMap, bounds, LookupFlags.Approximate | LookupFlags.IncludeAnchored); foreach (var pvsEntity in pvsEntities) { - if (!IoCManager.Resolve().TryGetComponent(pvsEntity, out ISpriteComponent? inRangeSprite) || + if (!EntityManager.TryGetComponent(pvsEntity, out ISpriteComponent? inRangeSprite) || !inRangeSprite.Visible || pvsEntity == _dragDropHelper.Dragged) continue; // check if it's able to be dropped on by current dragged entity - var dropArgs = new DragDropEvent(_dragger!, IoCManager.Resolve().GetComponent(pvsEntity).Coordinates, _dragDropHelper.Dragged, pvsEntity); + var dropArgs = new DragDropEvent(_dragger, EntityManager.GetComponent(pvsEntity).Coordinates, _dragDropHelper.Dragged, pvsEntity); var valid = ValidDragDrop(dropArgs); if (valid == null) continue; @@ -422,7 +423,7 @@ namespace Content.Client.DragDrop bool? valid = null; - foreach (var comp in IoCManager.Resolve().GetComponents(eventArgs.Target)) + foreach (var comp in EntityManager.GetComponents(eventArgs.Target)) { if (!comp.CanDragDropOn(eventArgs)) { @@ -440,7 +441,7 @@ namespace Content.Client.DragDrop // Need at least one IDraggable to return true or else we can't do shit valid = false; - foreach (var comp in IoCManager.Resolve().GetComponents(eventArgs.User)) + foreach (var comp in EntityManager.GetComponents(eventArgs.User)) { if (!comp.CanDrop(eventArgs)) continue; valid = true; diff --git a/Content.Client/Examine/ExamineSystem.cs b/Content.Client/Examine/ExamineSystem.cs index b6ee62c791..e4186f1a35 100644 --- a/Content.Client/Examine/ExamineSystem.cs +++ b/Content.Client/Examine/ExamineSystem.cs @@ -10,7 +10,6 @@ using Robust.Client.Graphics; using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Input.Binding; using Robust.Shared.IoC; @@ -33,8 +32,8 @@ namespace Content.Client.Examine public const string StyleClassEntityTooltip = "entity-tooltip"; - private IEntity? _examinedEntity; - private IEntity? _playerEntity; + private EntityUid _examinedEntity; + private EntityUid _playerEntity; private Popup? _examineTooltipOpen; private CancellationTokenSource? _requestCancelTokenSource; @@ -51,8 +50,8 @@ namespace Content.Client.Examine public override void Update(float frameTime) { - if (_examineTooltipOpen == null || !_examineTooltipOpen.Visible) return; - if (_examinedEntity == null || _playerEntity == null) return; + if (_examineTooltipOpen is not {Visible: true}) return; + if (!_examinedEntity.Valid || !_playerEntity.Valid) return; if (!CanExamine(_playerEntity, _examinedEntity)) CloseTooltip(); @@ -64,7 +63,7 @@ namespace Content.Client.Examine base.Shutdown(); } - public override bool CanExamine(IEntity examiner, MapCoordinates target, Ignored? predicate = null) + public override bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null) { var b = _eyeManager.GetWorldViewbounds(); if (!b.Contains(target.Position)) @@ -73,16 +72,16 @@ namespace Content.Client.Examine return base.CanExamine(examiner, target, predicate); } - private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid uid) + private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid entity) { - if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var entity)) + if (!entity.IsValid() || !EntityManager.EntityExists(entity)) { return false; } - _playerEntity = _playerManager.LocalPlayer?.ControlledEntity; + _playerEntity = _playerManager.LocalPlayer?.ControlledEntity ?? default; - if (_playerEntity == null || !CanExamine(_playerEntity, entity)) + if (_playerEntity == default || !CanExamine(_playerEntity, entity)) { return false; } @@ -104,7 +103,7 @@ namespace Content.Client.Examine args.Verbs.Add(verb); } - public async void DoExamine(IEntity entity) + public async void DoExamine(EntityUid entity) { // Close any examine tooltip that might already be opened CloseTooltip(); diff --git a/Content.Client/Explosion/ClusterFlashVisualizer.cs b/Content.Client/Explosion/ClusterFlashVisualizer.cs index 7ca1c02e11..406ddcedc5 100644 --- a/Content.Client/Explosion/ClusterFlashVisualizer.cs +++ b/Content.Client/Explosion/ClusterFlashVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Explosion; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Explosion @@ -17,7 +18,8 @@ namespace Content.Client.Explosion { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out var sprite)) { return; } diff --git a/Content.Client/Flash/FlashSystem.cs b/Content.Client/Flash/FlashSystem.cs index 9ff86debd6..d6644811f5 100644 --- a/Content.Client/Flash/FlashSystem.cs +++ b/Content.Client/Flash/FlashSystem.cs @@ -27,7 +27,7 @@ namespace Content.Client.Flash return; // Yes, this code is awful. I'm just porting it to an entity system so don't blame me. - if (_playerManager.LocalPlayer != null && _playerManager.LocalPlayer.Session.AttachedEntityUid != uid) + if (_playerManager.LocalPlayer != null && _playerManager.LocalPlayer.Session.AttachedEntity != uid) { return; } diff --git a/Content.Client/Fluids/PuddleVisualizer.cs b/Content.Client/Fluids/PuddleVisualizer.cs index 20a272b865..77ac584c69 100644 --- a/Content.Client/Fluids/PuddleVisualizer.cs +++ b/Content.Client/Fluids/PuddleVisualizer.cs @@ -10,7 +10,6 @@ using Robust.Shared.Maths; using Robust.Shared.Random; using Robust.Shared.Serialization.Manager.Attributes; - namespace Content.Client.Fluids { [UsedImplicitly] @@ -21,7 +20,7 @@ namespace Content.Client.Fluids // Whether the underlying solution color should be used [DataField("recolor")] public bool Recolor; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -46,8 +45,9 @@ namespace Content.Client.Fluids { base.OnChangeData(component); + var entities = IoCManager.Resolve(); if (component.TryGetData(PuddleVisuals.VolumeScale, out var volumeScale) && - component.Owner.TryGetComponent(out var spriteComponent)) + entities.TryGetComponent(component.Owner, out var spriteComponent)) { var cappedScale = Math.Min(1.0f, volumeScale * 0.75f +0.25f); UpdateVisual(component, spriteComponent, cappedScale); diff --git a/Content.Client/Ghost/GhostSystem.cs b/Content.Client/Ghost/GhostSystem.cs index 63455ad8d0..57aff0b24c 100644 --- a/Content.Client/Ghost/GhostSystem.cs +++ b/Content.Client/Ghost/GhostSystem.cs @@ -4,7 +4,6 @@ using Content.Shared.Ghost; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.Player; -using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -36,7 +35,7 @@ namespace Content.Client.Ghost foreach (var ghost in EntityManager.GetAllComponents(typeof(GhostComponent), true)) { - if (EntityManager.TryGetComponent(ghost.OwnerUid, out SpriteComponent? sprite)) + if (EntityManager.TryGetComponent(ghost.Owner, out SpriteComponent? sprite)) { sprite.Visible = value; } @@ -60,7 +59,7 @@ namespace Content.Client.Ghost private void OnGhostInit(EntityUid uid, GhostComponent component, ComponentInit args) { - if (EntityManager.TryGetComponent(component.OwnerUid, out SpriteComponent? sprite)) + if (EntityManager.TryGetComponent(component.Owner, out SpriteComponent? sprite)) { sprite.Visible = GhostVisibility; } @@ -101,7 +100,7 @@ namespace Content.Client.Ghost private void OnGhostWarpsResponse(GhostWarpsResponseEvent msg) { - var entity = _playerManager.LocalPlayer?.ControlledEntity?.Uid; + var entity = _playerManager.LocalPlayer?.ControlledEntity; if (entity == null || !EntityManager.TryGetComponent(entity.Value, out GhostComponent? ghost)) diff --git a/Content.Client/Gravity/GravityGeneratorVisualizer.cs b/Content.Client/Gravity/GravityGeneratorVisualizer.cs index c426309836..cc1b9808ad 100644 --- a/Content.Client/Gravity/GravityGeneratorVisualizer.cs +++ b/Content.Client/Gravity/GravityGeneratorVisualizer.cs @@ -38,7 +38,7 @@ namespace Content.Client.Gravity } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Hands/HandsGui.xaml.cs b/Content.Client/Hands/HandsGui.xaml.cs index 5887cb2115..abe5f35685 100644 --- a/Content.Client/Hands/HandsGui.xaml.cs +++ b/Content.Client/Hands/HandsGui.xaml.cs @@ -250,7 +250,7 @@ namespace Content.Client.Hands /// The item being held in this hand. /// [ViewVariables] - public IEntity? HeldItem { get; } + public EntityUid HeldItem { get; } /// /// The button in the gui associated with this hand. Assumed to be set by gui shortly after being received from the client HandsComponent. @@ -258,7 +258,7 @@ namespace Content.Client.Hands [ViewVariables] public HandButton HandButton { get; set; } = default!; - public GuiHand(string name, HandLocation handLocation, IEntity? heldItem) + public GuiHand(string name, HandLocation handLocation, EntityUid heldItem) { Name = name; HandLocation = handLocation; diff --git a/Content.Client/Hands/HandsVisualizer.cs b/Content.Client/Hands/HandsVisualizer.cs index 993e1032b5..38704a05d1 100644 --- a/Content.Client/Hands/HandsVisualizer.cs +++ b/Content.Client/Hands/HandsVisualizer.cs @@ -1,24 +1,22 @@ +using System; using Content.Shared.Hands.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.ResourceManagement; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Maths; -using System; -using System.Collections.Generic; namespace Content.Client.Hands { [UsedImplicitly] public class HandsVisualizer : AppearanceVisualizer { - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out var sprite)) return; if (!component.TryGetData(HandsVisuals.VisualState, out HandsVisualState visualState)) return; foreach (HandLocation location in Enum.GetValues(typeof(HandLocation))) diff --git a/Content.Client/Hands/ShowHandItemOverlay.cs b/Content.Client/Hands/ShowHandItemOverlay.cs index 803cd98736..1c73cbc0a8 100644 --- a/Content.Client/Hands/ShowHandItemOverlay.cs +++ b/Content.Client/Hands/ShowHandItemOverlay.cs @@ -46,7 +46,7 @@ namespace Content.Client.Hands var sys = EntitySystem.Get(); var handEntity = sys.GetActiveHandEntity(); - if (handEntity == null || !_cfg.GetCVar(CCVars.HudHeldItemShow) || !IoCManager.Resolve().HasComponent(handEntity)) + if (handEntity == default || !_cfg.GetCVar(CCVars.HudHeldItemShow) || !IoCManager.Resolve().HasComponent(handEntity)) return; var screen = args.ScreenHandle; diff --git a/Content.Client/Hands/Systems/HandsSystem.cs b/Content.Client/Hands/Systems/HandsSystem.cs index 1bcb60c113..ea38663bbc 100644 --- a/Content.Client/Hands/Systems/HandsSystem.cs +++ b/Content.Client/Hands/Systems/HandsSystem.cs @@ -56,13 +56,13 @@ namespace Content.Client.Hands private void HandlePickupAnimation(PickupAnimationMessage msg) { - if (!EntityManager.TryGetEntity(msg.EntityUid, out var entity)) + if (!msg.EntityUid.IsValid()) return; if (!_gameTiming.IsFirstTimePredicted) return; - ReusableAnimations.AnimateEntityPickup(entity, msg.InitialPosition, msg.FinalPosition); + ReusableAnimations.AnimateEntityPickup(msg.EntityUid, msg.InitialPosition, msg.FinalPosition); } public HandsGuiState GetGuiState() @@ -77,10 +77,10 @@ namespace Content.Client.Hands return new HandsGuiState(states, hands.ActiveHand); } - public IEntity? GetActiveHandEntity() + public EntityUid GetActiveHandEntity() { if (GetPlayerHandsComponent() is not { ActiveHand: { } active } hands) - return null; + return default; return hands.GetHand(active).HeldEntity; } @@ -89,7 +89,7 @@ namespace Content.Client.Hands { var player = _playerManager.LocalPlayer?.ControlledEntity; - if (player == null || !IoCManager.Resolve().TryGetComponent(player, out HandsComponent? hands)) + if (player is not {Valid: true} || !EntityManager.TryGetComponent(player.Value, out HandsComponent? hands)) return null; return hands; @@ -106,7 +106,7 @@ namespace Content.Client.Hands var pressedEntity = pressedHand.HeldEntity; var activeEntity = activeHand.HeldEntity; - if (pressedHand == activeHand && activeEntity != null) + if (pressedHand == activeHand && activeEntity != default) { // use item in hand // it will always be attack_self() in my heart. @@ -114,21 +114,21 @@ namespace Content.Client.Hands return; } - if (pressedHand != activeHand && pressedEntity == null) + if (pressedHand != activeHand && pressedEntity == default) { // change active hand RaiseNetworkEvent(new RequestSetHandEvent(handName)); return; } - if (pressedHand != activeHand && pressedEntity != null && activeEntity != null) + if (pressedHand != activeHand && pressedEntity != default && activeEntity != default) { // use active item on held item RaiseNetworkEvent(new ClientInteractUsingInHandMsg(pressedHand.Name)); return; } - if (pressedHand != activeHand && pressedEntity != null && activeEntity == null) + if (pressedHand != activeHand && pressedEntity != default && activeEntity == default) { // use active item on held item RaiseNetworkEvent(new MoveItemFromHandMsg(pressedHand.Name)); diff --git a/Content.Client/HealthOverlay/HealthOverlaySystem.cs b/Content.Client/HealthOverlay/HealthOverlaySystem.cs index b8a69fa5be..65aa6a5ae4 100644 --- a/Content.Client/HealthOverlay/HealthOverlaySystem.cs +++ b/Content.Client/HealthOverlay/HealthOverlaySystem.cs @@ -17,7 +17,7 @@ namespace Content.Client.HealthOverlay [Dependency] private readonly IEyeManager _eyeManager = default!; private readonly Dictionary _guis = new(); - private IEntity? _attachedEntity; + private EntityUid _attachedEntity; private bool _enabled; public bool Enabled @@ -55,7 +55,7 @@ namespace Content.Client.HealthOverlay } _guis.Clear(); - _attachedEntity = null; + _attachedEntity = default; } private void HandlePlayerAttached(PlayerAttachSysMessage message) diff --git a/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs b/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs index d994dc16fa..3ada93fd88 100644 --- a/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs +++ b/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs @@ -16,8 +16,9 @@ namespace Content.Client.HealthOverlay.UI public class HealthOverlayGui : BoxContainer { [Dependency] private readonly IEyeManager _eyeManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; - public HealthOverlayGui(IEntity entity) + public HealthOverlayGui(EntityUid entity) { IoCManager.InjectDependencies(this); IoCManager.Resolve().StateRoot.AddChild(this); @@ -62,7 +63,7 @@ namespace Content.Client.HealthOverlay.UI public HealthOverlayBar CritBar { get; } - public IEntity Entity { get; } + public EntityUid Entity { get; } public void SetVisibility(bool val) { @@ -72,13 +73,13 @@ namespace Content.Client.HealthOverlay.UI private void MoreFrameUpdate(FrameEventArgs args) { - if ((!IoCManager.Resolve().EntityExists(Entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if ((!_entities.EntityExists(Entity) ? EntityLifeStage.Deleted : _entities.GetComponent(Entity).EntityLifeStage) >= EntityLifeStage.Deleted) { return; } - if (!IoCManager.Resolve().TryGetComponent(Entity, out MobStateComponent? mobState) || - !IoCManager.Resolve().TryGetComponent(Entity, out DamageableComponent? damageable)) + if (!_entities.TryGetComponent(Entity, out MobStateComponent? mobState) || + !_entities.TryGetComponent(Entity, out DamageableComponent? damageable)) { CritBar.Visible = false; HealthBar.Visible = false; @@ -138,8 +139,8 @@ namespace Content.Client.HealthOverlay.UI MoreFrameUpdate(args); - if ((!IoCManager.Resolve().EntityExists(Entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Entity).EntityLifeStage) >= EntityLifeStage.Deleted || - _eyeManager.CurrentMap != IoCManager.Resolve().GetComponent(Entity).MapID) + if ((!_entities.EntityExists(Entity) ? EntityLifeStage.Deleted : _entities.GetComponent(Entity).EntityLifeStage) >= EntityLifeStage.Deleted || + _eyeManager.CurrentMap != _entities.GetComponent(Entity).MapID) { Visible = false; return; @@ -147,7 +148,7 @@ namespace Content.Client.HealthOverlay.UI Visible = true; - var screenCoordinates = _eyeManager.CoordinatesToScreen(IoCManager.Resolve().GetComponent(Entity).Coordinates); + var screenCoordinates = _eyeManager.CoordinatesToScreen(_entities.GetComponent(Entity).Coordinates); var playerPosition = UserInterfaceManager.ScreenToUIPosition(screenCoordinates); LayoutContainer.SetPosition(this, new Vector2(playerPosition.X - Width / 2, playerPosition.Y - Height - 30.0f)); } diff --git a/Content.Client/IconSmoothing/IconSmoothSystem.cs b/Content.Client/IconSmoothing/IconSmoothSystem.cs index 17c7e1324c..c38d7c8352 100644 --- a/Content.Client/IconSmoothing/IconSmoothSystem.cs +++ b/Content.Client/IconSmoothing/IconSmoothSystem.cs @@ -51,12 +51,12 @@ namespace Content.Client.IconSmoothing // Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us. // This is simpler to implement. If you want to optimize it be my guest. var senderEnt = ev.Sender; - if (IoCManager.Resolve().EntityExists(senderEnt) && - _mapManager.TryGetGrid(IoCManager.Resolve().GetComponent(senderEnt).GridID, out var grid1) && - IoCManager.Resolve().TryGetComponent(senderEnt, out IconSmoothComponent? iconSmooth) + if (EntityManager.EntityExists(senderEnt) && + _mapManager.TryGetGrid(EntityManager.GetComponent(senderEnt).GridID, out var grid1) && + EntityManager.TryGetComponent(senderEnt, out IconSmoothComponent? iconSmooth) && iconSmooth.Running) { - var coords = IoCManager.Resolve().GetComponent(senderEnt).Coordinates; + var coords = EntityManager.GetComponent(senderEnt).Coordinates; _dirtyEntities.Enqueue(senderEnt); AddValidEntities(grid1.GetInDir(coords, Direction.North)); @@ -130,7 +130,7 @@ namespace Content.Client.IconSmoothing /// public sealed class IconSmoothDirtyEvent : EntityEventArgs { - public IconSmoothDirtyEvent(IEntity sender, (GridId grid, Vector2i pos)? lastPosition, IconSmoothingMode mode) + public IconSmoothDirtyEvent(EntityUid sender, (GridId grid, Vector2i pos)? lastPosition, IconSmoothingMode mode) { LastPosition = lastPosition; Mode = mode; @@ -139,6 +139,6 @@ namespace Content.Client.IconSmoothing public (GridId grid, Vector2i pos)? LastPosition { get; } public IconSmoothingMode Mode { get; } - public IEntity Sender { get; } + public EntityUid Sender { get; } } } diff --git a/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs b/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs index 2c3484953d..1bd9093681 100644 --- a/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs +++ b/Content.Client/Instruments/UI/InstrumentMenu.xaml.cs @@ -135,11 +135,11 @@ namespace Content.Client.Instruments.UI var instrument = _owner.Instrument; // If either the entity or component are null, return. - if (instrumentEnt == null || instrument == null) + if (instrumentEnt == default || instrument == default) return false; // If we're a handheld instrument, we might be in a container. Get it just in case. - instrumentEnt.TryGetContainerMan(out var conMan); + instrumentEnt.Value.TryGetContainerMan(out var conMan); var localPlayer = IoCManager.Resolve().LocalPlayer; @@ -151,7 +151,7 @@ namespace Content.Client.Instruments.UI || conMan.Owner != localPlayer.ControlledEntity))) return false; // We check that we're in range unobstructed just in case. - return localPlayer.InRangeUnobstructed(instrumentEnt, + return localPlayer.InRangeUnobstructed(instrumentEnt.Value, predicate: (e) => e == instrumentEnt || e == localPlayer.ControlledEntity); } diff --git a/Content.Client/Interactable/InteractionSystem.cs b/Content.Client/Interactable/InteractionSystem.cs index 4b48df0daa..2abb966549 100644 --- a/Content.Client/Interactable/InteractionSystem.cs +++ b/Content.Client/Interactable/InteractionSystem.cs @@ -9,10 +9,10 @@ namespace Content.Client.Interactable { public override bool CanAccessViaStorage(EntityUid user, EntityUid target) { - if (!EntityManager.TryGetEntity(target, out var entity)) + if (!EntityManager.EntityExists(target)) return false; - if (!entity.TryGetContainer(out var container)) + if (!target.TryGetContainer(out var container)) return false; if (!EntityManager.TryGetComponent(container.Owner, out ClientStorageComponent storage)) diff --git a/Content.Client/Interactable/UnobstructedExtensions.cs b/Content.Client/Interactable/UnobstructedExtensions.cs index 742126689c..5d0a3b6f4e 100644 --- a/Content.Client/Interactable/UnobstructedExtensions.cs +++ b/Content.Client/Interactable/UnobstructedExtensions.cs @@ -15,7 +15,7 @@ namespace Content.Client.Interactable public static bool InRangeUnobstructed( this LocalPlayer origin, - IEntity other, + EntityUid other, float range = InteractionRange, CollisionGroup collisionMask = CollisionGroup.Impassable, Ignored? predicate = null, @@ -78,7 +78,7 @@ namespace Content.Client.Interactable bool popup = false) { var originEntity = origin.ControlledEntity; - if (originEntity == null) + if (originEntity == default) { // TODO: Take into account the player's camera position? return false; diff --git a/Content.Client/Inventory/ClientInventoryComponent.cs b/Content.Client/Inventory/ClientInventoryComponent.cs index 7b686da558..143d0762f9 100644 --- a/Content.Client/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/Inventory/ClientInventoryComponent.cs @@ -3,9 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Client.Clothing; using Content.Shared.CharacterAppearance; -using Content.Shared.Chemistry; using Content.Shared.Inventory; -using Content.Shared.Movement.Components; using Content.Shared.Movement.EntitySystems; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -24,9 +22,9 @@ namespace Content.Client.Inventory [ComponentReference(typeof(SharedInventoryComponent))] public class ClientInventoryComponent : SharedInventoryComponent { - private readonly Dictionary _slots = new(); + private readonly Dictionary _slots = new(); - public IReadOnlyDictionary AllSlots => _slots; + public IReadOnlyDictionary AllSlots => _slots; [ViewVariables] public InventoryInterfaceController InterfaceController { get; private set; } = default!; @@ -78,9 +76,9 @@ namespace Content.Client.Inventory } } - public override bool IsEquipped(IEntity item) + public override bool IsEquipped(EntityUid item) { - return item != null && _slots.Values.Any(e => e == item); + return item != default && _slots.Values.Any(e => e == item); } public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) @@ -92,9 +90,9 @@ namespace Content.Client.Inventory var doneSlots = new HashSet(); - foreach (var (slot, entityUid) in state.Entities) + foreach (var (slot, entity) in state.Entities) { - if (!IoCManager.Resolve().TryGetEntity(entityUid, out var entity)) + if (!IoCManager.Resolve().EntityExists(entity)) { continue; } @@ -108,9 +106,7 @@ namespace Content.Client.Inventory if (state.HoverEntity != null) { - var (slot, (entityUid, fits)) = state.HoverEntity.Value; - var entity = IoCManager.Resolve().GetEntity(entityUid); - + var (slot, (entity, fits)) = state.HoverEntity.Value; InterfaceController?.HoverInSlot(slot, entity, fits); } @@ -126,14 +122,14 @@ namespace Content.Client.Inventory EntitySystem.Get().RefreshMovementSpeedModifiers(((IComponent) this).Owner); } - private void _setSlot(Slots slot, IEntity entity) + private void _setSlot(Slots slot, EntityUid entity) { SetSlotVisuals(slot, entity); InterfaceController?.AddToSlot(slot, entity); } - internal void SetSlotVisuals(Slots slot, IEntity entity) + internal void SetSlotVisuals(Slots slot, EntityUid entity) { if (_sprite == null) { @@ -230,12 +226,12 @@ namespace Content.Client.Inventory _playerAttached = true; } - public bool TryGetSlot(Slots slot, [NotNullWhen(true)] out IEntity? item) + public bool TryGetSlot(Slots slot, [NotNullWhen(true)] out EntityUid item) { return _slots.TryGetValue(slot, out item); } - public bool TryFindItemSlots(IEntity item, [NotNullWhen(true)] out Slots? slots) + public bool TryFindItemSlots(EntityUid item, [NotNullWhen(true)] out Slots? slots) { slots = null; diff --git a/Content.Client/Inventory/ClientInventorySystem.cs b/Content.Client/Inventory/ClientInventorySystem.cs index 43754ebd2a..6c691803fa 100644 --- a/Content.Client/Inventory/ClientInventorySystem.cs +++ b/Content.Client/Inventory/ClientInventorySystem.cs @@ -1,5 +1,4 @@ using Content.Client.HUD; -using Content.Client.Items.Components; using Content.Shared.Input; using Content.Shared.Inventory; using Content.Shared.Movement.EntitySystems; @@ -36,7 +35,7 @@ namespace Content.Client.Inventory // jesus christ, this is duplicated to server/client, should really just be shared.. private void OnSlipAttemptEvent(EntityUid uid, ClientInventoryComponent component, SlipAttemptEvent args) { - if (component.TryGetSlot(EquipmentSlotDefines.Slots.SHOES, out IEntity? shoes)) + if (component.TryGetSlot(EquipmentSlotDefines.Slots.SHOES, out EntityUid shoes)) { RaiseLocalEvent(shoes, args, false); } @@ -46,7 +45,7 @@ namespace Content.Client.Inventory { foreach (var (_, ent) in component.AllSlots) { - if (ent != null) + if (ent != default) { RaiseLocalEvent(ent, args, false); } diff --git a/Content.Client/Inventory/HumanInventoryInterfaceController.cs b/Content.Client/Inventory/HumanInventoryInterfaceController.cs index 413f09978b..e1e1b62c34 100644 --- a/Content.Client/Inventory/HumanInventoryInterfaceController.cs +++ b/Content.Client/Inventory/HumanInventoryInterfaceController.cs @@ -3,10 +3,8 @@ using System.Linq; using Content.Client.HUD; using Content.Client.Items.Managers; using Content.Client.Items.UI; -using Content.Shared; using Content.Shared.CCVar; using JetBrains.Annotations; -using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; @@ -15,7 +13,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; -using Robust.Shared.Prototypes; using static Content.Shared.Inventory.EquipmentSlotDefines; using static Robust.Client.UserInterface.Controls.BoxContainer; @@ -155,7 +152,7 @@ namespace Content.Client.Inventory return buttons; } - public override void AddToSlot(Slots slot, IEntity entity) + public override void AddToSlot(Slots slot, EntityUid entity) { base.AddToSlot(slot, entity); @@ -184,7 +181,7 @@ namespace Content.Client.Inventory } } - public override void HoverInSlot(Slots slot, IEntity entity, bool fits) + public override void HoverInSlot(Slots slot, EntityUid entity, bool fits) { base.HoverInSlot(slot, entity, fits); @@ -213,7 +210,7 @@ namespace Content.Client.Inventory private void ClearButton(ItemSlotButton button, Slots slot) { button.OnPressed = (e) => AddToInventory(e, slot); - _itemSlotManager.SetItemSlot(button, null); + _itemSlotManager.SetItemSlot(button, default); } public override void PlayerAttached() diff --git a/Content.Client/Inventory/InventoryInterfaceController.cs b/Content.Client/Inventory/InventoryInterfaceController.cs index 6aea2f466c..16f3efdf8f 100644 --- a/Content.Client/Inventory/InventoryInterfaceController.cs +++ b/Content.Client/Inventory/InventoryInterfaceController.cs @@ -46,11 +46,11 @@ namespace Content.Client.Inventory /// specified slot, if any. Empty if none. public abstract IEnumerable GetItemSlotButtons(EquipmentSlotDefines.Slots slot); - public virtual void AddToSlot(EquipmentSlotDefines.Slots slot, IEntity entity) + public virtual void AddToSlot(EquipmentSlotDefines.Slots slot, EntityUid entity) { } - public virtual void HoverInSlot(EquipmentSlotDefines.Slots slot, IEntity entity, bool fits) + public virtual void HoverInSlot(EquipmentSlotDefines.Slots slot, EntityUid entity, bool fits) { } diff --git a/Content.Client/Items/Managers/IItemSlotManager.cs b/Content.Client/Items/Managers/IItemSlotManager.cs index bbebaf55b4..c5533a841a 100644 --- a/Content.Client/Items/Managers/IItemSlotManager.cs +++ b/Content.Client/Items/Managers/IItemSlotManager.cs @@ -7,10 +7,10 @@ namespace Content.Client.Items.Managers { public interface IItemSlotManager { - bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity? item); - void UpdateCooldown(ItemSlotButton? cooldownTexture, IEntity? entity); - bool SetItemSlot(ItemSlotButton button, IEntity? entity); - void HoverInSlot(ItemSlotButton button, IEntity? entity, bool fits); + bool OnButtonPressed(GUIBoundKeyEventArgs args, EntityUid item); + void UpdateCooldown(ItemSlotButton? cooldownTexture, EntityUid entity); + bool SetItemSlot(ItemSlotButton button, EntityUid entity); + void HoverInSlot(ItemSlotButton button, EntityUid entity, bool fits); event Action? EntityHighlightedUpdated; bool IsHighlighted(EntityUid uid); diff --git a/Content.Client/Items/Managers/ItemSlotManager.cs b/Content.Client/Items/Managers/ItemSlotManager.cs index 012951d56c..e0f708fb68 100644 --- a/Content.Client/Items/Managers/ItemSlotManager.cs +++ b/Content.Client/Items/Managers/ItemSlotManager.cs @@ -9,12 +9,8 @@ using Content.Shared.Hands.Components; using Content.Shared.Input; using Content.Shared.Interaction; using Robust.Client.GameObjects; -using Robust.Client.Graphics; -using Robust.Client.Input; -using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Shared.GameObjects; -using Robust.Shared.Input; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -32,9 +28,9 @@ namespace Content.Client.Items.Managers public event Action? EntityHighlightedUpdated; - public bool SetItemSlot(ItemSlotButton button, IEntity? entity) + public bool SetItemSlot(ItemSlotButton button, EntityUid entity) { - if (entity == null) + if (entity == default) { button.SpriteView.Sprite = null; button.StorageButton.Visible = false; @@ -42,31 +38,31 @@ namespace Content.Client.Items.Managers else { ISpriteComponent? sprite; - if (IoCManager.Resolve().TryGetComponent(entity, out HandVirtualItemComponent? virtPull) + if (_entityManager.TryGetComponent(entity, out HandVirtualItemComponent? virtPull) && _entityManager.TryGetComponent(virtPull.BlockingEntity, out ISpriteComponent pulledSprite)) { sprite = pulledSprite; } - else if (!IoCManager.Resolve().TryGetComponent(entity, out sprite)) + else if (!_entityManager.TryGetComponent(entity, out sprite)) { return false; } button.ClearHover(); button.SpriteView.Sprite = sprite; - button.StorageButton.Visible = IoCManager.Resolve().HasComponent(entity); + button.StorageButton.Visible = _entityManager.HasComponent(entity); } - button.Entity = entity ?? default; + button.Entity = entity; // im lazy button.UpdateSlotHighlighted(); return true; } - public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity? item) + public bool OnButtonPressed(GUIBoundKeyEventArgs args, EntityUid item) { - if (item == null) + if (item == default) return false; if (args.Function == ContentKeyFunctions.ExamineEntity) @@ -94,7 +90,7 @@ namespace Content.Client.Items.Managers return true; } - public void UpdateCooldown(ItemSlotButton? button, IEntity? entity) + public void UpdateCooldown(ItemSlotButton? button, EntityUid entity) { var cooldownDisplay = button?.CooldownDisplay; @@ -103,9 +99,9 @@ namespace Content.Client.Items.Managers return; } - if (entity == null || - (!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || - !IoCManager.Resolve().TryGetComponent(entity, out ItemCooldownComponent? cooldown) || + if (entity == default || + (!_entityManager.EntityExists(entity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || + !_entityManager.TryGetComponent(entity, out ItemCooldownComponent? cooldown) || !cooldown.CooldownStart.HasValue || !cooldown.CooldownEnd.HasValue) { @@ -124,23 +120,23 @@ namespace Content.Client.Items.Managers cooldownDisplay.Visible = ratio > -1f; } - public void HoverInSlot(ItemSlotButton button, IEntity? entity, bool fits) + public void HoverInSlot(ItemSlotButton button, EntityUid entity, bool fits) { - if (entity == null || !button.MouseIsHovering) + if (entity == default || !button.MouseIsHovering) { button.ClearHover(); return; } - if (!IoCManager.Resolve().HasComponent(entity)) + if (!_entityManager.HasComponent(entity)) { return; } // Set green / red overlay at 50% transparency var hoverEntity = _entityManager.SpawnEntity("hoverentity", MapCoordinates.Nullspace); - var hoverSprite = IoCManager.Resolve().GetComponent(hoverEntity); - hoverSprite.CopyFrom(IoCManager.Resolve().GetComponent(entity)); + var hoverSprite = _entityManager.GetComponent(hoverEntity); + hoverSprite.CopyFrom(_entityManager.GetComponent(entity)); hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127); button.HoverSpriteView.Sprite = hoverSprite; diff --git a/Content.Client/Items/UI/ItemSlotButton.cs b/Content.Client/Items/UI/ItemSlotButton.cs index de8fb657a0..499dcc31bf 100644 --- a/Content.Client/Items/UI/ItemSlotButton.cs +++ b/Content.Client/Items/UI/ItemSlotButton.cs @@ -142,7 +142,7 @@ namespace Content.Client.Items.UI ISpriteComponent? tempQualifier = HoverSpriteView.Sprite; if (tempQualifier != null) { - IoCManager.Resolve().DeleteEntity((EntityUid) tempQualifier.Owner); + IoCManager.Resolve().DeleteEntity(tempQualifier.Owner); } HoverSpriteView.Sprite = null; diff --git a/Content.Client/Items/UI/ItemStatusPanel.cs b/Content.Client/Items/UI/ItemStatusPanel.cs index 8d092eb1d3..f0bcb7c8a9 100644 --- a/Content.Client/Items/UI/ItemStatusPanel.cs +++ b/Content.Client/Items/UI/ItemStatusPanel.cs @@ -33,7 +33,7 @@ namespace Content.Client.Items.UI private readonly PanelContainer _panel; [ViewVariables] - private IEntity? _entity; + private EntityUid _entity; public ItemStatusPanel(Texture texture, StyleBox.Margin cutout, StyleBox.Margin flat, Label.AlignMode textAlign) { @@ -130,12 +130,12 @@ namespace Content.Client.Items.UI UpdateItemName(); } - public void Update(IEntity? entity) + public void Update(EntityUid entity) { - if (entity == null) + if (entity == default) { ClearOldStatus(); - _entity = null; + _entity = default; _panel.Visible = false; return; } @@ -153,17 +153,17 @@ namespace Content.Client.Items.UI private void UpdateItemName() { - if (_entity == null) + if (_entity == default) return; - if (IoCManager.Resolve().TryGetComponent(_entity, out HandVirtualItemComponent? virtualItem) - && _entityManager.TryGetEntity(virtualItem.BlockingEntity, out var blockEnt)) + if (_entityManager.TryGetComponent(_entity, out HandVirtualItemComponent? virtualItem) + && _entityManager.EntityExists(virtualItem.BlockingEntity)) { - _itemNameLabel.Text = IoCManager.Resolve().GetComponent(blockEnt).EntityName; + _itemNameLabel.Text = _entityManager.GetComponent(virtualItem.BlockingEntity).EntityName; } else { - _itemNameLabel.Text = IoCManager.Resolve().GetComponent(_entity).EntityName; + _itemNameLabel.Text = _entityManager.GetComponent(_entity).EntityName; } } @@ -185,7 +185,7 @@ namespace Content.Client.Items.UI ClearOldStatus(); - foreach (var statusComponent in IoCManager.Resolve().GetComponents(_entity!)) + foreach (var statusComponent in _entityManager.GetComponents(_entity)) { var control = statusComponent.MakeControl(); _statusContents.AddChild(control); @@ -194,7 +194,7 @@ namespace Content.Client.Items.UI } var collectMsg = new ItemStatusCollectMessage(); - IoCManager.Resolve().EventBus.RaiseLocalEvent(_entity, collectMsg); + _entityManager.EventBus.RaiseLocalEvent(_entity, collectMsg); foreach (var control in collectMsg.Controls) { diff --git a/Content.Client/Kitchen/UI/GrinderMenu.xaml.cs b/Content.Client/Kitchen/UI/GrinderMenu.xaml.cs index 199d82e52c..5f75581ecc 100644 --- a/Content.Client/Kitchen/UI/GrinderMenu.xaml.cs +++ b/Content.Client/Kitchen/UI/GrinderMenu.xaml.cs @@ -76,7 +76,7 @@ namespace Content.Client.Kitchen.UI BeakerContentBox.EjectButton.Disabled = true; ChamberContentBox.EjectButton.Disabled = true; break; - case SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage doneMessage: + case SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage: GrindButton.Disabled = false; JuiceButton.Disabled = false; GrindButton.Modulate = Color.White; @@ -93,9 +93,9 @@ namespace Content.Client.Kitchen.UI _chamberVisualContents.Clear(); ChamberContentBox.BoxContents.Clear(); - foreach (var uid in containedSolids) + foreach (var entity in containedSolids) { - if (!_entityManager.TryGetEntity(uid, out var entity)) + if (!_entityManager.EntityExists(entity)) { return; } @@ -103,7 +103,7 @@ namespace Content.Client.Kitchen.UI var solidItem = ChamberContentBox.BoxContents.AddItem(IoCManager.Resolve().GetComponent(entity).EntityName, texture); var solidIndex = ChamberContentBox.BoxContents.IndexOf(solidItem); - _chamberVisualContents.Add(solidIndex, uid); + _chamberVisualContents.Add(solidIndex, entity); } //Refresh beaker contents diff --git a/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs b/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs index 2a2258f898..85857b6c6f 100644 --- a/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs +++ b/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs @@ -108,24 +108,24 @@ namespace Content.Client.Kitchen.UI _solids.Clear(); _menu.IngredientsList.Clear(); - foreach (var t in containedSolids) + foreach (var entity in containedSolids) { - if (!_entityManager.TryGetEntity(t, out var entity)) + if (!_entityManager.EntityExists(entity)) { return; } - if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) + if ((!_entityManager.EntityExists(entity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted) { continue; } Texture? texture; - if (IoCManager.Resolve().TryGetComponent(entity, out IconComponent? iconComponent)) + if (_entityManager.TryGetComponent(entity, out IconComponent? iconComponent)) { texture = iconComponent.Icon?.Default; } - else if (IoCManager.Resolve().TryGetComponent(entity, out SpriteComponent? spriteComponent)) + else if (_entityManager.TryGetComponent(entity, out SpriteComponent? spriteComponent)) { texture = spriteComponent.Icon?.Default; } @@ -134,9 +134,9 @@ namespace Content.Client.Kitchen.UI continue; } - var solidItem = _menu.IngredientsList.AddItem(IoCManager.Resolve().GetComponent(entity).EntityName, texture); + var solidItem = _menu.IngredientsList.AddItem(_entityManager.GetComponent(entity).EntityName, texture); var solidIndex = _menu.IngredientsList.IndexOf(solidItem); - _solids.Add(solidIndex, t); + _solids.Add(solidIndex, entity); } } } diff --git a/Content.Client/Kudzu/KudzuVisualizer.cs b/Content.Client/Kudzu/KudzuVisualizer.cs index 8c807408b8..297742edc0 100644 --- a/Content.Client/Kudzu/KudzuVisualizer.cs +++ b/Content.Client/Kudzu/KudzuVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.Kudzu; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Kudzu; @@ -14,7 +15,8 @@ public class KudzuVisualizer : AppearanceVisualizer { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite)) { return; } diff --git a/Content.Client/Lathe/Visualizers/AutolatheVisualizer.cs b/Content.Client/Lathe/Visualizers/AutolatheVisualizer.cs index 06bb614fd4..44efd629d6 100644 --- a/Content.Client/Lathe/Visualizers/AutolatheVisualizer.cs +++ b/Content.Client/Lathe/Visualizers/AutolatheVisualizer.cs @@ -48,7 +48,7 @@ namespace Content.Client.Lathe.Visualizers return animation; } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { if (!IoCManager.Resolve().HasComponent(entity)) { diff --git a/Content.Client/Lathe/Visualizers/ProtolatheVisualizer.cs b/Content.Client/Lathe/Visualizers/ProtolatheVisualizer.cs index 5e20139d4b..f886f76f01 100644 --- a/Content.Client/Lathe/Visualizers/ProtolatheVisualizer.cs +++ b/Content.Client/Lathe/Visualizers/ProtolatheVisualizer.cs @@ -48,7 +48,7 @@ namespace Content.Client.Lathe.Visualizers return animation; } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { if (!IoCManager.Resolve().HasComponent(entity)) { diff --git a/Content.Client/Light/Components/LightBehaviourComponent.cs b/Content.Client/Light/Components/LightBehaviourComponent.cs index 1764f9d97f..550698f5ad 100644 --- a/Content.Client/Light/Components/LightBehaviourComponent.cs +++ b/Content.Client/Light/Components/LightBehaviourComponent.cs @@ -51,9 +51,9 @@ namespace Content.Client.Light.Components [ViewVariables] protected float MaxTime { get; set; } private float _maxTime = default; - private IEntity _parent = default!; + private EntityUid _parent = default!; - public void Initialize(IEntity parent, IRobustRandom random) + public void Initialize(EntityUid parent, IRobustRandom random) { _random = random; _parent = parent; @@ -128,7 +128,7 @@ namespace Content.Client.Light.Components if (Property == "Enabled") // special case for boolean { - ApplyProperty(interpolateValue < 0.5f? true : false); + ApplyProperty(interpolateValue < 0.5f); return (-1, playingTime); } @@ -183,7 +183,7 @@ namespace Content.Client.Light.Components if (Property == "Enabled") // special case for boolean { - ApplyProperty(interpolateValue < EndValue? true : false); + ApplyProperty(interpolateValue < EndValue); return (-1, playingTime); } @@ -258,7 +258,7 @@ namespace Content.Client.Light.Components ApplyProperty(InterpolateLinear(_randomValue3, _randomValue4, interpolateValue)); break; case AnimationInterpolationMode.Cubic: - ApplyProperty(InterpolateCubic(_randomValue1!, _randomValue2, _randomValue3, _randomValue4, interpolateValue)); + ApplyProperty(InterpolateCubic(_randomValue1, _randomValue2, _randomValue3, _randomValue4, interpolateValue)); break; default: case AnimationInterpolationMode.Nearest: diff --git a/Content.Client/Light/Visualizers/EmergencyLightVisualizer.cs b/Content.Client/Light/Visualizers/EmergencyLightVisualizer.cs index f02c3ce7d5..097492eb47 100644 --- a/Content.Client/Light/Visualizers/EmergencyLightVisualizer.cs +++ b/Content.Client/Light/Visualizers/EmergencyLightVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.Light.Component; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Light.Visualizers @@ -12,7 +13,8 @@ namespace Content.Client.Light.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite)) return; if (!component.TryGetData(EmergencyLightVisuals.On, out bool on)) diff --git a/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs b/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs index 6c978ae310..7a4fbc58aa 100644 --- a/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs +++ b/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs @@ -1,10 +1,10 @@ -using System; -using Content.Client.Light.Components; +using Content.Client.Light.Components; using Content.Shared.Light.Component; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Player; namespace Content.Client.Light.Visualizers @@ -16,9 +16,10 @@ namespace Content.Client.Light.Visualizers { base.OnChangeData(component); + var entities = IoCManager.Resolve(); if (component.TryGetData(ExpendableLightVisuals.Behavior, out string lightBehaviourID)) { - if (component.Owner.TryGetComponent(out var lightBehaviour)) + if (entities.TryGetComponent(component.Owner, out LightBehaviourComponent lightBehaviour)) { lightBehaviour.StopLightBehaviour(); @@ -26,7 +27,7 @@ namespace Content.Client.Light.Visualizers { lightBehaviour.StartLightBehaviour(lightBehaviourID); } - else if (component.Owner.TryGetComponent(out var light)) + else if (entities.TryGetComponent(component.Owner, out PointLightComponent light)) { light.Enabled = false; } @@ -39,7 +40,7 @@ namespace Content.Client.Light.Visualizers } if (component.TryGetData(ExpendableLightVisuals.State, out ExpendableLightState state) - && component.Owner.TryGetComponent(out var expendableLight)) + && entities.TryGetComponent(component.Owner, out ExpendableLightComponent expendableLight)) { switch (state) { diff --git a/Content.Client/Light/Visualizers/LightBulbVisualizer.cs b/Content.Client/Light/Visualizers/LightBulbVisualizer.cs index bfa594f419..9084beb029 100644 --- a/Content.Client/Light/Visualizers/LightBulbVisualizer.cs +++ b/Content.Client/Light/Visualizers/LightBulbVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Light; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; namespace Content.Client.Light.Visualizers @@ -13,7 +14,8 @@ namespace Content.Client.Light.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent sprite)) return; // update sprite state diff --git a/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs b/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs index 9b61da8e49..1210cff257 100644 --- a/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs +++ b/Content.Client/Light/Visualizers/PoweredLightVisualizer.cs @@ -7,7 +7,6 @@ using Robust.Client.GameObjects; using Robust.Shared.Animations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Maths; using Robust.Shared.Random; using Robust.Shared.Serialization.Manager.Attributes; @@ -28,7 +27,8 @@ namespace Content.Client.Light.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if (!component.TryGetData(PoweredLightVisuals.BulbState, out PoweredLightState state)) return; switch (state) diff --git a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs index 7446162a46..326ccf7f95 100644 --- a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs +++ b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs @@ -23,7 +23,7 @@ namespace Content.Client.Lobby.UI public class LobbyCharacterPreviewPanel : Control { private readonly IClientPreferencesManager _preferencesManager; - private IEntity _previewDummy; + private EntityUid _previewDummy; private readonly Label _summaryLabel; private readonly BoxContainer _loaded; private readonly Label _unloaded; @@ -98,11 +98,11 @@ namespace Content.Client.Lobby.UI _preferencesManager.OnServerDataLoaded -= UpdateUI; if (!disposing) return; - IoCManager.Resolve().DeleteEntity((EntityUid) _previewDummy); - _previewDummy = null!; + IoCManager.Resolve().DeleteEntity(_previewDummy); + _previewDummy = default; } - private static SpriteView MakeSpriteView(IEntity entity, Direction direction) + private static SpriteView MakeSpriteView(EntityUid entity, Direction direction) { return new() { @@ -136,7 +136,7 @@ namespace Content.Client.Lobby.UI } } - public static void GiveDummyJobClothes(IEntity dummy, HumanoidCharacterProfile profile) + public static void GiveDummyJobClothes(EntityUid dummy, HumanoidCharacterProfile profile) { var protoMan = IoCManager.Resolve(); @@ -144,6 +144,7 @@ namespace Content.Client.Lobby.UI var highPriorityJob = profile.JobPriorities.FirstOrDefault(p => p.Value == JobPriority.High).Key; + // ReSharper disable once ConstantNullCoalescingCondition var job = protoMan.Index(highPriorityJob ?? SharedGameTicker.FallbackOverflowJob); inventory.ClearAllSlotVisuals(); @@ -160,7 +161,7 @@ namespace Content.Client.Lobby.UI { var item = entityMan.SpawnEntity(itemType, MapCoordinates.Nullspace); inventory.SetSlotVisuals(slot, item); - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); } } } diff --git a/Content.Client/MachineLinking/SignalSwitchVisualizer.cs b/Content.Client/MachineLinking/SignalSwitchVisualizer.cs index 0fa48f1aa1..616c707371 100644 --- a/Content.Client/MachineLinking/SignalSwitchVisualizer.cs +++ b/Content.Client/MachineLinking/SignalSwitchVisualizer.cs @@ -13,7 +13,7 @@ namespace Content.Client.MachineLinking [DataField("layer")] private int Layer { get; } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -27,7 +27,8 @@ namespace Content.Client.MachineLinking { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite)) { return; } diff --git a/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs b/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs index b3203c034e..485e9b9070 100644 --- a/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs +++ b/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs @@ -1,17 +1,15 @@ -using System.Text; using System.Collections.Generic; -using System.Linq; -using Robust.Client.UserInterface.Controls; +using System.Text; +using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; +using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.CustomControls; +using Robust.Client.UserInterface.XAML; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; using static Content.Shared.MedicalScanner.SharedMedicalScannerComponent; -using Content.Shared.Damage.Prototypes; -using Content.Shared.FixedPoint; -using Robust.Client.AutoGenerated; -using Robust.Client.UserInterface.XAML; namespace Content.Client.MedicalScanner.UI { @@ -27,9 +25,10 @@ namespace Content.Client.MedicalScanner.UI { var text = new StringBuilder(); + var entities = IoCManager.Resolve(); if (!state.Entity.HasValue || !state.HasDamage() || - !IoCManager.Resolve().TryGetEntity(state.Entity.Value, out var entity)) + !entities.EntityExists(state.Entity.Value)) { Diagnostics.Text = Loc.GetString("medical-scanner-window-no-patient-data-text"); ScanButton.Disabled = true; @@ -37,7 +36,7 @@ namespace Content.Client.MedicalScanner.UI } else { - text.Append($"{Loc.GetString("medical-scanner-window-entity-health-text", ("entityName", Name: IoCManager.Resolve().GetComponent(entity).EntityName))}\n"); + text.Append($"{Loc.GetString("medical-scanner-window-entity-health-text", ("entityName", Name: entities.GetComponent(state.Entity.Value).EntityName))}\n"); var totalDamage = state.DamagePerType.Values.Sum(); @@ -46,12 +45,12 @@ namespace Content.Client.MedicalScanner.UI HashSet shownTypes = new(); // Show the total damage and type breakdown for each damage group. - foreach (var (damageGroupID, damageAmount) in state.DamagePerGroup) + foreach (var (damageGroupId, damageAmount) in state.DamagePerGroup) { - text.Append($"\n{Loc.GetString("medical-scanner-window-damage-group-text", ("damageGroup", damageGroupID), ("amount", damageAmount))}"); + text.Append($"\n{Loc.GetString("medical-scanner-window-damage-group-text", ("damageGroup", damageGroupId), ("amount", damageAmount))}"); // Show the damage for each type in that group. - var group = IoCManager.Resolve().Index(damageGroupID); + var group = IoCManager.Resolve().Index(damageGroupId); foreach (var type in group.DamageTypes) { if (state.DamagePerType.TryGetValue(type, out var typeAmount)) diff --git a/Content.Client/Mining/AsteroidRockVisualizer.cs b/Content.Client/Mining/AsteroidRockVisualizer.cs index 9d30ee6b99..1cfda51ba9 100644 --- a/Content.Client/Mining/AsteroidRockVisualizer.cs +++ b/Content.Client/Mining/AsteroidRockVisualizer.cs @@ -13,7 +13,7 @@ namespace Content.Client.Mining [DataField("layer")] private int Layer { get; } = 0; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/MobState/Overlays/CritOverlay.cs b/Content.Client/MobState/Overlays/CritOverlay.cs index 8b113da5bf..51b3b462ed 100644 --- a/Content.Client/MobState/Overlays/CritOverlay.cs +++ b/Content.Client/MobState/Overlays/CritOverlay.cs @@ -14,6 +14,7 @@ namespace Content.Client.MobState.Overlays [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; public override OverlaySpace Space => OverlaySpace.WorldSpace; private readonly ShaderInstance _gradientCircleShader; @@ -24,15 +25,14 @@ namespace Content.Client.MobState.Overlays _gradientCircleShader = _prototypeManager.Index("GradientCircleMask").Instance(); } - public static bool LocalPlayerHasState(IPlayerManager pm, bool critical, bool dead) { - var playerEntity = pm.LocalPlayer?.ControlledEntity; - - if (playerEntity == null) + public static bool LocalPlayerHasState(IPlayerManager pm, bool critical, bool dead, IEntityManager? entities = null) { + if (pm.LocalPlayer?.ControlledEntity is not {Valid: true} player) { return false; } - if (IoCManager.Resolve().TryGetComponent(playerEntity, out var mobState)) + IoCManager.Resolve(ref entities); + if (entities.TryGetComponent(player, out var mobState)) { if (critical) if (mobState.IsCritical()) @@ -47,7 +47,7 @@ namespace Content.Client.MobState.Overlays protected override void Draw(in OverlayDrawArgs args) { - if (!LocalPlayerHasState(_playerManager, true, false)) + if (!LocalPlayerHasState(_playerManager, true, false, _entities)) return; var worldHandle = args.WorldHandle; diff --git a/Content.Client/Morgue/Visualizers/BodyBagVisualizer.cs b/Content.Client/Morgue/Visualizers/BodyBagVisualizer.cs index cefa9bea45..1aeff3e8c8 100644 --- a/Content.Client/Morgue/Visualizers/BodyBagVisualizer.cs +++ b/Content.Client/Morgue/Visualizers/BodyBagVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Labels; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Morgue.Visualizers { @@ -12,7 +13,8 @@ namespace Content.Client.Morgue.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Morgue/Visualizers/CrematoriumVisualizer.cs b/Content.Client/Morgue/Visualizers/CrematoriumVisualizer.cs index a930b71c2e..de39fedbb4 100644 --- a/Content.Client/Morgue/Visualizers/CrematoriumVisualizer.cs +++ b/Content.Client/Morgue/Visualizers/CrematoriumVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Morgue.Visualizers @@ -23,7 +24,11 @@ namespace Content.Client.Morgue.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) + { + return; + } if (component.TryGetData(MorgueVisuals.Open, out bool open)) { diff --git a/Content.Client/Morgue/Visualizers/MorgueVisualizer.cs b/Content.Client/Morgue/Visualizers/MorgueVisualizer.cs index f7df0ce6bb..6f675a1135 100644 --- a/Content.Client/Morgue/Visualizers/MorgueVisualizer.cs +++ b/Content.Client/Morgue/Visualizers/MorgueVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.Morgue; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Morgue.Visualizers @@ -23,7 +24,11 @@ namespace Content.Client.Morgue.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) + { + return; + } if (component.TryGetData(MorgueVisuals.Open, out bool open)) { diff --git a/Content.Client/Movement/Components/ClimbableComponent.cs b/Content.Client/Movement/Components/ClimbableComponent.cs index fb74d4fb9b..6d5b4f5161 100644 --- a/Content.Client/Movement/Components/ClimbableComponent.cs +++ b/Content.Client/Movement/Components/ClimbableComponent.cs @@ -17,7 +17,7 @@ namespace Content.Client.Movement.Components var user = eventArgs.User; var target = eventArgs.Target; var dragged = eventArgs.Dragged; - bool Ignored(IEntity entity) => entity == target || entity == user || entity == dragged; + bool Ignored(EntityUid entity) => entity == target || entity == user || entity == dragged; return user.InRangeUnobstructed(target, Range, predicate: Ignored) && user.InRangeUnobstructed(dragged, Range, predicate: Ignored); } diff --git a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs index e1ee379b47..4d155491c1 100644 --- a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs +++ b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs @@ -5,10 +5,8 @@ using Content.Client.Resources; using Robust.Client.Graphics; using Robust.Client.Input; using Robust.Client.ResourceManagement; -using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Enums; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Timing; @@ -79,14 +77,12 @@ namespace Content.Client.NodeContainer var mousePos = _inputManager.MouseScreenPosition.Position; - var entity = _entityManager.GetEntity(node.Entity); - - var gridId = IoCManager.Resolve().GetComponent(entity).GridID; + var gridId = _entityManager.GetComponent(node.Entity).GridID; var grid = _mapManager.GetGrid(gridId); - var gridTile = grid.TileIndicesFor(IoCManager.Resolve().GetComponent(entity).Coordinates); + var gridTile = grid.TileIndicesFor(_entityManager.GetComponent(node.Entity).Coordinates); var sb = new StringBuilder(); - sb.Append($"entity: {entity}\n"); + sb.Append($"entity: {node.Entity}\n"); sb.Append($"group id: {group.GroupId}\n"); sb.Append($"node: {node.Name}\n"); sb.Append($"type: {node.Type}\n"); @@ -120,10 +116,10 @@ namespace Content.Client.NodeContainer if (!_system.Entities.TryGetValue(entity, out var nodeData)) return; - var gridId = IoCManager.Resolve().GetComponent(entity).GridID; + var gridId = _entityManager.GetComponent(entity).GridID; var grid = _mapManager.GetGrid(gridId); var gridDict = _gridIndex.GetOrNew(gridId); - var coords = IoCManager.Resolve().GetComponent(entity).Coordinates; + var coords = _entityManager.GetComponent(entity).Coordinates; // TODO: This probably shouldn't be capable of returning NaN... if (float.IsNaN(coords.Position.X) || float.IsNaN(coords.Position.Y)) diff --git a/Content.Client/Nutrition/Visualizers/CreamPiedVisualizer.cs b/Content.Client/Nutrition/Visualizers/CreamPiedVisualizer.cs index d31f74595c..94d57e07ba 100644 --- a/Content.Client/Nutrition/Visualizers/CreamPiedVisualizer.cs +++ b/Content.Client/Nutrition/Visualizers/CreamPiedVisualizer.cs @@ -13,7 +13,7 @@ namespace Content.Client.Nutrition.Visualizers [DataField("state")] private string? _state; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Nutrition/Visualizers/DrinkCanVisualizer.cs b/Content.Client/Nutrition/Visualizers/DrinkCanVisualizer.cs index 94df14440d..f004b5efd5 100644 --- a/Content.Client/Nutrition/Visualizers/DrinkCanVisualizer.cs +++ b/Content.Client/Nutrition/Visualizers/DrinkCanVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Nutrition.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Nutrition.Visualizers @@ -19,7 +20,8 @@ namespace Content.Client.Nutrition.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent sprite)) { return; } diff --git a/Content.Client/PDA/PDAVisualizer.cs b/Content.Client/PDA/PDAVisualizer.cs index 9fb063f0ca..003dd4f648 100644 --- a/Content.Client/PDA/PDAVisualizer.cs +++ b/Content.Client/PDA/PDAVisualizer.cs @@ -25,7 +25,7 @@ namespace Content.Client.PDA IDLight } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); var sprite = IoCManager.Resolve().GetComponent(entity); diff --git a/Content.Client/Parallax/ParallaxGenerator.cs b/Content.Client/Parallax/ParallaxGenerator.cs index ec1b9b8b81..7d77fc2047 100644 --- a/Content.Client/Parallax/ParallaxGenerator.cs +++ b/Content.Client/Parallax/ParallaxGenerator.cs @@ -182,7 +182,7 @@ namespace Content.Client.Parallax // Threshold noiseVal = MathF.Max(0, noiseVal - Threshold); noiseVal *= threshVal; - noiseVal = (float) MathF.Pow(noiseVal, powFactor); + noiseVal = MathF.Pow(noiseVal, powFactor); // Get colors based on noise values. var srcColor = Color.InterpolateBetween(OuterColor, InnerColor, noiseVal) @@ -408,7 +408,7 @@ namespace Content.Client.Parallax // Threshold noiseVal = MathF.Max(0, noiseVal - MaskThreshold); noiseVal *= threshVal; - noiseVal = (float) MathF.Pow(noiseVal, powFactor); + noiseVal = MathF.Pow(noiseVal, powFactor); var randomThresh = random.NextFloat(); if (randomThresh > noiseVal) diff --git a/Content.Client/ParticleAccelerator/ParticleAcceleratorPartVisualizer.cs b/Content.Client/ParticleAccelerator/ParticleAcceleratorPartVisualizer.cs index d4ca9a64fb..9b7a39c45d 100644 --- a/Content.Client/ParticleAccelerator/ParticleAcceleratorPartVisualizer.cs +++ b/Content.Client/ParticleAccelerator/ParticleAcceleratorPartVisualizer.cs @@ -33,7 +33,7 @@ namespace Content.Client.ParticleAccelerator _states.Add(ParticleAcceleratorVisualState.Level3, _baseState + "p3"); } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); if (!IoCManager.Resolve().TryGetComponent(entity, out var sprite)) @@ -50,7 +50,9 @@ namespace Content.Client.ParticleAccelerator public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) return; + + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent sprite)) return; if (!component.TryGetData(ParticleAcceleratorVisuals.VisualState, out ParticleAcceleratorVisualState state)) { state = ParticleAcceleratorVisualState.Unpowered; diff --git a/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.cs b/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.cs index d7c41f53ce..7227c7db70 100644 --- a/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.cs +++ b/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.cs @@ -484,7 +484,7 @@ namespace Content.Client.ParticleAccelerator.UI public void SetPowerState(ParticleAcceleratorUIState state, bool exists) { _base.ShaderOverride = exists ? null : _menu._greyScaleShader; - _base.ModulateSelfOverride = exists ? (Color?) null : new Color(127, 127, 127); + _base.ModulateSelfOverride = exists ? null : new Color(127, 127, 127); if (!state.Enabled || !exists) { diff --git a/Content.Client/Physics/Controllers/MoverController.cs b/Content.Client/Physics/Controllers/MoverController.cs index c128f608e4..1b01341cf9 100644 --- a/Content.Client/Physics/Controllers/MoverController.cs +++ b/Content.Client/Physics/Controllers/MoverController.cs @@ -17,10 +17,12 @@ namespace Content.Client.Physics.Controllers { base.UpdateBeforeSolve(prediction, frameTime); - var player = _playerManager.LocalPlayer?.ControlledEntity; - if (player == null || - !IoCManager.Resolve().TryGetComponent(player, out IMoverComponent? mover) || - !IoCManager.Resolve().TryGetComponent(player, out PhysicsComponent? body)) return; + if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player || + !EntityManager.TryGetComponent(player, out IMoverComponent? mover) || + !EntityManager.TryGetComponent(player, out PhysicsComponent? body)) + { + return; + } // Essentially we only want to set our mob to predicted so every other entity we just interpolate // (i.e. only see what the server has sent us). @@ -30,7 +32,7 @@ namespace Content.Client.Physics.Controllers // We set joints to predicted given these can affect how our mob moves. // I would only recommend disabling this if you make pulling not use joints anymore (someday maybe?) - if (IoCManager.Resolve().TryGetComponent(player, out JointComponent? jointComponent)) + if (EntityManager.TryGetComponent(player, out JointComponent? jointComponent)) { foreach (var joint in jointComponent.GetJoints) { @@ -40,10 +42,10 @@ namespace Content.Client.Physics.Controllers } // If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother. - if (IoCManager.Resolve().TryGetComponent(player, out SharedPullableComponent? pullableComp)) + if (EntityManager.TryGetComponent(player, out SharedPullableComponent? pullableComp)) { var puller = pullableComp.Puller; - if (puller != null && IoCManager.Resolve().TryGetComponent(puller, out var pullerBody)) + if (puller != default && EntityManager.TryGetComponent(puller, out var pullerBody)) { pullerBody.Predict = false; body.Predict = false; @@ -51,20 +53,20 @@ namespace Content.Client.Physics.Controllers } // If we're pulling a mob then make sure that isn't predicted so it doesn't fuck our velocity up. - if (IoCManager.Resolve().TryGetComponent(player, out SharedPullerComponent? pullerComp)) + if (EntityManager.TryGetComponent(player, out SharedPullerComponent? pullerComp)) { var pulling = pullerComp.Pulling; - if (pulling != null && - IoCManager.Resolve().HasComponent(pulling) && - IoCManager.Resolve().TryGetComponent(pulling, out PhysicsComponent? pullingBody)) + if (pulling != default && + EntityManager.HasComponent(pulling) && + EntityManager.TryGetComponent(pulling, out PhysicsComponent? pullingBody)) { pullingBody.Predict = false; } } // Server-side should just be handled on its own so we'll just do this shizznit - if (IoCManager.Resolve().TryGetComponent(player, out IMobMoverComponent? mobMover)) + if (EntityManager.TryGetComponent(player, out IMobMoverComponent? mobMover)) { HandleMobMovement(mover, body, mobMover); return; diff --git a/Content.Client/Pinpointer/PinpointerVisualizer.cs b/Content.Client/Pinpointer/PinpointerVisualizer.cs index 6cf214f5e1..6975c414e4 100644 --- a/Content.Client/Pinpointer/PinpointerVisualizer.cs +++ b/Content.Client/Pinpointer/PinpointerVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Pinpointer; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; namespace Content.Client.Pinpointer @@ -13,7 +14,8 @@ namespace Content.Client.Pinpointer { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent sprite)) return; // check if pinpointer screen is active diff --git a/Content.Client/PneumaticCannon/PneumaticCannonVisualizer.cs b/Content.Client/PneumaticCannon/PneumaticCannonVisualizer.cs index b88d04f227..04ecd55dbe 100644 --- a/Content.Client/PneumaticCannon/PneumaticCannonVisualizer.cs +++ b/Content.Client/PneumaticCannon/PneumaticCannonVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.PneumaticCannon; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.PneumaticCannon { @@ -10,7 +11,8 @@ namespace Content.Client.PneumaticCannon { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent sprite)) return; if (component.TryGetData(PneumaticCannonVisuals.Tank, out bool tank)) diff --git a/Content.Client/Popups/PopupSystem.cs b/Content.Client/Popups/PopupSystem.cs index 622013f2d6..8562eac402 100644 --- a/Content.Client/Popups/PopupSystem.cs +++ b/Content.Client/Popups/PopupSystem.cs @@ -4,7 +4,6 @@ using Content.Client.Stylesheets; using Content.Shared.GameTicking; using Content.Shared.Popups; using Robust.Client.Graphics; -using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; @@ -52,7 +51,7 @@ namespace Content.Client.Popups PopupMessage(message, _eyeManager.CoordinatesToScreen(transform.Coordinates)); } - public void PopupMessage(string message, ScreenCoordinates coordinates, IEntity? entity = null) + public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid entity = default) { var label = new PopupLabel(_eyeManager) { @@ -146,7 +145,7 @@ namespace Content.Client.Popups public float TimeLeft { get; private set; } public Vector2 InitialPos { get; set; } - public IEntity? Entity { get; set; } + public EntityUid Entity { get; set; } public PopupLabel(IEyeManager eyeManager) { @@ -160,7 +159,7 @@ namespace Content.Client.Popups { TimeLeft += eventArgs.DeltaSeconds; - var position = Entity == null + var position = Entity == default ? InitialPos : (_eyeManager.CoordinatesToScreen(IoCManager.Resolve().GetComponent(Entity).Coordinates).Position / UIScale) - DesiredSize / 2; diff --git a/Content.Client/Power/APC/ApcVisualizer.cs b/Content.Client/Power/APC/ApcVisualizer.cs index 3107cdbebb..b2f57624ff 100644 --- a/Content.Client/Power/APC/ApcVisualizer.cs +++ b/Content.Client/Power/APC/ApcVisualizer.cs @@ -9,7 +9,7 @@ namespace Content.Client.Power.APC public class ApcVisualizer : AppearanceVisualizer { [UsedImplicitly] - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Power/SMES/SmesVisualizer.cs b/Content.Client/Power/SMES/SmesVisualizer.cs index 13f6a0068a..09b8df501e 100644 --- a/Content.Client/Power/SMES/SmesVisualizer.cs +++ b/Content.Client/Power/SMES/SmesVisualizer.cs @@ -10,7 +10,7 @@ namespace Content.Client.Power.SMES [UsedImplicitly] public class SmesVisualizer : AppearanceVisualizer { - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Power/Visualizers/CableVisualizer.cs b/Content.Client/Power/Visualizers/CableVisualizer.cs index 7d151d1c6d..ad614428fc 100644 --- a/Content.Client/Power/Visualizers/CableVisualizer.cs +++ b/Content.Client/Power/Visualizers/CableVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.Wires; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.Power @@ -15,7 +16,8 @@ namespace Content.Client.Power { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite)) return; if (!component.TryGetData(WireVisVisuals.ConnectedMask, out WireVisDirFlags mask)) diff --git a/Content.Client/PowerCell/PowerCellVisualizer.cs b/Content.Client/PowerCell/PowerCellVisualizer.cs index 7b6aebbee6..4d58a23ca1 100644 --- a/Content.Client/PowerCell/PowerCellVisualizer.cs +++ b/Content.Client/PowerCell/PowerCellVisualizer.cs @@ -13,7 +13,7 @@ namespace Content.Client.PowerCell [DataField("prefix")] private string? _prefix; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/PowerCell/PowerChargerVisualizer.cs b/Content.Client/PowerCell/PowerChargerVisualizer.cs index c5af6aa785..f86e4b8c9d 100644 --- a/Content.Client/PowerCell/PowerChargerVisualizer.cs +++ b/Content.Client/PowerCell/PowerChargerVisualizer.cs @@ -9,7 +9,7 @@ namespace Content.Client.PowerCell [UsedImplicitly] public class PowerChargerVisualizer : AppearanceVisualizer { - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs b/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs index e709966659..f08a74d1e5 100644 --- a/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs +++ b/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs @@ -1,9 +1,7 @@ using System.Linq; using Content.Client.Info; using Content.Client.Lobby.UI; -using Content.Client.Parallax; using Content.Client.Resources; -using Content.Client.Stylesheets; using Content.Shared.CharacterAppearance.Systems; using Content.Shared.Preferences; using Content.Shared.Roles; @@ -138,7 +136,7 @@ namespace Content.Client.Preferences.UI private class CharacterPickerButton : ContainerButton { - private IEntity _previewDummy; + private EntityUid _previewDummy; public CharacterPickerButton( IEntityManager entityManager, @@ -219,7 +217,7 @@ namespace Content.Client.Preferences.UI return; IoCManager.Resolve().DeleteEntity((EntityUid) _previewDummy); - _previewDummy = null!; + _previewDummy = default; } } } diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index c2a3377ec0..6e3f38cecb 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -21,7 +21,6 @@ using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; @@ -76,7 +75,7 @@ namespace Content.Client.Preferences.UI private readonly List _antagPreferences; - private readonly IEntity _previewDummy; + private readonly EntityUid _previewDummy; private Control _previewSpriteControl => CSpriteViewFront; private Control _previewSpriteSideControl => CSpriteViewSide; private readonly SpriteView _previewSprite; diff --git a/Content.Client/Recycling/RecyclerVisualizer.cs b/Content.Client/Recycling/RecyclerVisualizer.cs index 5b7fbe889f..a1580ee17b 100644 --- a/Content.Client/Recycling/RecyclerVisualizer.cs +++ b/Content.Client/Recycling/RecyclerVisualizer.cs @@ -17,7 +17,7 @@ namespace Content.Client.Recycling [DataField("state_off")] private string _stateOff = "grinder-o0"; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -34,7 +34,8 @@ namespace Content.Client.Recycling { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Security/DeployableBarrierVisualizer.cs b/Content.Client/Security/DeployableBarrierVisualizer.cs index 9b0799f0d7..4b88189a50 100644 --- a/Content.Client/Security/DeployableBarrierVisualizer.cs +++ b/Content.Client/Security/DeployableBarrierVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Security; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Security { @@ -12,7 +13,8 @@ namespace Content.Client.Security { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite)) return; if (!component.TryGetData(DeployableBarrierVisuals.State, out DeployableBarrierState state)) diff --git a/Content.Client/Shuttles/ThrusterVisualizer.cs b/Content.Client/Shuttles/ThrusterVisualizer.cs index 904035539b..5f7712450a 100644 --- a/Content.Client/Shuttles/ThrusterVisualizer.cs +++ b/Content.Client/Shuttles/ThrusterVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.Shuttles.Components; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Shuttles { @@ -10,7 +11,8 @@ namespace Content.Client.Shuttles { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? spriteComponent)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? spriteComponent)) return; component.TryGetData(ThrusterVisualState.State, out bool state); diff --git a/Content.Client/Singularity/SingularityOverlay.cs b/Content.Client/Singularity/SingularityOverlay.cs index bf10dfb1cb..9157e859a1 100644 --- a/Content.Client/Singularity/SingularityOverlay.cs +++ b/Content.Client/Singularity/SingularityOverlay.cs @@ -43,7 +43,7 @@ namespace Content.Client.Singularity var viewportWB = _eyeManager.GetWorldViewport(); // Has to be correctly handled because of the way intensity/falloff transform works so just do it. _shader?.SetParameter("renderScale", args.Viewport.RenderScale); - foreach (SingularityShaderInstance instance in _singularities.Values) + foreach (var instance in _singularities.Values) { // To be clear, this needs to use "inside-viewport" pixels. // In other words, specifically NOT IViewportControl.WorldToScreen (which uses outer coordinates). @@ -80,29 +80,29 @@ namespace Content.Client.Singularity if (!_singularities.Keys.Contains(singuloEntity) && SinguloQualifies(singuloEntity, currentEyeLoc)) { - _singularities.Add(singuloEntity, new SingularityShaderInstance(IoCManager.Resolve().GetComponent(singuloEntity).MapPosition.Position, distortion.Intensity, distortion.Falloff)); + _singularities.Add(singuloEntity, new SingularityShaderInstance(_entityManager.GetComponent(singuloEntity).MapPosition.Position, distortion.Intensity, distortion.Falloff)); } } var activeShaderIds = _singularities.Keys; - foreach (var activeSinguloUid in activeShaderIds) //Remove all singulos that are added and no longer qualify + foreach (var activeSingulo in activeShaderIds) //Remove all singulos that are added and no longer qualify { - if (_entityManager.TryGetEntity(activeSinguloUid, out var singuloEntity)) + if (_entityManager.EntityExists(activeSingulo)) { - if (!SinguloQualifies(singuloEntity, currentEyeLoc)) + if (!SinguloQualifies(activeSingulo, currentEyeLoc)) { - _singularities.Remove(activeSinguloUid); + _singularities.Remove(activeSingulo); } else { - if (!IoCManager.Resolve().TryGetComponent(singuloEntity, out var distortion)) + if (!_entityManager.TryGetComponent(activeSingulo, out var distortion)) { - _singularities.Remove(activeSinguloUid); + _singularities.Remove(activeSingulo); } else { - var shaderInstance = _singularities[activeSinguloUid]; - shaderInstance.CurrentMapCoords = IoCManager.Resolve().GetComponent(singuloEntity).MapPosition.Position; + var shaderInstance = _singularities[activeSingulo]; + shaderInstance.CurrentMapCoords = _entityManager.GetComponent(activeSingulo).MapPosition.Position; shaderInstance.Intensity = distortion.Intensity; shaderInstance.Falloff = distortion.Falloff; } @@ -111,15 +111,15 @@ namespace Content.Client.Singularity } else { - _singularities.Remove(activeSinguloUid); + _singularities.Remove(activeSingulo); } } } - private bool SinguloQualifies(IEntity singuloEntity, MapCoordinates currentEyeLoc) + private bool SinguloQualifies(EntityUid singuloEntity, MapCoordinates currentEyeLoc) { - return IoCManager.Resolve().GetComponent(singuloEntity).MapID == currentEyeLoc.MapId && IoCManager.Resolve().GetComponent(singuloEntity).Coordinates.InRange(_entityManager, EntityCoordinates.FromMap(_entityManager, IoCManager.Resolve().GetComponent(singuloEntity).ParentUid, currentEyeLoc), MaxDist); + return _entityManager.GetComponent(singuloEntity).MapID == currentEyeLoc.MapId && _entityManager.GetComponent(singuloEntity).Coordinates.InRange(_entityManager, EntityCoordinates.FromMap(_entityManager, _entityManager.GetComponent(singuloEntity).ParentUid, currentEyeLoc), MaxDist); } private sealed class SingularityShaderInstance diff --git a/Content.Client/Singularity/Visualizers/EmitterVisualizer.cs b/Content.Client/Singularity/Visualizers/EmitterVisualizer.cs index 5bc71fee3f..58c877bcfb 100644 --- a/Content.Client/Singularity/Visualizers/EmitterVisualizer.cs +++ b/Content.Client/Singularity/Visualizers/EmitterVisualizer.cs @@ -4,6 +4,7 @@ using Content.Shared.Storage; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Singularity.Visualizers { @@ -17,7 +18,8 @@ namespace Content.Client.Singularity.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/Singularity/Visualizers/RadiationCollectorVisualizer.cs b/Content.Client/Singularity/Visualizers/RadiationCollectorVisualizer.cs index e943f027ae..02c527f1f6 100644 --- a/Content.Client/Singularity/Visualizers/RadiationCollectorVisualizer.cs +++ b/Content.Client/Singularity/Visualizers/RadiationCollectorVisualizer.cs @@ -44,7 +44,7 @@ namespace Content.Client.Singularity.Visualizers } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { if (!IoCManager.Resolve().HasComponent(entity)) { @@ -56,8 +56,9 @@ namespace Content.Client.Singularity.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out var sprite)) return; - if (!component.Owner.TryGetComponent(out var animPlayer)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent sprite)) return; + if (!entities.TryGetComponent(component.Owner, out AnimationPlayerComponent animPlayer)) return; if (!component.TryGetData(RadiationCollectorVisuals.VisualState, out RadiationCollectorVisualState state)) { state = RadiationCollectorVisualState.Deactive; diff --git a/Content.Client/Singularity/Visualizers/SingularityVisualizer.cs b/Content.Client/Singularity/Visualizers/SingularityVisualizer.cs index 3af27ff263..8f93407df3 100644 --- a/Content.Client/Singularity/Visualizers/SingularityVisualizer.cs +++ b/Content.Client/Singularity/Visualizers/SingularityVisualizer.cs @@ -14,7 +14,7 @@ namespace Content.Client.Singularity.Visualizers [DataField("layer")] private int Layer { get; } = 0; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Smoking/BurnStateVisualizer.cs b/Content.Client/Smoking/BurnStateVisualizer.cs index ab0ded6d48..71469bab90 100644 --- a/Content.Client/Smoking/BurnStateVisualizer.cs +++ b/Content.Client/Smoking/BurnStateVisualizer.cs @@ -25,8 +25,6 @@ namespace Content.Client.Smoking [DataField("unlitPrefix")] private string _unlitPrefix = "unlit"; - - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); @@ -39,9 +37,10 @@ namespace Content.Client.Smoking private void SetState(AppearanceComponent component, SmokableState burnState) { - var clothing = IoCManager.Resolve().GetComponentOrNull(component.Owner); + var entities = IoCManager.Resolve(); + var clothing = entities.GetComponentOrNull(component.Owner); - if (component.Owner.TryGetComponent(out var sprite)) + if (entities.TryGetComponent(component.Owner, out ISpriteComponent sprite)) { switch (burnState) { diff --git a/Content.Client/Spawners/ClientEntitySpawnerComponent.cs b/Content.Client/Spawners/ClientEntitySpawnerComponent.cs index 88f6ea7f10..0b8a698045 100644 --- a/Content.Client/Spawners/ClientEntitySpawnerComponent.cs +++ b/Content.Client/Spawners/ClientEntitySpawnerComponent.cs @@ -15,7 +15,7 @@ namespace Content.Client.Spawners [DataField("prototypes")] private List _prototypes = new() { "HVDummyWire" }; - private readonly List _entity = new(); + private readonly List _entity = new(); protected override void Initialize() { diff --git a/Content.Client/Stack/StackVisualizer.cs b/Content.Client/Stack/StackVisualizer.cs index bf9d5d23a2..5980d5d52a 100644 --- a/Content.Client/Stack/StackVisualizer.cs +++ b/Content.Client/Stack/StackVisualizer.cs @@ -78,7 +78,7 @@ namespace Content.Client.Stack [DataField("sprite")] private ResourcePath? _spritePath; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -101,7 +101,8 @@ namespace Content.Client.Stack { base.OnChangeData(component); - if (component.Owner.TryGetComponent(out var spriteComponent)) + var entities = IoCManager.Resolve(); + if (entities.TryGetComponent(component.Owner, out ISpriteComponent spriteComponent)) { if (_isComposite) { diff --git a/Content.Client/StationEvents/RadiationPulseOverlay.cs b/Content.Client/StationEvents/RadiationPulseOverlay.cs index 8cdfbc5a7b..a4f8f0ad15 100644 --- a/Content.Client/StationEvents/RadiationPulseOverlay.cs +++ b/Content.Client/StationEvents/RadiationPulseOverlay.cs @@ -4,11 +4,11 @@ using System.Linq; using Robust.Client.Graphics; using Robust.Shared.Enums; using Robust.Shared.GameObjects; -using Robust.Shared.Timing; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; +using Robust.Shared.Timing; namespace Content.Client.StationEvents { @@ -93,7 +93,7 @@ namespace Content.Client.StationEvents ( _baseShader.Duplicate(), new RadiationShaderInstance( - IoCManager.Resolve().GetComponent(pulseEntity).MapPosition.Position, + _entityManager.GetComponent(pulseEntity).MapPosition.Position, pulse.Range, pulse.StartTime, pulse.EndTime @@ -104,26 +104,26 @@ namespace Content.Client.StationEvents } var activeShaderIds = _pulses.Keys; - foreach (var activePulseUid in activeShaderIds) //Remove all pulses that are added and no longer qualify + foreach (var pulseEntity in activeShaderIds) //Remove all pulses that are added and no longer qualify { - if (_entityManager.TryGetEntity(activePulseUid, out var pulseEntity) && + if (_entityManager.EntityExists(pulseEntity) && PulseQualifies(pulseEntity, currentEyeLoc) && - IoCManager.Resolve().TryGetComponent(pulseEntity, out var pulse)) + _entityManager.TryGetComponent(pulseEntity, out var pulse)) { - var shaderInstance = _pulses[activePulseUid]; - shaderInstance.instance.CurrentMapCoords = IoCManager.Resolve().GetComponent(pulseEntity).MapPosition.Position; + var shaderInstance = _pulses[pulseEntity]; + shaderInstance.instance.CurrentMapCoords = _entityManager.GetComponent(pulseEntity).MapPosition.Position; shaderInstance.instance.Range = pulse.Range; } else { - _pulses[activePulseUid].shd.Dispose(); - _pulses.Remove(activePulseUid); + _pulses[pulseEntity].shd.Dispose(); + _pulses.Remove(pulseEntity); } } } - private bool PulseQualifies(IEntity pulseEntity, MapCoordinates currentEyeLoc) + private bool PulseQualifies(EntityUid pulseEntity, MapCoordinates currentEyeLoc) { - return IoCManager.Resolve().GetComponent(pulseEntity).MapID == currentEyeLoc.MapId && IoCManager.Resolve().GetComponent(pulseEntity).Coordinates.InRange(_entityManager, EntityCoordinates.FromMap(_entityManager, IoCManager.Resolve().GetComponent(pulseEntity).ParentUid, currentEyeLoc), MaxDist); + return _entityManager.GetComponent(pulseEntity).MapID == currentEyeLoc.MapId && _entityManager.GetComponent(pulseEntity).Coordinates.InRange(_entityManager, EntityCoordinates.FromMap(_entityManager, _entityManager.GetComponent(pulseEntity).ParentUid, currentEyeLoc), MaxDist); } private sealed record RadiationShaderInstance(Vector2 CurrentMapCoords, float Range, TimeSpan Start, TimeSpan End) diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs index 178c046645..d5ed253eba 100644 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ b/Content.Client/Storage/ClientStorageComponent.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using Content.Client.Animations; using Content.Client.Hands; -using Content.Client.Items.Managers; using Content.Client.Items.Components; +using Content.Client.Items.Managers; using Content.Client.UserInterface.Controls; using Content.Shared.DragDrop; using Content.Shared.Storage; @@ -22,6 +22,7 @@ using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.Players; using static Robust.Client.UserInterface.Control; +using static Robust.Client.UserInterface.Controls.BaseButton; using static Robust.Client.UserInterface.Controls.BoxContainer; namespace Content.Client.Storage @@ -33,20 +34,25 @@ namespace Content.Client.Storage public class ClientStorageComponent : SharedStorageComponent, IDraggable { [Dependency] private readonly IItemSlotManager _itemSlotManager = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; - private List _storedEntities = new(); + private List _storedEntities = new(); private int StorageSizeUsed; private int StorageCapacityMax; private StorageWindow? _window; public bool UIOpen => _window?.IsOpen ?? false; - public override IReadOnlyList StoredEntities => _storedEntities; + public override IReadOnlyList StoredEntities => _storedEntities; protected override void OnAdd() { base.OnAdd(); - _window = new StorageWindow(this) {Title = IoCManager.Resolve().GetComponent(Owner).EntityName}; + _window = new StorageWindow(this, _playerManager, _entityManager) + { + Title = _entityManager.GetComponent(Owner).EntityName + }; _window.EntityList.GenerateItem += GenerateButton; _window.EntityList.ItemPressed += Interact; } @@ -66,9 +72,7 @@ namespace Content.Client.Storage return; } - _storedEntities = state.StoredEntities - .Select(id => IoCManager.Resolve().GetEntity(id)) - .ToList(); + _storedEntities = state.StoredEntities.ToList(); } [Obsolete("Component Messages are deprecated, use Entity Events instead.")] @@ -101,7 +105,7 @@ namespace Content.Client.Storage /// private void HandleStorageMessage(StorageHeldItemsMessage storageState) { - _storedEntities = storageState.StoredEntities.Select(id => IoCManager.Resolve().GetEntity(id)).ToList(); + _storedEntities = storageState.StoredEntities.ToList(); StorageSizeUsed = storageState.StorageSizeUsed; StorageCapacityMax = storageState.StorageSizeMax; _window?.BuildEntityList(storageState.StoredEntities.ToList()); @@ -115,12 +119,12 @@ namespace Content.Client.Storage { for (var i = 0; msg.StoredEntities.Count > i; i++) { - var entityId = msg.StoredEntities[i]; + var entity = msg.StoredEntities[i]; var initialPosition = msg.EntityPositions[i]; - if (IoCManager.Resolve().TryGetEntity(entityId, out var entity)) + if (_entityManager.EntityExists(entity)) { - ReusableAnimations.AnimateEntityPickup(entity, initialPosition, IoCManager.Resolve().GetComponent(Owner).LocalPosition); + ReusableAnimations.AnimateEntityPickup(entity, initialPosition, _entityManager.GetComponent(Owner).LocalPosition); } } } @@ -146,23 +150,23 @@ namespace Content.Client.Storage /// /// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity /// - /// - private void Interact(BaseButton.ButtonEventArgs buttonEventArgs, EntityUid entityUid) + /// + private void Interact(ButtonEventArgs args, EntityUid entity) { - if (buttonEventArgs.Event.Function == EngineKeyFunctions.UIClick) + if (args.Event.Function == EngineKeyFunctions.UIClick) { #pragma warning disable 618 - SendNetworkMessage(new RemoveEntityMessage(entityUid)); + SendNetworkMessage(new RemoveEntityMessage(entity)); #pragma warning restore 618 - buttonEventArgs.Event.Handle(); + args.Event.Handle(); } - else if (IoCManager.Resolve().TryGetEntity(entityUid, out var entity)) + else if (_entityManager.EntityExists(entity)) { - _itemSlotManager.OnButtonPressed(buttonEventArgs.Event, entity); + _itemSlotManager.OnButtonPressed(args.Event, entity); } } - public override bool Remove(IEntity entity) + public override bool Remove(EntityUid entity) { if (_storedEntities.Remove(entity)) { @@ -176,13 +180,13 @@ namespace Content.Client.Storage /// /// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label /// - private void GenerateButton(EntityUid entityUid, EntityContainerButton button) + private void GenerateButton(EntityUid entity, EntityContainerButton button) { - if (!IoCManager.Resolve().TryGetEntity(entityUid, out var entity)) + if (!_entityManager.EntityExists(entity)) return; - IoCManager.Resolve().TryGetComponent(entity, out ISpriteComponent? sprite); - IoCManager.Resolve().TryGetComponent(entity, out ItemComponent? item); + _entityManager.TryGetComponent(entity, out ISpriteComponent? sprite); + _entityManager.TryGetComponent(entity, out ItemComponent? item); button.AddChild(new BoxContainer { @@ -202,7 +206,7 @@ namespace Content.Client.Storage { HorizontalExpand = true, ClipText = true, - Text = IoCManager.Resolve().GetComponent(entity).EntityName + Text = _entityManager.GetComponent(entity).EntityName }, new Label { @@ -223,12 +227,12 @@ namespace Content.Client.Storage private Control _vBox; private readonly Label _information; public readonly EntityListDisplay EntityList; - public ClientStorageComponent StorageEntity; + public readonly ClientStorageComponent StorageEntity; private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) }; private readonly StyleBoxFlat _unHoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.0f) }; - public StorageWindow(ClientStorageComponent storageEntity) + public StorageWindow(ClientStorageComponent storageEntity, IPlayerManager players, IEntityManager entities) { StorageEntity = storageEntity; SetSize = (200, 320); @@ -250,9 +254,9 @@ namespace Content.Client.Storage containerButton.AddChild(innerContainerButton); containerButton.OnPressed += args => { - var controlledEntity = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + var controlledEntity = players.LocalPlayer?.ControlledEntity; - if (controlledEntity != null && IoCManager.Resolve().TryGetComponent(controlledEntity, out HandsComponent? hands)) + if (controlledEntity != default && entities.HasComponent(controlledEntity.Value)) { #pragma warning disable 618 StorageEntity.SendNetworkMessage(new InsertEntityMessage()); @@ -278,12 +282,12 @@ namespace Content.Client.Storage Name = "EntityListContainer", }; _vBox.AddChild(EntityList); - EntityList.OnMouseEntered += args => + EntityList.OnMouseEntered += _ => { innerContainerButton.PanelOverride = _hoveredBox; }; - EntityList.OnMouseExited += args => + EntityList.OnMouseExited += _ => { innerContainerButton.PanelOverride = _unHoveredBox; }; diff --git a/Content.Client/Storage/Visualizers/BagOpenCloseVisualizer.cs b/Content.Client/Storage/Visualizers/BagOpenCloseVisualizer.cs index 5a4037e3d4..ec0cff6002 100644 --- a/Content.Client/Storage/Visualizers/BagOpenCloseVisualizer.cs +++ b/Content.Client/Storage/Visualizers/BagOpenCloseVisualizer.cs @@ -1,7 +1,4 @@ - -using Content.Shared.Stacks; -using Content.Shared.Storage; -using Content.Shared.Storage.Components; +using Content.Shared.Storage.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -27,12 +24,14 @@ namespace Content.Client.Storage.Visualizers } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); + var entities = IoCManager.Resolve(); + if (_openIcon != null && - IoCManager.Resolve().TryGetComponent(entity, out var spriteComponent) && + entities.TryGetComponent(entity, out var spriteComponent) && spriteComponent.BaseRSI?.Path != null) { spriteComponent.LayerMapReserveBlank(OpenIcon); @@ -45,22 +44,23 @@ namespace Content.Client.Storage.Visualizers { base.OnChangeData(component); - if (_openIcon != null - && component.Owner.TryGetComponent(out var spriteComponent)) - { - if (component.TryGetData(SharedBagOpenVisuals.BagState, out var bagState)) - { - switch (bagState) - { - case SharedBagState.Open: - spriteComponent.LayerSetVisible(OpenIcon, true); - break; - default: - spriteComponent.LayerSetVisible(OpenIcon, false); - break; - } + var entities = IoCManager.Resolve(); - } + if (_openIcon == null || + !entities.TryGetComponent(component.Owner, out SpriteComponent spriteComponent)) + return; + + if (!component.TryGetData(SharedBagOpenVisuals.BagState, out var bagState)) + return; + + switch (bagState) + { + case SharedBagState.Open: + spriteComponent.LayerSetVisible(OpenIcon, true); + break; + default: + spriteComponent.LayerSetVisible(OpenIcon, false); + break; } } } diff --git a/Content.Client/Storage/Visualizers/MappedItemVisualizer.cs b/Content.Client/Storage/Visualizers/MappedItemVisualizer.cs index 6b0f77f850..29eccbec52 100644 --- a/Content.Client/Storage/Visualizers/MappedItemVisualizer.cs +++ b/Content.Client/Storage/Visualizers/MappedItemVisualizer.cs @@ -16,7 +16,7 @@ namespace Content.Client.Storage.Visualizers [DataField("sprite")] private ResourcePath? _rsiPath; private List _spriteLayers = new(); - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); @@ -30,14 +30,16 @@ namespace Content.Client.Storage.Visualizers public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); - if (component.Owner.TryGetComponent(out var spriteComponent)) + + var entities = IoCManager.Resolve(); + if (entities.TryGetComponent(component.Owner, out ISpriteComponent spriteComponent)) { if (_spriteLayers.Count == 0) { InitLayers(spriteComponent, component); } - EnableLayers(spriteComponent, component); + EnableLayers(spriteComponent, component); } } diff --git a/Content.Client/Storage/Visualizers/StorageVisualizer.cs b/Content.Client/Storage/Visualizers/StorageVisualizer.cs index 52768036cc..cd1a73927e 100644 --- a/Content.Client/Storage/Visualizers/StorageVisualizer.cs +++ b/Content.Client/Storage/Visualizers/StorageVisualizer.cs @@ -17,7 +17,7 @@ namespace Content.Client.Storage.Visualizers [DataField("state_closed")] private string? _stateClosed; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { if (!IoCManager.Resolve().TryGetComponent(entity, out ISpriteComponent? sprite)) { @@ -34,7 +34,8 @@ namespace Content.Client.Storage.Visualizers { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/SubFloor/SubFloorShowLayerVisualizer.cs b/Content.Client/SubFloor/SubFloorShowLayerVisualizer.cs index e3958a59c8..7052d30ecb 100644 --- a/Content.Client/SubFloor/SubFloorShowLayerVisualizer.cs +++ b/Content.Client/SubFloor/SubFloorShowLayerVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.SubFloor; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.SubFloor { @@ -12,7 +13,8 @@ namespace Content.Client.SubFloor { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out SpriteComponent? sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite)) return; if (component.TryGetData(SubFloorVisuals.SubFloor, out bool subfloor)) diff --git a/Content.Client/Suspicion/TraitorOverlay.cs b/Content.Client/Suspicion/TraitorOverlay.cs index 6e1212d66d..a816da46e4 100644 --- a/Content.Client/Suspicion/TraitorOverlay.cs +++ b/Content.Client/Suspicion/TraitorOverlay.cs @@ -41,32 +41,34 @@ namespace Content.Client.Suspicion var viewport = _eyeManager.GetWorldViewport(); var ent = _playerManager.LocalPlayer?.ControlledEntity; - if (ent == null || IoCManager.Resolve().TryGetComponent(ent, out SuspicionRoleComponent? sus) != true) + if (ent == default || _entityManager.TryGetComponent(ent.Value, out SuspicionRoleComponent? sus) != true) { return; } - foreach (var (_, uid) in sus.Allies) + foreach (var (_, ally) in sus.Allies) { // Otherwise the entity can not exist yet - if (!_entityManager.TryGetEntity(uid, out var ally)) + if (!_entityManager.EntityExists(ally)) { continue; } - if (!IoCManager.Resolve().TryGetComponent(ally, out IPhysBody? physics)) + if (!_entityManager.TryGetComponent(ally, out IPhysBody? physics)) { continue; } - if (!ExamineSystemShared.InRangeUnOccluded(IoCManager.Resolve().GetComponent(ent).MapPosition, IoCManager.Resolve().GetComponent(ally).MapPosition, 15, + var entPosition = _entityManager.GetComponent(ent.Value).MapPosition; + var allyPosition = _entityManager.GetComponent(ally).MapPosition; + if (!ExamineSystemShared.InRangeUnOccluded(entPosition, allyPosition, 15, entity => entity == ent || entity == ally)) { continue; } // if not on the same map, continue - if (IoCManager.Resolve().GetComponent(physics.Owner).MapID != _eyeManager.CurrentMap || physics.Owner.IsInContainer()) + if (_entityManager.GetComponent(physics.Owner).MapID != _eyeManager.CurrentMap || physics.Owner.IsInContainer()) { continue; } diff --git a/Content.Client/Tabletop/TabletopSystem.cs b/Content.Client/Tabletop/TabletopSystem.cs index be986d8422..2c10d80a93 100644 --- a/Content.Client/Tabletop/TabletopSystem.cs +++ b/Content.Client/Tabletop/TabletopSystem.cs @@ -18,6 +18,7 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; +using static Robust.Shared.Input.Binding.PointerInputCmdHandler; using DrawDepth = Content.Shared.DrawDepth.DrawDepth; namespace Content.Client.Tabletop @@ -51,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: { (EntityUid) this: var playerEntity } }) return; + if (_playerManager.LocalPlayer is not {ControlledEntity: var playerEntity}) return; if (StunnedOrNoHands(playerEntity)) { @@ -153,7 +154,7 @@ namespace Content.Client.Tabletop _window = null; } - private bool OnUse(in PointerInputCmdHandler.PointerInputCmdArgs args) + private bool OnUse(in PointerInputCmdArgs args) { return args.State switch { @@ -163,13 +164,13 @@ namespace Content.Client.Tabletop }; } - private bool OnMouseDown(in PointerInputCmdHandler.PointerInputCmdArgs args) + private bool OnMouseDown(in PointerInputCmdArgs args) { // Return if no player entity - if (_playerManager.LocalPlayer is not { ControlledEntity: { (EntityUid) this : var playerEntityUid } }) return false; + if (_playerManager.LocalPlayer is not { ControlledEntity: var playerEntity}) return false; // Return if can not see table or stunned/no hands - if (!CanSeeTable(playerEntityUid, _table) || StunnedOrNoHands(playerEntityUid)) + if (!CanSeeTable(playerEntity, _table) || StunnedOrNoHands(playerEntity)) { return false; } @@ -198,7 +199,7 @@ namespace Content.Client.Tabletop return true; } - private bool OnMouseUp(in PointerInputCmdHandler.PointerInputCmdArgs args) + private bool OnMouseUp(in PointerInputCmdArgs args) { StopDragging(); return false; diff --git a/Content.Client/Tabletop/Visualizers/TabletopItemVisualizer.cs b/Content.Client/Tabletop/Visualizers/TabletopItemVisualizer.cs index 1febac6a49..972a24a650 100644 --- a/Content.Client/Tabletop/Visualizers/TabletopItemVisualizer.cs +++ b/Content.Client/Tabletop/Visualizers/TabletopItemVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.Tabletop; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Maths; namespace Content.Client.Tabletop.Visualizers @@ -11,7 +12,8 @@ namespace Content.Client.Tabletop.Visualizers { public override void OnChangeData(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out var sprite)) + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(appearance.Owner, out var sprite)) { return; } diff --git a/Content.Client/Toilet/ToiletVisualizer.cs b/Content.Client/Toilet/ToiletVisualizer.cs index e714b0cbcf..e9096e6c5d 100644 --- a/Content.Client/Toilet/ToiletVisualizer.cs +++ b/Content.Client/Toilet/ToiletVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.Toilet; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Toilet { @@ -10,14 +11,13 @@ namespace Content.Client.Toilet { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if (!component.TryGetData(ToiletVisuals.LidOpen, out bool lidOpen)) lidOpen = false; if (!component.TryGetData(ToiletVisuals.SeatUp, out bool seatUp)) seatUp = false; - var state = string.Format("{0}_toilet_{1}", - lidOpen ? "open" : "closed", - seatUp ? "seat_up" : "seat_down"); + var state = $"{(lidOpen ? "open" : "closed")}_toilet_{(seatUp ? "seat_up" : "seat_down")}"; sprite.LayerSetState(0, state); } diff --git a/Content.Client/Trigger/TimerTriggerVisualizer.cs b/Content.Client/Trigger/TimerTriggerVisualizer.cs index 9b6df47a67..19061d1bdc 100644 --- a/Content.Client/Trigger/TimerTriggerVisualizer.cs +++ b/Content.Client/Trigger/TimerTriggerVisualizer.cs @@ -36,7 +36,7 @@ namespace Content.Client.Trigger } } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { if (!IoCManager.Resolve().HasComponent(entity)) { diff --git a/Content.Client/VendingMachines/UI/VendingMachineVisualizer.cs b/Content.Client/VendingMachines/UI/VendingMachineVisualizer.cs index d4d3ecadf4..0538828536 100644 --- a/Content.Client/VendingMachines/UI/VendingMachineVisualizer.cs +++ b/Content.Client/VendingMachines/UI/VendingMachineVisualizer.cs @@ -117,7 +117,7 @@ namespace Content.Client.VendingMachines.UI flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(key, 0f)); } - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); diff --git a/Content.Client/Verbs/UI/VerbMenuPresenter.cs b/Content.Client/Verbs/UI/VerbMenuPresenter.cs index 8a010ad110..0f2afc685b 100644 --- a/Content.Client/Verbs/UI/VerbMenuPresenter.cs +++ b/Content.Client/Verbs/UI/VerbMenuPresenter.cs @@ -32,7 +32,7 @@ namespace Content.Client.Verbs.UI public EntityUid CurrentTarget; public Dictionary> CurrentVerbs = new(); - public VerbMenuPresenter(VerbSystem verbSystem) : base() + public VerbMenuPresenter(VerbSystem verbSystem) { IoCManager.InjectDependencies(this); _verbSystem = verbSystem; @@ -41,10 +41,9 @@ namespace Content.Client.Verbs.UI /// /// Open a verb menu and fill it work verbs applicable to the given target entity. /// - public void OpenVerbMenu(IEntity target) + public void OpenVerbMenu(EntityUid target) { - var user = _playerManager.LocalPlayer?.ControlledEntity; - if (user == null) + if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} user) return; Close(); diff --git a/Content.Client/Verbs/VerbSystem.cs b/Content.Client/Verbs/VerbSystem.cs index e4f32ca055..732704bac2 100644 --- a/Content.Client/Verbs/VerbSystem.cs +++ b/Content.Client/Verbs/VerbSystem.cs @@ -20,8 +20,6 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Maths; -using static Content.Shared.Interaction.SharedInteractionSystem; namespace Content.Client.Verbs { @@ -87,7 +85,7 @@ namespace Content.Client.Verbs /// /// Get all of the entities in an area for displaying on the context menu. /// - public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true)] out List? result) + public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true)] out List? result) { result = null; @@ -107,8 +105,8 @@ namespace Content.Client.Verbs if ((visibility & MenuVisibility.NoFov) == 0) { var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos); - Ignored? predicate = e => e == player || entitiesUnderMouse.Contains(e); - if (!_examineSystem.CanExamine(player, targetPos, predicate)) + bool Predicate(EntityUid e) => e == player || entitiesUnderMouse.Contains(e); + if (!_examineSystem.CanExamine(player.Value, targetPos, Predicate)) return false; } @@ -130,7 +128,7 @@ namespace Content.Client.Verbs { foreach (var entity in entities.ToList()) { - if (!player.IsInSameOrTransparentContainer(entity)) + if (!player.Value.IsInSameOrTransparentContainer(entity)) entities.Remove(entity); } } @@ -155,7 +153,7 @@ namespace Content.Client.Verbs // Remove any entities that do not have LOS if ((visibility & MenuVisibility.NoFov) == 0) { - var playerPos = IoCManager.Resolve().GetComponent(player).MapPosition; + var playerPos = IoCManager.Resolve().GetComponent(player.Value).MapPosition; foreach (var entity in entities.ToList()) { if (!ExamineSystemShared.InRangeUnOccluded( @@ -180,7 +178,7 @@ namespace Content.Client.Verbs /// Ask the server to send back a list of server-side verbs, and for now return an incomplete list of verbs /// (only those defined locally). /// - public Dictionary> GetVerbs(IEntity target, IEntity user, VerbType verbTypes) + public Dictionary> GetVerbs(EntityUid target, EntityUid user, VerbType verbTypes) { if (!target.IsClientSide()) { diff --git a/Content.Client/Viewport/GameScreenBase.cs b/Content.Client/Viewport/GameScreenBase.cs index 3f09603ae6..0dca62e76f 100644 --- a/Content.Client/Viewport/GameScreenBase.cs +++ b/Content.Client/Viewport/GameScreenBase.cs @@ -6,7 +6,6 @@ using Content.Client.ContextMenu.UI; using Content.Client.Interactable; using Content.Client.Interactable.Components; using Content.Client.State; -using Content.Shared; using Content.Shared.CCVar; using Robust.Client.GameObjects; using Robust.Client.Graphics; @@ -44,7 +43,7 @@ namespace Content.Client.Viewport private IEventBus _eventBus => _entityManager.EventBus; - private IEntity? _lastHoveredEntity; + private EntityUid _lastHoveredEntity; private bool _outlineEnabled = true; @@ -84,7 +83,7 @@ namespace Content.Client.Viewport // lead to extremely thick outlines in the other viewports. Fixing this probably requires changing how the // hover outline works, so that it only highlights the entity in a single viewport. - IEntity? entityToClick = null; + EntityUid entityToClick = default; var renderScale = 1; if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp) { @@ -107,7 +106,7 @@ namespace Content.Client.Viewport } var inRange = false; - if (localPlayer.ControlledEntity != null && entityToClick != null) + if (localPlayer.ControlledEntity != default && entityToClick != default) { inRange = localPlayer.InRangeUnobstructed(entityToClick, ignoreInsideBlocker: true); } @@ -115,7 +114,7 @@ namespace Content.Client.Viewport InteractionOutlineComponent? outline; if(!_outlineEnabled || !ConfigurationManager.GetCVar(CCVars.OutlineEnabled)) { - if(entityToClick != null && IoCManager.Resolve().TryGetComponent(entityToClick, out outline)) + if(entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline)) { outline.OnMouseLeave(); //Prevent outline remains from persisting post command. } @@ -124,7 +123,7 @@ namespace Content.Client.Viewport if (entityToClick == _lastHoveredEntity) { - if (entityToClick != null && IoCManager.Resolve().TryGetComponent(entityToClick, out outline)) + if (entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline)) { outline.UpdateInRange(inRange, renderScale); } @@ -132,42 +131,42 @@ namespace Content.Client.Viewport return; } - if (_lastHoveredEntity != null && !((!IoCManager.Resolve().EntityExists(_lastHoveredEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_lastHoveredEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && - IoCManager.Resolve().TryGetComponent(_lastHoveredEntity, out outline)) + if (_lastHoveredEntity != default && !((!_entityManager.EntityExists(_lastHoveredEntity) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_lastHoveredEntity).EntityLifeStage) >= EntityLifeStage.Deleted) && + _entityManager.TryGetComponent(_lastHoveredEntity, out outline)) { outline.OnMouseLeave(); } _lastHoveredEntity = entityToClick; - if (_lastHoveredEntity != null && IoCManager.Resolve().TryGetComponent(_lastHoveredEntity, out outline)) + if (_lastHoveredEntity != default && _entityManager.TryGetComponent(_lastHoveredEntity, out outline)) { outline.OnMouseEnter(inRange, renderScale); } } - public IEntity? GetEntityUnderPosition(MapCoordinates coordinates) + public EntityUid GetEntityUnderPosition(MapCoordinates coordinates) { var entitiesUnderPosition = GetEntitiesUnderPosition(coordinates); - return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : null; + return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : default; } - public IList GetEntitiesUnderPosition(EntityCoordinates coordinates) + public IList GetEntitiesUnderPosition(EntityCoordinates coordinates) { return GetEntitiesUnderPosition(coordinates.ToMap(EntityManager)); } - public IList GetEntitiesUnderPosition(MapCoordinates coordinates) + public IList GetEntitiesUnderPosition(MapCoordinates coordinates) { // Find all the entities intersecting our click var entities = IoCManager.Resolve().GetEntitiesIntersecting(coordinates.MapId, Box2.CenteredAround(coordinates.Position, (1, 1))); // Check the entities against whether or not we can click them - var foundEntities = new List<(IEntity clicked, int drawDepth, uint renderOrder)>(); + var foundEntities = new List<(EntityUid clicked, int drawDepth, uint renderOrder)>(); foreach (var entity in entities) { - if (IoCManager.Resolve().TryGetComponent(entity, out var component) + if (_entityManager.TryGetComponent(entity, out var component) && !entity.IsInContainer() && component.CheckClick(coordinates.Position, out var drawDepthClicked, out var renderOrder)) { @@ -176,9 +175,9 @@ namespace Content.Client.Viewport } if (foundEntities.Count == 0) - return new List(); + return new List(); - foundEntities.Sort(new ClickableEntityComparer()); + foundEntities.Sort(new ClickableEntityComparer(_entityManager)); // 0 is the top element. foundEntities.Reverse(); return foundEntities.Select(a => a.clicked).ToList(); @@ -193,20 +192,27 @@ namespace Content.Client.Viewport /// state manager to use to get the current game screen /// coordinates to check /// the entities under the position, empty list if none found - public static IList GetEntitiesUnderPosition(IStateManager stateManager, EntityCoordinates coordinates) + public static IList GetEntitiesUnderPosition(IStateManager stateManager, EntityCoordinates coordinates) { if (stateManager.CurrentState is GameScreenBase gameScreenBase) { return gameScreenBase.GetEntitiesUnderPosition(coordinates); } - return ImmutableList.Empty; + return ImmutableList.Empty; } - internal class ClickableEntityComparer : IComparer<(IEntity clicked, int depth, uint renderOrder)> + internal class ClickableEntityComparer : IComparer<(EntityUid clicked, int depth, uint renderOrder)> { - public int Compare((IEntity clicked, int depth, uint renderOrder) x, - (IEntity clicked, int depth, uint renderOrder) y) + private readonly IEntityManager _entities; + + public ClickableEntityComparer(IEntityManager entities) + { + _entities = entities; + } + + public int Compare((EntityUid clicked, int depth, uint renderOrder) x, + (EntityUid clicked, int depth, uint renderOrder) y) { var val = x.depth.CompareTo(y.depth); if (val != 0) @@ -223,8 +229,8 @@ namespace Content.Client.Viewport } */ - var transX = IoCManager.Resolve().GetComponent(x.clicked); - var transY = IoCManager.Resolve().GetComponent(y.clicked); + var transX = _entities.GetComponent(x.clicked); + var transY = _entities.GetComponent(y.clicked); val = transX.Coordinates.Y.CompareTo(transY.Coordinates.Y); if (val != 0) { @@ -254,7 +260,7 @@ namespace Content.Client.Viewport if (args.Viewport is IViewportControl vp) { var mousePosWorld = vp.ScreenToMap(kArgs.PointerLocation.Position); - entityToClick = GetEntityUnderPosition(mousePosWorld) ?? EntityUid.Invalid; + entityToClick = GetEntityUnderPosition(mousePosWorld); coordinates = MapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) : EntityCoordinates.FromMap(MapManager, mousePosWorld); diff --git a/Content.Client/Visualizer/GenericEnumVisualizer.cs b/Content.Client/Visualizer/GenericEnumVisualizer.cs index 06df062ea8..29181d71da 100644 --- a/Content.Client/Visualizer/GenericEnumVisualizer.cs +++ b/Content.Client/Visualizer/GenericEnumVisualizer.cs @@ -1,6 +1,6 @@ using System; -using System.Linq; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -55,7 +55,8 @@ namespace Content.Client.Visualizer { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite)) return; if (!component.TryGetData(Key, out object status)) return; if (!States.TryGetValue(status, out var val)) return; sprite.LayerSetState(Layer, val); diff --git a/Content.Client/Wall/Components/LowWallComponent.cs b/Content.Client/Wall/Components/LowWallComponent.cs index 356671f9af..21d26b55c8 100644 --- a/Content.Client/Wall/Components/LowWallComponent.cs +++ b/Content.Client/Wall/Components/LowWallComponent.cs @@ -33,7 +33,7 @@ namespace Content.Client.Wall.Components public CornerFill LastCornerSW { get; private set; } public CornerFill LastCornerNW { get; private set; } - [ViewVariables] private IEntity? _overlayEntity; + [ViewVariables] private EntityUid _overlayEntity; [ViewVariables] private ISpriteComponent? _overlaySprite; @@ -63,10 +63,10 @@ namespace Content.Client.Wall.Components { base.Shutdown(); - IEntity? tempQualifier = _overlayEntity; + EntityUid tempQualifier = _overlayEntity; if (tempQualifier != null) { - IoCManager.Resolve().DeleteEntity((EntityUid) tempQualifier); + IoCManager.Resolve().DeleteEntity(tempQualifier); } } diff --git a/Content.Client/Wall/ReinforcedWallVisualizer.cs b/Content.Client/Wall/ReinforcedWallVisualizer.cs index ca23401cf4..11810c3889 100644 --- a/Content.Client/Wall/ReinforcedWallVisualizer.cs +++ b/Content.Client/Wall/ReinforcedWallVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; namespace Content.Client.Wall { @@ -22,7 +23,8 @@ namespace Content.Client.Wall { var entity = component.Owner; - if (!entity.TryGetComponent(out ISpriteComponent? sprite)) return; + var entities = IoCManager.Resolve(); + if (!entities.TryGetComponent(entity, out ISpriteComponent? sprite)) return; if (stage < 0) { diff --git a/Content.Client/Weapons/Melee/Components/MeleeWeaponArcAnimationComponent.cs b/Content.Client/Weapons/Melee/Components/MeleeWeaponArcAnimationComponent.cs index 81ccdc9850..0c80abd800 100644 --- a/Content.Client/Weapons/Melee/Components/MeleeWeaponArcAnimationComponent.cs +++ b/Content.Client/Weapons/Melee/Components/MeleeWeaponArcAnimationComponent.cs @@ -25,7 +25,7 @@ namespace Content.Client.Weapons.Melee.Components _sprite = IoCManager.Resolve().GetComponent(Owner); } - public void SetData(MeleeWeaponAnimationPrototype prototype, Angle baseAngle, IEntity attacker, bool followAttacker = true) + public void SetData(MeleeWeaponAnimationPrototype prototype, Angle baseAngle, EntityUid attacker, bool followAttacker = true) { _meleeWeaponAnimation = prototype; _sprite?.AddLayer(new RSI.StateId(prototype.State)); @@ -72,7 +72,7 @@ namespace Content.Client.Weapons.Melee.Components if (_meleeWeaponAnimation.Length.TotalSeconds <= _timer) { - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); } } } diff --git a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs index 809ee4503b..7cdc05cba2 100644 --- a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs +++ b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs @@ -44,28 +44,29 @@ namespace Content.Client.Weapons.Melee return; } - if (!EntityManager.TryGetEntity(msg.Attacker, out var attacker)) + var attacker = msg.Attacker; + if (!EntityManager.EntityExists(msg.Attacker)) { // FIXME: This should never happen. Logger.Error($"Tried to play a weapon arc {msg.ArcPrototype}, but the attacker does not exist. attacker={msg.Attacker}, source={msg.Source}"); return; } - if (!((!IoCManager.Resolve().EntityExists(attacker) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(attacker).EntityLifeStage) >= EntityLifeStage.Deleted)) + if (!((!EntityManager.EntityExists(attacker) ? EntityLifeStage.Deleted : EntityManager.GetComponent(attacker).EntityLifeStage) >= EntityLifeStage.Deleted)) { var lunge = attacker.EnsureComponent(); lunge.SetData(msg.Angle); - var entity = EntityManager.SpawnEntity(weaponArc.Prototype, IoCManager.Resolve().GetComponent(attacker).Coordinates); - IoCManager.Resolve().GetComponent(entity).LocalRotation = msg.Angle; + var entity = EntityManager.SpawnEntity(weaponArc.Prototype, EntityManager.GetComponent(attacker).Coordinates); + EntityManager.GetComponent(entity).LocalRotation = msg.Angle; - var weaponArcAnimation = IoCManager.Resolve().GetComponent(entity); + var weaponArcAnimation = EntityManager.GetComponent(entity); weaponArcAnimation.SetData(weaponArc, msg.Angle, attacker, msg.ArcFollowAttacker); // Due to ISpriteComponent limitations, weapons that don't use an RSI won't have this effect. - if (EntityManager.TryGetEntity(msg.Source, out var source) && + if (EntityManager.EntityExists(msg.Source) && msg.TextureEffect && - IoCManager.Resolve().TryGetComponent(source, out ISpriteComponent? sourceSprite) && + EntityManager.TryGetComponent(msg.Source, out ISpriteComponent? sourceSprite) && sourceSprite.BaseRSI?.Path != null) { var curTime = _gameTiming.CurTime; @@ -73,7 +74,7 @@ namespace Content.Client.Weapons.Melee { EffectSprite = sourceSprite.BaseRSI.Path.ToString(), RsiState = sourceSprite.LayerGetState(0).Name, - Coordinates = IoCManager.Resolve().GetComponent(attacker).Coordinates, + Coordinates = EntityManager.GetComponent(attacker).Coordinates, Color = Vector4.Multiply(new Vector4(255, 255, 255, 125), 1.0f), ColorDelta = Vector4.Multiply(new Vector4(0, 0, 0, -10), 1.0f), Velocity = msg.Angle.ToWorldVec(), @@ -86,14 +87,14 @@ namespace Content.Client.Weapons.Melee } } - foreach (var uid in msg.Hits) + foreach (var hit in msg.Hits) { - if (!EntityManager.TryGetEntity(uid, out var hitEntity) || (!IoCManager.Resolve().EntityExists(hitEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(hitEntity).EntityLifeStage) >= EntityLifeStage.Deleted) + if (!EntityManager.EntityExists(hit)) { continue; } - if (!IoCManager.Resolve().TryGetComponent(hitEntity, out ISpriteComponent? sprite)) + if (!EntityManager.TryGetComponent(hit, out ISpriteComponent? sprite)) { continue; } @@ -102,7 +103,7 @@ namespace Content.Client.Weapons.Melee var newColor = Color.Red * originalColor; sprite.Color = newColor; - hitEntity.SpawnTimer(100, () => + hit.SpawnTimer(100, () => { // Only reset back to the original color if something else didn't change the color in the mean time. if (sprite.Color == newColor) @@ -115,9 +116,9 @@ namespace Content.Client.Weapons.Melee private void PlayLunge(PlayLungeAnimationMessage msg) { - if (EntityManager.TryGetEntity(msg.Source, out var entity)) + if (EntityManager.EntityExists(msg.Source)) { - entity.EnsureComponent().SetData(msg.Angle); + msg.Source.EnsureComponent().SetData(msg.Angle); } else { diff --git a/Content.Client/Weapons/Ranged/Barrels/Visualizers/BarrelBoltVisualizer.cs b/Content.Client/Weapons/Ranged/Barrels/Visualizers/BarrelBoltVisualizer.cs index da9364c079..cce9bbdac8 100644 --- a/Content.Client/Weapons/Ranged/Barrels/Visualizers/BarrelBoltVisualizer.cs +++ b/Content.Client/Weapons/Ranged/Barrels/Visualizers/BarrelBoltVisualizer.cs @@ -9,7 +9,7 @@ namespace Content.Client.Weapons.Ranged.Barrels.Visualizers [UsedImplicitly] public sealed class BarrelBoltVisualizer : AppearanceVisualizer { - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); var sprite = IoCManager.Resolve().GetComponent(entity); diff --git a/Content.Client/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs b/Content.Client/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs index b80752fdc5..948c1aeff3 100644 --- a/Content.Client/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs +++ b/Content.Client/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs @@ -19,7 +19,7 @@ namespace Content.Client.Weapons.Ranged.Barrels.Visualizers [DataField("zeroVisible")] private bool _zeroVisible; - public override void InitializeEntity(IEntity entity) + public override void InitializeEntity(EntityUid entity) { base.InitializeEntity(entity); var sprite = IoCManager.Resolve().GetComponent(entity); diff --git a/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs b/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs index 9908236fc9..a6bea89365 100644 --- a/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs +++ b/Content.Client/Weapons/Ranged/RangedWeaponSystem.cs @@ -1,6 +1,5 @@ using System; using Content.Client.CombatMode; -using Content.Client.Hands; using Content.Shared.Hands.Components; using Content.Shared.Weapons.Ranged.Components; using JetBrains.Annotations; @@ -48,12 +47,12 @@ namespace Content.Client.Weapons.Ranged } var entity = _playerManager.LocalPlayer?.ControlledEntity; - if (entity == null || !IoCManager.Resolve().TryGetComponent(entity, out SharedHandsComponent? hands)) + if (entity == default || !EntityManager.TryGetComponent(entity.Value, out SharedHandsComponent? hands)) { return; } - if (!hands.TryGetActiveHeldEntity(out var held) || !IoCManager.Resolve().TryGetComponent(held, out ClientRangedWeaponComponent? weapon)) + if (!hands.TryGetActiveHeldEntity(out var held) || !EntityManager.TryGetComponent(held, out ClientRangedWeaponComponent? weapon)) { _blocked = true; return; diff --git a/Content.IntegrationTests/Tests/Administration/Logs/AddTests.cs b/Content.IntegrationTests/Tests/Administration/Logs/AddTests.cs index bb9aef7ecf..e78d501560 100644 --- a/Content.IntegrationTests/Tests/Administration/Logs/AddTests.cs +++ b/Content.IntegrationTests/Tests/Administration/Logs/AddTests.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Content.Server.Administration.Logs; using Content.Server.Database; using Content.Server.GameTicking; -using Content.Shared.Administration.Logs; using Content.Shared.CCVar; using Content.Shared.Database; using NUnit.Framework; @@ -161,7 +160,7 @@ public class AddTests : ContentIntegrationTest await server.WaitPost(() => { var coordinates = GetMainEntityCoordinates(sMaps); - var entity = sEntities.SpawnEntity(null, coordinates).Uid; + var entity = sEntities.SpawnEntity(null, coordinates); if (parallel) { diff --git a/Content.IntegrationTests/Tests/Body/LungTest.cs b/Content.IntegrationTests/Tests/Body/LungTest.cs index b26f4d609e..78875aecb1 100644 --- a/Content.IntegrationTests/Tests/Body/LungTest.cs +++ b/Content.IntegrationTests/Tests/Body/LungTest.cs @@ -153,7 +153,7 @@ namespace Content.IntegrationTests.Tests.Body MapId mapId; IMapGrid grid = null; RespiratorComponent respirator = null; - EntityUid human = null; + EntityUid human = default; var testMapName = "Maps/Test/Breathing/3by3-20oxy-80nit.yml"; diff --git a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs index a01f151e0b..61326e5be6 100644 --- a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs +++ b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs @@ -1,4 +1,3 @@ -using System.Linq; using System.Threading.Tasks; using Content.Server.Buckle.Components; using Content.Server.Hands.Components; @@ -7,10 +6,8 @@ using Content.Shared.ActionBlocker; using Content.Shared.Body.Components; using Content.Shared.Body.Part; using Content.Shared.Buckle.Components; -using Content.Shared.Coordinates; using Content.Shared.Standing; using NUnit.Framework; -using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; @@ -58,8 +55,8 @@ namespace Content.IntegrationTests.Tests.Buckle var sOptions = new ServerIntegrationOptions {ExtraPrototypes = Prototypes}; var (_, server) = await StartConnectedServerClientPair(cOptions, sOptions); - IEntity human = null; - IEntity chair = null; + EntityUid human = default; + EntityUid chair = default; BuckleComponent buckle = null; StrapComponent strap = null; @@ -72,23 +69,23 @@ namespace Content.IntegrationTests.Tests.Buckle var standingState = EntitySystem.Get(); var grid = GetMainGrid(mapManager); - var coordinates = grid.GridEntityId.ToCoordinates(); + var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0); human = entityManager.SpawnEntity(BuckleDummyId, coordinates); chair = entityManager.SpawnEntity(StrapDummyId, coordinates); // Default state, unbuckled - Assert.True(IoCManager.Resolve().TryGetComponent(human, out buckle)); + Assert.True(entityManager.TryGetComponent(human, out buckle)); Assert.NotNull(buckle); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); Assert.True(actionBlocker.CanMove(human)); Assert.True(actionBlocker.CanChangeDirection(human)); - Assert.True(standingState.Down((EntityUid) human)); - Assert.True(standingState.Stand((EntityUid) human)); + Assert.True(standingState.Down(human)); + Assert.True(standingState.Stand(human)); // Default state, no buckled entities, strap - Assert.True(IoCManager.Resolve().TryGetComponent(chair, out strap)); + Assert.True(entityManager.TryGetComponent(chair, out strap)); Assert.NotNull(strap); Assert.IsEmpty(strap.BuckledEntities); Assert.Zero(strap.OccupiedSize); @@ -98,12 +95,11 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.NotNull(buckle.BuckledTo); Assert.True(buckle.Buckled); - var player = IoCManager.Resolve().Sessions.Single(); Assert.True(((BuckleComponentState) buckle.GetComponentState()).Buckled); Assert.False(actionBlocker.CanMove(human)); Assert.False(actionBlocker.CanChangeDirection(human)); - Assert.False(standingState.Down((EntityUid) human)); - Assert.That((IoCManager.Resolve().GetComponent(human).WorldPosition - IoCManager.Resolve().GetComponent(chair).WorldPosition).Length, Is.LessThanOrEqualTo(buckle.BuckleOffset.Length)); + Assert.False(standingState.Down(human)); + Assert.That((entityManager.GetComponent(human).WorldPosition - entityManager.GetComponent(chair).WorldPosition).Length, Is.LessThanOrEqualTo(buckle.BuckleOffset.Length)); // Side effects of buckling for the strap Assert.That(strap.BuckledEntities, Does.Contain(human)); @@ -136,7 +132,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.False(buckle.Buckled); Assert.True(actionBlocker.CanMove(human)); Assert.True(actionBlocker.CanChangeDirection(human)); - Assert.True(standingState.Down((EntityUid) human)); + Assert.True(standingState.Down(human)); // Unbuckle, strap Assert.IsEmpty(strap.BuckledEntities); @@ -160,6 +156,7 @@ namespace Content.IntegrationTests.Tests.Buckle await server.WaitAssertion(() => { + var entityManager = IoCManager.Resolve(); var actionBlocker = EntitySystem.Get(); var standingState = EntitySystem.Get(); @@ -171,7 +168,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.False(buckle.Buckled); // Move away from the chair - IoCManager.Resolve().GetComponent(human).WorldPosition += (1000, 1000); + entityManager.GetComponent(human).WorldPosition += (1000, 1000); // Out of range Assert.False(buckle.TryBuckle(human, chair)); @@ -179,7 +176,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.False(buckle.ToggleBuckle(human, chair)); // Move near the chair - IoCManager.Resolve().GetComponent(human).WorldPosition = IoCManager.Resolve().GetComponent(chair).WorldPosition + (0.5f, 0); + entityManager.GetComponent(human).WorldPosition = entityManager.GetComponent(chair).WorldPosition + (0.5f, 0); // In range Assert.True(buckle.TryBuckle(human, chair)); @@ -194,13 +191,13 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.False(buckle.Buckled); Assert.True(actionBlocker.CanMove(human)); Assert.True(actionBlocker.CanChangeDirection(human)); - Assert.True(standingState.Down((EntityUid) human)); + Assert.True(standingState.Down(human)); // Re-buckle Assert.True(buckle.TryBuckle(human, chair)); // Move away from the chair - IoCManager.Resolve().GetComponent(human).WorldPosition += (1, 0); + entityManager.GetComponent(human).WorldPosition += (1, 0); }); await server.WaitRunTicks(1); @@ -220,7 +217,7 @@ namespace Content.IntegrationTests.Tests.Buckle var options = new ServerContentIntegrationOption {ExtraPrototypes = Prototypes}; var server = StartServer(options); - IEntity human = null; + EntityUid human = default; BuckleComponent buckle = null; HandsComponent hands = null; SharedBodyComponent body = null; @@ -233,16 +230,16 @@ namespace Content.IntegrationTests.Tests.Buckle var entityManager = IoCManager.Resolve(); var grid = GetMainGrid(mapManager); - var coordinates = grid.GridEntityId.ToCoordinates(); + var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0); human = entityManager.SpawnEntity(BuckleDummyId, coordinates); - IEntity chair = entityManager.SpawnEntity(StrapDummyId, coordinates); + var chair = entityManager.SpawnEntity(StrapDummyId, coordinates); // Component sanity check - Assert.True(IoCManager.Resolve().TryGetComponent(human, out buckle)); - Assert.True(IoCManager.Resolve().HasComponent(chair)); - Assert.True(IoCManager.Resolve().TryGetComponent(human, out hands)); - Assert.True(IoCManager.Resolve().TryGetComponent(human, out body)); + Assert.True(entityManager.TryGetComponent(human, out buckle)); + Assert.True(entityManager.HasComponent(chair)); + Assert.True(entityManager.TryGetComponent(human, out hands)); + Assert.True(entityManager.TryGetComponent(human, out body)); // Buckle Assert.True(buckle.TryBuckle(human, chair)); @@ -255,7 +252,7 @@ namespace Content.IntegrationTests.Tests.Buckle var akms = entityManager.SpawnEntity(ItemDummyId, coordinates); // Equip items - Assert.True(IoCManager.Resolve().TryGetComponent(akms, out ItemComponent item)); + Assert.True(entityManager.TryGetComponent(akms, out ItemComponent item)); Assert.True(hands.PutInHand(item)); } }); @@ -308,8 +305,8 @@ namespace Content.IntegrationTests.Tests.Buckle }; var server = StartServer(options); - IEntity human = null; - IEntity chair = null; + EntityUid human = default; + EntityUid chair = default; BuckleComponent buckle = null; await server.WaitAssertion(() => @@ -318,14 +315,14 @@ namespace Content.IntegrationTests.Tests.Buckle var entityManager = IoCManager.Resolve(); var grid = GetMainGrid(mapManager); - var coordinates = grid.GridEntityId.ToCoordinates(); + var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0); human = entityManager.SpawnEntity(BuckleDummyId, coordinates); chair = entityManager.SpawnEntity(StrapDummyId, coordinates); // Component sanity check - Assert.True(IoCManager.Resolve().TryGetComponent(human, out buckle)); - Assert.True(IoCManager.Resolve().HasComponent(chair)); + Assert.True(entityManager.TryGetComponent(human, out buckle)); + Assert.True(entityManager.HasComponent(chair)); // Buckle Assert.True(buckle.TryBuckle(human, chair)); @@ -333,7 +330,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.True(buckle.Buckled); // Move the buckled entity away - IoCManager.Resolve().GetComponent(human).WorldPosition += (100, 0); + entityManager.GetComponent(human).WorldPosition += (100, 0); }); await WaitUntil(server, () => !buckle.Buckled, 10); @@ -342,8 +339,10 @@ namespace Content.IntegrationTests.Tests.Buckle await server.WaitAssertion(() => { + var entityManager = IoCManager.Resolve(); + // Move the now unbuckled entity back onto the chair - IoCManager.Resolve().GetComponent(human).WorldPosition -= (100, 0); + entityManager.GetComponent(human).WorldPosition -= (100, 0); // Buckle Assert.True(buckle.TryBuckle(human, chair)); diff --git a/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs b/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs index a11774c8fb..12db1b9870 100644 --- a/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs +++ b/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs @@ -43,7 +43,7 @@ namespace Content.IntegrationTests.Tests.Chemistry //since i have no clue how to isolate each loop assert-wise im just gonna throw this one in for good measure Console.WriteLine($"Testing {reactionPrototype.ID}"); - IEntity beaker; + EntityUid beaker; Solution component = null; server.Assert(() => @@ -67,7 +67,7 @@ namespace Content.IntegrationTests.Tests.Chemistry //(i'm sorry) var foundProductsMap = reactionPrototype.Products .Concat(reactionPrototype.Reactants.Where(x => x.Value.Catalyst).ToDictionary(x => x.Key, x => x.Value.Amount)) - .ToDictionary(x => x, x => false); + .ToDictionary(x => x, _ => false); foreach (var reagent in component.Contents) { Assert.That(foundProductsMap.TryFirstOrNull(x => x.Key.Key == reagent.ReagentId && x.Key.Value == reagent.Quantity, out var foundProduct)); diff --git a/Content.IntegrationTests/Tests/ClickableTest.cs b/Content.IntegrationTests/Tests/ClickableTest.cs index ecd9c3128e..66a9d8b79e 100644 --- a/Content.IntegrationTests/Tests/ClickableTest.cs +++ b/Content.IntegrationTests/Tests/ClickableTest.cs @@ -77,8 +77,7 @@ namespace Content.IntegrationTests.Tests await _server.WaitPost(() => { var gridEnt = mapManager.GetAllGrids().First().GridEntityId; - IEntity tempQualifier = serverEntManager.GetEntity(gridEnt); - worldPos = IoCManager.Resolve().GetComponent(tempQualifier).WorldPosition; + worldPos = IoCManager.Resolve().GetComponent(gridEnt).WorldPosition; var ent = serverEntManager.SpawnEntity(prototype, new EntityCoordinates(gridEnt, 0f, 0f)); IoCManager.Resolve().GetComponent(ent).LocalRotation = angle; @@ -93,8 +92,7 @@ namespace Content.IntegrationTests.Tests await _client.WaitPost(() => { - var ent = clientEntManager.GetEntity(entity); - var clickable = IoCManager.Resolve().GetComponent(ent); + var clickable = IoCManager.Resolve().GetComponent(entity); hit = clickable.CheckClick((clickPosX, clickPosY) + worldPos!.Value, out _, out _); }); diff --git a/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs b/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs index 3b10bc266c..a63f0f0019 100644 --- a/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs +++ b/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs @@ -74,14 +74,17 @@ namespace Content.IntegrationTests.Tests { var (c, s) = await Start(); - EntityUid dummyUid = default; + await c.WaitIdleAsync(); + + var cEntities = c.ResolveDependency(); + + EntityUid dummy = default; s.Post(() => { var pos = new MapCoordinates(Vector2.Zero, new MapId(1)); var ent = IoCManager.Resolve(); var container = ent.SpawnEntity("ContainerOcclusionA", pos); - var dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos); - dummyUid = dummy; + dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos); IoCManager.Resolve().GetComponent(container).Insert(dummy); }); @@ -90,9 +93,8 @@ namespace Content.IntegrationTests.Tests c.Assert(() => { - var dummy = IoCManager.Resolve().GetEntity(dummyUid); - var sprite = IoCManager.Resolve().GetComponent(dummy); - var light = IoCManager.Resolve().GetComponent(dummy); + var sprite = cEntities.GetComponent(dummy); + var light = cEntities.GetComponent(dummy); Assert.True(sprite.ContainerOccluded); Assert.True(light.ContainerOccluded); }); @@ -105,14 +107,17 @@ namespace Content.IntegrationTests.Tests { var (c, s) = await Start(); - EntityUid dummyUid = default; + await c.WaitIdleAsync(); + + var cEntities = c.ResolveDependency(); + + EntityUid dummy = default; s.Post(() => { var pos = new MapCoordinates(Vector2.Zero, new MapId(1)); var ent = IoCManager.Resolve(); var container = ent.SpawnEntity("ContainerOcclusionB", pos); - var dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos); - dummyUid = dummy; + dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos); IoCManager.Resolve().GetComponent(container).Insert(dummy); }); @@ -121,9 +126,8 @@ namespace Content.IntegrationTests.Tests c.Assert(() => { - var dummy = IoCManager.Resolve().GetEntity(dummyUid); - var sprite = IoCManager.Resolve().GetComponent(dummy); - var light = IoCManager.Resolve().GetComponent(dummy); + var sprite = cEntities.GetComponent(dummy); + var light = cEntities.GetComponent(dummy); Assert.False(sprite.ContainerOccluded); Assert.False(light.ContainerOccluded); }); @@ -136,15 +140,18 @@ namespace Content.IntegrationTests.Tests { var (c, s) = await Start(); - EntityUid dummyUid = default; + await c.WaitIdleAsync(); + + var cEntities = c.ResolveDependency(); + + EntityUid dummy = default; s.Post(() => { var pos = new MapCoordinates(Vector2.Zero, new MapId(1)); var ent = IoCManager.Resolve(); var containerA = ent.SpawnEntity("ContainerOcclusionA", pos); var containerB = ent.SpawnEntity("ContainerOcclusionB", pos); - var dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos); - dummyUid = dummy; + dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos); IoCManager.Resolve().GetComponent(containerA).Insert(containerB); IoCManager.Resolve().GetComponent(containerB).Insert(dummy); @@ -154,9 +161,8 @@ namespace Content.IntegrationTests.Tests c.Assert(() => { - var dummy = IoCManager.Resolve().GetEntity(dummyUid); - var sprite = IoCManager.Resolve().GetComponent(dummy); - var light = IoCManager.Resolve().GetComponent(dummy); + var sprite = cEntities.GetComponent(dummy); + var light = cEntities.GetComponent(dummy); Assert.True(sprite.ContainerOccluded); Assert.True(light.ContainerOccluded); }); diff --git a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs index 8945f961d5..a254427e41 100644 --- a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs +++ b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs @@ -95,7 +95,7 @@ namespace Content.IntegrationTests.Tests.Damageable sEntityManager.EventBus.SubscribeLocalEvent(DamageChangedListener); - IEntity sDamageableEntity = null; + EntityUid sDamageableEntity = default; DamageableComponent sDamageableComponent = null; DamageableSystem sDamageableSystem = null; diff --git a/Content.IntegrationTests/Tests/DeleteInventoryTest.cs b/Content.IntegrationTests/Tests/DeleteInventoryTest.cs index decafab3e1..dde7ab1bab 100644 --- a/Content.IntegrationTests/Tests/DeleteInventoryTest.cs +++ b/Content.IntegrationTests/Tests/DeleteInventoryTest.cs @@ -28,17 +28,17 @@ namespace Content.IntegrationTests.Tests var entMgr = IoCManager.Resolve(); var container = entMgr.SpawnEntity(null, MapCoordinates.Nullspace); - var inv = (InventoryComponent) IoCManager.Resolve().AddComponent(container); + var inv = IoCManager.Resolve().AddComponent(container); var child = entMgr.SpawnEntity(null, MapCoordinates.Nullspace); - var item = (ClothingComponent) IoCManager.Resolve().AddComponent(child); + var item = IoCManager.Resolve().AddComponent(child); item.SlotFlags = SlotFlags.HEAD; // Equip item. Assert.That(inv.Equip(Slots.HEAD, item, false), Is.True); // Delete parent. - IoCManager.Resolve().DeleteEntity((EntityUid) container); + IoCManager.Resolve().DeleteEntity(container); // Assert that child item was also deleted. Assert.That(item.Deleted, Is.True); diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs index 0cbfc16f27..94bd41862b 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs @@ -32,7 +32,7 @@ namespace Content.IntegrationTests.Tests.Destructible var sPrototypeManager = server.ResolveDependency(); var sEntitySystemManager = server.ResolveDependency(); - IEntity sDestructibleEntity = null; + EntityUid sDestructibleEntity = default; DamageableComponent sDamageableComponent = null; TestDestructibleListenerSystem sTestThresholdListenerSystem = null; DamageableSystem sDamageableSystem = null; diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs index fad076471c..401d6a3030 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs @@ -30,7 +30,7 @@ namespace Content.IntegrationTests.Tests.Destructible var sMapManager = server.ResolveDependency(); var sEntitySystemManager = server.ResolveDependency(); - IEntity sDestructibleEntity = null; + EntityUid sDestructibleEntity = default; DamageableComponent sDamageableComponent = null; TestDestructibleListenerSystem sTestThresholdListenerSystem = null; DamageableSystem sDamageableSystem = null; diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs index 6d3ccc570a..85132fbd56 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs @@ -30,8 +30,7 @@ namespace Content.IntegrationTests.Tests.Destructible var sPrototypeManager = server.ResolveDependency(); var sEntitySystemManager = server.ResolveDependency(); - IEntity sDestructibleEntity = null; - DamageableComponent sDamageableComponent = null; + EntityUid sDestructibleEntity = default; TestDestructibleListenerSystem sTestThresholdListenerSystem = null; await server.WaitPost(() => @@ -40,7 +39,6 @@ namespace Content.IntegrationTests.Tests.Destructible var coordinates = new EntityCoordinates(gridId, 0, 0); sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDestructionEntityId, coordinates); - sDamageableComponent = IoCManager.Resolve().GetComponent(sDestructibleEntity); sTestThresholdListenerSystem = sEntitySystemManager.GetEntitySystem(); }); @@ -73,12 +71,12 @@ namespace Content.IntegrationTests.Tests.Destructible foreach (var entity in entitiesInRange) { - if (IoCManager.Resolve().GetComponent(entity).EntityPrototype == null) + if (sEntityManager.GetComponent(entity).EntityPrototype == null) { continue; } - if (IoCManager.Resolve().GetComponent(entity).EntityPrototype.Name != SpawnedEntityId) + if (sEntityManager.GetComponent(entity).EntityPrototype?.Name != SpawnedEntityId) { continue; } diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs index f0c42f172b..547275ff66 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs @@ -36,7 +36,7 @@ namespace Content.IntegrationTests.Tests.Destructible var sPrototypeManager = server.ResolveDependency(); var sEntitySystemManager = server.ResolveDependency(); - EntityUid sDestructibleEntity = null; ; + EntityUid sDestructibleEntity = default; DamageableComponent sDamageableComponent = null; DestructibleComponent sDestructibleComponent = null; TestDestructibleListenerSystem sTestThresholdListenerSystem = null; diff --git a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs index d6aa0b1150..7b8f0e4602 100644 --- a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs +++ b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs @@ -64,8 +64,8 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem(); - IEntity device1 = null; - IEntity device2 = null; + EntityUid device1 = default; + EntityUid device2 = default; DeviceNetworkComponent networkComponent1 = null; DeviceNetworkComponent networkComponent2 = null; @@ -126,8 +126,8 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem(); - IEntity device1 = null; - IEntity device2 = null; + EntityUid device1 = default; + EntityUid device2 = default; DeviceNetworkComponent networkComponent1 = null; DeviceNetworkComponent networkComponent2 = null; WirelessNetworkComponent wirelessNetworkComponent = null; @@ -208,8 +208,8 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem(); - IEntity device1 = null; - IEntity device2 = null; + EntityUid device1 = default; + EntityUid device2 = default; DeviceNetworkComponent networkComponent1 = null; DeviceNetworkComponent networkComponent2 = null; WiredNetworkComponent wiredNetworkComponent = null; diff --git a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs index 0d40199825..660735d28f 100644 --- a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs +++ b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs @@ -37,7 +37,7 @@ namespace Content.IntegrationTests.Tests.Disposal } } - private void UnitInsert(DisposalUnitComponent unit, bool result, params IEntity[] entities) + private void UnitInsert(DisposalUnitComponent unit, bool result, params EntityUid[] entities) { var system = EntitySystem.Get(); @@ -48,7 +48,7 @@ namespace Content.IntegrationTests.Tests.Disposal } } - private void UnitContains(DisposalUnitComponent unit, bool result, params IEntity[] entities) + private void UnitContains(DisposalUnitComponent unit, bool result, params EntityUid[] entities) { foreach (var entity in entities) { @@ -56,13 +56,13 @@ namespace Content.IntegrationTests.Tests.Disposal } } - private void UnitInsertContains(DisposalUnitComponent unit, bool result, params IEntity[] entities) + private void UnitInsertContains(DisposalUnitComponent unit, bool result, params EntityUid[] entities) { UnitInsert(unit, result, entities); UnitContains(unit, result, entities); } - private void Flush(DisposalUnitComponent unit, bool result, params IEntity[] entities) + private void Flush(DisposalUnitComponent unit, bool result, params EntityUid[] entities) { Assert.That(unit.ContainedEntities, Is.SupersetOf(entities)); Assert.That(entities.Length, Is.EqualTo(unit.ContainedEntities.Count)); @@ -127,10 +127,10 @@ namespace Content.IntegrationTests.Tests.Disposal var server = StartServer(options); await server.WaitIdleAsync(); - IEntity human = default!; - IEntity wrench = default!; - IEntity disposalUnit = default!; - IEntity disposalTrunk = default!; + EntityUid human = default!; + EntityUid wrench = default!; + EntityUid disposalUnit = default!; + EntityUid disposalTrunk = default!; DisposalUnitComponent unit = default!; var mapManager = server.ResolveDependency(); diff --git a/Content.IntegrationTests/Tests/Doors/AirlockTest.cs b/Content.IntegrationTests/Tests/Doors/AirlockTest.cs index ebfa220b9b..10627b8b4b 100644 --- a/Content.IntegrationTests/Tests/Doors/AirlockTest.cs +++ b/Content.IntegrationTests/Tests/Doors/AirlockTest.cs @@ -56,7 +56,7 @@ namespace Content.IntegrationTests.Tests.Doors var mapManager = server.ResolveDependency(); var entityManager = server.ResolveDependency(); - EntityUid airlock = null; + EntityUid airlock = default; ServerDoorComponent doorComponent = null; server.Assert(() => @@ -97,7 +97,7 @@ namespace Content.IntegrationTests.Tests.Doors { Assert.DoesNotThrow(() => { - IoCManager.Resolve().DeleteEntity((EntityUid) airlock); + IoCManager.Resolve().DeleteEntity(airlock); }); }); @@ -121,8 +121,8 @@ namespace Content.IntegrationTests.Tests.Doors var entityManager = server.ResolveDependency(); IPhysBody physBody = null; - EntityUid physicsDummy = null; - EntityUid airlock = null; + EntityUid physicsDummy = default; + EntityUid airlock = default; ServerDoorComponent doorComponent = null; var physicsDummyStartingX = -1; diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index 918f57abfd..6a4b69e38f 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -15,7 +15,7 @@ using Robust.Shared.Timing; namespace Content.IntegrationTests.Tests { [TestFixture] - [TestOf(typeof(IEntity))] + [TestOf(typeof(EntityUid))] public class EntityTest : ContentIntegrationTest { [Test] @@ -89,7 +89,7 @@ namespace Content.IntegrationTests.Tests testEntity = entityMan.SpawnEntity(prototype.ID, testLocation); server.RunTicks(2); Assert.That((!IoCManager.Resolve().EntityExists(testEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(testEntity).EntityLifeStage) >= EntityLifeStage.Initialized); - entityMan.DeleteEntity((EntityUid) testEntity); + entityMan.DeleteEntity(testEntity); }, "Entity '{0}' threw an exception.", prototype.ID); } @@ -194,7 +194,7 @@ namespace Content.IntegrationTests.Tests server.RunTicks(2); - entityManager.DeleteEntity((EntityUid) entity); + entityManager.DeleteEntity(entity); } }); }); @@ -336,7 +336,7 @@ namespace Content.IntegrationTests.Tests } server.RunTicks(2); - entityManager.DeleteEntity((EntityUid) entity); + entityManager.DeleteEntity(entity); } }); }); diff --git a/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs b/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs index 9a09dd1623..c58d26ab0a 100644 --- a/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs +++ b/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs @@ -85,12 +85,11 @@ namespace Content.IntegrationTests.Tests.Fluids var sPauseManager = server.ResolveDependency(); var sTileDefinitionManager = server.ResolveDependency(); var sGameTiming = server.ResolveDependency(); - var sEntityManager = server.ResolveDependency(); MapId sMapId = default; IMapGrid sGrid; GridId sGridId = default; - EntityUid sGridEntity = null; + EntityUid sGridEntity = default; EntityCoordinates sCoordinates = default; // Spawn a paused map with one tile to spawn puddles on @@ -100,7 +99,7 @@ namespace Content.IntegrationTests.Tests.Fluids sPauseManager.SetMapPaused(sMapId, true); sGrid = sMapManager.CreateGrid(sMapId); sGridId = sGrid.Index; - sGridEntity = sEntityManager.GetEntity(sGrid.GridEntityId); + sGridEntity = sGrid.GridEntityId; IoCManager.Resolve().GetComponent(sGridEntity).EntityPaused = true; // See https://github.com/space-wizards/RobustToolbox/issues/1444 var tileDefinition = sTileDefinitionManager["underplating"]; diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs b/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs index 59e86b1b26..0826619632 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs @@ -42,10 +42,10 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var server = StartServer(options); - IEntity human; - IEntity otherHuman; - IEntity cuffs; - IEntity secondCuffs; + EntityUid human; + EntityUid otherHuman; + EntityUid cuffs; + EntityUid secondCuffs; CuffableComponent cuffed; HandsComponent hands; @@ -63,16 +63,14 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); - IoCManager.Resolve().GetComponent(human).WorldPosition = IoCManager.Resolve().GetComponent(otherHuman).WorldPosition; + entityManager.GetComponent(human).WorldPosition = entityManager.GetComponent(otherHuman).WorldPosition; // Test for components existing - ref CuffableComponent? comp = ref cuffed!; - Assert.True(IoCManager.Resolve().TryGetComponent(human, out comp), $"Human has no {nameof(CuffableComponent)}"); - ref HandsComponent? comp1 = ref hands!; - Assert.True(IoCManager.Resolve().TryGetComponent(human, out comp1), $"Human has no {nameof(HandsComponent)}"); - Assert.True(IoCManager.Resolve().TryGetComponent(human, out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}"); - Assert.True(IoCManager.Resolve().TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}"); - Assert.True(IoCManager.Resolve().TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}"); + Assert.True(entityManager.TryGetComponent(human, out cuffed), $"Human has no {nameof(CuffableComponent)}"); + Assert.True(entityManager.TryGetComponent(human, out hands), $"Human has no {nameof(HandsComponent)}"); + Assert.True(entityManager.TryGetComponent(human, out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}"); + Assert.True(entityManager.TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}"); + Assert.True(entityManager.TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}"); // Test to ensure cuffed players register the handcuffs cuffed.TryAddNewCuffs(human, cuffs); @@ -94,7 +92,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking await server.WaitIdleAsync(); } - private void AddHand(IEntity to) + private void AddHand(EntityUid to) { var host = IoCManager.Resolve(); host.ExecuteCommand(null, $"addhand {to}"); diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/ActionsComponentTests.cs b/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/ActionsComponentTests.cs index 239ffb5c0e..f1b1dd11c6 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/ActionsComponentTests.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/ActionsComponentTests.cs @@ -66,13 +66,16 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs await server.WaitIdleAsync(); await client.WaitIdleAsync(); + var cEntities = IoCManager.Resolve(); + + var sEntities = IoCManager.Resolve(); var serverPlayerManager = server.ResolveDependency(); var innateActions = new List(); await server.WaitAssertion(() => { var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity; - var actionsComponent = IoCManager.Resolve().GetComponent(playerEnt!); + var actionsComponent = sEntities.GetComponent(playerEnt!.Value); // player should begin with their innate actions granted innateActions.AddRange(actionsComponent.InnateActions); @@ -99,7 +102,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs { var local = clientPlayerMgr.LocalPlayer; var controlled = local!.ControlledEntity; - var actionsComponent = IoCManager.Resolve().GetComponent(controlled!); + var actionsComponent = cEntities.GetComponent(controlled!); // we should have our innate actions and debug1. foreach (var innateAction in innateActions) @@ -123,14 +126,14 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs if (expectEmpty) { Assert.That(slot.HasAssignment, Is.False); - Assert.That(slot.Item, Is.Null); + Assert.That(slot.Item, Is.EqualTo(default)); Assert.That(slot.Action, Is.Null); Assert.That(slot.ActionEnabled, Is.False); continue; } Assert.That(slot.HasAssignment); // all the actions we gave so far are not tied to an item - Assert.That(slot.Item, Is.Null); + Assert.That(slot.Item, Is.EqualTo(default)); Assert.That(slot.Action, Is.Not.Null); Assert.That(slot.ActionEnabled); var asAction = slot.Action as ActionPrototype; @@ -154,7 +157,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs await server.WaitAssertion(() => { var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity; - var actionsComponent = IoCManager.Resolve().GetComponent(playerEnt!); + var actionsComponent = IoCManager.Resolve().GetComponent(playerEnt!.Value); actionsComponent.Revoke(ActionType.DebugInstant); }); @@ -189,7 +192,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs var expected = expectedOrder[idx++]; Assert.That(slot.HasAssignment); // all the actions we gave so far are not tied to an item - Assert.That(slot.Item, Is.Null); + Assert.That(slot.Item, Is.EqualTo(default)); Assert.That(slot.Action, Is.Not.Null); var asAction = slot.Action as ActionPrototype; Assert.That(asAction, Is.Not.Null); @@ -207,7 +210,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs else { Assert.That(slot.HasAssignment, Is.False); - Assert.That(slot.Item, Is.Null); + Assert.That(slot.Item, Is.EqualTo(default)); Assert.That(slot.Action, Is.Null); Assert.That(slot.ActionEnabled, Is.False); } @@ -232,6 +235,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs await server.WaitIdleAsync(); await client.WaitIdleAsync(); + var clientEntities = client.ResolveDependency(); + var serverPlayerManager = server.ResolveDependency(); var serverEntManager = server.ResolveDependency(); var serverGameTiming = server.ResolveDependency(); @@ -240,18 +245,18 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs ServerActionsComponent serverActionsComponent = null; ClientActionsComponent clientActionsComponent = null; - IEntity serverPlayerEnt = null; - IEntity serverFlashlight = null; + EntityUid serverPlayerEnt = default; + EntityUid serverFlashlight = default; await server.WaitAssertion(() => { - serverPlayerEnt = serverPlayerManager.Sessions.Single().AttachedEntity; - serverActionsComponent = IoCManager.Resolve().GetComponent(serverPlayerEnt!); + serverPlayerEnt = serverPlayerManager.Sessions.Single().AttachedEntity!.Value; + serverActionsComponent = serverEntManager.GetComponent(serverPlayerEnt); // spawn and give them an item that has actions serverFlashlight = serverEntManager.SpawnEntity("TestFlashlight", new EntityCoordinates(serverPlayerEnt, (0, 0))); - Assert.That(IoCManager.Resolve().TryGetComponent(serverFlashlight, out var itemActions)); + Assert.That(serverEntManager.TryGetComponent(serverFlashlight, out var itemActions)); // we expect this only to have a toggle light action initially var actionConfigs = itemActions.ActionConfigs.ToList(); Assert.That(actionConfigs.Count == 1); @@ -260,11 +265,11 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs // grant an extra item action, before pickup, initially disabled itemActions.GrantOrUpdate(ItemActionType.DebugToggle, false); - IoCManager.Resolve().GetComponent(serverPlayerEnt).PutInHand(IoCManager.Resolve().GetComponent(serverFlashlight), false); + serverEntManager.GetComponent(serverPlayerEnt).PutInHand(serverEntManager.GetComponent(serverFlashlight), false); // grant an extra item action, after pickup, with a cooldown itemActions.GrantOrUpdate(ItemActionType.DebugInstant, cooldown: cooldown); - Assert.That(serverActionsComponent.TryGetItemActionStates((EntityUid) serverFlashlight, out var state)); + Assert.That(serverActionsComponent.TryGetItemActionStates(serverFlashlight, out var state)); // they should have been granted all 3 actions Assert.That(state.Count == 3); Assert.That(state.TryGetValue(ItemActionType.ToggleLight, out var toggleLightState)); @@ -286,7 +291,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs { var local = clientPlayerMgr.LocalPlayer; var controlled = local!.ControlledEntity; - clientActionsComponent = IoCManager.Resolve().GetComponent(controlled!); + clientActionsComponent = clientEntities.GetComponent(controlled!); var lightEntry = clientActionsComponent.ItemActionStates() .Where(entry => entry.Value.ContainsKey(ItemActionType.ToggleLight)) @@ -334,8 +339,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs await server.WaitAssertion(() => { // drop the item, and the item actions should go away - IoCManager.Resolve().GetComponent(serverPlayerEnt) - .TryDropEntity(serverFlashlight, IoCManager.Resolve().GetComponent(serverPlayerEnt).Coordinates, false); + serverEntManager.GetComponent(serverPlayerEnt) + .TryDropEntity(serverFlashlight, serverEntManager.GetComponent(serverPlayerEnt).Coordinates, false); Assert.That(serverActionsComponent.ItemActionStates().ContainsKey(serverFlashlight), Is.False); }); @@ -352,7 +357,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs { // pick the item up again, the states should be back to what they were when dropped, // as the states "stick" with the item - IoCManager.Resolve().GetComponent(serverPlayerEnt).PutInHand(IoCManager.Resolve().GetComponent(serverFlashlight), false); + serverEntManager.GetComponent(serverPlayerEnt).PutInHand(serverEntManager.GetComponent(serverFlashlight), false); Assert.That(serverActionsComponent.ItemActionStates().TryGetValue(serverFlashlight, out var lightStates)); Assert.That(lightStates.TryGetValue(ItemActionType.ToggleLight, out var lightState)); Assert.That(lightState.Equals(new ActionState(true, toggledOn: true))); diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs b/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs index 3ccf1ca83b..663499941a 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/Mobs/AlertsComponentTests.cs @@ -31,7 +31,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs { var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity; Assert.NotNull(playerEnt); - var alertsComponent = IoCManager.Resolve().GetComponent(playerEnt); + var alertsComponent = IoCManager.Resolve().GetComponent(playerEnt!.Value); Assert.NotNull(alertsComponent); // show 2 alerts @@ -71,7 +71,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs { var playerEnt = serverPlayerManager.Sessions.Single().AttachedEntity; Assert.NotNull(playerEnt); - var alertsComponent = IoCManager.Resolve().GetComponent(playerEnt); + var alertsComponent = IoCManager.Resolve().GetComponent(playerEnt!.Value); Assert.NotNull(alertsComponent); alertsComponent.ClearAlert(AlertType.Debug1); diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs b/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs index 583db23cb5..83b7eb0275 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs @@ -37,8 +37,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var server = StartServer(options); - IEntity human; - IEntity table; + EntityUid human; + EntityUid table; ClimbingComponent climbing; server.Assert(() => @@ -54,19 +54,17 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement // Test for climb components existing // Players and tables should have these in their prototypes. - ref ClimbingComponent? comp = ref climbing!; - Assert.That(IoCManager.Resolve().TryGetComponent(human, out comp), "Human has no climbing"); - Assert.That(IoCManager.Resolve().TryGetComponent(table, out ClimbableComponent? _), "Table has no climbable"); + Assert.That(entityManager.TryGetComponent(human, out climbing), "Human has no climbing"); + Assert.That(entityManager.TryGetComponent(table, out ClimbableComponent? _), "Table has no climbable"); // Now let's make the player enter a climbing transitioning state. climbing.IsClimbing = true; climbing.TryMoveTo(IoCManager.Resolve().GetComponent(human).WorldPosition, IoCManager.Resolve().GetComponent(table).WorldPosition); - var body = IoCManager.Resolve().GetComponent(human); + var body = entityManager.GetComponent(human); // TODO: Check it's climbing // Force the player out of climb state. It should immediately remove the ClimbController. climbing.IsClimbing = false; - }); await server.WaitIdleAsync(); diff --git a/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs b/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs index 9ced1f20f6..69a3a97e7f 100644 --- a/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs +++ b/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using Content.Server.Gravity; using Content.Server.Gravity.EntitySystems; -using Content.Shared.Acts; using Content.Shared.Alert; using Content.Shared.Coordinates; using NUnit.Framework; @@ -44,7 +43,7 @@ namespace Content.IntegrationTests.Tests.Gravity var mapManager = server.ResolveDependency(); var entityManager = server.ResolveDependency(); - IEntity human = null; + EntityUid human = default; SharedAlertsComponent alerts = null; await server.WaitAssertion(() => diff --git a/Content.IntegrationTests/Tests/GravityGridTest.cs b/Content.IntegrationTests/Tests/GravityGridTest.cs index 6f3784826d..a88623551a 100644 --- a/Content.IntegrationTests/Tests/GravityGridTest.cs +++ b/Content.IntegrationTests/Tests/GravityGridTest.cs @@ -33,7 +33,7 @@ namespace Content.IntegrationTests.Tests var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var server = StartServer(options); - IEntity generator = null; + EntityUid generator = default; IMapGrid grid1 = null; IMapGrid grid2 = null; @@ -65,9 +65,8 @@ namespace Content.IntegrationTests.Tests Assert.That(generatorComponent.GravityActive, Is.True); - var entityMan = IoCManager.Resolve(); - var grid1Entity = entityMan.GetEntity(grid1.GridEntityId); - var grid2Entity = entityMan.GetEntity(grid2.GridEntityId); + var grid1Entity = grid1.GridEntityId; + var grid2Entity = grid2.GridEntityId; Assert.That(!IoCManager.Resolve().GetComponent(grid1Entity).Enabled); Assert.That(IoCManager.Resolve().GetComponent(grid2Entity).Enabled); @@ -83,8 +82,7 @@ namespace Content.IntegrationTests.Tests Assert.That(generatorComponent.GravityActive, Is.False); - var entityMan = IoCManager.Resolve(); - var grid2Entity = entityMan.GetEntity(grid2.GridEntityId); + var grid2Entity = grid2.GridEntityId; Assert.That(IoCManager.Resolve().GetComponent(grid2Entity).Enabled, Is.False); }); diff --git a/Content.IntegrationTests/Tests/GridTileLookupTest.cs b/Content.IntegrationTests/Tests/GridTileLookupTest.cs index da9c90f947..38d0f125be 100644 --- a/Content.IntegrationTests/Tests/GridTileLookupTest.cs +++ b/Content.IntegrationTests/Tests/GridTileLookupTest.cs @@ -32,7 +32,7 @@ namespace Content.IntegrationTests.Tests server.Assert(() => { - List entities; + List entities; var mapOne = mapManager.CreateMap(); var gridOne = mapManager.CreateGrid(mapOne); diff --git a/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs b/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs index 6e421e64ef..dd149f7659 100644 --- a/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs +++ b/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs @@ -61,10 +61,10 @@ namespace Content.IntegrationTests.Tests var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var server = StartServer(options); - IEntity human = null; - IEntity uniform = null; - IEntity idCard = null; - IEntity pocketItem = null; + EntityUid human = default; + EntityUid uniform = default; + EntityUid idCard = default; + EntityUid pocketItem = default; InventoryComponent inventory = null; server.Assert(() => @@ -121,7 +121,7 @@ namespace Content.IntegrationTests.Tests await server.WaitIdleAsync(); } - private static bool IsDescendant(IEntity descendant, IEntity parent) + private static bool IsDescendant(EntityUid descendant, EntityUid parent) { var tmpParent = IoCManager.Resolve().GetComponent(descendant).Parent; while (tmpParent != null) diff --git a/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs b/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs index b1a5e4288a..50f8b25c2d 100644 --- a/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs +++ b/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs @@ -49,7 +49,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click await server.WaitIdleAsync(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var mapId = MapId.Nullspace; @@ -61,16 +61,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click }); await server.WaitIdleAsync(); - IEntity user = null; - IEntity target = null; - IEntity item = null; + EntityUid user = default; + EntityUid target = default; + EntityUid item = default; server.Assert(() => { - user = entityManager.SpawnEntity(null, coords); + user = sEntities.SpawnEntity(null, coords); user.EnsureComponent().AddHand("hand", HandLocation.Left); - target = entityManager.SpawnEntity(null, coords); - item = entityManager.SpawnEntity(null, coords); + target = sEntities.SpawnEntity(null, coords); + item = sEntities.SpawnEntity(null, coords); item.EnsureComponent(); }); @@ -89,16 +89,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; }; testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; }; - interactionSystem.DoAttack(user, IoCManager.Resolve().GetComponent(target).Coordinates, false, target); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.DoAttack(user, sEntities.GetComponent(target).Coordinates, false, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(attack); Assert.That(interactUsing, Is.False); Assert.That(interactHand); - Assert.That(IoCManager.Resolve().TryGetComponent(user, out var hands)); - Assert.That(hands.PutInHand(IoCManager.Resolve().GetComponent(item))); + Assert.That(sEntities.TryGetComponent(user, out var hands)); + Assert.That(hands.PutInHand(sEntities.GetComponent(item))); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(interactUsing); }); @@ -119,7 +119,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click await server.WaitIdleAsync(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var mapId = MapId.Nullspace; @@ -131,19 +131,19 @@ namespace Content.IntegrationTests.Tests.Interaction.Click }); await server.WaitIdleAsync(); - IEntity user = null; - IEntity target = null; - IEntity item = null; - IEntity wall = null; + EntityUid user = default; + EntityUid target = default; + EntityUid item = default; + EntityUid wall = default; server.Assert(() => { - user = entityManager.SpawnEntity(null, coords); + user = sEntities.SpawnEntity(null, coords); user.EnsureComponent().AddHand("hand", HandLocation.Left); - target = entityManager.SpawnEntity(null, new MapCoordinates((1.9f, 0), mapId)); - item = entityManager.SpawnEntity(null, coords); + target = sEntities.SpawnEntity(null, new MapCoordinates((1.9f, 0), mapId)); + item = sEntities.SpawnEntity(null, coords); item.EnsureComponent(); - wall = entityManager.SpawnEntity("DummyDebugWall", new MapCoordinates((1, 0), IoCManager.Resolve().GetComponent(user).MapID)); + wall = sEntities.SpawnEntity("DummyDebugWall", new MapCoordinates((1, 0), sEntities.GetComponent(user).MapID)); }); await server.WaitRunTicks(1); @@ -161,16 +161,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; }; testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; }; - interactionSystem.DoAttack(user, IoCManager.Resolve().GetComponent(target).Coordinates, false, target); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.DoAttack(user, sEntities.GetComponent(target).Coordinates, false, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(attack, Is.False); Assert.That(interactUsing, Is.False); Assert.That(interactHand, Is.False); - Assert.That(IoCManager.Resolve().TryGetComponent(user, out var hands)); - Assert.That(hands.PutInHand(IoCManager.Resolve().GetComponent(item))); + Assert.That(sEntities.TryGetComponent(user, out var hands)); + Assert.That(hands.PutInHand(sEntities.GetComponent(item))); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(interactUsing, Is.False); }); @@ -190,7 +190,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click await server.WaitIdleAsync(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var mapId = MapId.Nullspace; @@ -202,16 +202,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click }); await server.WaitIdleAsync(); - IEntity user = null; - IEntity target = null; - IEntity item = null; + EntityUid user = default; + EntityUid target = default; + EntityUid item = default; server.Assert(() => { - user = entityManager.SpawnEntity(null, coords); + user = sEntities.SpawnEntity(null, coords); user.EnsureComponent().AddHand("hand", HandLocation.Left); - target = entityManager.SpawnEntity(null, new MapCoordinates((InteractionSystem.InteractionRange - 0.1f, 0), mapId)); - item = entityManager.SpawnEntity(null, coords); + target = sEntities.SpawnEntity(null, new MapCoordinates((InteractionSystem.InteractionRange - 0.1f, 0), mapId)); + item = sEntities.SpawnEntity(null, coords); item.EnsureComponent(); }); @@ -230,16 +230,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; }; testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; }; - interactionSystem.DoAttack(user, IoCManager.Resolve().GetComponent(target).Coordinates, false, target); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.DoAttack(user, sEntities.GetComponent(target).Coordinates, false, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(attack); Assert.That(interactUsing, Is.False); Assert.That(interactHand); - Assert.That(IoCManager.Resolve().TryGetComponent(user, out var hands)); - Assert.That(hands.PutInHand(IoCManager.Resolve().GetComponent(item))); + Assert.That(sEntities.TryGetComponent(user, out var hands)); + Assert.That(hands.PutInHand(sEntities.GetComponent(item))); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(interactUsing); }); @@ -260,7 +260,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click await server.WaitIdleAsync(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var mapId = MapId.Nullspace; @@ -272,16 +272,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click }); await server.WaitIdleAsync(); - IEntity user = null; - IEntity target = null; - IEntity item = null; + EntityUid user = default; + EntityUid target = default; + EntityUid item = default; server.Assert(() => { - user = entityManager.SpawnEntity(null, coords); + user = sEntities.SpawnEntity(null, coords); user.EnsureComponent().AddHand("hand", HandLocation.Left); - target = entityManager.SpawnEntity(null, new MapCoordinates((InteractionSystem.InteractionRange, 0), mapId)); - item = entityManager.SpawnEntity(null, coords); + target = sEntities.SpawnEntity(null, new MapCoordinates((InteractionSystem.InteractionRange, 0), mapId)); + item = sEntities.SpawnEntity(null, coords); item.EnsureComponent(); }); @@ -300,16 +300,16 @@ namespace Content.IntegrationTests.Tests.Interaction.Click testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; }; testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; }; - interactionSystem.DoAttack(user, IoCManager.Resolve().GetComponent(target).Coordinates, false, target); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.DoAttack(user, sEntities.GetComponent(target).Coordinates, false, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(attack, Is.False); Assert.That(interactUsing, Is.False); Assert.That(interactHand, Is.False); - Assert.That(IoCManager.Resolve().TryGetComponent(user, out var hands)); - Assert.That(hands.PutInHand(IoCManager.Resolve().GetComponent(item))); + Assert.That(sEntities.TryGetComponent(user, out var hands)); + Assert.That(hands.PutInHand(sEntities.GetComponent(item))); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(interactUsing, Is.False); }); @@ -330,7 +330,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click await server.WaitIdleAsync(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var mapId = MapId.Nullspace; @@ -342,21 +342,21 @@ namespace Content.IntegrationTests.Tests.Interaction.Click }); await server.WaitIdleAsync(); - IEntity user = null; - IEntity target = null; - IEntity item = null; - IEntity containerEntity = null; + EntityUid user = default; + EntityUid target = default; + EntityUid item = default; + EntityUid containerEntity = default; IContainer container = null; server.Assert(() => { - user = entityManager.SpawnEntity(null, coords); + user = sEntities.SpawnEntity(null, coords); user.EnsureComponent().AddHand("hand", HandLocation.Left); - target = entityManager.SpawnEntity(null, coords); - item = entityManager.SpawnEntity(null, coords); + target = sEntities.SpawnEntity(null, coords); + item = sEntities.SpawnEntity(null, coords); item.EnsureComponent(); - containerEntity = entityManager.SpawnEntity(null, coords); - container = ContainerHelpers.EnsureContainer(containerEntity, "InteractionTestContainer"); + containerEntity = sEntities.SpawnEntity(null, coords); + container = containerEntity.EnsureContainer("InteractionTestContainer"); }); await server.WaitRunTicks(1); @@ -373,31 +373,31 @@ namespace Content.IntegrationTests.Tests.Interaction.Click server.Assert(() => { Assert.That(container.Insert(user)); - Assert.That(IoCManager.Resolve().GetComponent(user).Parent.Owner, Is.EqualTo(containerEntity)); + Assert.That(sEntities.GetComponent(user).Parent.Owner, Is.EqualTo(containerEntity)); testInteractionSystem.AttackEvent = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); attack = true; }; testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactUsing = true; }; testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactHand = true; }; - interactionSystem.DoAttack(user, IoCManager.Resolve().GetComponent(target).Coordinates, false, target); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.DoAttack(user, sEntities.GetComponent(target).Coordinates, false, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(attack, Is.False); Assert.That(interactUsing, Is.False); Assert.That(interactHand, Is.False); - interactionSystem.DoAttack(user, IoCManager.Resolve().GetComponent(containerEntity).Coordinates, false, containerEntity); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(containerEntity).Coordinates, containerEntity); + interactionSystem.DoAttack(user, sEntities.GetComponent(containerEntity).Coordinates, false, containerEntity); + interactionSystem.UserInteraction(user, sEntities.GetComponent(containerEntity).Coordinates, containerEntity); Assert.That(attack); Assert.That(interactUsing, Is.False); Assert.That(interactHand); - Assert.That(IoCManager.Resolve().TryGetComponent(user, out var hands)); - Assert.That(hands.PutInHand(IoCManager.Resolve().GetComponent(item))); + Assert.That(sEntities.TryGetComponent(user, out var hands)); + Assert.That(hands.PutInHand(sEntities.GetComponent(item))); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(target).Coordinates, target); + interactionSystem.UserInteraction(user, sEntities.GetComponent(target).Coordinates, target); Assert.That(interactUsing, Is.False); - interactionSystem.UserInteraction(user, IoCManager.Resolve().GetComponent(containerEntity).Coordinates, containerEntity); + interactionSystem.UserInteraction(user, sEntities.GetComponent(containerEntity).Coordinates, containerEntity); Assert.That(interactUsing, Is.True); }); diff --git a/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs b/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs index 4cb57aa744..b56deeb030 100644 --- a/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs +++ b/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs @@ -34,11 +34,11 @@ namespace Content.IntegrationTests.Tests.Interaction await server.WaitIdleAsync(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var mapManager = server.ResolveDependency(); - IEntity origin = null; - IEntity other = null; + EntityUid origin = default; + EntityUid other = default; IContainer container = null; IComponent component = null; EntityCoordinates entityCoordinates = default; @@ -49,12 +49,12 @@ namespace Content.IntegrationTests.Tests.Interaction var mapId = mapManager.CreateMap(); var coordinates = new MapCoordinates(Vector2.Zero, mapId); - origin = entityManager.SpawnEntity(HumanId, coordinates); - other = entityManager.SpawnEntity(HumanId, coordinates); - container = ContainerHelpers.EnsureContainer(other, "InRangeUnobstructedTestOtherContainer"); - component = IoCManager.Resolve().GetComponent(other); - entityCoordinates = IoCManager.Resolve().GetComponent(other).Coordinates; - mapCoordinates = IoCManager.Resolve().GetComponent(other).MapPosition; + origin = sEntities.SpawnEntity(HumanId, coordinates); + other = sEntities.SpawnEntity(HumanId, coordinates); + container = other.EnsureContainer("InRangeUnobstructedTestOtherContainer"); + component = sEntities.GetComponent(other); + entityCoordinates = sEntities.GetComponent(other).Coordinates; + mapCoordinates = sEntities.GetComponent(other).MapPosition; }); await server.WaitIdleAsync(); diff --git a/Content.IntegrationTests/Tests/InventoryHelpersTest.cs b/Content.IntegrationTests/Tests/InventoryHelpersTest.cs index a952a8c0d1..33f8447522 100644 --- a/Content.IntegrationTests/Tests/InventoryHelpersTest.cs +++ b/Content.IntegrationTests/Tests/InventoryHelpersTest.cs @@ -8,7 +8,6 @@ using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Prototypes; using static Content.Shared.Inventory.EquipmentSlotDefines; namespace Content.IntegrationTests.Tests @@ -50,19 +49,21 @@ namespace Content.IntegrationTests.Tests var options = new ServerIntegrationOptions {ExtraPrototypes = Prototypes}; var server = StartServer(options); - IEntity human = null; + await server.WaitIdleAsync(); + + var sEntities = server.ResolveDependency(); + + EntityUid human = default; InventoryComponent inventory = null; - server.Assert(() => + await server.WaitAssertion(() => { var mapMan = IoCManager.Resolve(); mapMan.CreateNewMapEntity(MapId.Nullspace); - var entityMan = IoCManager.Resolve(); - - human = entityMan.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace); - inventory = IoCManager.Resolve().GetComponent(human); + human = sEntities.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace); + inventory = sEntities.GetComponent(human); // Can't do the test if this human doesn't have the slots for it. Assert.That(inventory.HasSlot(Slots.INNERCLOTHING)); @@ -72,7 +73,10 @@ namespace Content.IntegrationTests.Tests // Do we actually have the uniform equipped? Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform)); - Assert.That(IoCManager.Resolve().GetComponent(uniform.Owner).EntityPrototype != null && IoCManager.Resolve().GetComponent(uniform.Owner).EntityPrototype.ID == "InventoryJumpsuitJanitorDummy"); + Assert.That(sEntities.GetComponent(uniform.Owner).EntityPrototype is + { + ID: "InventoryJumpsuitJanitorDummy" + }); EntitySystem.Get().TryStun(human, TimeSpan.FromSeconds(1f)); @@ -85,10 +89,11 @@ namespace Content.IntegrationTests.Tests // Let's try skipping the interaction check and see if it equips it! Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy")); Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent id)); - Assert.That(IoCManager.Resolve().GetComponent(id.Owner).EntityPrototype != null && IoCManager.Resolve().GetComponent(id.Owner).EntityPrototype.ID == "InventoryIDCardDummy"); + Assert.That(sEntities.GetComponent(id.Owner).EntityPrototype is + { + ID: "InventoryIDCardDummy" + }); }); - - await server.WaitIdleAsync(); } } } diff --git a/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs b/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs index 0c644afaf4..4498f0b34e 100644 --- a/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs +++ b/Content.IntegrationTests/Tests/MindEntityDeletionTest.cs @@ -20,8 +20,8 @@ namespace Content.IntegrationTests.Tests { var (_, server) = await StartConnectedServerDummyTickerClientPair(); - IEntity playerEnt = null; - IEntity visitEnt = null; + EntityUid playerEnt = default; + EntityUid visitEnt = default; Mind mind = null; server.Assert(() => { @@ -49,12 +49,12 @@ namespace Content.IntegrationTests.Tests server.Assert(() => { - IoCManager.Resolve().DeleteEntity((EntityUid) visitEnt); + IoCManager.Resolve().DeleteEntity(visitEnt); - Assert.That(mind.VisitingEntity, Is.Null); + Assert.That(mind.VisitingEntity, Is.EqualTo(default)); // This used to throw so make sure it doesn't. - IoCManager.Resolve().DeleteEntity((EntityUid) playerEnt); + IoCManager.Resolve().DeleteEntity(playerEnt); }); await server.WaitIdleAsync(); @@ -66,7 +66,7 @@ namespace Content.IntegrationTests.Tests // Has to be a non-dummy ticker so we have a proper map. var (_, server) = await StartConnectedServerClientPair(); - IEntity playerEnt = null; + EntityUid playerEnt = default; Mind mind = null; server.Assert(() => { @@ -110,7 +110,7 @@ namespace Content.IntegrationTests.Tests // Has to be a non-dummy ticker so we have a proper map. var (_, server) = await StartConnectedServerClientPair(); - IEntity playerEnt = null; + EntityUid playerEnt = default; Mind mind = null; MapId map = default; server.Assert(() => diff --git a/Content.IntegrationTests/Tests/Networking/ConnectTest.cs b/Content.IntegrationTests/Tests/Networking/ConnectTest.cs index 4c3bb935fb..ced087aa57 100644 --- a/Content.IntegrationTests/Tests/Networking/ConnectTest.cs +++ b/Content.IntegrationTests/Tests/Networking/ConnectTest.cs @@ -55,8 +55,7 @@ namespace Content.IntegrationTests.Tests.Networking var clEntityManager = client.ResolveDependency(); var svEntityManager = server.ResolveDependency(); - IEntity tempQualifier = svEntityManager.GetEntities().Last(); - var lastSvEntity = (EntityUid) tempQualifier; + var lastSvEntity = svEntityManager.GetEntities().Last(); Assert.That(clEntityManager.GetComponent(lastSvEntity).Coordinates, Is.EqualTo(svEntityManager.GetComponent(lastSvEntity).Coordinates)); diff --git a/Content.IntegrationTests/Tests/Networking/SimplePredictReconcileTest.cs b/Content.IntegrationTests/Tests/Networking/SimplePredictReconcileTest.cs index 2c7c1aa2fe..9a31a29f44 100644 --- a/Content.IntegrationTests/Tests/Networking/SimplePredictReconcileTest.cs +++ b/Content.IntegrationTests/Tests/Networking/SimplePredictReconcileTest.cs @@ -12,7 +12,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Players; using Robust.Shared.Reflection; using Robust.Shared.Serialization; using Robust.Shared.Timing; @@ -77,7 +76,7 @@ namespace Content.IntegrationTests.Tests.Networking var cGameTiming = client.ResolveDependency(); var cGameStateManager = client.ResolveDependency(); - IEntity serverEnt = default!; + EntityUid serverEnt = default; PredictionTestComponent serverComponent = default!; PredictionTestComponent clientComponent = default!; @@ -112,8 +111,7 @@ namespace Content.IntegrationTests.Tests.Networking await client.WaitPost(() => { - IEntity tempQualifier = cEntityManager.GetEntity(serverEnt); - clientComponent = IoCManager.Resolve().GetComponent(tempQualifier); + clientComponent = cEntityManager.GetComponent(serverEnt); }); Assert.That(clientComponent.Foo, Is.False); @@ -456,8 +454,7 @@ namespace Content.IntegrationTests.Tests.Networking private void HandleMessage(SetFooMessage message, EntitySessionEventArgs args) { - var entity = EntityManager.GetEntity(message.Uid); - var component = IoCManager.Resolve().GetComponent(entity); + var component = IoCManager.Resolve().GetComponent(message.Uid); var old = component.Foo; if (Allow) { diff --git a/Content.IntegrationTests/Tests/PDA/PDAExtensionsTests.cs b/Content.IntegrationTests/Tests/PDA/PDAExtensionsTests.cs index a9a6db0289..57653a63d9 100644 --- a/Content.IntegrationTests/Tests/PDA/PDAExtensionsTests.cs +++ b/Content.IntegrationTests/Tests/PDA/PDAExtensionsTests.cs @@ -9,7 +9,6 @@ using Content.Shared.Containers.ItemSlots; using NUnit.Framework; using Robust.Server.Player; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.IntegrationTests.Tests.PDA { @@ -60,7 +59,7 @@ namespace Content.IntegrationTests.Tests.PDA await server.WaitAssertion(() => { - var player = sPlayerManager.Sessions.Single().AttachedEntity; + var player = sPlayerManager.Sessions.Single().AttachedEntity!.Value; Assert.NotNull(player); @@ -70,14 +69,14 @@ namespace Content.IntegrationTests.Tests.PDA Assert.NotNull(id); // Put PDA in hand - var dummyPda = sEntityManager.SpawnEntity(PdaDummy, IoCManager.Resolve().GetComponent(player).MapPosition); - var pdaItemComponent = IoCManager.Resolve().GetComponent(dummyPda); - IoCManager.Resolve().GetComponent(player).PutInHand(pdaItemComponent); + var dummyPda = sEntityManager.SpawnEntity(PdaDummy, sEntityManager.GetComponent(player).MapPosition); + var pdaItemComponent = sEntityManager.GetComponent(dummyPda); + sEntityManager.GetComponent(player).PutInHand(pdaItemComponent); - var pdaComponent = IoCManager.Resolve().GetComponent(dummyPda); - var pdaIdCard = sEntityManager.SpawnEntity(IdCardDummy, IoCManager.Resolve().GetComponent(player).MapPosition); + var pdaComponent = sEntityManager.GetComponent(dummyPda); + var pdaIdCard = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent(player).MapPosition); - var itemSlots = IoCManager.Resolve().GetComponent(dummyPda); + var itemSlots = sEntityManager.GetComponent(dummyPda); sEntityManager.EntitySysManager.GetEntitySystem() .TryInsert(dummyPda, pdaComponent.IdSlot, pdaIdCard); var pdaContainedId = pdaComponent.ContainedID; @@ -90,11 +89,11 @@ namespace Content.IntegrationTests.Tests.PDA Assert.That(id, Is.EqualTo(pdaContainedId)); // Put ID card in hand - var idDummy = sEntityManager.SpawnEntity(IdCardDummy, IoCManager.Resolve().GetComponent(player).MapPosition); - var idItemComponent = IoCManager.Resolve().GetComponent(idDummy); - IoCManager.Resolve().GetComponent(player).PutInHand(idItemComponent); + var idDummy = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent(player).MapPosition); + var idItemComponent = sEntityManager.GetComponent(idDummy); + sEntityManager.GetComponent(player).PutInHand(idItemComponent); - var idCardComponent = IoCManager.Resolve().GetComponent(idDummy); + var idCardComponent = sEntityManager.GetComponent(idDummy); // The ID in the hand should be found first Assert.NotNull(player.GetHeldId()); @@ -103,7 +102,7 @@ namespace Content.IntegrationTests.Tests.PDA Assert.That(id, Is.EqualTo(idCardComponent)); // Remove all IDs and PDAs - var inventory = IoCManager.Resolve().GetComponent(player); + var inventory = sEntityManager.GetComponent(player); foreach (var slot in inventory.Slots) { @@ -114,13 +113,13 @@ namespace Content.IntegrationTests.Tests.PDA continue; } - if (IoCManager.Resolve().HasComponent(item.Owner)) + if (sEntityManager.HasComponent(item.Owner)) { inventory.ForceUnequip(slot); } } - var hands = IoCManager.Resolve().GetComponent(player); + var hands = sEntityManager.GetComponent(player); hands.Drop(dummyPda, false); hands.Drop(idDummy, false); diff --git a/Content.IntegrationTests/Tests/SaveLoadMapTest.cs b/Content.IntegrationTests/Tests/SaveLoadMapTest.cs index 4ca9802ba9..e4d2096ce1 100644 --- a/Content.IntegrationTests/Tests/SaveLoadMapTest.cs +++ b/Content.IntegrationTests/Tests/SaveLoadMapTest.cs @@ -3,7 +3,6 @@ using NUnit.Framework; using Robust.Server.Maps; using Robust.Shared.ContentPack; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -26,7 +25,7 @@ namespace Content.IntegrationTests.Tests await server.WaitIdleAsync(); var mapLoader = server.ResolveDependency(); var mapManager = server.ResolveDependency(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); var resManager = server.ResolveDependency(); server.Post(() => @@ -39,14 +38,14 @@ namespace Content.IntegrationTests.Tests { var mapGrid = mapManager.CreateGrid(mapId); - var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId); - IoCManager.Resolve().GetComponent(mapGridEnt).WorldPosition = new Vector2(10, 10); + var mapGridEnt = mapGrid.GridEntityId; + sEntities.GetComponent(mapGridEnt).WorldPosition = new Vector2(10, 10); mapGrid.SetTile(new Vector2i(0,0), new Tile(1, 512)); } { var mapGrid = mapManager.CreateGrid(mapId); - var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId); - IoCManager.Resolve().GetComponent(mapGridEnt).WorldPosition = new Vector2(-8, -8); + var mapGridEnt = mapGrid.GridEntityId; + sEntities.GetComponent(mapGridEnt).WorldPosition = new Vector2(-8, -8); mapGrid.SetTile(new Vector2i(0, 0), new Tile(2, 511)); } diff --git a/Content.IntegrationTests/Tests/ShuttleTest.cs b/Content.IntegrationTests/Tests/ShuttleTest.cs index eb939bd8e9..fc59763bd1 100644 --- a/Content.IntegrationTests/Tests/ShuttleTest.cs +++ b/Content.IntegrationTests/Tests/ShuttleTest.cs @@ -1,10 +1,8 @@ #nullable enable using System.Threading.Tasks; -using Content.Server.Shuttles; using Content.Server.Shuttles.Components; using NUnit.Framework; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; @@ -21,30 +19,29 @@ namespace Content.IntegrationTests.Tests await server.WaitIdleAsync(); - var entMan = server.ResolveDependency(); var mapMan = server.ResolveDependency(); - IEntity? gridEnt = null; + var sEntities = server.ResolveDependency(); + + EntityUid gridEnt = default; await server.WaitAssertion(() => { var mapId = mapMan.CreateMap(); var grid = mapMan.CreateGrid(mapId); - gridEnt = entMan.GetEntity(grid.GridEntityId); + gridEnt = grid.GridEntityId; - Assert.That(IoCManager.Resolve().TryGetComponent(gridEnt, out ShuttleComponent? shuttleComponent)); - Assert.That(IoCManager.Resolve().TryGetComponent(gridEnt, out PhysicsComponent? physicsComponent)); + Assert.That(sEntities.TryGetComponent(gridEnt, out ShuttleComponent? shuttleComponent)); + Assert.That(sEntities.TryGetComponent(gridEnt, out PhysicsComponent? physicsComponent)); Assert.That(physicsComponent!.BodyType, Is.EqualTo(BodyType.Dynamic)); - Assert.That(IoCManager.Resolve().GetComponent(gridEnt).LocalPosition, Is.EqualTo(Vector2.Zero)); + Assert.That(sEntities.GetComponent(gridEnt).LocalPosition, Is.EqualTo(Vector2.Zero)); physicsComponent.ApplyLinearImpulse(Vector2.One); }); - // TODO: Should have tests that collision + rendertree + pointlights work on a moved grid but I'll deal with that - // when we get rotations. await server.WaitRunTicks(1); await server.WaitAssertion(() => { - Assert.That((gridEnt != null ? IoCManager.Resolve().GetComponent(gridEnt) : null).LocalPosition, Is.Not.EqualTo(Vector2.Zero)); + Assert.That(sEntities.GetComponent(gridEnt).LocalPosition, Is.Not.EqualTo(Vector2.Zero)); }); } } diff --git a/Content.IntegrationTests/Tests/Tag/TagTest.cs b/Content.IntegrationTests/Tests/Tag/TagTest.cs index 51de1b767e..db27cad716 100644 --- a/Content.IntegrationTests/Tests/Tag/TagTest.cs +++ b/Content.IntegrationTests/Tests/Tag/TagTest.cs @@ -54,7 +54,7 @@ namespace Content.IntegrationTests.Tests.Tag var sEntityManager = server.ResolveDependency(); var sPrototypeManager = server.ResolveDependency(); - IEntity sTagDummy = null!; + EntityUid sTagDummy = default; TagComponent sTagComponent = null!; await server.WaitPost(() => diff --git a/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs b/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs index 9e9dabd26a..290df1a1d2 100644 --- a/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs +++ b/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs @@ -46,7 +46,7 @@ namespace Content.IntegrationTests.Tests.Utility await server.WaitAssertion(() => { var grid = GetMainGrid(sMapManager); - var gridEnt = sEntityManager.GetEntity(grid.GridEntityId); + var gridEnt = grid.GridEntityId; var gridPos = IoCManager.Resolve().GetComponent(gridEnt).WorldPosition; var entityCoordinates = GetMainEntityCoordinates(sMapManager); diff --git a/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs b/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs index d15e392c34..c8d71f51f0 100644 --- a/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs +++ b/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs @@ -4,7 +4,6 @@ using Content.Shared.Containers.ItemSlots; using Content.Shared.Whitelist; using NUnit.Framework; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; namespace Content.IntegrationTests.Tests.Utility @@ -66,22 +65,18 @@ namespace Content.IntegrationTests.Tests.Utility await server.WaitIdleAsync(); var mapManager = server.ResolveDependency(); - var entityManager = server.ResolveDependency(); + var sEntities = server.ResolveDependency(); await server.WaitAssertion(() => { var mapId = GetMainMapId(mapManager); var mapCoordinates = new MapCoordinates(0, 0, mapId); - IEntity tempQualifier = entityManager.SpawnEntity("ValidComponentDummy", mapCoordinates); - var validComponent = (EntityUid) tempQualifier; - IEntity tempQualifier1 = entityManager.SpawnEntity("ValidTagDummy", mapCoordinates); - var validTag = (EntityUid) tempQualifier1; + var validComponent = sEntities.SpawnEntity("ValidComponentDummy", mapCoordinates); + var validTag = sEntities.SpawnEntity("ValidTagDummy", mapCoordinates); - IEntity tempQualifier2 = entityManager.SpawnEntity("InvalidComponentDummy", mapCoordinates); - var invalidComponent = (EntityUid) tempQualifier2; - IEntity tempQualifier3 = entityManager.SpawnEntity("InvalidTagDummy", mapCoordinates); - var invalidTag = (EntityUid) tempQualifier3; + var invalidComponent = sEntities.SpawnEntity("InvalidComponentDummy", mapCoordinates); + var invalidTag = sEntities.SpawnEntity("InvalidTagDummy", mapCoordinates); // Test instantiated on its own var whitelistInst = new EntityWhitelist @@ -102,8 +97,8 @@ namespace Content.IntegrationTests.Tests.Utility Assert.That(whitelistInst.IsValid(invalidTag), Is.False); // Test from serialized - var dummy = entityManager.SpawnEntity("WhitelistDummy", mapCoordinates); - var whitelistSer = IoCManager.Resolve().GetComponent(dummy).Slots.Values.First().Whitelist; + var dummy = sEntities.SpawnEntity("WhitelistDummy", mapCoordinates); + var whitelistSer = sEntities.GetComponent(dummy).Slots.Values.First().Whitelist; Assert.That(whitelistSer, Is.Not.Null); Assert.That(whitelistSer.Components, Is.Not.Null); diff --git a/Content.Server/AI/Commands/AddAiCommand.cs b/Content.Server/AI/Commands/AddAiCommand.cs index 8fb5a74fe9..694ee57f62 100644 --- a/Content.Server/AI/Commands/AddAiCommand.cs +++ b/Content.Server/AI/Commands/AddAiCommand.cs @@ -13,6 +13,8 @@ namespace Content.Server.AI.Commands [AdminCommand(AdminFlags.Fun)] public class AddAiCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "addai"; public string Description => "Add an ai component with a given processor to an entity."; public string Help => "Usage: addai ..." @@ -29,25 +31,25 @@ namespace Content.Server.AI.Commands var entId = new EntityUid(int.Parse(args[0])); - if (!IoCManager.Resolve().TryGetEntity(entId, out var ent)) + if (!_entities.EntityExists(entId)) { shell.WriteLine($"Unable to find entity with uid {entId}"); return; } - if (IoCManager.Resolve().HasComponent(ent)) + if (_entities.HasComponent(entId)) { shell.WriteLine("Entity already has an AI component."); return; } // TODO: IMover refffaaccctttooorrr - if (IoCManager.Resolve().HasComponent(ent)) + if (_entities.HasComponent(entId)) { - IoCManager.Resolve().RemoveComponent(ent); + _entities.RemoveComponent(entId); } - var comp = IoCManager.Resolve().AddComponent(ent); + var comp = _entities.AddComponent(entId); var behaviorManager = IoCManager.Resolve(); for (var i = 1; i < args.Length; i++) diff --git a/Content.Server/AI/EntitySystems/AiFactionTagSystem.cs b/Content.Server/AI/EntitySystems/AiFactionTagSystem.cs index adf2a0d2c5..0b590484be 100644 --- a/Content.Server/AI/EntitySystems/AiFactionTagSystem.cs +++ b/Content.Server/AI/EntitySystems/AiFactionTagSystem.cs @@ -54,12 +54,12 @@ namespace Content.Server.AI.EntitySystems public Faction GetHostileFactions(Faction faction) => _hostileFactions.TryGetValue(faction, out var hostiles) ? hostiles : Faction.None; - public Faction GetFactions(IEntity entity) => + public Faction GetFactions(EntityUid entity) => IoCManager.Resolve().TryGetComponent(entity, out AiFactionTagComponent? factionTags) ? factionTags.Factions : Faction.None; - public IEnumerable GetNearbyHostiles(IEntity entity, float range) + public IEnumerable GetNearbyHostiles(EntityUid entity, float range) { var ourFaction = GetFactions(entity); var hostile = GetHostileFactions(ourFaction); diff --git a/Content.Server/AI/Operators/Combat/Melee/SwingMeleeWeaponOperator.cs b/Content.Server/AI/Operators/Combat/Melee/SwingMeleeWeaponOperator.cs index 89c5186d23..9454697001 100644 --- a/Content.Server/AI/Operators/Combat/Melee/SwingMeleeWeaponOperator.cs +++ b/Content.Server/AI/Operators/Combat/Melee/SwingMeleeWeaponOperator.cs @@ -12,10 +12,10 @@ namespace Content.Server.AI.Operators.Combat.Melee private readonly float _burstTime; private float _elapsedTime; - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; - public SwingMeleeWeaponOperator(IEntity owner, IEntity target, float burstTime = 1.0f) + public SwingMeleeWeaponOperator(EntityUid owner, EntityUid target, float burstTime = 1.0f) { _owner = owner; _target = target; diff --git a/Content.Server/AI/Operators/Combat/Melee/UnarmedCombatOperator.cs b/Content.Server/AI/Operators/Combat/Melee/UnarmedCombatOperator.cs index d08aee2254..c02ec75f5f 100644 --- a/Content.Server/AI/Operators/Combat/Melee/UnarmedCombatOperator.cs +++ b/Content.Server/AI/Operators/Combat/Melee/UnarmedCombatOperator.cs @@ -11,11 +11,11 @@ namespace Content.Server.AI.Operators.Combat.Melee private readonly float _burstTime; private float _elapsedTime; - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; private UnarmedCombatComponent? _unarmedCombat; - public UnarmedCombatOperator(IEntity owner, IEntity target, float burstTime = 1.0f) + public UnarmedCombatOperator(EntityUid owner, EntityUid target, float burstTime = 1.0f) { _owner = owner; _target = target; diff --git a/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs b/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs index 2cb31f716c..5812ba66d7 100644 --- a/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs +++ b/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs @@ -14,10 +14,10 @@ namespace Content.Server.AI.Operators.Inventory /// public sealed class CloseLastStorageOperator : AiOperator { - private readonly IEntity _owner; - private IEntity? _target; + private readonly EntityUid _owner; + private EntityUid _target; - public CloseLastStorageOperator(IEntity owner) + public CloseLastStorageOperator(EntityUid owner) { _owner = owner; } @@ -38,7 +38,7 @@ namespace Content.Server.AI.Operators.Inventory _target = blackboard.GetState().GetValue(); - return _target != null; + return _target != default; } public override bool Shutdown(Outcome outcome) @@ -48,13 +48,13 @@ namespace Content.Server.AI.Operators.Inventory var blackboard = UtilityAiHelpers.GetBlackboard(_owner); - blackboard?.GetState().SetValue(null); + blackboard?.GetState().SetValue(default); return true; } public override Outcome Execute(float frameTime) { - if (_target == null || !_owner.InRangeUnobstructed(_target, popup: true)) + if (_target == default || !_owner.InRangeUnobstructed(_target, popup: true)) { return Outcome.Failed; } diff --git a/Content.Server/AI/Operators/Inventory/DropEntityOperator.cs b/Content.Server/AI/Operators/Inventory/DropEntityOperator.cs index c123bcd28a..952bc6b46b 100644 --- a/Content.Server/AI/Operators/Inventory/DropEntityOperator.cs +++ b/Content.Server/AI/Operators/Inventory/DropEntityOperator.cs @@ -6,9 +6,9 @@ namespace Content.Server.AI.Operators.Inventory { public class DropEntityOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _entity; - public DropEntityOperator(IEntity owner, IEntity entity) + private readonly EntityUid _owner; + private readonly EntityUid _entity; + public DropEntityOperator(EntityUid owner, EntityUid entity) { _owner = owner; _entity = entity; diff --git a/Content.Server/AI/Operators/Inventory/DropHandItemsOperator.cs b/Content.Server/AI/Operators/Inventory/DropHandItemsOperator.cs index e35b11bd57..81908858f5 100644 --- a/Content.Server/AI/Operators/Inventory/DropHandItemsOperator.cs +++ b/Content.Server/AI/Operators/Inventory/DropHandItemsOperator.cs @@ -6,9 +6,9 @@ namespace Content.Server.AI.Operators.Inventory { public class DropHandItemsOperator : AiOperator { - private readonly IEntity _owner; + private readonly EntityUid _owner; - public DropHandItemsOperator(IEntity owner) + public DropHandItemsOperator(EntityUid owner) { _owner = owner; } diff --git a/Content.Server/AI/Operators/Inventory/EquipEntityOperator.cs b/Content.Server/AI/Operators/Inventory/EquipEntityOperator.cs index 0c1e3ee9a2..e2f3ae82fa 100644 --- a/Content.Server/AI/Operators/Inventory/EquipEntityOperator.cs +++ b/Content.Server/AI/Operators/Inventory/EquipEntityOperator.cs @@ -6,9 +6,9 @@ namespace Content.Server.AI.Operators.Inventory { public sealed class EquipEntityOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _entity; - public EquipEntityOperator(IEntity owner, IEntity entity) + private readonly EntityUid _owner; + private readonly EntityUid _entity; + public EquipEntityOperator(EntityUid owner, EntityUid entity) { _owner = owner; _entity = entity; diff --git a/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs b/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs index d7603b8f3b..746c8510af 100644 --- a/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs +++ b/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs @@ -11,10 +11,10 @@ namespace Content.Server.AI.Operators.Inventory /// public class InteractWithEntityOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _useTarget; + private readonly EntityUid _owner; + private readonly EntityUid _useTarget; - public InteractWithEntityOperator(IEntity owner, IEntity useTarget) + public InteractWithEntityOperator(EntityUid owner, EntityUid useTarget) { _owner = owner; _useTarget = useTarget; diff --git a/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs b/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs index 5c3b0e7895..fbd207ae7e 100644 --- a/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs +++ b/Content.Server/AI/Operators/Inventory/OpenStorageOperator.cs @@ -14,10 +14,10 @@ namespace Content.Server.AI.Operators.Inventory /// public sealed class OpenStorageOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; - public OpenStorageOperator(IEntity owner, IEntity target) + public OpenStorageOperator(EntityUid owner, EntityUid target) { _owner = owner; _target = target; diff --git a/Content.Server/AI/Operators/Inventory/PickupEntityOperator.cs b/Content.Server/AI/Operators/Inventory/PickupEntityOperator.cs index 6c545b3d95..4dfb9cc588 100644 --- a/Content.Server/AI/Operators/Inventory/PickupEntityOperator.cs +++ b/Content.Server/AI/Operators/Inventory/PickupEntityOperator.cs @@ -11,10 +11,10 @@ namespace Content.Server.AI.Operators.Inventory public class PickupEntityOperator : AiOperator { // Input variables - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; - public PickupEntityOperator(IEntity owner, IEntity target) + public PickupEntityOperator(EntityUid owner, EntityUid target) { _owner = owner; _target = target; diff --git a/Content.Server/AI/Operators/Inventory/UseItemInInventoryOperator.cs b/Content.Server/AI/Operators/Inventory/UseItemInInventoryOperator.cs index e116bb1098..bc7905967b 100644 --- a/Content.Server/AI/Operators/Inventory/UseItemInInventoryOperator.cs +++ b/Content.Server/AI/Operators/Inventory/UseItemInInventoryOperator.cs @@ -10,10 +10,10 @@ namespace Content.Server.AI.Operators.Inventory /// public class UseItemInInventoryOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; - public UseItemInInventoryOperator(IEntity owner, IEntity target) + public UseItemInInventoryOperator(EntityUid owner, EntityUid target) { _owner = owner; _target = target; diff --git a/Content.Server/AI/Operators/Movement/MoveToEntityOperator.cs b/Content.Server/AI/Operators/Movement/MoveToEntityOperator.cs index 2569ffc04e..8be961e4c5 100644 --- a/Content.Server/AI/Operators/Movement/MoveToEntityOperator.cs +++ b/Content.Server/AI/Operators/Movement/MoveToEntityOperator.cs @@ -8,9 +8,9 @@ namespace Content.Server.AI.Operators.Movement public sealed class MoveToEntityOperator : AiOperator { // TODO: This and steering need to support InRangeUnobstructed now - private readonly IEntity _owner; + private readonly EntityUid _owner; private EntityTargetSteeringRequest? _request; - private readonly IEntity _target; + private readonly EntityUid _target; // For now we'll just get as close as we can because we're not doing LOS checks to be able to pick up at the max interaction range public float ArrivalDistance { get; } public float PathfindingProximity { get; } @@ -18,8 +18,8 @@ namespace Content.Server.AI.Operators.Movement private readonly bool _requiresInRangeUnobstructed; public MoveToEntityOperator( - IEntity owner, - IEntity target, + EntityUid owner, + EntityUid target, float arrivalDistance = 1.0f, float pathfindingProximity = 1.5f, bool requiresInRangeUnobstructed = false) diff --git a/Content.Server/AI/Operators/Movement/MoveToGridOperator.cs b/Content.Server/AI/Operators/Movement/MoveToGridOperator.cs index de560b50c0..f89005e286 100644 --- a/Content.Server/AI/Operators/Movement/MoveToGridOperator.cs +++ b/Content.Server/AI/Operators/Movement/MoveToGridOperator.cs @@ -8,12 +8,12 @@ namespace Content.Server.AI.Operators.Movement { public sealed class MoveToGridOperator : AiOperator { - private readonly IEntity _owner; + private readonly EntityUid _owner; private GridTargetSteeringRequest? _request; private readonly EntityCoordinates _target; public float DesiredRange { get; set; } - public MoveToGridOperator(IEntity owner, EntityCoordinates target, float desiredRange = 1.5f) + public MoveToGridOperator(EntityUid owner, EntityCoordinates target, float desiredRange = 1.5f) { _owner = owner; _target = target; diff --git a/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs b/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs index 51b6d71a77..6261c9df60 100644 --- a/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs +++ b/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs @@ -11,11 +11,11 @@ namespace Content.Server.AI.Operators.Nutrition { public class UseDrinkInInventoryOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; private float _interactionCooldown; - public UseDrinkInInventoryOperator(IEntity owner, IEntity target) + public UseDrinkInInventoryOperator(EntityUid owner, EntityUid target) { _owner = owner; _target = target; @@ -29,10 +29,12 @@ namespace Content.Server.AI.Operators.Nutrition return Outcome.Continuing; } + var entities = IoCManager.Resolve(); + // TODO: Also have this check storage a la backpack etc. - if ((!IoCManager.Resolve().EntityExists(_target) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || - !IoCManager.Resolve().TryGetComponent(_owner, out HandsComponent? handsComponent) || - !IoCManager.Resolve().TryGetComponent(_target, out ItemComponent? itemComponent)) + if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || + !entities.TryGetComponent(_owner, out HandsComponent? handsComponent) || + !entities.TryGetComponent(_target, out ItemComponent? itemComponent)) { return Outcome.Failed; } @@ -43,7 +45,7 @@ namespace Content.Server.AI.Operators.Nutrition { if (handsComponent.GetItem(slot) != itemComponent) continue; handsComponent.ActiveHand = slot; - if (!IoCManager.Resolve().TryGetComponent(_target, out drinkComponent)) + if (!entities.TryGetComponent(_target, out drinkComponent)) { return Outcome.Failed; } @@ -59,7 +61,7 @@ namespace Content.Server.AI.Operators.Nutrition } if (drinkComponent.Deleted || EntitySystem.Get().IsEmpty(drinkComponent.Owner, drinkComponent) - || IoCManager.Resolve().TryGetComponent(_owner, out ThirstComponent? thirstComponent) && + || entities.TryGetComponent(_owner, out ThirstComponent? thirstComponent) && thirstComponent.CurrentThirst >= thirstComponent.ThirstThresholds[ThirstThreshold.Okay]) { return Outcome.Success; diff --git a/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs b/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs index 5d4b6afc51..e4912ec3b5 100644 --- a/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs +++ b/Content.Server/AI/Operators/Nutrition/UseFoodInInventoryOperator.cs @@ -10,11 +10,11 @@ namespace Content.Server.AI.Operators.Nutrition { public class UseFoodInInventoryOperator : AiOperator { - private readonly IEntity _owner; - private readonly IEntity _target; + private readonly EntityUid _owner; + private readonly EntityUid _target; private float _interactionCooldown; - public UseFoodInInventoryOperator(IEntity owner, IEntity target) + public UseFoodInInventoryOperator(EntityUid owner, EntityUid target) { _owner = owner; _target = target; @@ -28,10 +28,12 @@ namespace Content.Server.AI.Operators.Nutrition return Outcome.Continuing; } + var entities = IoCManager.Resolve(); + // TODO: Also have this check storage a la backpack etc. - if ((!IoCManager.Resolve().EntityExists(_target) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || - !IoCManager.Resolve().TryGetComponent(_owner, out HandsComponent? handsComponent) || - !IoCManager.Resolve().TryGetComponent(_target, out ItemComponent? itemComponent)) + if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || + !entities.TryGetComponent(_owner, out HandsComponent? handsComponent) || + !entities.TryGetComponent(_target, out ItemComponent? itemComponent)) { return Outcome.Failed; } @@ -42,7 +44,7 @@ namespace Content.Server.AI.Operators.Nutrition { if (handsComponent.GetItem(slot) != itemComponent) continue; handsComponent.ActiveHand = slot; - if (!IoCManager.Resolve().TryGetComponent(_target, out foodComponent)) + if (!entities.TryGetComponent(_target, out foodComponent)) { return Outcome.Failed; } @@ -57,9 +59,9 @@ namespace Content.Server.AI.Operators.Nutrition return Outcome.Failed; } - if ((!IoCManager.Resolve().EntityExists(_target) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || + if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent(_target).EntityLifeStage) >= EntityLifeStage.Deleted || foodComponent.UsesRemaining == 0 || - IoCManager.Resolve().TryGetComponent(_owner, out HungerComponent? hungerComponent) && + entities.TryGetComponent(_owner, out HungerComponent? hungerComponent) && hungerComponent.CurrentHunger >= hungerComponent.HungerThresholds[HungerThreshold.Okay]) { return Outcome.Success; diff --git a/Content.Server/AI/Operators/Sequences/GoPickupEntitySequence.cs b/Content.Server/AI/Operators/Sequences/GoPickupEntitySequence.cs index e7d9471e26..c4f8776956 100644 --- a/Content.Server/AI/Operators/Sequences/GoPickupEntitySequence.cs +++ b/Content.Server/AI/Operators/Sequences/GoPickupEntitySequence.cs @@ -7,7 +7,7 @@ namespace Content.Server.AI.Operators.Sequences { public class GoPickupEntitySequence : SequenceOperator { - public GoPickupEntitySequence(IEntity owner, IEntity target) + public GoPickupEntitySequence(EntityUid owner, EntityUid target) { Sequence = new Queue(new AiOperator[] { @@ -17,4 +17,4 @@ namespace Content.Server.AI.Operators.Sequences }); } } -} \ No newline at end of file +} diff --git a/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs b/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs index 2db8ca2fe5..6b5912f0b2 100644 --- a/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs +++ b/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.AI.Pathfinding.Pathfinders; using Content.Shared.AI; @@ -171,7 +170,7 @@ namespace Content.Server.AI.Pathfinding.Accessible /// /// /// - public bool CanAccess(IEntity entity, IEntity target, float range = 0.0f) + public bool CanAccess(EntityUid entity, EntityUid target, float range = 0.0f) { // TODO: Handle this gracefully instead of just failing. if (!IoCManager.Resolve().GetComponent(target).GridID.IsValid()) @@ -208,7 +207,7 @@ namespace Content.Server.AI.Pathfinding.Accessible return CanAccess(entity, targetNode); } - public bool CanAccess(IEntity entity, PathfindingNode targetNode) + public bool CanAccess(EntityUid entity, PathfindingNode targetNode) { if (IoCManager.Resolve().GetComponent(entity).GridID != targetNode.TileRef.GridIndex) { @@ -423,7 +422,7 @@ namespace Content.Server.AI.Pathfinding.Accessible /// /// /// - public PathfindingRegion? GetRegion(IEntity entity) + public PathfindingRegion? GetRegion(EntityUid entity) { if (!IoCManager.Resolve().GetComponent(entity).GridID.IsValid()) { diff --git a/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs b/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs index aed00d3ca7..79823f9b2b 100644 --- a/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs +++ b/Content.Server/AI/Pathfinding/Accessible/ReachableArgs.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.AI.Components; using Robust.Shared.GameObjects; @@ -26,7 +25,7 @@ namespace Content.Server.AI.Pathfinding.Accessible /// /// /// - public static ReachableArgs GetArgs(IEntity entity) + public static ReachableArgs GetArgs(EntityUid entity) { var collisionMask = 0; if (IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? physics)) diff --git a/Content.Server/AI/Pathfinding/PathfindingNode.cs b/Content.Server/AI/Pathfinding/PathfindingNode.cs index c653b0aeae..24716cd826 100644 --- a/Content.Server/AI/Pathfinding/PathfindingNode.cs +++ b/Content.Server/AI/Pathfinding/PathfindingNode.cs @@ -23,17 +23,17 @@ namespace Content.Server.AI.Pathfinding /// Whenever there's a change in the collision layers we update the mask as the graph has more reads than writes /// public int BlockedCollisionMask { get; private set; } - private readonly Dictionary _blockedCollidables = new(0); + private readonly Dictionary _blockedCollidables = new(0); - public IReadOnlyDictionary PhysicsLayers => _physicsLayers; - private readonly Dictionary _physicsLayers = new(0); + public IReadOnlyDictionary PhysicsLayers => _physicsLayers; + private readonly Dictionary _physicsLayers = new(0); /// /// The entities on this tile that require access to traverse /// /// We don't store the ICollection, at least for now, as we'd need to replicate the access code here public IReadOnlyCollection AccessReaders => _accessReaders.Values; - private readonly Dictionary _accessReaders = new(0); + private readonly Dictionary _accessReaders = new(0); public PathfindingNode(PathfindingChunk parent, TileRef tileRef) { @@ -42,7 +42,7 @@ namespace Content.Server.AI.Pathfinding GenerateMask(); } - public static bool IsRelevant(IEntity entity, IPhysBody physicsComponent) + public static bool IsRelevant(EntityUid entity, IPhysBody physicsComponent) { if (IoCManager.Resolve().GetComponent(entity).GridID == GridId.Invalid || (PathfindingSystem.TrackedCollisionLayers & physicsComponent.CollisionLayer) == 0) @@ -258,7 +258,7 @@ namespace Content.Server.AI.Pathfinding /// /// TODO: These 2 methods currently don't account for a bunch of changes (e.g. airlock unpowered, wrenching, etc.) /// TODO: Could probably optimise this slightly more. - public void AddEntity(IEntity entity, IPhysBody physicsComponent) + public void AddEntity(EntityUid entity, IPhysBody physicsComponent) { // If we're a door if (IoCManager.Resolve().HasComponent(entity) || IoCManager.Resolve().HasComponent(entity)) @@ -294,7 +294,7 @@ namespace Content.Server.AI.Pathfinding /// Will check each category and remove it from the applicable one /// /// - public void RemoveEntity(IEntity entity) + public void RemoveEntity(EntityUid entity) { // There's no guarantee that the entity isn't deleted // 90% of updates are probably entities moving around diff --git a/Content.Server/AI/Pathfinding/PathfindingSystem.cs b/Content.Server/AI/Pathfinding/PathfindingSystem.cs index d3045f286f..bd3663af42 100644 --- a/Content.Server/AI/Pathfinding/PathfindingSystem.cs +++ b/Content.Server/AI/Pathfinding/PathfindingSystem.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Threading; using Content.Server.Access; -using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.CPUJob.JobQueues; @@ -46,7 +45,7 @@ namespace Content.Server.AI.Pathfinding private readonly Queue _tileUpdateQueue = new(); // Need to store previously known entity positions for collidables for when they move - private readonly Dictionary _lastKnownPositions = new(); + private readonly Dictionary _lastKnownPositions = new(); public const int TrackedCollisionLayers = (int) (CollisionGroup.Impassable | @@ -85,15 +84,15 @@ namespace Content.Server.AI.Pathfinding foreach (var update in _collidableUpdateQueue) { - if (!EntityManager.TryGetEntity(update.Owner, out var entity)) continue; + if (!EntityManager.EntityExists(update.Owner)) continue; if (update.CanCollide) { - HandleEntityAdd(entity); + HandleEntityAdd(update.Owner); } else { - HandleEntityRemove(entity); + HandleEntityRemove(update.Owner); } totalUpdates++; @@ -182,7 +181,7 @@ namespace Content.Server.AI.Pathfinding /// /// /// - public PathfindingNode GetNode(IEntity entity) + public PathfindingNode GetNode(EntityUid entity) { var tile = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(entity).GridID).GetTileRef(IoCManager.Resolve().GetComponent(entity).Coordinates); return GetNode(tile); @@ -263,7 +262,7 @@ namespace Content.Server.AI.Pathfinding /// /// The node will filter it to the correct category (if possible) /// - private void HandleEntityAdd(IEntity entity) + private void HandleEntityAdd(EntityUid entity) { if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || _lastKnownPositions.ContainsKey(entity) || @@ -282,7 +281,7 @@ namespace Content.Server.AI.Pathfinding _lastKnownPositions.Add(entity, node); } - private void HandleEntityRemove(IEntity entity) + private void HandleEntityRemove(EntityUid entity) { if (!_lastKnownPositions.TryGetValue(entity, out var node)) { @@ -361,7 +360,7 @@ namespace Content.Server.AI.Pathfinding // TODO: Need to rethink the pathfinder utils (traversable etc.). Maybe just chuck them all in PathfindingSystem // Otherwise you get the steerer using this and the pathfinders using a different traversable. // Also look at increasing tile cost the more physics entities are on it - public bool CanTraverse(IEntity entity, EntityCoordinates coordinates) + public bool CanTraverse(EntityUid entity, EntityCoordinates coordinates) { var gridId = coordinates.GetGridId(EntityManager); var tile = _mapManager.GetGrid(gridId).GetTileRef(coordinates); @@ -369,7 +368,7 @@ namespace Content.Server.AI.Pathfinding return CanTraverse(entity, node); } - public bool CanTraverse(IEntity entity, PathfindingNode node) + public bool CanTraverse(EntityUid entity, PathfindingNode node) { if (IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? physics) && (physics.CollisionMask & node.BlockedCollisionMask) != 0) diff --git a/Content.Server/AI/Steering/AiSteeringSystem.cs b/Content.Server/AI/Steering/AiSteeringSystem.cs index 7b9f90b1bc..cc46521f09 100644 --- a/Content.Server/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/AI/Steering/AiSteeringSystem.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; -using Content.Server.Access.Components; using Content.Server.Access.Systems; using Content.Server.AI.Components; using Content.Server.AI.Pathfinding; @@ -11,7 +10,6 @@ using Content.Server.AI.Pathfinding.Pathfinders; using Content.Server.CPUJob.JobQueues; using Content.Shared.ActionBlocker; using Content.Shared.Interaction.Helpers; -using Content.Shared.Movement; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; @@ -47,43 +45,43 @@ namespace Content.Server.AI.Steering /// private const float InRangeUnobstructedCooldown = 0.25f; - private Dictionary RunningAgents => _agentLists[_listIndex]; + private Dictionary RunningAgents => _agentLists[_listIndex]; // We'll cycle the running list every tick as all we're doing is getting a vector2 for the // agent's steering. Should help a lot given this is the most expensive operator by far. // The AI will keep moving, it's just it'll keep moving in its existing direction. // If we change to 20/30 TPS you might want to change this but for now it's fine - private readonly List> _agentLists = new(AgentListCount); + private readonly List> _agentLists = new(AgentListCount); private const int AgentListCount = 2; private int _listIndex; // Cache nextGrid - private readonly Dictionary _nextGrid = new(); + private readonly Dictionary _nextGrid = new(); /// /// Current live paths for AI /// - private readonly Dictionary> _paths = new(); + private readonly Dictionary> _paths = new(); /// /// Pathfinding request jobs we're waiting on /// - private readonly Dictionary> Job)> _pathfindingRequests = + private readonly Dictionary> Job)> _pathfindingRequests = new(); /// /// Keep track of how long we've been in 1 position and re-path if it's been too long /// - private readonly Dictionary _stuckCounter = new(); + private readonly Dictionary _stuckCounter = new(); /// /// Get a fixed position for the target entity; if they move then re-path /// - private readonly Dictionary _entityTargetPosition = new(); + private readonly Dictionary _entityTargetPosition = new(); // Anti-Stuck // Given the collision avoidance can lead to twitching need to store a reference position and check if we've been near this too long - private readonly Dictionary _stuckPositions = new(); + private readonly Dictionary _stuckPositions = new(); public override void Initialize() { @@ -91,7 +89,7 @@ namespace Content.Server.AI.Steering for (var i = 0; i < AgentListCount; i++) { - _agentLists.Add(new Dictionary()); + _agentLists.Add(new Dictionary()); } } @@ -101,7 +99,7 @@ namespace Content.Server.AI.Steering /// We'll add it to the movement list that has the least number of agents /// /// - public void Register(IEntity entity, IAiSteeringRequest steeringRequest) + public void Register(EntityUid entity, IAiSteeringRequest steeringRequest) { var lowestListCount = 1000; var lowestListIndex = 0; @@ -127,9 +125,9 @@ namespace Content.Server.AI.Steering /// /// /// - public void Unregister(IEntity entity) + public void Unregister(EntityUid entity) { - if (IoCManager.Resolve().TryGetComponent(entity, out AiControllerComponent? controller)) + if (EntityManager.TryGetComponent(entity, out AiControllerComponent? controller)) { controller.VelocityDir = Vector2.Zero; } @@ -194,7 +192,7 @@ namespace Content.Server.AI.Steering /// /// /// - public bool IsRegistered(IEntity entity) + public bool IsRegistered(EntityUid entity) { foreach (var agentList in _agentLists) { @@ -245,26 +243,26 @@ namespace Content.Server.AI.Steering /// /// /// - private SteeringStatus Steer(IEntity entity, IAiSteeringRequest steeringRequest, float frameTime) + private SteeringStatus Steer(EntityUid entity, IAiSteeringRequest steeringRequest, float frameTime) { // Main optimisation to be done below is the redundant calls and adding more variables - if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || - !IoCManager.Resolve().TryGetComponent(entity, out AiControllerComponent? controller) || + if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || + !EntityManager.TryGetComponent(entity, out AiControllerComponent? controller) || !EntitySystem.Get().CanMove(entity) || - !IoCManager.Resolve().GetComponent(entity).GridID.IsValid()) + !EntityManager.GetComponent(entity).GridID.IsValid()) { return SteeringStatus.NoPath; } var entitySteering = steeringRequest as EntityTargetSteeringRequest; - if (entitySteering != null && (!IoCManager.Resolve().EntityExists(entitySteering.Target) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entitySteering.Target).EntityLifeStage) >= EntityLifeStage.Deleted) + if (entitySteering != null && (!EntityManager.EntityExists(entitySteering.Target) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entitySteering.Target).EntityLifeStage) >= EntityLifeStage.Deleted) { controller.VelocityDir = Vector2.Zero; return SteeringStatus.NoPath; } - if (_pauseManager.IsGridPaused(IoCManager.Resolve().GetComponent(entity).GridID)) + if (_pauseManager.IsGridPaused(EntityManager.GetComponent(entity).GridID)) { controller.VelocityDir = Vector2.Zero; return SteeringStatus.Pending; @@ -272,14 +270,14 @@ namespace Content.Server.AI.Steering // Validation // Check if we can even arrive -> Currently only samegrid movement supported - if (IoCManager.Resolve().GetComponent(entity).GridID != steeringRequest.TargetGrid.GetGridId(EntityManager)) + if (EntityManager.GetComponent(entity).GridID != steeringRequest.TargetGrid.GetGridId(EntityManager)) { controller.VelocityDir = Vector2.Zero; return SteeringStatus.NoPath; } // Check if we have arrived - var targetDistance = (IoCManager.Resolve().GetComponent(entity).MapPosition.Position - steeringRequest.TargetMap.Position).Length; + var targetDistance = (EntityManager.GetComponent(entity).MapPosition.Position - steeringRequest.TargetMap.Position).Length; steeringRequest.TimeUntilInteractionCheck -= frameTime; if (targetDistance <= steeringRequest.ArrivalDistance && steeringRequest.TimeUntilInteractionCheck <= 0.0f) @@ -348,7 +346,7 @@ namespace Content.Server.AI.Steering return SteeringStatus.Pending; } - var ignoredCollision = new List(); + var ignoredCollision = new List(); // Check if the target entity has moved - If so then re-path // TODO: Patch the path from the target's position back towards us, stopping if it ever intersects the current path // Probably need a separate "PatchPath" job @@ -408,7 +406,7 @@ namespace Content.Server.AI.Steering /// /// /// - private void RequestPath(IEntity entity, IAiSteeringRequest steeringRequest) + private void RequestPath(EntityUid entity, IAiSteeringRequest steeringRequest) { if (_pathfindingRequests.ContainsKey(entity)) { @@ -416,11 +414,11 @@ namespace Content.Server.AI.Steering } var cancelToken = new CancellationTokenSource(); - var gridManager = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(entity).GridID); - var startTile = gridManager.GetTileRef(IoCManager.Resolve().GetComponent(entity).Coordinates); + var gridManager = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridID); + var startTile = gridManager.GetTileRef(EntityManager.GetComponent(entity).Coordinates); var endTile = gridManager.GetTileRef(steeringRequest.TargetGrid); var collisionMask = 0; - if (IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? physics)) + if (EntityManager.TryGetComponent(entity, out IPhysBody? physics)) { collisionMask = physics.CollisionMask; } @@ -443,11 +441,11 @@ namespace Content.Server.AI.Steering /// /// /// - private void UpdatePath(IEntity entity, Queue path) + private void UpdatePath(EntityUid entity, Queue path) { _pathfindingRequests.Remove(entity); - var entityTile = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(entity).GridID).GetTileRef(IoCManager.Resolve().GetComponent(entity).Coordinates); + var entityTile = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridID).GetTileRef(EntityManager.GetComponent(entity).Coordinates); var tile = path.Dequeue(); var closestDistance = PathfindingHelpers.OctileDistance(entityTile, tile); @@ -474,7 +472,7 @@ namespace Content.Server.AI.Steering /// /// /// - private EntityCoordinates? NextGrid(IEntity entity, IAiSteeringRequest steeringRequest) + private EntityCoordinates? NextGrid(EntityUid entity, IAiSteeringRequest steeringRequest) { // Remove the cached grid if (!_paths.ContainsKey(entity) && _nextGrid.ContainsKey(entity)) @@ -485,7 +483,7 @@ namespace Content.Server.AI.Steering // If no tiles left just move towards the target (if we're close) if (!_paths.ContainsKey(entity) || _paths[entity].Count == 0) { - if ((steeringRequest.TargetGrid.Position - IoCManager.Resolve().GetComponent(entity).Coordinates.Position).Length <= 2.0f) + if ((steeringRequest.TargetGrid.Position - EntityManager.GetComponent(entity).Coordinates.Position).Length <= 2.0f) { return steeringRequest.TargetGrid; } @@ -495,7 +493,7 @@ namespace Content.Server.AI.Steering } if (!_nextGrid.TryGetValue(entity, out var nextGrid) || - (nextGrid.Position - IoCManager.Resolve().GetComponent(entity).Coordinates.Position).Length <= TileTolerance) + (nextGrid.Position - EntityManager.GetComponent(entity).Coordinates.Position).Length <= TileTolerance) { UpdateGridCache(entity); nextGrid = _nextGrid[entity]; @@ -510,11 +508,11 @@ namespace Content.Server.AI.Steering /// /// /// - private void UpdateGridCache(IEntity entity, bool dequeue = true) + private void UpdateGridCache(EntityUid entity, bool dequeue = true) { if (_paths[entity].Count == 0) return; var nextTile = dequeue ? _paths[entity].Dequeue() : _paths[entity].Peek(); - var nextGrid = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(entity).GridID).GridTileToLocal(nextTile.GridIndices); + var nextGrid = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridID).GridTileToLocal(nextTile.GridIndices); _nextGrid[entity] = nextGrid; } @@ -522,16 +520,16 @@ namespace Content.Server.AI.Steering /// Check if we've been near our last EntityCoordinates too long and try to fix it /// /// - private void HandleStuck(IEntity entity) + private void HandleStuck(EntityUid entity) { if (!_stuckPositions.TryGetValue(entity, out var stuckPosition)) { - _stuckPositions[entity] = IoCManager.Resolve().GetComponent(entity).Coordinates; + _stuckPositions[entity] = EntityManager.GetComponent(entity).Coordinates; _stuckCounter[entity] = 0; return; } - if ((IoCManager.Resolve().GetComponent(entity).Coordinates.Position - stuckPosition.Position).Length <= 1.0f) + if ((EntityManager.GetComponent(entity).Coordinates.Position - stuckPosition.Position).Length <= 1.0f) { _stuckCounter.TryGetValue(entity, out var stuckCount); _stuckCounter[entity] = stuckCount + 1; @@ -539,7 +537,7 @@ namespace Content.Server.AI.Steering else { // No longer stuck - _stuckPositions[entity] = IoCManager.Resolve().GetComponent(entity).Coordinates; + _stuckPositions[entity] = EntityManager.GetComponent(entity).Coordinates; _stuckCounter[entity] = 0; return; } @@ -562,10 +560,10 @@ namespace Content.Server.AI.Steering /// /// /// - private Vector2 Seek(IEntity entity, EntityCoordinates grid) + private Vector2 Seek(EntityUid entity, EntityCoordinates grid) { // is-even much - var entityPos = IoCManager.Resolve().GetComponent(entity).Coordinates; + var entityPos = EntityManager.GetComponent(entity).Coordinates; return entityPos == grid ? Vector2.Zero : (grid.Position - entityPos.Position).Normalized; @@ -578,9 +576,9 @@ namespace Content.Server.AI.Steering /// /// /// - private Vector2 Arrival(IEntity entity, EntityCoordinates grid, float slowingDistance = 1.0f) + private Vector2 Arrival(EntityUid entity, EntityCoordinates grid, float slowingDistance = 1.0f) { - var entityPos = IoCManager.Resolve().GetComponent(entity).Coordinates; + var entityPos = EntityManager.GetComponent(entity).Coordinates; DebugTools.Assert(slowingDistance > 0.0f); if (entityPos == grid) { @@ -597,16 +595,16 @@ namespace Content.Server.AI.Steering /// /// /// - private Vector2 Pursuit(IEntity entity, IEntity target) + private Vector2 Pursuit(EntityUid entity, EntityUid target) { - var entityPos = IoCManager.Resolve().GetComponent(entity).Coordinates; - var targetPos = IoCManager.Resolve().GetComponent(target).Coordinates; + var entityPos = EntityManager.GetComponent(entity).Coordinates; + var targetPos = EntityManager.GetComponent(target).Coordinates; if (entityPos == targetPos) { return Vector2.Zero; } - if (IoCManager.Resolve().TryGetComponent(target, out IPhysBody? physics)) + if (EntityManager.TryGetComponent(target, out IPhysBody? physics)) { var targetDistance = (targetPos.Position - entityPos.Position); targetPos = targetPos.Offset(physics.LinearVelocity * targetDistance); @@ -622,9 +620,9 @@ namespace Content.Server.AI.Steering /// entity's travel direction /// /// - private Vector2 CollisionAvoidance(IEntity entity, Vector2 direction, ICollection ignoredTargets) + private Vector2 CollisionAvoidance(EntityUid entity, Vector2 direction, ICollection ignoredTargets) { - if (direction == Vector2.Zero || !IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? physics)) + if (direction == Vector2.Zero || !EntityManager.TryGetComponent(entity, out IPhysBody? physics)) { return Vector2.Zero; } @@ -636,8 +634,8 @@ namespace Content.Server.AI.Steering var avoidanceVector = Vector2.Zero; var checkTiles = new HashSet(); var avoidTiles = new HashSet(); - var entityGridCoords = IoCManager.Resolve().GetComponent(entity).Coordinates; - var grid = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(entity).GridID); + var entityGridCoords = EntityManager.GetComponent(entity).Coordinates; + var grid = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridID); var currentTile = grid.GetTileRef(entityGridCoords); var halfwayTile = grid.GetTileRef(entityGridCoords.Offset(direction / 2)); var nextTile = grid.GetTileRef(entityGridCoords.Offset(direction)); @@ -660,18 +658,18 @@ 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 ((!IoCManager.Resolve().EntityExists(physicsEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(physicsEntity).EntityLifeStage) >= EntityLifeStage.Deleted) continue; + if ((!EntityManager.EntityExists(physicsEntity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(physicsEntity).EntityLifeStage) >= EntityLifeStage.Deleted) 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 // i.e. towards the right - if (IoCManager.Resolve().TryGetComponent(physicsEntity, out IPhysBody? otherPhysics) && + if (EntityManager.TryGetComponent(physicsEntity, out IPhysBody? otherPhysics) && Vector2.Dot(otherPhysics.LinearVelocity, direction) > 0) { continue; } - var centerGrid = IoCManager.Resolve().GetComponent(physicsEntity).Coordinates; + var centerGrid = EntityManager.GetComponent(physicsEntity).Coordinates; // Check how close we are to center of tile and get the inverse; if we're closer this is stronger var additionalVector = (centerGrid.Position - entityGridCoords.Position); var distance = additionalVector.Length; diff --git a/Content.Server/AI/Steering/EntityTargetSteeringRequest.cs b/Content.Server/AI/Steering/EntityTargetSteeringRequest.cs index 3d21553f9e..e4cf246772 100644 --- a/Content.Server/AI/Steering/EntityTargetSteeringRequest.cs +++ b/Content.Server/AI/Steering/EntityTargetSteeringRequest.cs @@ -9,8 +9,8 @@ namespace Content.Server.AI.Steering public SteeringStatus Status { get; set; } = SteeringStatus.Pending; public MapCoordinates TargetMap => IoCManager.Resolve().GetComponent(_target).MapPosition; public EntityCoordinates TargetGrid => IoCManager.Resolve().GetComponent(_target).Coordinates; - public IEntity Target => _target; - private readonly IEntity _target; + public EntityUid Target => _target; + private readonly EntityUid _target; /// public float ArrivalDistance { get; } @@ -31,7 +31,7 @@ namespace Content.Server.AI.Steering /// public float TimeUntilInteractionCheck { get; set; } - public EntityTargetSteeringRequest(IEntity target, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false) + public EntityTargetSteeringRequest(EntityUid target, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false) { _target = target; ArrivalDistance = arrivalDistance; diff --git a/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs b/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs index 2051a1584c..9fcb56e390 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs @@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves { public sealed class EquipGloves : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs b/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs index 70cdaaff15..f3c3d7c4dd 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves { public sealed class PickUpGloves : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs b/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs index 3f3a7f664f..9429572ada 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs @@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head { public sealed class EquipHead : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs b/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs index 6a380a115b..d756710afe 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head { public sealed class PickUpHead : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs index a9bc02db85..fd1b7f2e81 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs @@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing { public sealed class EquipOuterClothing : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs index e15440b701..501b8ca7ab 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing { public sealed class PickUpOuterClothing : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs b/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs index d3ce78c7ff..f35416f313 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs @@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes { public sealed class EquipShoes : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs b/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs index a1780a5115..49db12a914 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes { public sealed class PickUpShoes : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs index 2a727425ae..3f600d9c6b 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs @@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee { public sealed class EquipMelee : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs index 497807a27f..0885487bb2 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs @@ -21,13 +21,13 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee { public sealed class MeleeWeaponAttackEntity : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { MoveToEntityOperator moveOperator; var equipped = context.GetState().GetValue(); - if (equipped != null && IoCManager.Resolve().TryGetComponent(equipped, out MeleeWeaponComponent? meleeWeaponComponent)) + if (equipped != default && IoCManager.Resolve().TryGetComponent(equipped, out MeleeWeaponComponent? meleeWeaponComponent)) { moveOperator = new MoveToEntityOperator(Owner, Target, meleeWeaponComponent.Range - 0.01f); } diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs index 272bbbdf2c..c33e420922 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs @@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee { public sealed class PickUpMeleeWeapon : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs index ab2aaeea2a..524e77eb9d 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs @@ -19,7 +19,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee { public sealed class UnarmedAttackEntity : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/IAiUtility.cs b/Content.Server/AI/Utility/Actions/IAiUtility.cs index c09989707c..fc7f5bb0b8 100644 --- a/Content.Server/AI/Utility/Actions/IAiUtility.cs +++ b/Content.Server/AI/Utility/Actions/IAiUtility.cs @@ -7,7 +7,7 @@ namespace Content.Server.AI.Utility.Actions /// /// NPC this action is attached to. /// - IEntity Owner { get; set; } + EntityUid Owner { get; set; } /// /// Highest possible score for this action. diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs b/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs index 9f7e7e6ac0..0987af5f08 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink { public sealed class PickUpDrink : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs b/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs index 7ef0ee9a02..fe18717229 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs @@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink { public sealed class UseDrinkInInventory : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs b/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs index 24ede12d18..b4760e884e 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs @@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food { public sealed class PickUpFood : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs b/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs index 2bce14ccfa..6b76794694 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs @@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food { public sealed class UseFoodInInventory : UtilityAction { - public IEntity Target { get; set; } = default!; + public EntityUid Target { get; set; } = default!; public override void SetupOperators(Blackboard context) { diff --git a/Content.Server/AI/Utility/Actions/UtilityAction.cs b/Content.Server/AI/Utility/Actions/UtilityAction.cs index fe906ad38e..9d8b48ee27 100644 --- a/Content.Server/AI/Utility/Actions/UtilityAction.cs +++ b/Content.Server/AI/Utility/Actions/UtilityAction.cs @@ -36,7 +36,7 @@ namespace Content.Server.AI.Utility.Actions public const float CombatBonus = 30.0f; public const float DangerBonus = 50.0f; - public IEntity Owner { get; set; } + public EntityUid Owner { get; set; } /// /// All the considerations are multiplied together to get the final score; a consideration of 0.0 means the action is not possible. diff --git a/Content.Server/AI/Utility/Considerations/Combat/Melee/CanUnarmedCombatCon.cs b/Content.Server/AI/Utility/Considerations/Combat/Melee/CanUnarmedCombatCon.cs index 75a3a0c59f..07f8990b31 100644 --- a/Content.Server/AI/Utility/Considerations/Combat/Melee/CanUnarmedCombatCon.cs +++ b/Content.Server/AI/Utility/Considerations/Combat/Melee/CanUnarmedCombatCon.cs @@ -10,13 +10,9 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee { protected override float GetScore(Blackboard context) { - IEntity tempQualifier = context.GetState().GetValue(); - if (tempQualifier != null) - { - IoCManager.Resolve().HasComponent(tempQualifier); - } - - return RETURNED_VALUE ?? false ? 1.0f : 0.0f; + var entityManager = IoCManager.Resolve(); + var entity = context.GetState().GetValue(); + return entityManager.HasComponent(entity) ? 1.0f : 0.0f; } } } diff --git a/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs index 6360b0d045..26c3f83f59 100644 --- a/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs +++ b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs @@ -10,14 +10,17 @@ namespace Content.Server.AI.Utility.Considerations.Movement protected override float GetScore(Blackboard context) { var self = context.GetState().GetValue(); - var target = context.GetState().GetValue(); - if (target == null || (!IoCManager.Resolve().EntityExists(target) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(target).EntityLifeStage) >= EntityLifeStage.Deleted || IoCManager.Resolve().GetComponent(target).GridID != (self != null ? IoCManager.Resolve().GetComponent(self) : null).GridID) + var entities = IoCManager.Resolve(); + + if (context.GetState().GetValue() is not {Valid: true} target || + (!entities.EntityExists(target) ? EntityLifeStage.Deleted : entities.GetComponent(target).EntityLifeStage) >= EntityLifeStage.Deleted || + entities.GetComponent(target).GridID != entities.GetComponent(self).GridID) { return 0.0f; } // Anything further than 100 tiles gets clamped - return (IoCManager.Resolve().GetComponent(target).Coordinates.Position - IoCManager.Resolve().GetComponent(self).Coordinates.Position).Length / 100; + return (entities.GetComponent(target).Coordinates.Position - entities.GetComponent(self).Coordinates.Position).Length / 100; } } } diff --git a/Content.Server/AI/Utility/Considerations/State/StoredStateEntityIsNullCon.cs b/Content.Server/AI/Utility/Considerations/State/StoredStateEntityIsNullCon.cs index 4e53cdab94..17c41986ae 100644 --- a/Content.Server/AI/Utility/Considerations/State/StoredStateEntityIsNullCon.cs +++ b/Content.Server/AI/Utility/Considerations/State/StoredStateEntityIsNullCon.cs @@ -27,7 +27,7 @@ namespace Content.Server.AI.Utility.Considerations.State return 0; } - context.GetStoredState(stateData, out StoredStateData state); + context.GetStoredState(stateData, out StoredStateData state); return state.GetValue() == null ? 1.0f : 0.0f; } } diff --git a/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs b/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs index 6c3d79ba6c..8a4278a601 100644 --- a/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs +++ b/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs @@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.ExpandableActions /// public abstract class ExpandableUtilityAction : IAiUtility { - public IEntity Owner { get; set; } = default!; + public EntityUid Owner { get; set; } = default!; public abstract float Bonus { get; } diff --git a/Content.Server/AI/Utility/UtilityAiHelpers.cs b/Content.Server/AI/Utility/UtilityAiHelpers.cs index 7b24ef57ea..733ad15029 100644 --- a/Content.Server/AI/Utility/UtilityAiHelpers.cs +++ b/Content.Server/AI/Utility/UtilityAiHelpers.cs @@ -8,7 +8,7 @@ namespace Content.Server.AI.Utility { public static class UtilityAiHelpers { - public static Blackboard? GetBlackboard(IEntity entity) + public static Blackboard? GetBlackboard(EntityUid entity) { if (!IoCManager.Resolve().TryGetComponent(entity, out AiControllerComponent? aiControllerComponent)) { diff --git a/Content.Server/AI/Utils/Visibility.cs b/Content.Server/AI/Utils/Visibility.cs index 6cbc876508..128a2c8cd7 100644 --- a/Content.Server/AI/Utils/Visibility.cs +++ b/Content.Server/AI/Utils/Visibility.cs @@ -1,21 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; -using Content.Server.AI.Components; -using Content.Shared.Physics; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Maths; -using Robust.Shared.Physics; -using Robust.Shared.Physics.Broadphase; namespace Content.Server.AI.Utils { public static class Visibility { // Should this be in robust or something? Fark it - public static IEnumerable GetNearestEntities(EntityCoordinates grid, Type component, float range) + public static IEnumerable GetNearestEntities(EntityCoordinates grid, Type component, float range) { var inRange = GetEntitiesInRange(grid, component, range).ToList(); var sortedInRange = inRange.OrderBy(o => (IoCManager.Resolve().GetComponent(o).Coordinates.Position - grid.Position).Length); @@ -23,7 +18,7 @@ namespace Content.Server.AI.Utils return sortedInRange; } - public static IEnumerable GetEntitiesInRange(EntityCoordinates grid, Type component, float range) + public static IEnumerable GetEntitiesInRange(EntityCoordinates grid, Type component, float range) { var entityManager = IoCManager.Resolve(); foreach (var entity in entityManager.GetAllComponents(component).Select(c => c.Owner)) diff --git a/Content.Server/AI/WorldState/Blackboard.cs b/Content.Server/AI/WorldState/Blackboard.cs index eb33315fac..83eecd0f83 100644 --- a/Content.Server/AI/WorldState/Blackboard.cs +++ b/Content.Server/AI/WorldState/Blackboard.cs @@ -12,18 +12,18 @@ namespace Content.Server.AI.WorldState { // Some stuff like "My Health" is easy to represent as components but abstract stuff like "How much food is nearby" // is harder. This also allows data to be cached if it's being hit frequently. - + // This also stops you from re-writing the same boilerplate everywhere of stuff like "Do I have OuterClothing on?" private readonly Dictionary _states = new(); private readonly List _planningStates = new(); - public Blackboard(IEntity owner) + public Blackboard(EntityUid owner) { Setup(owner); } - private void Setup(IEntity owner) + private void Setup(EntityUid owner) { var typeFactory = IoCManager.Resolve(); var blackboardManager = IoCManager.Resolve(); diff --git a/Content.Server/AI/WorldState/StateData.cs b/Content.Server/AI/WorldState/StateData.cs index 8563ef57fe..ad55329f53 100644 --- a/Content.Server/AI/WorldState/StateData.cs +++ b/Content.Server/AI/WorldState/StateData.cs @@ -10,7 +10,7 @@ namespace Content.Server.AI.WorldState /// public interface IAiState { - void Setup(IEntity owner); + void Setup(EntityUid owner); } public interface IPlanningState @@ -32,9 +32,9 @@ namespace Content.Server.AI.WorldState public abstract class StateData : IAiState { public abstract string Name { get; } - protected IEntity Owner { get; private set; } = default!; + protected EntityUid Owner { get; private set; } = default!; - public void Setup(IEntity owner) + public void Setup(EntityUid owner) { Owner = owner; } @@ -51,11 +51,11 @@ namespace Content.Server.AI.WorldState { // Probably not the best class name but couldn't think of anything better public abstract string Name { get; } - private IEntity? Owner { get; set; } + private EntityUid Owner { get; set; } private T? _value; - public void Setup(IEntity owner) + public void Setup(EntityUid owner) { Owner = owner; } @@ -79,10 +79,10 @@ namespace Content.Server.AI.WorldState public abstract class PlanningStateData : IAiState, IPlanningState { public abstract string Name { get; } - protected IEntity? Owner { get; private set; } + protected EntityUid Owner { get; private set; } protected T? Value; - public void Setup(IEntity owner) + public void Setup(EntityUid owner) { Owner = owner; } @@ -108,7 +108,7 @@ namespace Content.Server.AI.WorldState public abstract class CachedStateData : IAiState, ICachedState { public abstract string Name { get; } - protected IEntity Owner { get; private set; } = default!; + protected EntityUid Owner { get; private set; } = default!; private bool _cached; protected T Value = default!; private TimeSpan _lastCache = TimeSpan.Zero; @@ -117,7 +117,7 @@ namespace Content.Server.AI.WorldState /// protected double CacheTime { get; set; } = 2.0f; - public void Setup(IEntity owner) + public void Setup(EntityUid owner) { Owner = owner; } diff --git a/Content.Server/AI/WorldState/States/Clothing/EquippedClothingState.cs b/Content.Server/AI/WorldState/States/Clothing/EquippedClothingState.cs index 1314680392..695dc524a9 100644 --- a/Content.Server/AI/WorldState/States/Clothing/EquippedClothingState.cs +++ b/Content.Server/AI/WorldState/States/Clothing/EquippedClothingState.cs @@ -8,13 +8,13 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Clothing { [UsedImplicitly] - public sealed class EquippedClothingState : StateData> + public sealed class EquippedClothingState : StateData> { public override string Name => "EquippedClothing"; - public override Dictionary GetValue() + public override Dictionary GetValue() { - var result = new Dictionary(); + var result = new Dictionary(); if (!IoCManager.Resolve().TryGetComponent(Owner, out InventoryComponent? inventoryComponent)) { diff --git a/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs b/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs index 71f9f51b43..c239437713 100644 --- a/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs +++ b/Content.Server/AI/WorldState/States/Clothing/NearbyClothingState.cs @@ -11,13 +11,13 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Clothing { [UsedImplicitly] - public sealed class NearbyClothingState : CachedStateData> + public sealed class NearbyClothingState : CachedStateData> { public override string Name => "NearbyClothing"; - protected override List GetTrueValue() + protected override List GetTrueValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out AiControllerComponent? controller)) { diff --git a/Content.Server/AI/WorldState/States/Combat/Nearby/NearbyMeleeWeapons.cs b/Content.Server/AI/WorldState/States/Combat/Nearby/NearbyMeleeWeapons.cs index b064011b41..53d994031f 100644 --- a/Content.Server/AI/WorldState/States/Combat/Nearby/NearbyMeleeWeapons.cs +++ b/Content.Server/AI/WorldState/States/Combat/Nearby/NearbyMeleeWeapons.cs @@ -9,13 +9,13 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Combat.Nearby { [UsedImplicitly] - public sealed class NearbyMeleeWeapons : CachedStateData> + public sealed class NearbyMeleeWeapons : CachedStateData> { public override string Name => "NearbyMeleeWeapons"; - protected override List GetTrueValue() + protected override List GetTrueValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out AiControllerComponent? controller)) { diff --git a/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs b/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs index 369c7afd02..4ed2c20cc0 100644 --- a/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs +++ b/Content.Server/AI/WorldState/States/Combat/WeaponEntityState.cs @@ -4,13 +4,13 @@ using Robust.Shared.GameObjects; namespace Content.Server.AI.WorldState.States.Combat { [UsedImplicitly] - public sealed class WeaponEntityState : PlanningStateData + public sealed class WeaponEntityState : PlanningStateData { // Similar to TargetEntity public override string Name => "WeaponEntity"; public override void Reset() { - Value = null; + Value = default; } } } diff --git a/Content.Server/AI/WorldState/States/Hands/HandItemsState.cs b/Content.Server/AI/WorldState/States/Hands/HandItemsState.cs index 5c95083458..2a0ec7503b 100644 --- a/Content.Server/AI/WorldState/States/Hands/HandItemsState.cs +++ b/Content.Server/AI/WorldState/States/Hands/HandItemsState.cs @@ -7,12 +7,12 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Hands { [UsedImplicitly] - public class HandItemsState : StateData> + public class HandItemsState : StateData> { public override string Name => "HandItems"; - public override List GetValue() + public override List GetValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? handsComponent)) { return result; diff --git a/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs b/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs index 43547899a4..fb2c55b130 100644 --- a/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs +++ b/Content.Server/AI/WorldState/States/Inventory/EquippedEntityState.cs @@ -9,18 +9,18 @@ namespace Content.Server.AI.WorldState.States.Inventory /// AKA what's in active hand /// [UsedImplicitly] - public sealed class EquippedEntityState : StateData + public sealed class EquippedEntityState : StateData { public override string Name => "EquippedEntity"; - public override IEntity? GetValue() + public override EntityUid GetValue() { if (!IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? handsComponent)) { - return null; + return default; } - return handsComponent.GetActiveHand?.Owner; + return handsComponent.GetActiveHand?.Owner ?? default; } } } diff --git a/Content.Server/AI/WorldState/States/Inventory/InventoryState.cs b/Content.Server/AI/WorldState/States/Inventory/InventoryState.cs index dc6767bd90..857ffe4eb0 100644 --- a/Content.Server/AI/WorldState/States/Inventory/InventoryState.cs +++ b/Content.Server/AI/WorldState/States/Inventory/InventoryState.cs @@ -7,11 +7,11 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Inventory { [UsedImplicitly] - public sealed class EnumerableInventoryState : StateData> + public sealed class EnumerableInventoryState : StateData> { public override string Name => "EnumerableInventory"; - public override IEnumerable GetValue() + public override IEnumerable GetValue() { if (IoCManager.Resolve().TryGetComponent(Owner, out HandsComponent? handsComponent)) { diff --git a/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs b/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs index 9be38ae361..9471791287 100644 --- a/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs +++ b/Content.Server/AI/WorldState/States/Inventory/LastOpenedStorageState.cs @@ -9,16 +9,16 @@ namespace Content.Server.AI.WorldState.States.Inventory /// If we open a storage locker than it will be stored here /// Useful if we want to close it after /// - public sealed class LastOpenedStorageState : StoredStateData + public sealed class LastOpenedStorageState : StoredStateData { // TODO: IF we chain lockers need to handle it. // Fine for now I guess public override string Name => "LastOpenedStorage"; - public override void SetValue(IEntity? value) + public override void SetValue(EntityUid value) { base.SetValue(value); - if (value != null && !IoCManager.Resolve().HasComponent(value)) + if (value.Valid && !IoCManager.Resolve().HasComponent(value)) { Logger.Warning("Set LastOpenedStorageState for an entity that doesn't have a storage component"); } diff --git a/Content.Server/AI/WorldState/States/Mobs/NearbyBodiesState.cs b/Content.Server/AI/WorldState/States/Mobs/NearbyBodiesState.cs index b8e9dd89e2..4bbfe3957d 100644 --- a/Content.Server/AI/WorldState/States/Mobs/NearbyBodiesState.cs +++ b/Content.Server/AI/WorldState/States/Mobs/NearbyBodiesState.cs @@ -9,13 +9,13 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Mobs { [UsedImplicitly] - public sealed class NearbyBodiesState : CachedStateData> + public sealed class NearbyBodiesState : CachedStateData> { public override string Name => "NearbyBodies"; - protected override List GetTrueValue() + protected override List GetTrueValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out AiControllerComponent? controller)) { diff --git a/Content.Server/AI/WorldState/States/Mobs/NearbyPlayersState.cs b/Content.Server/AI/WorldState/States/Mobs/NearbyPlayersState.cs index a4a85e9020..e7cd8412ad 100644 --- a/Content.Server/AI/WorldState/States/Mobs/NearbyPlayersState.cs +++ b/Content.Server/AI/WorldState/States/Mobs/NearbyPlayersState.cs @@ -1,24 +1,21 @@ using System.Collections.Generic; -using System.Linq; using Content.Server.AI.Components; using Content.Shared.Damage; using JetBrains.Annotations; -using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Map; using Robust.Shared.Player; namespace Content.Server.AI.WorldState.States.Mobs { [UsedImplicitly] - public sealed class NearbyPlayersState : CachedStateData> + public sealed class NearbyPlayersState : CachedStateData> { public override string Name => "NearbyPlayers"; - protected override List GetTrueValue() + protected override List GetTrueValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out AiControllerComponent? controller)) { @@ -31,14 +28,14 @@ namespace Content.Server.AI.WorldState.States.Mobs foreach (var player in nearbyPlayers) { - if (player.AttachedEntity == null) + if (player.AttachedEntity is not {Valid: true} playerEntity) { continue; } - if (player.AttachedEntity != Owner && IoCManager.Resolve().HasComponent(player.AttachedEntity)) + if (player.AttachedEntity != Owner && IoCManager.Resolve().HasComponent(playerEntity)) { - result.Add(player.AttachedEntity); + result.Add(playerEntity); } } diff --git a/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs b/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs index 0acfa56ceb..48e8172ef3 100644 --- a/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs +++ b/Content.Server/AI/WorldState/States/Movement/MoveTargetState.cs @@ -4,12 +4,12 @@ using Robust.Shared.GameObjects; namespace Content.Server.AI.WorldState.States.Movement { [UsedImplicitly] - public sealed class MoveTargetState : PlanningStateData + public sealed class MoveTargetState : PlanningStateData { public override string Name => "MoveTarget"; public override void Reset() { - Value = null; + Value = default; } } } diff --git a/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs b/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs index 57377a0953..c69dcaaf60 100644 --- a/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs +++ b/Content.Server/AI/WorldState/States/Nutrition/NearbyDrinkState.cs @@ -11,13 +11,13 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Nutrition { [UsedImplicitly] - public sealed class NearbyDrinkState: CachedStateData> + public sealed class NearbyDrinkState: CachedStateData> { public override string Name => "NearbyDrink"; - protected override List GetTrueValue() + protected override List GetTrueValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out AiControllerComponent? controller)) { diff --git a/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs b/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs index c820b8d2b5..3614292748 100644 --- a/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs +++ b/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs @@ -11,13 +11,13 @@ using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Nutrition { [UsedImplicitly] - public sealed class NearbyFoodState : CachedStateData> + public sealed class NearbyFoodState : CachedStateData> { public override string Name => "NearbyFood"; - protected override List GetTrueValue() + protected override List GetTrueValue() { - var result = new List(); + var result = new List(); if (!IoCManager.Resolve().TryGetComponent(Owner, out AiControllerComponent? controller)) { diff --git a/Content.Server/AI/WorldState/States/SelfState.cs b/Content.Server/AI/WorldState/States/SelfState.cs index dc1ed00ac8..889bad9fc8 100644 --- a/Content.Server/AI/WorldState/States/SelfState.cs +++ b/Content.Server/AI/WorldState/States/SelfState.cs @@ -4,11 +4,11 @@ using Robust.Shared.GameObjects; namespace Content.Server.AI.WorldState.States { [UsedImplicitly] - public sealed class SelfState : StateData + public sealed class SelfState : StateData { public override string Name => "Self"; - public override IEntity GetValue() + public override EntityUid GetValue() { return Owner; } diff --git a/Content.Server/AI/WorldState/States/TargetEntityState.cs b/Content.Server/AI/WorldState/States/TargetEntityState.cs index de5b7edb2d..dea4c554fe 100644 --- a/Content.Server/AI/WorldState/States/TargetEntityState.cs +++ b/Content.Server/AI/WorldState/States/TargetEntityState.cs @@ -7,13 +7,13 @@ namespace Content.Server.AI.WorldState.States /// Could be target item to equip, target to attack, etc. /// [UsedImplicitly] - public sealed class TargetEntityState : PlanningStateData + public sealed class TargetEntityState : PlanningStateData { public override string Name => "TargetEntity"; public override void Reset() { - Value = null; + Value = default; } } } diff --git a/Content.Server/AME/AMENodeGroup.cs b/Content.Server/AME/AMENodeGroup.cs index f57d1605bb..4617946964 100644 --- a/Content.Server/AME/AMENodeGroup.cs +++ b/Content.Server/AME/AMENodeGroup.cs @@ -49,7 +49,6 @@ namespace Content.Server.AME if (IoCManager.Resolve().TryGetComponent(nodeOwner, out AMEShieldComponent? shield)) { var nodeNeighbors = grid.GetCellsInSquareArea(IoCManager.Resolve().GetComponent(nodeOwner).Coordinates, 1) - .Select(sgc => IoCManager.Resolve().GetEntity(sgc)) .Where(entity => entity != nodeOwner && IoCManager.Resolve().HasComponent(entity)); if (nodeNeighbors.Count() >= 8) diff --git a/Content.Server/AME/Components/AMEControllerComponent.cs b/Content.Server/AME/Components/AMEControllerComponent.cs index cf14a58492..7504c4971c 100644 --- a/Content.Server/AME/Components/AMEControllerComponent.cs +++ b/Content.Server/AME/Components/AMEControllerComponent.cs @@ -28,6 +28,8 @@ namespace Content.Server.AME.Components [ComponentReference(typeof(IInteractUsing))] public class AMEControllerComponent : SharedAMEControllerComponent, IActivate, IInteractUsing { + [Dependency] private readonly IEntityManager _entities = default!; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(AMEControllerUiKey.Key); private bool _injecting; [ViewVariables] public bool Injecting => _injecting; @@ -38,7 +40,7 @@ namespace Content.Server.AME.Components [DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"); [DataField("injectSound")] private SoundSpecifier _injectSound = new SoundPathSpecifier("/Audio/Effects/bang.ogg"); - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] private int _stability = 100; @@ -55,9 +57,9 @@ namespace Content.Server.AME.Components UserInterface.OnReceiveMessage += OnUiReceiveMessage; } - IoCManager.Resolve().TryGetComponent(Owner, out _appearance); + _entities.TryGetComponent(Owner, out _appearance); - IoCManager.Resolve().TryGetComponent(Owner, out _powerSupplier); + _entities.TryGetComponent(Owner, out _powerSupplier); _injecting = false; InjectionAmount = 2; @@ -92,11 +94,10 @@ namespace Content.Server.AME.Components return; } - var jar = _jarSlot.ContainedEntity; - if (jar is null) + if (_jarSlot.ContainedEntity is not {Valid: true} jar) return; - IoCManager.Resolve().TryGetComponent(jar, out var fuelJar); + _entities.TryGetComponent(jar, out var fuelJar); if (fuelJar != null && _powerSupplier != null) { var availableInject = fuelJar.FuelAmount >= InjectionAmount ? InjectionAmount : fuelJar.FuelAmount; @@ -120,12 +121,12 @@ namespace Content.Server.AME.Components /// Data relevant to the event such as the actor which triggered it. void IActivate.Activate(ActivateEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!_entities.TryGetComponent(args.User, out ActorComponent? actor)) { return; } - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!_entities.TryGetComponent(args.User, out HandsComponent? hands)) { Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-no-hands-text")); return; @@ -151,14 +152,13 @@ namespace Content.Server.AME.Components private AMEControllerBoundUserInterfaceState GetUserInterfaceState() { - var jar = _jarSlot.ContainedEntity; - if (jar == null) + if (_jarSlot.ContainedEntity is not {Valid: true} jar) { return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), false, HasJar, 0, InjectionAmount, GetCoreCount()); } - var jarcomponent = IoCManager.Resolve().GetComponent(jar); - return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), _injecting, HasJar, jarcomponent.FuelAmount, InjectionAmount, GetCoreCount()); + var jarComponent = _entities.GetComponent(jar); + return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), _injecting, HasJar, jarComponent.FuelAmount, InjectionAmount, GetCoreCount()); } /// @@ -166,10 +166,10 @@ namespace Content.Server.AME.Components /// /// The player entity. /// Returns true if the entity can use the controller, and false if it cannot. - private bool PlayerCanUseController(IEntity playerEntity, bool needsPower = true) + private bool PlayerCanUseController(EntityUid playerEntity, bool needsPower = true) { //Need player entity to check if they are still able to use the dispenser - if (playerEntity == null) + if (playerEntity == default) return false; var actionBlocker = EntitySystem.Get(); @@ -197,7 +197,7 @@ namespace Content.Server.AME.Components /// A user interface message from the client. private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) { - if (obj.Session.AttachedEntity == null) + if (obj.Session.AttachedEntity is not {Valid: true} player) { return; } @@ -209,13 +209,13 @@ namespace Content.Server.AME.Components _ => true, }; - if (!PlayerCanUseController(obj.Session.AttachedEntity, needsPower)) + if (!PlayerCanUseController(player, needsPower)) return; switch (msg.Button) { case UiButton.Eject: - TryEject(obj.Session.AttachedEntity); + TryEject(player); break; case UiButton.ToggleInjection: ToggleInjection(); @@ -234,19 +234,18 @@ namespace Content.Server.AME.Components ClickSound(); } - private void TryEject(IEntity user) + private void TryEject(EntityUid user) { if (!HasJar || _injecting) return; - var jar = _jarSlot.ContainedEntity; - if (jar is null) + if (_jarSlot.ContainedEntity is not {Valid: true} jar) return; _jarSlot.Remove(jar); UpdateUserInterface(); - if (!IoCManager.Resolve().TryGetComponent(user, out var hands) || !IoCManager.Resolve().TryGetComponent(jar, out var item)) + if (!_entities.TryGetComponent(user, out var hands) || !_entities.TryGetComponent(jar, out var item)) return; if (hands.CanPutInHand(item)) hands.PutInHand(item); @@ -290,7 +289,7 @@ namespace Content.Server.AME.Components private AMENodeGroup? GetAMENodeGroup() { - IoCManager.Resolve().TryGetComponent(Owner, out NodeContainerComponent? nodeContainer); + _entities.TryGetComponent(Owner, out NodeContainerComponent? nodeContainer); var engineNodeGroup = nodeContainer?.Nodes.Values .Select(node => node.NodeGroup) @@ -336,7 +335,7 @@ namespace Content.Server.AME.Components async Task IInteractUsing.InteractUsing(InteractUsingEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!_entities.TryGetComponent(args.User, out HandsComponent? hands)) { Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-no-hands-text")); return true; @@ -349,7 +348,7 @@ namespace Content.Server.AME.Components } var activeHandEntity = hands.GetActiveHand.Owner; - if (IoCManager.Resolve().TryGetComponent(activeHandEntity, out var fuelContainer)) + if (_entities.HasComponent(activeHandEntity)) { if (HasJar) { diff --git a/Content.Server/AME/Components/AMEPartComponent.cs b/Content.Server/AME/Components/AMEPartComponent.cs index c3da184a86..4858674075 100644 --- a/Content.Server/AME/Components/AMEPartComponent.cs +++ b/Content.Server/AME/Components/AMEPartComponent.cs @@ -58,7 +58,7 @@ namespace Content.Server.AME.Components SoundSystem.Play(Filter.Pvs(Owner), _unwrapSound.GetSound(), Owner); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); return true; } diff --git a/Content.Server/Access/AccessReaderChangeMessage.cs b/Content.Server/Access/AccessReaderChangeMessage.cs index e9a71e59ac..ff2600a2b1 100644 --- a/Content.Server/Access/AccessReaderChangeMessage.cs +++ b/Content.Server/Access/AccessReaderChangeMessage.cs @@ -4,11 +4,11 @@ namespace Content.Server.Access { public sealed class AccessReaderChangeMessage : EntityEventArgs { - public IEntity Sender { get; } + public EntityUid Sender { get; } public bool Enabled { get; } - public AccessReaderChangeMessage(IEntity entity, bool enabled) + public AccessReaderChangeMessage(EntityUid entity, bool enabled) { Sender = entity; Enabled = enabled; diff --git a/Content.Server/Access/Components/IdCardConsoleComponent.cs b/Content.Server/Access/Components/IdCardConsoleComponent.cs index 5c57f8acf1..8a3d400317 100644 --- a/Content.Server/Access/Components/IdCardConsoleComponent.cs +++ b/Content.Server/Access/Components/IdCardConsoleComponent.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using Content.Server.Access.Systems; @@ -6,7 +5,6 @@ using Content.Server.Power.Components; using Content.Server.UserInterface; using Content.Shared.Access; using Content.Shared.Containers.ItemSlots; -using Content.Shared.Interaction; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -21,9 +19,10 @@ namespace Content.Server.Access.Components public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key); - [ViewVariables] private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + [ViewVariables] private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; protected override void Initialize() { @@ -40,7 +39,7 @@ namespace Content.Server.Access.Components private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) { - if (obj.Session.AttachedEntity == null) + if (obj.Session.AttachedEntity is not {Valid: true} player) { return; } @@ -51,10 +50,10 @@ namespace Content.Server.Access.Components switch (msg.Button) { case UiButton.PrivilegedId: - HandleIdButton(obj.Session.AttachedEntity, PrivilegedIdSlot); + HandleIdButton(player, PrivilegedIdSlot); break; case UiButton.TargetId: - HandleIdButton(obj.Session.AttachedEntity, TargetIdSlot); + HandleIdButton(player, TargetIdSlot); break; } break; @@ -70,14 +69,14 @@ namespace Content.Server.Access.Components /// private bool PrivilegedIdIsAuthorized() { - if (!IoCManager.Resolve().TryGetComponent(Owner, out AccessReader? reader)) + if (!_entities.TryGetComponent(Owner, out AccessReader? reader)) { return true; } var privilegedIdEntity = PrivilegedIdSlot.Item; var accessSystem = EntitySystem.Get(); - return privilegedIdEntity != null && accessSystem.IsAllowed(reader, privilegedIdEntity); + return privilegedIdEntity != null && accessSystem.IsAllowed(reader, privilegedIdEntity.Value); } /// @@ -86,8 +85,7 @@ namespace Content.Server.Access.Components /// private void TryWriteToTargetId(string newFullName, string newJobTitle, List newAccessList) { - var targetIdEntity = TargetIdSlot.Item; - if (targetIdEntity == null || !PrivilegedIdIsAuthorized()) + if (TargetIdSlot.Item is not {Valid: true} targetIdEntity || !PrivilegedIdIsAuthorized()) return; var cardSystem = EntitySystem.Get(); @@ -107,7 +105,7 @@ namespace Content.Server.Access.Components /// /// Called when one of the insert/remove ID buttons gets pressed. /// - private void HandleIdButton(IEntity user, ItemSlot slot) + private void HandleIdButton(EntityUid user, ItemSlot slot) { if (slot.HasItem) EntitySystem.Get().TryEjectToHands(((IComponent) this).Owner, slot, user); @@ -117,12 +115,16 @@ namespace Content.Server.Access.Components public void UpdateUserInterface() { - var targetIdEntity = TargetIdSlot.Item; IdCardConsoleBoundUserInterfaceState newState; // this could be prettier - if (targetIdEntity == null) + if (TargetIdSlot.Item is not {Valid: true} targetIdEntity) { - IEntity? tempQualifier = PrivilegedIdSlot.Item; + var privilegedIdName = string.Empty; + if (PrivilegedIdSlot.Item is {Valid: true} item) + { + privilegedIdName = _entities.GetComponent(item).EntityName; + } + newState = new IdCardConsoleBoundUserInterfaceState( PrivilegedIdSlot.HasItem, PrivilegedIdIsAuthorized(), @@ -130,16 +132,16 @@ namespace Content.Server.Access.Components null, null, null, - (tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier).EntityName : null) ?? string.Empty, + privilegedIdName, string.Empty); } else { - var targetIdComponent = IoCManager.Resolve().GetComponent(targetIdEntity); - var targetAccessComponent = IoCManager.Resolve().GetComponent(targetIdEntity); + var targetIdComponent = _entities.GetComponent(targetIdEntity); + var targetAccessComponent = _entities.GetComponent(targetIdEntity); var name = string.Empty; - if(PrivilegedIdSlot.Item != null) - name = IoCManager.Resolve().GetComponent(PrivilegedIdSlot.Item).EntityName; + if (PrivilegedIdSlot.Item is {Valid: true} item) + name = _entities.GetComponent(item).EntityName; newState = new IdCardConsoleBoundUserInterfaceState( PrivilegedIdSlot.HasItem, PrivilegedIdIsAuthorized(), @@ -148,7 +150,7 @@ namespace Content.Server.Access.Components targetIdComponent.JobTitle, targetAccessComponent.Tags.ToArray(), name, - IoCManager.Resolve().GetComponent(targetIdEntity).EntityName); + _entities.GetComponent(targetIdEntity).EntityName); } UserInterface?.SetState(newState); } diff --git a/Content.Server/Access/Systems/AccessReaderSystem.cs b/Content.Server/Access/Systems/AccessReaderSystem.cs index 45ee5116c7..0a14852427 100644 --- a/Content.Server/Access/Systems/AccessReaderSystem.cs +++ b/Content.Server/Access/Systems/AccessReaderSystem.cs @@ -1,3 +1,7 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; using Content.Server.Access.Components; using Content.Server.Inventory.Components; using Content.Server.Items; @@ -9,10 +13,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Prototypes; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; namespace Content.Server.Access.Systems { @@ -106,16 +106,11 @@ namespace Content.Server.Access.Systems return true; } - if (EntityManager.TryGetComponent(uid, out PDAComponent? pda)) + if (EntityManager.TryGetComponent(uid, out PDAComponent? pda) && + pda.ContainedID?.Owner is {Valid: true} id) { - IEntity tempQualifier = pda?.ContainedID?.Owner; - if (tempQualifier != null) - { - IoCManager.Resolve().GetComponent(tempQualifier); - } - - tags = RETURNED_VALUE?.Tags; - return tags != null; + tags = EntityManager.GetComponent(id).Tags; + return true; } tags = null; diff --git a/Content.Server/Act/IDisarmedAct.cs b/Content.Server/Act/IDisarmedAct.cs index d32912451d..42571c7c86 100644 --- a/Content.Server/Act/IDisarmedAct.cs +++ b/Content.Server/Act/IDisarmedAct.cs @@ -29,12 +29,12 @@ namespace Content.Server.Act /// /// The entity being disarmed. /// - public IEntity? Target { get; init; } + public EntityUid Target { get; init; } /// /// The entity performing the disarm. /// - public IEntity? Source { get; init; } + public EntityUid Source { get; init; } /// /// Probability for push/knockdown. diff --git a/Content.Server/Act/ISuicideAct.cs b/Content.Server/Act/ISuicideAct.cs index b8e7c3f571..6865e915ea 100644 --- a/Content.Server/Act/ISuicideAct.cs +++ b/Content.Server/Act/ISuicideAct.cs @@ -7,7 +7,7 @@ namespace Content.Server.Act [RequiresExplicitImplementation] public interface ISuicideAct { - public SuicideKind Suicide(IEntity victim, IChatManager chat); + public SuicideKind Suicide(EntityUid victim, IChatManager chat); } public enum SuicideKind diff --git a/Content.Server/Actions/Actions/DisarmAction.cs b/Content.Server/Actions/Actions/DisarmAction.cs index 2140ef6c1f..a3cfb5c2e8 100644 --- a/Content.Server/Actions/Actions/DisarmAction.cs +++ b/Content.Server/Actions/Actions/DisarmAction.cs @@ -1,5 +1,9 @@ +using System; +using System.Linq; using Content.Server.Act; +using Content.Server.Administration.Logs; using Content.Server.Interaction; +using Content.Server.Popups; using Content.Server.Weapon.Melee; using Content.Shared.ActionBlocker; using Content.Shared.Actions; @@ -7,7 +11,9 @@ using Content.Shared.Actions.Behaviors; using Content.Shared.Actions.Components; using Content.Shared.Audio; using Content.Shared.Cooldown; +using Content.Shared.Database; using Content.Shared.Interaction.Helpers; +using Content.Shared.Popups; using Content.Shared.Sound; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -20,14 +26,6 @@ using Robust.Shared.Player; using Robust.Shared.Random; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using System; -using System.Collections.Generic; -using System.Linq; -using Content.Server.Administration.Logs; -using Content.Server.Popups; -using Content.Shared.Administration.Logs; -using Content.Shared.Database; -using Content.Shared.Popups; namespace Content.Server.Actions.Actions { @@ -60,7 +58,7 @@ namespace Content.Server.Actions.Actions // Fall back to a normal interaction with the entity var player = actor.PlayerSession; var coordinates = IoCManager.Resolve().GetComponent(args.Target).Coordinates; - var target = (EntityUid) args.Target; + var target = args.Target; EntitySystem.Get().HandleUseInteraction(player, coordinates, target); return; } diff --git a/Content.Server/Actions/Commands/CooldownAction.cs b/Content.Server/Actions/Commands/CooldownAction.cs index cb5e8d9b1a..ffb9b45519 100644 --- a/Content.Server/Actions/Commands/CooldownAction.cs +++ b/Content.Server/Actions/Commands/CooldownAction.cs @@ -30,7 +30,7 @@ namespace Content.Server.Actions.Commands } if (attachedEntity == null) return; - if (!IoCManager.Resolve().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent)) + if (!IoCManager.Resolve().TryGetComponent(attachedEntity.Value, out ServerActionsComponent? actionsComponent)) { shell.WriteLine("user has no actions component"); return; diff --git a/Content.Server/Actions/Commands/GrantAction.cs b/Content.Server/Actions/Commands/GrantAction.cs index 3df0bc6050..6c828dcd38 100644 --- a/Content.Server/Actions/Commands/GrantAction.cs +++ b/Content.Server/Actions/Commands/GrantAction.cs @@ -28,7 +28,7 @@ namespace Content.Server.Actions.Commands } if (attachedEntity == null) return; - if (!IoCManager.Resolve().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent)) + if (!IoCManager.Resolve().TryGetComponent(attachedEntity.Value, out ServerActionsComponent? actionsComponent)) { shell.WriteLine("user has no actions component"); return; diff --git a/Content.Server/Actions/Commands/RevokeAction.cs b/Content.Server/Actions/Commands/RevokeAction.cs index 094b1c0e28..91fcc194d0 100644 --- a/Content.Server/Actions/Commands/RevokeAction.cs +++ b/Content.Server/Actions/Commands/RevokeAction.cs @@ -28,7 +28,7 @@ namespace Content.Server.Actions.Commands if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return; } if (attachedEntity == null) return; - if (!IoCManager.Resolve().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent)) + if (!IoCManager.Resolve().TryGetComponent(attachedEntity.Value, out ServerActionsComponent? actionsComponent)) { shell.WriteLine("user has no actions component"); return; diff --git a/Content.Server/Actions/ServerActionsComponent.cs b/Content.Server/Actions/ServerActionsComponent.cs index fb51fda434..703e276174 100644 --- a/Content.Server/Actions/ServerActionsComponent.cs +++ b/Content.Server/Actions/ServerActionsComponent.cs @@ -1,12 +1,8 @@ using System; -using Content.Shared.ActionBlocker; using Content.Shared.Actions; using Content.Shared.Actions.Components; using Content.Shared.Actions.Prototypes; -using Content.Shared.Interaction.Events; using Content.Shared.Interaction; -using Robust.Server.GameObjects; -using Robust.Server.GameStates; using Robust.Shared; using Robust.Shared.Configuration; using Robust.Shared.GameObjects; @@ -24,6 +20,7 @@ namespace Content.Server.Actions public sealed class ServerActionsComponent : SharedActionsComponent { [Dependency] private readonly IConfigurationManager _configManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; private float MaxUpdateRange; @@ -55,15 +52,14 @@ namespace Content.Server.Actions throw new ArgumentNullException(nameof(session)); } - var player = session.AttachedEntity; - if (player != Owner) return; + if (session.AttachedEntity is not {Valid: true} player || player != Owner) return; var attempt = ActionAttempt(performActionMessage, session); if (attempt == null) return; if (!attempt.TryGetActionState(this, out var actionState) || !actionState.Enabled) { Logger.DebugS("action", "user {0} attempted to use" + - " action {1} which is not granted to them", IoCManager.Resolve().GetComponent(player).EntityName, + " action {1} which is not granted to them", _entities.GetComponent(player).EntityName, attempt); return; } @@ -71,7 +67,7 @@ namespace Content.Server.Actions if (actionState.IsOnCooldown(GameTiming)) { Logger.DebugS("action", "user {0} attempted to use" + - " action {1} which is on cooldown", IoCManager.Resolve().GetComponent(player).EntityName, + " action {1} which is on cooldown", _entities.GetComponent(player).EntityName, attempt); return; } @@ -86,7 +82,7 @@ namespace Content.Server.Actions if (toggleMsg.ToggleOn == actionState.ToggledOn) { Logger.DebugS("action", "user {0} attempted to" + - " toggle action {1} to {2}, but it is already toggled {2}", IoCManager.Resolve().GetComponent(player).EntityName, + " toggle action {1} to {2}, but it is already toggled {2}", _entities.GetComponent(player).EntityName, attempt.Action.Name, toggleMsg.ToggleOn); return; } @@ -109,17 +105,17 @@ namespace Content.Server.Actions break; case BehaviorType.TargetEntity: if (performActionMessage is not ITargetEntityActionMessage targetEntityMsg) return; - if (!EntityManager.TryGetEntity(targetEntityMsg.Target, out var entity)) + if (!EntityManager.EntityExists(targetEntityMsg.Target)) { Logger.DebugS("action", "user {0} attempted to" + " perform target entity action {1} but could not find entity with " + - "provided uid {2}", IoCManager.Resolve().GetComponent(player).EntityName, attempt.Action.Name, + "provided uid {2}", _entities.GetComponent(player).EntityName, attempt.Action.Name, targetEntityMsg.Target); return; } - if (!CheckRangeAndSetFacing(IoCManager.Resolve().GetComponent(entity).Coordinates, player)) return; + if (!CheckRangeAndSetFacing(_entities.GetComponent(targetEntityMsg.Target).Coordinates, player)) return; - attempt.DoTargetEntityAction(player, entity); + attempt.DoTargetEntityAction(player, targetEntityMsg.Target); break; case BehaviorType.None: break; @@ -131,48 +127,52 @@ namespace Content.Server.Actions private IActionAttempt? ActionAttempt(BasePerformActionMessage message, ICommonSession session) { IActionAttempt? attempt; + var player = session.AttachedEntity; + switch (message) { case PerformActionMessage performActionMessage: if (!ActionManager.TryGet(performActionMessage.ActionType, out var action)) { Logger.DebugS("action", "user {0} attempted to perform" + - " unrecognized action {1}", session.AttachedEntity, + " unrecognized action {1}", player, performActionMessage.ActionType); return null; } attempt = new ActionAttempt(action); break; case PerformItemActionMessage performItemActionMessage: - if (!ActionManager.TryGet(performItemActionMessage.ActionType, out var itemAction)) + var type = performItemActionMessage.ActionType; + if (!ActionManager.TryGet(type, out var itemAction)) { Logger.DebugS("action", "user {0} attempted to perform" + " unrecognized item action {1}", - session.AttachedEntity, performItemActionMessage.ActionType); + player, type); return null; } - if (!EntityManager.TryGetEntity(performItemActionMessage.Item, out var item)) + var item = performItemActionMessage.Item; + if (!EntityManager.EntityExists(item)) { Logger.DebugS("action", "user {0} attempted to perform" + " item action {1} for unknown item {2}", - session.AttachedEntity, performItemActionMessage.ActionType, performItemActionMessage.Item); + player, type, item); return null; } - if (!IoCManager.Resolve().TryGetComponent(item, out var actionsComponent)) + if (!_entities.TryGetComponent(item, out var actionsComponent)) { Logger.DebugS("action", "user {0} attempted to perform" + " item action {1} for item {2} which has no ItemActionsComponent", - session.AttachedEntity, performItemActionMessage.ActionType, item); + player, type, item); return null; } - if (actionsComponent.Holder != session.AttachedEntity) + if (actionsComponent.Holder != player) { Logger.DebugS("action", "user {0} attempted to perform" + " item action {1} for item {2} which they are not holding", - session.AttachedEntity, performItemActionMessage.ActionType, item); + player, type, item); return null; } @@ -186,7 +186,7 @@ namespace Content.Server.Actions { Logger.DebugS("action", "user {0} attempted to" + " perform action {1} as a {2} behavior, but this action is actually a" + - " {3} behavior", session.AttachedEntity, attempt, message.BehaviorType, + " {3} behavior", player, attempt, message.BehaviorType, attempt.Action.BehaviorType); return null; } @@ -194,17 +194,17 @@ namespace Content.Server.Actions return attempt; } - private bool CheckRangeAndSetFacing(EntityCoordinates target, IEntity player) + private bool CheckRangeAndSetFacing(EntityCoordinates target, EntityUid player) { // ensure it's within their clickable range var targetWorldPos = target.ToMapPos(EntityManager); - var rangeBox = new Box2(IoCManager.Resolve().GetComponent(player).WorldPosition, IoCManager.Resolve().GetComponent(player).WorldPosition) + var rangeBox = new Box2(_entities.GetComponent(player).WorldPosition, _entities.GetComponent(player).WorldPosition) .Enlarged(MaxUpdateRange); if (!rangeBox.Contains(targetWorldPos)) { Logger.DebugS("action", "user {0} attempted to" + " perform target action further than allowed range", - IoCManager.Resolve().GetComponent(player).EntityName); + _entities.GetComponent(player).EntityName); return false; } diff --git a/Content.Server/Actions/Spells/GiveItemSpell.cs b/Content.Server/Actions/Spells/GiveItemSpell.cs index 21f472771f..e1c4f9323a 100644 --- a/Content.Server/Actions/Spells/GiveItemSpell.cs +++ b/Content.Server/Actions/Spells/GiveItemSpell.cs @@ -57,7 +57,7 @@ namespace Content.Server.Actions.Spells if (!IoCManager.Resolve().TryGetComponent(spawnedProto, out ItemComponent? itemComponent)) { Logger.Error($"Tried to use {nameof(GiveItemSpell)} but prototype has no {nameof(ItemComponent)}?"); - IoCManager.Resolve().DeleteEntity((EntityUid) spawnedProto); + IoCManager.Resolve().DeleteEntity(spawnedProto); return; } diff --git a/Content.Server/Administration/AdminSystem.cs b/Content.Server/Administration/AdminSystem.cs index 0da1c32f89..52f4a62c76 100644 --- a/Content.Server/Administration/AdminSystem.cs +++ b/Content.Server/Administration/AdminSystem.cs @@ -125,13 +125,12 @@ namespace Content.Server.Administration var name = session.Name; var username = string.Empty; - if(session.AttachedEntity != null) - username = IoCManager.Resolve().GetComponent(session.AttachedEntity).EntityName; + if (session.AttachedEntity != default) + username = EntityManager.GetComponent(session.AttachedEntity.Value).EntityName; var antag = session.ContentData()?.Mind?.AllRoles.Any(r => r.Antagonist) ?? false; - var uid = session.AttachedEntity ?? EntityUid.Invalid; - return new PlayerInfo(name, username, antag, uid, session.UserId); + return new PlayerInfo(name, username, antag, session.AttachedEntity ?? default, session.UserId); } } } diff --git a/Content.Server/Administration/AdminVerbSystem.cs b/Content.Server/Administration/AdminVerbSystem.cs index 0b422cad5b..e22bf17073 100644 --- a/Content.Server/Administration/AdminVerbSystem.cs +++ b/Content.Server/Administration/AdminVerbSystem.cs @@ -15,7 +15,6 @@ using Content.Server.Mind.Commands; using Content.Server.Mind.Components; using Content.Server.Players; using Content.Shared.Administration; -using Content.Shared.Administration.Logs; using Content.Shared.Body.Components; using Content.Shared.Database; using Content.Shared.GameTicking; @@ -56,7 +55,7 @@ namespace Content.Server.Administration private void AddDebugVerbs(GetOtherVerbsEvent args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out var actor)) + if (!EntityManager.TryGetComponent(args.User, out var actor)) return; var player = actor.PlayerSession; @@ -68,7 +67,7 @@ namespace Content.Server.Administration verb.Text = Loc.GetString("delete-verb-get-data-text"); verb.Category = VerbCategory.Debug; verb.IconTexture = "/Textures/Interface/VerbIcons/delete_transparent.svg.192dpi.png"; - verb.Act = () => IoCManager.Resolve().DeleteEntity((EntityUid) args.Target); + verb.Act = () => EntityManager.DeleteEntity(args.Target); verb.Impact = LogImpact.Medium; args.Verbs.Add(verb); } @@ -88,8 +87,8 @@ namespace Content.Server.Administration // Control mob verb if (_groupController.CanCommand(player, "controlmob") && args.User != args.Target && - IoCManager.Resolve().HasComponent(args.User) && - IoCManager.Resolve().TryGetComponent(args.Target, out var targetMind)) + EntityManager.HasComponent(args.User) && + EntityManager.TryGetComponent(args.Target, out var targetMind)) { Verb verb = new(); verb.Text = Loc.GetString("control-mob-verb-get-data-text"); @@ -106,7 +105,7 @@ namespace Content.Server.Administration // Make Sentient verb if (_groupController.CanCommand(player, "makesentient") && args.User != args.Target && - !IoCManager.Resolve().HasComponent(args.Target)) + !EntityManager.HasComponent(args.Target)) { Verb verb = new(); verb.Text = Loc.GetString("make-sentient-verb-get-data-text"); @@ -125,9 +124,9 @@ namespace Content.Server.Administration verb.Category = VerbCategory.Debug; verb.Act = () => { - var coords = IoCManager.Resolve().GetComponent(args.Target).Coordinates; + var coords = EntityManager.GetComponent(args.Target).Coordinates; Timer.Spawn(_gameTiming.TickPeriod, () => _explosions.SpawnExplosion(coords, 0, 1, 2, 1), CancellationToken.None); - if (IoCManager.Resolve().TryGetComponent(args.Target, out SharedBodyComponent? body)) + if (EntityManager.TryGetComponent(args.Target, out SharedBodyComponent? body)) { body.Gib(); } @@ -138,7 +137,7 @@ namespace Content.Server.Administration // Set clothing verb if (_groupController.CanCommand(player, "setoutfit") && - IoCManager.Resolve().HasComponent(args.Target)) + EntityManager.HasComponent(args.Target)) { Verb verb = new(); verb.Text = Loc.GetString("set-outfit-verb-get-data-text"); @@ -168,7 +167,7 @@ namespace Content.Server.Administration // Get Disposal tube direction verb if (_groupController.CanCommand(player, "tubeconnections") && - IoCManager.Resolve().TryGetComponent(args.Target, out var tube)) + EntityManager.TryGetComponent(args.Target, out var tube)) { Verb verb = new(); verb.Text = Loc.GetString("tube-direction-verb-get-data-text"); @@ -180,7 +179,7 @@ namespace Content.Server.Administration // Make ghost role verb if (_groupController.CanCommand(player, "makeghostrole") && - !(IoCManager.Resolve().GetComponentOrNull(args.TargetUid)?.HasMind ?? false)) + !(EntityManager.GetComponentOrNull(args.Target)?.HasMind ?? false)) { Verb verb = new(); verb.Text = Loc.GetString("make-ghost-role-verb-get-data-text"); @@ -194,7 +193,7 @@ namespace Content.Server.Administration // Configuration verb. Is this even used for anything!? if (_groupController.CanAdminMenu(player) && - IoCManager.Resolve().TryGetComponent(args.TargetUid, out var config)) + EntityManager.TryGetComponent(args.Target, out var config)) { Verb verb = new(); verb.Text = Loc.GetString("configure-verb-get-data-text"); @@ -206,7 +205,7 @@ namespace Content.Server.Administration // Add verb to open Solution Editor if (_groupController.CanCommand(player, "addreagent") && - IoCManager.Resolve().HasComponent(args.Target)) + EntityManager.HasComponent(args.Target)) { Verb verb = new(); verb.Text = Loc.GetString("edit-solutions-verb-get-data-text"); diff --git a/Content.Server/Administration/Commands/AGhost.cs b/Content.Server/Administration/Commands/AGhost.cs index b93df56ebb..ec639a76f7 100644 --- a/Content.Server/Administration/Commands/AGhost.cs +++ b/Content.Server/Administration/Commands/AGhost.cs @@ -7,13 +7,14 @@ using Robust.Server.Player; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Map; namespace Content.Server.Administration.Commands { [AdminCommand(AdminFlags.Admin)] public class AGhost : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "aghost"; public string Description => "Makes you an admin ghost."; public string Help => "aghost"; @@ -35,34 +36,35 @@ namespace Content.Server.Administration.Commands return; } - if (mind.VisitingEntity != null && IoCManager.Resolve().HasComponent(mind.VisitingEntity)) + if (mind.VisitingEntity != default && _entities.HasComponent(mind.VisitingEntity)) { player.ContentData()!.Mind?.UnVisit(); return; } - var canReturn = mind.CurrentEntity != null; - IEntity? tempQualifier = player.AttachedEntity; - var ghost = IoCManager.Resolve().SpawnEntity((string?) "AdminObserver", (EntityCoordinates) ((tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier) : null).Coordinates - ?? EntitySystem.Get().GetObserverSpawnPoint())); + var canReturn = mind.CurrentEntity != default; + var coordinates = player.AttachedEntity.HasValue + ? _entities.GetComponent(player.AttachedEntity.Value).Coordinates + : EntitySystem.Get().GetObserverSpawnPoint(); + var ghost = _entities.SpawnEntity("AdminObserver", coordinates); if (canReturn) { // TODO: Remove duplication between all this and "GamePreset.OnGhostAttempt()"... 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; mind.Visit(ghost); } else { - IoCManager.Resolve().GetComponent(ghost).EntityName = player.Name; + _entities.GetComponent(ghost).EntityName = player.Name; mind.TransferTo(ghost); } - var comp = IoCManager.Resolve().GetComponent(ghost); + var comp = _entities.GetComponent(ghost); EntitySystem.Get().SetCanReturnToBody(comp, canReturn); } } diff --git a/Content.Server/Administration/Commands/AddEntityStorageCommand.cs b/Content.Server/Administration/Commands/AddEntityStorageCommand.cs index 85da28ad53..d3385136cd 100644 --- a/Content.Server/Administration/Commands/AddEntityStorageCommand.cs +++ b/Content.Server/Administration/Commands/AddEntityStorageCommand.cs @@ -38,7 +38,7 @@ namespace Content.Server.Administration.Commands if (entityManager.TryGetComponent(storageUid, out var storage)) { - storage.Insert(entityManager.GetEntity(entityUid)); + storage.Insert(entityUid); } else { diff --git a/Content.Server/Administration/Commands/ControlMob.cs b/Content.Server/Administration/Commands/ControlMob.cs index 0bfe8cc4e9..6dae68645e 100644 --- a/Content.Server/Administration/Commands/ControlMob.cs +++ b/Content.Server/Administration/Commands/ControlMob.cs @@ -13,14 +13,15 @@ namespace Content.Server.Administration.Commands [AdminCommand(AdminFlags.Admin)] class ControlMob : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "controlmob"; public string Description => Loc.GetString("control-mob-command-description"); public string Help => Loc.GetString("control-mob-command-help-text"); public void Execute(IConsoleShell shell, string argStr, string[] args) { - var player = shell.Player as IPlayerSession; - if (player == null) + if (shell.Player is not IPlayerSession player) { shell.WriteLine("shell-server-cannot"); return; @@ -32,25 +33,21 @@ namespace Content.Server.Administration.Commands return; } - - var entityManager = IoCManager.Resolve(); - if (!int.TryParse(args[0], out var targetId)) { shell.WriteLine(Loc.GetString("shell-argument-must-be-number")); return; } - var eUid = new EntityUid(targetId); + var target = new EntityUid(targetId); - if (!eUid.IsValid() || !entityManager.EntityExists(eUid)) + if (!target.IsValid() || !_entities.EntityExists(target)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } - var target = entityManager.GetEntity(eUid); - if (!IoCManager.Resolve().TryGetComponent(target, out MindComponent? mindComponent)) + if (!_entities.HasComponent(target)) { shell.WriteLine(Loc.GetString("shell-entity-is-not-mob")); return; diff --git a/Content.Server/Administration/Commands/DeleteComponent.cs b/Content.Server/Administration/Commands/DeleteComponent.cs index 868466d013..d848b1312b 100644 --- a/Content.Server/Administration/Commands/DeleteComponent.cs +++ b/Content.Server/Administration/Commands/DeleteComponent.cs @@ -37,7 +37,7 @@ namespace Content.Server.Administration.Commands foreach (var component in components) { - var uid = (EntityUid) component.Owner; + var uid = component.Owner; entityManager.RemoveComponent(uid, component); i++; } diff --git a/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs b/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs index 07fde752d8..18ca44536c 100644 --- a/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs +++ b/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs @@ -37,12 +37,12 @@ namespace Content.Server.Administration.Commands var entityManager = IoCManager.Resolve(); var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner)); - var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; }); + var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; }); var count = 0; foreach (var entity in entitiesWithAllComponents) { - IoCManager.Resolve().DeleteEntity((EntityUid) entity); + IoCManager.Resolve().DeleteEntity(entity); count += 1; } diff --git a/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs b/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs index 730aded3e7..56c2d1b4ee 100644 --- a/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs +++ b/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs @@ -1,9 +1,8 @@ +using System.Linq; using Content.Shared.Administration; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using System.Linq; -using Robust.Shared.Prototypes; namespace Content.Server.Administration.Commands { @@ -29,7 +28,7 @@ namespace Content.Server.Administration.Commands foreach (var entity in entities) { - IoCManager.Resolve().DeleteEntity((EntityUid) entity); + IoCManager.Resolve().DeleteEntity(entity); i++; } diff --git a/Content.Server/Administration/Commands/DeleteEntityCommand.cs b/Content.Server/Administration/Commands/DeleteEntityCommand.cs index 79c6623842..5a35db8c2b 100644 --- a/Content.Server/Administration/Commands/DeleteEntityCommand.cs +++ b/Content.Server/Administration/Commands/DeleteEntityCommand.cs @@ -28,13 +28,13 @@ namespace Content.Server.Administration.Commands var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetEntity(id, out var entity)) + if (!entityManager.EntityExists(id)) { shell.WriteLine($"No entity found with id {id}."); return; } - IoCManager.Resolve().DeleteEntity((EntityUid) entity); + IoCManager.Resolve().DeleteEntity(id); shell.WriteLine($"Deleted entity with id {id}."); } } diff --git a/Content.Server/Administration/Commands/ExplosionCommand.cs b/Content.Server/Administration/Commands/ExplosionCommand.cs index 1b2d77bdfd..6e94dc4030 100644 --- a/Content.Server/Administration/Commands/ExplosionCommand.cs +++ b/Content.Server/Administration/Commands/ExplosionCommand.cs @@ -19,7 +19,7 @@ namespace Content.Server.Administration.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { var player = shell.Player as IPlayerSession; - if (player?.AttachedEntity == null) + if (player?.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("You must have an attached entity."); return; @@ -33,7 +33,7 @@ namespace Content.Server.Administration.Commands var lgh = int.Parse(args[4]); var fla = int.Parse(args[5]); - var mapTransform = IoCManager.Resolve().GetComponent(player.AttachedEntity).GetMapTransform(); + var mapTransform = IoCManager.Resolve().GetComponent(playerEntity).GetMapTransform(); var coords = new EntityCoordinates(mapTransform.Owner, x, y); EntitySystem.Get().SpawnExplosion(coords, dev, hvy, lgh, fla); diff --git a/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs b/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs index c6a49508eb..e6086e72f8 100644 --- a/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs +++ b/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs @@ -5,7 +5,6 @@ using Content.Shared.Administration; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Prototypes; namespace Content.Server.Administration.Commands { @@ -48,17 +47,17 @@ namespace Content.Server.Administration.Commands var entityManager = IoCManager.Resolve(); var entityIds = new HashSet(); - var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner)); - var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; }); + var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner)).ToArray(); + var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; }); foreach (var entity in entitiesWithAllComponents) { - if (IoCManager.Resolve().GetComponent(entity).EntityPrototype == null) + if (entityManager.GetComponent(entity).EntityPrototype is not { } prototypeId) { continue; } - entityIds.Add(IoCManager.Resolve().GetComponent(entity).EntityPrototype.ID); + entityIds.Add(prototypeId.ID); } if (entityIds.Count == 0) diff --git a/Content.Server/Administration/Commands/RejuvenateCommand.cs b/Content.Server/Administration/Commands/RejuvenateCommand.cs index 6aeef64345..04591c59f8 100644 --- a/Content.Server/Administration/Commands/RejuvenateCommand.cs +++ b/Content.Server/Administration/Commands/RejuvenateCommand.cs @@ -27,22 +27,21 @@ namespace Content.Server.Administration.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { - var player = shell.Player as IPlayerSession; - if (args.Length < 1 && player != null) //Try to heal the users mob if applicable + if (args.Length < 1 && shell.Player is IPlayerSession player) //Try to heal the users mob if applicable { shell.WriteLine(Loc.GetString("rejuvenate-command-self-heal-message")); - if (player.AttachedEntity == null) + if (player.AttachedEntity == default) { shell.WriteLine(Loc.GetString("rejuvenate-command-no-entity-attached-message")); return; } - PerformRejuvenate(player.AttachedEntity); + PerformRejuvenate(player.AttachedEntity.Value); } var entityManager = IoCManager.Resolve(); foreach (var arg in args) { - if(!EntityUid.TryParse(arg, out var uid) || !entityManager.TryGetEntity(uid, out var entity)) + if (!EntityUid.TryParse(arg, out var entity) || !entityManager.EntityExists(entity)) { shell.WriteLine(Loc.GetString("shell-could-not-find-entity",("entity", arg))); continue; @@ -51,9 +50,9 @@ namespace Content.Server.Administration.Commands } } - public static void PerformRejuvenate(IEntity target) + public static void PerformRejuvenate(EntityUid target) { - var targetUid = (EntityUid) target; + var targetUid = target; var entMan = IoCManager.Resolve(); entMan.GetComponentOrNull(targetUid)?.UpdateState(0); entMan.GetComponentOrNull(targetUid)?.ResetFood(); @@ -61,24 +60,24 @@ namespace Content.Server.Administration.Commands EntitySystem.Get().TryRemoveAllStatusEffects(target); - if (IoCManager.Resolve().TryGetComponent(target, out FlammableComponent? flammable)) + if (entMan.TryGetComponent(target, out FlammableComponent? flammable)) { EntitySystem.Get().Extinguish(target, flammable); } - if (IoCManager.Resolve().TryGetComponent(target, out DamageableComponent? damageable)) + if (entMan.TryGetComponent(target, out DamageableComponent? damageable)) { EntitySystem.Get().SetAllDamage(damageable, 0); } - if (IoCManager.Resolve().TryGetComponent(target, out CreamPiedComponent? creamPied)) + if (entMan.TryGetComponent(target, out CreamPiedComponent? creamPied)) { EntitySystem.Get().SetCreamPied(target, creamPied, false); } - if (IoCManager.Resolve().HasComponent(target)) + if (entMan.HasComponent(target)) { - IoCManager.Resolve().RemoveComponent(target); + entMan.RemoveComponent(target); } } } diff --git a/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs b/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs index fb4cc0698d..bc73bf7c51 100644 --- a/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs +++ b/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs @@ -36,7 +36,7 @@ namespace Content.Server.Administration.Commands if (entityManager.TryGetComponent(parent, out var storage)) { - storage.Remove(entityManager.GetEntity(entityUid)); + storage.Remove(entityUid); } else { diff --git a/Content.Server/Administration/Commands/RemoveExtraComponents.cs b/Content.Server/Administration/Commands/RemoveExtraComponents.cs index b32fd54819..ae1d31b209 100644 --- a/Content.Server/Administration/Commands/RemoveExtraComponents.cs +++ b/Content.Server/Administration/Commands/RemoveExtraComponents.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Content.Shared.Administration; +using Content.Shared.Administration; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -33,16 +32,17 @@ namespace Content.Server.Administration.Commands foreach (var entity in entityManager.GetEntities()) { - if (checkPrototype && IoCManager.Resolve().GetComponent(entity).EntityPrototype != prototype || IoCManager.Resolve().GetComponent(entity).EntityPrototype == null) + var metaData = entityManager.GetComponent(entity); + if (checkPrototype && metaData.EntityPrototype != prototype || metaData.EntityPrototype == null) { continue; } var modified = false; - foreach (var component in IoCManager.Resolve().GetComponents(entity)) + foreach (var component in entityManager.GetComponents(entity)) { - if (IoCManager.Resolve().GetComponent(entity).EntityPrototype.Components.ContainsKey(component.Name)) + if (metaData.EntityPrototype.Components.ContainsKey(component.Name)) continue; entityManager.RemoveComponent(entity, component); diff --git a/Content.Server/Administration/Commands/SetMindCommand.cs b/Content.Server/Administration/Commands/SetMindCommand.cs index 6e2c4cf269..9fc34085f7 100644 --- a/Content.Server/Administration/Commands/SetMindCommand.cs +++ b/Content.Server/Administration/Commands/SetMindCommand.cs @@ -42,9 +42,7 @@ namespace Content.Server.Administration.Commands return; } - var target = entityManager.GetEntity(eUid); - - if (!IoCManager.Resolve().HasComponent(target)) + if (!entityManager.HasComponent(eUid)) { shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-mind-message")); return; @@ -69,11 +67,11 @@ namespace Content.Server.Administration.Commands { mind = new Mind.Mind(session.UserId) { - CharacterName = IoCManager.Resolve().GetComponent(target).EntityName + CharacterName = entityManager.GetComponent(eUid).EntityName }; mind.ChangeOwningPlayer(session.UserId); } - mind.TransferTo(target); + mind.TransferTo(eUid); } } } diff --git a/Content.Server/Administration/Commands/SetOutfitCommand.cs b/Content.Server/Administration/Commands/SetOutfitCommand.cs index 09b0bac877..6bf82f8a95 100644 --- a/Content.Server/Administration/Commands/SetOutfitCommand.cs +++ b/Content.Server/Administration/Commands/SetOutfitCommand.cs @@ -43,17 +43,15 @@ namespace Content.Server.Administration.Commands var entityManager = IoCManager.Resolve(); - var eUid = new EntityUid(entityUid); + var target = new EntityUid(entityUid); - if (!eUid.IsValid() || !entityManager.EntityExists(eUid)) + if (!target.IsValid() || !entityManager.EntityExists(target)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } - var target = entityManager.GetEntity(eUid); - - if (!IoCManager.Resolve().TryGetComponent(target, out var inventoryComponent)) + if (!entityManager.TryGetComponent(target, out var inventoryComponent)) { shell.WriteLine(Loc.GetString("shell-target-entity-does-not-have-message",("missing", "inventory"))); return; @@ -82,7 +80,7 @@ namespace Content.Server.Administration.Commands HumanoidCharacterProfile? profile = null; // Check if we are setting the outfit of a player to respect the preferences - if (IoCManager.Resolve().TryGetComponent(target, out var actorComponent)) + if (entityManager.TryGetComponent(target, out var actorComponent)) { var userId = actorComponent.PlayerSession.UserId; var preferencesManager = IoCManager.Resolve(); @@ -98,15 +96,15 @@ namespace Content.Server.Administration.Commands { continue; } - var equipmentEntity = entityManager.SpawnEntity(gearStr, IoCManager.Resolve().GetComponent(target).Coordinates); + var equipmentEntity = entityManager.SpawnEntity(gearStr, entityManager.GetComponent(target).Coordinates); if (slot == EquipmentSlotDefines.Slots.IDCARD && - IoCManager.Resolve().TryGetComponent(equipmentEntity, out var pdaComponent) && + entityManager.TryGetComponent(equipmentEntity, out var pdaComponent) && pdaComponent.ContainedID != null) { - pdaComponent.ContainedID.FullName = IoCManager.Resolve().GetComponent(target).EntityName; + pdaComponent.ContainedID.FullName = entityManager.GetComponent(target).EntityName; } - inventoryComponent.Equip(slot, IoCManager.Resolve().GetComponent(equipmentEntity), false); + inventoryComponent.Equip(slot, entityManager.GetComponent(equipmentEntity), false); } } } diff --git a/Content.Server/Administration/Commands/WarpCommand.cs b/Content.Server/Administration/Commands/WarpCommand.cs index 685fe76ed5..8a9c8b5291 100644 --- a/Content.Server/Administration/Commands/WarpCommand.cs +++ b/Content.Server/Administration/Commands/WarpCommand.cs @@ -53,19 +53,19 @@ namespace Content.Server.Administration.Commands } else { - if (player.Status != SessionStatus.InGame || player.AttachedEntity == null) + if (player.Status != SessionStatus.InGame || player.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("You are not in-game!"); return; } var mapManager = IoCManager.Resolve(); - var currentMap = IoCManager.Resolve().GetComponent(player.AttachedEntity).MapID; - var currentGrid = IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID; + var currentMap = entMan.GetComponent(playerEntity).MapID; + var currentGrid = entMan.GetComponent(playerEntity).GridID; var found = entMan.EntityQuery(true) .Where(p => p.Location == location) - .Select(p => IoCManager.Resolve().GetComponent(p.Owner).Coordinates) + .Select(p => entMan.GetComponent(p.Owner).Coordinates) .OrderBy(p => p, Comparer.Create((a, b) => { // Sort so that warp points on the same grid/map are first. @@ -113,8 +113,8 @@ namespace Content.Server.Administration.Commands if (found.GetGridId(entMan) != GridId.Invalid) { - IoCManager.Resolve().GetComponent(player.AttachedEntity).Coordinates = found; - if (IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out IPhysBody? physics)) + entMan.GetComponent(playerEntity).Coordinates = found; + if (entMan.TryGetComponent(playerEntity, out IPhysBody? physics)) { physics.LinearVelocity = Vector2.Zero; } diff --git a/Content.Server/Administration/Logs/AdminLogSystem.Json.cs b/Content.Server/Administration/Logs/AdminLogSystem.Json.cs index 1878c466ed..1c21f167af 100644 --- a/Content.Server/Administration/Logs/AdminLogSystem.Json.cs +++ b/Content.Server/Administration/Logs/AdminLogSystem.Json.cs @@ -57,8 +57,7 @@ public partial class AdminLogSystem EntityUid? entityId = properties[key] switch { EntityUid id => id, - IEntity entity => entity, - IPlayerSession {AttachedEntityUid: { }} session => session.AttachedEntityUid.Value, + IPlayerSession {AttachedEntity: {Valid: true}} session => session.AttachedEntity, IComponent component => component.Owner, _ => null }; diff --git a/Content.Server/Administration/Logs/Converters/PlayerSessionConverter.cs b/Content.Server/Administration/Logs/Converters/PlayerSessionConverter.cs index 5d4cd75c77..5d7c133c78 100644 --- a/Content.Server/Administration/Logs/Converters/PlayerSessionConverter.cs +++ b/Content.Server/Administration/Logs/Converters/PlayerSessionConverter.cs @@ -12,10 +12,12 @@ public class PlayerSessionConverter : AdminLogConverter { writer.WriteStartObject(); - if (value.Player.AttachedEntity != null) + if (value.Player.AttachedEntity is {Valid: true} playerEntity) { - writer.WriteNumber("id", (int) (EntityUid) value.Player.AttachedEntity); - writer.WriteString("name", IoCManager.Resolve().GetComponent(value.Player.AttachedEntity).EntityName); + var entityManager = IoCManager.Resolve(); + + writer.WriteNumber("id", (int) value.Player.AttachedEntity); + writer.WriteString("name", entityManager.GetComponent(playerEntity).EntityName); } writer.WriteString("player", value.Player.UserId.UserId); diff --git a/Content.Server/Administration/UI/SetOutfitEui.cs b/Content.Server/Administration/UI/SetOutfitEui.cs index 74f3932ee4..24e727682c 100644 --- a/Content.Server/Administration/UI/SetOutfitEui.cs +++ b/Content.Server/Administration/UI/SetOutfitEui.cs @@ -12,8 +12,9 @@ namespace Content.Server.Administration.UI public sealed class SetOutfitEui : BaseEui { [Dependency] private readonly IAdminManager _adminManager = default!; - private readonly IEntity _target; - public SetOutfitEui(IEntity entity) + private readonly EntityUid _target; + + public SetOutfitEui(EntityUid entity) { _target = entity; IoCManager.InjectDependencies(this); diff --git a/Content.Server/Alert/Click/StopPulling.cs b/Content.Server/Alert/Click/StopPulling.cs index 212720a099..30d3d11cce 100644 --- a/Content.Server/Alert/Click/StopPulling.cs +++ b/Content.Server/Alert/Click/StopPulling.cs @@ -19,7 +19,7 @@ namespace Content.Server.Alert.Click { var ps = EntitySystem.Get(); var playerTarget = ps.GetPulled(args.Player); - if (playerTarget != null && IoCManager.Resolve().TryGetComponent(playerTarget, out SharedPullableComponent playerPullable)) + if (playerTarget != default && IoCManager.Resolve().TryGetComponent(playerTarget, out SharedPullableComponent playerPullable)) { ps.TryStopPull(playerPullable); } diff --git a/Content.Server/Alert/Commands/ClearAlert.cs b/Content.Server/Alert/Commands/ClearAlert.cs index 850a0d8740..693101d996 100644 --- a/Content.Server/Alert/Commands/ClearAlert.cs +++ b/Content.Server/Alert/Commands/ClearAlert.cs @@ -34,7 +34,7 @@ namespace Content.Server.Alert.Commands if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return; } - if (!IoCManager.Resolve().TryGetComponent(attachedEntity, out ServerAlertsComponent? alertsComponent)) + if (!IoCManager.Resolve().TryGetComponent(attachedEntity.Value, out ServerAlertsComponent? alertsComponent)) { shell.WriteLine("user has no alerts component"); return; diff --git a/Content.Server/Alert/Commands/ShowAlert.cs b/Content.Server/Alert/Commands/ShowAlert.cs index 70dfcb76e3..a328911f95 100644 --- a/Content.Server/Alert/Commands/ShowAlert.cs +++ b/Content.Server/Alert/Commands/ShowAlert.cs @@ -40,7 +40,7 @@ namespace Content.Server.Alert.Commands if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return; } - if (!IoCManager.Resolve().TryGetComponent(attachedEntity, out ServerAlertsComponent? alertsComponent)) + if (!IoCManager.Resolve().TryGetComponent(attachedEntity.Value, out ServerAlertsComponent? alertsComponent)) { shell.WriteLine("user has no alerts component"); return; @@ -59,7 +59,7 @@ namespace Content.Server.Alert.Commands shell.WriteLine("invalid severity " + sevint); return; } - alertsComponent.ShowAlert(alert.AlertType, sevint == -1 ? (short?) null : sevint); + alertsComponent.ShowAlert(alert.AlertType, sevint == -1 ? null : sevint); } } } diff --git a/Content.Server/Alert/ServerAlertsComponent.cs b/Content.Server/Alert/ServerAlertsComponent.cs index 32db5fd927..e7c33448cb 100644 --- a/Content.Server/Alert/ServerAlertsComponent.cs +++ b/Content.Server/Alert/ServerAlertsComponent.cs @@ -67,7 +67,7 @@ namespace Content.Server.Alert { Logger.DebugS("alert", "user {0} attempted to" + " click alert {1} which is not currently showing for them", - IoCManager.Resolve().GetComponent(player).EntityName, msg.Type); + IoCManager.Resolve().GetComponent(player.Value).EntityName, msg.Type); break; } @@ -77,7 +77,7 @@ namespace Content.Server.Alert break; } - alert.OnClick?.AlertClicked(new ClickAlertEventArgs(player, alert)); + alert.OnClick?.AlertClicked(new ClickAlertEventArgs(player.Value, alert)); break; } } diff --git a/Content.Server/Animals/Systems/UdderSystem.cs b/Content.Server/Animals/Systems/UdderSystem.cs index 91d00f8ed3..8e46ba743b 100644 --- a/Content.Server/Animals/Systems/UdderSystem.cs +++ b/Content.Server/Animals/Systems/UdderSystem.cs @@ -1,16 +1,15 @@ -using System; using Content.Server.Animals.Components; +using Content.Server.Chemistry.Components.SolutionManager; +using Content.Server.Chemistry.EntitySystems; +using Content.Server.DoAfter; +using Content.Server.Nutrition.Components; +using Content.Server.Popups; +using Content.Shared.Nutrition.Components; +using Content.Shared.Verbs; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Content.Server.Chemistry.EntitySystems; -using Content.Server.Nutrition.Components; -using Content.Shared.Nutrition.Components; -using Content.Server.Chemistry.Components.SolutionManager; -using Content.Server.DoAfter; using Robust.Shared.Localization; -using Content.Shared.Verbs; using Robust.Shared.Player; -using Content.Server.Popups; namespace Content.Server.Animals.Systems { @@ -42,7 +41,7 @@ namespace Content.Server.Animals.Systems continue; // Actually there is food digestion so no problem with instant reagent generation "OnFeed" - if (IoCManager.Resolve().TryGetComponent(udder.Owner, out var hunger)) + if (EntityManager.TryGetComponent(udder.Owner, out var hunger)) { hunger.HungerThresholds.TryGetValue(HungerThreshold.Peckish, out var targetThreshold); @@ -110,8 +109,7 @@ namespace Content.Server.Animals.Systems var split = _solutionContainerSystem.SplitSolution(uid, solution, quantity); _solutionContainerSystem.TryAddSolution(ev.ContainerUid, targetSolution, split); - var container = EntityManager.GetEntity(ev.ContainerUid); - _popupSystem.PopupEntity(Loc.GetString("udder-system-success", ("amount", quantity), ("target", container)), uid, Filter.Entities(ev.UserUid)); + _popupSystem.PopupEntity(Loc.GetString("udder-system-success", ("amount", quantity), ("target", ev.ContainerUid)), uid, Filter.Entities(ev.UserUid)); } private void OnMilkingFailed(EntityUid uid, UdderComponent component, MilkingFailEvent ev) @@ -123,16 +121,18 @@ namespace Content.Server.Animals.Systems { if (args.Using == null || !args.CanInteract || - !IoCManager.Resolve().HasComponent(args.Using)) + !EntityManager.HasComponent(args.Using.Value)) return; - Verb verb = new(); - verb.Act = () => + Verb verb = new() { - AttemptMilk(uid, args.User, args.Using, component); + Act = () => + { + AttemptMilk(uid, args.User, args.Using.Value, component); + }, + Text = Loc.GetString("udder-system-verb-milk"), + Priority = 2 }; - verb.Text = Loc.GetString("udder-system-verb-milk"); - verb.Priority = 2; args.Verbs.Add(verb); } diff --git a/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs b/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs index 1c5f856579..c492f16f8b 100644 --- a/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs +++ b/Content.Server/Arcade/Components/BlockGameArcadeComponent.cs @@ -664,11 +664,11 @@ namespace Content.Server.Arcade.Components _running = false; _gameOver = true; - if (_component._player?.AttachedEntity != null) + if (_component._player?.AttachedEntity is {Valid: true} playerEntity) { var blockGameSystem = EntitySystem.Get(); - _highScorePlacement = blockGameSystem.RegisterHighScore(IoCManager.Resolve().GetComponent(_component._player.AttachedEntity).EntityName, Points); + _highScorePlacement = blockGameSystem.RegisterHighScore(IoCManager.Resolve().GetComponent(playerEntity).EntityName, Points); SendHighscoreUpdate(); } _component.UserInterface?.SendMessage(new BlockGameMessages.BlockGameGameOverScreenMessage(Points, _highScorePlacement?.LocalPlacement, _highScorePlacement?.GlobalPlacement)); diff --git a/Content.Server/Atmos/Commands/AddAtmosCommand.cs b/Content.Server/Atmos/Commands/AddAtmosCommand.cs index a88d5a85da..be4fc7e35e 100644 --- a/Content.Server/Atmos/Commands/AddAtmosCommand.cs +++ b/Content.Server/Atmos/Commands/AddAtmosCommand.cs @@ -11,6 +11,8 @@ namespace Content.Server.Atmos.Commands [AdminCommand(AdminFlags.Debug)] public class AddAtmosCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "addatmos"; public string Description => "Adds atmos support to a grid."; public string Help => $"{Command} "; @@ -39,21 +41,19 @@ namespace Content.Server.Atmos.Commands return; } - var entMan = IoCManager.Resolve(); - - if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid)) + if (!_entities.EntityExists(gridComp.GridEntityId)) { shell.WriteLine("Failed to get grid entity."); return; } - if (IoCManager.Resolve().HasComponent(grid)) + if (_entities.HasComponent(gridComp.GridEntityId)) { shell.WriteLine("Grid already has an atmosphere."); return; } - IoCManager.Resolve().AddComponent(grid); + _entities.AddComponent(gridComp.GridEntityId); shell.WriteLine($"Added atmosphere to grid {id}."); } diff --git a/Content.Server/Atmos/Commands/AddUnsimulatedAtmosCommand.cs b/Content.Server/Atmos/Commands/AddUnsimulatedAtmosCommand.cs index 75526ac9a3..b5e4850aaa 100644 --- a/Content.Server/Atmos/Commands/AddUnsimulatedAtmosCommand.cs +++ b/Content.Server/Atmos/Commands/AddUnsimulatedAtmosCommand.cs @@ -41,19 +41,19 @@ namespace Content.Server.Atmos.Commands var entMan = IoCManager.Resolve(); - if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid)) + if (!entMan.EntityExists(gridComp.GridEntityId)) { shell.WriteLine("Failed to get grid entity."); return; } - if (IoCManager.Resolve().HasComponent(grid)) + if (entMan.HasComponent(gridComp.GridEntityId)) { shell.WriteLine("Grid already has an atmosphere."); return; } - IoCManager.Resolve().AddComponent(grid); + entMan.AddComponent(gridComp.GridEntityId); shell.WriteLine($"Added unsimulated atmosphere to grid {id}."); } diff --git a/Content.Server/Atmos/Commands/DeleteGasCommand.cs b/Content.Server/Atmos/Commands/DeleteGasCommand.cs index efd78fc2c0..b3f879dd6d 100644 --- a/Content.Server/Atmos/Commands/DeleteGasCommand.cs +++ b/Content.Server/Atmos/Commands/DeleteGasCommand.cs @@ -27,19 +27,20 @@ namespace Content.Server.Atmos.Commands switch (args.Length) { case 0: + { if (player == null) { shell.WriteLine("A grid must be specified when the command isn't used by a player."); return; } - if (player.AttachedEntity == null) + if (player.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("You have no entity to get a grid from."); return; } - gridId = IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID; + gridId = IoCManager.Resolve().GetComponent(playerEntity).GridID; if (gridId == GridId.Invalid) { @@ -48,6 +49,7 @@ namespace Content.Server.Atmos.Commands } break; + } case 1: { if (!int.TryParse(args[0], out var number)) @@ -59,13 +61,13 @@ namespace Content.Server.Atmos.Commands return; } - if (player.AttachedEntity == null) + if (player.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("You have no entity from which to get a grid id."); return; } - gridId = IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID; + gridId = IoCManager.Resolve().GetComponent(playerEntity).GridID; if (gridId == GridId.Invalid) { diff --git a/Content.Server/Atmos/Components/BreathToolComponent.cs b/Content.Server/Atmos/Components/BreathToolComponent.cs index ba589d1bb4..326e45ad62 100644 --- a/Content.Server/Atmos/Components/BreathToolComponent.cs +++ b/Content.Server/Atmos/Components/BreathToolComponent.cs @@ -12,6 +12,8 @@ namespace Content.Server.Atmos.Components [RegisterComponent] public class BreathToolComponent : Component, IEquipped, IUnequipped { + [Dependency] private readonly IEntityManager _entities = default!; + /// /// Tool is functional only in allowed slots /// @@ -20,7 +22,7 @@ namespace Content.Server.Atmos.Components public override string Name => "BreathMask"; public bool IsFunctional { get; private set; } - public IEntity? ConnectedInternalsEntity { get; private set; } + public EntityUid ConnectedInternalsEntity { get; private set; } protected override void Shutdown() { @@ -33,7 +35,7 @@ namespace Content.Server.Atmos.Components if ((EquipmentSlotDefines.SlotMasks[eventArgs.Slot] & _allowedSlots) != _allowedSlots) return; IsFunctional = true; - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out InternalsComponent? internals)) + if (_entities.TryGetComponent(eventArgs.User, out InternalsComponent? internals)) { ConnectedInternalsEntity = eventArgs.User; internals.ConnectBreathTool(Owner); @@ -48,9 +50,9 @@ namespace Content.Server.Atmos.Components public void DisconnectInternals() { var old = ConnectedInternalsEntity; - ConnectedInternalsEntity = null; + ConnectedInternalsEntity = default; - if (old != null && IoCManager.Resolve().TryGetComponent(old, out var internalsComponent)) + if (old != default && _entities.TryGetComponent(old, out var internalsComponent)) { internalsComponent.DisconnectBreathTool(); } diff --git a/Content.Server/Atmos/Components/GasAnalyzerComponent.cs b/Content.Server/Atmos/Components/GasAnalyzerComponent.cs index 579a2e87cd..32c5eb1980 100644 --- a/Content.Server/Atmos/Components/GasAnalyzerComponent.cs +++ b/Content.Server/Atmos/Components/GasAnalyzerComponent.cs @@ -13,7 +13,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; -using Robust.Shared.Players; using Robust.Shared.ViewVariables; namespace Content.Server.Atmos.Components @@ -21,6 +20,8 @@ namespace Content.Server.Atmos.Components [RegisterComponent] public class GasAnalyzerComponent : SharedGasAnalyzerComponent, IAfterInteract, IDropped, IUse { + [Dependency] private readonly IEntityManager _entities = default!; + private GasAnalyzerDanger _pressureDanger; private float _timeSinceSync; private const float TimeBetweenSyncs = 2f; @@ -40,7 +41,7 @@ namespace Content.Server.Atmos.Components UserInterface.OnClosed += UserInterfaceOnClose; } - IoCManager.Resolve().TryGetComponent(Owner, out _appearance); + _entities.TryGetComponent(Owner, out _appearance); } public override ComponentState GetComponentState() @@ -123,7 +124,7 @@ namespace Content.Server.Atmos.Components { // Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth var pressure = 0f; - var tile = EntitySystem.Get().GetTileMixture(IoCManager.Resolve().GetComponent(Owner).Coordinates); + var tile = EntitySystem.Get().GetTileMixture(_entities.GetComponent(Owner).Coordinates); if (tile != null) { pressure = tile.Pressure; @@ -158,24 +159,24 @@ namespace Content.Server.Atmos.Components // Check if the player is still holding the gas analyzer => if not, don't update foreach (var session in UserInterface.SubscribedSessions) { - if (session.AttachedEntity == null) + if (session.AttachedEntity is not {Valid: true} playerEntity) return; - if (!IoCManager.Resolve().TryGetComponent(session.AttachedEntity, out HandsComponent? handsComponent)) + if (!_entities.TryGetComponent(playerEntity, out HandsComponent? handsComponent)) return; - var activeHandEntity = handsComponent?.GetActiveHand?.Owner; - if (activeHandEntity == null || !IoCManager.Resolve().TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer)) + if (handsComponent?.GetActiveHand?.Owner is not {Valid: true} activeHandEntity || + !_entities.TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer)) { return; } } - var pos = IoCManager.Resolve().GetComponent(Owner).Coordinates; + var pos = _entities.GetComponent(Owner).Coordinates; if (!_checkPlayer && _position.HasValue) { // Check if position is out of range => don't update - if (!_position.Value.InRange(IoCManager.Resolve(), pos, SharedInteractionSystem.InteractionRange)) + if (!_position.Value.InRange(_entities, pos, SharedInteractionSystem.InteractionRange)) return; pos = _position.Value; @@ -220,20 +221,19 @@ namespace Content.Server.Atmos.Components switch (message) { case GasAnalyzerRefreshMessage msg: - var player = serverMsg.Session.AttachedEntity; - if (player == null) + if (serverMsg.Session.AttachedEntity is not {Valid: true} player) { return; } - if (!IoCManager.Resolve().TryGetComponent(player, out HandsComponent? handsComponent)) + if (!_entities.TryGetComponent(player, out HandsComponent? handsComponent)) { Owner.PopupMessage(player, Loc.GetString("gas-analyzer-component-player-has-no-hands-message")); return; } - var activeHandEntity = handsComponent.GetActiveHand?.Owner; - if (activeHandEntity == null || !IoCManager.Resolve().TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer)) + if (handsComponent.GetActiveHand?.Owner is not {Valid: true} activeHandEntity || + !_entities.TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer)) { serverMsg.Session.AttachedEntity?.PopupMessage(Loc.GetString("gas-analyzer-component-need-gas-analyzer-in-hand-message")); return; @@ -253,7 +253,7 @@ namespace Content.Server.Atmos.Components return true; } - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { OpenInterface(actor.PlayerSession, eventArgs.ClickLocation); } @@ -265,7 +265,7 @@ namespace Content.Server.Atmos.Components void IDropped.Dropped(DroppedEventArgs eventArgs) { - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { CloseInterface(actor.PlayerSession); } @@ -273,7 +273,7 @@ namespace Content.Server.Atmos.Components bool IUse.UseEntity(UseEntityEventArgs eventArgs) { - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { ToggleInterface(actor.PlayerSession); return true; diff --git a/Content.Server/Atmos/Components/GasTankComponent.cs b/Content.Server/Atmos/Components/GasTankComponent.cs index 9074587c70..a32b58c102 100644 --- a/Content.Server/Atmos/Components/GasTankComponent.cs +++ b/Content.Server/Atmos/Components/GasTankComponent.cs @@ -175,7 +175,7 @@ namespace Content.Server.Atmos.Components UpdateUserInterface(); } - public void DisconnectFromInternals(IEntity? owner = null) + public void DisconnectFromInternals(EntityUid? owner = null) { if (!IsConnected) return; IsConnected = false; @@ -190,7 +190,7 @@ namespace Content.Server.Atmos.Components new GasTankBoundUserInterfaceState { TankPressure = Air?.Pressure ?? 0, - OutputPressure = initialUpdate ? OutputPressure : (float?) null, + OutputPressure = initialUpdate ? OutputPressure : null, InternalsConnected = IsConnected, CanConnectInternals = IsFunctional && internals != null }); @@ -216,7 +216,7 @@ namespace Content.Server.Atmos.Components { var user = GetInternalsComponent()?.Owner; - if (user == null || !EntitySystem.Get().CanUse(user)) + if (user == null || !EntitySystem.Get().CanUse(user.Value)) return; if (IsConnected) @@ -228,10 +228,10 @@ namespace Content.Server.Atmos.Components ConnectToInternals(); } - private InternalsComponent? GetInternalsComponent(IEntity? owner = null) + private InternalsComponent? GetInternalsComponent(EntityUid? owner = null) { if ((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) return null; - if (owner != null) return IoCManager.Resolve().GetComponentOrNull(owner); + if (owner != null) return IoCManager.Resolve().GetComponentOrNull(owner.Value); return Owner.TryGetContainer(out var container) ? IoCManager.Resolve().GetComponentOrNull(container.Owner) : null; @@ -271,7 +271,7 @@ namespace Content.Server.Atmos.Components EntitySystem.Get().SpawnExplosion(((IComponent) this).Owner, (int) (range * 0.25f), (int) (range * 0.5f), (int) (range * 1.5f), 1); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); return; } @@ -285,7 +285,7 @@ namespace Content.Server.Atmos.Components SoundSystem.Play(Filter.Pvs(Owner), _ruptureSound.GetSound(), IoCManager.Resolve().GetComponent(Owner).Coordinates, AudioHelpers.WithVariation(0.125f)); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); return; } diff --git a/Content.Server/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs b/Content.Server/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs index b899a3b1bf..9628303ffd 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs @@ -11,7 +11,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Timing; namespace Content.Server.Atmos.EntitySystems { @@ -132,18 +131,18 @@ namespace Content.Server.Atmos.EntitySystems // Afterwards we reset all the chunk data for the next time we tick. foreach (var session in _playerObservers) { - if (session.AttachedEntity == null) continue; - - var entity = session.AttachedEntity; + if (session.AttachedEntity is not {Valid: true} entity) + continue; var worldBounds = Box2.CenteredAround(IoCManager.Resolve().GetComponent(entity).WorldPosition, new Vector2(LocalViewRange, LocalViewRange)); foreach (var grid in _mapManager.FindGridsIntersecting(IoCManager.Resolve().GetComponent(entity).MapID, worldBounds)) { - if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) continue; + if (!EntityManager.EntityExists(grid.GridEntityId)) + continue; - if (!IoCManager.Resolve().TryGetComponent(gridEnt, out var gam)) continue; + if (!IoCManager.Resolve().TryGetComponent(grid.GridEntityId, out var gam)) continue; var entityTile = grid.GetTileRef(IoCManager.Resolve().GetComponent(entity).Coordinates).GridIndices; var baseTile = new Vector2i(entityTile.X - (LocalViewRange / 2), entityTile.Y - (LocalViewRange / 2)); diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs index b6e5f2516e..f944229e10 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs @@ -1,7 +1,6 @@ using Content.Server.Atmos.Components; using Content.Shared.Atmos; using Content.Shared.Audio; -using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Containers; using Robust.Shared.GameObjects; @@ -63,7 +62,7 @@ namespace Content.Server.Atmos.EntitySystems if (difference > tile.PressureDifference) { tile.PressureDifference = difference; - tile.PressureDirection = ((Vector2i)(tile.GridIndices - other.GridIndices)).GetDir().ToAtmosDirection(); + tile.PressureDirection = (tile.GridIndices - other.GridIndices).GetDir().ToAtmosDirection(); } } } diff --git a/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs b/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs index 91a672d503..69061876bd 100644 --- a/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs +++ b/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs @@ -1,9 +1,7 @@ using System; -using System.Data; using Content.Server.Administration.Logs; using Content.Server.Alert; using Content.Server.Atmos.Components; -using Content.Shared.Administration.Logs; using Content.Shared.Alert; using Content.Shared.Atmos; using Content.Shared.Damage; @@ -86,7 +84,7 @@ namespace Content.Server.Atmos.EntitySystems if (totalDamage >= barotrauma.MaxDamage) continue; - var uid = (EntityUid) barotrauma.Owner; + var uid = barotrauma.Owner; var status = IoCManager.Resolve().GetComponentOrNull(barotrauma.Owner); diff --git a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs index b6290c5d87..16e2c02143 100644 --- a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs +++ b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs @@ -6,7 +6,6 @@ using Content.Server.Atmos.Components; using Content.Server.Stunnable; using Content.Server.Temperature.Systems; using Content.Shared.ActionBlocker; -using Content.Shared.Administration.Logs; using Content.Shared.Alert; using Content.Shared.Atmos; using Content.Shared.Damage; @@ -69,7 +68,7 @@ namespace Content.Server.Atmos.EntitySystems private void OnCollideEvent(EntityUid uid, FlammableComponent flammable, StartCollideEvent args) { - var otherUid = (EntityUid) args.OtherFixture.Body.Owner; + var otherUid = args.OtherFixture.Body.Owner; if (!EntityManager.TryGetComponent(otherUid, out FlammableComponent? otherFlammable)) return; @@ -217,7 +216,7 @@ namespace Content.Server.Atmos.EntitySystems // TODO: This needs cleanup to take off the crust from TemperatureComponent and shit. foreach (var (flammable, physics, transform) in EntityManager.EntityQuery()) { - var uid = (EntityUid) flammable.Owner; + var uid = flammable.Owner; // Slowly dry ourselves off if wet. if (flammable.FireStacks < 0) diff --git a/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs b/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs index d20ab1fbe6..0f5a66645d 100644 --- a/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs +++ b/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs @@ -19,17 +19,16 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Timing; // ReSharper disable once RedundantUsingDirective -using Dependency = Robust.Shared.IoC.DependencyAttribute; namespace Content.Server.Atmos.EntitySystems { [UsedImplicitly] internal sealed class GasTileOverlaySystem : SharedGasTileOverlaySystem { - [Dependency] private readonly IGameTiming _gameTiming = default!; - [Dependency] private readonly IPlayerManager _playerManager = default!; - [Dependency] private readonly IMapManager _mapManager = default!; - [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; + [Robust.Shared.IoC.Dependency] private readonly IGameTiming _gameTiming = default!; + [Robust.Shared.IoC.Dependency] private readonly IPlayerManager _playerManager = default!; + [Robust.Shared.IoC.Dependency] private readonly IMapManager _mapManager = default!; + [Robust.Shared.IoC.Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; /// /// The tiles that have had their atmos data updated since last tick @@ -190,7 +189,7 @@ namespace Content.Server.Atmos.EntitySystems /// /// /// - private List GetChunksInRange(IEntity entity) + private List GetChunksInRange(EntityUid entity) { var inRange = new List(); @@ -311,10 +310,10 @@ namespace Content.Server.Atmos.EntitySystems // Afterwards we reset all the chunk data for the next time we tick. foreach (var (session, overlay) in _knownPlayerChunks) { - if (session.AttachedEntity == null) continue; + if (session.AttachedEntity is not {Valid: true} entity) 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 chunksInRange = GetChunksInRange(entity); var knownChunks = overlay.GetKnownChunks(); var chunksToRemove = new List(); var chunksToAdd = new List(); diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs index 454b171b29..d3f1d69c83 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs @@ -4,14 +4,11 @@ using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.Piping.Components; using Content.Server.Atmos.Piping.Unary.Components; -using Content.Server.Destructible; using Content.Server.Hands.Components; using Content.Server.NodeContainer; using Content.Server.NodeContainer.NodeGroups; using Content.Server.NodeContainer.Nodes; -using Content.Server.UserInterface; using Content.Shared.ActionBlocker; -using Content.Shared.Administration.Logs; using Content.Shared.Atmos; using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Database; @@ -19,7 +16,6 @@ using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using JetBrains.Annotations; using Robust.Server.GameObjects; -using Robust.Server.Player; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -85,7 +81,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private bool CheckInteract(ICommonSession session) { - if (session.AttachedEntityUid is not {} uid + if (session.AttachedEntity is not {} uid || !_actionBlockerSystem.CanInteract(uid) || !_actionBlockerSystem.CanUse(uid)) return false; @@ -110,14 +106,14 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems if (containerManager.TryGetContainer(canister.ContainerName, out var tankContainer) && tankContainer.ContainedEntities.Count > 0) { - var tank = (EntityUid) tankContainer.ContainedEntities[0]; + var tank = tankContainer.ContainedEntities[0]; var tankComponent = EntityManager.GetComponent(tank); tankLabel = EntityManager.GetComponent(tank).EntityName; tankPressure = tankComponent.Air.Pressure; } _userInterfaceSystem.TrySetUiState(uid, GasCanisterUiKey.Key, - new GasCanisterBoundUserInterfaceState(IoCManager.Resolve().GetComponent(canister.Owner).EntityName, + new GasCanisterBoundUserInterfaceState(EntityManager.GetComponent(canister.Owner).EntityName, canister.Air.Pressure, portStatus, tankLabel, tankPressure, canister.ReleasePressure, canister.ReleaseValve, canister.MinReleasePressure, canister.MaxReleasePressure)); } @@ -205,13 +201,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems if (container.ContainedEntities.Count > 0) { - IEntity tempQualifier = container.ContainedEntities[0]; - var gasTank = IoCManager.Resolve().GetComponent(tempQualifier); + var gasTank = EntityManager.GetComponent(container.ContainedEntities[0]); _atmosphereSystem.ReleaseGasTo(canister.Air, gasTank.Air, canister.ReleasePressure); } else { - var environment = _atmosphereSystem.GetTileMixture(IoCManager.Resolve().GetComponent(canister.Owner).Coordinates, true); + var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent(canister.Owner).Coordinates, true); _atmosphereSystem.ReleaseGasTo(canister.Air, environment, canister.ReleasePressure); } } @@ -244,7 +239,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private void OnCanisterActivate(EntityUid uid, GasCanisterComponent component, ActivateInWorldEvent args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) return; _userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession); @@ -254,16 +249,15 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private void OnCanisterInteractHand(EntityUid uid, GasCanisterComponent component, InteractHandEvent args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) return; _userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession); args.Handled = true; } - private void OnCanisterInteractUsing(EntityUid uid, GasCanisterComponent component, InteractUsingEvent args) + private void OnCanisterInteractUsing(EntityUid canister, GasCanisterComponent component, InteractUsingEvent args) { - var canister = EntityManager.GetEntity(uid); var container = canister.EnsureContainer(component.ContainerName); // Container full. @@ -271,11 +265,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems return; // Check the used item is valid... - if (!IoCManager.Resolve().TryGetComponent(args.Used, out GasTankComponent? _)) + if (!EntityManager.TryGetComponent(args.Used, out GasTankComponent? _)) return; // Check the user has hands. - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!EntityManager.TryGetComponent(args.User, out HandsComponent? hands)) return; if (!args.User.InRangeUnobstructed(canister, SharedInteractionSystem.InteractionRange, popup: true)) @@ -284,7 +278,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems if (!hands.Drop(args.Used, container)) return; - _adminLogSystem.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {args.User:player} inserted tank {container.ContainedEntities[0]} into {uid}"); + _adminLogSystem.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {args.User:player} inserted tank {container.ContainedEntities[0]} into {canister}"); args.Handled = true; } diff --git a/Content.Server/Body/Commands/AddHandCommand.cs b/Content.Server/Body/Commands/AddHandCommand.cs index 67e71b574b..d709c79246 100644 --- a/Content.Server/Body/Commands/AddHandCommand.cs +++ b/Content.Server/Body/Commands/AddHandCommand.cs @@ -1,7 +1,6 @@ using Content.Server.Administration; using Content.Shared.Administration; using Content.Shared.Body.Components; -using Content.Shared.Body.Part; using Robust.Server.Player; using Robust.Shared.Console; using Robust.Shared.GameObjects; @@ -45,13 +44,13 @@ namespace Content.Server.Body.Commands return; } - if (player.AttachedEntityUid == null) + if (player.AttachedEntity == null) { shell.WriteLine("You don't have an entity to add a hand to."); return; } - entity = player.AttachedEntityUid.Value; + entity = player.AttachedEntity.Value; hand = entityManager.SpawnEntity(DefaultHandPrototype, entityManager.GetComponent(entity).Coordinates); break; } @@ -76,13 +75,13 @@ namespace Content.Server.Body.Commands return; } - if (player.AttachedEntityUid == null) + if (player.AttachedEntity == null) { shell.WriteLine("You don't have an entity to add a hand to."); return; } - entity = player.AttachedEntityUid.Value; + entity = player.AttachedEntity.Value; hand = entityManager.SpawnEntity(args[0], entityManager.GetComponent(entity).Coordinates); } diff --git a/Content.Server/Body/Commands/AttachBodyPartCommand.cs b/Content.Server/Body/Commands/AttachBodyPartCommand.cs index 9edf7167b5..c46e366400 100644 --- a/Content.Server/Body/Commands/AttachBodyPartCommand.cs +++ b/Content.Server/Body/Commands/AttachBodyPartCommand.cs @@ -20,7 +20,7 @@ namespace Content.Server.Body.Commands var player = shell.Player as IPlayerSession; var entityManager = IoCManager.Resolve(); - IEntity entity; + EntityUid entity; EntityUid partUid; switch (args.Length) @@ -44,7 +44,7 @@ namespace Content.Server.Body.Commands return; } - entity = player.AttachedEntity; + entity = player.AttachedEntity.Value; break; case 2: @@ -60,44 +60,44 @@ namespace Content.Server.Body.Commands return; } - if (!entityManager.TryGetEntity(entityUid, out var tempEntity)) + if (!entityManager.EntityExists(entityUid)) { shell.WriteLine($"{entityUid} is not a valid entity."); return; } - entity = tempEntity; + entity = entityUid; break; default: shell.WriteLine(Help); return; } - if (!IoCManager.Resolve().TryGetComponent(entity, out SharedBodyComponent? body)) + if (!entityManager.TryGetComponent(entity, out SharedBodyComponent? body)) { - shell.WriteLine($"Entity {IoCManager.Resolve().GetComponent(entity).EntityName} with uid {entity} does not have a {nameof(SharedBodyComponent)} component."); + shell.WriteLine($"Entity {entityManager.GetComponent(entity).EntityName} with uid {entity} does not have a {nameof(SharedBodyComponent)} component."); return; } - if (!entityManager.TryGetEntity(partUid, out var partEntity)) + if (!entityManager.EntityExists(partUid)) { shell.WriteLine($"{partUid} is not a valid entity."); return; } - if (!IoCManager.Resolve().TryGetComponent(partEntity, out SharedBodyPartComponent? part)) + if (!entityManager.TryGetComponent(partUid, out SharedBodyPartComponent? part)) { - shell.WriteLine($"Entity {IoCManager.Resolve().GetComponent(partEntity).EntityName} with uid {args[0]} does not have a {nameof(SharedBodyPartComponent)} component."); + shell.WriteLine($"Entity {entityManager.GetComponent(partUid).EntityName} with uid {args[0]} does not have a {nameof(SharedBodyPartComponent)} component."); return; } if (body.HasPart(part)) { - shell.WriteLine($"Body part {IoCManager.Resolve().GetComponent(partEntity).EntityName} with uid {partEntity} is already attached to entity {IoCManager.Resolve().GetComponent(entity).EntityName} with uid {entity}"); + shell.WriteLine($"Body part {entityManager.GetComponent(partUid).EntityName} with uid {partUid} is already attached to entity {entityManager.GetComponent(entity).EntityName} with uid {entity}"); return; } - body.SetPart($"AttachBodyPartVerb-{partEntity}", part); + body.SetPart($"AttachBodyPartVerb-{partUid}", part); } } } diff --git a/Content.Server/Body/Commands/DestroyMechanismCommand.cs b/Content.Server/Body/Commands/DestroyMechanismCommand.cs index 9d2726cde3..e6e7e255e8 100644 --- a/Content.Server/Body/Commands/DestroyMechanismCommand.cs +++ b/Content.Server/Body/Commands/DestroyMechanismCommand.cs @@ -37,7 +37,7 @@ namespace Content.Server.Body.Commands return; } - if (!IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out SharedBodyComponent? body)) + if (!IoCManager.Resolve().TryGetComponent(player.AttachedEntity.Value, out SharedBodyComponent? 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/Commands/RemoveHandCommand.cs b/Content.Server/Body/Commands/RemoveHandCommand.cs index e474ebfb1a..60807b59c4 100644 --- a/Content.Server/Body/Commands/RemoveHandCommand.cs +++ b/Content.Server/Body/Commands/RemoveHandCommand.cs @@ -33,7 +33,7 @@ namespace Content.Server.Body.Commands return; } - if (!IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out SharedBodyComponent? body)) + if (!IoCManager.Resolve().TryGetComponent(player.AttachedEntity.Value, out SharedBodyComponent? 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/Components/BodyComponent.cs b/Content.Server/Body/Components/BodyComponent.cs index 640fdd8c92..f7c0df0e9e 100644 --- a/Content.Server/Body/Components/BodyComponent.cs +++ b/Content.Server/Body/Components/BodyComponent.cs @@ -1,6 +1,5 @@ using Content.Server.Ghost; using Content.Shared.Audio; -using Content.Shared.Body; using Content.Shared.Body.Components; using Content.Shared.Body.Part; using Content.Shared.Random.Helpers; @@ -103,7 +102,7 @@ namespace Content.Server.Body.Components } } - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); } } } diff --git a/Content.Server/Body/Components/BodyPartComponent.cs b/Content.Server/Body/Components/BodyPartComponent.cs index e28049b5e5..eb586b4a2c 100644 --- a/Content.Server/Body/Components/BodyPartComponent.cs +++ b/Content.Server/Body/Components/BodyPartComponent.cs @@ -2,13 +2,10 @@ using System.Collections.Generic; using System.Threading.Tasks; using Content.Server.UserInterface; using Content.Shared.Body.Components; -using Content.Shared.Body.Part; using Content.Shared.Body.Surgery; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Random.Helpers; -using Content.Shared.Verbs; -using Robust.Server.Console; using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Containers; @@ -27,7 +24,7 @@ namespace Content.Server.Body.Components private readonly Dictionary _optionsCache = new(); private SharedBodyComponent? _owningBodyCache; private int _idHash; - private IEntity? _surgeonCache; + private EntityUid? _surgeonCache; private Container _mechanismContainer = default!; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SurgeryUIKey.Key); @@ -104,7 +101,7 @@ namespace Content.Server.Body.Components _surgeonCache = null; _owningBodyCache = null; - if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out SharedBodyComponent? body)) + if (IoCManager.Resolve().TryGetComponent(eventArgs.Target.Value, out SharedBodyComponent? body)) { SendSlots(eventArgs, body); } @@ -161,7 +158,7 @@ namespace Content.Server.Body.Components private void ReceiveBodyPartSlot(int key) { if (_surgeonCache == null || - !IoCManager.Resolve().TryGetComponent(_surgeonCache, out ActorComponent? actor)) + !IoCManager.Resolve().TryGetComponent(_surgeonCache.Value, out ActorComponent? actor)) { return; } @@ -176,7 +173,7 @@ namespace Content.Server.Body.Components // TODO: sanity checks to see whether user is in range, user is still able-bodied, target is still the same, etc etc if (!_optionsCache.TryGetValue(key, out var targetObject)) { - _owningBodyCache.Owner.PopupMessage(_surgeonCache, + _owningBodyCache.Owner.PopupMessage(_surgeonCache.Value, Loc.GetString("bodypart-component-no-way-to-attach-message", ("partName", Owner))); } @@ -185,7 +182,7 @@ namespace Content.Server.Body.Components ? Loc.GetString("bodypart-component-attach-success-message",("partName", Owner)) : Loc.GetString("bodypart-component-attach-fail-message",("partName", Owner)); - _owningBodyCache.Owner.PopupMessage(_surgeonCache, message); + _owningBodyCache.Owner.PopupMessage(_surgeonCache.Value, message); } private void OpenSurgeryUI(IPlayerSession session) diff --git a/Content.Server/Body/Components/BodyScannerComponent.cs b/Content.Server/Body/Components/BodyScannerComponent.cs index 3b4deae1e1..75a16fcf73 100644 --- a/Content.Server/Body/Components/BodyScannerComponent.cs +++ b/Content.Server/Body/Components/BodyScannerComponent.cs @@ -29,7 +29,7 @@ namespace Content.Server.Body.Components return; } - if (IoCManager.Resolve().TryGetComponent(session.AttachedEntity, out SharedBodyComponent? body)) + if (IoCManager.Resolve().TryGetComponent(session.AttachedEntity.Value, out SharedBodyComponent? body)) { var state = InterfaceState(body); UserInterface?.SetState(state); diff --git a/Content.Server/Body/Components/InternalsComponent.cs b/Content.Server/Body/Components/InternalsComponent.cs index 3f1b9524f4..3b849e158f 100644 --- a/Content.Server/Body/Components/InternalsComponent.cs +++ b/Content.Server/Body/Components/InternalsComponent.cs @@ -9,24 +9,24 @@ namespace Content.Server.Body.Components public class InternalsComponent : Component { public override string Name => "Internals"; - [ViewVariables] public IEntity? GasTankEntity { get; set; } - [ViewVariables] public IEntity? BreathToolEntity { get; set; } + [ViewVariables] public EntityUid GasTankEntity { get; set; } + [ViewVariables] public EntityUid BreathToolEntity { get; set; } public void DisconnectBreathTool() { var old = BreathToolEntity; - BreathToolEntity = null; + BreathToolEntity = default; - if (old != null && IoCManager.Resolve().TryGetComponent(old, out BreathToolComponent? breathTool) ) + if (old != default && IoCManager.Resolve().TryGetComponent(old, out BreathToolComponent? breathTool) ) { breathTool.DisconnectInternals(); DisconnectTank(); } } - public void ConnectBreathTool(IEntity toolEntity) + public void ConnectBreathTool(EntityUid toolEntity) { - if (BreathToolEntity != null && IoCManager.Resolve().TryGetComponent(BreathToolEntity, out BreathToolComponent? tool)) + if (BreathToolEntity != default && IoCManager.Resolve().TryGetComponent(BreathToolEntity, out BreathToolComponent? tool)) { tool.DisconnectInternals(); } @@ -36,20 +36,20 @@ namespace Content.Server.Body.Components public void DisconnectTank() { - if (GasTankEntity != null && IoCManager.Resolve().TryGetComponent(GasTankEntity, out GasTankComponent? tank)) + if (GasTankEntity != default && IoCManager.Resolve().TryGetComponent(GasTankEntity, out GasTankComponent? tank)) { tank.DisconnectFromInternals(Owner); } - GasTankEntity = null; + GasTankEntity = default; } - public bool TryConnectTank(IEntity tankEntity) + public bool TryConnectTank(EntityUid tankEntity) { - if (BreathToolEntity == null) + if (BreathToolEntity == default) return false; - if (GasTankEntity != null && IoCManager.Resolve().TryGetComponent(GasTankEntity, out GasTankComponent? tank)) + if (GasTankEntity != default && IoCManager.Resolve().TryGetComponent(GasTankEntity, out GasTankComponent? tank)) { tank.DisconnectFromInternals(Owner); } @@ -60,12 +60,12 @@ namespace Content.Server.Body.Components public bool AreInternalsWorking() { - return BreathToolEntity != null && - GasTankEntity != null && + return BreathToolEntity != default && + GasTankEntity != default && IoCManager.Resolve().TryGetComponent(BreathToolEntity, out BreathToolComponent? breathTool) && breathTool.IsFunctional && IoCManager.Resolve().TryGetComponent(GasTankEntity, out GasTankComponent? gasTank) && - gasTank.Air != null; + gasTank.Air != default; } } diff --git a/Content.Server/Body/Components/MechanismComponent.cs b/Content.Server/Body/Components/MechanismComponent.cs index 8eb8a9d19d..ec5f538c4c 100644 --- a/Content.Server/Body/Components/MechanismComponent.cs +++ b/Content.Server/Body/Components/MechanismComponent.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Content.Server.UserInterface; using Content.Shared.Body.Components; -using Content.Shared.Body.Part; using Content.Shared.Body.Surgery; using Content.Shared.Interaction; using Content.Shared.Popups; @@ -20,6 +19,8 @@ namespace Content.Server.Body.Components [ComponentReference(typeof(SharedMechanismComponent))] public class MechanismComponent : SharedMechanismComponent, IAfterInteract { + [Dependency] private readonly IEntityManager _entities = default!; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SurgeryUIKey.Key); protected override void Initialize() @@ -44,17 +45,17 @@ namespace Content.Server.Body.Components PerformerCache = null; BodyCache = null; - if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out SharedBodyComponent? body)) + if (_entities.TryGetComponent(eventArgs.Target.Value, out SharedBodyComponent? body)) { SendBodyPartListToUser(eventArgs, body); } - else if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out var part)) + else if (_entities.TryGetComponent(eventArgs.Target.Value, out var part)) { DebugTools.AssertNotNull(part); if (!part.TryAddMechanism(this)) { - eventArgs.Target.PopupMessage(eventArgs.User, Loc.GetString("mechanism-component-cannot-fit-message")); + eventArgs.Target.Value.PopupMessage(eventArgs.User, Loc.GetString("mechanism-component-cannot-fit-message")); } } @@ -77,7 +78,7 @@ namespace Content.Server.Body.Components } if (OptionsCache.Count > 0 && - IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + _entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { OpenSurgeryUI(actor.PlayerSession); UpdateSurgeryUIBodyPartRequest(actor.PlayerSession, toSend); @@ -87,7 +88,7 @@ namespace Content.Server.Body.Components else // If surgery cannot be performed, show message saying so. { eventArgs.Target?.PopupMessage(eventArgs.User, - Loc.GetString("mechanism-component-no-way-to-install-message", ("partName", Name: IoCManager.Resolve().GetComponent(Owner).EntityName))); + Loc.GetString("mechanism-component-no-way-to-install-message", ("partName", Name: _entities.GetComponent(Owner).EntityName))); } } @@ -97,7 +98,7 @@ namespace Content.Server.Body.Components private void HandleReceiveBodyPart(int key) { if (PerformerCache == null || - !IoCManager.Resolve().TryGetComponent(PerformerCache, out ActorComponent? actor)) + !_entities.TryGetComponent(PerformerCache.Value, out ActorComponent? actor)) { return; } @@ -112,8 +113,8 @@ namespace Content.Server.Body.Components // TODO: sanity checks to see whether user is in range, user is still able-bodied, target is still the same, etc etc if (!OptionsCache.TryGetValue(key, out var targetObject)) { - BodyCache.Owner.PopupMessage(PerformerCache, - Loc.GetString("mechanism-component-no-useful-way-to-use-message",("partName", Name: IoCManager.Resolve().GetComponent(Owner).EntityName))); + BodyCache.Owner.PopupMessage(PerformerCache.Value, + Loc.GetString("mechanism-component-no-useful-way-to-use-message",("partName", Name: _entities.GetComponent(Owner).EntityName))); return; } @@ -122,7 +123,7 @@ namespace Content.Server.Body.Components ? Loc.GetString("mechanism-component-jam-inside-message",("ownerName", Owner),("them", PerformerCache)) : Loc.GetString("mechanism-component-cannot-fit-message"); - BodyCache.Owner.PopupMessage(PerformerCache, message); + BodyCache.Owner.PopupMessage(PerformerCache.Value, message); // TODO: {1:theName} } diff --git a/Content.Server/Body/Surgery/BiologicalSurgeryDataComponent.cs b/Content.Server/Body/Surgery/BiologicalSurgeryDataComponent.cs index b0285dcd6c..2a233b7d40 100644 --- a/Content.Server/Body/Surgery/BiologicalSurgeryDataComponent.cs +++ b/Content.Server/Body/Surgery/BiologicalSurgeryDataComponent.cs @@ -51,7 +51,7 @@ namespace Content.Server.Body.Surgery } } - private async Task SurgeryDoAfter(IEntity performer) + private async Task SurgeryDoAfter(EntityUid performer) { if (!IoCManager.Resolve().HasComponent(performer)) { @@ -203,7 +203,7 @@ namespace Content.Server.Body.Surgery return GetSurgeryStep(toolType) != null; } - public bool PerformSurgery(SurgeryType surgeryType, IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + public bool PerformSurgery(SurgeryType surgeryType, IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { var step = GetSurgeryStep(surgeryType); @@ -216,7 +216,7 @@ namespace Content.Server.Body.Surgery return true; } - private async void OpenSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private async void OpenSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) { @@ -231,7 +231,7 @@ namespace Content.Server.Body.Surgery } } - private async void ClampVesselsSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private async void ClampVesselsSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) return; @@ -243,7 +243,7 @@ namespace Content.Server.Body.Surgery } } - private async void RetractSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private async void RetractSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) return; @@ -255,7 +255,7 @@ namespace Content.Server.Body.Surgery } } - private async void CauterizeIncisionSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private async void CauterizeIncisionSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) return; @@ -269,7 +269,7 @@ namespace Content.Server.Body.Surgery } } - private void LoosenOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private void LoosenOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) return; if (Parent.Mechanisms.Count <= 0) return; @@ -290,7 +290,7 @@ namespace Content.Server.Body.Surgery } private async void LoosenOrganSurgeryCallback(SharedMechanismComponent? target, IBodyPartContainer container, ISurgeon surgeon, - IEntity performer) + EntityUid performer) { if (Parent == null || target == null || !Parent.Mechanisms.Contains(target)) { @@ -311,7 +311,7 @@ namespace Content.Server.Body.Surgery } } - private void RemoveOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private void RemoveOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) return; @@ -331,7 +331,7 @@ namespace Content.Server.Body.Surgery } private async void RemoveOrganSurgeryCallback(SharedMechanismComponent? target, IBodyPartContainer container, ISurgeon surgeon, - IEntity performer) + EntityUid performer) { if (Parent == null || target == null || !Parent.Mechanisms.Contains(target)) { @@ -354,7 +354,7 @@ namespace Content.Server.Body.Surgery } } - private async void RemoveBodyPartSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer) + private async void RemoveBodyPartSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer) { if (Parent == null) return; if (container is not SharedBodyComponent body) return; diff --git a/Content.Server/Body/Surgery/Components/SurgeryToolComponent.cs b/Content.Server/Body/Surgery/Components/SurgeryToolComponent.cs index 6020b766a8..70ccfd94d5 100644 --- a/Content.Server/Body/Surgery/Components/SurgeryToolComponent.cs +++ b/Content.Server/Body/Surgery/Components/SurgeryToolComponent.cs @@ -5,7 +5,6 @@ using Content.Server.Body.Components; using Content.Server.Body.Surgery.Messages; using Content.Server.UserInterface; using Content.Shared.Body.Components; -using Content.Shared.Body.Part; using Content.Shared.Body.Surgery; using Content.Shared.Interaction; using Content.Shared.Popups; @@ -27,6 +26,8 @@ namespace Content.Server.Body.Surgery.Components [RegisterComponent] public class SurgeryToolComponent : Component, ISurgeon, IAfterInteract { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "SurgeryTool"; private readonly Dictionary _optionsCache = new(); @@ -45,7 +46,7 @@ namespace Content.Server.Body.Surgery.Components public SharedBodyComponent? BodyCache { get; private set; } - public IEntity? PerformerCache { get; private set; } + public EntityUid? PerformerCache { get; private set; } async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { @@ -54,7 +55,7 @@ namespace Content.Server.Body.Surgery.Components return false; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { return false; } @@ -62,7 +63,7 @@ namespace Content.Server.Body.Surgery.Components CloseAllSurgeryUIs(); // Attempt surgery on a body by sending a list of operable parts for the client to choose from - if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out SharedBodyComponent? body)) + if (_entities.TryGetComponent(eventArgs.Target.Value, out SharedBodyComponent? body)) { // Create dictionary to send to client (text to be shown : data sent back if selected) var toSend = new Dictionary(); @@ -89,7 +90,7 @@ namespace Content.Server.Body.Surgery.Components NotUsefulPopup(); } } - else if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out var part)) + else if (_entities.TryGetComponent(eventArgs.Target.Value, out var part)) { // Attempt surgery on a DroppedBodyPart - there's only one possible target so no need for selection UI PerformerCache = eventArgs.User; @@ -109,7 +110,7 @@ namespace Content.Server.Body.Surgery.Components } // Log error if the surgery fails somehow. - Logger.Debug($"Error when trying to perform surgery on ${nameof(SharedBodyPartComponent)} {IoCManager.Resolve().GetComponent(eventArgs.User).EntityName}"); + Logger.Debug($"Error when trying to perform surgery on ${nameof(SharedBodyPartComponent)} {_entities.GetComponent(eventArgs.User).EntityName}"); throw new InvalidOperationException(); } @@ -129,8 +130,8 @@ namespace Content.Server.Body.Surgery.Components if (_optionsCache.Count > 0 && PerformerCache != null) { - OpenSurgeryUI(IoCManager.Resolve().GetComponent(PerformerCache).PlayerSession); - UpdateSurgeryUIMechanismRequest(IoCManager.Resolve().GetComponent(PerformerCache).PlayerSession, + OpenSurgeryUI(_entities.GetComponent(PerformerCache.Value).PlayerSession); + UpdateSurgeryUIMechanismRequest(_entities.GetComponent(PerformerCache.Value).PlayerSession, toSend); _callbackCache = callback; } @@ -160,7 +161,7 @@ namespace Content.Server.Body.Surgery.Components #pragma warning disable 618 SendMessage(message); #pragma warning restore 618 - IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, message); + _entities.EventBus.RaiseEvent(EventSource.Local, message); } private void UpdateSurgeryUIBodyPartRequest(IPlayerSession session, Dictionary options) @@ -214,7 +215,7 @@ namespace Content.Server.Body.Surgery.Components private void HandleReceiveBodyPart(int key) { if (PerformerCache == null || - !IoCManager.Resolve().TryGetComponent(PerformerCache, out ActorComponent? actor)) + !_entities.TryGetComponent(PerformerCache.Value, out ActorComponent? actor)) { return; } @@ -228,10 +229,10 @@ namespace Content.Server.Body.Surgery.Components return; } - var target = (SharedBodyPartComponent) targetObject!; + var target = (SharedBodyPartComponent) targetObject; // TODO BODY Reconsider - if (!target.AttemptSurgery(_surgeryType, BodyCache, this, PerformerCache)) + if (!target.AttemptSurgery(_surgeryType, BodyCache, this, PerformerCache.Value)) { NotUsefulAnymorePopup(); } @@ -248,21 +249,21 @@ namespace Content.Server.Body.Surgery.Components !_optionsCache.TryGetValue(key, out var targetObject) || targetObject is not MechanismComponent target || PerformerCache == null || - !IoCManager.Resolve().TryGetComponent(PerformerCache, out ActorComponent? actor)) + !_entities.TryGetComponent(PerformerCache.Value, out ActorComponent? actor)) { NotUsefulAnymorePopup(); return; } CloseSurgeryUI(actor.PlayerSession); - _callbackCache?.Invoke(target, BodyCache, this, PerformerCache); + _callbackCache?.Invoke(target, BodyCache, this, PerformerCache.Value); } private void NotUsefulPopup() { if (PerformerCache == null) return; - BodyCache?.Owner.PopupMessage(PerformerCache, + BodyCache?.Owner.PopupMessage(PerformerCache.Value, Loc.GetString("surgery-tool-component-not-useful-message", ("bodyPart", Owner))); } @@ -270,7 +271,7 @@ namespace Content.Server.Body.Surgery.Components { if (PerformerCache == null) return; - BodyCache?.Owner.PopupMessage(PerformerCache, + BodyCache?.Owner.PopupMessage(PerformerCache.Value, Loc.GetString("surgery-tool-component-not-useful-anymore-message", ("bodyPart", Owner))); } } diff --git a/Content.Server/Body/Surgery/Components/SurgeryToolSystem.cs b/Content.Server/Body/Surgery/Components/SurgeryToolSystem.cs index 5e95ace8be..279e71b7e7 100644 --- a/Content.Server/Body/Surgery/Components/SurgeryToolSystem.cs +++ b/Content.Server/Body/Surgery/Components/SurgeryToolSystem.cs @@ -2,7 +2,6 @@ using Content.Server.Body.Surgery.Messages; using Content.Shared.ActionBlocker; using Content.Shared.GameTicking; -using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Helpers; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -57,8 +56,8 @@ namespace Content.Server.Body.Surgery.Components continue; } - if (!_actionBlockerSystem.CanInteract(tool.PerformerCache) || - !tool.PerformerCache.InRangeUnobstructed(tool.BodyCache)) + if (!_actionBlockerSystem.CanInteract(tool.PerformerCache.Value) || + !tool.PerformerCache.Value.InRangeUnobstructed(tool.BodyCache)) { tool.CloseAllSurgeryUIs(); } diff --git a/Content.Server/Body/Systems/MetabolizerSystem.cs b/Content.Server/Body/Systems/MetabolizerSystem.cs index 39f77931c5..4fc32bbadb 100644 --- a/Content.Server/Body/Systems/MetabolizerSystem.cs +++ b/Content.Server/Body/Systems/MetabolizerSystem.cs @@ -89,7 +89,7 @@ namespace Content.Server.Body.Systems if (!Resolve(((IComponent) body).Owner, ref manager, false)) return; _solutionContainerSystem.TryGetSolution(((IComponent) body).Owner, meta.SolutionName, out solution, manager); - solutionEntityUid = body.OwnerUid; + solutionEntityUid = body.Owner; } } } @@ -163,7 +163,7 @@ namespace Content.Server.Body.Systems if (effect.ShouldLog) { - var entity = EntityManager.GetEntity(args.SolutionEntity); + var entity = args.SolutionEntity; _logSystem.Add(LogType.ReagentEffect, effect.LogImpact, $"Metabolism effect {effect.GetType().Name} of reagent {args.Reagent.Name:reagent} applied on entity {entity} at {IoCManager.Resolve().GetComponent(entity).Coordinates}"); } diff --git a/Content.Server/Body/Systems/RespiratorSystem.cs b/Content.Server/Body/Systems/RespiratorSystem.cs index 4599e59f55..993dcd8ec9 100644 --- a/Content.Server/Body/Systems/RespiratorSystem.cs +++ b/Content.Server/Body/Systems/RespiratorSystem.cs @@ -199,7 +199,7 @@ namespace Content.Server.Body.Systems private void TakeSuffocationDamage(EntityUid uid, RespiratorComponent respirator) { if (!respirator.Suffocating) - _logSys.Add(LogType.Asphyxiation, $"{EntityManager.GetEntity(uid)} started suffocating"); + _logSys.Add(LogType.Asphyxiation, $"{uid:Entity} started suffocating"); respirator.Suffocating = true; @@ -214,7 +214,7 @@ namespace Content.Server.Body.Systems private void StopSuffocation(EntityUid uid, RespiratorComponent respirator) { if (respirator.Suffocating) - _logSys.Add(LogType.Asphyxiation, $"{EntityManager.GetEntity(uid)} stopped suffocating"); + _logSys.Add(LogType.Asphyxiation, $"{uid:Entity} stopped suffocating"); respirator.Suffocating = false; diff --git a/Content.Server/Botany/Components/LogComponent.cs b/Content.Server/Botany/Components/LogComponent.cs index 632846476a..9384d28f55 100644 --- a/Content.Server/Botany/Components/LogComponent.cs +++ b/Content.Server/Botany/Components/LogComponent.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using Content.Shared.ActionBlocker; using Content.Shared.Interaction; -using Content.Shared.Interaction.Events; using Content.Shared.Random.Helpers; using Content.Shared.Tag; using Robust.Shared.GameObjects; @@ -27,7 +26,7 @@ namespace Content.Server.Botany.Components plank.RandomOffset(0.25f); } - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); return true; } diff --git a/Content.Server/Botany/Components/PlantHolderComponent.cs b/Content.Server/Botany/Components/PlantHolderComponent.cs index 55c136befc..075a14178a 100644 --- a/Content.Server/Botany/Components/PlantHolderComponent.cs +++ b/Content.Server/Botany/Components/PlantHolderComponent.cs @@ -18,7 +18,6 @@ using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Random.Helpers; using Content.Shared.Tag; -using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -419,7 +418,7 @@ namespace Content.Server.Botany.Components MutationMod = MathHelper.Clamp(MutationMod, 0f, 3f); } - public bool DoHarvest(IEntity user) + public bool DoHarvest(EntityUid user) { if (Seed == null || (!IoCManager.Resolve().EntityExists(user) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(user).EntityLifeStage) >= EntityLifeStage.Deleted || !EntitySystem.Get().CanInteract(user)) return false; @@ -661,7 +660,7 @@ namespace Content.Server.Botany.Components if (seeds.Seed == null) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-seed-packet-message")); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) usingItem); + IoCManager.Resolve().QueueDeleteEntity(usingItem); return false; } @@ -675,7 +674,7 @@ namespace Content.Server.Botany.Components Health = Seed.Endurance; _lastCycle = _gameTiming.CurTime; - IoCManager.Resolve().QueueDeleteEntity((EntityUid) usingItem); + IoCManager.Resolve().QueueDeleteEntity(usingItem); CheckLevelSanity(); UpdateSprite(); @@ -731,8 +730,8 @@ namespace Content.Server.Botany.Components { var amount = FixedPoint2.New(5); var sprayed = false; - var targetEntity = (EntityUid) Owner; - var solutionEntity = (EntityUid) usingItem; + var targetEntity = Owner; + var solutionEntity = usingItem; if (IoCManager.Resolve().TryGetComponent(usingItem, out SprayComponent? spray)) { @@ -823,7 +822,7 @@ namespace Content.Server.Botany.Components ForceUpdateByExternalCause(); } - IoCManager.Resolve().QueueDeleteEntity((EntityUid) usingItem); + IoCManager.Resolve().QueueDeleteEntity(usingItem); return true; } diff --git a/Content.Server/Botany/Components/SeedExtractorComponent.cs b/Content.Server/Botany/Components/SeedExtractorComponent.cs index 78229fe2d4..5476bfcae5 100644 --- a/Content.Server/Botany/Components/SeedExtractorComponent.cs +++ b/Content.Server/Botany/Components/SeedExtractorComponent.cs @@ -31,7 +31,7 @@ namespace Content.Server.Botany.Components { eventArgs.User.PopupMessageCursor(Loc.GetString("seed-extractor-component-interact-message",("name", Name: IoCManager.Resolve().GetComponent(eventArgs.Using).EntityName))); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) eventArgs.Using); + IoCManager.Resolve().QueueDeleteEntity(eventArgs.Using); var random = _random.Next(_minSeeds, _maxSeeds); diff --git a/Content.Server/Botany/Seed.cs b/Content.Server/Botany/Seed.cs index 1e11c2f69e..a9648df2a2 100644 --- a/Content.Server/Botany/Seed.cs +++ b/Content.Server/Botany/Seed.cs @@ -248,7 +248,7 @@ namespace Content.Server.Botany return newSeed; } - public IEntity SpawnSeedPacket(EntityCoordinates transformCoordinates, IEntityManager? entityManager = null) + public EntityUid SpawnSeedPacket(EntityCoordinates transformCoordinates, IEntityManager? entityManager = null) { entityManager ??= IoCManager.Resolve(); @@ -278,33 +278,33 @@ namespace Content.Server.Botany } } - public IEnumerable AutoHarvest(EntityCoordinates position, int yieldMod = 1) + public IEnumerable AutoHarvest(EntityCoordinates position, int yieldMod = 1) { if (position.IsValid(IoCManager.Resolve()) && ProductPrototypes != null && ProductPrototypes.Count > 0) return GenerateProduct(position, yieldMod); - return Enumerable.Empty(); + return Enumerable.Empty(); } - public IEnumerable Harvest(IEntity user, int yieldMod = 1) + public IEnumerable Harvest(EntityUid user, int yieldMod = 1) { AddToDatabase(); if (user == null) - return Enumerable.Empty(); + return Enumerable.Empty(); if (ProductPrototypes == null || ProductPrototypes.Count == 0 || Yield <= 0) { user.PopupMessageCursor(Loc.GetString("botany-harvest-fail-message")); - return Enumerable.Empty(); + return Enumerable.Empty(); } user.PopupMessageCursor(Loc.GetString("botany-harvest-success-message", ("name", DisplayName))); return GenerateProduct(IoCManager.Resolve().GetComponent(user).Coordinates, yieldMod); } - public IEnumerable GenerateProduct(EntityCoordinates position, int yieldMod = 1) + public IEnumerable GenerateProduct(EntityCoordinates position, int yieldMod = 1) { var totalYield = 0; if (Yield > -1) @@ -325,7 +325,7 @@ namespace Content.Server.Botany var random = IoCManager.Resolve(); var entityManager = IoCManager.Resolve(); - var products = new List(); + var products = new List(); for (var i = 0; i < totalYield; i++) { @@ -357,9 +357,9 @@ namespace Content.Server.Botany return Clone(); } - public bool CheckHarvest(IEntity user, IEntity? held = null) + public bool CheckHarvest(EntityUid user, EntityUid? held = null) { - return (!Ligneous || (Ligneous && held != null && held.HasTag("BotanySharp"))); + return !Ligneous || (Ligneous && held != null && held.Value.HasTag("BotanySharp")); } } } diff --git a/Content.Server/Bql/QuerySelectors.cs b/Content.Server/Bql/QuerySelectors.cs index c900413a1c..5431cb19ce 100644 --- a/Content.Server/Bql/QuerySelectors.cs +++ b/Content.Server/Bql/QuerySelectors.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Mind.Components; using Content.Server.Power.Components; -using Content.Server.Chemistry.Components.SolutionManager; using Content.Shared.Tag; using Robust.Server.Bql; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Server.Bql { @@ -36,7 +35,7 @@ namespace Content.Server.Bql { return DoSelection( - entityManager.EntityQuery().Select(x => (EntityUid) x.Owner), + entityManager.EntityQuery().Select(x => x.Owner), arguments, isInverted, entityManager); } } @@ -57,7 +56,7 @@ namespace Content.Server.Bql public override IEnumerable DoInitialSelection(IReadOnlyList arguments, bool isInverted, IEntityManager entityManager) { - return DoSelection(entityManager.EntityQuery().Select(x => (EntityUid) x.Owner), arguments, + return DoSelection(entityManager.EntityQuery().Select(x => x.Owner), arguments, isInverted, entityManager); } @@ -79,7 +78,7 @@ namespace Content.Server.Bql public override IEnumerable DoInitialSelection(IReadOnlyList arguments, bool isInverted, IEntityManager entityManager) { - return DoSelection(entityManager.EntityQuery().Select(x => (EntityUid) x.Owner), arguments, + return DoSelection(entityManager.EntityQuery().Select(x => x.Owner), arguments, isInverted, entityManager); } } @@ -108,7 +107,7 @@ namespace Content.Server.Bql public override IEnumerable DoInitialSelection(IReadOnlyList arguments, bool isInverted, IEntityManager entityManager) { - return DoSelection(entityManager.EntityQuery().Select(x => (EntityUid) x.Owner), arguments, + return DoSelection(entityManager.EntityQuery().Select(x => x.Owner), arguments, isInverted, entityManager); } } @@ -130,7 +129,7 @@ namespace Content.Server.Bql public override IEnumerable DoInitialSelection(IReadOnlyList arguments, bool isInverted, IEntityManager entityManager) { - return DoSelection(entityManager.EntityQuery().Select(x => (EntityUid) x.Owner), arguments, + return DoSelection(entityManager.EntityQuery().Select(x => x.Owner), arguments, isInverted, entityManager); } } diff --git a/Content.Server/Buckle/Components/BuckleComponent.cs b/Content.Server/Buckle/Components/BuckleComponent.cs index df8c9d0817..ed0fbc8a01 100644 --- a/Content.Server/Buckle/Components/BuckleComponent.cs +++ b/Content.Server/Buckle/Components/BuckleComponent.cs @@ -1,3 +1,5 @@ +using System; +using System.Diagnostics.CodeAnalysis; using Content.Server.Alert; using Content.Server.Hands.Components; using Content.Server.Pulling; @@ -20,8 +22,6 @@ using Robust.Shared.Player; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; -using System; -using System.Diagnostics.CodeAnalysis; namespace Content.Server.Buckle.Components { @@ -115,8 +115,8 @@ namespace Content.Server.Buckle.Components /// The strap to reattach to. public void ReAttach(StrapComponent strap) { - var ownTransform = _entityManager.GetComponent(OwnerUid); - var strapTransform = _entityManager.GetComponent(strap.OwnerUid); + var ownTransform = _entityManager.GetComponent(Owner); + var strapTransform = _entityManager.GetComponent(strap.Owner); ownTransform.AttachParent(strapTransform); ownTransform.LocalRotation = Angle.Zero; @@ -126,10 +126,10 @@ namespace Content.Server.Buckle.Components case StrapPosition.None: break; case StrapPosition.Stand: - EntitySystem.Get().Stand(OwnerUid); + EntitySystem.Get().Stand(Owner); break; case StrapPosition.Down: - EntitySystem.Get().Down(OwnerUid, false, false); + EntitySystem.Get().Down(Owner, false, false); break; } @@ -157,10 +157,10 @@ namespace Content.Server.Buckle.Components return false; } - var strapUid = strap.OwnerUid; - bool Ignored(EntityUid entity) => entity == OwnerUid || entity == user || entity == strapUid; + var strapUid = strap.Owner; + bool Ignored(EntityUid entity) => entity == Owner || entity == user || entity == strapUid; - if (!OwnerUid.InRangeUnobstructed(strapUid, Range, predicate: Ignored, popup: true)) + if (!Owner.InRangeUnobstructed(strapUid, Range, predicate: Ignored, popup: true)) { return false; } @@ -184,7 +184,7 @@ namespace Content.Server.Buckle.Components if (Buckled) { - var message = Loc.GetString(OwnerUid == user + var message = Loc.GetString(Owner == user ? "buckle-component-already-buckled-message" : "buckle-component-other-already-buckled-message", ("owner", Owner)); popupSystem.PopupEntity(message, user, Filter.Entities(user)); @@ -197,7 +197,7 @@ namespace Content.Server.Buckle.Components { if (parent == _entityManager.GetComponent(user)) { - var message = Loc.GetString(OwnerUid == user + var message = Loc.GetString(Owner == user ? "buckle-component-cannot-buckle-message" : "buckle-component-other-cannot-buckle-message", ("owner", Owner)); popupSystem.PopupEntity(message, user, Filter.Entities(user)); @@ -210,7 +210,7 @@ namespace Content.Server.Buckle.Components if (!strap.HasSpace(this)) { - var message = Loc.GetString(OwnerUid == user + var message = Loc.GetString(Owner == user ? "buckle-component-cannot-fit-message" : "buckle-component-other-cannot-fit-message", ("owner", Owner)); popupSystem.PopupEntity(message, user, Filter.Entities(user)); @@ -233,7 +233,7 @@ namespace Content.Server.Buckle.Components if (!strap.TryAdd(this)) { - var message = Loc.GetString(OwnerUid == user + var message = Loc.GetString(Owner == user ? "buckle-component-cannot-buckle-message" : "buckle-component-other-cannot-buckle-message", ("owner", Owner)); popupSystem.PopupEntity(message, user, Filter.Entities(user)); @@ -245,16 +245,16 @@ namespace Content.Server.Buckle.Components ReAttach(strap); BuckledTo = strap; - LastEntityBuckledTo = BuckledTo.OwnerUid; + LastEntityBuckledTo = BuckledTo.Owner; DontCollide = true; UpdateBuckleStatus(); #pragma warning disable 618 - SendMessage(new BuckleMessage(OwnerUid, to)); + SendMessage(new BuckleMessage(Owner, to)); #pragma warning restore 618 - if (_entityManager.TryGetComponent(OwnerUid, out SharedPullableComponent? ownerPullable)) + if (_entityManager.TryGetComponent(Owner, out SharedPullableComponent? ownerPullable)) { if (ownerPullable.Puller != null) { @@ -309,7 +309,7 @@ namespace Content.Server.Buckle.Components return false; } - if (!user.InRangeUnobstructed(oldBuckledTo.OwnerUid, Range, popup: true)) + if (!user.InRangeUnobstructed(oldBuckledTo.Owner, Range, popup: true)) { return false; } @@ -317,25 +317,25 @@ namespace Content.Server.Buckle.Components BuckledTo = null; - if (_entityManager.GetComponent(OwnerUid).Parent == _entityManager.GetComponent(oldBuckledTo.OwnerUid)) + if (_entityManager.GetComponent(Owner).Parent == _entityManager.GetComponent(oldBuckledTo.Owner)) { - _entityManager.GetComponent(OwnerUid).AttachParentToContainerOrGrid(); - _entityManager.GetComponent(OwnerUid).WorldRotation = _entityManager.GetComponent(oldBuckledTo.OwnerUid).WorldRotation; + _entityManager.GetComponent(Owner).AttachParentToContainerOrGrid(); + _entityManager.GetComponent(Owner).WorldRotation = _entityManager.GetComponent(oldBuckledTo.Owner).WorldRotation; } Appearance?.SetData(BuckleVisuals.Buckled, false); - if (IoCManager.Resolve().HasComponent(OwnerUid) + if (IoCManager.Resolve().HasComponent(Owner) || (_mobState?.IsIncapacitated() ?? false)) { - EntitySystem.Get().Down(OwnerUid); + EntitySystem.Get().Down(Owner); } else { - EntitySystem.Get().Stand(OwnerUid); + EntitySystem.Get().Stand(Owner); } - _mobState?.CurrentState?.EnterState(OwnerUid, IoCManager.Resolve()); + _mobState?.CurrentState?.EnterState(Owner, IoCManager.Resolve()); UpdateBuckleStatus(); @@ -343,7 +343,7 @@ namespace Content.Server.Buckle.Components SoundSystem.Play(Filter.Pvs(Owner), oldBuckledTo.UnbuckleSound.GetSound(), Owner); #pragma warning disable 618 - SendMessage(new UnbuckleMessage(OwnerUid, oldBuckledTo.OwnerUid)); + SendMessage(new UnbuckleMessage(Owner, oldBuckledTo.Owner)); #pragma warning restore 618 return true; @@ -365,7 +365,7 @@ namespace Content.Server.Buckle.Components /// true if the buckling status was changed, false otherwise. public bool ToggleBuckle(EntityUid user, EntityUid to, bool force = false) { - if (BuckledTo?.OwnerUid == to) + if (BuckledTo?.Owner == to) { return TryUnbuckle(user, force); } @@ -382,7 +382,7 @@ namespace Content.Server.Buckle.Components protected override void Shutdown() { BuckledTo?.Remove(this); - TryUnbuckle(OwnerUid, true); + TryUnbuckle(Owner, true); _buckleTime = default; UpdateBuckleStatus(); @@ -395,7 +395,7 @@ namespace Content.Server.Buckle.Components int? drawDepth = null; if (BuckledTo != null && - IoCManager.Resolve().GetComponent(BuckledTo.OwnerUid).LocalRotation.GetCardinalDir() == Direction.North && + IoCManager.Resolve().GetComponent(BuckledTo.Owner).LocalRotation.GetCardinalDir() == Direction.North && BuckledTo.SpriteComponent != null) { drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1; @@ -414,7 +414,7 @@ namespace Content.Server.Buckle.Components if (!IsOnStrapEntityThisFrame && DontCollide) { DontCollide = false; - TryUnbuckle(OwnerUid); + TryUnbuckle(Owner); Dirty(); } diff --git a/Content.Server/Buckle/Components/StrapComponent.cs b/Content.Server/Buckle/Components/StrapComponent.cs index b7e520e0b3..0e650dfd83 100644 --- a/Content.Server/Buckle/Components/StrapComponent.cs +++ b/Content.Server/Buckle/Components/StrapComponent.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Content.Shared.ActionBlocker; using Content.Shared.Acts; using Content.Shared.Alert; using Content.Shared.Buckle.Components; @@ -10,7 +9,6 @@ using Content.Shared.Sound; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -23,7 +21,7 @@ namespace Content.Server.Buckle.Components { [ComponentDependency] public readonly SpriteComponent? SpriteComponent = null; - private readonly HashSet _buckledEntities = new(); + private readonly HashSet _buckledEntities = new(); /// /// The angle in degrees to rotate the player by when they get strapped @@ -40,7 +38,7 @@ namespace Content.Server.Buckle.Components /// /// The entity that is currently buckled here, synced from /// - public IReadOnlyCollection BuckledEntities => _buckledEntities; + public IReadOnlyCollection BuckledEntities => _buckledEntities; /// /// The change in position to the strapped mob diff --git a/Content.Server/Buckle/Systems/StrapSystem.cs b/Content.Server/Buckle/Systems/StrapSystem.cs index 359de7388e..9acd58d2db 100644 --- a/Content.Server/Buckle/Systems/StrapSystem.cs +++ b/Content.Server/Buckle/Systems/StrapSystem.cs @@ -1,14 +1,11 @@ using Content.Server.Buckle.Components; using Content.Server.Interaction; -using Content.Shared.Hands.Components; -using Content.Shared.Interaction.Helpers; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using System.Collections.Generic; namespace Content.Server.Buckle.Systems { @@ -39,7 +36,7 @@ namespace Content.Server.Buckle.Systems // Add unstrap verbs for every strapped entity. foreach (var entity in component.BuckledEntities) { - var buckledComp = IoCManager.Resolve().GetComponent(entity); + var buckledComp = EntityManager.GetComponent(entity); if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target, range: buckledComp.Range)) continue; @@ -50,7 +47,7 @@ namespace Content.Server.Buckle.Systems if (entity == args.User) verb.Text = Loc.GetString("verb-self-target-pronoun"); else - verb.Text = IoCManager.Resolve().GetComponent(entity).EntityName; + verb.Text = EntityManager.GetComponent(entity).EntityName; // In the event that you have more than once entity with the same name strapped to the same object, // these two verbs will be identical according to Verb.CompareTo, and only one with actually be added to @@ -61,7 +58,7 @@ namespace Content.Server.Buckle.Systems } // Add a verb to buckle the user. - if (IoCManager.Resolve().TryGetComponent(args.User, out var buckle) && + if (EntityManager.TryGetComponent(args.User, out var buckle) && buckle.BuckledTo != component && args.User != component.Owner && component.HasSpace(buckle) && @@ -75,24 +72,24 @@ namespace Content.Server.Buckle.Systems } // If the user is currently holding/pulling an entity that can be buckled, add a verb for that. - if (args.Using != null && - IoCManager.Resolve().TryGetComponent(args.Using, out var usingBuckle) && + if (args.Using is {Valid: true} @using && + EntityManager.TryGetComponent(@using, out var usingBuckle) && component.HasSpace(usingBuckle) && - _interactionSystem.InRangeUnobstructed(args.Using, args.Target, range: usingBuckle.Range)) + _interactionSystem.InRangeUnobstructed(@using, args.Target, range: usingBuckle.Range)) { // Check that the entity is unobstructed from the target (ignoring the user). - bool Ignored(IEntity entity) => entity == args.User || entity == args.Target || entity == args.Using; - if (!_interactionSystem.InRangeUnobstructed(args.Using, args.Target, usingBuckle.Range, predicate: Ignored)) + bool Ignored(EntityUid entity) => entity == args.User || entity == args.Target || entity == @using; + if (!_interactionSystem.InRangeUnobstructed(@using, args.Target, usingBuckle.Range, predicate: Ignored)) return; Verb verb = new(); verb.Act = () => usingBuckle.TryBuckle(args.User, args.Target); verb.Category = VerbCategory.Buckle; - verb.Text = IoCManager.Resolve().GetComponent(args.Using).EntityName; + verb.Text = EntityManager.GetComponent(@using).EntityName; // If the used entity is a person being pulled, prioritize this verb. Conversely, if it is // just a held object, the user is probably just trying to sit down. - verb.Priority = IoCManager.Resolve().HasComponent(args.Using) ? 1 : -1; + verb.Priority = EntityManager.HasComponent(@using) ? 1 : -1; args.Verbs.Add(verb); } diff --git a/Content.Server/Cargo/Components/CargoConsoleComponent.cs b/Content.Server/Cargo/Components/CargoConsoleComponent.cs index 4018f466fd..1e6f0ba9d4 100644 --- a/Content.Server/Cargo/Components/CargoConsoleComponent.cs +++ b/Content.Server/Cargo/Components/CargoConsoleComponent.cs @@ -4,7 +4,6 @@ using Content.Server.Power.Components; using Content.Server.UserInterface; using Content.Shared.Cargo; using Content.Shared.Cargo.Components; -using Content.Shared.Interaction; using Content.Shared.Sound; using Robust.Server.GameObjects; using Robust.Shared.Audio; @@ -131,8 +130,7 @@ namespace Content.Server.Cargo.Components break; } - var uid = msg.Session.AttachedEntityUid; - if (uid == null) + if (msg.Session.AttachedEntity is not {Valid: true} player) break; PrototypeManager.TryIndex(order.ProductId, out CargoProductPrototype? product); @@ -143,7 +141,7 @@ namespace Content.Server.Cargo.Components (capacity.CurrentCapacity == capacity.MaxCapacity || capacity.CurrentCapacity + order.Amount > capacity.MaxCapacity || !_cargoConsoleSystem.CheckBalance(_bankAccount.Id, (-product.PointCost) * order.Amount) - || !_cargoConsoleSystem.ApproveOrder(Owner, uid.Value, orders.Database.Id, msg.OrderNumber) + || !_cargoConsoleSystem.ApproveOrder(Owner, player, orders.Database.Id, msg.OrderNumber) || !_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)) ) { @@ -161,11 +159,11 @@ namespace Content.Server.Cargo.Components // TODO replace with shuttle code // TEMPORARY loop for spawning stuff on telepad (looks for a telepad adjacent to the console) - IEntity? cargoTelepad = null; + EntityUid? cargoTelepad = null; var indices = IoCManager.Resolve().GetComponent(Owner).Coordinates.ToVector2i(IoCManager.Resolve(), _mapManager); var offsets = new Vector2i[] { new Vector2i(0, 1), new Vector2i(1, 1), new Vector2i(1, 0), new Vector2i(1, -1), new Vector2i(0, -1), new Vector2i(-1, -1), new Vector2i(-1, 0), new Vector2i(-1, 1), }; - var adjacentEntities = new List>(); //Probably better than IEnumerable.concat + var adjacentEntities = new List>(); //Probably better than IEnumerable.concat foreach (var offset in offsets) { adjacentEntities.Add((indices+offset).GetEntitiesInTileFast(IoCManager.Resolve().GetComponent(Owner).GridID)); @@ -173,7 +171,7 @@ namespace Content.Server.Cargo.Components foreach (var enumerator in adjacentEntities) { - foreach (IEntity entity in enumerator) + foreach (EntityUid entity in enumerator) { if (IoCManager.Resolve().HasComponent(entity) && IoCManager.Resolve().TryGetComponent(entity, out var powerReceiver) && powerReceiver.Powered) { @@ -184,7 +182,7 @@ namespace Content.Server.Cargo.Components } if (cargoTelepad != null) { - if (IoCManager.Resolve().TryGetComponent(cargoTelepad, out var telepadComponent)) + if (IoCManager.Resolve().TryGetComponent(cargoTelepad.Value, out var telepadComponent)) { var approvedOrders = _cargoConsoleSystem.RemoveAndGetApprovedOrders(orders.Database.Id); orders.Database.ClearOrderCapacity(); diff --git a/Content.Server/CharacterAppearance/Components/MagicMirrorComponent.cs b/Content.Server/CharacterAppearance/Components/MagicMirrorComponent.cs index c59ec1a9c2..c980287e5e 100644 --- a/Content.Server/CharacterAppearance/Components/MagicMirrorComponent.cs +++ b/Content.Server/CharacterAppearance/Components/MagicMirrorComponent.cs @@ -17,6 +17,7 @@ namespace Content.Server.CharacterAppearance.Components [ComponentReference(typeof(IActivate))] public class MagicMirrorComponent : SharedMagicMirrorComponent, IActivate { + [Dependency] private readonly IEntityManager _entities = default!; [Dependency] private readonly SpriteAccessoryManager _spriteAccessoryManager = default!; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MagicMirrorUiKey.Key); @@ -43,12 +44,12 @@ namespace Content.Server.CharacterAppearance.Components private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) { - if (obj.Session.AttachedEntity == null) + if (obj.Session.AttachedEntity is not {Valid: true} player) { return; } - if (!IoCManager.Resolve().TryGetComponent(obj.Session.AttachedEntity, out HumanoidAppearanceComponent? looks)) + if (!_entities.TryGetComponent(player, out HumanoidAppearanceComponent? looks)) { return; } @@ -91,17 +92,17 @@ namespace Content.Server.CharacterAppearance.Components break; } - EntitySystem.Get().ForceAppearanceUpdate(obj.Session.AttachedEntity); + EntitySystem.Get().ForceAppearanceUpdate(player); } void IActivate.Activate(ActivateEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (!_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { return; } - if (!IoCManager.Resolve().TryGetComponent(eventArgs.User, out HumanoidAppearanceComponent? looks)) + if (!_entities.TryGetComponent(eventArgs.User, out HumanoidAppearanceComponent? looks)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("magic-mirror-component-activate-user-has-no-hair")); return; diff --git a/Content.Server/Chat/Commands/MeCommand.cs b/Content.Server/Chat/Commands/MeCommand.cs index e19c8d2879..5884ae9f9d 100644 --- a/Content.Server/Chat/Commands/MeCommand.cs +++ b/Content.Server/Chat/Commands/MeCommand.cs @@ -24,7 +24,7 @@ namespace Content.Server.Chat.Commands return; } - if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue) + if (player.Status != SessionStatus.InGame || !player.AttachedEntity.HasValue) return; if (args.Length < 1) diff --git a/Content.Server/Chat/Commands/SayCommand.cs b/Content.Server/Chat/Commands/SayCommand.cs index 718ca42667..6d6034532b 100644 --- a/Content.Server/Chat/Commands/SayCommand.cs +++ b/Content.Server/Chat/Commands/SayCommand.cs @@ -19,14 +19,13 @@ namespace Content.Server.Chat.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { - var player = shell.Player as IPlayerSession; - if (player == null) + if (shell.Player is not IPlayerSession player) { shell.WriteLine("This command cannot be run from the server."); return; } - if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue) + if (player.Status != SessionStatus.InGame || !player.AttachedEntity.HasValue) return; if (args.Length < 1) @@ -38,9 +37,8 @@ namespace Content.Server.Chat.Commands var chat = IoCManager.Resolve(); var chatSanitizer = IoCManager.Resolve(); - var playerEntity = player.AttachedEntity; - if (playerEntity == null) + if (player.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("You don't have an entity!"); return; @@ -58,7 +56,7 @@ namespace Content.Server.Chat.Commands return; } - if (mindComponent.OwnedEntity == null) + if (mindComponent.OwnedEntity == default) { shell.WriteError("You don't have an entity!"); return; diff --git a/Content.Server/Chat/Commands/SuicideCommand.cs b/Content.Server/Chat/Commands/SuicideCommand.cs index 6ebaeb5ad9..82e5a4e45a 100644 --- a/Content.Server/Chat/Commands/SuicideCommand.cs +++ b/Content.Server/Chat/Commands/SuicideCommand.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Linq; using Content.Server.Act; using Content.Server.Administration; @@ -9,7 +8,6 @@ using Content.Server.Hands.Components; using Content.Server.Items; using Content.Server.Players; using Content.Server.Popups; -using Content.Shared.Administration.Logs; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using Content.Shared.Database; @@ -27,13 +25,15 @@ namespace Content.Server.Chat.Commands [AnyCommand] internal class SuicideCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entities = default!; + public string Command => "suicide"; public string Description => Loc.GetString("suicide-command-description"); public string Help => Loc.GetString("suicide-command-help-text"); - private void DealDamage(ISuicideAct suicide, IChatManager chat, IEntity target) + private void DealDamage(ISuicideAct suicide, IChatManager chat, EntityUid target) { var kind = suicide.Suicide(target, chat); if (kind != SuicideKind.Special) @@ -73,10 +73,9 @@ namespace Content.Server.Chat.Commands var chat = IoCManager.Resolve(); var mind = player.ContentData()?.Mind; - var owner = mind?.OwnedComponent?.Owner; // This check also proves mind not-null for at the end when the mob is ghosted. - if (owner == null) + if (mind?.OwnedComponent?.Owner is not {Valid: true} owner) { shell.WriteLine("You don't have a mind!"); return; @@ -88,11 +87,11 @@ namespace Content.Server.Chat.Commands EntitySystem.Get().Add(LogType.Suicide, $"{player.AttachedEntity} is committing suicide"); // Held item suicide - var handsComponent = IoCManager.Resolve().GetComponent(owner); + var handsComponent = _entities.GetComponent(owner); var itemComponent = handsComponent.GetActiveHand; if (itemComponent != null) { - var suicide = IoCManager.Resolve().GetComponents(itemComponent.Owner).FirstOrDefault(); + var suicide = _entities.GetComponents(itemComponent.Owner).FirstOrDefault(); if (suicide != null) { @@ -107,9 +106,9 @@ namespace Content.Server.Chat.Commands { foreach (var entity in entities) { - if (IoCManager.Resolve().HasComponent(entity)) + if (_entities.HasComponent(entity)) continue; - var suicide = IoCManager.Resolve().GetComponents(entity).FirstOrDefault(); + var suicide = _entities.GetComponents(entity).FirstOrDefault(); if (suicide != null) { DealDamage(suicide, chat, owner); diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index 673ea6bbfc..02cb35f2f4 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -114,7 +114,7 @@ namespace Content.Server.Chat.Managers _netManager.ServerSendMessage(msg, player.ConnectedClient); } - public void EntitySay(IEntity source, string message, bool hideChat=false) + public void EntitySay(EntityUid source, string message, bool hideChat=false) { if (!EntitySystem.Get().CanSpeak(source)) { @@ -122,7 +122,7 @@ namespace Content.Server.Chat.Managers } // Check if message exceeds the character limit if the sender is a player - if (IoCManager.Resolve().TryGetComponent(source, out ActorComponent? actor) && + if (_entManager.TryGetComponent(source, out ActorComponent? actor) && message.Length > MaxMessageLength) { var feedback = Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)); @@ -142,19 +142,22 @@ namespace Content.Server.Chat.Managers // We'll try to avoid using MapPosition as EntityCoordinates can early-out and potentially be faster for common use cases // Downside is it may potentially convert to MapPosition unnecessarily. - var sourceMapId = IoCManager.Resolve().GetComponent(source).MapID; - var sourceCoords = IoCManager.Resolve().GetComponent(source).Coordinates; + var sourceMapId = _entManager.GetComponent(source).MapID; + var sourceCoords = _entManager.GetComponent(source).Coordinates; var clients = new List(); foreach (var player in _playerManager.Sessions) { - if (player.AttachedEntity == null) continue; - var transform = IoCManager.Resolve().GetComponent(player.AttachedEntity); + if (player.AttachedEntity is not {Valid: true} playerEntity) + continue; + + var transform = _entManager.GetComponent(playerEntity); if (transform.MapID != sourceMapId || - !IoCManager.Resolve().HasComponent(player.AttachedEntity) && - !sourceCoords.InRange(_entManager, transform.Coordinates, VoiceRange)) continue; + !_entManager.HasComponent(playerEntity) && + !sourceCoords.InRange(_entManager, transform.Coordinates, VoiceRange)) + continue; clients.Add(player.ConnectedClient); } @@ -168,9 +171,9 @@ namespace Content.Server.Chat.Managers message = message[0].ToString().ToUpper() + message.Remove(0, 1); - if (IoCManager.Resolve().TryGetComponent(source, out InventoryComponent? inventory) && + if (_entManager.TryGetComponent(source, out InventoryComponent? inventory) && inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.EARS, out ItemComponent? item) && - IoCManager.Resolve().TryGetComponent(item.Owner, out HeadsetComponent? headset)) + _entManager.TryGetComponent(item.Owner, out HeadsetComponent? headset)) { headset.RadioRequested = true; } @@ -194,13 +197,13 @@ namespace Content.Server.Chat.Managers var msg = _netManager.CreateNetMessage(); msg.Channel = ChatChannel.Local; msg.Message = message; - msg.MessageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",("entityName", Name: IoCManager.Resolve().GetComponent(source).EntityName)); + msg.MessageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",("entityName", Name: _entManager.GetComponent(source).EntityName)); msg.SenderEntity = source; msg.HideChat = hideChat; _netManager.ServerSendToMany(msg, clients); } - public void EntityMe(IEntity source, string action) + public void EntityMe(EntityUid source, string action) { if (!EntitySystem.Get().CanEmote(source)) { @@ -208,7 +211,7 @@ namespace Content.Server.Chat.Managers } // Check if entity is a player - if (!IoCManager.Resolve().TryGetComponent(source, out ActorComponent? actor)) + if (!_entManager.TryGetComponent(source, out ActorComponent? actor)) { return; } @@ -223,7 +226,7 @@ namespace Content.Server.Chat.Managers action = FormattedMessage.EscapeText(action); var clients = Filter.Empty() - .AddInRange(IoCManager.Resolve().GetComponent(source).MapPosition, VoiceRange) + .AddInRange(_entManager.GetComponent(source).MapPosition, VoiceRange) .Recipients .Select(p => p.ConnectedClient) .ToList(); @@ -231,7 +234,7 @@ namespace Content.Server.Chat.Managers var msg = _netManager.CreateNetMessage(); msg.Channel = ChatChannel.Emotes; msg.Message = action; - msg.MessageWrap = Loc.GetString("chat-manager-entity-me-wrap-message", ("entityName",Name: IoCManager.Resolve().GetComponent(source).EntityName)); + msg.MessageWrap = Loc.GetString("chat-manager-entity-me-wrap-message", ("entityName",Name: _entManager.GetComponent(source).EntityName)); msg.SenderEntity = source; _netManager.ServerSendToMany(msg, clients); } @@ -296,11 +299,14 @@ namespace Content.Server.Chat.Managers var msg = _netManager.CreateNetMessage(); msg.Channel = ChatChannel.Dead; msg.Message = message; - IEntity? tempQualifier = player.AttachedEntity; + + var playerName = player.AttachedEntity is {Valid: true} playerEntity + ? _entManager.GetComponent(playerEntity).EntityName + : "???"; msg.MessageWrap = Loc.GetString("chat-manager-send-dead-chat-wrap-message", ("deadChannelName", Loc.GetString("chat-manager-dead-channel-name")), - ("playerName", (tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier).EntityName : null) ?? "???")); - msg.SenderEntity = player.AttachedEntityUid.GetValueOrDefault(); + ("playerName", (playerName))); + msg.SenderEntity = player.AttachedEntity.GetValueOrDefault(); _netManager.ServerSendToMany(msg, clients.ToList()); } diff --git a/Content.Server/Chat/Managers/ChatSanitizationManager.cs b/Content.Server/Chat/Managers/ChatSanitizationManager.cs index 65a4cc04ba..af246e8f0f 100644 --- a/Content.Server/Chat/Managers/ChatSanitizationManager.cs +++ b/Content.Server/Chat/Managers/ChatSanitizationManager.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -69,7 +68,7 @@ public class ChatSanitizationManager : IChatSanitizationManager _configurationManager.OnValueChanged(CCVars.ChatSanitizerEnabled, x => doSanitize = x, true); } - public bool TrySanitizeOutSmilies(string input, IEntity speaker, out string sanitized, [NotNullWhen(true)] out string? emote) + public bool TrySanitizeOutSmilies(string input, EntityUid speaker, out string sanitized, [NotNullWhen(true)] out string? emote) { if (!doSanitize) { diff --git a/Content.Server/Chat/Managers/IChatManager.cs b/Content.Server/Chat/Managers/IChatManager.cs index 28c1aec2b9..abf7cd2032 100644 --- a/Content.Server/Chat/Managers/IChatManager.cs +++ b/Content.Server/Chat/Managers/IChatManager.cs @@ -23,8 +23,8 @@ namespace Content.Server.Chat.Managers void DispatchServerMessage(IPlayerSession player, string message); /// If true, message will not be logged to chat boxes but will still produce a speech bubble. - void EntitySay(IEntity source, string message, bool hideChat=false); - void EntityMe(IEntity source, string action); + void EntitySay(EntityUid source, string message, bool hideChat=false); + void EntityMe(EntityUid source, string action); void SendOOC(IPlayerSession player, string message); void SendAdminChat(IPlayerSession player, string message); diff --git a/Content.Server/Chat/Managers/IChatSanitizationManager.cs b/Content.Server/Chat/Managers/IChatSanitizationManager.cs index ebd2a79b03..4538a9d655 100644 --- a/Content.Server/Chat/Managers/IChatSanitizationManager.cs +++ b/Content.Server/Chat/Managers/IChatSanitizationManager.cs @@ -7,5 +7,5 @@ public interface IChatSanitizationManager { public void Initialize(); - public bool TrySanitizeOutSmilies(string input, IEntity speaker, out string sanitized, [NotNullWhen(true)] out string? emote); + public bool TrySanitizeOutSmilies(string input, EntityUid speaker, out string sanitized, [NotNullWhen(true)] out string? emote); } diff --git a/Content.Server/Chemistry/Components/ChemMasterComponent.cs b/Content.Server/Chemistry/Components/ChemMasterComponent.cs index ac13cb21fd..b04d92beb9 100644 --- a/Content.Server/Chemistry/Components/ChemMasterComponent.cs +++ b/Content.Server/Chemistry/Components/ChemMasterComponent.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Chemistry.EntitySystems; using Content.Server.Hands.Components; using Content.Server.Items; -using Content.Server.Sprite; +using Content.Server.Labels.Components; using Content.Server.Power.Components; using Content.Server.UserInterface; using Content.Shared.ActionBlocker; @@ -18,15 +17,12 @@ using Content.Shared.Random.Helpers; using Content.Shared.Sound; using Robust.Server.GameObjects; using Robust.Shared.Audio; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Player; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using Robust.Shared.Log; -using Content.Server.Labels.Components; -using Robust.Shared.IoC; namespace Content.Server.Chemistry.Components { @@ -41,6 +37,8 @@ namespace Content.Server.Chemistry.Components [ComponentReference(typeof(SharedChemMasterComponent))] public class ChemMasterComponent : SharedChemMasterComponent, IActivate { + [Dependency] private readonly IEntityManager _entities = default!; + [ViewVariables] private uint _pillType = 1; @@ -51,7 +49,7 @@ namespace Content.Server.Chemistry.Components private bool _bufferModeTransfer = true; [ViewVariables] - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] private Solution BufferSolution => _bufferSolution ??= EntitySystem.Get().EnsureSolution(Owner, SolutionName); @@ -107,7 +105,7 @@ namespace Content.Server.Chemistry.Components /// A user interface message from the client. private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) { - if (obj.Session.AttachedEntity == null) + if (obj.Session.AttachedEntity is not {Valid: true} player) return; var msg = (UiActionMessage) obj.Message; @@ -117,13 +115,13 @@ namespace Content.Server.Chemistry.Components _ => true, }; - if (!PlayerCanUseChemMaster(obj.Session.AttachedEntity, needsPower)) + if (!PlayerCanUseChemMaster(player, needsPower)) return; switch (msg.Action) { case UiAction.Eject: - EntitySystem.Get().TryEjectToHands(((IComponent) this).Owner, BeakerSlot, obj.Session.AttachedEntityUid); + EntitySystem.Get().TryEjectToHands(((IComponent) this).Owner, BeakerSlot, player); break; case UiAction.ChemButton: TransferReagent(msg.Id, msg.Amount, msg.IsBuffer); @@ -143,7 +141,7 @@ namespace Content.Server.Chemistry.Components case UiAction.CreatePills: case UiAction.CreateBottles: _label = msg.Label; - TryCreatePackage(obj.Session.AttachedEntity, msg.Action, msg.Label, msg.PillAmount, msg.BottleAmount); + TryCreatePackage(player, msg.Action, msg.Label, msg.PillAmount, msg.BottleAmount); break; default: throw new ArgumentOutOfRangeException(); @@ -158,10 +156,10 @@ namespace Content.Server.Chemistry.Components /// The player entity. /// whether the device requires power /// Returns true if the entity can use the chem master, and false if it cannot. - private bool PlayerCanUseChemMaster(IEntity? playerEntity, bool needsPower = true) + private bool PlayerCanUseChemMaster(EntityUid playerEntity, bool needsPower = true) { //Need player entity to check if they are still able to use the chem master - if (playerEntity == null) + if (playerEntity == default) return false; var actionBlocker = EntitySystem.Get(); @@ -182,18 +180,18 @@ namespace Content.Server.Chemistry.Components /// Returns a private ChemMasterBoundUserInterfaceState GetUserInterfaceState() { - var beaker = BeakerSlot.Item; - if (beaker is null || !IoCManager.Resolve().TryGetComponent(beaker, out FitsInDispenserComponent? fits) || + if (BeakerSlot.Item is not {Valid: true} beaker || + !_entities.TryGetComponent(beaker, out FitsInDispenserComponent? fits) || !EntitySystem.Get().TryGetSolution(beaker, fits.Solution, out var beakerSolution)) { return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0), - "", _label, IoCManager.Resolve().GetComponent(Owner).EntityName, new List(), BufferSolution.Contents, _bufferModeTransfer, + "", _label, _entities.GetComponent(Owner).EntityName, new List(), BufferSolution.Contents, _bufferModeTransfer, BufferSolution.TotalVolume, _pillType); } return new ChemMasterBoundUserInterfaceState(Powered, true, beakerSolution.CurrentVolume, beakerSolution.MaxVolume, - IoCManager.Resolve().GetComponent(beaker).EntityName, _label, IoCManager.Resolve().GetComponent(Owner).EntityName, beakerSolution.Contents, BufferSolution.Contents, _bufferModeTransfer, + _entities.GetComponent(beaker).EntityName, _label, _entities.GetComponent(Owner).EntityName, beakerSolution.Contents, BufferSolution.Contents, _bufferModeTransfer, BufferSolution.TotalVolume, _pillType); } @@ -205,10 +203,11 @@ namespace Content.Server.Chemistry.Components private void TransferReagent(string id, FixedPoint2 amount, bool isBuffer) { - if (!BeakerSlot.HasItem && _bufferModeTransfer) return; - var beaker = BeakerSlot.Item; + if (!BeakerSlot.HasItem && _bufferModeTransfer) + return; - if (beaker is null || !IoCManager.Resolve().TryGetComponent(beaker, out FitsInDispenserComponent? fits) || + if (BeakerSlot.Item is not {Valid: true} beaker || + !_entities.TryGetComponent(beaker, out FitsInDispenserComponent? fits) || !EntitySystem.Get().TryGetSolution(beaker, fits.Solution, out var beakerSolution)) return; @@ -282,7 +281,7 @@ namespace Content.Server.Chemistry.Components return _bufferSolution.Contents[_bufferSolution.Contents.Count - 1].ReagentId; } - private void TryCreatePackage(IEntity user, UiAction action, string label, int pillAmount, int bottleAmount) + private void TryCreatePackage(EntityUid user, UiAction action, string label, int pillAmount, int bottleAmount) { if (BufferSolution.TotalVolume == 0) { @@ -302,13 +301,13 @@ namespace Content.Server.Chemistry.Components var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(30)); for (int i = 0; i < bottleAmount; i++) { - var bottle = IoCManager.Resolve().SpawnEntity("ChemistryEmptyBottle01", IoCManager.Resolve().GetComponent(Owner).Coordinates); + var bottle = _entities.SpawnEntity("ChemistryEmptyBottle01", _entities.GetComponent(Owner).Coordinates); //Adding label LabelComponent labelComponent = bottle.EnsureComponent(); - labelComponent.OriginalName = IoCManager.Resolve().GetComponent(bottle).EntityName; - string val = IoCManager.Resolve().GetComponent(bottle).EntityName + $" ({label})"; - IoCManager.Resolve().GetComponent(bottle).EntityName = val; + labelComponent.OriginalName = _entities.GetComponent(bottle).EntityName; + string val = _entities.GetComponent(bottle).EntityName + $" ({label})"; + _entities.GetComponent(bottle).EntityName = val; labelComponent.CurrentLabel = label; var bufferSolution = BufferSolution.SplitSolution(actualVolume); @@ -317,8 +316,8 @@ namespace Content.Server.Chemistry.Components EntitySystem.Get().TryAddSolution(bottle, bottleSolution, bufferSolution); //Try to give them the bottle - if (IoCManager.Resolve().TryGetComponent(user, out var hands) && - IoCManager.Resolve().TryGetComponent(bottle, out var item)) + if (_entities.TryGetComponent(user, out var hands) && + _entities.TryGetComponent(bottle, out var item)) { if (hands.CanPutInHand(item)) { @@ -328,7 +327,7 @@ namespace Content.Server.Chemistry.Components } //Put it on the floor - IoCManager.Resolve().GetComponent(bottle).Coordinates = IoCManager.Resolve().GetComponent(user).Coordinates; + _entities.GetComponent(bottle).Coordinates = _entities.GetComponent(user).Coordinates; //Give it an offset bottle.RandomOffset(0.2f); } @@ -345,13 +344,13 @@ namespace Content.Server.Chemistry.Components var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(50)); for (int i = 0; i < pillAmount; i++) { - var pill = IoCManager.Resolve().SpawnEntity("pill", IoCManager.Resolve().GetComponent(Owner).Coordinates); + var pill = _entities.SpawnEntity("pill", _entities.GetComponent(Owner).Coordinates); //Adding label LabelComponent labelComponent = pill.EnsureComponent(); - labelComponent.OriginalName = IoCManager.Resolve().GetComponent(pill).EntityName; - string val = IoCManager.Resolve().GetComponent(pill).EntityName + $" ({label})"; - IoCManager.Resolve().GetComponent(pill).EntityName = val; + labelComponent.OriginalName = _entities.GetComponent(pill).EntityName; + string val = _entities.GetComponent(pill).EntityName + $" ({label})"; + _entities.GetComponent(pill).EntityName = val; labelComponent.CurrentLabel = label; var bufferSolution = BufferSolution.SplitSolution(actualVolume); @@ -359,15 +358,15 @@ namespace Content.Server.Chemistry.Components EntitySystem.Get().TryAddSolution(pill, pillSolution, bufferSolution); //Change pill Sprite component state - if (!IoCManager.Resolve().TryGetComponent(pill, out SpriteComponent? sprite)) + if (!_entities.TryGetComponent(pill, out SpriteComponent? sprite)) { return; } sprite?.LayerSetState(0, "pill" + _pillType); //Try to give them the bottle - if (IoCManager.Resolve().TryGetComponent(user, out var hands) && - IoCManager.Resolve().TryGetComponent(pill, out var item)) + if (_entities.TryGetComponent(user, out var hands) && + _entities.TryGetComponent(pill, out var item)) { if (hands.CanPutInHand(item)) { @@ -377,7 +376,7 @@ namespace Content.Server.Chemistry.Components } //Put it on the floor - IoCManager.Resolve().GetComponent(pill).Coordinates = IoCManager.Resolve().GetComponent(user).Coordinates; + _entities.GetComponent(pill).Coordinates = _entities.GetComponent(user).Coordinates; //Give it an offset pill.RandomOffset(0.2f); } @@ -395,12 +394,12 @@ namespace Content.Server.Chemistry.Components /// Data relevant to the event such as the actor which triggered it. void IActivate.Activate(ActivateEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!_entities.TryGetComponent(args.User, out ActorComponent? actor)) { return; } - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!_entities.TryGetComponent(args.User, out HandsComponent? hands)) { Owner.PopupMessage(args.User, Loc.GetString("chem-master-component-activate-no-hands")); return; diff --git a/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs index a1bfed42a9..e4a45d7c32 100644 --- a/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs @@ -30,7 +30,7 @@ namespace Content.Server.Chemistry.Components } } - protected override void ReactWithEntity(IEntity entity, double solutionFraction) + protected override void ReactWithEntity(EntityUid entity, double solutionFraction) { if (!EntitySystem.Get().TryGetSolution(Owner, SolutionName, out var solution)) return; @@ -82,7 +82,7 @@ namespace Content.Server.Chemistry.Components IoCManager.Resolve().SpawnEntity(_foamedMetalPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); } - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); }); } } diff --git a/Content.Server/Chemistry/Components/HyposprayComponent.cs b/Content.Server/Chemistry/Components/HyposprayComponent.cs index 937d22178c..48ca60ff6f 100644 --- a/Content.Server/Chemistry/Components/HyposprayComponent.cs +++ b/Content.Server/Chemistry/Components/HyposprayComponent.cs @@ -14,7 +14,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -41,9 +40,9 @@ namespace Content.Server.Chemistry.Components Dirty(); } - public bool TryDoInject(IEntity? target, IEntity user) + public bool TryDoInject(EntityUid? target, EntityUid user) { - if (target == null || !EligibleEntity(target)) + if (target == default || !EligibleEntity(target.Value)) return false; string? msgFormat = null; @@ -67,7 +66,7 @@ namespace Content.Server.Chemistry.Components return true; } - if (!solutionsSys.TryGetInjectableSolution(target, out var targetSolution)) + if (!solutionsSys.TryGetInjectableSolution(target.Value, out var targetSolution)) { user.PopupMessage(user, Loc.GetString("hypospray-cant-inject", ("target", target))); @@ -78,9 +77,9 @@ namespace Content.Server.Chemistry.Components ("other", target))); if (target != user) { - target.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message")); + target.Value.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message")); var meleeSys = EntitySystem.Get(); - var angle = Angle.FromWorldVec(IoCManager.Resolve().GetComponent(target).WorldPosition - IoCManager.Resolve().GetComponent(user).WorldPosition); + var angle = Angle.FromWorldVec(IoCManager.Resolve().GetComponent(target.Value).WorldPosition - IoCManager.Resolve().GetComponent(user).WorldPosition); meleeSys.SendLunge(angle, user); } @@ -107,11 +106,11 @@ namespace Content.Server.Chemistry.Components return true; } - removedSolution.DoEntityReaction(target, ReactionMethod.Injection); + removedSolution.DoEntityReaction(target.Value, ReactionMethod.Injection); - EntitySystem.Get().TryAddSolution(target, targetSolution, removedSolution); + EntitySystem.Get().TryAddSolution(target.Value, targetSolution, removedSolution); - static bool EligibleEntity(IEntity entity) + static bool EligibleEntity(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/Chemistry/Components/InjectorComponent.cs b/Content.Server/Chemistry/Components/InjectorComponent.cs index 3f9928ed8b..3778ad7730 100644 --- a/Content.Server/Chemistry/Components/InjectorComponent.cs +++ b/Content.Server/Chemistry/Components/InjectorComponent.cs @@ -4,7 +4,6 @@ using Content.Server.Body.Components; using Content.Server.Body.Systems; using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Chemistry.EntitySystems; -using Content.Shared.Body.Components; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; @@ -14,7 +13,6 @@ using Content.Shared.Popups; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -28,6 +26,8 @@ namespace Content.Server.Chemistry.Components [RegisterComponent] public class InjectorComponent : SharedInjectorComponent, IAfterInteract, IUse { + [Dependency] private readonly IEntityManager _entities = default!; + public const string SolutionName = "injector"; /// @@ -81,7 +81,7 @@ namespace Content.Server.Chemistry.Components /// /// Toggle between draw/inject state if applicable /// - private void Toggle(IEntity user) + private void Toggle(EntityUid user) { if (_injectOnly) { @@ -117,26 +117,24 @@ namespace Content.Server.Chemistry.Components var solutionsSys = EntitySystem.Get(); //Make sure we have the attacking entity - if (eventArgs.Target == null || !IoCManager.Resolve().HasComponent(Owner)) + if (eventArgs.Target is not {Valid: true} target || + !_entities.HasComponent(Owner)) { return false; } - var targetEntity = eventArgs.Target; - - // Handle injecting/drawing for solutions if (ToggleState == InjectorToggleMode.Inject) { - if (solutionsSys.TryGetInjectableSolution(targetEntity, out var injectableSolution)) + if (solutionsSys.TryGetInjectableSolution(target, out var injectableSolution)) { - TryInject(targetEntity, injectableSolution, eventArgs.User, false); + TryInject(target, injectableSolution, eventArgs.User, false); } - else if (solutionsSys.TryGetRefillableSolution(targetEntity, out var refillableSolution)) + else if (solutionsSys.TryGetRefillableSolution(target, out var refillableSolution)) { - TryInject(targetEntity, refillableSolution, eventArgs.User, true); + TryInject(target, refillableSolution, eventArgs.User, true); } - else if (IoCManager.Resolve().TryGetComponent(targetEntity, out BloodstreamComponent? bloodstream)) + else if (_entities.TryGetComponent(target, out BloodstreamComponent? bloodstream)) { TryInjectIntoBloodstream(bloodstream, eventArgs.User); } @@ -144,20 +142,20 @@ namespace Content.Server.Chemistry.Components { eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("injector-component-cannot-transfer-message", - ("target", targetEntity))); + ("target", target))); } } else if (ToggleState == InjectorToggleMode.Draw) { - if (solutionsSys.TryGetDrawableSolution(targetEntity, out var drawableSolution)) + if (solutionsSys.TryGetDrawableSolution(target, out var drawableSolution)) { - TryDraw(targetEntity, drawableSolution, eventArgs.User); + TryDraw(target, drawableSolution, eventArgs.User); } else { eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("injector-component-cannot-draw-message", - ("target", targetEntity))); + ("target", target))); } } @@ -175,7 +173,7 @@ namespace Content.Server.Chemistry.Components return true; } - private void TryInjectIntoBloodstream(BloodstreamComponent targetBloodstream, IEntity user) + private void TryInjectIntoBloodstream(BloodstreamComponent targetBloodstream, EntityUid user) { // Get transfer amount. May be smaller than _transferAmount if not enough room var realTransferAmount = FixedPoint2.Min(_transferAmount, targetBloodstream.Solution.AvailableVolume); @@ -204,7 +202,7 @@ namespace Content.Server.Chemistry.Components AfterInject(); } - private void TryInject(IEntity targetEntity, Solution targetSolution, IEntity user, bool asRefill) + private void TryInject(EntityUid targetEntity, Solution targetSolution, EntityUid user, bool asRefill) { if (!EntitySystem.Get().TryGetSolution(Owner, SolutionName, out var solution) || solution.CurrentVolume == 0) @@ -266,7 +264,7 @@ namespace Content.Server.Chemistry.Components } } - private void TryDraw(IEntity targetEntity, Solution targetSolution, IEntity user) + private void TryDraw(EntityUid targetEntity, Solution targetSolution, EntityUid user) { if (!EntitySystem.Get().TryGetSolution(Owner, SolutionName, out var solution) || solution.AvailableVolume == 0) @@ -304,7 +302,7 @@ namespace Content.Server.Chemistry.Components public override ComponentState GetComponentState() { - IoCManager.Resolve().EntitySysManager.GetEntitySystem() + _entities.EntitySysManager.GetEntitySystem() .TryGetSolution(Owner, SolutionName, out var solution); var currentVolume = solution?.CurrentVolume ?? FixedPoint2.Zero; diff --git a/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs b/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs index 520ce6173e..d6f7dacece 100644 --- a/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs +++ b/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs @@ -43,6 +43,7 @@ namespace Content.Server.Chemistry.Components public static string SolutionName = "reagent"; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; [ViewVariables] [DataField("pack")] private string _packPrototypeId = ""; @@ -63,7 +64,7 @@ namespace Content.Server.Chemistry.Components } [ViewVariables] - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ReagentDispenserUiKey.Key); @@ -142,13 +143,13 @@ namespace Content.Server.Chemistry.Components _ => true, }; - if (!PlayerCanUseDispenser(obj.Session.AttachedEntity, needsPower)) + if (!PlayerCanUseDispenser(obj.Session.AttachedEntity.Value, needsPower)) return; switch (msg.Button) { case UiButton.Eject: - EntitySystem.Get().TryEjectToHands(((IComponent) this).Owner, BeakerSlot, obj.Session.AttachedEntityUid); + EntitySystem.Get().TryEjectToHands(((IComponent) this).Owner, BeakerSlot, obj.Session.AttachedEntity); break; case UiButton.Clear: TryClear(); @@ -200,7 +201,7 @@ namespace Content.Server.Chemistry.Components /// /// The player entity. /// Returns true if the entity can use the dispenser, and false if it cannot. - private bool PlayerCanUseDispenser(IEntity? playerEntity, bool needsPower = true) + private bool PlayerCanUseDispenser(EntityUid? playerEntity, bool needsPower = true) { //Need player entity to check if they are still able to use the dispenser if (playerEntity == null) @@ -209,7 +210,7 @@ namespace Content.Server.Chemistry.Components var actionBlocker = EntitySystem.Get(); //Check if player can interact in their current state - if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity)) + if (!actionBlocker.CanInteract(playerEntity.Value) || !actionBlocker.CanUse(playerEntity.Value)) return false; //Check if device is powered if (needsPower && !Powered) @@ -224,18 +225,18 @@ namespace Content.Server.Chemistry.Components /// Returns a private ReagentDispenserBoundUserInterfaceState GetUserInterfaceState() { - var beaker = BeakerSlot.Item; - if (beaker == null || !IoCManager.Resolve().TryGetComponent(beaker, out FitsInDispenserComponent? fits) || + if (BeakerSlot.Item is not {Valid: true} beaker || + !_entities.TryGetComponent(beaker, out FitsInDispenserComponent? fits) || !EntitySystem.Get().TryGetSolution(beaker, fits.Solution, out var solution)) { return new ReagentDispenserBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0), - string.Empty, Inventory, IoCManager.Resolve().GetComponent(Owner).EntityName, null, _dispenseAmount); + string.Empty, Inventory, _entities.GetComponent(Owner).EntityName, null, _dispenseAmount); } return new ReagentDispenserBoundUserInterfaceState(Powered, true, solution.CurrentVolume, solution.MaxVolume, - IoCManager.Resolve().GetComponent(beaker).EntityName, Inventory, IoCManager.Resolve().GetComponent(Owner).EntityName, solution.Contents.ToList(), _dispenseAmount); + _entities.GetComponent(beaker).EntityName, Inventory, _entities.GetComponent(Owner).EntityName, solution.Contents.ToList(), _dispenseAmount); } public void UpdateUserInterface() @@ -249,11 +250,9 @@ namespace Content.Server.Chemistry.Components /// private void TryClear() { - var beaker = BeakerSlot.Item; - - if (beaker == null || !IoCManager.Resolve().TryGetComponent(beaker, out FitsInDispenserComponent? fits) || - !EntitySystem.Get() - .TryGetSolution(beaker, fits.Solution, out var solution)) + if (BeakerSlot.Item is not {Valid: true} beaker || + !_entities.TryGetComponent(beaker, out FitsInDispenserComponent? fits) || + !EntitySystem.Get().TryGetSolution(beaker, fits.Solution, out var solution)) return; EntitySystem.Get().RemoveAllSolution(beaker, solution); @@ -267,11 +266,9 @@ namespace Content.Server.Chemistry.Components /// The index of the reagent in Inventory. private void TryDispense(int dispenseIndex) { - var beaker = BeakerSlot.Item; - - if (beaker is null || !IoCManager.Resolve().TryGetComponent(beaker, out FitsInDispenserComponent? fits) - || !EntitySystem.Get() - .TryGetSolution(beaker, fits.Solution, out var solution)) return; + if (BeakerSlot.Item is not {Valid: true} beaker || + !_entities.TryGetComponent(beaker, out FitsInDispenserComponent? fits) || + !EntitySystem.Get().TryGetSolution(beaker, fits.Solution, out var solution)) return; EntitySystem.Get() .TryAddReagent(beaker, solution, Inventory[dispenseIndex].ID, _dispenseAmount, out _); @@ -285,12 +282,12 @@ namespace Content.Server.Chemistry.Components /// Data relevant to the event such as the actor which triggered it. void IActivate.Activate(ActivateEventArgs args) { - if (!IoCManager.Resolve().TryGetComponent(args.User, out ActorComponent? actor)) + if (!_entities.TryGetComponent(args.User, out ActorComponent? actor)) { return; } - if (!IoCManager.Resolve().TryGetComponent(args.User, out HandsComponent? hands)) + if (!_entities.TryGetComponent(args.User, out HandsComponent? hands)) { Owner.PopupMessage(args.User, Loc.GetString("reagent-dispenser-component-activate-no-hands")); return; diff --git a/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs index d4f3beff8c..a2f4787819 100644 --- a/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs @@ -26,7 +26,7 @@ namespace Content.Server.Chemistry.Components } } - protected override void ReactWithEntity(IEntity entity, double solutionFraction) + protected override void ReactWithEntity(EntityUid entity, double solutionFraction) { if (!EntitySystem.Get().TryGetSolution(Owner, SolutionName, out var solution)) return; @@ -58,7 +58,7 @@ namespace Content.Server.Chemistry.Components { if ((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted) return; - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); } } } diff --git a/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs index bbbf366024..e7c7f7c66a 100644 --- a/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs @@ -26,6 +26,8 @@ namespace Content.Server.Chemistry.Components [Dependency] protected readonly IMapManager MapManager = default!; [Dependency] protected readonly IPrototypeManager PrototypeManager = default!; + [Dependency] private readonly IEntityManager _entities = default!; + public int Amount { get; set; } public SolutionAreaEffectInceptionComponent? Inception { get; set; } @@ -46,11 +48,11 @@ namespace Content.Server.Chemistry.Components if (Inception != null) return; - if (IoCManager.Resolve().HasComponent(Owner)) + if (_entities.HasComponent(Owner)) return; Amount = amount; - var inception = IoCManager.Resolve().AddComponent(Owner); + var inception = _entities.AddComponent(Owner); inception.Add(this); inception.Setup(amount, duration, spreadDelay, removeDelay); @@ -62,7 +64,7 @@ namespace Content.Server.Chemistry.Components /// public void Spread() { - if (IoCManager.Resolve().GetComponent(Owner).EntityPrototype == null) + if (_entities.GetComponent(Owner).EntityPrototype == null) { Logger.Error("AreaEffectComponent needs its owner to be spawned by a prototype."); return; @@ -70,24 +72,26 @@ namespace Content.Server.Chemistry.Components void SpreadToDir(Direction dir) { - var grid = MapManager.GetGrid(IoCManager.Resolve().GetComponent(Owner).GridID); - var coords = IoCManager.Resolve().GetComponent(Owner).Coordinates; + var grid = MapManager.GetGrid(_entities.GetComponent(Owner).GridID); + var coords = _entities.GetComponent(Owner).Coordinates; foreach (var neighbor in grid.GetInDir(coords, dir)) { - if (IoCManager.Resolve().TryGetComponent(neighbor, + if (_entities.TryGetComponent(neighbor, out SolutionAreaEffectComponent? comp) && comp.Inception == Inception) return; - if (IoCManager.Resolve().TryGetComponent(neighbor, + if (_entities.TryGetComponent(neighbor, out AirtightComponent? airtight) && airtight.AirBlocked) return; } - var newEffect = IoCManager.Resolve().SpawnEntity(IoCManager.Resolve().GetComponent(Owner).EntityPrototype.ID, grid.DirectionToGrid(coords, dir)); + var newEffect = _entities.SpawnEntity( + _entities.GetComponent(Owner).EntityPrototype?.ID, + grid.DirectionToGrid(coords, dir)); - if (!IoCManager.Resolve().TryGetComponent(newEffect, out SolutionAreaEffectComponent? effectComponent)) + if (!_entities.TryGetComponent(newEffect, out SolutionAreaEffectComponent? effectComponent)) { - IoCManager.Resolve().DeleteEntity((EntityUid) newEffect); + _entities.DeleteEntity(newEffect); return; } @@ -132,8 +136,8 @@ namespace Content.Server.Chemistry.Components return; var chemistry = EntitySystem.Get(); - var mapGrid = MapManager.GetGrid(IoCManager.Resolve().GetComponent(Owner).GridID); - var tile = mapGrid.GetTileRef(IoCManager.Resolve().GetComponent(Owner).Coordinates.ToVector2i(IoCManager.Resolve(), MapManager)); + var mapGrid = MapManager.GetGrid(_entities.GetComponent(Owner).GridID); + var tile = mapGrid.GetTileRef(_entities.GetComponent(Owner).Coordinates.ToVector2i(_entities, MapManager)); var solutionFraction = 1 / Math.Floor(averageExposures); @@ -164,7 +168,7 @@ namespace Content.Server.Chemistry.Components } } - protected abstract void ReactWithEntity(IEntity entity, double solutionFraction); + protected abstract void ReactWithEntity(EntityUid entity, double solutionFraction); public void TryAddSolution(Solution solution) { diff --git a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs index b581addab6..efc13a5978 100644 --- a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs @@ -5,7 +5,6 @@ using Content.Server.Chemistry.EntitySystems; using Content.Server.UserInterface; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; @@ -25,6 +24,8 @@ namespace Content.Server.Chemistry.Components [RegisterComponent] public sealed class SolutionTransferComponent : Component, IAfterInteract { + [Dependency] private readonly IEntityManager _entities = default!; + // Behavior is as such: // If it's a reagent tank, TAKE reagent. // If it's anything else, GIVE reagent. @@ -116,21 +117,21 @@ namespace Content.Server.Chemistry.Components if (!eventArgs.InRangeUnobstructed() || eventArgs.Target == null) return false; - if (!IoCManager.Resolve().HasComponent(Owner)) + if (!_entities.HasComponent(Owner)) return false; - var target = eventArgs.Target!; - if (!IoCManager.Resolve().HasComponent(target)) + var target = eventArgs.Target!.Value; + if (!_entities.HasComponent(target)) { return false; } - if (CanReceive && IoCManager.Resolve().TryGetComponent(target, out ReagentTankComponent? tank) + if (CanReceive && _entities.TryGetComponent(target, out ReagentTankComponent? tank) && solutionsSys.TryGetRefillableSolution(Owner, out var ownerRefill) - && solutionsSys.TryGetDrainableSolution(eventArgs.Target, out var targetDrain)) + && solutionsSys.TryGetDrainableSolution(target, out var targetDrain)) { - var transferred = DoTransfer(eventArgs.User, eventArgs.Target, targetDrain, Owner, ownerRefill, tank.TransferAmount); + var transferred = DoTransfer(eventArgs.User, target, targetDrain, Owner, ownerRefill, tank.TransferAmount); if (transferred > 0) { var toTheBrim = ownerRefill.AvailableVolume == 0; @@ -144,7 +145,7 @@ namespace Content.Server.Chemistry.Components } } - if (CanSend && solutionsSys.TryGetRefillableSolution(eventArgs.Target, out var targetRefill) + if (CanSend && solutionsSys.TryGetRefillableSolution(target, out var targetRefill) && solutionsSys.TryGetDrainableSolution(Owner, out var ownerDrain)) { var transferred = DoTransfer(eventArgs.User, Owner, ownerDrain, target, targetRefill, TransferAmount); @@ -164,10 +165,10 @@ namespace Content.Server.Chemistry.Components } /// The actual amount transferred. - private static FixedPoint2 DoTransfer(IEntity user, - IEntity sourceEntity, + private static FixedPoint2 DoTransfer(EntityUid user, + EntityUid sourceEntity, Solution source, - IEntity targetEntity, + EntityUid targetEntity, Solution target, FixedPoint2 amount) { diff --git a/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs index 65f73c3ecb..5a8745f5ab 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs @@ -1,4 +1,3 @@ -using Content.Shared.Administration.Logs; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; @@ -6,22 +5,22 @@ using Content.Shared.Database; using Content.Shared.FixedPoint; using Robust.Shared.Audio; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Player; namespace Content.Server.Chemistry.EntitySystems { public class ChemicalReactionSystem : SharedChemicalReactionSystem { - protected override void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid ownerUid, FixedPoint2 unitReactions) + protected override void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid Owner, FixedPoint2 unitReactions) { - base.OnReaction(solution, reaction, randomReagent, ownerUid, unitReactions); + base.OnReaction(solution, reaction, randomReagent, Owner, unitReactions); + + var coordinates = EntityManager.GetComponent(Owner); - var entity = EntityManager.GetEntity(ownerUid); _logSystem.Add(LogType.ChemicalReaction, reaction.Impact, - $"Chemical reaction {reaction.ID} occurred with strength {unitReactions:strength} on entity {entity} at {IoCManager.Resolve().GetComponent(entity).Coordinates}"); + $"Chemical reaction {reaction.ID} occurred with strength {unitReactions:strength} on entity {Owner} at {coordinates}"); - SoundSystem.Play(Filter.Pvs(ownerUid, entityManager:EntityManager), reaction.Sound.GetSound(), ownerUid); + SoundSystem.Play(Filter.Pvs(Owner, entityManager:EntityManager), reaction.Sound.GetSound(), Owner); } } } diff --git a/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs b/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs index 41c84661c2..09b354fbfc 100644 --- a/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs @@ -1,6 +1,5 @@ using Content.Server.Chemistry.Components; using Content.Server.Popups; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -29,7 +28,7 @@ namespace Content.Server.Chemistry.EntitySystems } // Try not to make this public if you can help it. - private void Expand(RehydratableComponent component, IEntity owner) + private void Expand(RehydratableComponent component, EntityUid owner) { if (component.Expanding) { diff --git a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs index 2f52634590..26fbabdfe9 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs @@ -13,9 +13,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; -using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; using Robust.Shared.Utility; namespace Content.Server.Chemistry.EntitySystems @@ -290,10 +288,10 @@ namespace Content.Server.Chemistry.EntitySystems UpdateChemicals(uid, solution); } - public FixedPoint2 GetReagentQuantity(EntityUid ownerUid, string reagentId) + public FixedPoint2 GetReagentQuantity(EntityUid Owner, string reagentId) { var reagentQuantity = FixedPoint2.New(0); - if (EntityManager.TryGetEntity(ownerUid, out var owner) + if (EntityManager.EntityExists(Owner) && IoCManager.Resolve().TryGetComponent(owner, out SolutionContainerManagerComponent? managerComponent)) { foreach (var solution in managerComponent.Solutions.Values) diff --git a/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs b/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs index edfb898034..9fd7d8c331 100644 --- a/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/TransformableContainerSystem.cs @@ -50,7 +50,7 @@ namespace Content.Server.Chemistry.EntitySystems var spriteSpec = new SpriteSpecifier.Rsi( new ResourcePath("Objects/Consumable/Drinks/" + proto.SpriteReplacementPath), "icon"); - var ownerEntity = EntityManager.GetEntity(uid); + var Owner if (IoCManager.Resolve().TryGetComponent(ownerEntity, out SpriteComponent? sprite)) { sprite?.LayerSetSprite(0, spriteSpec); diff --git a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs index 7451bdf82c..24691b8ccd 100644 --- a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs @@ -123,7 +123,7 @@ namespace Content.Server.Chemistry.EntitySystems if (contents.CurrentVolume == 0 || vapor.Timer > vapor.AliveTime) { // Delete this - IoCManager.Resolve().QueueDeleteEntity((EntityUid) entity); + IoCManager.Resolve().QueueDeleteEntity(entity); } } } diff --git a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs index 949f39fcc8..a7dac3c58b 100644 --- a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs @@ -2,10 +2,7 @@ using Content.Server.Chemistry.Components; using Content.Server.Chemistry.EntitySystems; using Content.Server.Coordinates.Helpers; -using Content.Shared.Administration.Logs; using Content.Shared.Audio; -using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; using Content.Shared.Database; using Content.Shared.Sound; @@ -122,7 +119,7 @@ namespace Content.Server.Chemistry.ReactionEffects if (areaEffectComponent == null) { Logger.Error("Couldn't get AreaEffectComponent from " + _prototypeId); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) ent); + IoCManager.Resolve().QueueDeleteEntity(ent); return; } @@ -132,6 +129,6 @@ namespace Content.Server.Chemistry.ReactionEffects SoundSystem.Play(Filter.Pvs(args.SolutionEntity), _sound.GetSound(), args.SolutionEntity, AudioHelpers.WithVariation(0.125f)); } - protected abstract SolutionAreaEffectComponent? GetAreaEffectComponent(IEntity entity); + protected abstract SolutionAreaEffectComponent? GetAreaEffectComponent(EntityUid entity); } } diff --git a/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs index daa9c877bd..df7d4f59c1 100644 --- a/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs @@ -10,7 +10,7 @@ namespace Content.Server.Chemistry.ReactionEffects [DataDefinition] public class FoamAreaReactionEffect : AreaReactionEffect { - protected override SolutionAreaEffectComponent? GetAreaEffectComponent(IEntity entity) + protected override SolutionAreaEffectComponent? GetAreaEffectComponent(EntityUid entity) { return IoCManager.Resolve().GetComponentOrNull(entity); } diff --git a/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs index b39e23bd7e..917f38dbb7 100644 --- a/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs @@ -10,7 +10,7 @@ namespace Content.Server.Chemistry.ReactionEffects [DataDefinition] public class SmokeAreaReactionEffect : AreaReactionEffect { - protected override SolutionAreaEffectComponent? GetAreaEffectComponent(IEntity entity) + protected override SolutionAreaEffectComponent? GetAreaEffectComponent(EntityUid entity) { return IoCManager.Resolve().GetComponentOrNull(entity); } diff --git a/Content.Server/Chemistry/ReagentEffects/DoAction.cs b/Content.Server/Chemistry/ReagentEffects/DoAction.cs index ed2acff393..29a6ee575b 100644 --- a/Content.Server/Chemistry/ReagentEffects/DoAction.cs +++ b/Content.Server/Chemistry/ReagentEffects/DoAction.cs @@ -2,8 +2,6 @@ using Content.Shared.Actions.Components; using Content.Shared.Actions.Prototypes; using Content.Shared.Chemistry.Reagent; -using Content.Shared.Construction.Steps; -using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; @@ -29,7 +27,7 @@ public class DoAction : ReagentEffect if (actions.IsGranted(proto.ActionType)) { var attempt = new ActionAttempt(proto); - attempt.DoInstantAction(args.EntityManager.GetEntity(args.SolutionEntity)); + attempt.DoInstantAction(args.args.SolutionEntity) } } } diff --git a/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs b/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs index 4abe8b2413..b2b0f39426 100644 --- a/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs @@ -1,7 +1,6 @@ using System.Linq; using Content.Server.Cleanable; using Content.Server.Coordinates.Helpers; -using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; @@ -33,7 +32,7 @@ namespace Content.Server.Chemistry.TileReactions break; amount = next; - IoCManager.Resolve().QueueDeleteEntity((EntityUid) entity); + IoCManager.Resolve().QueueDeleteEntity(entity); } } diff --git a/Content.Server/Climbing/Components/ClimbableComponent.cs b/Content.Server/Climbing/Components/ClimbableComponent.cs index 0ec321a182..f5d687ef97 100644 --- a/Content.Server/Climbing/Components/ClimbableComponent.cs +++ b/Content.Server/Climbing/Components/ClimbableComponent.cs @@ -8,7 +8,6 @@ using Content.Shared.Climbing; using Content.Shared.DragDrop; using Content.Shared.Interaction.Helpers; using Content.Shared.Popups; -using Content.Shared.Verbs; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -66,7 +65,7 @@ namespace Content.Server.Climbing.Components /// The object that is being vaulted /// The reason why it cant be dropped /// - private bool CanVault(IEntity user, IEntity target, out string reason) + private bool CanVault(EntityUid user, EntityUid target, out string reason) { if (!EntitySystem.Get().CanInteract(user)) { @@ -106,7 +105,7 @@ namespace Content.Server.Climbing.Components /// The object that is being vaulted onto /// The reason why it cant be dropped /// - private bool CanVault(IEntity user, IEntity dragged, IEntity target, out string reason) + private bool CanVault(EntityUid user, EntityUid dragged, EntityUid target, out string reason) { if (!EntitySystem.Get().CanInteract(user)) { @@ -120,7 +119,7 @@ namespace Content.Server.Climbing.Components return false; } - bool Ignored(IEntity entity) => entity == target || entity == user || entity == dragged; + bool Ignored(EntityUid entity) => entity == target || entity == user || entity == dragged; if (!user.InRangeUnobstructed(target, Range, predicate: Ignored) || !user.InRangeUnobstructed(dragged, Range, predicate: Ignored)) @@ -147,7 +146,7 @@ namespace Content.Server.Climbing.Components return true; } - private async void TryMoveEntity(IEntity user, IEntity entityToMove) + private async void TryMoveEntity(EntityUid user, EntityUid entityToMove) { var doAfterEventArgs = new DoAfterEventArgs(user, _climbDelay, default, entityToMove) { @@ -191,7 +190,7 @@ namespace Content.Server.Climbing.Components } } - public async void TryClimb(IEntity user) + public async void TryClimb(EntityUiduser) { if (!IoCManager.Resolve().TryGetComponent(user, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing) return; diff --git a/Content.Server/Cloning/CloningSystem.cs b/Content.Server/Cloning/CloningSystem.cs index e70c2b4678..f90dd57d17 100644 --- a/Content.Server/Cloning/CloningSystem.cs +++ b/Content.Server/Cloning/CloningSystem.cs @@ -35,7 +35,7 @@ namespace Content.Server.Cloning internal void TransferMindToClone(Mind.Mind mind) { if (!ClonesWaitingForMind.TryGetValue(mind, out var entityUid) || - !EntityManager.TryGetEntity(entityUid, out var entity) || + !EntityManager.EntityExists(entityUid) || !IoCManager.Resolve().TryGetComponent(entity, out MindComponent? mindComp) || mindComp.Mind != null) return; @@ -59,7 +59,7 @@ namespace Content.Server.Cloning private void HandleMindAdded(EntityUid uid, BeingClonedComponent component, MindAddedMessage message) { if (component.Parent == EntityUid.Invalid || - !EntityManager.TryGetEntity(component.Parent, out var parent) || + !EntityManager.EntityExists(component.Parent) || !IoCManager.Resolve().TryGetComponent(parent, out var cloningPodComponent) || component.Owner != cloningPodComponent.BodyContainer?.ContainedEntity) { diff --git a/Content.Server/Cloning/Components/CloningPodComponent.cs b/Content.Server/Cloning/Components/CloningPodComponent.cs index 12abf36cba..dbab695dab 100644 --- a/Content.Server/Cloning/Components/CloningPodComponent.cs +++ b/Content.Server/Cloning/Components/CloningPodComponent.cs @@ -1,6 +1,6 @@ using System; -using Content.Server.EUI; using Content.Server.Climbing; +using Content.Server.EUI; using Content.Server.Mind.Components; using Content.Server.Power.Components; using Content.Server.UserInterface; @@ -107,7 +107,7 @@ namespace Content.Server.Cloning.Components if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var cloneUid)) { - if (IoCManager.Resolve().TryGetEntity(cloneUid, out var clone) && + if (IoCManager.Resolve().EntityExists(cloneUid) && IoCManager.Resolve().TryGetComponent(clone, out var cloneState) && !cloneState.IsDead() && IoCManager.Resolve().TryGetComponent(clone, out MindComponent? cloneMindComp) && diff --git a/Content.Server/Clothing/Components/ClothingComponent.cs b/Content.Server/Clothing/Components/ClothingComponent.cs index bf6fd752d1..762e7a75f0 100644 --- a/Content.Server/Clothing/Components/ClothingComponent.cs +++ b/Content.Server/Clothing/Components/ClothingComponent.cs @@ -9,7 +9,6 @@ using Content.Shared.Sound; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using static Content.Shared.Inventory.EquipmentSlotDefines; @@ -96,7 +95,7 @@ namespace Content.Server.Clothing.Components return false; } - public bool TryEquip(InventoryComponent inv, Slots slot, IEntity user) + public bool TryEquip(InventoryComponent inv, Slots slot, EntityUiduser) { if (!inv.Equip(slot, this, true, out var reason)) { diff --git a/Content.Server/Clothing/Components/MagbootsComponent.cs b/Content.Server/Clothing/Components/MagbootsComponent.cs index c34ac5f84a..8e987943a4 100644 --- a/Content.Server/Clothing/Components/MagbootsComponent.cs +++ b/Content.Server/Clothing/Components/MagbootsComponent.cs @@ -2,7 +2,6 @@ using Content.Server.Alert; using Content.Server.Atmos.Components; using Content.Server.Inventory.Components; using Content.Server.Items; -using Content.Shared.ActionBlocker; using Content.Shared.Actions; using Content.Shared.Actions.Behaviors.Item; using Content.Shared.Actions.Components; @@ -10,14 +9,11 @@ using Content.Shared.Alert; using Content.Shared.Clothing; using Content.Shared.Interaction; using Content.Shared.Inventory; -using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using static Content.Shared.Inventory.EquipmentSlotDefines; @@ -51,7 +47,7 @@ namespace Content.Server.Clothing.Components } } - public void Toggle(IEntity user) + public void Toggle(EntityUiduser) { On = !On; } diff --git a/Content.Server/Commands/CommandUtils.cs b/Content.Server/Commands/CommandUtils.cs index 2b89e0f6d7..296d8fe13d 100644 --- a/Content.Server/Commands/CommandUtils.cs +++ b/Content.Server/Commands/CommandUtils.cs @@ -39,7 +39,7 @@ namespace Content.Server.Commands /// sending a failure to the performer if unable to. /// public static bool TryGetAttachedEntityByUsernameOrId(IConsoleShell shell, - string usernameOrId, IPlayerSession performer, [NotNullWhen(true)] out IEntity? attachedEntity) + string usernameOrId, IPlayerSession performer, [NotNullWhen(true)] out EntityUid? attachedEntity) { attachedEntity = null; if (!TryGetSessionByUsernameOrId(shell, usernameOrId, performer, out var session)) return false; @@ -53,7 +53,7 @@ namespace Content.Server.Commands return true; } - public static string SubstituteEntityDetails(IConsoleShell shell, IEntity ent, string ruleString) + public static string SubstituteEntityDetails(IConsoleShell shell, EntityUid ent, string ruleString) { // gross, is there a better way to do this? ruleString = ruleString.Replace("$ID", ent.ToString()); @@ -69,9 +69,8 @@ namespace Content.Server.Commands if (shell.Player is IPlayerSession player) { - if (player.AttachedEntity != null) + if (player.AttachedEntity is {Valid: true} p) { - var p = player.AttachedEntity; ruleString = ruleString.Replace("$PID", ent.ToString()); ruleString = ruleString.Replace("$PWX", IoCManager.Resolve().GetComponent(p).WorldPosition.X.ToString(CultureInfo.InvariantCulture)); diff --git a/Content.Server/Communications/CommunicationsConsoleComponent.cs b/Content.Server/Communications/CommunicationsConsoleComponent.cs index 888041ba4a..7d8b826bcb 100644 --- a/Content.Server/Communications/CommunicationsConsoleComponent.cs +++ b/Content.Server/Communications/CommunicationsConsoleComponent.cs @@ -7,13 +7,9 @@ using Content.Server.Power.Components; using Content.Server.RoundEnd; using Content.Server.UserInterface; using Content.Shared.Communications; -using Content.Shared.Interaction; using Robust.Server.GameObjects; -using Robust.Server.Player; -using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Player; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; using Timer = Robust.Shared.Timing.Timer; @@ -25,7 +21,9 @@ namespace Content.Server.Communications { [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IChatManager _chatManager = default!; - private bool Powered => !IoCManager.Resolve().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; + [Dependency] private readonly IEntityManager _entities = default!; + + private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered; private RoundEndSystem RoundEndSystem => EntitySystem.Get(); @@ -109,8 +107,7 @@ namespace Content.Server.Communications var message = msg.Message.Length <= 256 ? msg.Message.Trim() : $"{msg.Message.Trim().Substring(0, 256)}..."; var author = "Unknown"; - var mob = obj.Session.AttachedEntity; - if (mob != null && mob.TryGetHeldId(out var id)) + if (obj.Session.AttachedEntity is {Valid: true} mob && mob.TryGetHeldId(out var id)) { author = $"{id.FullName} ({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(id.JobTitle ?? string.Empty)})".Trim(); } diff --git a/Content.Server/Construction/AnchorableSystem.cs b/Content.Server/Construction/AnchorableSystem.cs index 2e82c95e55..358379a621 100644 --- a/Content.Server/Construction/AnchorableSystem.cs +++ b/Content.Server/Construction/AnchorableSystem.cs @@ -30,10 +30,10 @@ namespace Content.Server.Construction return; // If the used entity doesn't have a tool, return early. - if (!EntityManager.TryGetComponent(args.UsedUid, out ToolComponent? usedTool)) + if (!EntityManager.TryGetComponent(args.Used, out ToolComponent? usedTool)) return; - args.Handled = await TryToggleAnchor(uid, args.UserUid, args.UsedUid, anchorable, usingTool:usedTool); + args.Handled = await TryToggleAnchor(uid, args.User, args.Used, anchorable, usingTool:usedTool); } /// diff --git a/Content.Server/Construction/Commands/FixRotationsCommand.cs b/Content.Server/Construction/Commands/FixRotationsCommand.cs index a6f7eccac1..34c6cdcd49 100644 --- a/Content.Server/Construction/Commands/FixRotationsCommand.cs +++ b/Content.Server/Construction/Commands/FixRotationsCommand.cs @@ -1,5 +1,4 @@ using Content.Server.Administration; -using Content.Server.Window; using Content.Server.Power.Components; using Content.Shared.Administration; using Content.Shared.Construction; @@ -24,19 +23,19 @@ namespace Content.Server.Construction.Commands public void Execute(IConsoleShell shell, string argsOther, string[] args) { var player = shell.Player as IPlayerSession; - + var entityManager = IoCManager.Resolve(); GridId gridId; switch (args.Length) { case 0: - if (player?.AttachedEntity == null) + if (player?.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("Only a player can run this command."); return; } - gridId = IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID; + gridId = entityManager.GetComponent(playerEntity).GridID; break; case 1: if (!int.TryParse(args[0], out var id)) @@ -59,17 +58,16 @@ namespace Content.Server.Construction.Commands return; } - var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity)) + if (!entityManager.EntityExists(grid.GridEntityId)) { shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity."); return; } var changed = 0; - foreach (var childUid in IoCManager.Resolve().GetComponent(gridEntity).ChildEntityUids) + foreach (var child in entityManager.GetComponent(grid.GridEntityId).ChildEntities) { - if (!entityManager.TryGetEntity(childUid, out var childEntity)) + if (!entityManager.EntityExists(child)) { continue; } @@ -78,27 +76,27 @@ namespace Content.Server.Construction.Commands // Occluders should only count if the state of it right now is enabled. // This prevents issues with edge firelocks. - if (entityManager.TryGetComponent(childUid, out var occluder)) + if (entityManager.TryGetComponent(child, out var occluder)) { valid |= occluder.Enabled; } // low walls & grilles - valid |= IoCManager.Resolve().HasComponent(childEntity); + valid |= entityManager.HasComponent(child); // cables - valid |= IoCManager.Resolve().HasComponent(childEntity); + valid |= entityManager.HasComponent(child); // anything else that might need this forced - valid |= childEntity.HasTag("ForceFixRotations"); + valid |= child.HasTag("ForceFixRotations"); // override - valid &= !childEntity.HasTag("ForceNoFixRotations"); + valid &= !child.HasTag("ForceNoFixRotations"); if (!valid) { continue; } - if (IoCManager.Resolve().GetComponent(childEntity).LocalRotation != Angle.Zero) + if (entityManager.GetComponent(child).LocalRotation != Angle.Zero) { - IoCManager.Resolve().GetComponent(childEntity).LocalRotation = Angle.Zero; + entityManager.GetComponent(child).LocalRotation = Angle.Zero; changed++; } } diff --git a/Content.Server/Construction/Commands/TileWallsCommand.cs b/Content.Server/Construction/Commands/TileWallsCommand.cs index 81a1d01512..7754398bf1 100644 --- a/Content.Server/Construction/Commands/TileWallsCommand.cs +++ b/Content.Server/Construction/Commands/TileWallsCommand.cs @@ -21,18 +21,19 @@ namespace Content.Server.Construction.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { var player = shell.Player as IPlayerSession; + var entityManager = IoCManager.Resolve(); GridId gridId; switch (args.Length) { case 0: - if (player?.AttachedEntity == null) + if (player?.AttachedEntity is not {Valid: true} playerEntity) { shell.WriteLine("Only a player can run this command."); return; } - gridId = IoCManager.Resolve().GetComponent(player.AttachedEntity).GridID; + gridId = entityManager.GetComponent(playerEntity).GridID; break; case 1: if (!int.TryParse(args[0], out var id)) @@ -55,8 +56,7 @@ namespace Content.Server.Construction.Commands return; } - var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity)) + if (!entityManager.EntityExists(grid.GridEntityId)) { shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity."); return; @@ -65,16 +65,16 @@ namespace Content.Server.Construction.Commands var tileDefinitionManager = IoCManager.Resolve(); var prototypeManager = IoCManager.Resolve(); var underplating = tileDefinitionManager["underplating"]; - var underplatingTile = new Robust.Shared.Map.Tile(underplating.TileId); + var underplatingTile = new Tile(underplating.TileId); var changed = 0; - foreach (var childUid in IoCManager.Resolve().GetComponent(gridEntity).ChildEntityUids) + foreach (var child in entityManager.GetComponent(grid.GridEntityId).ChildEntities) { - if (!entityManager.TryGetEntity(childUid, out var childEntity)) + if (!entityManager.EntityExists(child)) { continue; } - var prototype = IoCManager.Resolve().GetComponent(childEntity).EntityPrototype; + var prototype = IoCManager.Resolve().GetComponent(child).EntityPrototype; while (true) { if (prototype?.Parent == null) @@ -90,12 +90,12 @@ namespace Content.Server.Construction.Commands continue; } - if (!IoCManager.Resolve().GetComponent(childEntity).Anchored) + if (!IoCManager.Resolve().GetComponent(child).Anchored) { continue; } - var tile = grid.GetTileRef(IoCManager.Resolve().GetComponent(childEntity).Coordinates); + var tile = grid.GetTileRef(IoCManager.Resolve().GetComponent(child).Coordinates); var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId]; if (tileDef.Name == "underplating") @@ -103,7 +103,7 @@ namespace Content.Server.Construction.Commands continue; } - grid.SetTile(IoCManager.Resolve().GetComponent(childEntity).Coordinates, underplatingTile); + grid.SetTile(IoCManager.Resolve().GetComponent(child).Coordinates, underplatingTile); changed++; } diff --git a/Content.Server/Construction/Completions/BuildComputer.cs b/Content.Server/Construction/Completions/BuildComputer.cs index 2cf431ee22..8feab86221 100644 --- a/Content.Server/Construction/Completions/BuildComputer.cs +++ b/Content.Server/Construction/Completions/BuildComputer.cs @@ -1,5 +1,4 @@ using System.Linq; -using System.Threading.Tasks; using Content.Server.Construction.Components; using Content.Shared.Construction; using JetBrains.Annotations; @@ -59,7 +58,7 @@ namespace Content.Server.Construction.Completions foreach (var ent in computerContainer.ContainedEntities.ToArray()) { computerContainer.ForceRemove(ent); - IoCManager.Resolve().DeleteEntity((EntityUid) ent); + IoCManager.Resolve().DeleteEntity(ent); } computerContainer.Insert(board); diff --git a/Content.Server/Construction/Completions/DeleteEntitiesInContainer.cs b/Content.Server/Construction/Completions/DeleteEntitiesInContainer.cs index ea88d2d73a..43bcd9a735 100644 --- a/Content.Server/Construction/Completions/DeleteEntitiesInContainer.cs +++ b/Content.Server/Construction/Completions/DeleteEntitiesInContainer.cs @@ -1,5 +1,4 @@ using System.Linq; -using System.Threading.Tasks; using Content.Shared.Construction; using Robust.Shared.Containers; using Robust.Shared.GameObjects; @@ -23,7 +22,7 @@ namespace Content.Server.Construction.Completions foreach (var contained in container.ContainedEntities.ToArray()) { if(container.Remove(contained)) - IoCManager.Resolve().QueueDeleteEntity((EntityUid) contained); + IoCManager.Resolve().QueueDeleteEntity(contained); } } } diff --git a/Content.Server/Construction/Components/MachineComponent.cs b/Content.Server/Construction/Components/MachineComponent.cs index 7854a0ffa5..aaa4216d5e 100644 --- a/Content.Server/Construction/Components/MachineComponent.cs +++ b/Content.Server/Construction/Components/MachineComponent.cs @@ -4,7 +4,6 @@ using Content.Server.Stack; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Components @@ -90,7 +89,7 @@ namespace Content.Server.Construction.Components { var stack = EntitySystem.Get().Spawn(amount, stackType, IoCManager.Resolve().GetComponent(Owner).Coordinates); - if (!partContainer.Insert(IoCManager.Resolve().GetEntity(stack))) + if (!partContainer.Insert(stack)) throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {IoCManager.Resolve().GetComponent(Owner).EntityPrototype?.ID ?? "N/A"}"); } diff --git a/Content.Server/Construction/Components/MachineFrameComponent.cs b/Content.Server/Construction/Components/MachineFrameComponent.cs index ce0474edbc..260cd8a8e9 100644 --- a/Content.Server/Construction/Components/MachineFrameComponent.cs +++ b/Content.Server/Construction/Components/MachineFrameComponent.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Content.Server.Stack; using Content.Shared.Construction; @@ -319,7 +318,7 @@ namespace Content.Server.Construction.Components if (splitStack == null) return false; - if(!_partContainer.Insert(IoCManager.Resolve().GetEntity(splitStack.Value))) + if(!_partContainer.Insert(splitStack.Value)) return false; _materialProgress[type] += needed; diff --git a/Content.Server/Construction/Components/WelderRefinableComponent.cs b/Content.Server/Construction/Components/WelderRefinableComponent.cs index 9f67195476..42dc194bff 100644 --- a/Content.Server/Construction/Components/WelderRefinableComponent.cs +++ b/Content.Server/Construction/Components/WelderRefinableComponent.cs @@ -4,14 +4,11 @@ using Content.Server.Stack; using Content.Server.Tools; using Content.Server.Tools.Components; using Content.Shared.Interaction; -using Content.Shared.Stacks; using Content.Shared.Tools; -using Content.Shared.Tools.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; -using Robust.Shared.ViewVariables; namespace Content.Server.Construction.Components { @@ -61,7 +58,7 @@ namespace Content.Server.Construction.Components // get last owner coordinates and delete it var resultPosition = IoCManager.Resolve().GetComponent(Owner).Coordinates; - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); // spawn each result after refine foreach (var result in _refineResult!) diff --git a/Content.Server/Construction/ConstructionSystem.Graph.cs b/Content.Server/Construction/ConstructionSystem.Graph.cs index 2269e205ba..109a89c445 100644 --- a/Content.Server/Construction/ConstructionSystem.Graph.cs +++ b/Content.Server/Construction/ConstructionSystem.Graph.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; using Content.Server.Construction.Components; using Content.Shared.Construction; using Content.Shared.Construction.Prototypes; using Content.Shared.Construction.Steps; -using Microsoft.EntityFrameworkCore.Metadata.Builders; using Robust.Server.Containers; using Robust.Shared.Containers; using Robust.Shared.GameObjects; @@ -166,8 +164,7 @@ namespace Content.Server.Construction Resolve(uid, ref containerManager, false); // We create the new entity. - IEntity tempQualifier = EntityManager.SpawnEntity(newEntity, transform.Coordinates); - var newUid = (EntityUid) tempQualifier; + var newUid = EntityManager.SpawnEntity(newEntity, transform.Coordinates); // Construction transferring. var newConstruction = EntityManager.EnsureComponent(newUid); diff --git a/Content.Server/Construction/ConstructionSystem.Initial.cs b/Content.Server/Construction/ConstructionSystem.Initial.cs index 0ff0fd6f82..5de9d4f8a5 100644 --- a/Content.Server/Construction/ConstructionSystem.Initial.cs +++ b/Content.Server/Construction/ConstructionSystem.Initial.cs @@ -43,13 +43,13 @@ namespace Content.Server.Construction } // LEGACY CODE. See warning at the top of the file! - private IEnumerable EnumerateNearby(IEntity user) + private IEnumerable EnumerateNearby(EntityUid user) { - if (IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) + if (EntityManager.TryGetComponent(user, out HandsComponent? hands)) { foreach (var itemComponent in hands?.GetAllHeldItems()!) { - if (IoCManager.Resolve().TryGetComponent(itemComponent.Owner, out ServerStorageComponent? storage)) + if (EntityManager.TryGetComponent(itemComponent.Owner, out ServerStorageComponent? storage)) { foreach (var storedEntity in storage.StoredEntities!) { @@ -61,11 +61,11 @@ namespace Content.Server.Construction } } - if (IoCManager.Resolve().TryGetComponent(user!, out InventoryComponent? inventory)) + if (EntityManager.TryGetComponent(user!, out InventoryComponent? inventory)) { foreach (var held in inventory.GetAllHeldItems()) { - if (IoCManager.Resolve().TryGetComponent(held, out ServerStorageComponent? storage)) + if (EntityManager.TryGetComponent(held, out ServerStorageComponent? storage)) { foreach (var storedEntity in storage.StoredEntities!) { @@ -84,7 +84,7 @@ namespace Content.Server.Construction } // LEGACY CODE. See warning at the top of the file! - private async Task Construct(IEntity user, string materialContainer, ConstructionGraphPrototype graph, ConstructionGraphEdge edge, ConstructionGraphNode targetNode) + private async Task Construct(EntityUid user, string materialContainer, ConstructionGraphPrototype graph, ConstructionGraphEdge edge, ConstructionGraphNode targetNode) { // We need a place to hold our construction items! var container = ContainerHelpers.EnsureContainer(user, materialContainer, out var existed); @@ -164,17 +164,17 @@ namespace Content.Server.Construction if (!materialStep.EntityValid(entity, out var stack)) continue; - var splitStack = _stackSystem.Split(entity, materialStep.Amount, user.ToCoordinates(), stack); + var splitStack = _stackSystem.Split(entity, materialStep.Amount, user.ToCoordinates(0, 0), stack); if (splitStack == null) continue; if (string.IsNullOrEmpty(materialStep.Store)) { - if (!container.Insert(EntityManager.GetEntity(splitStack.Value))) + if (!container.Insert(splitStack.Value)) continue; } - else if (!GetContainer(materialStep.Store).Insert(EntityManager.GetEntity(splitStack.Value))) + else if (!GetContainer(materialStep.Store).Insert(splitStack.Value)) continue; handled = true; @@ -235,10 +235,10 @@ namespace Content.Server.Construction return null; } - var newEntity = EntityManager.SpawnEntity(graph.Nodes[edge.Target].Entity, IoCManager.Resolve().GetComponent(user).Coordinates); + var newEntity = EntityManager.SpawnEntity(graph.Nodes[edge.Target].Entity, EntityManager.GetComponent(user).Coordinates); // Yes, this should throw if it's missing the component. - var construction = IoCManager.Resolve().GetComponent(newEntity); + var construction = EntityManager.GetComponent(newEntity); // We attempt to set the pathfinding target. SetPathfindingTarget(newEntity, targetNode.Name, construction); @@ -285,9 +285,11 @@ namespace Content.Server.Construction return; } - if (!_prototypeManager.TryIndex(constructionPrototype.Graph, out ConstructionGraphPrototype? constructionGraph)) + if (!_prototypeManager.TryIndex(constructionPrototype.Graph, + out ConstructionGraphPrototype? constructionGraph)) { - _sawmill.Error($"Invalid construction graph '{constructionPrototype.Graph}' in recipe '{ev.PrototypeName}'!"); + _sawmill.Error( + $"Invalid construction graph '{constructionPrototype.Graph}' in recipe '{ev.PrototypeName}'!"); return; } @@ -295,25 +297,26 @@ namespace Content.Server.Construction var targetNode = constructionGraph.Nodes[constructionPrototype.TargetNode]; var pathFind = constructionGraph.Path(startNode.Name, targetNode.Name); - var user = args.SenderSession.AttachedEntity; + if (args.SenderSession.AttachedEntity is not {Valid: true} user || + !Get().CanInteract(user)) return; - if (user == null || !Get().CanInteract(user)) return; - - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) return; + if (!EntityManager.TryGetComponent(user, out HandsComponent? hands)) return; foreach (var condition in constructionPrototype.Conditions) { - if (!condition.Condition(user, user.ToCoordinates(), Direction.South)) + if (!condition.Condition(user, user.ToCoordinates(0, 0), Direction.South)) return; } - if(pathFind == null) - throw new InvalidDataException($"Can't find path from starting node to target node in construction! Recipe: {ev.PrototypeName}"); + if (pathFind == null) + throw new InvalidDataException( + $"Can't find path from starting node to target node in construction! Recipe: {ev.PrototypeName}"); var edge = startNode.GetEdge(pathFind[0].Name); - if(edge == null) - throw new InvalidDataException($"Can't find edge from starting node to the next node in pathfinding! Recipe: {ev.PrototypeName}"); + if (edge == null) + throw new InvalidDataException( + $"Can't find edge from starting node to the next node in pathfinding! Recipe: {ev.PrototypeName}"); // No support for conditions here! @@ -326,9 +329,8 @@ namespace Content.Server.Construction } } - var item = await Construct(user, "item_construction", constructionGraph, edge, targetNode); - - if(item != null && IoCManager.Resolve().TryGetComponent(item, out ItemComponent? itemComp)) + if (await Construct(user, "item_construction", constructionGraph, edge, targetNode) is {Valid: true} item && + EntityManager.TryGetComponent(item, out ItemComponent? itemComp)) hands.PutInHandOrDrop(itemComp); } @@ -350,9 +352,7 @@ namespace Content.Server.Construction return; } - var user = args.SenderSession.AttachedEntity; - - if (user == null) + if (args.SenderSession.AttachedEntity is not {Valid: true} user) { _sawmill.Error($"Client sent {nameof(TryStartStructureConstructionMessage)} with no attached entity!"); return; @@ -397,9 +397,8 @@ namespace Content.Server.Construction _beingBuilt[args.SenderSession].Remove(ev.Ack); } - if (user == null - || !Get().CanInteract(user) - || !IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands) || hands.GetActiveHand == null + if (!Get().CanInteract(user) + || !EntityManager.TryGetComponent(user, out HandsComponent? hands) || hands.GetActiveHand == null || !user.InRangeUnobstructed(ev.Location, ignoreInsideBlocker:constructionPrototype.CanBuildInImpassable)) { Cleanup(); @@ -415,9 +414,8 @@ namespace Content.Server.Construction throw new InvalidDataException($"Can't find edge from starting node to the next node in pathfinding! Recipe: {ev.PrototypeName}"); var valid = false; - var holding = hands.GetActiveHand?.Owner; - if (holding == null) + if (hands.GetActiveHand?.Owner is not {Valid: true} holding) { Cleanup(); return; @@ -447,9 +445,8 @@ namespace Content.Server.Construction return; } - var structure = await Construct(user, (ev.Ack + constructionPrototype.GetHashCode()).ToString(), constructionGraph, edge, targetNode); - - if (structure == null) + if (await Construct(user, (ev.Ack + constructionPrototype.GetHashCode()).ToString(), constructionGraph, + edge, targetNode) is not {Valid: true} structure) { Cleanup(); return; @@ -457,13 +454,13 @@ namespace Content.Server.Construction // We do this to be able to move the construction to its proper position in case it's anchored... // Oh wow transform anchoring is amazing wow I love it!!!! - var wasAnchored = IoCManager.Resolve().GetComponent(structure).Anchored; - IoCManager.Resolve().GetComponent(structure).Anchored = false; + var wasAnchored = EntityManager.GetComponent(structure).Anchored; + EntityManager.GetComponent(structure).Anchored = false; - IoCManager.Resolve().GetComponent(structure).Coordinates = ev.Location; - IoCManager.Resolve().GetComponent(structure).LocalRotation = constructionPrototype.CanRotate ? ev.Angle : Angle.Zero; + EntityManager.GetComponent(structure).Coordinates = ev.Location; + EntityManager.GetComponent(structure).LocalRotation = constructionPrototype.CanRotate ? ev.Angle : Angle.Zero; - IoCManager.Resolve().GetComponent(structure).Anchored = wasAnchored; + EntityManager.GetComponent(structure).Anchored = wasAnchored; RaiseNetworkEvent(new AckStructureConstructionMessage(ev.Ack)); diff --git a/Content.Server/Construction/ConstructionSystem.Interactions.cs b/Content.Server/Construction/ConstructionSystem.Interactions.cs index b79e3105db..f506471150 100644 --- a/Content.Server/Construction/ConstructionSystem.Interactions.cs +++ b/Content.Server/Construction/ConstructionSystem.Interactions.cs @@ -273,7 +273,7 @@ namespace Content.Server.Construction if (doAfterState == DoAfterState.Cancelled) return HandleResult.False; - var insert = interactUsing.UsedUid; + var insert = interactUsing.Used; // Since many things inherit this step, we delegate the "is this entity valid?" logic to them. // While this is very OOP and I find it icky, I must admit that it simplifies the code here a lot. @@ -312,7 +312,7 @@ namespace Content.Server.Construction // we split the stack in two and insert the split stack. if (insertStep is MaterialConstructionGraphStep materialInsertStep) { - if (_stackSystem.Split(insert, materialInsertStep.Amount, EntityManager.GetComponent(interactUsing.UserUid).Coordinates) is not {} stack) + if (_stackSystem.Split(insert, materialInsertStep.Amount, EntityManager.GetComponent(interactUsing.User).Coordinates) is not {} stack) return HandleResult.False; insert = stack; @@ -329,8 +329,7 @@ namespace Content.Server.Construction construction.Containers.Add(store); // The container doesn't necessarily need to exist, so we ensure it. - _containerSystem.EnsureContainer(uid, store) - .Insert(EntityManager.GetEntity(insert)); + _containerSystem.EnsureContainer(uid, store).Insert(insert); } else { diff --git a/Content.Server/Conveyor/ConveyorSystem.cs b/Content.Server/Conveyor/ConveyorSystem.cs index 8578013aab..b5ee3a5dd3 100644 --- a/Content.Server/Conveyor/ConveyorSystem.cs +++ b/Content.Server/Conveyor/ConveyorSystem.cs @@ -5,12 +5,10 @@ using Content.Server.MachineLinking.Events; using Content.Server.MachineLinking.Models; using Content.Server.Power.Components; using Content.Server.Stunnable; -using Content.Server.Stunnable.Components; using Content.Shared.Conveyor; using Content.Shared.MachineLinking; using Content.Shared.Movement.Components; using Content.Shared.Popups; -using Content.Shared.Stunnable; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -129,7 +127,7 @@ namespace Content.Server.Conveyor return new Angle(IoCManager.Resolve().GetComponent(component.Owner).LocalRotation.Theta + radians + adjustment); } - public IEnumerable<(IEntity, IPhysBody)> GetEntitiesToMove(ConveyorComponent comp) + public IEnumerable<(EntityUid, IPhysBody)> GetEntitiesToMove(ConveyorComponent comp) { //todo uuuhhh cache this foreach (var entity in _entityLookup.GetEntitiesIntersecting(comp.Owner, flags: LookupFlags.Approximate)) diff --git a/Content.Server/Coordinates/Helpers/GridTileLookupHelpers.cs b/Content.Server/Coordinates/Helpers/GridTileLookupHelpers.cs index 41587963d4..6eb3297fbf 100644 --- a/Content.Server/Coordinates/Helpers/GridTileLookupHelpers.cs +++ b/Content.Server/Coordinates/Helpers/GridTileLookupHelpers.cs @@ -13,7 +13,7 @@ namespace Content.Server.Coordinates.Helpers /// Helper that returns all entities in a turf very fast. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IEnumerable GetEntitiesInTileFast(this TileRef turf, GridTileLookupSystem? gridTileLookup = null) + public static IEnumerable GetEntitiesInTileFast(this TileRef turf, GridTileLookupSystem? gridTileLookup = null) { gridTileLookup ??= EntitySystem.Get(); @@ -24,7 +24,7 @@ namespace Content.Server.Coordinates.Helpers /// Helper that returns all entities in a turf. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IEnumerable GetEntitiesInTileFast(this Vector2i indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null) + public static IEnumerable GetEntitiesInTileFast(this Vector2i indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null) { gridTileLookup ??= EntitySystem.Get(); return gridTileLookup.GetEntitiesIntersecting(gridId, indices); diff --git a/Content.Server/Cuffs/Components/CuffableComponent.cs b/Content.Server/Cuffs/Components/CuffableComponent.cs index e7b5389d05..bebaa03f37 100644 --- a/Content.Server/Cuffs/Components/CuffableComponent.cs +++ b/Content.Server/Cuffs/Components/CuffableComponent.cs @@ -4,12 +4,10 @@ using System.Linq; using Content.Server.Alert; using Content.Server.DoAfter; using Content.Server.Hands.Components; -using Content.Shared.ActionBlocker; using Content.Shared.Alert; using Content.Shared.Cuffs.Components; using Content.Shared.Interaction.Helpers; using Content.Shared.Popups; -using Content.Shared.Verbs; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Containers; @@ -19,7 +17,6 @@ using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.ViewVariables; namespace Content.Server.Cuffs.Components @@ -34,9 +31,9 @@ namespace Content.Server.Cuffs.Components [ViewVariables] public int CuffedHandCount => Container.ContainedEntities.Count * 2; - protected IEntity LastAddedCuffs => Container.ContainedEntities[^1]; + protected EntityUid LastAddedCuffs => Container.ContainedEntities[^1]; - public IReadOnlyList StoredEntities => Container.ContainedEntities; + public IReadOnlyList StoredEntities => Container.ContainedEntities; /// /// Container of various handcuffs currently applied to the entity. @@ -90,7 +87,7 @@ namespace Content.Server.Cuffs.Components /// Add a set of cuffs to an existing CuffedComponent. /// /// - public bool TryAddNewCuffs(IEntity user, IEntity handcuff) + public bool TryAddNewCuffs(EntityUid user, EntityUid handcuff) { if (!IoCManager.Resolve().HasComponent(handcuff)) { @@ -178,7 +175,7 @@ namespace Content.Server.Cuffs.Components /// /// The cuffed entity /// Optional param for the handcuff entity to remove from the cuffed entity. If null, uses the most recently added handcuff entity. - public async void TryUncuff(IEntity user, IEntity? cuffsToRemove = null) + public async void TryUncuff(EntityUid user, EntityUid cuffsToRemove = default) { if (_uncuffing) return; diff --git a/Content.Server/Cuffs/Components/HandcuffComponent.cs b/Content.Server/Cuffs/Components/HandcuffComponent.cs index 251c3120cf..89280f37b6 100644 --- a/Content.Server/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Server/Cuffs/Components/HandcuffComponent.cs @@ -2,7 +2,6 @@ using System; using System.Threading.Tasks; using Content.Server.DoAfter; using Content.Server.Hands.Components; -using Content.Server.Stunnable.Components; using Content.Shared.ActionBlocker; using Content.Shared.Cuffs.Components; using Content.Shared.Interaction; @@ -16,7 +15,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -195,7 +193,7 @@ namespace Content.Server.Cuffs.Components /// /// Update the cuffed state of an entity /// - private async void TryUpdateCuff(IEntity user, IEntity target, CuffableComponent cuffs) + private async void TryUpdateCuff(EntityUid user, EntityUid target, CuffableComponent cuffs) { var cuffTime = CuffTime; diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index b056e6891a..204a92428b 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -55,7 +55,7 @@ namespace Content.Server.Cuffs { return; } - if (!EntityManager.TryGetEntity(args.User, out var userEntity)) + if (!EntityManager.EntityExists(args.User) { // Should this even be possible? args.Cancel(); diff --git a/Content.Server/Damage/Commands/GodModeCommand.cs b/Content.Server/Damage/Commands/GodModeCommand.cs index 80535aac80..1d79d7c20c 100644 --- a/Content.Server/Damage/Commands/GodModeCommand.cs +++ b/Content.Server/Damage/Commands/GodModeCommand.cs @@ -31,13 +31,13 @@ namespace Content.Server.Damage.Commands return; } - if (player.AttachedEntityUid == null) + if (player.AttachedEntity == null) { shell.WriteLine("An entity needs to be specified when you aren't attached to an entity."); return; } - entity = player.AttachedEntityUid.Value; + entity = player.AttachedEntity.Value; break; case 1: if (!EntityUid.TryParse(args[0], out var id)) diff --git a/Content.Server/Damage/Commands/HurtCommand.cs b/Content.Server/Damage/Commands/HurtCommand.cs index b20c4c5fdb..d9c9c94cb8 100644 --- a/Content.Server/Damage/Commands/HurtCommand.cs +++ b/Content.Server/Damage/Commands/HurtCommand.cs @@ -1,4 +1,3 @@ -using System; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; @@ -42,10 +41,10 @@ namespace Content.Server.Damage.Commands return $"Damage Types:{msg}"; } - private delegate void Damage(IEntity entity, bool ignoreResistances); + private delegate void Damage(EntityUid entity, bool ignoreResistances); private bool TryParseEntity(IConsoleShell shell, IPlayerSession? player, string arg, - [NotNullWhen(true)] out IEntity? entity) + [NotNullWhen(true)] out EntityUid entity) { entity = null; @@ -72,7 +71,7 @@ namespace Content.Server.Damage.Commands var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetEntity(entityUid, out var parsedEntity)) + if (!entityManager.EntityExists(entityUid) { shell.WriteLine($"No entity found with uid {entityUid}"); @@ -85,7 +84,7 @@ namespace Content.Server.Damage.Commands private bool TryParseDamageArgs( IConsoleShell shell, - IEntity target, + EntityUid target, string[] args, [NotNullWhen(true)] out Damage? func) { @@ -141,7 +140,7 @@ namespace Content.Server.Damage.Commands { var player = shell.Player as IPlayerSession; bool ignoreResistances; - IEntity entity; + EntityUid entity; Damage? damageFunc; switch (args.Length) diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs index a91435657c..b2d03e03c7 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs @@ -14,7 +14,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors public string? Solution; /// - /// If there is a SpillableComponent on IEntity owner use it to create a puddle/smear. + /// If there is a SpillableComponent on EntityUidowner use it to create a puddle/smear. /// Or whatever solution is specified in the behavior itself. /// If none are available do nothing. /// diff --git a/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs b/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs index b2c52eef15..3e23796215 100644 --- a/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs @@ -1,10 +1,6 @@ using Content.Server.DeviceNetwork.Components; -using Content.Server.NodeContainer; -using Content.Server.NodeContainer.NodeGroups; -using Content.Server.Power.Components; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using System.Diagnostics.CodeAnalysis; using Robust.Shared.IoC; namespace Content.Server.DeviceNetwork.Systems @@ -23,8 +19,8 @@ namespace Content.Server.DeviceNetwork.Systems /// private void OnBeforePacketSent(EntityUid uid, WiredNetworkComponent component, BeforePacketSentEvent args) { - IEntity sender = EntityManager.GetEntity(args.Sender); - IEntity receiver = EntityManager.GetEntity(uid); + args.Sender + uid if (IoCManager.Resolve().GetComponent(receiver).GridID != IoCManager.Resolve().GetComponent(sender).GridID) { diff --git a/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs b/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs index f4be680740..398aa51b49 100644 --- a/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs @@ -19,7 +19,7 @@ namespace Content.Server.DeviceNetwork.Systems /// private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args) { - var sender = EntityManager.GetEntity(args.Sender); + var sender = args.Sender var ownPosition = IoCManager.Resolve().GetComponent(component.Owner).WorldPosition; var position = IoCManager.Resolve().GetComponent(sender).WorldPosition; diff --git a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs index a3231fe3ba..05a7955464 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs @@ -112,7 +112,7 @@ namespace Content.Server.Disposal.Tube.Components var actionBlocker = EntitySystem.Get(); var groupController = IoCManager.Resolve(); //Check if player can interact in their current state - if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntityUid!.Value) || !actionBlocker.CanUse(session.AttachedEntityUid!.Value))) + if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity!.Value) || !actionBlocker.CanUse(session.AttachedEntity!.Value))) return false; return true; diff --git a/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs index bc16a54a0e..c83fd1ad3d 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs @@ -94,7 +94,7 @@ namespace Content.Server.Disposal.Tube.Components var actionBlocker = EntitySystem.Get(); var groupController = IoCManager.Resolve(); //Check if player can interact in their current state - if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntityUid!.Value) || !actionBlocker.CanUse(session.AttachedEntityUid!.Value))) + if (!groupController.CanAdminMenu(session) && (!actionBlocker.CanInteract(session.AttachedEntity!.Value) || !actionBlocker.CanUse(session.AttachedEntity!.Value))) return false; return true; diff --git a/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs index 4e9c794c08..ae34576379 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs @@ -7,13 +7,10 @@ using Content.Shared.Acts; using Content.Shared.Disposal.Components; using Content.Shared.Popups; using Content.Shared.Sound; -using Content.Shared.Verbs; -using Robust.Server.Console; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Serialization.Manager.Attributes; @@ -100,7 +97,7 @@ namespace Content.Server.Disposal.Tube.Components } } - public void PopupDirections(IEntity entity) + public void PopupDirections(EntityUid entity) { var directions = string.Join(", ", ConnectableDirections()); diff --git a/Content.Server/Disposal/Tube/Components/IDisposalTubeComponent.cs b/Content.Server/Disposal/Tube/Components/IDisposalTubeComponent.cs index 8110acb798..3f31ead82a 100644 --- a/Content.Server/Disposal/Tube/Components/IDisposalTubeComponent.cs +++ b/Content.Server/Disposal/Tube/Components/IDisposalTubeComponent.cs @@ -11,6 +11,6 @@ namespace Content.Server.Disposal.Tube.Components Direction NextDirection(DisposalHolderComponent holder); bool CanConnect(Direction direction, IDisposalTubeComponent with); - void PopupDirections(IEntity entity); + void PopupDirections(EntityUid entity); } } diff --git a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs index b8266c5d6b..27e2f06bef 100644 --- a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs +++ b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs @@ -5,9 +5,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Localization; using Robust.Shared.Player; using Robust.Shared.Timing; @@ -68,7 +68,7 @@ namespace Content.Server.Disposal.Tube return; } - var entity = EntityManager.GetEntity(uid); + var uid component.LastClang = _gameTiming.CurTime; SoundSystem.Play(Filter.Pvs(entity), component.ClangSound.GetSound(), entity); } diff --git a/Content.Server/Disposal/TubeConnectionsCommand.cs b/Content.Server/Disposal/TubeConnectionsCommand.cs index d8344d19e9..666ca60349 100644 --- a/Content.Server/Disposal/TubeConnectionsCommand.cs +++ b/Content.Server/Disposal/TubeConnectionsCommand.cs @@ -38,7 +38,7 @@ namespace Content.Server.Disposal } var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetEntity(id, out var entity)) + if (!entityManager.EntityExists(id) { shell.WriteLine(Loc.GetString("shell-could-not-find-entity-with-uid",("uid", id))); return; diff --git a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs index 8a667bebaa..62f344e79b 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs @@ -1,11 +1,6 @@ -using System; using System.Collections.Generic; -using System.Linq; using Content.Server.Atmos; -using Content.Server.Atmos.EntitySystems; using Content.Server.Disposal.Tube.Components; -using Content.Server.Disposal.Tube; -using Content.Server.Disposal.Unit.EntitySystems; using Content.Server.Items; using Content.Shared.Atmos; using Content.Shared.Body.Components; @@ -77,7 +72,7 @@ namespace Content.Server.Disposal.Unit.Components Container = ContainerHelpers.EnsureContainer(Owner, nameof(DisposalHolderComponent)); } - private bool CanInsert(IEntity entity) + private bool CanInsert(EntityUid entity) { if (!Container.CanInsert(entity)) { @@ -88,7 +83,7 @@ namespace Content.Server.Disposal.Unit.Components IoCManager.Resolve().HasComponent(entity); } - public bool TryInsert(IEntity entity) + public bool TryInsert(EntityUid entity) { if (!CanInsert(entity) || !Container.Insert(entity)) { diff --git a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs index 2136768560..e1bbcf5439 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs @@ -71,7 +71,7 @@ namespace Content.Server.Disposal.Unit.Components /// [ViewVariables] public Container Container = default!; - [ViewVariables] public IReadOnlyList ContainedEntities => Container.ContainedEntities; + [ViewVariables] public IReadOnlyList ContainedEntities => Container.ContainedEntities; [ViewVariables] public bool Powered => @@ -88,7 +88,7 @@ namespace Content.Server.Disposal.Unit.Components [DataField("air")] public GasMixture Air { get; set; } = new(Atmospherics.CellVolume); - private bool PlayerCanUse(IEntity? player) + private bool PlayerCanUse(EntityUid player) { if (player == null) { diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index d9edba6ff1..21c0692511 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -116,7 +116,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems private void DoInsertDisposalUnit(DoInsertDisposalUnitEvent ev) { - var toInsert = EntityManager.GetEntity(ev.ToInsert); + var toInsert = ev.ToInsert if (!EntityManager.TryGetComponent(ev.Unit, out DisposalUnitComponent? unit)) { @@ -547,7 +547,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems : SharedDisposalUnitComponent.LightState.Ready); } - public void Remove(DisposalUnitComponent component, IEntity entity) + public void Remove(DisposalUnitComponent component, EntityUid entity) { component.Container.Remove(entity); @@ -600,7 +600,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems } } - public override bool CanInsert(SharedDisposalUnitComponent component, IEntity entity) + public override bool CanInsert(SharedDisposalUnitComponent component, EntityUid entity) { if (!base.CanInsert(component, entity) || component is not DisposalUnitComponent serverComp) return false; @@ -629,7 +629,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems }, component.AutomaticEngageToken.Token); } - public void AfterInsert(DisposalUnitComponent component, IEntity entity) + public void AfterInsert(DisposalUnitComponent component, EntityUid entity) { TryQueueEngage(component); diff --git a/Content.Server/DoAfter/DoAfterEventArgs.cs b/Content.Server/DoAfter/DoAfterEventArgs.cs index 79d91462ca..b53d2237a9 100644 --- a/Content.Server/DoAfter/DoAfterEventArgs.cs +++ b/Content.Server/DoAfter/DoAfterEventArgs.cs @@ -1,11 +1,7 @@ using System; using System.Threading; -using Content.Shared.Interaction.Helpers; -using Content.Shared.Physics; using Robust.Shared.GameObjects; -// ReSharper disable UnassignedReadonlyField - namespace Content.Server.DoAfter { public sealed class DoAfterEventArgs @@ -98,14 +94,6 @@ namespace Content.Server.DoAfter /// public object? BroadcastFinishedEvent { get; set; } - public DoAfterEventArgs( - IEntity user, - float delay, - CancellationToken cancelToken = default, - IEntity? target = null) : this((EntityUid) user, delay, cancelToken, target ?? null) - { - } - public DoAfterEventArgs( EntityUid user, float delay, diff --git a/Content.Server/Doors/Components/ServerDoorComponent.cs b/Content.Server/Doors/Components/ServerDoorComponent.cs index bfcffa35d7..34f7a46b28 100644 --- a/Content.Server/Doors/Components/ServerDoorComponent.cs +++ b/Content.Server/Doors/Components/ServerDoorComponent.cs @@ -25,7 +25,6 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; @@ -257,7 +256,7 @@ namespace Content.Server.Doors.Components if (!ClickOpen) return; - DoorClickShouldActivateEvent ev = new DoorClickShouldActivateEvent(eventArgs); + var ev = new DoorClickShouldActivateEvent(eventArgs); IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, ev, false); if (ev.Handled) return; @@ -274,18 +273,17 @@ namespace Content.Server.Doors.Components #region Opening - public void TryOpen(IEntity? user=null) + public void TryOpen(EntityUid user = default) { var msg = new DoorOpenAttemptEvent(); IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, msg); if (msg.Cancelled) return; - if (user == null) + if (!user.Valid) { // a machine opened it or something, idk Open(); - return; } else if (CanOpenByEntity(user)) { @@ -303,9 +301,9 @@ namespace Content.Server.Doors.Components } } - public bool CanOpenByEntity(IEntity user) + public bool CanOpenByEntity(EntityUid user) { - if(!CanOpenGeneric()) + if (!CanOpenGeneric()) { return false; } @@ -422,14 +420,14 @@ namespace Content.Server.Doors.Components #region Closing - public void TryClose(IEntity? user=null) + public void TryClose(EntityUid user = default) { var msg = new DoorCloseAttemptEvent(); IoCManager.Resolve().EventBus.RaiseLocalEvent(Owner, msg); if (msg.Cancelled) return; - if (user != null && !CanCloseByEntity(user)) + if (user != default && !CanCloseByEntity(user)) { Deny(); return; @@ -438,7 +436,7 @@ namespace Content.Server.Doors.Components Close(); } - public bool CanCloseByEntity(IEntity user) + public bool CanCloseByEntity(EntityUid user) { if (!CanCloseGeneric()) { diff --git a/Content.Server/Electrocution/ElectrocutionSystem.cs b/Content.Server/Electrocution/ElectrocutionSystem.cs index 495e166714..506c4a74a5 100644 --- a/Content.Server/Electrocution/ElectrocutionSystem.cs +++ b/Content.Server/Electrocution/ElectrocutionSystem.cs @@ -9,7 +9,6 @@ using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.Power.NodeGroups; using Content.Server.Window; -using Content.Shared.Administration.Logs; using Content.Shared.Alert; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; @@ -24,7 +23,6 @@ using Content.Shared.Speech.EntitySystems; using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Content.Shared.Weapons.Melee; -using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -99,7 +97,7 @@ namespace Content.Server.Electrocution foreach (var finished in finishedElectrocutionsQueue) { - var uid = (EntityUid) finished.Owner; + var uid = finished.Owner; if (EntityManager.EntityExists(finished.Electrocuting)) { // TODO: damage should be scaled by shock damage multiplier @@ -366,13 +364,12 @@ namespace Content.Server.Electrocution if (sourceUid != null) { _popupSystem.PopupEntity(Loc.GetString("electrocuted-component-mob-shocked-by-source-popup-others", - ("mob", EntityManager.GetEntity(uid)), ("source", EntityManager.GetEntity(sourceUid.Value))), - uid, filter); + ("mob", uid), ("source", (sourceUid.Value))), uid, filter); } else { _popupSystem.PopupEntity(Loc.GetString("electrocuted-component-mob-shocked-popup-others", - ("mob", EntityManager.GetEntity(uid))), uid, filter); + ("mob", uid)), uid, filter); } return true; @@ -395,14 +392,14 @@ namespace Content.Server.Electrocution visited.Add(entity); if (EntityManager.TryGetComponent(entity, out SharedPullableComponent? pullable) - && pullable.Puller != null + && pullable.Puller != default && !visited.Contains(pullable.Puller)) { GetChainedElectrocutionTargetsRecurse(pullable.Puller, depth + 1, visited, all); } if (EntityManager.TryGetComponent(entity, out SharedPullerComponent? puller) - && puller.Pulling != null + && puller.Pulling != default && !visited.Contains(puller.Pulling)) { GetChainedElectrocutionTargetsRecurse(puller.Pulling, depth + 1, visited, all); diff --git a/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs b/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs index 4d088e216b..f29bcf7e54 100644 --- a/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs +++ b/Content.Server/Engineering/EntitySystems/DisassembleOnActivateSystem.cs @@ -52,7 +52,7 @@ namespace Content.Server.Engineering.EntitySystems hands.PutInHandOrDrop(item); } - IoCManager.Resolve().DeleteEntity((EntityUid) component.Owner); + IoCManager.Resolve().DeleteEntity(component.Owner); return; } diff --git a/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs b/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs index b0b4ae0563..bcbcdc0da4 100644 --- a/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs +++ b/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs @@ -69,7 +69,7 @@ namespace Content.Server.Engineering.EntitySystems EntityManager.SpawnEntity(component.Prototype, args.ClickLocation.SnapToGrid(grid)); if (component.RemoveOnInteract && stackComp == null && !((!IoCManager.Resolve().EntityExists(component.Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(component.Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) - IoCManager.Resolve().DeleteEntity((EntityUid) component.Owner); + IoCManager.Resolve().DeleteEntity(component.Owner); } } } diff --git a/Content.Server/Examine/ExamineSystem.cs b/Content.Server/Examine/ExamineSystem.cs index 037913bb63..303009423e 100644 --- a/Content.Server/Examine/ExamineSystem.cs +++ b/Content.Server/Examine/ExamineSystem.cs @@ -35,16 +35,16 @@ namespace Content.Server.Examine var playerEnt = session.AttachedEntity; var channel = player.ConnectedClient; - if (playerEnt == null - || !EntityManager.TryGetEntity(request.EntityUid, out var entity) - || !CanExamine(playerEnt, entity)) + if (playerEnt == default + || !EntityManager.EntityExists(request.EntityUid) + || !CanExamine(playerEnt, request.EntityUid)) { RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage( request.EntityUid, _entityNotFoundMessage), channel); return; } - var text = GetExamineText(entity, player.AttachedEntity); + var text = GetExamineText(request.EntityUid, player.AttachedEntity); RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text), channel); } } diff --git a/Content.Server/Explosion/Components/ClusterFlashComponent.cs b/Content.Server/Explosion/Components/ClusterFlashComponent.cs index 0d5ac0ba53..f9128ba8cb 100644 --- a/Content.Server/Explosion/Components/ClusterFlashComponent.cs +++ b/Content.Server/Explosion/Components/ClusterFlashComponent.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Content.Server.Explosion.EntitySystems; using Content.Server.Flash.Components; @@ -100,7 +99,7 @@ namespace Content.Server.Explosion.Components var delay = 20; var grenadesInserted = _grenadesContainer.ContainedEntities.Count + _unspawnedCount; var thrownCount = 0; - var segmentAngle = (int) (360 / grenadesInserted); + var segmentAngle = 360 / grenadesInserted; while (TryGetGrenade(out var grenade)) { var angleMin = segmentAngle * thrownCount; @@ -123,14 +122,14 @@ namespace Content.Server.Explosion.Components }); } - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); }); return true; } - private bool TryGetGrenade([NotNullWhen(true)] out IEntity? grenade) + private bool TryGetGrenade(out EntityUid grenade) { - grenade = null; + grenade = default; if (_unspawnedCount > 0) { diff --git a/Content.Server/Explosion/Components/OnUseTimerTriggerComponent.cs b/Content.Server/Explosion/Components/OnUseTimerTriggerComponent.cs index f26fe65b08..c43149b88f 100644 --- a/Content.Server/Explosion/Components/OnUseTimerTriggerComponent.cs +++ b/Content.Server/Explosion/Components/OnUseTimerTriggerComponent.cs @@ -17,7 +17,7 @@ namespace Content.Server.Explosion.Components private float _delay = 0f; // TODO: Need to split this out so it's a generic "OnUseTimerTrigger" component. - public void Trigger(IEntity user) + public void Trigger(EntityUid user) { if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) appearance.SetData(TriggerVisuals.VisualState, TriggerVisualState.Primed); diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index 6ced1674d8..102fbcd4e8 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -5,7 +5,6 @@ using Content.Server.Administration.Logs; using Content.Server.Camera; using Content.Server.Explosion.Components; using Content.Shared.Acts; -using Content.Shared.Administration.Logs; using Content.Shared.Database; using Content.Shared.Interaction.Helpers; using Content.Shared.Maps; @@ -53,7 +52,7 @@ namespace Content.Server.Explosion.EntitySystems [Dependency] private readonly TriggerSystem _triggers = default!; [Dependency] private readonly AdminLogSystem _logSystem = default!; - private bool IgnoreExplosivePassable(IEntity e) + private bool IgnoreExplosivePassable(EntityUid e) { return e.HasTag("ExplosivePassable"); } @@ -82,12 +81,12 @@ namespace Content.Server.Explosion.EntitySystems foreach (var player in players) { - if (player.AttachedEntity == null || !IoCManager.Resolve().TryGetComponent(player.AttachedEntity, out CameraRecoilComponent? recoil)) + if (!player.AttachedEntity.Valid || !EntityManager.TryGetComponent(player.AttachedEntity, out CameraRecoilComponent? recoil)) { continue; } - var playerPos = IoCManager.Resolve().GetComponent(player.AttachedEntity).WorldPosition; + var playerPos = EntityManager.GetComponent(player.AttachedEntity).WorldPosition; var delta = epicenter.ToMapPos(EntityManager) - playerPos; //Change if zero. Will result in a NaN later breaking camera shake if not changed @@ -122,26 +121,26 @@ namespace Content.Server.Explosion.EntitySystems { var entitiesInRange = _entityLookup.GetEntitiesInRange(mapId, boundingBox, 0).ToList(); - var impassableEntities = new List<(IEntity, float)>(); - var nonImpassableEntities = new List<(IEntity, float)>(); + var impassableEntities = new List<(EntityUid, float)>(); + var nonImpassableEntities = new List<(EntityUid, float)>(); // TODO: Given this seems to rely on physics it should just query directly like everything else. // The entities are paired with their distance to the epicenter // and splitted into two lists based on if they are Impassable or not foreach (var entity in entitiesInRange) { - if ((!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || entity.IsInContainer()) + if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || entity.IsInContainer()) { continue; } - if (!IoCManager.Resolve().GetComponent(entity).Coordinates.TryDistance(EntityManager, epicenter, out var distance) || + if (!EntityManager.GetComponent(entity).Coordinates.TryDistance(EntityManager, epicenter, out var distance) || distance > maxRange) { continue; } - if (!IoCManager.Resolve().TryGetComponent(entity, out PhysicsComponent? body) || body.Fixtures.Count < 1) + if (!EntityManager.TryGetComponent(entity, out PhysicsComponent? body) || body.Fixtures.Count < 1) { continue; } @@ -310,7 +309,7 @@ namespace Content.Server.Explosion.EntitySystems } else { - while (EntityManager.TryGetEntity(entity, out var e) && e.TryGetContainer(out var container)) + while (EntityManager.EntityExists(entity) && entity.TryGetContainer(out var container)) { entity = container.Owner; } diff --git a/Content.Server/Explosion/EntitySystems/TriggerSystem.cs b/Content.Server/Explosion/EntitySystems/TriggerSystem.cs index 5f4af077a4..1df2297336 100644 --- a/Content.Server/Explosion/EntitySystems/TriggerSystem.cs +++ b/Content.Server/Explosion/EntitySystems/TriggerSystem.cs @@ -20,10 +20,10 @@ namespace Content.Server.Explosion.EntitySystems /// public class TriggerEvent : HandledEntityEventArgs { - public IEntity Triggered { get; } - public IEntity? User { get; } + public EntityUid Triggered { get; } + public EntityUid User { get; } - public TriggerEvent(IEntity triggered, IEntity? user = null) + public TriggerEvent(EntityUid triggered, EntityUid user = default) { Triggered = triggered; User = user; @@ -116,13 +116,13 @@ namespace Content.Server.Explosion.EntitySystems Trigger(component.Owner); } - public void Trigger(IEntity trigger, IEntity? user = null) + public void Trigger(EntityUid trigger, EntityUid user = default) { var triggerEvent = new TriggerEvent(trigger, user); EntityManager.EventBus.RaiseLocalEvent(trigger, triggerEvent); } - public void HandleTimerTrigger(TimeSpan delay, IEntity triggered, IEntity? user = null) + public void HandleTimerTrigger(TimeSpan delay, EntityUid triggered, EntityUid user = default) { if (delay.TotalSeconds <= 0) { diff --git a/Content.Server/Extinguisher/FireExtinguisherComponent.cs b/Content.Server/Extinguisher/FireExtinguisherComponent.cs index a67bce5af0..26e8a9382c 100644 --- a/Content.Server/Extinguisher/FireExtinguisherComponent.cs +++ b/Content.Server/Extinguisher/FireExtinguisherComponent.cs @@ -1,15 +1,13 @@ -using System; using System.Threading.Tasks; using Content.Server.Chemistry.Components; using Content.Server.Chemistry.EntitySystems; using Content.Shared.ActionBlocker; using Content.Shared.Audio; -using Content.Shared.Chemistry.Reagent; +using Content.Shared.Extinguisher; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Sound; -using Content.Shared.Extinguisher; -using Content.Shared.FixedPoint; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -59,26 +57,27 @@ namespace Content.Server.Extinguisher return false; } - var targetEntity = eventArgs.Target; - if (IoCManager.Resolve().HasComponent(eventArgs.Target) - && solutionContainerSystem.TryGetDrainableSolution(targetEntity, out var targetSolution) - && solutionContainerSystem.TryGetDrainableSolution(Owner, out var container)) + if (eventArgs.Target is not {Valid: true} target || + !IoCManager.Resolve().HasComponent(target) || + !solutionContainerSystem.TryGetDrainableSolution(target, out var targetSolution) || + !solutionContainerSystem.TryGetDrainableSolution(Owner, out var container)) { - var transfer = FixedPoint2.Min(container.AvailableVolume, targetSolution.DrainAvailable); - if (transfer > 0) - { - var drained = solutionContainerSystem.Drain(targetEntity, targetSolution, transfer); - solutionContainerSystem.TryAddSolution(Owner, container, drained); - - SoundSystem.Play(Filter.Pvs(Owner), _refillSound.GetSound(), Owner); - eventArgs.Target.PopupMessage(eventArgs.User, - Loc.GetString("fire-extingusiher-component-after-interact-refilled-message", ("owner", Owner))); - } - - return true; + return false; } - return false; + var transfer = FixedPoint2.Min(container.AvailableVolume, targetSolution.DrainAvailable); + if (transfer > 0) + { + var drained = solutionContainerSystem.Drain(target, targetSolution, transfer); + solutionContainerSystem.TryAddSolution(Owner, container, drained); + + SoundSystem.Play(Filter.Pvs(Owner), _refillSound.GetSound(), Owner); + eventArgs.Target.Value.PopupMessage(eventArgs.User, + Loc.GetString("fire-extingusiher-component-after-interact-refilled-message", ("owner", Owner))); + } + + return true; + } bool IUse.UseEntity(UseEntityEventArgs eventArgs) { @@ -91,13 +90,13 @@ namespace Content.Server.Extinguisher ToggleSafety(eventArgs.User); } - private void ToggleSafety(IEntity user) + private void ToggleSafety(EntityUid user) { SoundSystem.Play(Filter.Pvs(Owner), SafetySound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f).WithVolume(-4f)); SetSafety(user, !_safety); } - private void SetSafety(IEntity user, bool state) + private void SetSafety(EntityUid user, bool state) { if (!EntitySystem.Get().CanInteract(user) || !_hasSafety) return; diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index 7333571b24..1355d2f2ea 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -3,7 +3,6 @@ using Content.Server.Flash.Components; using Content.Server.Inventory.Components; using Content.Server.Items; using Content.Server.Stunnable; -using Content.Server.Stunnable.Components; using Content.Server.Weapon.Melee; using Content.Shared.Examine; using Content.Shared.Flash; @@ -13,7 +12,6 @@ using Content.Shared.Inventory; using Content.Shared.Physics; using Content.Shared.Popups; using Content.Shared.Sound; -using Content.Shared.Stunnable; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; @@ -50,7 +48,7 @@ namespace Content.Server.Flash } args.Handled = true; - foreach (IEntity e in args.HitEntities) + foreach (EntityUide in args.HitEntities) { Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo); } @@ -83,7 +81,7 @@ namespace Content.Server.Flash } } - private bool UseFlash(FlashComponent comp, IEntity user) + private bool UseFlash(FlashComponent comp, EntityUiduser) { if (comp.HasUses) { @@ -136,9 +134,9 @@ namespace Content.Server.Flash if (displayPopup && user != null && target != user) { - // TODO Resolving the IEntity here bad. - if(EntityManager.TryGetEntity(user.Value, out var userEntity) - && EntityManager.TryGetEntity(target, out var targetEntity)) + // TODO Resolving the EntityUidhere bad. + if(EntityManager.EntityExists(user.Value) + && EntityManager.EntityExists(target) userEntity.PopupMessage(targetEntity, Loc.GetString( diff --git a/Content.Server/Fluids/Components/MopComponent.cs b/Content.Server/Fluids/Components/MopComponent.cs index c74965f482..097c9a83ad 100644 --- a/Content.Server/Fluids/Components/MopComponent.cs +++ b/Content.Server/Fluids/Components/MopComponent.cs @@ -1,9 +1,7 @@ using System.Threading.Tasks; using Content.Server.Chemistry.EntitySystems; using Content.Server.DoAfter; -using Content.Server.Fluids.EntitySystems; using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; @@ -143,7 +141,7 @@ namespace Content.Server.Fluids.Components // is the puddle cleaned? if (puddleSolution.TotalVolume - transferAmount <= 0) { - IoCManager.Resolve().DeleteEntity((EntityUid) puddleComponent.Owner); + IoCManager.Resolve().DeleteEntity(puddleComponent.Owner); // After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly. // we do this WITHOUT adding to the existing puddle. Otherwise we have might have water puddles with the vomit sprite. diff --git a/Content.Server/Fluids/Components/SpillExtensions.cs b/Content.Server/Fluids/Components/SpillExtensions.cs index 9b9efc3e0f..b79072698f 100644 --- a/Content.Server/Fluids/Components/SpillExtensions.cs +++ b/Content.Server/Fluids/Components/SpillExtensions.cs @@ -28,32 +28,12 @@ namespace Content.Server.Fluids.Components /// Play the spill sound. /// The puddle if one was created, null otherwise. /// Whether to attempt to merge with existing puddles - public static PuddleComponent? SpillAt(this Solution solution, IEntity entity, string prototype, + public static PuddleComponent? SpillAt(this Solution solution, EntityUid entity, string prototype, bool sound = true, bool combine = true) { return solution.SpillAt(IoCManager.Resolve().GetComponent(entity).Coordinates, prototype, sound, combine: combine); } - /// - /// Spills the specified solution at the entity's location if possible. - /// - /// - /// The entity to use as a location to spill the solution at. - /// - /// Initial solution for the prototype. - /// The prototype to use. - /// Play the spill sound. - /// - /// Whether to attempt to merge with existing puddles - /// The puddle if one was created, null otherwise. - public static PuddleComponent? SpillAt(this Solution solution, EntityUid entity, string prototype, - bool sound = true, IEntityManager? entityManager = null, bool combine = true) - { - entityManager ??= IoCManager.Resolve(); - - return solution.SpillAt(entityManager.GetComponent(entity).Coordinates, prototype, sound, combine: combine); - } - /// /// Spills the specified solution at the entity's location if possible. /// @@ -66,7 +46,7 @@ namespace Content.Server.Fluids.Components /// Play the spill sound. /// Whether to attempt to merge with existing puddles /// True if a puddle was created, false otherwise. - public static bool TrySpillAt(this Solution solution, IEntity entity, string prototype, + public static bool TrySpillAt(this Solution solution, EntityUid entity, string prototype, [NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true, bool combine = true) { puddle = solution.SpillAt(entity, prototype, sound, combine: combine); diff --git a/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs b/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs index ff32c906ea..5bac9f8434 100644 --- a/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs +++ b/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs @@ -1,6 +1,5 @@ using Content.Server.Chemistry.EntitySystems; using Content.Server.Fluids.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -20,7 +19,7 @@ namespace Content.Server.Fluids.EntitySystems var queueDelete = new RemQueue(); foreach (var evaporationComponent in EntityManager.EntityQuery()) { - var uid = (EntityUid) evaporationComponent.Owner; + var uid = evaporationComponent.Owner; evaporationComponent.Accumulator += frameTime; if (!_solutionContainerSystem.TryGetSolution(uid, evaporationComponent.SolutionName, out var solution)) diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs index 3d105159fe..f78866590b 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs @@ -5,9 +5,7 @@ using System.Linq; using Content.Server.Chemistry.EntitySystems; using Content.Server.Construction.Components; using Content.Server.Fluids.Components; -using Content.Shared.Administration.Logs; using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.Database; using Content.Shared.Directions; using Content.Shared.Examine; @@ -26,7 +24,6 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Player; -using Robust.Shared.Prototypes; namespace Content.Server.Fluids.EntitySystems { @@ -61,7 +58,7 @@ namespace Content.Server.Fluids.EntitySystems private void UpdateVisuals(EntityUid uid, PuddleComponent puddleComponent) { - if ((!IoCManager.Resolve().EntityExists(puddleComponent.Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(puddleComponent.Owner).EntityLifeStage) >= EntityLifeStage.Deleted || EmptyHolder(uid, puddleComponent) || + if ((!EntityManager.EntityExists(puddleComponent.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent(puddleComponent.Owner).EntityLifeStage) >= EntityLifeStage.Deleted || EmptyHolder(uid, puddleComponent) || !EntityManager.TryGetComponent(uid, out var appearanceComponent)) { return; @@ -106,7 +103,7 @@ namespace Content.Server.Fluids.EntitySystems verb.Text = Loc.GetString("spill-target-verb-get-data-text"); // TODO VERB ICONS spill icon? pouring out a glass/beaker? verb.Act = () => _solutionContainerSystem.SplitSolution(args.Target, - solution, solution.DrainAvailable).SpillAt(IoCManager.Resolve().GetComponent(args.Target).Coordinates, "PuddleSmear"); + solution, solution.DrainAvailable).SpillAt(EntityManager.GetComponent(args.Target).Coordinates, "PuddleSmear"); verb.Impact = LogImpact.Medium; // dangerous reagent reaction are logged separately. args.Verbs.Add(verb); } @@ -121,10 +118,10 @@ namespace Content.Server.Fluids.EntitySystems private void OnUnanchored(EntityUid uid, PuddleComponent puddle, UnanchoredEvent unanchoredEvent) { - if (!IoCManager.Resolve().GetComponent(puddle.Owner).Anchored) + if (!EntityManager.GetComponent(puddle.Owner).Anchored) return; - IoCManager.Resolve().QueueDeleteEntity((EntityUid) puddle.Owner); + EntityManager.QueueDeleteEntity(puddle.Owner); } /// @@ -288,11 +285,11 @@ namespace Content.Server.Fluids.EntitySystems puddle = default; // We're most likely in space, do nothing. - if (!IoCManager.Resolve().GetComponent(puddleComponent.Owner).GridID.IsValid()) + if (!EntityManager.GetComponent(puddleComponent.Owner).GridID.IsValid()) return false; - var mapGrid = _mapManager.GetGrid(IoCManager.Resolve().GetComponent(puddleComponent.Owner).GridID); - var coords = IoCManager.Resolve().GetComponent(puddleComponent.Owner).Coordinates; + var mapGrid = _mapManager.GetGrid(EntityManager.GetComponent(puddleComponent.Owner).GridID); + var coords = EntityManager.GetComponent(puddleComponent.Owner).Coordinates; if (!coords.Offset(direction).TryGetTileRef(out var tile)) { @@ -305,7 +302,7 @@ namespace Content.Server.Fluids.EntitySystems return false; } - if (!IoCManager.Resolve().GetComponent(puddleComponent.Owner).Anchored) + if (!EntityManager.GetComponent(puddleComponent.Owner).Anchored) return false; foreach (var entity in mapGrid.GetInDir(coords, direction)) @@ -330,9 +327,10 @@ namespace Content.Server.Fluids.EntitySystems puddle ??= () => { - IEntity tempQualifier = IoCManager.Resolve().SpawnEntity(IoCManager.Resolve().GetComponent(puddleComponent.Owner).EntityPrototype?.ID, + var id = EntityManager.SpawnEntity( + EntityManager.GetComponent(puddleComponent.Owner).EntityPrototype?.ID, mapGrid.DirectionToGrid(coords, direction)); - return IoCManager.Resolve().GetComponent(tempQualifier); + return EntityManager.GetComponent(id); }; return true; diff --git a/Content.Server/GameTicking/Commands/MappingCommand.cs b/Content.Server/GameTicking/Commands/MappingCommand.cs index 34e45facd9..457b1ae9e0 100644 --- a/Content.Server/GameTicking/Commands/MappingCommand.cs +++ b/Content.Server/GameTicking/Commands/MappingCommand.cs @@ -76,7 +76,7 @@ namespace Content.Server.GameTicking.Commands shell.ExecuteCommand($"addmap {mapId} false"); shell.ExecuteCommand($"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true"); - IEntity? tempQualifier = player.AttachedEntity; + EntityUid tempQualifier = player.AttachedEntity; if ((tempQualifier != null ? IoCManager.Resolve().GetComponent(tempQualifier).EntityPrototype : null)?.ID != "AdminObserver") shell.ExecuteCommand("aghost"); diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index 3e4d0d0c46..34ff901b66 100644 --- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs +++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs @@ -3,11 +3,9 @@ using System.Collections.Generic; using System.Linq; using Content.Server.Database; using Content.Server.GameTicking.Events; -using Content.Server.Players; -using Content.Server.Mind; using Content.Server.Ghost; -using Content.Server.Roles; -using Content.Server.Station; +using Content.Server.Mind; +using Content.Server.Players; using Content.Shared.CCVar; using Content.Shared.Coordinates; using Content.Shared.GameTicking; @@ -371,7 +369,7 @@ namespace Content.Server.GameTicking { // TODO: Maybe something less naive here? // FIXME: Actually, definitely. - IoCManager.Resolve().DeleteEntity((EntityUid) entity); + IoCManager.Resolve().DeleteEntity(entity); } _mapManager.Restart(); diff --git a/Content.Server/GameTicking/Presets/GamePreset.cs b/Content.Server/GameTicking/Presets/GamePreset.cs index 434463bf02..4f4904432a 100644 --- a/Content.Server/GameTicking/Presets/GamePreset.cs +++ b/Content.Server/GameTicking/Presets/GamePreset.cs @@ -30,7 +30,7 @@ namespace Content.Server.GameTicking.Presets /// /// Called when a player is spawned in (this includes, but is not limited to, before Start) /// - public virtual void OnSpawnPlayerCompleted(IPlayerSession session, IEntity mob, bool lateJoin) { } + public virtual void OnSpawnPlayerCompleted(IPlayerSession session, EntityUid mob, bool lateJoin) { } /// /// Called when a player attempts to ghost. @@ -39,10 +39,10 @@ namespace Content.Server.GameTicking.Presets { var playerEntity = mind.OwnedEntity; - if (playerEntity != null && IoCManager.Resolve().HasComponent(playerEntity)) + if (playerEntity != default && IoCManager.Resolve().HasComponent(playerEntity)) return false; - if (mind.VisitingEntity != null) + if (mind.VisitingEntity != default) { mind.UnVisit(); } diff --git a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs index a3da383f75..a183fb4ad2 100644 --- a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs +++ b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs @@ -63,7 +63,7 @@ namespace Content.Server.GameTicking.Presets return true; } - public override void OnSpawnPlayerCompleted(IPlayerSession session, IEntity mob, bool lateJoin) + public override void OnSpawnPlayerCompleted(IPlayerSession session, EntityUid mob, bool lateJoin) { var startingBalance = _cfg.GetCVar(CCVars.TraitorDeathMatchStartingBalance); @@ -86,7 +86,7 @@ namespace Content.Server.GameTicking.Presets foreach (var slot in victimSlots) { if (inventory.TryGetSlotItem(slot, out ItemComponent? vItem)) - IoCManager.Resolve().DeleteEntity((EntityUid) vItem.Owner); + IoCManager.Resolve().DeleteEntity(vItem.Owner); } // Replace their items: diff --git a/Content.Server/Ghost/Components/GhostRadioComponent.cs b/Content.Server/Ghost/Components/GhostRadioComponent.cs index fa70b7fe3f..1f8d25f85d 100644 --- a/Content.Server/Ghost/Components/GhostRadioComponent.cs +++ b/Content.Server/Ghost/Components/GhostRadioComponent.cs @@ -2,7 +2,6 @@ using Content.Server.Radio.Components; using Content.Shared.Chat; using Robust.Server.GameObjects; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -24,7 +23,7 @@ namespace Content.Server.Ghost.Components public IReadOnlyList Channels => _channels; - public void Receive(string message, int channel, IEntity speaker) + public void Receive(string message, int channel, EntityUidspeaker) { if (!IoCManager.Resolve().TryGetComponent(Owner, out ActorComponent? actor)) return; @@ -40,6 +39,6 @@ namespace Content.Server.Ghost.Components _netManager.ServerSendMessage(msg, playerChannel); } - public void Broadcast(string message, IEntity speaker) { } + public void Broadcast(string message, EntityUidspeaker) { } } } diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index e70c3155c0..ad3d563209 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -169,7 +169,7 @@ namespace Content.Server.Ghost return; } - if (!EntityManager.TryGetEntity(msg.Target, out var entity)) + if (!EntityManager.EntityExists(msg.Target) { Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid entity id: {msg.Target}"); return; @@ -180,7 +180,7 @@ namespace Content.Server.Ghost private void DeleteEntity(EntityUid uid) { - if (!EntityManager.TryGetEntity(uid, out var entity) + if (!EntityManager.EntityExists(uid) || (!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted || (!IoCManager.Resolve().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(entity).EntityLifeStage) == EntityLifeStage.Terminating) return; diff --git a/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs b/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs index ed31c325cf..35de4887fa 100644 --- a/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs +++ b/Content.Server/Ghost/Roles/Components/GhostRoleMobSpawnerComponent.cs @@ -1,13 +1,11 @@ using System; using Content.Server.Mind.Commands; using Content.Server.Mind.Components; -using Content.Server.Players; using JetBrains.Annotations; using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Content.Server.Ghost.Roles.Components @@ -58,7 +56,7 @@ namespace Content.Server.Ghost.Roles.Components Taken = true; if (_deleteOnSpawn) - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); return true; } diff --git a/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs b/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs index 20c8f4b93d..0a618b30b6 100644 --- a/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs +++ b/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs @@ -219,7 +219,7 @@ namespace Content.Server.Gravity.EntitySystems public void UpdateState(GravityGeneratorComponent grav, ApcPowerReceiverComponent powerReceiver) { - var uid = (EntityUid) grav.Owner; + var uid = grav.Owner; var appearance = EntityManager.GetComponentOrNull(uid); appearance?.SetData(GravityGeneratorVisuals.Charge, grav.Charge); diff --git a/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs b/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs index af2198cc67..d652761f43 100644 --- a/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs +++ b/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs @@ -41,7 +41,7 @@ namespace Content.Server.Gravity.EntitySystems if (_mapManager.TryGetGrid(IoCManager.Resolve().GetComponent(status.Owner).GridID, out var grid)) { - var gridEntity = EntityManager.GetEntity(grid.GridEntityId); + var gridgrid.GridEntityId if (IoCManager.Resolve().GetComponent(gridEntity).Enabled) { RemoveWeightless(status); diff --git a/Content.Server/Hands/Components/HandsComponent.cs b/Content.Server/Hands/Components/HandsComponent.cs index 96bd44a42a..1f387b3485 100644 --- a/Content.Server/Hands/Components/HandsComponent.cs +++ b/Content.Server/Hands/Components/HandsComponent.cs @@ -36,7 +36,7 @@ namespace Content.Server.Hands.Components int IDisarmedAct.Priority => int.MaxValue; // We want this to be the last disarm act to run. - protected override void OnHeldEntityRemovedFromHand(IEntity heldEntity, HandState handState) + protected override void OnHeldEntityRemovedFromHand(EntityUid heldEntity, HandState handState) { if (IoCManager.Resolve().TryGetComponent(heldEntity, out ItemComponent? item)) { @@ -49,7 +49,7 @@ namespace Content.Server.Hands.Components } } - protected override void HandlePickupAnimation(IEntity entity) + protected override void HandlePickupAnimation(EntityUid entity) { var initialPosition = EntityCoordinates.FromMap(IoCManager.Resolve().GetComponent(Owner).Parent?.Owner ?? Owner, IoCManager.Resolve().GetComponent(entity).MapPosition); diff --git a/Content.Server/Hands/Systems/HandVirtualItemSystem.cs b/Content.Server/Hands/Systems/HandVirtualItemSystem.cs index 80fe3c2274..8a56d897f5 100644 --- a/Content.Server/Hands/Systems/HandVirtualItemSystem.cs +++ b/Content.Server/Hands/Systems/HandVirtualItemSystem.cs @@ -1,11 +1,9 @@ using Content.Server.Hands.Components; -using Content.Server.Pulling; using Content.Shared.Hands; using Content.Shared.Hands.Components; using Content.Shared.Interaction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Server.Hands.Systems { @@ -32,9 +30,9 @@ namespace Content.Server.Hands.Systems if (!hand.IsEmpty) continue; - var pos = IoCManager.Resolve().GetComponent(hands.Owner).Coordinates; + var pos = EntityManager.GetComponent(hands.Owner).Coordinates; var virtualItem = EntityManager.SpawnEntity("HandVirtualItem", pos); - var virtualItemComp = IoCManager.Resolve().GetComponent(virtualItem); + var virtualItemComp = EntityManager.GetComponent(virtualItem); virtualItemComp.BlockingEntity = blockingEnt; hands.PutEntityIntoHand(hand, virtualItem); return true; @@ -74,7 +72,7 @@ namespace Content.Server.Hands.Systems var targEv = new VirtualItemDeletedEvent(comp.BlockingEntity, user); RaiseLocalEvent(comp.BlockingEntity, targEv, false); - IoCManager.Resolve().QueueDeleteEntity((EntityUid) comp.Owner); + EntityManager.QueueDeleteEntity(comp.Owner); } /// @@ -83,23 +81,22 @@ namespace Content.Server.Hands.Systems /// public void DeleteInHandsMatching(EntityUid user, EntityUid matching) { - if (EntityManager.TryGetComponent(user, out var hands)) - { - foreach (var handName in hands.ActivePriorityEnumerable()) - { - var hand = hands.GetHand(handName); - if (hand.IsEmpty) - continue; + if (!EntityManager.TryGetComponent(user, out var hands)) + return; - if (hand.HeldEntity != null) - { - if (EntityManager.TryGetComponent(hand.HeldEntity, - out var virt) - && virt.BlockingEntity == matching) - { - Delete(virt, user); - } - } + foreach (var handName in hands.ActivePriorityEnumerable()) + { + var hand = hands.GetHand(handName); + if (hand.IsEmpty) + continue; + + if (hand.HeldEntity == default) + continue; + + if (EntityManager.TryGetComponent(hand.HeldEntity, out var virt) + && virt.BlockingEntity == matching) + { + Delete(virt, user); } } } diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index e668ee5d14..c9060bd148 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -14,10 +14,8 @@ using Content.Shared.Hands; using Content.Shared.Hands.Components; using Content.Shared.Input; using Content.Shared.Physics.Pull; -using Content.Shared.Popups; using JetBrains.Annotations; using Robust.Server.Player; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Input.Binding; using Robust.Shared.IoC; @@ -84,12 +82,12 @@ namespace Content.Server.Hands.Systems // and clear it. foreach (var hand in component.Hands) { - if (hand.HeldEntity == null - || !IoCManager.Resolve().TryGetComponent(hand.HeldEntity, out HandVirtualItemComponent? virtualItem) + if (hand.HeldEntity == default + || !EntityManager.TryGetComponent(hand.HeldEntity, out HandVirtualItemComponent? virtualItem) || virtualItem.BlockingEntity != args.Pulled.Owner) continue; - IoCManager.Resolve().DeleteEntity((EntityUid) hand.HeldEntity); + EntityManager.DeleteEntity(hand.HeldEntity); break; } } @@ -98,10 +96,10 @@ namespace Content.Server.Hands.Systems { var player = session?.AttachedEntity; - if (player == null) + if (!player.HasValue || !player.Value.IsValid()) return; - if (!IoCManager.Resolve().TryGetComponent(player, out SharedHandsComponent? hands)) + if (!EntityManager.TryGetComponent(player.Value, out SharedHandsComponent? hands)) return; if (!hands.TryGetSwapHandsResult(out var nextHand)) @@ -114,10 +112,10 @@ namespace Content.Server.Hands.Systems { var player = session?.AttachedEntity; - if (player == null) + if (player == default) return false; - if (!IoCManager.Resolve().TryGetComponent(player, out SharedHandsComponent? hands)) + if (!EntityManager.TryGetComponent(player.Value, out SharedHandsComponent? hands)) return false; var activeHand = hands.ActiveHand; @@ -173,14 +171,14 @@ namespace Content.Server.Hands.Systems { foreach (var inhand in component.GetAllHeldItems()) { - if (IoCManager.Resolve().HasComponent(inhand.Owner)) + if (EntityManager.HasComponent(inhand.Owner)) continue; args.PushText(Loc.GetString("comp-hands-examine", ("user", component.Owner), ("item", inhand.Owner))); } } - private static bool TryGetHandsComp( + private bool TryGetHandsComp( ICommonSession? session, [NotNullWhen(true)] out SharedHandsComponent? hands) { @@ -191,10 +189,10 @@ namespace Content.Server.Hands.Systems var playerEnt = playerSession.AttachedEntity; - if (playerEnt == null || !IoCManager.Resolve().EntityExists(playerEnt)) + if (playerEnt == default || !EntityManager.EntityExists(playerEnt)) return false; - return IoCManager.Resolve().TryGetComponent(playerEnt, out hands); + return EntityManager.TryGetComponent(playerEnt, out hands); } private void HandleActivateItem(ICommonSession? session) @@ -220,27 +218,27 @@ namespace Content.Server.Hands.Systems var playerEnt = playerSession.AttachedEntity; - if (playerEnt == null || - !IoCManager.Resolve().EntityExists(playerEnt) || + if (playerEnt == default || + !EntityManager.EntityExists(playerEnt) || playerEnt.IsInContainer() || - !IoCManager.Resolve().TryGetComponent(playerEnt, out SharedHandsComponent? hands) || + !EntityManager.TryGetComponent(playerEnt, out SharedHandsComponent? hands) || !hands.TryGetActiveHeldEntity(out var throwEnt) || !_actionBlockerSystem.CanThrow(playerEnt)) return false; - if (IoCManager.Resolve().TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually) + if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually) { - var splitStack = _stackSystem.Split(throwEnt, 1, IoCManager.Resolve().GetComponent(playerEnt).Coordinates, stack); + var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent(playerEnt).Coordinates, stack); - if (splitStack == null) + if (!splitStack.Valid) return false; - throwEnt = EntityManager.GetEntity(splitStack.Value); + throwEnt = splitStack; } else if (!hands.Drop(throwEnt)) return false; - var direction = coords.ToMapPos(EntityManager) - IoCManager.Resolve().GetComponent(playerEnt).WorldPosition; + var direction = coords.ToMapPos(EntityManager) - EntityManager.GetComponent(playerEnt).WorldPosition; if (direction == Vector2.Zero) return true; @@ -269,15 +267,15 @@ namespace Content.Server.Hands.Systems var plyEnt = playerSession.AttachedEntity; - if (plyEnt == null || !IoCManager.Resolve().EntityExists(plyEnt)) + if (plyEnt == default || !EntityManager.EntityExists(plyEnt)) return; - if (!IoCManager.Resolve().TryGetComponent(plyEnt, out SharedHandsComponent? hands) || - !IoCManager.Resolve().TryGetComponent(plyEnt, out InventoryComponent? inventory)) + if (!EntityManager.TryGetComponent(plyEnt, out SharedHandsComponent? hands) || + !EntityManager.TryGetComponent(plyEnt, out InventoryComponent? inventory)) return; if (!inventory.TryGetSlotItem(equipmentSlot, out ItemComponent? equipmentItem) || - !IoCManager.Resolve().TryGetComponent(equipmentItem.Owner, out ServerStorageComponent? storageComponent)) + !EntityManager.TryGetComponent(equipmentItem.Owner, out ServerStorageComponent? storageComponent)) { plyEnt.PopupMessage(Loc.GetString("hands-system-missing-equipment-slot", ("slotName", SlotNames[equipmentSlot].ToLower()))); return; @@ -299,7 +297,7 @@ namespace Content.Server.Hands.Systems if (storageComponent.Remove(lastStoredEntity)) { if (!hands.TryPickupEntityToActiveHand(lastStoredEntity)) - IoCManager.Resolve().GetComponent(lastStoredEntity).Coordinates = IoCManager.Resolve().GetComponent(plyEnt).Coordinates; + EntityManager.GetComponent(lastStoredEntity).Coordinates = EntityManager.GetComponent(plyEnt).Coordinates; } } } diff --git a/Content.Server/Headset/HeadsetComponent.cs b/Content.Server/Headset/HeadsetComponent.cs index 1ed527dd59..fb459a490d 100644 --- a/Content.Server/Headset/HeadsetComponent.cs +++ b/Content.Server/Headset/HeadsetComponent.cs @@ -50,12 +50,12 @@ namespace Content.Server.Headset _radioSystem = EntitySystem.Get(); } - public bool CanListen(string message, IEntity source) + public bool CanListen(string message, EntityUidsource) { return RadioRequested; } - public void Receive(string message, int channel, IEntity source) + public void Receive(string message, int channel, EntityUidsource) { if (Owner.TryGetContainer(out var container)) { @@ -74,12 +74,12 @@ namespace Content.Server.Headset } } - public void Listen(string message, IEntity speaker) + public void Listen(string message, EntityUidspeaker) { Broadcast(message, speaker); } - public void Broadcast(string message, IEntity speaker) + public void Broadcast(string message, EntityUidspeaker) { _radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency); RadioRequested = false; diff --git a/Content.Server/Interaction/Components/ClumsyComponent.cs b/Content.Server/Interaction/Components/ClumsyComponent.cs index 194939d74f..6fbff2c75f 100644 --- a/Content.Server/Interaction/Components/ClumsyComponent.cs +++ b/Content.Server/Interaction/Components/ClumsyComponent.cs @@ -2,7 +2,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; - namespace Content.Server.Interaction.Components { /// @@ -28,7 +27,7 @@ namespace Content.Server.Interaction.Components /// The chance that a "bad action" happens if the user is clumsy, between 0 and 1 inclusive. /// /// True if a "bad action" happened, false if the normal action should happen. - public static bool TryRollClumsy(IEntity entity, float chance) + public static bool TryRollClumsy(EntityUid entity, float chance) { return IoCManager.Resolve().TryGetComponent(entity, out ClumsyComponent? clumsy) && clumsy.RollClumsy(chance); diff --git a/Content.Server/Interaction/InteractionSystem.cs b/Content.Server/Interaction/InteractionSystem.cs index c8b58237a2..cf93a10061 100644 --- a/Content.Server/Interaction/InteractionSystem.cs +++ b/Content.Server/Interaction/InteractionSystem.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -10,7 +9,6 @@ using Content.Server.Items; using Content.Server.Pulling; using Content.Server.Storage.Components; using Content.Shared.ActionBlocker; -using Content.Shared.Administration.Logs; using Content.Shared.Database; using Content.Shared.DragDrop; using Content.Shared.Input; @@ -72,7 +70,7 @@ namespace Content.Server.Interaction } #region Client Input Validation - private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out IEntity? userEntity) + private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out EntityUid userEntity) { userEntity = null; @@ -103,7 +101,7 @@ namespace Content.Server.Interaction public override bool CanAccessViaStorage(EntityUid user, EntityUid target) { - if (!EntityManager.TryGetEntity(target, out var entity)) + if (!EntityManager.EntityExists(target) return false; if (!entity.TryGetContainer(out var container)) @@ -129,7 +127,7 @@ namespace Content.Server.Interaction /// private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, EntitySessionEventArgs args) { - if (!EntityManager.TryGetEntity(msg.ItemUid, out var item)) + if (!EntityManager.EntityExists(msg.ItemUid) { Logger.WarningS("system.interaction", $"Client sent inventory interaction with an invalid target item. Session={args.SenderSession}"); @@ -163,9 +161,9 @@ namespace Content.Server.Interaction if (!_actionBlockerSystem.CanInteract(userEntity)) return; - if (!EntityManager.TryGetEntity(msg.Dropped, out var dropped)) + if (!EntityManager.EntityExists(msg.Dropped) return; - if (!EntityManager.TryGetEntity(msg.Target, out var target)) + if (!EntityManager.EntityExists(msg.Target) return; var interactionArgs = new DragDropEvent(userEntity, msg.DropLocation, dropped, target); @@ -208,7 +206,7 @@ namespace Content.Server.Interaction return false; } - if (!EntityManager.TryGetEntity(uid, out var used)) + if (!EntityManager.EntityExists(uid) return false; InteractionActivate(user, used); @@ -238,7 +236,7 @@ namespace Content.Server.Interaction /// /// /// - internal void AiUseInteraction(IEntity entity, EntityCoordinates coords, EntityUid uid) + internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid) { if (IoCManager.Resolve().HasComponent(entity)) throw new InvalidOperationException(); @@ -285,7 +283,7 @@ namespace Content.Server.Interaction if (userEntity == uid) return false; - if (!EntityManager.TryGetEntity(uid, out var pulledObject)) + if (!EntityManager.EntityExists(uid) return false; if (!InRangeUnobstructed(userEntity, pulledObject, popup: true)) @@ -306,7 +304,7 @@ namespace Content.Server.Interaction /// Whether to use default or alternative interactions (usually as a result of /// alt+clicking). If combat mode is enabled, the alternative action is to perform the default non-combat /// interaction. Having an item in the active hand also disables alternative interactions. - public async void UserInteraction(IEntity user, EntityCoordinates coordinates, EntityUid clickedUid, bool altInteract = false) + public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid clickedUid, bool altInteract = false) { // TODO COMBAT Consider using alt-interact for advanced combat? maybe alt-interact disarms? if (!altInteract && IoCManager.Resolve().TryGetComponent(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode) @@ -322,7 +320,7 @@ namespace Content.Server.Interaction return; // Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null - EntityManager.TryGetEntity(clickedUid, out var target); + EntityManager.EntityExists(clickedUid); // Check if interacted entity is in the same container, the direct child, or direct parent of the user. // This is bypassed IF the interaction happened through an item slot (e.g., backpack UI) @@ -371,7 +369,7 @@ namespace Content.Server.Interaction } } - private bool ValidateInteractAndFace(IEntity user, EntityCoordinates coordinates) + private bool ValidateInteractAndFace(EntityUid user, EntityCoordinates coordinates) { // Verify user is on the same map as the entity they clicked on if (coordinates.GetMapId(_entityManager) != IoCManager.Resolve().GetComponent(user).MapID) @@ -391,7 +389,7 @@ namespace Content.Server.Interaction /// Finds components with the InteractHand interface and calls their function /// NOTE: Does not have an InRangeUnobstructed check /// - public void InteractHand(IEntity user, IEntity target) + public void InteractHand(EntityUid user, EntityUid target) { if (!_actionBlockerSystem.CanInteract(user)) return; @@ -423,7 +421,7 @@ namespace Content.Server.Interaction /// Will have two behaviors, either "uses" the used entity at range on the target entity if it is capable of accepting that action /// Or it will use the used entity itself on the position clicked, regardless of what was there /// - public async Task InteractUsingRanged(IEntity user, IEntity used, IEntity? target, EntityCoordinates clickLocation, bool inRangeUnobstructed) + public async Task InteractUsingRanged(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation, bool inRangeUnobstructed) { if (InteractDoBefore(user, used, inRangeUnobstructed ? target : null, clickLocation, false)) return true; @@ -452,7 +450,7 @@ namespace Content.Server.Interaction return await InteractDoAfter(user, used, inRangeUnobstructed ? target : null, clickLocation, false); } - public void DoAttack(IEntity user, EntityCoordinates coordinates, bool wideAttack, EntityUid targetUid = default) + public void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid targetUid = default) { if (!ValidateInteractAndFace(user, coordinates)) return; @@ -460,12 +458,12 @@ namespace Content.Server.Interaction if (!_actionBlockerSystem.CanAttack(user)) return; - IEntity? targetEnt = null; + EntityUid targetEnt = null; if (!wideAttack) { // Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null - EntityManager.TryGetEntity(targetUid, out targetEnt); + EntityManager.EntityExists(targetUid); // Check if interacted entity is in the same container, the direct child, or direct parent of the user. if (targetEnt != null && !user.IsInSameOrParentContainer(targetEnt) && !CanAccessViaStorage(user, targetEnt)) @@ -521,7 +519,7 @@ namespace Content.Server.Interaction } } else if (!wideAttack && - (targetEnt != null || EntityManager.TryGetEntity(targetUid, out targetEnt)) && + (targetEnt != null || EntityManager.EntityExists(targetUid) && IoCManager.Resolve().HasComponent(targetEnt)) { // We pick up items if our hand is empty, even if we're in combat mode. diff --git a/Content.Server/Inventory/Components/HumanInventoryControllerComponent.cs b/Content.Server/Inventory/Components/HumanInventoryControllerComponent.cs index cb8e756e26..6fc56584b2 100644 --- a/Content.Server/Inventory/Components/HumanInventoryControllerComponent.cs +++ b/Content.Server/Inventory/Components/HumanInventoryControllerComponent.cs @@ -1,7 +1,6 @@ using System.Diagnostics.CodeAnalysis; using Content.Server.Items; using Content.Shared.Item; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -25,7 +24,7 @@ namespace Content.Server.Inventory.Components _inventory = Owner.EnsureComponent(); } - bool IInventoryController.CanEquip(Slots slot, IEntity entity, bool flagsCheck, [NotNullWhen(false)] out string? reason) + bool IInventoryController.CanEquip(Slots slot, EntityUid entity, bool flagsCheck, [NotNullWhen(false)] out string? reason) { var slotMask = SlotMasks[slot]; reason = null; diff --git a/Content.Server/Inventory/Components/IInventoryController.cs b/Content.Server/Inventory/Components/IInventoryController.cs index bd980e3b4f..b55db7da67 100644 --- a/Content.Server/Inventory/Components/IInventoryController.cs +++ b/Content.Server/Inventory/Components/IInventoryController.cs @@ -17,12 +17,12 @@ namespace Content.Server.Inventory.Components /// Whether the entity passes default slot masks & flags checks. /// The translated reason why the item cannot be equiped, if this function returns false. Can be null. /// True if the entity can be equipped, false otherwise - bool CanEquip(Slots slot, IEntity entity, bool flagsCheck, [NotNullWhen(false)] out string? reason) + bool CanEquip(Slots slot, EntityUid entity, bool flagsCheck, [NotNullWhen(false)] out string? reason) { reason = null; return flagsCheck; } - bool CanEquip(Slots slot, IEntity entity, bool flagsCheck) => CanEquip(slot, entity, flagsCheck, out _); + bool CanEquip(Slots slot, EntityUid entity, bool flagsCheck) => CanEquip(slot, entity, flagsCheck, out _); } } diff --git a/Content.Server/Inventory/Components/InventoryComponent.cs b/Content.Server/Inventory/Components/InventoryComponent.cs index bd66b4281b..993b563ff6 100644 --- a/Content.Server/Inventory/Components/InventoryComponent.cs +++ b/Content.Server/Inventory/Components/InventoryComponent.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Content.Server.Administration.Commands; using Content.Server.Clothing.Components; using Content.Server.Hands.Components; using Content.Server.Interaction; @@ -11,15 +10,9 @@ using Content.Server.Storage.Components; using Content.Shared.ActionBlocker; using Content.Shared.Acts; using Content.Shared.Inventory; -using Content.Shared.Movement.Components; using Content.Shared.Movement.EntitySystems; using Content.Shared.Popups; -using Content.Shared.Verbs; -using Robust.Server.Console; -using Robust.Server.GameObjects; -using Robust.Server.Player; using Robust.Shared.Audio; -using Robust.Shared.Console; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -69,7 +62,7 @@ namespace Content.Server.Inventory.Components { if (TryGetSlotItem(slot, out ItemComponent? item)) { - IoCManager.Resolve().DeleteEntity((EntityUid) item.Owner); + IoCManager.Resolve().DeleteEntity(item.Owner); } RemoveSlot(slot); @@ -78,7 +71,7 @@ namespace Content.Server.Inventory.Components base.OnRemove(); } - public IEnumerable GetAllHeldItems() + public IEnumerable GetAllHeldItems() { foreach (var (_, container) in _slotContainers) { @@ -192,7 +185,7 @@ namespace Content.Server.Inventory.Components public bool Equip(Slots slot, ItemComponent item, bool mobCheck = true) => Equip(slot, item, mobCheck, out var _); - public bool Equip(Slots slot, IEntity entity, bool mobCheck = true) => + public bool Equip(Slots slot, EntityUid entity, bool mobCheck = true) => Equip(slot, IoCManager.Resolve().GetComponent(entity), mobCheck); /// @@ -250,7 +243,7 @@ namespace Content.Server.Inventory.Components public bool CanEquip(Slots slot, ItemComponent item, bool mobCheck = true) => CanEquip(slot, item, mobCheck, out var _); - public bool CanEquip(Slots slot, IEntity entity, bool mobCheck = true) => + public bool CanEquip(Slots slot, EntityUid entity, bool mobCheck = true) => CanEquip(slot, IoCManager.Resolve().GetComponent(entity), mobCheck); /// @@ -403,7 +396,7 @@ namespace Content.Server.Inventory.Components /// The underlying Container System just notified us that an entity was removed from it. /// We need to make sure we process that removed entity as being unequipped from the slot. /// - public void ForceUnequip(IContainer container, IEntity entity) + public void ForceUnequip(IContainer container, EntityUid entity) { // make sure this is one of our containers. // Technically the correct way would be to enumerate the possible slot names @@ -554,7 +547,7 @@ namespace Content.Server.Inventory.Components } } - public override bool IsEquipped(IEntity item) + public override bool IsEquipped(EntityUid item) { if (item == null) return false; foreach (var containerSlot in _slotContainers.Values) diff --git a/Content.Server/Inventory/InventoryHelpers.cs b/Content.Server/Inventory/InventoryHelpers.cs index 45ae29fe90..59a4472df7 100644 --- a/Content.Server/Inventory/InventoryHelpers.cs +++ b/Content.Server/Inventory/InventoryHelpers.cs @@ -33,7 +33,7 @@ namespace Content.Server.Inventory // Helper method that deletes the item and returns false. bool DeleteItem() { - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); return false; } diff --git a/Content.Server/Jobs/AddComponentSpecial.cs b/Content.Server/Jobs/AddComponentSpecial.cs index a7d9f0eeb7..4bf1c87c3d 100644 --- a/Content.Server/Jobs/AddComponentSpecial.cs +++ b/Content.Server/Jobs/AddComponentSpecial.cs @@ -1,4 +1,3 @@ -using Content.Server.Interaction.Components; using Content.Shared.Roles; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -14,7 +13,7 @@ namespace Content.Server.Jobs [DataField("component", required:true)] public string Component { get; } = string.Empty; - public override void AfterEquip(IEntity mob) + public override void AfterEquip(EntityUidmob) { // Yes, this will throw if your component is invalid. var component = (Component)IoCManager.Resolve().GetComponent(Component); diff --git a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs index 87b06697a0..2233e6952e 100644 --- a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs +++ b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs @@ -1,6 +1,5 @@ using Content.Server.Hands.Components; using Content.Server.Holiday; -using Content.Server.Holiday.Interfaces; using Content.Server.Items; using Content.Shared.Roles; using JetBrains.Annotations; @@ -22,7 +21,7 @@ namespace Content.Server.Jobs [DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer))] public string Prototype { get; } = string.Empty; - public override void AfterEquip(IEntity mob) + public override void AfterEquip(EntityUidmob) { if (string.IsNullOrEmpty(Holiday) || string.IsNullOrEmpty(Prototype)) return; diff --git a/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs b/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs index aa5f7116da..f7bc1c25c6 100644 --- a/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs +++ b/Content.Server/Kitchen/Components/KitchenSpikeComponent.cs @@ -73,7 +73,7 @@ namespace Content.Server.Kitchen.Components } } - private bool Spikeable(IEntity user, IEntity victim, [NotNullWhen(true)] out SharedButcherableComponent? butcherable) + private bool Spikeable(EntityUid user, EntityUid victim, [NotNullWhen(true)] out SharedButcherableComponent? butcherable) { butcherable = null; @@ -95,7 +95,7 @@ namespace Content.Server.Kitchen.Components return true; } - public async void TrySpike(IEntity victim, IEntity user) + public async void TrySpike(EntityUid victim, EntityUiduser) { var victimUid = (EntityUid) victim; if (_beingButchered.Contains(victimUid)) return; @@ -159,7 +159,7 @@ namespace Content.Server.Kitchen.Components SoundSystem.Play(Filter.Pvs(Owner), SpikeSound.GetSound(), Owner); } - SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat) + SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { var othersMessage = Loc.GetString("comp-kitchen-spike-suicide-other", ("victim", victim)); victim.PopupMessageOtherClients(othersMessage); diff --git a/Content.Server/Kitchen/Components/MicrowaveComponent.cs b/Content.Server/Kitchen/Components/MicrowaveComponent.cs index 8aed651bbd..d638618367 100644 --- a/Content.Server/Kitchen/Components/MicrowaveComponent.cs +++ b/Content.Server/Kitchen/Components/MicrowaveComponent.cs @@ -14,7 +14,6 @@ using Content.Shared.Acts; using Content.Shared.Body.Components; using Content.Shared.Body.Part; using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Kitchen; @@ -29,7 +28,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Player; -using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -189,7 +187,7 @@ namespace Content.Server.Kitchen.Components UserInterface?.SetState(new MicrowaveUpdateUserInterfaceState ( solution.Contents.ToArray(), - _storage.ContainedEntities.Select(item => (EntityUid) item).ToArray(), + _storage.ContainedEntities.Select(item => item).ToArray(), _busy, _currentCookTimeButtonIndex, _currentCookTimerTime @@ -411,7 +409,7 @@ namespace Content.Server.Kitchen.Components { var item = _storage.ContainedEntities.ElementAt(i); _storage.Remove(item); - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); } } @@ -433,7 +431,7 @@ namespace Content.Server.Kitchen.Components private void SubtractContents(FoodRecipePrototype recipe) { - var solutionUid = (EntityUid) Owner; + var solutionUid = Owner; if (!EntitySystem.Get().TryGetSolution(Owner, SolutionName, out var solution)) { return; @@ -459,7 +457,7 @@ namespace Content.Server.Kitchen.Components if (IoCManager.Resolve().GetComponent(item).EntityPrototype.ID == recipeSolid.Key) { _storage.Remove(item); - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); break; } } @@ -469,7 +467,7 @@ namespace Content.Server.Kitchen.Components private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary solids) { - if (_currentCookTimerTime != (uint) recipe.CookTime) + if (_currentCookTimerTime != recipe.CookTime) { return MicrowaveSuccessState.RecipeFail; } @@ -513,7 +511,7 @@ namespace Content.Server.Kitchen.Components SoundSystem.Play(Filter.Pvs(Owner), _clickSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2f)); } - SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat) + SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { var headCount = 0; diff --git a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs index 4971e168b5..9f3c1153e9 100644 --- a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Content.Server.Chemistry.EntitySystems; using Content.Server.Hands.Components; @@ -22,7 +21,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Player; -using Robust.Shared.Utility; namespace Content.Server.Kitchen.EntitySystems { @@ -62,7 +60,7 @@ namespace Content.Server.Kitchen.EntitySystems return; } - IEntity heldEnt = args.Used; + EntityUidheldEnt = args.Used; // First, check if user is trying to insert a beaker. // No promise it will be a beaker right now, but whatever. @@ -196,7 +194,7 @@ namespace Content.Server.Kitchen.EntitySystems if (component.Chamber.ContainedEntities.TryFirstOrDefault(x => x == msg.EntityID, out var ent)) { component.Chamber.Remove(ent); - ent.RandomOffset(0.4f); + SharedEntityExtensions.RandomOffset(ent, 0.4f); EnqueueUiUpdate(component); ClickSound(component); } @@ -242,7 +240,7 @@ namespace Content.Server.Kitchen.EntitySystems IoCManager.Resolve().TryGetComponent(comp.Owner, out ApcPowerReceiverComponent? receiver) && receiver.Powered, canJuice, canGrind, - comp.Chamber.ContainedEntities.Select(item => (EntityUid) item).ToArray(), + comp.Chamber.ContainedEntities.Select(item => item).ToArray(), //Remember the beaker can be null! comp.HeldBeaker?.Contents.ToArray() )); @@ -253,7 +251,7 @@ namespace Content.Server.Kitchen.EntitySystems /// Tries to eject whatever is in the beaker slot. Puts the item in the user's hands or failing that on top /// of the grinder. /// - private void EjectBeaker(ReagentGrinderComponent component, IEntity? user) + private void EjectBeaker(ReagentGrinderComponent component, EntityUid user) { if (component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null || component.Busy) return; @@ -282,7 +280,7 @@ namespace Content.Server.Kitchen.EntitySystems /// The wzhzhzh of the grinder. Processes the contents of the grinder and puts the output in the beaker. /// /// true for wanting to juice, false for wanting to grind. - private void DoWork(ReagentGrinderComponent component, IEntity user, + private void DoWork(ReagentGrinderComponent component, EntityUid user, SharedReagentGrinderComponent.GrinderProgram program) { //Have power, are we busy, chamber has anything to grind, a beaker for the grounds to go? @@ -304,7 +302,7 @@ namespace Content.Server.Kitchen.EntitySystems SoundSystem.Play(Filter.Pvs(component.Owner), component.GrindSound.GetSound(), component.Owner, AudioParams.Default); // Get each item inside the chamber and get the reagents it contains. // Transfer those reagents to the beaker, given we have one in. - component.Owner.SpawnTimer(component.WorkTime, (Action) (() => + component.Owner.SpawnTimer(component.WorkTime, () => { foreach (var item in component.Chamber.ContainedEntities.ToList()) { @@ -319,18 +317,18 @@ namespace Content.Server.Kitchen.EntitySystems solution.ScaleSolution(juiceEvent.Scalar); _solutionsSystem.TryAddSolution(beakerEntity, component.HeldBeaker, solution); _solutionsSystem.RemoveAllSolution(beakerEntity, solution); - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); } component.Busy = false; EnqueueUiUpdate(component); bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage()); - })); + }); break; case SharedReagentGrinderComponent.GrinderProgram.Juice: SoundSystem.Play(Filter.Pvs(component.Owner), component.JuiceSound.GetSound(), component.Owner, AudioParams.Default); - component.Owner.SpawnTimer(component.WorkTime, (Action) (() => + component.Owner.SpawnTimer(component.WorkTime, () => { foreach (var item in component.Chamber.ContainedEntities.ToList()) { @@ -351,13 +349,13 @@ namespace Content.Server.Kitchen.EntitySystems component.HeldBeaker.MaxVolume) continue; juiceMe.JuiceSolution.ScaleSolution(juiceEvent.Scalar); _solutionsSystem.TryAddSolution(beakerEntity, component.HeldBeaker, juiceMe.JuiceSolution); - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); } bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage()); component.Busy = false; EnqueueUiUpdate(component); - })); + }); break; } } diff --git a/Content.Server/Labels/Label/HandLabelerSystem.cs b/Content.Server/Labels/Label/HandLabelerSystem.cs index 18815e4696..d5e9ac8a65 100644 --- a/Content.Server/Labels/Label/HandLabelerSystem.cs +++ b/Content.Server/Labels/Label/HandLabelerSystem.cs @@ -1,16 +1,16 @@ +using System; using Content.Server.Labels.Components; using Content.Server.UserInterface; using Content.Shared.ActionBlocker; -using Content.Shared.Labels; using Content.Shared.Interaction; +using Content.Shared.Labels; +using Content.Shared.Popups; +using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Players; using Robust.Shared.IoC; -using JetBrains.Annotations; using Robust.Shared.Localization; -using Content.Shared.Popups; -using System; +using Robust.Shared.Players; namespace Content.Server.Labels { @@ -42,7 +42,7 @@ namespace Content.Server.Labels handLabeler.Owner.PopupMessage(args.User, result); } - private void AddLabelTo(EntityUid uid, HandLabelerComponent? handLabeler, IEntity target, out string? result) + private void AddLabelTo(EntityUid uid, HandLabelerComponent? handLabeler, EntityUid target, out string? result) { if (!Resolve(uid, ref handLabeler)) { @@ -81,7 +81,7 @@ namespace Content.Server.Labels private bool CheckInteract(ICommonSession session) { - if (session.AttachedEntityUid is not { } uid + if (session.AttachedEntity is not { } uid || !Get().CanInteract(uid) || !Get().CanUse(uid)) return false; diff --git a/Content.Server/Lathe/Components/LatheComponent.cs b/Content.Server/Lathe/Components/LatheComponent.cs index 72e7941549..75b4edb4a6 100644 --- a/Content.Server/Lathe/Components/LatheComponent.cs +++ b/Content.Server/Lathe/Components/LatheComponent.cs @@ -202,7 +202,7 @@ namespace Content.Server.Lathe.Components SetAppearance(LatheVisualState.Idle); }); - IoCManager.Resolve().DeleteEntity((EntityUid) eventArgs.Using); + IoCManager.Resolve().DeleteEntity(eventArgs.Using); return true; } diff --git a/Content.Server/Light/Components/HandheldLightComponent.cs b/Content.Server/Light/Components/HandheldLightComponent.cs index 6e87fbbde8..e46b95da19 100644 --- a/Content.Server/Light/Components/HandheldLightComponent.cs +++ b/Content.Server/Light/Components/HandheldLightComponent.cs @@ -12,7 +12,6 @@ using Content.Shared.Light.Component; using Content.Shared.Popups; using Content.Shared.Rounding; using Content.Shared.Sound; -using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.Audio; @@ -21,7 +20,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -104,7 +102,7 @@ namespace Content.Server.Light.Components /// Illuminates the light if it is not active, extinguishes it if it is active. /// /// True if the light's status was toggled, false otherwise. - public bool ToggleStatus(IEntity user) + public bool ToggleStatus(EntityUiduser) { if (!EntitySystem.Get().CanUse(user)) return false; return Activated ? TurnOff() : TurnOn(user); @@ -130,7 +128,7 @@ namespace Content.Server.Light.Components return true; } - public bool TurnOn(IEntity user) + public bool TurnOn(EntityUiduser) { if (Activated) { diff --git a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs index 7bbf0b7969..48f59c9c47 100644 --- a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs +++ b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs @@ -1,8 +1,8 @@ +using System.Linq; using Content.Server.Light.Components; using Content.Server.Storage.Components; using Content.Shared.ActionBlocker; using Content.Shared.Interaction; -using Content.Shared.Interaction.Events; using Content.Shared.Light; using Content.Shared.Popups; using JetBrains.Annotations; @@ -12,8 +12,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Player; -using System; -using System.Linq; namespace Content.Server.Light.EntitySystems { @@ -71,7 +69,7 @@ namespace Content.Server.Light.EntitySystems if (eventArgs.Used != null) { - var usedUid = (EntityUid) eventArgs.Used; + var usedUid = eventArgs.Used; // want to insert a new light bulb? if (EntityManager.TryGetComponent(usedUid, out LightBulbComponent ? bulb)) diff --git a/Content.Server/Light/EntitySystems/MatchstickSystem.cs b/Content.Server/Light/EntitySystems/MatchstickSystem.cs index 63b0ac6f50..6b974d14ed 100644 --- a/Content.Server/Light/EntitySystems/MatchstickSystem.cs +++ b/Content.Server/Light/EntitySystems/MatchstickSystem.cs @@ -58,7 +58,7 @@ namespace Content.Server.Light.EntitySystems args.IsHot = component.CurrentState == SmokableState.Lit; } - public void Ignite(MatchstickComponent component, IEntity user) + public void Ignite(MatchstickComponent component, EntityUiduser) { // Play Sound SoundSystem.Play( diff --git a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs index dff18f2986..71bdfb210d 100644 --- a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs +++ b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs @@ -1,30 +1,28 @@ using System; +using Content.Server.Administration.Logs; using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; using Content.Server.Ghost; using Content.Server.Light.Components; using Content.Server.MachineLinking.Events; using Content.Server.Power.Components; -using Content.Server.Power.EntitySystems; -using Content.Shared.Light; +using Content.Server.Temperature.Components; +using Content.Shared.Audio; using Content.Shared.Damage; +using Content.Shared.Database; +using Content.Shared.Hands.Components; +using Content.Shared.Interaction; +using Content.Shared.Light; +using Content.Shared.Popups; using Robust.Server.GameObjects; +using Robust.Shared.Audio; +using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Timing; -using Robust.Shared.Containers; -using Content.Shared.Interaction; -using Content.Shared.Hands.Components; -using Content.Server.Temperature.Components; -using Content.Shared.Popups; using Robust.Shared.Localization; -using Robust.Shared.Audio; -using Robust.Shared.Player; using Robust.Shared.Maths; -using Content.Shared.Audio; -using Content.Server.Administration.Logs; -using Content.Shared.Administration.Logs; -using Content.Shared.Database; +using Robust.Shared.Player; +using Robust.Shared.Timing; namespace Content.Server.Light.EntitySystems { @@ -102,7 +100,7 @@ namespace Content.Server.Light.EntitySystems return; // check if it's possible to apply burn damage to user - var userUid = (EntityUid) args.User; + var userUid = args.User; if (EntityManager.TryGetComponent(userUid, out HeatResistanceComponent? heatResist) && EntityManager.TryGetComponent(bulbUid.Value, out LightBulbComponent? lightBulb)) { @@ -179,7 +177,7 @@ namespace Content.Server.Light.EntitySystems return null; // try to remove bulb from container - var bulbEnt = EntityManager.GetEntity(bulbUid.Value); + var bulbbulbUid.Value if (!light.LightBulbContainer.Remove(bulbEnt)) return null; diff --git a/Content.Server/Lock/LockSystem.cs b/Content.Server/Lock/LockSystem.cs index e995041faf..2a676636eb 100644 --- a/Content.Server/Lock/LockSystem.cs +++ b/Content.Server/Lock/LockSystem.cs @@ -67,7 +67,7 @@ namespace Content.Server.Lock ("entityName", Name: IoCManager.Resolve().GetComponent(lockComp.Owner).EntityName))); } - public bool TryLock(EntityUid uid, IEntity user, LockComponent? lockComp = null) + public bool TryLock(EntityUid uid, EntityUid user, LockComponent? lockComp = null) { if (!Resolve(uid, ref lockComp)) return false; @@ -96,7 +96,7 @@ namespace Content.Server.Lock return true; } - public bool TryUnlock(EntityUid uid, IEntity user, LockComponent? lockComp = null) + public bool TryUnlock(EntityUid uid, EntityUid user, LockComponent? lockComp = null) { if (!Resolve(uid, ref lockComp)) return false; @@ -128,7 +128,7 @@ namespace Content.Server.Lock /// /// Before locking the entity, check whether it's a locker. If is, prevent it from being locked from the inside or while it is open. /// - public bool CanToggleLock(EntityUid uid, IEntity user, EntityStorageComponent? storage = null, bool quiet = true) + public bool CanToggleLock(EntityUid uid, EntityUid user, EntityStorageComponent? storage = null, bool quiet = true) { if (!Resolve(uid, ref storage, logMissing: false)) return true; @@ -144,7 +144,7 @@ namespace Content.Server.Lock return true; } - private bool HasUserAccess(EntityUid uid, IEntity user, AccessReader? reader = null, bool quiet = true) + private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReader? reader = null, bool quiet = true) { // Not having an AccessComponent means you get free access. woo! if (!Resolve(uid, ref reader)) diff --git a/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs b/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs index 0bde20c91e..7adb0122b6 100644 --- a/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs +++ b/Content.Server/MachineLinking/Events/LinkAttemptEvent.cs @@ -5,13 +5,13 @@ namespace Content.Server.MachineLinking.Events { public class LinkAttemptEvent : CancellableEntityEventArgs { - public readonly IEntity Attemptee; + public readonly EntityUid Attemptee, public readonly SignalTransmitterComponent TransmitterComponent; public readonly string TransmitterPort; public readonly SignalReceiverComponent ReceiverComponent; public readonly string ReceiverPort; - public LinkAttemptEvent(IEntity attemptee, SignalTransmitterComponent transmitterComponent, string transmitterPort, SignalReceiverComponent receiverComponent, string receiverPort) + public LinkAttemptEvent(EntityUid attemptee, SignalTransmitterComponent transmitterComponent, string transmitterPort, SignalReceiverComponent receiverComponent, string receiverPort) { TransmitterComponent = transmitterComponent; this.TransmitterPort = transmitterPort; diff --git a/Content.Server/MachineLinking/System/SignalLinkerSystem.cs b/Content.Server/MachineLinking/System/SignalLinkerSystem.cs index 555cce3138..3f3f5bccb3 100644 --- a/Content.Server/MachineLinking/System/SignalLinkerSystem.cs +++ b/Content.Server/MachineLinking/System/SignalLinkerSystem.cs @@ -198,7 +198,7 @@ namespace Content.Server.MachineLinking.System args.Handled = true; } - private void LinkerInteraction(IEntity entity, SignalTransmitterComponent transmitter, string transmitterPort, + private void LinkerInteraction(EntityUid entity, SignalTransmitterComponent transmitter, string transmitterPort, SignalReceiverComponent receiver, string receiverPort) { if (_linkCollection.LinkExists(transmitter, transmitterPort, receiver, receiverPort)) @@ -256,7 +256,7 @@ namespace Content.Server.MachineLinking.System } } - private void LinkerSaveInteraction(IEntity entity, SignalLinkerComponent linkerComponent, + private void LinkerSaveInteraction(EntityUid entity, SignalLinkerComponent linkerComponent, SignalTransmitterComponent transmitterComponent, string transmitterPort) { if (SavePortInSignalLinker(linkerComponent, transmitterComponent, transmitterPort)) diff --git a/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs b/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs index 17ca92f4b1..6a117e05c3 100644 --- a/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs +++ b/Content.Server/MachineLinking/System/TriggerOnSignalReceivedSystem.cs @@ -19,7 +19,7 @@ namespace Content.Server.MachineLinking.System private void OnSignalReceived(EntityUid uid, TriggerOnSignalReceivedComponent component, SignalReceivedEvent args) { - _trigger.Trigger(EntityManager.GetEntity(uid)); + _trigger.Trigger(uid) } } } diff --git a/Content.Server/Medical/Components/MedicalScannerComponent.cs b/Content.Server/Medical/Components/MedicalScannerComponent.cs index 745839be88..861f6098ac 100644 --- a/Content.Server/Medical/Components/MedicalScannerComponent.cs +++ b/Content.Server/Medical/Components/MedicalScannerComponent.cs @@ -18,7 +18,6 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.ViewVariables; @@ -166,7 +165,7 @@ namespace Content.Server.Medical.Components UserInterface?.Open(actor.PlayerSession); } - public void InsertBody(IEntity user) + public void InsertBody(EntityUiduser) { _bodyContainer.Insert(user); UpdateUserInterface(); diff --git a/Content.Server/Mind/Mind.cs b/Content.Server/Mind/Mind.cs index 2091065f1d..4a156cdb62 100644 --- a/Content.Server/Mind/Mind.cs +++ b/Content.Server/Mind/Mind.cs @@ -62,12 +62,12 @@ namespace Content.Server.Mind public NetUserId OriginalOwnerUserId { get; } [ViewVariables] - public bool IsVisitingEntity => VisitingEntity != null; + public bool IsVisitingEntity => VisitingEntity != default; [ViewVariables] - public IEntity? VisitingEntity { get; private set; } + public EntityUid VisitingEntity { get; private set; } - [ViewVariables] public IEntity? CurrentEntity => VisitingEntity ?? OwnedEntity; + [ViewVariables] public EntityUid CurrentEntity => VisitingEntity.IsValid() ? VisitingEntity : OwnedEntity; [ViewVariables(VVAccess.ReadWrite)] public string? CharacterName { get; set; } @@ -90,7 +90,7 @@ namespace Content.Server.Mind /// Can be null. /// [ViewVariables] - public IEntity? OwnedEntity => OwnedComponent?.Owner; + public EntityUid OwnedEntity => OwnedComponent?.Owner ?? default; /// /// An enumerable over all the roles this mind has. @@ -153,7 +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 == null) + if (OwnedEntity == default) return true; var targetMobState = IoCManager.Resolve().GetComponentOrNull(OwnedEntity); // This can be null if it's a brain (this happens very often) @@ -184,8 +184,7 @@ namespace Content.Server.Mind role.Greet(); var message = new RoleAddedEvent(role); - IEntity? tempQualifier = OwnedEntity; - (tempQualifier != null ? IoCManager.Resolve() : null).EventBus.RaiseLocalEvent(OwnedEntity, message); + IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity, message); return role; } @@ -207,8 +206,7 @@ namespace Content.Server.Mind _roles.Remove(role); var message = new RoleRemovedEvent(role); - IEntity? tempQualifier = OwnedEntity; - (tempQualifier != null ? IoCManager.Resolve() : null).EventBus.RaiseLocalEvent(OwnedEntity, message); + IoCManager.Resolve().EventBus.RaiseLocalEvent(OwnedEntity, message); } public bool HasRole() where T : Role @@ -248,7 +246,7 @@ namespace Content.Server.Mind /// /// Transfer this mind's control over to a new entity. /// - /// + /// /// The entity to control. /// Can be null, in which case it will simply detach the mind from any entity. /// @@ -258,31 +256,30 @@ namespace Content.Server.Mind /// /// Thrown if is already owned by another mind. /// - public void TransferTo(EntityUid? entityUid, bool ghostCheckOverride = false) + public void TransferTo(EntityUid entity = default, bool ghostCheckOverride = false) { var entMan = IoCManager.Resolve(); - IEntity? entity = (entityUid != null) ? entMan.GetEntity(entityUid.Value) : null; MindComponent? component = null; var alreadyAttached = false; - if (entityUid != null) + if (entity != default) { - if (!entMan.TryGetComponent(entityUid.Value, out component)) + if (!entMan.TryGetComponent(entity, out component)) { - component = entMan.AddComponent(entityUid.Value); + component = entMan.AddComponent(entity); } else if (component!.HasMind) { EntitySystem.Get().OnGhostAttempt(component.Mind!, false); } - if (entMan.TryGetComponent(entityUid.Value, out var actor)) + if (entMan.TryGetComponent(entity, out var actor)) { // Happens when transferring to your currently visited entity. if (actor.PlayerSession != Session) { - throw new ArgumentException("Visit target already has a session.", nameof(entityUid)); + throw new ArgumentException("Visit target already has a session.", nameof(entity)); } alreadyAttached = true; @@ -296,14 +293,14 @@ namespace Content.Server.Mind if (IsVisitingEntity && (ghostCheckOverride // to force mind transfer, for example from ControlMobVerb - || !IoCManager.Resolve().TryGetComponent(VisitingEntity!, out GhostComponent? ghostComponent) // visiting entity is not a Ghost + || !entMan.TryGetComponent(VisitingEntity!, out GhostComponent? ghostComponent) // visiting entity is not a Ghost || !ghostComponent.CanReturnToBody)) // it is a ghost, but cannot return to body anyway, so it's okay { - VisitingEntity = null; + VisitingEntity = default; } // Player is CURRENTLY connected. - if (Session != null && !alreadyAttached && VisitingEntity == null) + if (Session != null && !alreadyAttached && VisitingEntity == default) { Session.AttachToEntity(entity); Logger.Info($"Session {Session.Name} transferred to entity {entity}."); @@ -352,7 +349,7 @@ namespace Content.Server.Mind newOwnerData.UpdateMindFromMindChangeOwningPlayer(this); } - public void Visit(IEntity entity) + public void Visit(EntityUid entity) { Session?.AttachToEntity(entity); VisitingEntity = entity; @@ -373,16 +370,17 @@ namespace Content.Server.Mind Session?.AttachToEntity(OwnedEntity); var oldVisitingEnt = VisitingEntity; // Null this before removing the component to avoid any infinite loops. - VisitingEntity = null; + VisitingEntity = default; DebugTools.AssertNotNull(oldVisitingEnt); - if (IoCManager.Resolve().HasComponent(oldVisitingEnt!)) + var entities = IoCManager.Resolve(); + if (entities.HasComponent(oldVisitingEnt!)) { - IoCManager.Resolve().RemoveComponent(oldVisitingEnt); + entities.RemoveComponent(oldVisitingEnt); } - IoCManager.Resolve().EventBus.RaiseLocalEvent(oldVisitingEnt, new MindUnvisitedMessage()); + entities.EventBus.RaiseLocalEvent(oldVisitingEnt, new MindUnvisitedMessage()); } public bool TryGetSession([NotNullWhen(true)] out IPlayerSession? session) diff --git a/Content.Server/Morgue/Components/BodyBagEntityStorageComponent.cs b/Content.Server/Morgue/Components/BodyBagEntityStorageComponent.cs index 5d3eaf4e65..fb21adce49 100644 --- a/Content.Server/Morgue/Components/BodyBagEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/BodyBagEntityStorageComponent.cs @@ -1,21 +1,9 @@ -using System.Threading.Tasks; -using Content.Server.Hands.Components; -using Content.Server.Items; -using Content.Server.Paper; using Content.Server.Storage.Components; using Content.Shared.Body.Components; -using Content.Shared.Examine; using Content.Shared.Interaction; -using Content.Shared.Morgue; -using Content.Shared.Popups; using Content.Shared.Standing; -using Robust.Server.GameObjects; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Utility; -using Robust.Shared.ViewVariables; namespace Content.Server.Morgue.Components { @@ -27,9 +15,9 @@ namespace Content.Server.Morgue.Components { public override string Name => "BodyBagEntityStorage"; - protected override bool AddToContents(IEntity entity) + protected override bool AddToContents(EntityUid entity) { - if (IoCManager.Resolve().HasComponent(entity) && !EntitySystem.Get().IsDown((EntityUid) entity)) return false; + if (IoCManager.Resolve().HasComponent(entity) && !EntitySystem.Get().IsDown(entity)) return false; return base.AddToContents(entity); } } diff --git a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs index cc84234915..d386d1ea28 100644 --- a/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/CrematoriumEntityStorageComponent.cs @@ -12,7 +12,6 @@ using Content.Shared.Popups; using Content.Shared.Sound; using Content.Shared.Standing; using Robust.Server.GameObjects; -using Robust.Server.Player; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -69,7 +68,7 @@ namespace Content.Server.Morgue.Components } } - public override bool CanOpen(IEntity user, bool silent = false) + public override bool CanOpen(EntityUid user, bool silent = false) { if (Cooking) { @@ -117,7 +116,7 @@ namespace Content.Server.Morgue.Components { var item = Contents.ContainedEntities[i]; Contents.Remove(item); - IoCManager.Resolve().DeleteEntity((EntityUid) item); + IoCManager.Resolve().DeleteEntity(item); } var ash = IoCManager.Resolve().SpawnEntity("Ash", IoCManager.Resolve().GetComponent(Owner).Coordinates); @@ -131,12 +130,16 @@ namespace Content.Server.Morgue.Components }, _cremateCancelToken.Token); } - SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat) + SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { if (IoCManager.Resolve().TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind) { EntitySystem.Get().OnGhostAttempt(mind, false); - mind.OwnedEntity?.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message")); + + if (mind.OwnedEntity.Valid) + { + mind.OwnedEntity.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message")); + } } victim.PopupMessageOtherClients(Loc.GetString("crematorium-entity-storage-component-suicide-message-others", ("victim", victim))); @@ -144,11 +147,11 @@ namespace Content.Server.Morgue.Components if (CanInsert(victim)) { Insert(victim); - EntitySystem.Get().Down((EntityUid) victim, false); + EntitySystem.Get().Down(victim, false); } else { - IoCManager.Resolve().DeleteEntity((EntityUid) victim); + IoCManager.Resolve().DeleteEntity(victim); } Cremate(); diff --git a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs index 833950ecac..33e5de4c9f 100644 --- a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs @@ -40,7 +40,7 @@ namespace Content.Server.Morgue.Components private string? _trayPrototypeId; [ViewVariables] - private IEntity? _tray; + private EntityUid _tray; [ViewVariables] public ContainerSlot? TrayContainer { get; private set; } @@ -69,14 +69,14 @@ namespace Content.Server.Morgue.Components return base.ContentsDumpPosition(); } - protected override bool AddToContents(IEntity entity) + protected override bool AddToContents(EntityUid entity) { - if (IoCManager.Resolve().HasComponent(entity) && !EntitySystem.Get().IsDown((EntityUid) entity)) + if (IoCManager.Resolve().HasComponent(entity) && !EntitySystem.Get().IsDown(entity)) return false; return base.AddToContents(entity); } - public override bool CanOpen(IEntity user, bool silent = false) + public override bool CanOpen(EntityUid user, bool silent = false) { if (!Owner.InRangeUnobstructed( IoCManager.Resolve().GetComponent(Owner).Coordinates.Offset(IoCManager.Resolve().GetComponent(Owner).LocalRotation.GetCardinalDir()), @@ -145,7 +145,7 @@ namespace Content.Server.Morgue.Components } } - protected override IEnumerable DetermineCollidingEntities() + protected override IEnumerable DetermineCollidingEntities() { if (_tray == null) { diff --git a/Content.Server/Morgue/Components/MorgueTrayComponent.cs b/Content.Server/Morgue/Components/MorgueTrayComponent.cs index 8ba23bbd97..aef91523d4 100644 --- a/Content.Server/Morgue/Components/MorgueTrayComponent.cs +++ b/Content.Server/Morgue/Components/MorgueTrayComponent.cs @@ -12,7 +12,7 @@ namespace Content.Server.Morgue.Components public override string Name => "MorgueTray"; [ViewVariables] - public IEntity? Morgue { get; set; } + public EntityUid Morgue { get; set; } void IActivate.Activate(ActivateEventArgs eventArgs) { diff --git a/Content.Server/NodeContainer/Nodes/Node.cs b/Content.Server/NodeContainer/Nodes/Node.cs index a3d1f7425e..2de408c15c 100644 --- a/Content.Server/NodeContainer/Nodes/Node.cs +++ b/Content.Server/NodeContainer/Nodes/Node.cs @@ -31,7 +31,7 @@ namespace Content.Server.NodeContainer.Nodes /// /// The entity that owns this node via its . /// - [ViewVariables] public IEntity Owner { get; private set; } = default!; + [ViewVariables] public EntityUid Owner { get; private set; } = default!; /// /// If this node should be considered for connection by other nodes. @@ -69,7 +69,7 @@ namespace Content.Server.NodeContainer.Nodes /// Invoked when the owning is initialized. /// /// The owning entity. - public virtual void Initialize(IEntity owner) + public virtual void Initialize(EntityUid owner) { Owner = owner; } diff --git a/Content.Server/Nuke/Commands/ToggleNukeCommand.cs b/Content.Server/Nuke/Commands/ToggleNukeCommand.cs index 64003964d7..94ba74125b 100644 --- a/Content.Server/Nuke/Commands/ToggleNukeCommand.cs +++ b/Content.Server/Nuke/Commands/ToggleNukeCommand.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Server.Administration; using Content.Shared.Administration; using JetBrains.Annotations; @@ -5,7 +6,6 @@ using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using System.Linq; namespace Content.Server.Nuke.Commands { @@ -42,7 +42,7 @@ namespace Content.Server.Nuke.Commands return; } - bombUid = bomb.OwnerUid; + bombUid = bomb.Owner; } var nukeSys = EntitySystem.Get(); diff --git a/Content.Server/Nuke/NukeSystem.cs b/Content.Server/Nuke/NukeSystem.cs index 40e9417e86..bceb21a134 100644 --- a/Content.Server/Nuke/NukeSystem.cs +++ b/Content.Server/Nuke/NukeSystem.cs @@ -1,25 +1,25 @@ +using System.Collections.Generic; +using Content.Server.Chat.Managers; using Content.Server.Construction.Components; +using Content.Server.Coordinates.Helpers; using Content.Server.Popups; using Content.Server.UserInterface; using Content.Shared.ActionBlocker; +using Content.Shared.Audio; using Content.Shared.Body.Components; using Content.Shared.Containers.ItemSlots; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Nuke; -using Content.Server.Chat.Managers; +using Content.Shared.Sound; using Robust.Server.GameObjects; using Robust.Server.Player; +using Robust.Shared.Audio; +using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Player; -using System.Collections.Generic; -using Content.Server.Coordinates.Helpers; -using Content.Shared.Audio; -using Content.Shared.Sound; -using Robust.Shared.Audio; -using Robust.Shared.Containers; namespace Content.Server.Nuke { @@ -166,7 +166,7 @@ namespace Content.Server.Nuke if (!component.DiskSlot.HasItem) return; - _itemSlots.TryEjectToHands(uid, component.DiskSlot, args.Session.AttachedEntityUid); + _itemSlots.TryEjectToHands(uid, component.DiskSlot, args.Session.AttachedEntity); } private async void OnAnchorButtonPressed(EntityUid uid, NukeComponent component, NukeAnchorMessage args) @@ -413,7 +413,7 @@ namespace Content.Server.Nuke var ents = _lookup.GetEntitiesInRange(pos, component.BlastRadius); foreach (var ent in ents) { - var entUid = (EntityUid) ent; + var entUid = ent; if (!EntityManager.EntityExists(entUid)) continue;; diff --git a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs index 384310528e..b6e1066808 100644 --- a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs @@ -1,4 +1,3 @@ -using System.Linq; using Content.Server.Body.Components; using Content.Server.Body.Systems; using Content.Server.Chemistry.Components.SolutionManager; @@ -114,44 +113,44 @@ namespace Content.Server.Nutrition.EntitySystems private void AfterInteract(EntityUid uid, DrinkComponent component, AfterInteractEvent args) { - if (args.Handled || args.TargetUid == null) + if (args.Handled || args.Target == default) return; - if (!_actionBlockerSystem.CanInteract(args.UserUid) || !_actionBlockerSystem.CanUse(args.UserUid)) + if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User)) return; - if (!args.UserUid.InRangeUnobstructed(uid, popup: true)) - { - args.Handled = true; - return; - } - - if (args.UserUid == args.TargetUid) - { - args.Handled = TryUseDrink(uid, args.UserUid); - return; - } - - if (!args.UserUid.InRangeUnobstructed(args.TargetUid.Value, popup: true)) + if (!args.User.InRangeUnobstructed(uid, popup: true)) { args.Handled = true; return; } if (args.User == args.Target) - args.Handled = TryUseDrink(uid, args.UserUid, component); + { + args.Handled = TryUseDrink(uid, args.User); + return; + } + + if (!args.User.InRangeUnobstructed(args.Target.Value, popup: true)) + { + args.Handled = true; + return; + } + + if (args.User == args.Target) + args.Handled = TryUseDrink(uid, args.User, component); else - args.Handled = TryForceDrink(uid, args.UserUid, args.TargetUid.Value, component); + args.Handled = TryForceDrink(uid, args.User, args.Target.Value, component); } private void OnUse(EntityUid uid, DrinkComponent component, UseInHandEvent args) { if (args.Handled) return; - if (!_actionBlockerSystem.CanInteract(args.UserUid) || !_actionBlockerSystem.CanUse(args.UserUid)) + if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User)) return; - if (!args.UserUid.InRangeUnobstructed(uid, popup: true)) + if (!args.User.InRangeUnobstructed(uid, popup: true)) { args.Handled = true; return; @@ -168,11 +167,11 @@ namespace Content.Server.Nutrition.EntitySystems if (_solutionContainerSystem.DrainAvailable(uid) <= 0) { - args.User.PopupMessage(Loc.GetString("drink-component-on-use-is-empty", ("owner", EntityManager.GetEntity(uid)))); + args.User.PopupMessage(Loc.GetString("drink-component-on-use-is-empty", ("owner", uid))); return; } - args.Handled = TryUseDrink(uid, args.UserUid, component); + args.Handled = TryUseDrink(uid, args.User, component); } private void HandleLand(EntityUid uid, DrinkComponent component, LandEvent args) @@ -185,12 +184,10 @@ namespace Content.Server.Nutrition.EntitySystems component.Opened = true; UpdateAppearance(component); - var entity = EntityManager.GetEntity(uid); - var solution = _solutionContainerSystem.Drain(uid, interactions, interactions.DrainAvailable); - solution.SpillAt(entity, "PuddleSmear"); + solution.SpillAt(uid, "PuddleSmear"); - SoundSystem.Play(Filter.Pvs(entity), component.BurstSound.GetSound(), entity, AudioParams.Default.WithVolume(-4)); + SoundSystem.Play(Filter.Pvs(uid), component.BurstSound.GetSound(), uid, AudioParams.Default.WithVolume(-4)); } } @@ -241,7 +238,7 @@ namespace Content.Server.Nutrition.EntitySystems if (!drink.Opened) { _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open", - ("owner", Name: IoCManager.Resolve().GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); + ("owner", Name: EntityManager.GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); return true; } @@ -252,7 +249,7 @@ namespace Content.Server.Nutrition.EntitySystems drinkSolution.DrainAvailable <= 0) { _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty", - ("entity", Name: IoCManager.Resolve().GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); + ("entity", Name: EntityManager.GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); return true; } @@ -324,7 +321,7 @@ namespace Content.Server.Nutrition.EntitySystems if (!drink.Opened) { _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open", - ("owner", Name: IoCManager.Resolve().GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); + ("owner", Name: EntityManager.GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); return true; } @@ -332,7 +329,7 @@ namespace Content.Server.Nutrition.EntitySystems drinkSolution.DrainAvailable <= 0) { _popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty", - ("entity", Name: IoCManager.Resolve().GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); + ("entity", Name: EntityManager.GetComponent(drink.Owner).EntityName)), uid, Filter.Entities(userUid)); return true; } @@ -362,10 +359,7 @@ namespace Content.Server.Nutrition.EntitySystems }); // logging - var user = EntityManager.GetEntity(userUid); - var target = EntityManager.GetEntity(targetUid); - var drinkable = EntityManager.GetEntity(uid); - _logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{user} is forcing {target} to drink {drinkable}"); + _logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{userUid} is forcing {targetUid} to drink {uid}"); drink.InUse = true; return true; diff --git a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs index e6c4d59002..dd4aa14bc8 100644 --- a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs @@ -1,8 +1,11 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Content.Server.Body.Components; using Content.Server.Body.Systems; using Content.Server.Chemistry.EntitySystems; using Content.Server.DoAfter; using Content.Server.Hands.Components; +using Content.Server.Inventory.Components; using Content.Server.Items; using Content.Server.Nutrition.Components; using Content.Server.Popups; @@ -15,20 +18,16 @@ using Content.Shared.Database; using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; +using Content.Shared.Inventory; using Content.Shared.MobState.Components; +using Content.Shared.Tag; using Content.Shared.Verbs; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Player; -using System.Collections.Generic; -using System.Linq; using Robust.Shared.Utility; -using Content.Server.Inventory.Components; -using Content.Shared.Inventory; -using System.Diagnostics.CodeAnalysis; -using Content.Shared.Tag; namespace Content.Server.Nutrition.EntitySystems { @@ -65,16 +64,16 @@ namespace Content.Server.Nutrition.EntitySystems if (ev.Handled) return; - if (!_actionBlockerSystem.CanInteract(ev.UserUid) || !_actionBlockerSystem.CanUse(ev.UserUid)) + if (!_actionBlockerSystem.CanInteract(ev.User) || !_actionBlockerSystem.CanUse(ev.User)) return; - if (!ev.UserUid.InRangeUnobstructed(uid, popup: true)) + if (!ev.User.InRangeUnobstructed(uid, popup: true)) { ev.Handled = true; return; } - ev.Handled = TryUseFood(uid, ev.UserUid); + ev.Handled = TryUseFood(uid, ev.User); } /// @@ -82,80 +81,79 @@ namespace Content.Server.Nutrition.EntitySystems /// private void OnFeedFood(EntityUid uid, FoodComponent foodComponent, AfterInteractEvent args) { - if (args.Handled || args.TargetUid == null) + if (args.Handled || args.Target == default) return; - if (!_actionBlockerSystem.CanInteract(args.UserUid) || !_actionBlockerSystem.CanUse(args.UserUid)) + if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User)) return; - if (!args.UserUid.InRangeUnobstructed(uid, popup: true)) + if (!args.User.InRangeUnobstructed(uid, popup: true)) { args.Handled = true; return; } - if (args.UserUid == args.TargetUid) + if (args.User == args.Target) { - args.Handled = TryUseFood(uid, args.UserUid); + args.Handled = TryUseFood(uid, args.User); return; } - if (!args.UserUid.InRangeUnobstructed(args.TargetUid.Value, popup: true)) + if (!args.User.InRangeUnobstructed(args.Target.Value, popup: true)) { args.Handled = true; return; } - args.Handled = TryForceFeed(uid, args.UserUid, args.TargetUid.Value); + args.Handled = TryForceFeed(uid, args.User, args.Target.Value); } /// /// Tries to eat some food /// /// Food entity. - /// Feeding initiator. - /// Feeding target. + /// Feeding initiator. /// True if an interaction occurred (i.e., food was consumed, or a pop-up message was created) - public bool TryUseFood(EntityUid uid, EntityUid userUid, FoodComponent? component = null) + public bool TryUseFood(EntityUid uid, EntityUid user, FoodComponent? food = null) { - if (!Resolve(uid, ref component)) + if (!Resolve(uid, ref food)) return false; - if (uid == userUid || //Suppresses self-eating + if (uid == user || //Suppresses self-eating EntityManager.TryGetComponent(uid, out var mobState) && mobState.IsAlive()) // Suppresses eating alive mobs return false; - if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution)) + if (!_solutionContainerSystem.TryGetSolution(uid, food.SolutionName, out var solution)) return false; - if (component.UsesRemaining <= 0) + if (food.UsesRemaining <= 0) { - _popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty", ("entity", EntityManager.GetEntity(uid))), userUid, Filter.Entities(userUid)); - DeleteAndSpawnTrash(component, userUid); + _popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty", ("entity", uid)), user, Filter.Entities(user)); + DeleteAndSpawnTrash(food, user); return true; } - if (!EntityManager.TryGetComponent(userUid, out SharedBodyComponent ? body) || - !_bodySystem.TryGetComponentsOnMechanisms(userUid, out var stomachs, body)) + if (!EntityManager.TryGetComponent(user, out SharedBodyComponent ? body) || + !_bodySystem.TryGetComponentsOnMechanisms(user, out var stomachs, body)) return false; - if (IsMouthBlocked(userUid, out var blocker)) + if (IsMouthBlocked(user, out var blocker)) { var name = EntityManager.GetComponent(blocker.Value).EntityName; _popupSystem.PopupEntity(Loc.GetString("food-system-remove-mask", ("entity", name)), - userUid, Filter.Entities(userUid)); + user, Filter.Entities(user)); return true; } var usedUtensils = new List(); - if (!TryGetRequiredUtensils(userUid, component, out var utensils)) + if (!TryGetRequiredUtensils(user, food, out var utensils)) return true; - if (!userUid.InRangeUnobstructed(uid, popup: true)) + if (!user.InRangeUnobstructed(uid, popup: true)) return true; - var transferAmount = component.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) component.TransferAmount, solution.CurrentVolume) : solution.CurrentVolume; + var transferAmount = food.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) food.TransferAmount, solution.CurrentVolume) : solution.CurrentVolume; var split = _solutionContainerSystem.SplitSolution(uid, solution, transferAmount); var firstStomach = stomachs.FirstOrNull( stomach => _stomachSystem.CanTransferSolution(((IComponent) stomach.Comp).Owner, split)); @@ -163,51 +161,51 @@ namespace Content.Server.Nutrition.EntitySystems if (firstStomach == null) { _solutionContainerSystem.TryAddSolution(uid, solution, split); - _popupSystem.PopupEntity(Loc.GetString("food-system-you-cannot-eat-any-more"), userUid, Filter.Entities(userUid)); + _popupSystem.PopupEntity(Loc.GetString("food-system-you-cannot-eat-any-more"), user, Filter.Entities(user)); return true; } // TODO: Account for partial transfer. - split.DoEntityReaction(userUid, ReactionMethod.Ingestion); + split.DoEntityReaction(user, ReactionMethod.Ingestion); _stomachSystem.TryTransferSolution(((IComponent) firstStomach.Value.Comp).Owner, split, firstStomach.Value.Comp); - SoundSystem.Play(Filter.Pvs(userUid), component.UseSound.GetSound(), userUid, AudioParams.Default.WithVolume(-1f)); - _popupSystem.PopupEntity(Loc.GetString(component.EatMessage, ("food", component.Owner)), userUid, Filter.Entities(userUid)); + SoundSystem.Play(Filter.Pvs(user), food.UseSound.GetSound(), user, AudioParams.Default.WithVolume(-1f)); + _popupSystem.PopupEntity(Loc.GetString(food.EatMessage, ("food", food.Owner)), user, Filter.Entities(user)); // Try to break all used utensils foreach (var utensil in usedUtensils) { - _utensilSystem.TryBreak(((IComponent) utensil).Owner, userUid); + _utensilSystem.TryBreak(((IComponent) utensil).Owner, user); } - if (component.UsesRemaining > 0) + if (food.UsesRemaining > 0) { return true; } - if (string.IsNullOrEmpty(component.TrashPrototype)) - EntityManager.QueueDeleteEntity(((IComponent) component).Owner); + if (string.IsNullOrEmpty(food.TrashPrototype)) + EntityManager.QueueDeleteEntity(((IComponent) food).Owner); else - DeleteAndSpawnTrash(component, userUid); + DeleteAndSpawnTrash(food, user); return true; } - private void DeleteAndSpawnTrash(FoodComponent component, EntityUid? userUid = null) + private void DeleteAndSpawnTrash(FoodComponent component, EntityUid? user = null) { //We're empty. Become trash. - var position = IoCManager.Resolve().GetComponent(component.Owner).Coordinates; - var finisher = IoCManager.Resolve().SpawnEntity(component.TrashPrototype, position); + var position = EntityManager.GetComponent(component.Owner).Coordinates; + var finisher = EntityManager.SpawnEntity(component.TrashPrototype, position); // If the user is holding the item - if (userUid != null && - EntityManager.TryGetComponent(userUid.Value, out HandsComponent? handsComponent) && + if (user != null && + EntityManager.TryGetComponent(user.Value, out HandsComponent? handsComponent) && handsComponent.IsHolding(component.Owner)) { EntityManager.DeleteEntity(((IComponent) component).Owner); // Put the trash in the user's hand - if (IoCManager.Resolve().TryGetComponent(finisher, out ItemComponent? item) && + if (EntityManager.TryGetComponent(finisher, out ItemComponent? item) && handsComponent.CanPutInHand(item)) { handsComponent.PutInHand(item); @@ -220,24 +218,26 @@ namespace Content.Server.Nutrition.EntitySystems private void AddEatVerb(EntityUid uid, FoodComponent component, GetInteractionVerbsEvent ev) { - if (uid == ev.UserUid || + if (uid == ev.User || !ev.CanInteract || !ev.CanAccess || - !EntityManager.TryGetComponent(ev.UserUid, out SharedBodyComponent? body) || - !_bodySystem.TryGetComponentsOnMechanisms(ev.UserUid, out var stomachs, body)) + !EntityManager.TryGetComponent(ev.User, out SharedBodyComponent? body) || + !_bodySystem.TryGetComponentsOnMechanisms(ev.User, out var stomachs, body)) return; if (EntityManager.TryGetComponent(uid, out var mobState) && mobState.IsAlive()) return; - Verb verb = new(); - verb.Act = () => + Verb verb = new() { - TryUseFood(uid, ev.UserUid, component); + Act = () => + { + TryUseFood(uid, ev.User, component); + }, + Text = Loc.GetString("food-system-verb-eat"), + Priority = -1 }; - verb.Text = Loc.GetString("food-system-verb-eat"); - verb.Priority = -1; ev.Verbs.Add(verb); } @@ -245,12 +245,12 @@ namespace Content.Server.Nutrition.EntitySystems /// /// Attempts to force feed a target. Returns true if any interaction occurred, including pop-up generation /// - public bool TryForceFeed(EntityUid uid, EntityUid userUid, EntityUid targetUid, FoodComponent? food = null) + public bool TryForceFeed(EntityUid uid, EntityUid user, EntityUid target, FoodComponent? food = null) { if (!Resolve(uid, ref food)) return false; - if (!EntityManager.HasComponent(targetUid)) + if (!EntityManager.HasComponent(target)) return false; if (!_solutionContainerSystem.TryGetSolution(uid, food.SolutionName, out var foodSolution)) @@ -259,44 +259,41 @@ namespace Content.Server.Nutrition.EntitySystems if (food.UsesRemaining <= 0) { _popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty", - ("entity", EntityManager.GetEntity(uid))), userUid, Filter.Entities(userUid)); - DeleteAndSpawnTrash(food, userUid); + ("entity", uid)), user, Filter.Entities(user)); + DeleteAndSpawnTrash(food, user); return true; } - if (IsMouthBlocked(targetUid, out var blocker)) + if (IsMouthBlocked(target, out var blocker)) { var name = EntityManager.GetComponent(blocker.Value).EntityName; _popupSystem.PopupEntity(Loc.GetString("food-system-remove-mask", ("entity", name)), - userUid, Filter.Entities(userUid)); + user, Filter.Entities(user)); return true; } - if (!TryGetRequiredUtensils(userUid, food, out var utensils)) + if (!TryGetRequiredUtensils(user, food, out var utensils)) return true; - EntityManager.TryGetComponent(userUid, out MetaDataComponent? meta); + EntityManager.TryGetComponent(user, out MetaDataComponent? meta); var userName = meta?.EntityName ?? string.Empty; _popupSystem.PopupEntity(Loc.GetString("food-system-force-feed", ("user", userName)), - userUid, Filter.Entities(targetUid)); + user, Filter.Entities(target)); - _doAfterSystem.DoAfter(new DoAfterEventArgs(userUid, food.ForceFeedDelay, target: targetUid) + _doAfterSystem.DoAfter(new DoAfterEventArgs(user, food.ForceFeedDelay, target: target) { BreakOnUserMove = true, BreakOnDamage = true, BreakOnStun = true, BreakOnTargetMove = true, MovementThreshold = 1.0f, - TargetFinishedEvent = new ForceFeedEvent(userUid, food, foodSolution, utensils), + TargetFinishedEvent = new ForceFeedEvent(user, food, foodSolution, utensils), BroadcastCancelledEvent = new ForceFeedCancelledEvent(food) }); // logging - var user = EntityManager.GetEntity(userUid); - var target = EntityManager.GetEntity(targetUid); - var edible = EntityManager.GetEntity(uid); - _logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{user} is forcing {target} to eat {edible}"); + _logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{user} is forcing {target} to eat {uid}"); food.InUse = true; return true; @@ -383,15 +380,12 @@ namespace Content.Server.Nutrition.EntitySystems return; // logging - var userEntity = (user == null) ? null : EntityManager.GetEntity(user.Value); - var targetEntity = EntityManager.GetEntity(target); - var edible = EntityManager.GetEntity(uid); - if (userEntity == null) - _logSystem.Add(LogType.ForceFeed, $"{edible} was thrown into the mouth of {targetEntity}"); + if (user == null) + _logSystem.Add(LogType.ForceFeed, $"{uid} was thrown into the mouth of {target}"); else - _logSystem.Add(LogType.ForceFeed, $"{userEntity} threw {edible} into the mouth of {targetEntity}"); + _logSystem.Add(LogType.ForceFeed, $"{user} threw {uid} into the mouth of {target}"); - var filter = (user == null) ? Filter.Entities(target) : Filter.Entities(target, user.Value); + var filter = user == null ? Filter.Entities(target) : Filter.Entities(target, user.Value); _popupSystem.PopupEntity(Loc.GetString(food.EatMessage), target, filter); foodSolution.DoEntityReaction(uid, ReactionMethod.Ingestion); @@ -404,7 +398,7 @@ namespace Content.Server.Nutrition.EntitySystems DeleteAndSpawnTrash(food); } - private bool TryGetRequiredUtensils(EntityUid userUid, FoodComponent component, + private bool TryGetRequiredUtensils(EntityUid user, FoodComponent component, out List utensils, HandsComponent? hands = null) { utensils = new(); @@ -412,7 +406,7 @@ namespace Content.Server.Nutrition.EntitySystems if (component.Utensil != UtensilType.None) return true; - if (!Resolve(userUid, ref hands, false)) + if (!Resolve(user, ref hands, false)) return false; var usedTypes = UtensilType.None; @@ -420,7 +414,7 @@ namespace Content.Server.Nutrition.EntitySystems foreach (var item in hands.GetAllHeldItems()) { // Is utensil? - if (!IoCManager.Resolve().TryGetComponent(item.Owner, out UtensilComponent? utensil)) + if (!EntityManager.TryGetComponent(item.Owner, out UtensilComponent? utensil)) continue; if ((utensil.Types & component.Utensil) != 0 && // Acceptable type? @@ -435,7 +429,7 @@ namespace Content.Server.Nutrition.EntitySystems // If "required" field is set, try to block eating without proper utensils used if (component.UtensilRequired && (usedTypes & component.Utensil) != component.Utensil) { - _popupSystem.PopupEntity(Loc.GetString("food-you-need-to-hold-utensil", ("utensil", component.Utensil ^ usedTypes)), userUid, Filter.Entities(userUid)); + _popupSystem.PopupEntity(Loc.GetString("food-you-need-to-hold-utensil", ("utensil", component.Utensil ^ usedTypes)), user, Filter.Entities(user)); return false; } @@ -464,7 +458,7 @@ namespace Content.Server.Nutrition.EntitySystems { // For now, lets just assume that any masks always covers the mouth // TODO MASKS if the ability is added to raise/lower masks, this needs to be updated. - blockingEntity = mask.OwnerUid; + blockingEntity = mask.Owner; return true; } @@ -473,7 +467,7 @@ namespace Content.Server.Nutrition.EntitySystems EntityManager.TryGetComponent(((IComponent) head).Owner, out TagComponent tag) && tag.HasTag("ConcealsFace")) { - blockingEntity = head.OwnerUid; + blockingEntity = head.Owner; return true; } diff --git a/Content.Server/Nutrition/EntitySystems/SliceableFoodSystem.cs b/Content.Server/Nutrition/EntitySystems/SliceableFoodSystem.cs index 9eca47cf86..e8ef70d63a 100644 --- a/Content.Server/Nutrition/EntitySystems/SliceableFoodSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/SliceableFoodSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Nutrition.EntitySystems if (args.Handled) return; - if (TrySliceFood(uid, args.UserUid, args.UsedUid, component)) + if (TrySliceFood(uid, args.User, args.Used, component)) args.Handled = true; } @@ -57,8 +57,7 @@ namespace Content.Server.Nutrition.EntitySystems return false; } - IEntity tempQualifier = EntityManager.SpawnEntity(component.Slice, transform.Coordinates); - var sliceUid = (EntityUid) tempQualifier; + var sliceUid = EntityManager.SpawnEntity(component.Slice, transform.Coordinates); var lostSolution = _solutionContainerSystem.SplitSolution(uid, solution, solution.CurrentVolume / FixedPoint2.New(component.Count)); @@ -87,8 +86,7 @@ namespace Content.Server.Nutrition.EntitySystems // Split last slice if (component.Count == 1) { - IEntity tempQualifier1 = EntityManager.SpawnEntity(component.Slice, transform.Coordinates); - var lastSlice = (EntityUid) tempQualifier1; + var lastSlice = EntityManager.SpawnEntity(component.Slice, transform.Coordinates); // Fill last slice with the rest of the solution FillSlice(lastSlice, solution); diff --git a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs index 2b5435b83d..a0dd8fa600 100644 --- a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs @@ -99,8 +99,8 @@ namespace Content.Server.Nutrition.EntitySystems !IoCManager.Resolve().TryGetComponent(containerManager.Owner, out BloodstreamComponent? bloodstream)) continue; - _reactiveSystem.ReactionEntity(containerManager.OwnerUid, ReactionMethod.Ingestion, inhaledSolution); - _bloodstreamSystem.TryAddToBloodstream(containerManager.OwnerUid, inhaledSolution, bloodstream); + _reactiveSystem.ReactionEntity(containerManager.Owner, ReactionMethod.Ingestion, inhaledSolution); + _bloodstreamSystem.TryAddToBloodstream(containerManager.Owner, inhaledSolution, bloodstream); } _timer -= UpdateTimer; diff --git a/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs b/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs index f30d228fba..1a364d2a4c 100644 --- a/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/UtensilSystem.cs @@ -32,29 +32,29 @@ namespace Content.Server.Nutrition.EntitySystems /// private void OnAfterInteract(EntityUid uid, UtensilComponent component, AfterInteractEvent ev) { - if (ev.Target == null) + if (ev.Target == default) return; - if (TryUseUtensil(ev.UserUid, ev.Target, component)) + if (TryUseUtensil(ev.User, ev.Target.Value, component)) ev.Handled = true; } - private bool TryUseUtensil(EntityUid userUid, EntityUid targetUid, UtensilComponent component) + private bool TryUseUtensil(EntityUid user, EntityUid target, UtensilComponent component) { - if (!EntityManager.TryGetComponent(targetUid, out FoodComponent food)) + if (!EntityManager.TryGetComponent(target, out FoodComponent food)) return false; //Prevents food usage with a wrong utensil if ((food.Utensil & component.Types) == 0) { - _popupSystem.PopupEntity(Loc.GetString("food-system-wrong-utensil", ("food", food.Owner), ("utensil", component.Owner)), userUid, Filter.Entities(userUid)); + _popupSystem.PopupEntity(Loc.GetString("food-system-wrong-utensil", ("food", food.Owner), ("utensil", component.Owner)), user, Filter.Entities(user)); return false; } - if (!userUid.InRangeUnobstructed(targetUid, popup: true)) + if (!user.InRangeUnobstructed(target, popup: true)) return false; - return _foodSystem.TryUseFood(targetUid, userUid); + return _foodSystem.TryUseFood(target, user); } /// @@ -70,7 +70,7 @@ namespace Content.Server.Nutrition.EntitySystems if (_robustRandom.Prob(component.BreakChance)) { SoundSystem.Play(Filter.Pvs(userUid), component.BreakSound.GetSound(), userUid, AudioParams.Default.WithVolume(-2f)); - IoCManager.Resolve().DeleteEntity((EntityUid) component.Owner); + IoCManager.Resolve().DeleteEntity(component.Owner); } } } diff --git a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs index 0ca98426e9..eb60a825f1 100644 --- a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs +++ b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs @@ -21,10 +21,10 @@ namespace Content.Server.Objectives.Conditions { var entity = mc.Mind?.OwnedEntity; - if (entity == null) + if (entity == default) return false; - return (IoCManager.Resolve().GetComponentOrNull(entity)?.IsAlive() ?? false) && mc.Mind != mind; + return (IoCManager.Resolve().GetComponentOrNull(entity.Value)?.IsAlive() ?? false) && mc.Mind != mind; }).Select(mc => mc.Mind).ToList(); return new KillRandomPersonCondition {Target = IoCManager.Resolve().Pick(allHumans)}; } diff --git a/Content.Server/PDA/PDASystem.cs b/Content.Server/PDA/PDASystem.cs index 63e6fb95d2..a0bcebb971 100644 --- a/Content.Server/PDA/PDASystem.cs +++ b/Content.Server/PDA/PDASystem.cs @@ -110,7 +110,7 @@ namespace Content.Server.PDA UpdatePDAUserInterface(pda); } - private bool OpenUI(PDAComponent pda, IEntity user) + private bool OpenUI(PDAComponent pda, EntityUiduser) { if (!IoCManager.Resolve().TryGetComponent(user, out ActorComponent? actor)) return false; @@ -145,7 +145,7 @@ namespace Content.Server.PDA private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg) { // cast EntityUid? to EntityUid - if (msg.Session.AttachedEntityUid is not EntityUid playerUid) + if (msg.Session.AttachedEntity is not EntityUid playerUid) return; switch (msg.Message) diff --git a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs index 2935fce44c..c1f7aac15f 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs @@ -11,7 +11,6 @@ using Content.Server.VendingMachines; using Content.Server.WireHacking; using Content.Shared.ActionBlocker; using Content.Shared.Interaction; -using Content.Shared.Interaction.Events; using Content.Shared.Singularity.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; @@ -153,8 +152,8 @@ namespace Content.Server.ParticleAccelerator.Components } - if (obj.Session.AttachedEntityUid == null || - !EntitySystem.Get().CanInteract(obj.Session.AttachedEntityUid.Value)) + if (!obj.Session.AttachedEntity.Valid || + !EntitySystem.Get().CanInteract(obj.Session.AttachedEntity)) { return; } diff --git a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorEmitterComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorEmitterComponent.cs index c5e420f696..b4053089df 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorEmitterComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorEmitterComponent.cs @@ -16,14 +16,15 @@ namespace Content.Server.ParticleAccelerator.Components public void Fire(ParticleAcceleratorPowerState strength) { - var projectile = IoCManager.Resolve().SpawnEntity("ParticlesProjectile", IoCManager.Resolve().GetComponent(Owner).Coordinates); + var entities = IoCManager.Resolve(); + var projectile = entities.SpawnEntity("ParticlesProjectile", entities.GetComponent(Owner).Coordinates); - if (!IoCManager.Resolve().TryGetComponent(projectile, out var particleProjectileComponent)) + if (!entities.TryGetComponent(projectile, out var particleProjectileComponent)) { Logger.Error("ParticleAcceleratorEmitter tried firing particles, but they was spawned without a ParticleProjectileComponent"); return; } - particleProjectileComponent.Fire(strength, IoCManager.Resolve().GetComponent(Owner).WorldRotation, Owner); + particleProjectileComponent.Fire(strength, entities.GetComponent(Owner).WorldRotation, Owner); } public override string ToString() diff --git a/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs index 76fe1ea32b..d3a134a347 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs @@ -6,8 +6,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; -using Robust.Shared.Physics.Collision; -using Robust.Shared.Physics.Dynamics; using Robust.Shared.Timing; namespace Content.Server.ParticleAccelerator.Components @@ -18,7 +16,7 @@ namespace Content.Server.ParticleAccelerator.Components public override string Name => "ParticleProjectile"; public ParticleAcceleratorPowerState State; - public void Fire(ParticleAcceleratorPowerState state, Angle angle, IEntity firer) + public void Fire(ParticleAcceleratorPowerState state, Angle angle, EntityUid firer) { State = state; @@ -72,7 +70,7 @@ namespace Content.Server.ParticleAccelerator.Components .LinearVelocity = angle.ToWorldVec() * 20f; IoCManager.Resolve().GetComponent(Owner).LocalRotation = angle; - Timer.Spawn(3000, () => IoCManager.Resolve().DeleteEntity((EntityUid) Owner)); + Timer.Spawn(3000, () => IoCManager.Resolve().DeleteEntity(Owner)); } } } diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index a756e6bf2e..4c1ba261e5 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -10,7 +10,6 @@ using Content.Shared.Inventory; using Content.Shared.Maps; using Content.Shared.Movement; using Content.Shared.Movement.Components; -using Content.Shared.Shuttles; using Content.Shared.Shuttles.Components; using Content.Shared.Tag; using Robust.Shared.Audio; @@ -315,7 +314,7 @@ namespace Content.Server.Physics.Controllers } } - private void PlayFootstepSound(IEntity mover, GridId gridId, EntityCoordinates coordinates, bool sprinting) + private void PlayFootstepSound(EntityUid mover, GridId gridId, EntityCoordinates coordinates, bool sprinting) { var grid = _mapManager.GetGrid(gridId); var tile = grid.GetTileRef(coordinates); diff --git a/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs b/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs index 319b16170c..f2b3028402 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonComponent.cs @@ -1,11 +1,9 @@ using System.Collections.Generic; using Content.Shared.Sound; using Content.Shared.Tools; -using Content.Shared.Verbs; using Robust.Shared.Analyzers; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; @@ -80,7 +78,7 @@ namespace Content.Server.PneumaticCannon public struct FireData { - public IEntity User; + public EntityUid User, public float Strength; public Vector2 Direction; } diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index b8a40e0c66..f5775d2b74 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -4,30 +4,24 @@ using System.Linq; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Server.Camera; -using Content.Server.CombatMode; using Content.Server.Hands.Components; using Content.Server.Items; using Content.Server.Nutrition.Components; using Content.Server.Storage.Components; using Content.Server.Stunnable; -using Content.Server.Stunnable.Components; -using Content.Shared.Interaction; -using Content.Shared.PneumaticCannon; -using Robust.Shared.Containers; -using Robust.Shared.GameObjects; -using Robust.Shared.Map; -using Content.Server.Throwing; -using Content.Server.Tools; using Content.Server.Tools.Components; using Content.Shared.CombatMode; +using Content.Shared.Interaction; +using Content.Shared.PneumaticCannon; using Content.Shared.Popups; -using Content.Shared.Sound; using Content.Shared.StatusEffect; using Content.Shared.Verbs; -using Content.Shared.Weapons.Melee; using Robust.Shared.Audio; +using Robust.Shared.Containers; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Player; using Robust.Shared.Random; @@ -167,13 +161,13 @@ namespace Content.Server.PneumaticCannon { args.User.PopupMessage(Loc.GetString("pneumatic-cannon-component-fire-no-gas", ("cannon", component.Owner))); - SoundSystem.Play(Filter.Pvs((EntityUid) args.Used), "/Audio/Items/hiss.ogg", (EntityUid) args.Used, AudioParams.Default); + SoundSystem.Play(Filter.Pvs(args.Used), "/Audio/Items/hiss.ogg", args.Used, AudioParams.Default); return; } AddToQueue(component, args.User, args.ClickLocation); } - public void AddToQueue(PneumaticCannonComponent comp, IEntity user, EntityCoordinates click) + public void AddToQueue(PneumaticCannonComponent comp, EntityUid user, EntityCoordinates click) { if (!IoCManager.Resolve().TryGetComponent(comp.Owner, out var storage)) return; @@ -230,7 +224,7 @@ namespace Content.Server.PneumaticCannon if (storage.StoredEntities == null) return; if (storage.StoredEntities.Count == 0) return; // click sound? - IEntity ent = _random.Pick(storage.StoredEntities); + EntityUident = _random.Pick(storage.StoredEntities); storage.Remove(ent); SoundSystem.Play(Filter.Pvs(data.User), comp.FireSound.GetSound(), ((IComponent) comp).Owner, AudioParams.Default); @@ -311,7 +305,7 @@ namespace Content.Server.PneumaticCannon args.Verbs.Add(ejectItems); } - public void TryRemoveGasTank(PneumaticCannonComponent component, IEntity user) + public void TryRemoveGasTank(PneumaticCannonComponent component, EntityUiduser) { if (component.GasTankSlot.ContainedEntity == null) { @@ -334,7 +328,7 @@ namespace Content.Server.PneumaticCannon } } - public void TryEjectAllItems(PneumaticCannonComponent component, IEntity user) + public void TryEjectAllItems(PneumaticCannonComponent component, EntityUiduser) { if (IoCManager.Resolve().TryGetComponent(component.Owner, out var storage)) { diff --git a/Content.Server/Pointing/Components/PointingArrowComponent.cs b/Content.Server/Pointing/Components/PointingArrowComponent.cs index 85f1acec11..eabd5e8f08 100644 --- a/Content.Server/Pointing/Components/PointingArrowComponent.cs +++ b/Content.Server/Pointing/Components/PointingArrowComponent.cs @@ -81,7 +81,7 @@ namespace Content.Server.Pointing.Components return; } - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); return; } diff --git a/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs b/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs index 35c813283c..90bbe6468a 100644 --- a/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs +++ b/Content.Server/Pointing/Components/RoguePointingArrowComponent.cs @@ -13,7 +13,7 @@ namespace Content.Server.Pointing.Components public class RoguePointingArrowComponent : SharedRoguePointingArrowComponent { [ViewVariables] - public IEntity? Chasing; + public EntityUid Chasing; [ViewVariables(VVAccess.ReadWrite)] [DataField("turningDelay")] diff --git a/Content.Server/Pointing/EntitySystems/PointingSystem.cs b/Content.Server/Pointing/EntitySystems/PointingSystem.cs index fc9a438f77..3516121b85 100644 --- a/Content.Server/Pointing/EntitySystems/PointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/PointingSystem.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; -using System.Linq; using Content.Server.Ghost.Components; using Content.Server.Players; using Content.Server.Pointing.Components; using Content.Server.Visible; -using Content.Shared.ActionBlocker; using Content.Shared.Input; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; -using Content.Shared.Popups; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -20,7 +17,6 @@ using Robust.Shared.Input.Binding; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; -using Robust.Shared.Maths; using Robust.Shared.Player; using Robust.Shared.Players; using Robust.Shared.Timing; @@ -57,7 +53,7 @@ namespace Content.Server.Pointing.EntitySystems } // TODO: FOV - private void SendMessage(IEntity source, IEnumerable viewers, IEntity? pointed, string selfMessage, + private void SendMessage(EntityUid source, IEnumerable viewers, EntityUid pointed, string selfMessage, string viewerMessage, string? viewerPointedAtMessage = null) { foreach (var viewer in viewers) @@ -78,7 +74,7 @@ namespace Content.Server.Pointing.EntitySystems } } - public bool InRange(IEntity pointer, EntityCoordinates coordinates) + public bool InRange(EntityUid pointer, EntityCoordinates coordinates) { if (IoCManager.Resolve().HasComponent(pointer)) { @@ -105,7 +101,7 @@ namespace Content.Server.Pointing.EntitySystems return false; } - if (EntityManager.TryGetEntity(uid, out var entity) && IoCManager.Resolve().HasComponent(entity)) + if (EntityManager.EntityExists(uid) { // this is a pointing arrow. no pointing here... return false; @@ -146,7 +142,7 @@ namespace Content.Server.Pointing.EntitySystems string viewerMessage; string? viewerPointedAtMessage = null; - if (EntityManager.TryGetEntity(uid, out var pointed)) + if (EntityManager.EntityExists(uid) { selfMessage = player == pointed ? Loc.GetString("pointing-system-point-at-self") diff --git a/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs b/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs index 6c6ada6ebc..e1078f6dc3 100644 --- a/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs @@ -37,7 +37,7 @@ namespace Content.Server.Pointing.EntitySystems } } - private IEntity? RandomNearbyPlayer(EntityUid uid, RoguePointingArrowComponent? component = null, TransformComponent? transform = null) + private EntityUid RandomNearbyPlayer(EntityUid uid, RoguePointingArrowComponent? component = null, TransformComponent? transform = null) { if (!Resolve(uid, ref component, ref transform)) return null; @@ -65,7 +65,7 @@ namespace Content.Server.Pointing.EntitySystems { foreach (var (component, transform) in EntityManager.EntityQuery()) { - var uid = (EntityUid) component.Owner; + var uid = component.Owner; component.Chasing ??= RandomNearbyPlayer(uid, component, transform); if (component.Chasing == null) diff --git a/Content.Server/Power/Components/BaseCharger.cs b/Content.Server/Power/Components/BaseCharger.cs index 016aa76061..5486d5f920 100644 --- a/Content.Server/Power/Components/BaseCharger.cs +++ b/Content.Server/Power/Components/BaseCharger.cs @@ -88,7 +88,7 @@ namespace Content.Server.Power.Components /// This will remove the item directly into the user's hand / floor /// /// - public void RemoveItem(IEntity user) + public void RemoveItem(EntityUiduser) { var heldItem = Container.ContainedEntity; if (heldItem == null) @@ -134,7 +134,7 @@ namespace Content.Server.Power.Components return CellChargerStatus.Charging; } - public bool TryInsertItem(IEntity entity) + public bool TryInsertItem(EntityUid entity) { if (!IsEntityCompatible(entity) || HasCell) { @@ -152,9 +152,9 @@ namespace Content.Server.Power.Components /// /// If the supplied entity should fit into the charger. /// - public abstract bool IsEntityCompatible(IEntity entity); + public abstract bool IsEntityCompatible(EntityUid entity); - protected abstract BatteryComponent? GetBatteryFrom(IEntity entity); + protected abstract BatteryComponent? GetBatteryFrom(EntityUid entity); private void UpdateStatus() { diff --git a/Content.Server/Power/Components/CableComponent.cs b/Content.Server/Power/Components/CableComponent.cs index 624451765d..0205722fd8 100644 --- a/Content.Server/Power/Components/CableComponent.cs +++ b/Content.Server/Power/Components/CableComponent.cs @@ -2,10 +2,8 @@ using System.Threading.Tasks; using Content.Server.Electrocution; using Content.Server.Stack; using Content.Server.Tools; -using Content.Server.Tools.Components; using Content.Shared.Interaction; using Content.Shared.Tools; -using Content.Shared.Tools.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; @@ -47,7 +45,7 @@ namespace Content.Server.Power.Components if (EntitySystem.Get().TryDoElectrifiedAct(Owner, eventArgs.User)) return false; - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); var droppedEnt = IoCManager.Resolve().SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation); // TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated... diff --git a/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs b/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs index 709ddd2015..8550c10c9b 100644 --- a/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs +++ b/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs @@ -77,7 +77,7 @@ namespace Content.Server.Power.EntitySystems private IEnumerable FindAvailableReceivers(EntityUid uid, float range) { - var owner = EntityManager.GetEntity(uid); + var owner = uid var nearbyEntities = IoCManager.Resolve() .GetEntitiesInRange(owner, range); @@ -174,7 +174,7 @@ namespace Content.Server.Power.EntitySystems RaiseLocalEvent(provider.Owner, new ReceiverConnectedEvent(receiver), broadcast: false); } - private static bool TryFindAvailableProvider(IEntity owner, float range, [NotNullWhen(true)] out ExtensionCableProviderComponent? foundProvider) + private static bool TryFindAvailableProvider(EntityUid owner, float range, [NotNullWhen(true)] out ExtensionCableProviderComponent? foundProvider) { var nearbyEntities = IoCManager.Resolve() .GetEntitiesInRange(owner, range); diff --git a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs index 6edac5a619..d2004f084e 100644 --- a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs @@ -30,7 +30,7 @@ namespace Content.Server.Power.EntitySystems private void OnProviderConnected(EntityUid uid, ApcPowerReceiverComponent receiver, ExtensionCableSystem.ProviderConnectedEvent args) { - var providerUid = (EntityUid) args.Provider.Owner; + var providerUid = args.Provider.Owner; if (!EntityManager.TryGetComponent(providerUid, out var provider)) return; diff --git a/Content.Server/PowerCell/Components/PowerCellChargerComponent.cs b/Content.Server/PowerCell/Components/PowerCellChargerComponent.cs index 3564d8bbdc..69b52d42c7 100644 --- a/Content.Server/PowerCell/Components/PowerCellChargerComponent.cs +++ b/Content.Server/PowerCell/Components/PowerCellChargerComponent.cs @@ -15,12 +15,12 @@ namespace Content.Server.PowerCell.Components { public override string Name => "PowerCellCharger"; - public override bool IsEntityCompatible(IEntity entity) + public override bool IsEntityCompatible(EntityUid entity) { return IoCManager.Resolve().HasComponent(entity); } - protected override BatteryComponent GetBatteryFrom(IEntity entity) + protected override BatteryComponent GetBatteryFrom(EntityUid entity) { return IoCManager.Resolve().GetComponent(entity); } diff --git a/Content.Server/PowerCell/Components/PowerCellComponent.cs b/Content.Server/PowerCell/Components/PowerCellComponent.cs index 7f973ee935..81ac3dca80 100644 --- a/Content.Server/PowerCell/Components/PowerCellComponent.cs +++ b/Content.Server/PowerCell/Components/PowerCellComponent.cs @@ -74,7 +74,7 @@ namespace Content.Server.PowerCell.Components CurrentCharge = 0; EntitySystem.Get().SpawnExplosion(((IComponent) this).Owner, 0, heavy, light, light*2); - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); } private void UpdateVisuals() diff --git a/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs b/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs index 4197079ace..375365d06a 100644 --- a/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs +++ b/Content.Server/PowerCell/Components/PowerCellSlotComponent.cs @@ -126,7 +126,7 @@ namespace Content.Server.PowerCell.Components /// (optional) the user to give the removed cell to. /// Should be played upon removal? /// The cell component of the entity that was removed, or null if removal failed. - public PowerCellComponent? EjectCell(IEntity? user, bool playSound = true) + public PowerCellComponent? EjectCell(EntityUid user, bool playSound = true) { var cell = Cell; if (cell == null || !CanRemoveCell) return null; @@ -159,7 +159,7 @@ namespace Content.Server.PowerCell.Components /// The cell to insert. /// Should be played upon insertion? /// True if insertion succeeded; false otherwise. - public bool InsertCell(IEntity cell, bool playSound = true) + public bool InsertCell(EntityUid cell, bool playSound = true) { if (Cell != null) return false; if (!IoCManager.Resolve().TryGetComponent((EntityUid) cell, out (ItemComponent?) var _)) return false; diff --git a/Content.Server/Projectiles/Components/HitscanComponent.cs b/Content.Server/Projectiles/Components/HitscanComponent.cs index 547e35f5d3..eccd27af5b 100644 --- a/Content.Server/Projectiles/Components/HitscanComponent.cs +++ b/Content.Server/Projectiles/Components/HitscanComponent.cs @@ -47,7 +47,7 @@ namespace Content.Server.Projectiles.Components [DataField("soundHitWall")] private SoundSpecifier _soundHitWall = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg"); - public void FireEffects(IEntity user, float distance, Angle angle, IEntity? hitEntity = null) + public void FireEffects(EntityUid user, float distance, Angle angle, EntityUid hitEntity = null) { var effectSystem = EntitySystem.Get(); _startTime = _gameTiming.CurTime; @@ -98,7 +98,7 @@ namespace Content.Server.Projectiles.Components { if (!((!IoCManager.Resolve().EntityExists(Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(Owner).EntityLifeStage) >= EntityLifeStage.Deleted)) { - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); } }); } diff --git a/Content.Server/Projectiles/Components/ProjectileComponent.cs b/Content.Server/Projectiles/Components/ProjectileComponent.cs index 302dc9c1f6..24f9555182 100644 --- a/Content.Server/Projectiles/Components/ProjectileComponent.cs +++ b/Content.Server/Projectiles/Components/ProjectileComponent.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; using Content.Shared.Damage; using Content.Shared.Projectiles; using Content.Shared.Sound; using Robust.Shared.GameObjects; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -32,7 +30,7 @@ namespace Content.Server.Projectiles.Components /// Function that makes the collision of this object ignore a specific entity so we don't collide with ourselves /// /// - public void IgnoreEntity(IEntity shooter) + public void IgnoreEntity(EntityUid shooter) { Shooter = shooter; Dirty(); diff --git a/Content.Server/Projectiles/ProjectileSystem.cs b/Content.Server/Projectiles/ProjectileSystem.cs index 9e5cc6b349..244a593931 100644 --- a/Content.Server/Projectiles/ProjectileSystem.cs +++ b/Content.Server/Projectiles/ProjectileSystem.cs @@ -1,7 +1,6 @@ using Content.Server.Administration.Logs; using Content.Server.Camera; using Content.Server.Projectiles.Components; -using Content.Shared.Administration.Logs; using Content.Shared.Body.Components; using Content.Shared.Damage; using Content.Shared.Database; @@ -57,7 +56,7 @@ namespace Content.Server.Projectiles var dmg = _damageableSystem.TryChangeDamage(otherEntity, component.Damage); component.DamagedEntity = true; - if (dmg is not null && EntityManager.TryGetEntity(component.Shooter, out var shooter)) + if (dmg is not null && EntityManager.EntityExists(component.Shooter) _adminLogSystem.Add(LogType.BulletHit, LogImpact.Low, $"Projectile {component.Owner} shot by {shooter} hit {otherEntity} and dealt {dmg.Total} damage"); } @@ -83,7 +82,7 @@ namespace Content.Server.Projectiles if (component.TimeLeft <= 0) { - IoCManager.Resolve().DeleteEntity((EntityUid) component.Owner); + IoCManager.Resolve().DeleteEntity(component.Owner); } } } diff --git a/Content.Server/RCD/Systems/RCDSystem.cs b/Content.Server/RCD/Systems/RCDSystem.cs index 2aa6fbebc3..62f1f768c8 100644 --- a/Content.Server/RCD/Systems/RCDSystem.cs +++ b/Content.Server/RCD/Systems/RCDSystem.cs @@ -1,3 +1,5 @@ +using System; +using System.Threading; using Content.Server.DoAfter; using Content.Server.RCD.Components; using Content.Shared.Coordinates; @@ -6,7 +8,6 @@ using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Maps; using Content.Shared.Popups; -using Content.Shared.Tag; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -14,8 +15,6 @@ using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Player; -using System; -using System.Threading; namespace Content.Server.RCD.Systems { @@ -118,10 +117,10 @@ namespace Content.Server.RCD.Systems } else //Delete what the user targeted { - IEntity? tempQualifier = args.Target; + EntityUid tempQualifier = args.Target; if (tempQualifier != null) { - IoCManager.Resolve().DeleteEntity((EntityUid) tempQualifier); + IoCManager.Resolve().DeleteEntity(tempQualifier); } } break; @@ -228,7 +227,7 @@ namespace Content.Server.RCD.Systems } } - private void NextMode(EntityUid uid, RCDComponent rcd, IEntity? user) + private void NextMode(EntityUid uid, RCDComponent rcd, EntityUid user) { SoundSystem.Play(Filter.Pvs(uid), rcd.SwapModeSound.GetSound(), uid); diff --git a/Content.Server/Radiation/RadiationPulseComponent.cs b/Content.Server/Radiation/RadiationPulseComponent.cs index 675ba5bd36..a83d968d29 100644 --- a/Content.Server/Radiation/RadiationPulseComponent.cs +++ b/Content.Server/Radiation/RadiationPulseComponent.cs @@ -5,7 +5,6 @@ using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Random; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; @@ -112,7 +111,7 @@ namespace Content.Server.Radiation return; if (_duration <= 0f) - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); _duration -= frameTime; } diff --git a/Content.Server/Radio/Components/HandheldRadioComponent.cs b/Content.Server/Radio/Components/HandheldRadioComponent.cs index 79b6e3edb6..c55da536b2 100644 --- a/Content.Server/Radio/Components/HandheldRadioComponent.cs +++ b/Content.Server/Radio/Components/HandheldRadioComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.Radio.Components _chatManager.EntitySay(Owner, message); } - public bool Use(IEntity user) + public bool Use(EntityUiduser) { RadioOn = !RadioOn; @@ -79,13 +79,13 @@ namespace Content.Server.Radio.Components return Use(eventArgs.User); } - public bool CanListen(string message, IEntity source) + public bool CanListen(string message, EntityUidsource) { return RadioOn && Owner.InRangeUnobstructed(IoCManager.Resolve().GetComponent(source).Coordinates, range: ListenRange); } - public void Receive(string message, int channel, IEntity speaker) + public void Receive(string message, int channel, EntityUidspeaker) { if (RadioOn) { @@ -93,12 +93,12 @@ namespace Content.Server.Radio.Components } } - public void Listen(string message, IEntity speaker) + public void Listen(string message, EntityUidspeaker) { Broadcast(message, speaker); } - public void Broadcast(string message, IEntity speaker) + public void Broadcast(string message, EntityUidspeaker) { _radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency); } diff --git a/Content.Server/Radio/Components/IListen.cs b/Content.Server/Radio/Components/IListen.cs index 77ee15a8f2..8bb6fba7f3 100644 --- a/Content.Server/Radio/Components/IListen.cs +++ b/Content.Server/Radio/Components/IListen.cs @@ -10,8 +10,8 @@ namespace Content.Server.Radio.Components { int ListenRange { get; } - bool CanListen(string message, IEntity source); + bool CanListen(string message, EntityUidsource); - void Listen(string message, IEntity speaker); + void Listen(string message, EntityUidspeaker); } } diff --git a/Content.Server/Radio/Components/IRadio.cs b/Content.Server/Radio/Components/IRadio.cs index f93bf4877b..5e9f2becdd 100644 --- a/Content.Server/Radio/Components/IRadio.cs +++ b/Content.Server/Radio/Components/IRadio.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Robust.Shared.GameObjects; namespace Content.Server.Radio.Components { @@ -7,8 +6,8 @@ namespace Content.Server.Radio.Components { IReadOnlyList Channels { get; } - void Receive(string message, int channel, IEntity speaker); + void Receive(string message, int channel, EntityUidspeaker); - void Broadcast(string message, IEntity speaker); + void Broadcast(string message, EntityUidspeaker); } } diff --git a/Content.Server/Radio/EntitySystems/ListeningSystem.cs b/Content.Server/Radio/EntitySystems/ListeningSystem.cs index 7bc4dc93c1..1c4b2b5763 100644 --- a/Content.Server/Radio/EntitySystems/ListeningSystem.cs +++ b/Content.Server/Radio/EntitySystems/ListeningSystem.cs @@ -7,7 +7,7 @@ namespace Content.Server.Radio.EntitySystems [UsedImplicitly] public class ListeningSystem : EntitySystem { - public void PingListeners(IEntity source, string message) + public void PingListeners(EntityUid source, string message) { foreach (var listener in EntityManager.EntityQuery(true)) { diff --git a/Content.Server/Radio/EntitySystems/RadioSystem.cs b/Content.Server/Radio/EntitySystems/RadioSystem.cs index ee2e749585..350590f6a4 100644 --- a/Content.Server/Radio/EntitySystems/RadioSystem.cs +++ b/Content.Server/Radio/EntitySystems/RadioSystem.cs @@ -11,7 +11,7 @@ namespace Content.Server.Radio.EntitySystems { private readonly List _messages = new(); - public void SpreadMessage(IRadio source, IEntity speaker, string message, int channel) + public void SpreadMessage(IRadio source, EntityUid speaker, string message, int channel) { if (_messages.Contains(message)) return; diff --git a/Content.Server/Recycling/Components/RecyclableComponent.cs b/Content.Server/Recycling/Components/RecyclableComponent.cs index 431d5587c0..89834beb0b 100644 --- a/Content.Server/Recycling/Components/RecyclableComponent.cs +++ b/Content.Server/Recycling/Components/RecyclableComponent.cs @@ -38,7 +38,7 @@ namespace Content.Server.Recycling.Components } - IoCManager.Resolve().QueueDeleteEntity((EntityUid) Owner); + IoCManager.Resolve().QueueDeleteEntity(Owner); } } } diff --git a/Content.Server/Recycling/Components/RecyclerComponent.cs b/Content.Server/Recycling/Components/RecyclerComponent.cs index 530a229212..e4608a1f5f 100644 --- a/Content.Server/Recycling/Components/RecyclerComponent.cs +++ b/Content.Server/Recycling/Components/RecyclerComponent.cs @@ -1,14 +1,12 @@ using Content.Server.Act; using Content.Server.Chat.Managers; using Content.Server.GameTicking; -using Content.Server.Mind.Components; using Content.Server.Players; using Content.Server.Popups; using Content.Shared.Body.Components; using Content.Shared.Popups; using Content.Shared.Recycling; using Robust.Server.GameObjects; -using Robust.Server.Player; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -47,7 +45,7 @@ namespace Content.Server.Recycling.Components } } - SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat) + SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { if (IoCManager.Resolve().TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind) { diff --git a/Content.Server/Recycling/RecyclerSystem.cs b/Content.Server/Recycling/RecyclerSystem.cs index 5e39f97dda..ea404ca977 100644 --- a/Content.Server/Recycling/RecyclerSystem.cs +++ b/Content.Server/Recycling/RecyclerSystem.cs @@ -1,13 +1,10 @@ -using System.Collections.Generic; using Content.Server.Power.Components; using Content.Server.Recycling.Components; using Content.Shared.Body.Components; using Content.Shared.Recycling; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Physics; using Robust.Shared.Physics.Dynamics; -using Robust.Shared.Utility; namespace Content.Server.Recycling { @@ -24,7 +21,7 @@ namespace Content.Server.Recycling Recycle(component, args.OtherFixture.Body.Owner); } - private void Recycle(RecyclerComponent component, IEntity entity) + private void Recycle(RecyclerComponent component, EntityUid entity) { // TODO: Prevent collision with recycled items @@ -42,7 +39,7 @@ namespace Content.Server.Recycling recyclable.Recycle(component.Efficiency); } - private bool CanGib(RecyclerComponent component, IEntity entity) + private bool CanGib(RecyclerComponent component, EntityUid entity) { // We suppose this entity has a Recyclable component. return IoCManager.Resolve().HasComponent(entity) && !component.Safe && diff --git a/Content.Server/Rotatable/RotatableSystem.cs b/Content.Server/Rotatable/RotatableSystem.cs index aaa4b54adc..d1f8019b82 100644 --- a/Content.Server/Rotatable/RotatableSystem.cs +++ b/Content.Server/Rotatable/RotatableSystem.cs @@ -74,7 +74,7 @@ namespace Content.Server.Rotatable /// /// Replace a flippable entity with it's flipped / mirror-symmetric entity. /// - public static void TryFlip(FlippableComponent component, IEntity user) + public static void TryFlip(FlippableComponent component, EntityUiduser) { if (IoCManager.Resolve().TryGetComponent(component.Owner, out IPhysBody? physics) && physics.BodyType == BodyType.Static) @@ -88,7 +88,7 @@ namespace Content.Server.Rotatable var newTransform = IoCManager.Resolve().GetComponent(entity); newTransform.LocalRotation = oldTransform.LocalRotation; newTransform.Anchored = false; - IoCManager.Resolve().DeleteEntity((EntityUid) component.Owner); + IoCManager.Resolve().DeleteEntity(component.Owner); } } } diff --git a/Content.Server/RoundEnd/RoundEndSystem.cs b/Content.Server/RoundEnd/RoundEndSystem.cs index 2dc92158d2..6584bb362a 100644 --- a/Content.Server/RoundEnd/RoundEndSystem.cs +++ b/Content.Server/RoundEnd/RoundEndSystem.cs @@ -3,10 +3,8 @@ using System.Threading; using Content.Server.Administration.Logs; using Content.Server.Chat.Managers; using Content.Server.GameTicking; -using Content.Shared.Administration.Logs; using Content.Shared.Database; using Content.Shared.GameTicking; -using Robust.Server.Player; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -80,12 +78,12 @@ namespace Content.Server.RoundEnd Timer.Spawn(CallCooldown, () => OnCallCooldownEnded?.Invoke(), _callCooldownEndedTokenSource.Token); } - public void RequestRoundEnd(IEntity? requester = null, bool checkCooldown = true) + public void RequestRoundEnd(EntityUid? requester = null, bool checkCooldown = true) { RequestRoundEnd(RoundEndCountdownTime, requester, checkCooldown); } - public void RequestRoundEnd(TimeSpan countdownTime, IEntity? requester = null, bool checkCooldown = true) + public void RequestRoundEnd(TimeSpan countdownTime, EntityUid? requester = null, bool checkCooldown = true) { if (IsRoundEndCountdownStarted) return; @@ -95,7 +93,7 @@ namespace Content.Server.RoundEnd return; } - if (requester != null) + if (requester != default) { _adminLog.Add(LogType.ShuttleCalled, LogImpact.High, $"Shuttle called by {requester}"); } @@ -118,7 +116,7 @@ namespace Content.Server.RoundEnd OnRoundEndCountdownStarted?.Invoke(); } - public void CancelRoundEndCountdown(IEntity? requester = null, bool checkCooldown = true) + public void CancelRoundEndCountdown(EntityUid? requester = null, bool checkCooldown = true) { if (!IsRoundEndCountdownStarted) return; @@ -128,7 +126,7 @@ namespace Content.Server.RoundEnd return; } - if (requester != null) + if (requester != default) { _adminLog.Add(LogType.ShuttleRecalled, LogImpact.High, $"Shuttle recalled by {requester}"); } diff --git a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs index 7ff0988c7c..59a4537cda 100644 --- a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs +++ b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs @@ -6,7 +6,6 @@ using Content.Server.Atmos.Piping.EntitySystems; using Content.Server.NodeContainer; using Content.Server.NodeContainer.NodeGroups; using Content.Shared.Administration; -using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Console; using Robust.Shared.GameObjects; @@ -56,8 +55,7 @@ namespace Content.Server.Sandbox.Commands return; } - var target = entityManager.GetEntity(eUid); - if (!IoCManager.Resolve().TryGetComponent(target, out NodeContainerComponent? nodeContainerComponent)) + if (!IoCManager.Resolve().TryGetComponent(eUid, out NodeContainerComponent? nodeContainerComponent)) { shell.WriteLine(Loc.GetString("shell-entity-is-not-node-container")); return; diff --git a/Content.Server/Sandbox/SandboxManager.cs b/Content.Server/Sandbox/SandboxManager.cs index e5b192f8e8..af319fbb14 100644 --- a/Content.Server/Sandbox/SandboxManager.cs +++ b/Content.Server/Sandbox/SandboxManager.cs @@ -1,12 +1,13 @@ using System.Linq; using Content.Server.Access.Components; -using Content.Shared.Containers.ItemSlots; +using Content.Server.Access.Systems; using Content.Server.GameTicking; using Content.Server.Hands.Components; using Content.Server.Inventory.Components; using Content.Server.Items; using Content.Server.PDA; using Content.Shared.Access; +using Content.Shared.Containers.ItemSlots; using Content.Shared.Sandbox; using Robust.Server.Console; using Robust.Server.GameObjects; @@ -19,7 +20,6 @@ using Robust.Shared.Network; using Robust.Shared.Prototypes; using Robust.Shared.ViewVariables; using static Content.Shared.Inventory.EquipmentSlotDefines; -using Content.Server.Access.Systems; namespace Content.Server.Sandbox { @@ -157,7 +157,7 @@ namespace Content.Server.Sandbox } } - void UpgradeId(IEntity id) + void UpgradeId(EntityUidid) { var accessSystem = EntitySystem.Get(); accessSystem.TrySetTags(id, allAccess); @@ -168,7 +168,7 @@ namespace Content.Server.Sandbox } } - IEntity CreateFreshId() + EntityUidCreateFreshId() { var card = _entityManager.SpawnEntity("CaptainIDCard", IoCManager.Resolve().GetComponent(player.AttachedEntity).Coordinates); UpgradeId(card); diff --git a/Content.Server/Shuttles/EntitySystems/DockingSystem.cs b/Content.Server/Shuttles/EntitySystems/DockingSystem.cs index a32f43b9e5..ff94f88fe2 100644 --- a/Content.Server/Shuttles/EntitySystems/DockingSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/DockingSystem.cs @@ -1,5 +1,3 @@ -using Content.Server.Atmos.Components; -using Content.Server.Atmos.EntitySystems; using Content.Server.Doors.Components; using Content.Server.Power.Components; using Content.Server.Shuttles.Components; @@ -112,7 +110,7 @@ namespace Content.Server.Shuttles.EntitySystems if (dockingFixture == null) { DebugTools.Assert(false); - Logger.ErrorS("docking", $"Found null fixture on {EntityManager.GetEntity(((IComponent) body).Owner)}"); + Logger.ErrorS("docking", $"Found null fixture on {((IComponent) body).Owner)}" return null; } @@ -146,7 +144,7 @@ namespace Content.Server.Shuttles.EntitySystems if (otherDockingFixture == null) { DebugTools.Assert(false); - Logger.ErrorS("docking", $"Found null docking fixture on {EntityManager.GetEntity(ent)}"); + Logger.ErrorS("docking", $"Found null docking fixture on {ent)}" continue; } diff --git a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs index e62d81a343..ac0afe52ec 100644 --- a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs @@ -96,7 +96,7 @@ namespace Content.Server.Shuttles.EntitySystems return; } - var pilotComponent = EntityManager.EnsureComponent((EntityUid) args.User); + var pilotComponent = EntityManager.EnsureComponent(args.User); if (!component.Enabled) { @@ -130,7 +130,7 @@ namespace Content.Server.Shuttles.EntitySystems ClearPilots(component); } - public void AddPilot(IEntity entity, ShuttleConsoleComponent component) + public void AddPilot(EntityUid entity, ShuttleConsoleComponent component) { if (!_blocker.CanInteract(entity) || !IoCManager.Resolve().TryGetComponent(entity, out PilotComponent? pilotComponent) || @@ -174,7 +174,7 @@ namespace Content.Server.Shuttles.EntitySystems EntityManager.RemoveComponent(pilotComponent.Owner); } - public void RemovePilot(IEntity entity) + public void RemovePilot(EntityUid entity) { if (!IoCManager.Resolve().TryGetComponent(entity, out PilotComponent? pilotComponent)) return; diff --git a/Content.Server/Shuttles/EntitySystems/ShuttleSystem.cs b/Content.Server/Shuttles/EntitySystems/ShuttleSystem.cs index af98cf6c03..98d1c9c9cf 100644 --- a/Content.Server/Shuttles/EntitySystems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/ShuttleSystem.cs @@ -52,7 +52,7 @@ namespace Content.Server.Shuttles.EntitySystems private void OnGridInit(GridInitializeEvent ev) { - EntityManager.GetEntity(ev.EntityUid).EnsureComponent(); + ev.EntityUid).EnsureComponent( } private void OnShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args) diff --git a/Content.Server/Singularity/Components/ContainmentFieldConnection.cs b/Content.Server/Singularity/Components/ContainmentFieldConnection.cs index 241e13d8a5..0f6f586c4e 100644 --- a/Content.Server/Singularity/Components/ContainmentFieldConnection.cs +++ b/Content.Server/Singularity/Components/ContainmentFieldConnection.cs @@ -5,7 +5,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; -using Robust.Shared.Physics; using Timer = Robust.Shared.Timing.Timer; namespace Content.Server.Singularity.Components @@ -14,7 +13,7 @@ namespace Content.Server.Singularity.Components { public readonly ContainmentFieldGeneratorComponent Generator1; public readonly ContainmentFieldGeneratorComponent Generator2; - private readonly List _fields = new(); + private readonly List _fields = new(); private int _sharedEnergyPool; private readonly CancellationTokenSource _powerDecreaseCancellationTokenSource = new(); public int SharedEnergyPool @@ -57,7 +56,7 @@ namespace Content.Server.Singularity.Components if (!IoCManager.Resolve().TryGetComponent(newEnt, out var containmentFieldComponent)) { Logger.Error("While creating Fields in ContainmentFieldConnection, a ContainmentField without a ContainmentFieldComponent was created. Deleting newly spawned ContainmentField..."); - IoCManager.Resolve().DeleteEntity((EntityUid) newEnt); + IoCManager.Resolve().DeleteEntity(newEnt); continue; } @@ -72,7 +71,7 @@ namespace Content.Server.Singularity.Components Timer.SpawnRepeating(1000, () => { SharedEnergyPool--;}, _powerDecreaseCancellationTokenSource.Token); } - public bool CanRepell(IEntity toRepell) + public bool CanRepell(EntityUidtoRepell) { var powerNeeded = 1; if (IoCManager.Resolve().TryGetComponent(toRepell, out var singularityComponent)) @@ -88,7 +87,7 @@ namespace Content.Server.Singularity.Components _powerDecreaseCancellationTokenSource.Cancel(); foreach (var field in _fields) { - IoCManager.Resolve().DeleteEntity((EntityUid) field); + IoCManager.Resolve().DeleteEntity(field); } _fields.Clear(); diff --git a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs index e1a0088548..d8d1f5113f 100644 --- a/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs +++ b/Content.Server/Singularity/Components/ContainmentFieldGeneratorComponent.cs @@ -9,7 +9,6 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Physics; -using Robust.Shared.Physics.Broadphase; using Robust.Shared.ViewVariables; namespace Content.Server.Singularity.Components @@ -63,7 +62,7 @@ namespace Content.Server.Singularity.Components private Tuple? _connection1; private Tuple? _connection2; - public bool CanRepell(IEntity toRepell) => _connection1?.Item2?.CanRepell(toRepell) == true || + public bool CanRepell(EntityUidtoRepell) => _connection1?.Item2?.CanRepell(toRepell) == true || _connection2?.Item2?.CanRepell(toRepell) == true; public void OnAnchoredChanged() diff --git a/Content.Server/Singularity/Components/ServerSingularityComponent.cs b/Content.Server/Singularity/Components/ServerSingularityComponent.cs index b9e1a57448..14a4dfc007 100644 --- a/Content.Server/Singularity/Components/ServerSingularityComponent.cs +++ b/Content.Server/Singularity/Components/ServerSingularityComponent.cs @@ -2,15 +2,10 @@ using Content.Shared.Singularity; using Content.Shared.Singularity.Components; using Content.Shared.Sound; using Robust.Shared.Audio; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Physics.Collision; -using Robust.Shared.Physics.Dynamics; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Timing; using Robust.Shared.ViewVariables; namespace Content.Server.Singularity.Components @@ -32,7 +27,7 @@ namespace Content.Server.Singularity.Components _energy = value; if (_energy <= 0) { - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); return; } diff --git a/Content.Server/Singularity/EntitySystems/EmitterSystem.cs b/Content.Server/Singularity/EntitySystems/EmitterSystem.cs index 821be6c9c4..1d6f639009 100644 --- a/Content.Server/Singularity/EntitySystems/EmitterSystem.cs +++ b/Content.Server/Singularity/EntitySystems/EmitterSystem.cs @@ -189,7 +189,7 @@ namespace Content.Server.Singularity.EntitySystems IoCManager.Resolve().GetComponent(projectile).WorldRotation = IoCManager.Resolve().GetComponent(component.Owner).WorldRotation; // TODO: Move to projectile's code. - Timer.Spawn(3000, () => IoCManager.Resolve().DeleteEntity((EntityUid) projectile)); + Timer.Spawn(3000, () => IoCManager.Resolve().DeleteEntity(projectile)); SoundSystem.Play(Filter.Pvs(component.Owner), component.FireSound.GetSound(), component.Owner, AudioHelpers.WithVariation(EmitterComponent.Variation).WithVolume(EmitterComponent.Volume).WithMaxDistance(EmitterComponent.Distance)); diff --git a/Content.Server/Singularity/EntitySystems/SingularitySystem.cs b/Content.Server/Singularity/EntitySystems/SingularitySystem.cs index c8ae54634b..a080ca4eef 100644 --- a/Content.Server/Singularity/EntitySystems/SingularitySystem.cs +++ b/Content.Server/Singularity/EntitySystems/SingularitySystem.cs @@ -99,7 +99,7 @@ namespace Content.Server.Singularity.EntitySystems return component.Level - 0.5f; } - private bool CanDestroy(SharedSingularityComponent component, IEntity entity) + private bool CanDestroy(SharedSingularityComponent component, EntityUid entity) { return entity == component.Owner || IoCManager.Resolve().HasComponent(entity) || @@ -108,7 +108,7 @@ namespace Content.Server.Singularity.EntitySystems IoCManager.Resolve().HasComponent(entity); } - private void HandleDestroy(ServerSingularityComponent component, IEntity entity) + private void HandleDestroy(ServerSingularityComponent component, EntityUid entity) { // TODO: Need singuloimmune tag if (CanDestroy(component, entity)) return; @@ -125,7 +125,7 @@ namespace Content.Server.Singularity.EntitySystems otherSingulo.BeingDeletedByAnotherSingularity = true; } - IoCManager.Resolve().QueueDeleteEntity((EntityUid) entity); + IoCManager.Resolve().QueueDeleteEntity(entity); if (IoCManager.Resolve().TryGetComponent(entity, out var singuloFood)) component.Energy += singuloFood.Energy; @@ -147,7 +147,7 @@ namespace Content.Server.Singularity.EntitySystems } } - private bool CanPull(IEntity entity) + private bool CanPull(EntityUid entity) { return !(IoCManager.Resolve().HasComponent(entity) || IoCManager.Resolve().HasComponent(entity) || diff --git a/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs b/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs index 8b05842d63..2c03f5e679 100644 --- a/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs +++ b/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using Content.Server.Power.Components; using Content.Server.Solar.Components; -using Content.Shared.Physics; using Content.Shared.GameTicking; +using Content.Shared.Physics; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -122,7 +122,7 @@ namespace Content.Server.Solar.EntitySystems } private void UpdatePanelCoverage(SolarPanelComponent panel) { - IEntity entity = panel.Owner; + EntityUid entity = panel.Owner; // So apparently, and yes, I *did* only find this out later, // this is just a really fancy way of saying "Lambert's law of cosines". diff --git a/Content.Server/Spawners/Components/RandomSpawnerComponent.cs b/Content.Server/Spawners/Components/RandomSpawnerComponent.cs index 92326d5917..7b0ae6490c 100644 --- a/Content.Server/Spawners/Components/RandomSpawnerComponent.cs +++ b/Content.Server/Spawners/Components/RandomSpawnerComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.Spawners.Components public override void MapInit() { Spawn(); - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); } } } diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index 2fa3fa2c82..0a6d0dfe88 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Collections.Immutable; using Content.Server.Hands.Components; using Content.Server.Items; using Content.Server.Popups; using Content.Shared.Interaction; -using Content.Shared.Popups; using Content.Shared.Stacks; using Content.Shared.Verbs; using JetBrains.Annotations; @@ -45,7 +42,7 @@ namespace Content.Server.Stack public EntityUid? Split(EntityUid uid, int amount, EntityCoordinates spawnPosition, SharedStackComponent? stack = null) { if (!Resolve(uid, ref stack)) - return null; + return default; // Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked... var prototype = _prototypeManager.TryIndex(stack.StackTypeId, out var stackType) @@ -54,11 +51,10 @@ namespace Content.Server.Stack // Try to remove the amount of things we want to split from the original stack... if (!Use(uid, amount, stack)) - return null; + return default; // Set the output parameter in the event instance to the newly split stack. - IEntity tempQualifier = EntityManager.SpawnEntity(prototype, spawnPosition); - var entity = (EntityUid) tempQualifier; + var entity = EntityManager.SpawnEntity(prototype, spawnPosition); if (EntityManager.TryGetComponent(entity, out SharedStackComponent? stackComp)) { @@ -77,8 +73,7 @@ namespace Content.Server.Stack public EntityUid Spawn(int amount, StackPrototype prototype, EntityCoordinates spawnPosition) { // Set the output result parameter to the new stack entity... - IEntity tempQualifier = EntityManager.SpawnEntity(prototype.Spawn, spawnPosition); - var entity = (EntityUid) tempQualifier; + var entity = EntityManager.SpawnEntity(prototype.Spawn, spawnPosition); var stack = EntityManager.GetComponent(entity); // And finally, set the correct amount! @@ -190,10 +185,11 @@ namespace Content.Server.Stack return; } - if(Split(uid, amount, userTransform.Coordinates, stack) is not {} splitStack) + var split = Split(uid, amount, userTransform.Coordinates, stack); + if (!split.Valid) return; - if (EntityManager.TryGetComponent(splitStack, out var item)) + if (EntityManager.TryGetComponent(split, out var item)) { hands.PutInHandOrDrop(item); } diff --git a/Content.Server/Standing/StandingStateSystem.cs b/Content.Server/Standing/StandingStateSystem.cs index 9b2118df32..3db2003236 100644 --- a/Content.Server/Standing/StandingStateSystem.cs +++ b/Content.Server/Standing/StandingStateSystem.cs @@ -16,20 +16,19 @@ public class StandingStateSystem : EntitySystem var direction = EntityManager.TryGetComponent(uid, out PhysicsComponent? comp) ? comp.LinearVelocity / 50 : Vector2.Zero; var dropAngle = _random.NextFloat(0.8f, 1.2f); - if (EntityManager.TryGetComponent(uid, out HandsComponent? hands)) + if (!EntityManager.TryGetComponent(uid, out HandsComponent? hands)) + return; + + foreach (var heldItem in hands.GetAllHeldItems()) { - foreach (var heldItem in hands.GetAllHeldItems()) - { - if (hands.Drop(heldItem.Owner)) - { - IEntity tempQualifier = EntityManager.GetEntity(uid); - Throwing.ThrowHelper.TryThrow(heldItem.Owner, - _random.NextAngle().RotateVec(direction / dropAngle + - IoCManager.Resolve().GetComponent(tempQualifier).WorldRotation.ToVec() / 50), - 0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f), - EntityManager.GetEntity(uid), 0); - } - } + if (!hands.Drop(heldItem.Owner)) + continue; + + var worldRotation = EntityManager.GetComponent(uid).WorldRotation.ToVec(); + Throwing.ThrowHelper.TryThrow(heldItem.Owner, + _random.NextAngle().RotateVec(direction / dropAngle + worldRotation / 50), + 0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f), + uid, 0); } } diff --git a/Content.Server/StationEvents/Events/GasLeak.cs b/Content.Server/StationEvents/Events/GasLeak.cs index a14db55d77..00f48583e6 100644 --- a/Content.Server/StationEvents/Events/GasLeak.cs +++ b/Content.Server/StationEvents/Events/GasLeak.cs @@ -1,6 +1,4 @@ -using System.Linq; using Content.Server.Atmos.EntitySystems; -using Content.Server.Station; using Content.Shared.Atmos; using Content.Shared.Station; using Robust.Shared.Audio; @@ -16,18 +14,18 @@ namespace Content.Server.StationEvents.Events { internal sealed class GasLeak : StationEvent { - [Dependency] private IRobustRandom _robustRandom = default!; - [Dependency] private IEntityManager _entityManager = default!; + [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; public override string Name => "GasLeak"; - public override string? StartAnnouncement => + public override string StartAnnouncement => "Attention crew, there is a gas leak on the station. We advise you to avoid the area and wear suit internals in the meantime."; // Sourced from https://github.com/vgstation-coders/vgstation13/blob/2c5a491446ab824a8fbbf39bcf656b590e0228df/sound/misc/bloblarm.ogg - public override string? StartAudio => "/Audio/Announcements/bloblarm.ogg"; + public override string StartAudio => "/Audio/Announcements/bloblarm.ogg"; - protected override string? EndAnnouncement => "The source of the gas leak has been fixed. Please be cautious around areas with gas remaining."; + protected override string EndAnnouncement => "The source of the gas leak has been fixed. Please be cautious around areas with gas remaining."; private static readonly Gas[] LeakableGases = { Gas.Plasma, @@ -62,7 +60,7 @@ namespace Content.Server.StationEvents.Events private StationId _targetStation; - private IEntity? _targetGrid; + private EntityUid _targetGrid; private Vector2i _targetTile; @@ -122,15 +120,15 @@ namespace Content.Server.StationEvents.Events var atmosphereSystem = EntitySystem.Get(); if (!_foundTile || - _targetGrid == null || - (!IoCManager.Resolve().EntityExists(_targetGrid) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted || - !atmosphereSystem.IsSimulatedGrid(IoCManager.Resolve().GetComponent(_targetGrid).GridID)) + _targetGrid == default || + (!_entityManager.EntityExists(_targetGrid) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted || + !atmosphereSystem.IsSimulatedGrid(_entityManager.GetComponent(_targetGrid).GridID)) { Running = false; return; } - var environment = atmosphereSystem.GetTileMixture(IoCManager.Resolve().GetComponent(_targetGrid).GridID, _targetTile, true); + var environment = atmosphereSystem.GetTileMixture(_entityManager.GetComponent(_targetGrid).GridID, _targetTile, true); environment?.AdjustMoles(_leakGas, LeakCooldown * _molesPerSecond); } @@ -142,7 +140,7 @@ namespace Content.Server.StationEvents.Events Spark(); _foundTile = false; - _targetGrid = null; + _targetGrid = default; _targetTile = default; _targetCoords = default; _leakGas = Gas.Oxygen; @@ -155,16 +153,16 @@ namespace Content.Server.StationEvents.Events if (_robustRandom.NextFloat() <= SparkChance) { if (!_foundTile || - _targetGrid == null || - (!IoCManager.Resolve().EntityExists(_targetGrid) ? EntityLifeStage.Deleted : IoCManager.Resolve().GetComponent(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted || - !atmosphereSystem.IsSimulatedGrid(IoCManager.Resolve().GetComponent(_targetGrid).GridID)) + _targetGrid == default || + (!_entityManager.EntityExists(_targetGrid) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted || + !atmosphereSystem.IsSimulatedGrid(_entityManager.GetComponent(_targetGrid).GridID)) { return; } // Don't want it to be so obnoxious as to instantly murder anyone in the area but enough that // it COULD start potentially start a bigger fire. - atmosphereSystem.HotspotExpose(IoCManager.Resolve().GetComponent(_targetGrid).GridID, _targetTile, 700f, 50f, true); + atmosphereSystem.HotspotExpose(_entityManager.GetComponent(_targetGrid).GridID, _targetTile, 700f, 50f, true); SoundSystem.Play(Filter.Pvs(_targetCoords), "/Audio/Effects/sparks4.ogg", _targetCoords); } } diff --git a/Content.Server/StationEvents/Events/KudzuGrowth.cs b/Content.Server/StationEvents/Events/KudzuGrowth.cs index 2b3b730693..edc89abff4 100644 --- a/Content.Server/StationEvents/Events/KudzuGrowth.cs +++ b/Content.Server/StationEvents/Events/KudzuGrowth.cs @@ -1,4 +1,3 @@ -using Content.Shared.Station; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -31,7 +30,7 @@ public class KudzuGrowth : StationEvent // Give crew at least 9 minutes to either have it gone, or to suffer another event. Kudzu is not actually required to be dead for another event to roll. protected override float EndAfter => 60*4; - private IEntity? _targetGrid; + private EntityUid _targetGrid; private Vector2i _targetTile; diff --git a/Content.Server/StationEvents/Events/PowerGridCheck.cs b/Content.Server/StationEvents/Events/PowerGridCheck.cs index 8c5c1e0b63..93c424e644 100644 --- a/Content.Server/StationEvents/Events/PowerGridCheck.cs +++ b/Content.Server/StationEvents/Events/PowerGridCheck.cs @@ -28,7 +28,7 @@ namespace Content.Server.StationEvents.Events private CancellationTokenSource? _announceCancelToken; - private readonly List _powered = new(); + private readonly List _powered = new(); public override void Announce() { diff --git a/Content.Server/StationEvents/Events/StationEvent.cs b/Content.Server/StationEvents/Events/StationEvent.cs index 6424d81b16..95303fdffa 100644 --- a/Content.Server/StationEvents/Events/StationEvent.cs +++ b/Content.Server/StationEvents/Events/StationEvent.cs @@ -3,9 +3,8 @@ using Content.Server.Administration.Logs; using Content.Server.Atmos.EntitySystems; using Content.Server.Chat.Managers; using Content.Server.Station; -using Content.Shared.Administration.Logs; -using Content.Shared.Station; using Content.Shared.Database; +using Content.Shared.Station; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -187,7 +186,7 @@ namespace Content.Server.StationEvents.Events } - public static bool TryFindRandomTile(out Vector2i tile, out StationId targetStation, out IEntity? targetGrid, out EntityCoordinates targetCoords, IRobustRandom? robustRandom = null, IEntityManager? entityManager = null) + public static bool TryFindRandomTile(out Vector2i tile, out StationId targetStation, out EntityUid targetGrid, out EntityCoordinates targetCoords, IRobustRandom? robustRandom = null, IEntityManager? entityManager = null) { tile = default; robustRandom ??= IoCManager.Resolve(); diff --git a/Content.Server/Storage/Components/EntityStorageComponent.cs b/Content.Server/Storage/Components/EntityStorageComponent.cs index bdfa7acef0..c854be1fe9 100644 --- a/Content.Server/Storage/Components/EntityStorageComponent.cs +++ b/Content.Server/Storage/Components/EntityStorageComponent.cs @@ -2,10 +2,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Content.Server.Tools; using Content.Server.Ghost.Components; -using Content.Server.Tools.Components; -using Content.Shared.ActionBlocker; +using Content.Server.Tools; using Content.Shared.Acts; using Content.Shared.Body.Components; using Content.Shared.Interaction; @@ -16,8 +14,6 @@ using Content.Shared.Popups; using Content.Shared.Sound; using Content.Shared.Storage; using Content.Shared.Tools; -using Content.Shared.Tools.Components; -using Content.Shared.Verbs; using Robust.Shared.Audio; using Robust.Shared.Containers; using Robust.Shared.GameObjects; @@ -165,7 +161,7 @@ namespace Content.Server.Storage.Components ToggleOpen(eventArgs.User); } - public virtual bool CanOpen(IEntity user, bool silent = false) + public virtual bool CanOpen(EntityUid user, bool silent = false) { if (IsWeldedShut) { @@ -182,12 +178,12 @@ namespace Content.Server.Storage.Components return true; } - public virtual bool CanClose(IEntity user, bool silent = false) + public virtual bool CanClose(EntityUid user, bool silent = false) { return true; } - public void ToggleOpen(IEntity user) + public void ToggleOpen(EntityUid user) { if (Open) { @@ -308,7 +304,7 @@ namespace Content.Server.Storage.Components } } - protected virtual bool AddToContents(IEntity entity) + protected virtual bool AddToContents(EntityUid entity) { if (entity == Owner) return false; if (IoCManager.Resolve().TryGetComponent(entity, out IPhysBody? entityPhysicsComponent)) @@ -343,14 +339,14 @@ namespace Content.Server.Storage.Components } } - public virtual bool TryOpenStorage(IEntity user) + public virtual bool TryOpenStorage(EntityUid user) { if (!CanOpen(user)) return false; OpenStorage(); return true; } - public virtual bool TryCloseStorage(IEntity user) + public virtual bool TryCloseStorage(EntityUid user) { if (!CanClose(user)) return false; CloseStorage(); @@ -358,13 +354,13 @@ namespace Content.Server.Storage.Components } /// - public bool Remove(IEntity entity) + public bool Remove(EntityUid entity) { return Contents.CanRemove(entity); } /// - public bool Insert(IEntity entity) + public bool Insert(EntityUid entity) { // Trying to add while open just dumps it on the ground below us. if (Open) @@ -384,7 +380,7 @@ namespace Content.Server.Storage.Components } /// - public bool CanInsert(IEntity entity) + public bool CanInsert(EntityUid entity) { if (Open) { @@ -447,7 +443,7 @@ namespace Content.Server.Storage.Components EmptyContents(); } - protected virtual IEnumerable DetermineCollidingEntities() + protected virtual IEnumerable DetermineCollidingEntities() { var entityLookup = IoCManager.Resolve(); return entityLookup.GetEntitiesIntersecting(Owner, -0.015f, LookupFlags.Approximate); diff --git a/Content.Server/Storage/Components/IStorageComponent.cs b/Content.Server/Storage/Components/IStorageComponent.cs index 3f7f052d90..85f560b68b 100644 --- a/Content.Server/Storage/Components/IStorageComponent.cs +++ b/Content.Server/Storage/Components/IStorageComponent.cs @@ -4,8 +4,8 @@ namespace Content.Server.Storage.Components { public interface IStorageComponent { - bool Remove(IEntity entity); - bool Insert(IEntity entity); - bool CanInsert(IEntity entity); + bool Remove(EntityUid entity); + bool Insert(EntityUid entity); + bool CanInsert(EntityUid entity); } } diff --git a/Content.Server/Storage/Components/SecretStashComponent.cs b/Content.Server/Storage/Components/SecretStashComponent.cs index cd3dc6b5aa..30a98e34ee 100644 --- a/Content.Server/Storage/Components/SecretStashComponent.cs +++ b/Content.Server/Storage/Components/SecretStashComponent.cs @@ -42,7 +42,7 @@ namespace Content.Server.Storage.Components /// /// /// True if item was hidden inside stash - public bool TryHideItem(IEntity user, IEntity itemToHide) + public bool TryHideItem(EntityUid user, EntityUid itemToHide) { if (_itemContainer.ContainedEntity != null) { @@ -76,7 +76,7 @@ namespace Content.Server.Storage.Components /// /// /// True if user recieved item - public bool TryGetItem(IEntity user) + public bool TryGetItem(EntityUiduser) { if (_itemContainer.ContainedEntity == null) return false; diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs index ca393f8a09..a880527ac2 100644 --- a/Content.Server/Storage/Components/ServerStorageComponent.cs +++ b/Content.Server/Storage/Components/ServerStorageComponent.cs @@ -50,7 +50,7 @@ namespace Content.Server.Storage.Components public Container? Storage; - private readonly Dictionary _sizeCache = new(); + private readonly Dictionary _sizeCache = new(); [DataField("occludesLight")] private bool _occludesLight = true; @@ -79,7 +79,7 @@ namespace Content.Server.Storage.Components public SoundSpecifier StorageSoundCollection { get; set; } = new SoundCollectionSpecifier("storageRustle"); [ViewVariables] - public override IReadOnlyList? StoredEntities => Storage?.ContainedEntities; + public override IReadOnlyList? StoredEntities => Storage?.ContainedEntities; [ViewVariables(VVAccess.ReadWrite)] public bool OccludesLight @@ -129,7 +129,7 @@ namespace Content.Server.Storage.Components foreach (var entity in Storage.ContainedEntities) { - var item = IoCManager.Resolve().GetComponent(entity); + var item = _entityManager.GetComponent(entity); _storageUsed += item.Size; } } @@ -139,17 +139,17 @@ namespace Content.Server.Storage.Components /// /// The entity to check /// true if it can be inserted, false otherwise - public bool CanInsert(IEntity entity) + public bool CanInsert(EntityUid entity) { EnsureInitialCalculated(); - if (IoCManager.Resolve().TryGetComponent(entity, out ServerStorageComponent? storage) && + if (_entityManager.TryGetComponent(entity, out ServerStorageComponent? storage) && storage._storageCapacityMax >= _storageCapacityMax) { return false; } - if (IoCManager.Resolve().TryGetComponent(entity, out SharedItemComponent? store) && + if (_entityManager.TryGetComponent(entity, out SharedItemComponent? store) && store.Size > _storageCapacityMax - _storageUsed) { return false; @@ -160,7 +160,7 @@ namespace Content.Server.Storage.Components return false; } - if (IoCManager.Resolve().GetComponent(entity).Anchored) + if (_entityManager.GetComponent(entity).Anchored) { return false; } @@ -173,12 +173,12 @@ namespace Content.Server.Storage.Components /// /// The entity to insert /// true if the entity was inserted, false otherwise - public bool Insert(IEntity entity) + public bool Insert(EntityUid entity) { return CanInsert(entity) && Storage?.Insert(entity) == true; } - public override bool Remove(IEntity entity) + public override bool Remove(EntityUid entity) { EnsureInitialCalculated(); return Storage?.Remove(entity) == true; @@ -197,7 +197,7 @@ namespace Content.Server.Storage.Components Logger.DebugS(LoggerName, $"Storage (UID {Owner}) had entity (UID {message.Entity}) inserted into it."); var size = 0; - if (IoCManager.Resolve().TryGetComponent(message.Entity, out SharedItemComponent? storable)) + if (_entityManager.TryGetComponent(message.Entity, out SharedItemComponent? storable)) size = storable.Size; _storageUsed += size; @@ -219,7 +219,7 @@ namespace Content.Server.Storage.Components if (!_sizeCache.TryGetValue(message.Entity, out var size)) { - Logger.WarningS(LoggerName, $"Removed entity {message.Entity} without a cached size from storage {Owner} at {IoCManager.Resolve().GetComponent(Owner).MapPosition}"); + Logger.WarningS(LoggerName, $"Removed entity {message.Entity} without a cached size from storage {Owner} at {_entityManager.GetComponent(Owner).MapPosition}"); RecalculateStorageUsed(); return; @@ -235,11 +235,11 @@ namespace Content.Server.Storage.Components /// /// The player to insert an entity from /// true if inserted, false otherwise - public bool PlayerInsertHeldEntity(IEntity player) + public bool PlayerInsertHeldEntity(EntityUid player) { EnsureInitialCalculated(); - if (!IoCManager.Resolve().TryGetComponent(player, out HandsComponent? hands) || + if (!_entityManager.TryGetComponent(player, out HandsComponent? hands) || hands.GetActiveHand == null) { return false; @@ -269,7 +269,7 @@ namespace Content.Server.Storage.Components /// /// The player to insert an entity with /// true if inserted, false otherwise - public bool PlayerInsertEntityInWorld(IEntity player, IEntity toInsert) + public bool PlayerInsertEntityInWorld(EntityUid player, EntityUid toInsert) { EnsureInitialCalculated(); @@ -285,14 +285,14 @@ namespace Content.Server.Storage.Components /// Opens the storage UI for an entity /// /// The entity to open the UI for - public void OpenStorageUI(IEntity entity) + public void OpenStorageUI(EntityUid entity) { PlaySoundCollection(); EnsureInitialCalculated(); - var userSession = IoCManager.Resolve().GetComponent(entity).PlayerSession; + var userSession = _entityManager.GetComponent(entity).PlayerSession; - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) \"used\" by player session (UID {userSession.AttachedEntityUid})."); + Logger.DebugS(LoggerName, $"Storage (UID {Owner}) \"used\" by player session (UID {userSession.AttachedEntity})."); SubscribeSession(userSession); #pragma warning disable 618 @@ -320,7 +320,7 @@ namespace Content.Server.Storage.Components { if (session.AttachedEntity == null) { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) detected no attached entity in player session (UID {session.AttachedEntityUid})."); + Logger.DebugS(LoggerName, $"Storage (UID {Owner}) detected no attached entity in player session (UID {session.AttachedEntity})."); UnsubscribeSession(session); return; @@ -340,7 +340,7 @@ namespace Content.Server.Storage.Components return; } - var stored = StoredEntities.Select(e => (EntityUid) e).ToArray(); + var stored = StoredEntities.Select(e => e).ToArray(); #pragma warning disable 618 SendNetworkMessage(new StorageHeldItemsMessage(stored, _storageUsed, _storageCapacityMax), session.ConnectedClient); @@ -357,7 +357,7 @@ namespace Content.Server.Storage.Components if (!SubscribedSessions.Contains(session)) { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) subscribed player session (UID {session.AttachedEntityUid})."); + Logger.DebugS(LoggerName, $"Storage (UID {Owner}) subscribed player session (UID {session.AttachedEntity})."); session.PlayerStatusChanged += HandlePlayerSessionChangeEvent; SubscribedSessions.Add(session); @@ -375,7 +375,7 @@ namespace Content.Server.Storage.Components { if (SubscribedSessions.Contains(session)) { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) unsubscribed player session (UID {session.AttachedEntityUid})."); + Logger.DebugS(LoggerName, $"Storage (UID {Owner}) unsubscribed player session (UID {session.AttachedEntity})."); SubscribedSessions.Remove(session); #pragma warning disable 618 @@ -418,7 +418,7 @@ namespace Content.Server.Storage.Components private void HandlePlayerSessionChangeEvent(object? obj, SessionStatusEventArgs sessionStatus) { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) handled a status change in player session (UID {sessionStatus.Session.AttachedEntityUid})."); + Logger.DebugS(LoggerName, $"Storage (UID {Owner}) handled a status change in player session (UID {sessionStatus.Session.AttachedEntity})."); if (sessionStatus.NewStatus != SessionStatus.InGame) { @@ -454,26 +454,26 @@ namespace Content.Server.Storage.Components var player = session.AttachedEntity; - if (player == null) + if (!player.Valid) { break; } - var ownerTransform = IoCManager.Resolve().GetComponent(Owner); - var playerTransform = IoCManager.Resolve().GetComponent(player); + var ownerTransform = _entityManager.GetComponent(Owner); + var playerTransform = _entityManager.GetComponent(player); - if (!playerTransform.Coordinates.InRange(IoCManager.Resolve(), ownerTransform.Coordinates, 2) || + if (!playerTransform.Coordinates.InRange(_entityManager, ownerTransform.Coordinates, 2) || Owner.IsInContainer() && !playerTransform.ContainsEntity(ownerTransform)) { break; } - if (!IoCManager.Resolve().TryGetEntity(remove.EntityUid, out var entity) || Storage?.Contains(entity) == false) + if (!remove.EntityUid.Valid || Storage?.Contains(remove.EntityUid) == false) { break; } - if (!IoCManager.Resolve().TryGetComponent(entity, out ItemComponent? item) || !IoCManager.Resolve().TryGetComponent(player, out HandsComponent? hands)) + if (!_entityManager.TryGetComponent(remove.EntityUid, out ItemComponent? item) || !_entityManager.TryGetComponent(player, out HandsComponent? hands)) { break; } @@ -531,7 +531,7 @@ namespace Content.Server.Storage.Components return false; Logger.DebugS(LoggerName, $"Storage (UID {Owner}) attacked by user (UID {eventArgs.User}) with entity (UID {eventArgs.Using})."); - if (IoCManager.Resolve().HasComponent(Owner)) + if (_entityManager.HasComponent(Owner)) { return false; } @@ -570,14 +570,14 @@ namespace Content.Server.Storage.Components // Pick up all entities in a radius around the clicked location. // The last half of the if is because carpets exist and this is terrible - if (_areaInsert && (eventArgs.Target == null || !IoCManager.Resolve().HasComponent(eventArgs.Target))) + if (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent(eventArgs.Target))) { - var validStorables = new List(); + var validStorables = new List(); foreach (var entity in IoCManager.Resolve().GetEntitiesInRange(eventArgs.ClickLocation, _areaInsertRadius, LookupFlags.None)) { if (entity.IsInContainer() || entity == eventArgs.User - || !IoCManager.Resolve().HasComponent(entity) + || !_entityManager.HasComponent(entity) || !EntitySystem.Get().InRangeUnobstructed(eventArgs.User, entity)) continue; validStorables.Add(entity); @@ -605,9 +605,9 @@ namespace Content.Server.Storage.Components // Check again, situation may have changed for some entities, but we'll still pick up any that are valid if (entity.IsInContainer() || entity == eventArgs.User - || !IoCManager.Resolve().HasComponent(entity)) + || !_entityManager.HasComponent(entity)) continue; - var position = EntityCoordinates.FromMap(IoCManager.Resolve().GetComponent(Owner).Parent?.Owner ?? Owner, IoCManager.Resolve().GetComponent(entity).MapPosition); + var position = EntityCoordinates.FromMap(_entityManager.GetComponent(Owner).Parent?.Owner ?? Owner, _entityManager.GetComponent(entity).MapPosition); if (PlayerInsertEntityInWorld(eventArgs.User, entity)) { successfullyInserted.Add(entity); @@ -633,19 +633,25 @@ namespace Content.Server.Storage.Components // Pick up the clicked entity else if (_quickInsert) { - if (eventArgs.Target == null - || eventArgs.Target.IsInContainer() - || eventArgs.Target == eventArgs.User - || !IoCManager.Resolve().HasComponent(eventArgs.Target)) + if (eventArgs.Target is not {Valid: true} target) + { return false; - var position = EntityCoordinates.FromMap(IoCManager.Resolve().GetComponent(Owner).Parent?.Owner ?? Owner, IoCManager.Resolve().GetComponent(eventArgs.Target).MapPosition); - if (PlayerInsertEntityInWorld(eventArgs.User, eventArgs.Target)) + } + + if (target.IsInContainer() + || target == eventArgs.User + || !_entityManager.HasComponent(target)) + return false; + var position = EntityCoordinates.FromMap( + _entityManager.GetComponent(Owner).Parent?.Owner ?? Owner, + _entityManager.GetComponent(target).MapPosition); + if (PlayerInsertEntityInWorld(eventArgs.User, target)) { #pragma warning disable 618 SendNetworkMessage(new AnimateInsertingEntitiesMessage( #pragma warning restore 618 - new List() {eventArgs.Target}, - new List() { position } + new List {target}, + new List {position} )); return true; } @@ -685,7 +691,7 @@ namespace Content.Server.Storage.Components foreach (var entity in storedEntities) { - var exActs = IoCManager.Resolve().GetComponents(entity).ToArray(); + var exActs = _entityManager.GetComponents(entity).ToArray(); foreach (var exAct in exActs) { exAct.OnExplosion(eventArgs); diff --git a/Content.Server/Storage/EntitySystems/ItemMapperSystem.cs b/Content.Server/Storage/EntitySystems/ItemMapperSystem.cs index 121efadb62..62dfff8d2d 100644 --- a/Content.Server/Storage/EntitySystems/ItemMapperSystem.cs +++ b/Content.Server/Storage/EntitySystems/ItemMapperSystem.cs @@ -3,7 +3,6 @@ using Content.Server.Storage.Components; using Content.Shared.Storage.Components; using Content.Shared.Storage.EntitySystems; using JetBrains.Annotations; -using Robust.Shared.Analyzers; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -19,7 +18,7 @@ namespace Content.Server.Storage.EntitySystems { if (IoCManager.Resolve().TryGetComponent(msg.Container.Owner, out ServerStorageComponent? component)) { - var containedLayers = component.StoredEntities ?? new List(); + var containedLayers = component.StoredEntities ?? new List(); var list = new List(); foreach (var mapLayerData in itemMapper.MapLayers.Values) { diff --git a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs index 3f49223706..929d9bd084 100644 --- a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs +++ b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs @@ -26,9 +26,8 @@ namespace Content.Server.Storage.EntitySystems if (args.Handled) return; - var owner = EntityManager.GetEntity(uid); var alreadySpawnedGroups = new List(); - IEntity? entityToPlaceInHands = null; + EntityUid entityToPlaceInHands = default; foreach (var storageItem in component.Items) { if (!string.IsNullOrEmpty(storageItem.GroupId) && @@ -42,24 +41,24 @@ namespace Content.Server.Storage.EntitySystems for (var i = 0; i < storageItem.Amount; i++) { - entityToPlaceInHands = EntityManager.SpawnEntity(storageItem.PrototypeId, IoCManager.Resolve().GetComponent(args.User).Coordinates); + entityToPlaceInHands = EntityManager.SpawnEntity(storageItem.PrototypeId, EntityManager.GetComponent(args.User).Coordinates); } if (!string.IsNullOrEmpty(storageItem.GroupId)) alreadySpawnedGroups.Add(storageItem.GroupId); } if (component.Sound != null) - SoundSystem.Play(Filter.Pvs(owner), component.Sound.GetSound()); + SoundSystem.Play(Filter.Pvs(uid), component.Sound.GetSound()); component.Uses--; if (component.Uses == 0) { args.Handled = true; - IoCManager.Resolve().DeleteEntity((EntityUid) owner); + EntityManager.DeleteEntity(uid); } - if (entityToPlaceInHands != null - && IoCManager.Resolve().TryGetComponent(args.User, out var hands)) + if (entityToPlaceInHands != default + && EntityManager.TryGetComponent(args.User, out var hands)) { hands.TryPutInAnyHand(entityToPlaceInHands); } diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 0858273f5d..a881ded3b1 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -2,16 +2,16 @@ using System.Collections.Generic; using Content.Server.Hands.Components; using Content.Server.Interaction; using Content.Server.Storage.Components; -using Content.Shared.Verbs; using Content.Shared.Movement; +using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Timing; using Robust.Shared.Localization; +using Robust.Shared.Timing; namespace Content.Server.Storage.EntitySystems { @@ -37,17 +37,17 @@ namespace Content.Server.Storage.EntitySystems private void OnRelayMovement(EntityUid uid, EntityStorageComponent component, RelayMovementEntityEvent args) { - if (EntityManager.HasComponent(args.Entity)) - { - if (_gameTiming.CurTime < - component.LastInternalOpenAttempt + EntityStorageComponent.InternalOpenAttemptDelay) - { - return; - } + if (!EntityManager.HasComponent(args.Entity)) + return; - component.LastInternalOpenAttempt = _gameTiming.CurTime; - component.TryOpenStorage(args.Entity); + if (_gameTiming.CurTime < + component.LastInternalOpenAttempt + EntityStorageComponent.InternalOpenAttemptDelay) + { + return; } + + component.LastInternalOpenAttempt = _gameTiming.CurTime; + component.TryOpenStorage(args.Entity); } /// diff --git a/Content.Server/Strip/StrippableComponent.cs b/Content.Server/Strip/StrippableComponent.cs index cee2d55d91..47e7ce68d4 100644 --- a/Content.Server/Strip/StrippableComponent.cs +++ b/Content.Server/Strip/StrippableComponent.cs @@ -95,7 +95,7 @@ namespace Content.Server.Strip return dictionary; } - foreach (IEntity entity in cuffed.StoredEntities) + foreach (EntityUid entity in cuffed.StoredEntities) { dictionary.Add(entity, entity.Name); } @@ -158,7 +158,7 @@ namespace Content.Server.Strip /// /// Places item in user's active hand to an inventory slot. /// - private async void PlaceActiveHandItemInInventory(IEntity user, Slots slot) + private async void PlaceActiveHandItemInInventory(EntityUid user, Slots slot) { var inventory = IoCManager.Resolve().GetComponent(Owner); var userHands = IoCManager.Resolve().GetComponent(user); @@ -223,7 +223,7 @@ namespace Content.Server.Strip /// /// Places item in user's active hand in one of the entity's hands. /// - private async void PlaceActiveHandItemInHands(IEntity user, string hand) + private async void PlaceActiveHandItemInHands(EntityUid user, string hand) { var hands = IoCManager.Resolve().GetComponent(Owner); var userHands = IoCManager.Resolve().GetComponent(user); @@ -289,7 +289,7 @@ namespace Content.Server.Strip /// /// Takes an item from the inventory and places it in the user's active hand. /// - private async void TakeItemFromInventory(IEntity user, Slots slot) + private async void TakeItemFromInventory(EntityUid user, Slots slot) { var inventory = IoCManager.Resolve().GetComponent(Owner); var userHands = IoCManager.Resolve().GetComponent(user); @@ -345,7 +345,7 @@ namespace Content.Server.Strip /// /// Takes an item from a hand and places it in the user's active hand. /// - private async void TakeItemFromHands(IEntity user, string hand) + private async void TakeItemFromHands(EntityUid user, string hand) { var hands = IoCManager.Resolve().GetComponent(Owner); var userHands = IoCManager.Resolve().GetComponent(user); diff --git a/Content.Server/Stunnable/StunOnCollideSystem.cs b/Content.Server/Stunnable/StunOnCollideSystem.cs index cc3d1e5863..026d5fa2f5 100644 --- a/Content.Server/Stunnable/StunOnCollideSystem.cs +++ b/Content.Server/Stunnable/StunOnCollideSystem.cs @@ -1,11 +1,8 @@ using System; using Content.Server.Alert; using Content.Server.Stunnable.Components; -using Content.Shared.Alert; -using Content.Shared.Movement.Components; using Content.Shared.Standing; using Content.Shared.StatusEffect; -using Content.Shared.Stunnable; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -26,7 +23,7 @@ namespace Content.Server.Stunnable private void HandleCollide(EntityUid uid, StunOnCollideComponent component, StartCollideEvent args) { - var otherUid = (EntityUid) args.OtherFixture.Body.Owner; + var otherUid = args.OtherFixture.Body.Owner; if (EntityManager.TryGetComponent(otherUid, out var status)) { diff --git a/Content.Server/Stunnable/StunbatonSystem.cs b/Content.Server/Stunnable/StunbatonSystem.cs index 82af37fc2d..dfda1a94f3 100644 --- a/Content.Server/Stunnable/StunbatonSystem.cs +++ b/Content.Server/Stunnable/StunbatonSystem.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using Content.Server.Items; -using Content.Server.Jittering; using Content.Server.PowerCell.Components; using Content.Server.Speech.EntitySystems; using Content.Server.Stunnable.Components; @@ -11,7 +10,6 @@ using Content.Shared.Audio; using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Jittering; -using Content.Shared.Popups; using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Content.Shared.Throwing; @@ -53,7 +51,7 @@ namespace Content.Server.Stunnable if (!EntityManager.TryGetComponent(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse)) return; - foreach (IEntity entity in args.HitEntities) + foreach (EntityUid entity in args.HitEntities) { StunEntity(entity, comp); } @@ -119,7 +117,7 @@ namespace Content.Server.Stunnable args.PushMarkup(msg); } - private void StunEntity(IEntity entity, StunbatonComponent comp) + private void StunEntity(EntityUid entity, StunbatonComponent comp) { if (!IoCManager.Resolve().TryGetComponent(entity, out StatusEffectsComponent? status) || !comp.Activated) return; @@ -169,7 +167,7 @@ namespace Content.Server.Stunnable comp.Activated = false; } - private void TurnOn(StunbatonComponent comp, IEntity user) + private void TurnOn(StunbatonComponent comp, EntityUiduser) { if (comp.Activated) { diff --git a/Content.Server/Tabletop/TabletopChessSetup.cs b/Content.Server/Tabletop/TabletopChessSetup.cs index a96e74a34d..d77d218391 100644 --- a/Content.Server/Tabletop/TabletopChessSetup.cs +++ b/Content.Server/Tabletop/TabletopChessSetup.cs @@ -35,9 +35,9 @@ namespace Content.Server.Tabletop SpawnPiecesRow(session, entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation); // Extra queens - IEntity tempQualifier = entityManager.SpawnEntity("BlackQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 3 * separation, mapId)); + EntityUidtempQualifier = entityManager.SpawnEntity("BlackQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 3 * separation, mapId)); session.Entities.Add(tempQualifier); - IEntity tempQualifier1 = entityManager.SpawnEntity("WhiteQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 4 * separation, mapId)); + EntityUidtempQualifier1 = entityManager.SpawnEntity("WhiteQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 4 * separation, mapId)); session.Entities.Add(tempQualifier1); } @@ -53,23 +53,23 @@ namespace Content.Server.Tabletop switch (piecesRow[i]) { case 'r': - IEntity tempQualifier = entityManager.SpawnEntity(color + "Rook", new MapCoordinates(x + i * separation, y, mapId)); + EntityUidtempQualifier = entityManager.SpawnEntity(color + "Rook", new MapCoordinates(x + i * separation, y, mapId)); session.Entities.Add(tempQualifier); break; case 'n': - IEntity tempQualifier1 = entityManager.SpawnEntity(color + "Knight", new MapCoordinates(x + i * separation, y, mapId)); + EntityUidtempQualifier1 = entityManager.SpawnEntity(color + "Knight", new MapCoordinates(x + i * separation, y, mapId)); session.Entities.Add(tempQualifier1); break; case 'b': - IEntity tempQualifier2 = entityManager.SpawnEntity(color + "Bishop", new MapCoordinates(x + i * separation, y, mapId)); + EntityUidtempQualifier2 = entityManager.SpawnEntity(color + "Bishop", new MapCoordinates(x + i * separation, y, mapId)); session.Entities.Add(tempQualifier2); break; case 'q': - IEntity tempQualifier3 = entityManager.SpawnEntity(color + "Queen", new MapCoordinates(x + i * separation, y, mapId)); + EntityUidtempQualifier3 = entityManager.SpawnEntity(color + "Queen", new MapCoordinates(x + i * separation, y, mapId)); session.Entities.Add(tempQualifier3); break; case 'k': - IEntity tempQualifier4 = entityManager.SpawnEntity(color + "King", new MapCoordinates(x + i * separation, y, mapId)); + EntityUidtempQualifier4 = entityManager.SpawnEntity(color + "King", new MapCoordinates(x + i * separation, y, mapId)); session.Entities.Add(tempQualifier4); break; } @@ -83,7 +83,7 @@ namespace Content.Server.Tabletop for (int i = 0; i < 8; i++) { - IEntity tempQualifier = entityManager.SpawnEntity(color + "Pawn", new MapCoordinates(x + i * separation, y, mapId)); + EntityUidtempQualifier = entityManager.SpawnEntity(color + "Pawn", new MapCoordinates(x + i * separation, y, mapId)); session.Entities.Add(tempQualifier); } } diff --git a/Content.Server/Tabletop/TabletopParchisSetup.cs b/Content.Server/Tabletop/TabletopParchisSetup.cs index 85501e8eb2..a5f69fdd58 100644 --- a/Content.Server/Tabletop/TabletopParchisSetup.cs +++ b/Content.Server/Tabletop/TabletopParchisSetup.cs @@ -35,43 +35,43 @@ namespace Content.Server.Tabletop var center = session.Position; // Red pieces. - IEntity tempQualifier = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y1)); + EntityUidtempQualifier = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y1)); session.Entities.Add(tempQualifier); - IEntity tempQualifier1 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y2)); + EntityUidtempQualifier1 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x1, -y2)); session.Entities.Add(tempQualifier1); - IEntity tempQualifier2 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y1)); + EntityUidtempQualifier2 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y1)); session.Entities.Add(tempQualifier2); - IEntity tempQualifier3 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y2)); + EntityUidtempQualifier3 = entityManager.SpawnEntity(RedPiecePrototype, center.Offset(-x2, -y2)); session.Entities.Add(tempQualifier3); // Green pieces. - IEntity tempQualifier4 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y1)); + EntityUidtempQualifier4 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y1)); session.Entities.Add(tempQualifier4); - IEntity tempQualifier5 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y2)); + EntityUidtempQualifier5 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x1, -y2)); session.Entities.Add(tempQualifier5); - IEntity tempQualifier6 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y1)); + EntityUidtempQualifier6 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y1)); session.Entities.Add(tempQualifier6); - IEntity tempQualifier7 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y2)); + EntityUidtempQualifier7 = entityManager.SpawnEntity(GreenPiecePrototype, center.Offset(x2, -y2)); session.Entities.Add(tempQualifier7); // Yellow pieces. - IEntity tempQualifier8 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y1)); + EntityUidtempQualifier8 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y1)); session.Entities.Add(tempQualifier8); - IEntity tempQualifier9 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y2)); + EntityUidtempQualifier9 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x1, y2)); session.Entities.Add(tempQualifier9); - IEntity tempQualifier10 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y1)); + EntityUidtempQualifier10 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y1)); session.Entities.Add(tempQualifier10); - IEntity tempQualifier11 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y2)); + EntityUidtempQualifier11 = entityManager.SpawnEntity(YellowPiecePrototype, center.Offset(x2, y2)); session.Entities.Add(tempQualifier11); // Blue pieces. - IEntity tempQualifier12 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y1)); + EntityUidtempQualifier12 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y1)); session.Entities.Add(tempQualifier12); - IEntity tempQualifier13 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y2)); + EntityUidtempQualifier13 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x1, y2)); session.Entities.Add(tempQualifier13); - IEntity tempQualifier14 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y1)); + EntityUidtempQualifier14 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y1)); session.Entities.Add(tempQualifier14); - IEntity tempQualifier15 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y2)); + EntityUidtempQualifier15 = entityManager.SpawnEntity(BluePiecePrototype, center.Offset(-x2, y2)); session.Entities.Add(tempQualifier15); } } diff --git a/Content.Server/Tabletop/TabletopSystem.Draggable.cs b/Content.Server/Tabletop/TabletopSystem.Draggable.cs index 71562a159b..d5e20b086e 100644 --- a/Content.Server/Tabletop/TabletopSystem.Draggable.cs +++ b/Content.Server/Tabletop/TabletopSystem.Draggable.cs @@ -25,7 +25,7 @@ namespace Content.Server.Tabletop /// private void OnTabletopMove(TabletopMoveEvent msg, EntitySessionEventArgs args) { - if (args.SenderSession as IPlayerSession is not { AttachedEntityUid: { } playerEntity } playerSession) + if (args.SenderSession as IPlayerSession is not { AttachedEntity: { } playerEntity } playerSession) return; if (!EntityManager.TryGetComponent(msg.TableUid, out TabletopGameComponent? tabletop) || tabletop.Session is not {} session) @@ -43,7 +43,7 @@ namespace Content.Server.Tabletop return; // Check if moved entity exists and has tabletop draggable component - if (!EntityManager.TryGetEntity(msg.MovedEntityUid, out var movedEntity)) + if (!EntityManager.EntityExists(msg.MovedEntityUid) return; if (!EntityManager.HasComponent(movedEntity)) @@ -59,7 +59,7 @@ namespace Content.Server.Tabletop private void OnDraggingPlayerChanged(TabletopDraggingPlayerChangedEvent msg) { - var draggedEntity = EntityManager.GetEntity(msg.DraggedEntityUid); + var draggedmsg.DraggedEntityUid if (!IoCManager.Resolve().TryGetComponent(draggedEntity, out var draggableComponent)) return; diff --git a/Content.Server/Toilet/ToiletComponent.cs b/Content.Server/Toilet/ToiletComponent.cs index 9ef10fb061..a753d902a9 100644 --- a/Content.Server/Toilet/ToiletComponent.cs +++ b/Content.Server/Toilet/ToiletComponent.cs @@ -15,7 +15,6 @@ using Content.Shared.Popups; using Content.Shared.Sound; using Content.Shared.Toilet; using Content.Shared.Tools; -using Content.Shared.Tools.Components; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -150,7 +149,7 @@ namespace Content.Server.Toilet } } - SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat) + SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat) { // check that victim even have head if (IoCManager.Resolve().TryGetComponent(victim, out var body) && diff --git a/Content.Server/Tools/Components/TilePryingComponent.cs b/Content.Server/Tools/Components/TilePryingComponent.cs index efa25dec18..108848d0b3 100644 --- a/Content.Server/Tools/Components/TilePryingComponent.cs +++ b/Content.Server/Tools/Components/TilePryingComponent.cs @@ -3,7 +3,6 @@ using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Maps; using Content.Shared.Tools; -using Content.Shared.Tools.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; @@ -32,7 +31,7 @@ namespace Content.Server.Tools.Components return true; } - public async void TryPryTile(IEntity user, EntityCoordinates clickLocation) + public async void TryPryTile(EntityUid user, EntityCoordinates clickLocation) { if (!IoCManager.Resolve().TryGetComponent(Owner, out var tool) && _toolComponentNeeded) return; diff --git a/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs b/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs index 8bf95e0101..31d5584e83 100644 --- a/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs +++ b/Content.Server/Traitor/Uplink/Account/UplinkAccountsSystem.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using Content.Server.Mind.Components; -using Content.Server.Stack; using Content.Shared.Stacks; using Content.Shared.Traitor.Uplink; using Robust.Shared.GameObjects; @@ -71,7 +69,7 @@ namespace Content.Server.Traitor.Uplink.Account } - public bool TryPurchaseItem(UplinkAccount acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out IEntity? purchasedItem) + public bool TryPurchaseItem(UplinkAccount acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out EntityUid purchasedItem) { purchasedItem = null; diff --git a/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs b/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs index 6b0add0d5e..33e6d43264 100644 --- a/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs +++ b/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs @@ -43,7 +43,7 @@ namespace Content.Server.Traitor.Uplink.Commands var user = session.AttachedEntity; // Get target item - IEntity? uplinkEntity = null; + EntityUid uplinkEntity = null; var entityManager = IoCManager.Resolve(); if (args.Length >= 2) { @@ -60,7 +60,7 @@ namespace Content.Server.Traitor.Uplink.Commands return; } - uplinkEntity = entityManager.GetEntity(eUid); + uplinkeUid } // Get TC count diff --git a/Content.Server/Traitor/Uplink/UplinkSystem.cs b/Content.Server/Traitor/Uplink/UplinkSystem.cs index 426527be16..cdbbfcad77 100644 --- a/Content.Server/Traitor/Uplink/UplinkSystem.cs +++ b/Content.Server/Traitor/Uplink/UplinkSystem.cs @@ -154,7 +154,7 @@ namespace Content.Server.Traitor.Uplink // try to put it into players hands if (IoCManager.Resolve().TryGetComponent(player, out SharedHandsComponent? hands)) - hands.TryPutInAnyHand(EntityManager.GetEntity(tcUid.Value)); + hands.TryPutInAnyHand(tcUid.Value) // play buying sound SoundSystem.Play(Filter.SinglePlayer(args.Session), uplink.BuySuccessSound.GetSound(), @@ -189,7 +189,7 @@ namespace Content.Server.Traitor.Uplink ui.SetState(new UplinkUpdateState(accData, listings)); } - public bool AddUplink(IEntity user, UplinkAccount account, IEntity? uplinkEntity = null) + public bool AddUplink(EntityUid user, UplinkAccount account, EntityUid uplinkEntity = null) { // Try to find target item if (uplinkEntity == null) @@ -205,7 +205,7 @@ namespace Content.Server.Traitor.Uplink return true; } - private IEntity? FindUplinkTarget(IEntity user) + private EntityUid FindUplinkTarget(EntityUiduser) { // Try to find PDA in inventory if (IoCManager.Resolve().TryGetComponent(user, out InventoryComponent? inventory)) diff --git a/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs b/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs index 622d298327..d1e68313c4 100644 --- a/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs +++ b/Content.Server/TraitorDeathMatch/Components/TraitorDeathMatchRedemptionComponent.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using Content.Server.Inventory.Components; using Content.Server.Mind.Components; -using Content.Server.PDA; using Content.Server.Traitor.Uplink.Account; using Content.Server.Traitor.Uplink.Components; using Content.Shared.Interaction; @@ -111,7 +110,7 @@ namespace Content.Server.TraitorDeathMatch.Components accounts.SetBalance(victimAccount, 0); accounts.AddToBalance(userAccount, transferAmount); - IoCManager.Resolve().DeleteEntity((EntityUid) victimUplink.Owner); + IoCManager.Resolve().DeleteEntity(victimUplink.Owner); Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-success-message", ("tcAmount", transferAmount))); return true; diff --git a/Content.Server/UserInterface/ActivatableUISystem.cs b/Content.Server/UserInterface/ActivatableUISystem.cs index ae57fdfbc1..504986ba35 100644 --- a/Content.Server/UserInterface/ActivatableUISystem.cs +++ b/Content.Server/UserInterface/ActivatableUISystem.cs @@ -1,23 +1,15 @@ using System.Linq; -using Content.Shared; -using Content.Shared.CCVar; +using Content.Server.Administration.Managers; using Content.Shared.ActionBlocker; using Content.Shared.Hands; -using Content.Shared.Popups; -using Content.Shared.Standing; -using Content.Shared.Stunnable; -using Content.Shared.Throwing; using Content.Shared.Interaction; -using Content.Shared.Interaction.Helpers; -using Content.Server.Administration.Managers; +using Content.Shared.Popups; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.Player; -using Robust.Shared.Configuration; -using Robust.Shared.Localization; using Robust.Shared.GameObjects; -using Robust.Shared.Network; using Robust.Shared.IoC; +using Robust.Shared.Localization; namespace Content.Server.UserInterface { @@ -65,7 +57,7 @@ namespace Content.Server.UserInterface SetCurrentSingleUser(uid, null, component); } - private bool InteractUI(IEntity user, ActivatableUIComponent aui) + private bool InteractUI(EntityUid user, ActivatableUIComponent aui) { if (!IoCManager.Resolve().TryGetComponent(user, out ActorComponent? actor)) return false; @@ -124,7 +116,7 @@ namespace Content.Server.UserInterface // Must ToList in order to close things safely. foreach (var session in ui.SubscribedSessions.ToArray()) { - if (session.AttachedEntityUid == null || !_actionBlockerSystem.CanInteract(session.AttachedEntityUid.Value)) + if (session.AttachedEntity == null || !_actionBlockerSystem.CanInteract(session.AttachedEntity.Value)) { ui.Close(session); } @@ -141,8 +133,8 @@ namespace Content.Server.UserInterface public class ActivatableUIOpenAttemptEvent : CancellableEntityEventArgs { - public IEntity User { get; } - public ActivatableUIOpenAttemptEvent(IEntity who) + public EntityUidUser { get; } + public ActivatableUIOpenAttemptEvent(EntityUidwho) { User = who; } diff --git a/Content.Server/VendingMachines/VendingMachineComponent.cs b/Content.Server/VendingMachines/VendingMachineComponent.cs index c61bde068b..52ea270bb7 100644 --- a/Content.Server/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/VendingMachines/VendingMachineComponent.cs @@ -3,13 +3,11 @@ using System.Collections.Generic; using System.Linq; using Content.Server.Access.Components; using Content.Server.Access.Systems; -using Content.Server.Advertise; using Content.Server.Popups; using Content.Server.Power.Components; using Content.Server.UserInterface; using Content.Server.WireHacking; using Content.Shared.Acts; -using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Sound; using Content.Shared.VendingMachines; @@ -22,7 +20,6 @@ using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; using Robust.Shared.ViewVariables; using static Content.Shared.Wires.SharedWiresComponent; @@ -191,7 +188,7 @@ namespace Content.Server.VendingMachines SoundSystem.Play(Filter.Pvs(Owner), _soundVend.GetSound(), Owner, AudioParams.Default.WithVolume(-2f)); } - private void TryEject(string id, IEntity? sender) + private void TryEject(string id, EntityUid sender) { if (IoCManager.Resolve().TryGetComponent(Owner, out var accessReader)) { diff --git a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs index 3d38cb9dba..a97905be3f 100644 --- a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs +++ b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Net.Security; using Content.Server.Administration; using Content.Shared.Administration; using Content.Shared.Verbs; @@ -30,7 +29,7 @@ namespace Content.Server.Verbs.Commands var verbSystem = EntitySystem.Get(); // get the 'player' entity (defaulting to command user, otherwise uses a uid) - IEntity? playerEntity = null; + EntityUid playerEntity = null; if (!int.TryParse(args[0], out var intPlayerUid)) { if (args[0] == "self" && shell.Player?.AttachedEntity != null) @@ -45,7 +44,7 @@ namespace Content.Server.Verbs.Commands } else { - entityManager.TryGetEntity(new EntityUid(intPlayerUid), out playerEntity); + entityManager.EntityExists(new EntityUid(intPlayerUid)); } // gets the target entity @@ -62,7 +61,7 @@ namespace Content.Server.Verbs.Commands } var entUid = new EntityUid(intUid); - if (!entityManager.TryGetEntity(entUid, out var target)) + if (!entityManager.EntityExists(entUid) { shell.WriteError(Loc.GetString("invoke-verb-command-invalid-target-entity")); return; diff --git a/Content.Server/Verbs/Commands/ListVerbsCommand.cs b/Content.Server/Verbs/Commands/ListVerbsCommand.cs index 57a27ba900..675b90403f 100644 --- a/Content.Server/Verbs/Commands/ListVerbsCommand.cs +++ b/Content.Server/Verbs/Commands/ListVerbsCommand.cs @@ -27,7 +27,7 @@ namespace Content.Server.Verbs.Commands var verbSystem = EntitySystem.Get(); // get the 'player' entity (defaulting to command user, otherwise uses a uid) - IEntity? playerEntity = null; + EntityUid playerEntity = null; if (!int.TryParse(args[0], out var intPlayerUid)) { if (args[0] == "self" && shell.Player?.AttachedEntity != null) @@ -42,7 +42,7 @@ namespace Content.Server.Verbs.Commands } else { - entityManager.TryGetEntity(new EntityUid(intPlayerUid), out playerEntity); + entityManager.EntityExists(new EntityUid(intPlayerUid)); } // gets the target entity @@ -59,7 +59,7 @@ namespace Content.Server.Verbs.Commands } var entUid = new EntityUid(intUid); - if (!entityManager.TryGetEntity(entUid, out var target)) + if (!entityManager.EntityExists(entUid) { shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-entity")); return; diff --git a/Content.Server/Verbs/VerbSystem.cs b/Content.Server/Verbs/VerbSystem.cs index 79e0feaa8e..021970b04f 100644 --- a/Content.Server/Verbs/VerbSystem.cs +++ b/Content.Server/Verbs/VerbSystem.cs @@ -1,7 +1,6 @@ using Content.Shared.Verbs; using Robust.Server.Player; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Log; namespace Content.Server.Verbs @@ -30,7 +29,7 @@ namespace Content.Server.Verbs return; } - if (!EntityManager.TryGetEntity(args.Target, out var targetEntity)) + if (!EntityManager.EntityExists(args.Target) { return; } @@ -56,7 +55,7 @@ namespace Content.Server.Verbs { var player = (IPlayerSession) eventArgs.SenderSession; - if (!EntityManager.TryGetEntity(args.EntityUid, out var target)) + if (!EntityManager.EntityExists(args.EntityUid) { Logger.Warning($"{nameof(HandleVerbRequest)} called on a non-existent entity with id {args.EntityUid} by player {player}."); return; diff --git a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs index a35eac7772..1cf192c5e9 100644 --- a/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/Weapon/Melee/MeleeWeaponSystem.cs @@ -8,7 +8,6 @@ using Content.Server.Chemistry.Components; using Content.Server.Chemistry.EntitySystems; using Content.Server.Cooldown; using Content.Server.Weapon.Melee.Components; -using Content.Shared.Administration.Logs; using Content.Shared.Damage; using Content.Shared.Database; using Content.Shared.Hands; @@ -70,7 +69,7 @@ namespace Content.Server.Weapon.Melee RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); } - private void OnClickAttack(EntityUid uid, MeleeWeaponComponent comp, ClickAttackEvent args) + private void OnClickAttack(EntityUid owner, MeleeWeaponComponent comp, ClickAttackEvent args) { args.Handled = true; var curTime = _gameTiming.CurTime; @@ -78,18 +77,15 @@ namespace Content.Server.Weapon.Melee if (curTime < comp.CooldownEnd || !args.Target.IsValid()) return; - var owner = EntityManager.GetEntity(uid); - var target = args.TargetEntity; - var location = IoCManager.Resolve().GetComponent(args.User).Coordinates; var diff = args.ClickLocation.ToMapPos(IoCManager.Resolve()) - location.ToMapPos(IoCManager.Resolve()); var angle = Angle.FromWorldVec(diff); - if (target != null) + if (args.Target is {Valid: true} target) { // Raise event before doing damage so we can cancel damage if the event is handled - var hitEvent = new MeleeHitEvent(new List() { target }, args.User); - RaiseLocalEvent(uid, hitEvent, false); + var hitEvent = new MeleeHitEvent(new List() { target }, args.User); + RaiseLocalEvent(owner, hitEvent, false); if (!hitEvent.Handled) { @@ -123,10 +119,10 @@ namespace Content.Server.Weapon.Melee comp.LastAttackTime = curTime; comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime); - RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); + RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); } - private void OnWideAttack(EntityUid uid, MeleeWeaponComponent comp, WideAttackEvent args) + private void OnWideAttack(EntityUid owner, MeleeWeaponComponent comp, WideAttackEvent args) { args.Handled = true; var curTime = _gameTiming.CurTime; @@ -136,8 +132,6 @@ namespace Content.Server.Weapon.Melee return; } - var owner = EntityManager.GetEntity(uid); - var location = IoCManager.Resolve().GetComponent(args.User).Coordinates; var diff = args.ClickLocation.ToMapPos(IoCManager.Resolve()) - location.ToMapPos(IoCManager.Resolve()); var angle = Angle.FromWorldVec(diff); @@ -145,7 +139,7 @@ namespace Content.Server.Weapon.Melee // This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes. var entities = ArcRayCast(IoCManager.Resolve().GetComponent(args.User).WorldPosition, angle, comp.ArcWidth, comp.Range, IoCManager.Resolve().GetComponent(owner).MapID, args.User); - var hitEntities = new List(); + var hitEntities = new List(); foreach (var entity in entities) { if (entity.IsInContainer() || entity == args.User) @@ -159,7 +153,7 @@ namespace Content.Server.Weapon.Melee // Raise event before doing damage so we can cancel damage if handled var hitEvent = new MeleeHitEvent(hitEntities, args.User); - RaiseLocalEvent(uid, hitEvent, false); + RaiseLocalEvent(owner, hitEvent, false); SendAnimation(comp.Arc, angle, args.User, owner, hitEntities); if (!hitEvent.Handled) @@ -195,14 +189,14 @@ namespace Content.Server.Weapon.Melee comp.LastAttackTime = curTime; comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.ArcCooldownTime); - RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); + RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); } /// /// Used for melee weapons that want some behavior on AfterInteract, /// but also want the cooldown (stun batons, flashes) /// - private void OnAfterInteract(EntityUid uid, MeleeWeaponComponent comp, AfterInteractEvent args) + private void OnAfterInteract(EntityUid owner, MeleeWeaponComponent comp, AfterInteractEvent args) { if (!args.CanReach) return; @@ -214,9 +208,7 @@ namespace Content.Server.Weapon.Melee return; } - var owner = EntityManager.GetEntity(uid); - - if (args.Target == null) + if (!args.Target.Valid) return; var location = IoCManager.Resolve().GetComponent(args.User).Coordinates; @@ -224,25 +216,25 @@ namespace Content.Server.Weapon.Melee var angle = Angle.FromWorldVec(diff); var hitEvent = new MeleeInteractEvent(args.Target, args.User); - RaiseLocalEvent(uid, hitEvent, false); + RaiseLocalEvent(owner, hitEvent, false); if (!hitEvent.CanInteract) return; - SendAnimation(comp.ClickArc, angle, args.User, owner, new List() { args.Target }, comp.ClickAttackEffect, false); + SendAnimation(comp.ClickArc, angle, args.User, owner, new List() { args.Target }, comp.ClickAttackEffect, false); comp.LastAttackTime = curTime; comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime); - RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); + RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false); } - private HashSet ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, IEntity ignore) + private HashSet ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, EntityUid ignore) { var widthRad = Angle.FromDegrees(arcWidth); var increments = 1 + 35 * (int) Math.Ceiling(widthRad / (2 * Math.PI)); var increment = widthRad / increments; var baseAngle = angle - widthRad / 2; - var resSet = new HashSet(); + var resSet = new HashSet(); for (var i = 0; i < increments; i++) { @@ -260,9 +252,8 @@ namespace Content.Server.Weapon.Melee return resSet; } - private void OnChemicalInjectorHit(EntityUid uid, MeleeChemicalInjectorComponent comp, MeleeHitEvent args) + private void OnChemicalInjectorHit(EntityUid owner, MeleeChemicalInjectorComponent comp, MeleeHitEvent args) { - IEntity owner = EntityManager.GetEntity(uid); if (!_solutionsSystem.TryGetInjectableSolution(owner, out var solutionContainer)) return; @@ -291,13 +282,13 @@ namespace Content.Server.Weapon.Melee } } - public void SendAnimation(string arc, Angle angle, IEntity attacker, IEntity source, IEnumerable hits, bool textureEffect = false, bool arcFollowAttacker = true) + public void SendAnimation(string arc, Angle angle, EntityUid attacker, EntityUid source, IEnumerable hits, bool textureEffect = false, bool arcFollowAttacker = true) { RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayMeleeWeaponAnimationMessage(arc, angle, attacker, source, - hits.Select(e => (EntityUid) e).ToList(), textureEffect, arcFollowAttacker), Filter.Pvs(source, 1f)); + hits.Select(e => e).ToList(), textureEffect, arcFollowAttacker), Filter.Pvs(source, 1f)); } - public void SendLunge(Angle angle, IEntity source) + public void SendLunge(Angle angle, EntityUid source) { RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayLungeAnimationMessage(angle, source), Filter.Pvs(source, 1f)); } @@ -323,14 +314,14 @@ namespace Content.Server.Weapon.Melee /// /// A list containing every hit entity. Can be zero. /// - public IEnumerable HitEntities { get; } + public IEnumerable HitEntities { get; } /// /// The user who attacked with the melee wepaon. /// - public IEntity User { get; } + public EntityUid User { get; } - public MeleeHitEvent(List hitEntities, IEntity user) + public MeleeHitEvent(List hitEntities, EntityUid user) { HitEntities = hitEntities; User = user; @@ -346,12 +337,12 @@ namespace Content.Server.Weapon.Melee /// /// The entity interacted with. /// - public IEntity Entity { get; } + public EntityUid Entity { get; } /// /// The user who interacted using the melee weapon. /// - public IEntity User { get; } + public EntityUid User { get; } /// /// Modified by the event handler to specify whether they could successfully interact with the entity. @@ -359,7 +350,7 @@ namespace Content.Server.Weapon.Melee /// public bool CanInteract { get; set; } = false; - public MeleeInteractEvent(IEntity entity, IEntity user) + public MeleeInteractEvent(EntityUid entity, EntityUid user) { Entity = entity; User = user; diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs index d74a069f14..3bb0b83d4e 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoBoxComponent.cs @@ -34,14 +34,14 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components set { _capacity = value; - _spawnedAmmo = new Stack(value); + _spawnedAmmo = new Stack(value); } } private int _capacity = 30; public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount; - private Stack _spawnedAmmo = new(); + private Stack _spawnedAmmo = new(); private Container _ammoContainer = default!; private int _unspawnedCount; @@ -81,7 +81,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } } - public IEntity? TakeAmmo() + public EntityUid TakeAmmo() { if (_spawnedAmmo.TryPop(out var ammo)) { @@ -102,7 +102,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return ammo; } - public bool TryInsertAmmo(IEntity user, IEntity entity) + public bool TryInsertAmmo(EntityUid user, EntityUid entity) { if (!IoCManager.Resolve().TryGetComponent(entity, out AmmoComponent? ammoComponent)) { @@ -140,7 +140,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components { var ammo = rangedMagazine.TakeAmmo(); - if (ammo == null) + if (!ammo.Valid) { continue; } @@ -158,7 +158,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return false; } - private bool TryUse(IEntity user) + private bool TryUse(EntityUiduser) { if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent)) { @@ -190,7 +190,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components public void EjectContents(int count) { var ejectCount = Math.Min(count, Capacity); - var ejectAmmo = new List(ejectCount); + var ejectAmmo = new List(ejectCount); for (var i = 0; i < Math.Min(count, Capacity); i++) { diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs index a8328dc75a..9c6e69f81f 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/AmmoComponent.cs @@ -104,7 +104,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } } - public IEntity? TakeBullet(EntityCoordinates spawnAt) + public EntityUid TakeBullet(EntityCoordinates spawnAt) { if (_ammoIsProjectile) { @@ -127,7 +127,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return entity; } - public void MuzzleFlash(IEntity entity, Angle angle) + public void MuzzleFlash(EntityUid entity, Angle angle) { if (_muzzleFlashSprite == null) { diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs index dd3888018b..7ffde4d0c0 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/RangedMagazineComponent.cs @@ -24,7 +24,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components { public override string Name => "RangedMagazine"; - private readonly Stack _spawnedAmmo = new(); + private readonly Stack _spawnedAmmo = new(); private Container _ammoContainer = default!; public int ShotsLeft => _spawnedAmmo.Count + _unspawnedCount; @@ -91,7 +91,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity); } - public bool TryInsertAmmo(IEntity user, IEntity ammo) + public bool TryInsertAmmo(EntityUid user, EntityUid ammo) { if (!IoCManager.Resolve().TryGetComponent(ammo, out AmmoComponent? ammoComponent)) { @@ -116,9 +116,9 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return true; } - public IEntity? TakeAmmo() + public EntityUid TakeAmmo() { - IEntity? ammo = null; + EntityUid ammo = default; // If anything's spawned use that first, otherwise use the fill prototype as a fallback (if we have spawn count left) if (_spawnedAmmo.TryPop(out var entity)) { diff --git a/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs b/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs index bdd0688867..b35f1d9fb8 100644 --- a/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs +++ b/Content.Server/Weapon/Ranged/Ammunition/Components/SpeedLoaderComponent.cs @@ -28,7 +28,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components [DataField("capacity")] private int _capacity = 6; private Container _ammoContainer = default!; - private Stack _spawnedAmmo = new(); + private Stack _spawnedAmmo = new(); private int _unspawnedCount; public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount; @@ -67,7 +67,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } } - public bool TryInsertAmmo(IEntity user, IEntity entity) + public bool TryInsertAmmo(EntityUid user, EntityUid entity) { if (!IoCManager.Resolve().TryGetComponent(entity, out AmmoComponent? ammoComponent)) { @@ -93,7 +93,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } - private bool UseEntity(IEntity user) + private bool UseEntity(EntityUid user) { if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? handsComponent)) { @@ -101,7 +101,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components } var ammo = TakeAmmo(); - if (ammo == null) + if (ammo == default) { return false; } @@ -120,7 +120,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components return true; } - private IEntity? TakeAmmo() + private EntityUid TakeAmmo() { if (_spawnedAmmo.TryPop(out var entity)) { @@ -147,12 +147,13 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components // This area is dirty but not sure of an easier way to do it besides add an interface or somethin var changed = false; - if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out RevolverBarrelComponent? revolverBarrel)) + var entities = IoCManager.Resolve(); + if (entities.TryGetComponent(eventArgs.Target.Value, out RevolverBarrelComponent? revolverBarrel)) { for (var i = 0; i < Capacity; i++) { var ammo = TakeAmmo(); - if (ammo == null) + if (ammo == default) { break; } @@ -167,12 +168,13 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components TryInsertAmmo(eventArgs.User, ammo); break; } - } else if (IoCManager.Resolve().TryGetComponent(eventArgs.Target, out BoltActionBarrelComponent? boltActionBarrel)) + } + else if (IoCManager.Resolve().TryGetComponent(eventArgs.Target.Value, out BoltActionBarrelComponent? boltActionBarrel)) { for (var i = 0; i < Capacity; i++) { var ammo = TakeAmmo(); - if (ammo == null) + if (ammo == default) { break; } diff --git a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs index a9485e066c..dc443ef7f0 100644 --- a/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs +++ b/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs @@ -74,10 +74,12 @@ namespace Content.Server.Weapon.Ranged.Barrels !_actionBlockerSystem.CanPickup(args.User)) return; - Verb verb = new(); - verb.Text = IoCManager.Resolve().GetComponent(component.PowerCell.Owner).EntityName; - verb.Category = VerbCategory.Eject; - verb.Act = () => component.TryEjectCell(args.User); + Verb verb = new() + { + Text = IoCManager.Resolve().GetComponent(component.PowerCell.Owner).EntityName, + Category = VerbCategory.Eject, + Act = () => component.TryEjectCell(args.User) + }; args.Verbs.Add(verb); } diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs index bdc167c284..1f2ee3cde7 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/BoltActionBarrelComponent.cs @@ -14,7 +14,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -48,7 +47,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components private int _capacity = 6; private ContainerSlot _chamberContainer = default!; - private Stack _spawnedAmmo = default!; + private Stack _spawnedAmmo = default!; private Container _ammoContainer = default!; [ViewVariables] @@ -141,7 +140,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { // TODO: Add existing ammo support on revolvers base.Initialize(); - _spawnedAmmo = new Stack(_capacity - 1); + _spawnedAmmo = new Stack(_capacity - 1); _ammoContainer = ContainerHelpers.EnsureContainer(Owner, $"{Name}-ammo-container", out var existing); if (existing) @@ -172,12 +171,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity); } - public override IEntity? PeekAmmo() + public override EntityUid PeekAmmo() { return _chamberContainer.ContainedEntity; } - public override IEntity? TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid TakeProjectile(EntityCoordinates spawnAt) { var chamberEntity = _chamberContainer.ContainedEntity; if (_autoCycle) @@ -228,7 +227,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components UpdateAppearance(); } - public bool TryInsertBullet(IEntity user, IEntity ammo) + public bool TryInsertBullet(EntityUid user, EntityUid ammo) { if (!IoCManager.Resolve().TryGetComponent(ammo, out AmmoComponent? ammoComponent)) { diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs index dfcc0592db..72e64e0337 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/PumpBarrelComponent.cs @@ -13,7 +13,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; @@ -45,7 +44,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // Even a point having a chamber? I guess it makes some of the below code cleaner private ContainerSlot _chamberContainer = default!; - private Stack _spawnedAmmo = new(DefaultCapacity - 1); + private Stack _spawnedAmmo = new(DefaultCapacity - 1); private Container _ammoContainer = default!; [ViewVariables] @@ -99,7 +98,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components void ISerializationHooks.AfterDeserialization() { - _spawnedAmmo = new Stack(Capacity - 1); + _spawnedAmmo = new Stack(Capacity - 1); } protected override void Initialize() @@ -141,12 +140,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity); } - public override IEntity? PeekAmmo() + public override EntityUid PeekAmmo() { return _chamberContainer.ContainedEntity; } - public override IEntity? TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid TakeProjectile(EntityCoordinates spawnAt) { var chamberEntity = _chamberContainer.ContainedEntity; diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs index ba331670e3..227e9c95db 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/RevolverBarrelComponent.cs @@ -13,7 +13,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; @@ -44,7 +43,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components private int _serializedCapacity = 6; [DataField("ammoSlots", readOnly: true)] - private IEntity?[] _ammoSlots = Array.Empty(); + private EntityUid[] _ammoSlots = Array.Empty(); public override int ShotsLeft => _ammoContainer.ContainedEntities.Count; @@ -137,7 +136,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components appearance.SetData(AmmoVisuals.AmmoMax, Capacity); } - public bool TryInsertBullet(IEntity user, IEntity entity) + public bool TryInsertBullet(EntityUid user, EntityUid entity) { if (!IoCManager.Resolve().TryGetComponent(entity, out AmmoComponent? ammoComponent)) { @@ -192,7 +191,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); } - public override IEntity? PeekAmmo() + public override EntityUid PeekAmmo() { return _ammoSlots[_currentSlot]; } @@ -203,10 +202,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// /// - public override IEntity? TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid TakeProjectile(EntityCoordinates spawnAt) { var ammo = _ammoSlots[_currentSlot]; - IEntity? bullet = null; + EntityUid bullet = null; if (ammo != null) { var ammoComponent = IoCManager.Resolve().GetComponent(ammo); diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs index 34bc239db4..4c72d1a6be 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs @@ -14,7 +14,6 @@ using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -24,6 +23,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components [NetworkedComponent()] public sealed class ServerBatteryBarrelComponent : ServerRangedBarrelComponent { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "BatteryBarrel"; // The minimum change we need before we can fire @@ -35,37 +36,28 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components [DataField("ammoPrototype")] [ViewVariables] private string? _ammoPrototype; - [ViewVariables] public IEntity? PowerCellEntity => _powerCellContainer.ContainedEntity; - public BatteryComponent? PowerCell - { - get - { - if (_powerCellContainer.ContainedEntity == null) - return null; - - return _powerCellContainer.ContainedEntity.GetComponentOrNull(); - } - } + [ViewVariables] public EntityUid? PowerCellEntity => _powerCellContainer.ContainedEntity; + public BatteryComponent? PowerCell => _powerCellContainer.ContainedEntity == null + ? null + : _entities.GetComponentOrNull(_powerCellContainer.ContainedEntity.Value); private ContainerSlot _powerCellContainer = default!; private ContainerSlot _ammoContainer = default!; [DataField("powerCellPrototype")] - private string? _powerCellPrototype = default; + private string? _powerCellPrototype; [DataField("powerCellRemovable")] - [ViewVariables] public bool PowerCellRemovable = default; + [ViewVariables] public bool PowerCellRemovable; public override int ShotsLeft { get { - var powerCell = _powerCellContainer.ContainedEntity; - - if (powerCell == null) + if (_powerCellContainer.ContainedEntity is not {Valid: true} powerCell) { return 0; } - return (int) Math.Ceiling(IoCManager.Resolve().GetComponent(powerCell).CurrentCharge / _baseFireCost); + return (int) Math.Ceiling(_entities.GetComponent(powerCell).CurrentCharge / _baseFireCost); } } @@ -73,14 +65,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { get { - var powerCell = _powerCellContainer.ContainedEntity; - - if (powerCell == null) + if (_powerCellContainer.ContainedEntity is not {Valid: true} powerCell) { return 0; } - return (int) Math.Ceiling((float) (IoCManager.Resolve().GetComponent(powerCell).MaxCharge / _baseFireCost)); + return (int) Math.Ceiling(_entities.GetComponent(powerCell).MaxCharge / _baseFireCost); } } @@ -104,19 +94,19 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components protected override void Initialize() { base.Initialize(); - _powerCellContainer = ContainerHelpers.EnsureContainer(Owner, $"{Name}-powercell-container", out var existing); + _powerCellContainer = Owner.EnsureContainer($"{Name}-powercell-container", out var existing); if (!existing && _powerCellPrototype != null) { - var powerCellEntity = IoCManager.Resolve().SpawnEntity(_powerCellPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); + var powerCellEntity = _entities.SpawnEntity(_powerCellPrototype, _entities.GetComponent(Owner).Coordinates); _powerCellContainer.Insert(powerCellEntity); } if (_ammoPrototype != null) { - _ammoContainer = ContainerHelpers.EnsureContainer(Owner, $"{Name}-ammo-container"); + _ammoContainer = Owner.EnsureContainer($"{Name}-ammo-container"); } - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { _appearanceComponent = appearanceComponent; } @@ -137,64 +127,64 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); } - public override IEntity PeekAmmo() + public override EntityUid PeekAmmo() { // Spawn a dummy entity because it's easier to work with I guess // This will get re-used for the projectile var ammo = _ammoContainer.ContainedEntity; if (ammo == null) { - ammo = IoCManager.Resolve().SpawnEntity(_ammoPrototype, IoCManager.Resolve().GetComponent(Owner).Coordinates); - _ammoContainer.Insert(ammo); + ammo = _entities.SpawnEntity(_ammoPrototype, _entities.GetComponent(Owner).Coordinates); + _ammoContainer.Insert(ammo.Value); } - return ammo; + return ammo.Value; } - public override IEntity? TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid TakeProjectile(EntityCoordinates spawnAt) { var powerCellEntity = _powerCellContainer.ContainedEntity; if (powerCellEntity == null) { - return null; + return default; } - var capacitor = IoCManager.Resolve().GetComponent(powerCellEntity); + var capacitor = _entities.GetComponent(powerCellEntity.Value); if (capacitor.CurrentCharge < _lowerChargeLimit) { - return null; + return default; } // Can fire confirmed // Multiply the entity's damage / whatever by the percentage of charge the shot has. - IEntity entity; + EntityUid? entity; var chargeChange = Math.Min(capacitor.CurrentCharge, _baseFireCost); if (capacitor.UseCharge(chargeChange) < _lowerChargeLimit) { // Handling of funny exploding cells. - return null; + return default; } var energyRatio = chargeChange / _baseFireCost; if (_ammoContainer.ContainedEntity != null) { entity = _ammoContainer.ContainedEntity; - _ammoContainer.Remove(entity); - IoCManager.Resolve().GetComponent(entity).Coordinates = spawnAt; + _ammoContainer.Remove(entity.Value); + _entities.GetComponent(entity.Value).Coordinates = spawnAt; } else { - entity = IoCManager.Resolve().SpawnEntity(_ammoPrototype, spawnAt); + entity = _entities.SpawnEntity(_ammoPrototype, spawnAt); } - if (IoCManager.Resolve().TryGetComponent(entity, out ProjectileComponent? projectileComponent)) + if (_entities.TryGetComponent(entity.Value, out ProjectileComponent? projectileComponent)) { if (energyRatio < 1.0) { projectileComponent.Damage *= energyRatio; } - } else if (IoCManager.Resolve().TryGetComponent(entity, out HitscanComponent? hitscanComponent)) + } else if (_entities.TryGetComponent(entity.Value, out HitscanComponent? hitscanComponent)) { hitscanComponent.Damage *= energyRatio; hitscanComponent.ColorModifier = energyRatio; @@ -206,17 +196,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); UpdateAppearance(); - return entity; + return entity.Value; } - public bool TryInsertPowerCell(IEntity entity) + public bool TryInsertPowerCell(EntityUid entity) { if (_powerCellContainer.ContainedEntity != null) { return false; } - if (!IoCManager.Resolve().HasComponent(entity)) + if (!_entities.HasComponent(entity)) { return false; } @@ -237,22 +227,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components return false; } - if (PowerCellEntity == null) - { - return false; - } - - return TryEjectCell(eventArgs.User); + return PowerCellEntity != default && TryEjectCell(eventArgs.User); } - public bool TryEjectCell(IEntity user) + public bool TryEjectCell(EntityUid user) { if (PowerCell == null || !PowerCellRemovable) { return false; } - if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands)) + if (!_entities.TryGetComponent(user, out HandsComponent? hands)) { return false; } @@ -266,9 +251,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components Dirty(); UpdateAppearance(); - if (!hands.PutInHand(IoCManager.Resolve().GetComponent(cell.Owner))) + if (!hands.PutInHand(_entities.GetComponent(cell.Owner))) { - IoCManager.Resolve().GetComponent(cell.Owner).Coordinates = IoCManager.Resolve().GetComponent(user).Coordinates; + _entities.GetComponent(cell.Owner).Coordinates = _entities.GetComponent(user).Coordinates; } SoundSystem.Play(Filter.Pvs(Owner), _soundPowerCellEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2)); @@ -277,7 +262,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public override async Task InteractUsing(InteractUsingEventArgs eventArgs) { - if (!IoCManager.Resolve().HasComponent(eventArgs.Using)) + if (!_entities.HasComponent(eventArgs.Using)) { return false; } diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs index 16abb91686..bdf400ddfe 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerMagazineBarrelComponent.cs @@ -18,7 +18,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Player; -using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -31,6 +30,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public sealed class ServerMagazineBarrelComponent : ServerRangedBarrelComponent, IExamine #pragma warning restore 618 { + [Dependency] private readonly IEntityManager _entities = default!; + public override string Name => "MagazineBarrel"; [ViewVariables] @@ -55,8 +56,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components count++; } - var magazine = MagazineContainer.ContainedEntity; - if (magazine != null) + if (MagazineContainer.ContainedEntity is {Valid: true} magazine) { count += IoCManager.Resolve().GetComponent(magazine).ShotsLeft; } @@ -71,8 +71,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { // Chamber var count = 1; - var magazine = MagazineContainer.ContainedEntity; - if (magazine != null) + if (MagazineContainer.ContainedEntity is {Valid: true} magazine) { count += IoCManager.Resolve().GetComponent(magazine).Capacity; } @@ -153,8 +152,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components public override ComponentState GetComponentState() { (int, int)? count = null; - var magazine = MagazineContainer.ContainedEntity; - if (magazine != null && IoCManager.Resolve().TryGetComponent(magazine, out RangedMagazineComponent? rangedMagazineComponent)) + if (MagazineContainer.ContainedEntity is {Valid: true} magazine && + IoCManager.Resolve().TryGetComponent(magazine, out RangedMagazineComponent? rangedMagazineComponent)) { count = (rangedMagazineComponent.ShotsLeft, rangedMagazineComponent.Capacity); } @@ -170,13 +169,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components { base.Initialize(); - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent)) { _appearanceComponent = appearanceComponent; } - _chamberContainer = ContainerHelpers.EnsureContainer(Owner, $"{Name}-chamber"); - MagazineContainer = ContainerHelpers.EnsureContainer(Owner, $"{Name}-magazine", out var existing); + _chamberContainer = Owner.EnsureContainer($"{Name}-chamber"); + MagazineContainer = Owner.EnsureContainer($"{Name}-magazine", out var existing); if (!existing && _magFillPrototype != null) { @@ -192,16 +191,16 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components UpdateAppearance(); } - public override IEntity? PeekAmmo() + public override EntityUid PeekAmmo() { - return BoltOpen ? null : _chamberContainer.ContainedEntity; + return BoltOpen ? default : _chamberContainer.ContainedEntity; } - public override IEntity? TakeProjectile(EntityCoordinates spawnAt) + public override EntityUid TakeProjectile(EntityCoordinates spawnAt) { if (BoltOpen) { - return null; + return default; } var entity = _chamberContainer.ContainedEntity; @@ -320,7 +319,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components return true; } - public void RemoveMagazine(IEntity user) + public void RemoveMagazine(EntityUiduser) { var mag = MagazineContainer.ContainedEntity; @@ -347,7 +346,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components UpdateAppearance(); } - public bool CanInsertMagazine(IEntity user, IEntity magazine, bool quiet = true) + public bool CanInsertMagazine(EntityUid user, EntityUid magazine, bool quiet = true) { if (!IoCManager.Resolve().TryGetComponent(magazine, out RangedMagazineComponent? magazineComponent)) { @@ -385,7 +384,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components return false; } - public void InsertMagazine(IEntity user, IEntity magazine) + public void InsertMagazine(EntityUid user, EntityUidmagazine) { SoundSystem.Play(Filter.Pvs(Owner), _soundMagInsert.GetSound(), Owner, AudioParams.Default.WithVolume(-2)); Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-success")); diff --git a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs index 3fd6c97c2c..cee5df72fb 100644 --- a/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs +++ b/Content.Server/Weapon/Ranged/Barrels/Components/ServerRangedBarrelComponent.cs @@ -6,8 +6,6 @@ using Content.Server.Administration.Logs; using Content.Server.Camera; using Content.Server.Projectiles.Components; using Content.Server.Weapon.Ranged.Ammunition.Components; -using Content.Shared.Administration.Logs; -using Content.Shared.Audio; using Content.Shared.Damage; using Content.Shared.Database; using Content.Shared.Examine; @@ -22,7 +20,6 @@ using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; -using Robust.Shared.Physics.Broadphase; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -45,6 +42,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // it's just when I re-organised it changed me as the contributor [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly IEntityManager _entities = default!; public override FireRateSelector FireRateSelector => _fireRateSelector; @@ -59,8 +57,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // _lastFire is when we actually fired (so if we hold the button then recoil doesn't build up if we're not firing) private TimeSpan _lastFire; - public abstract IEntity? PeekAmmo(); - public abstract IEntity? TakeProjectile(EntityCoordinates spawnAt); + public abstract EntityUid PeekAmmo(); + public abstract EntityUid TakeProjectile(EntityCoordinates spawnAt); // Recoil / spray control [DataField("minAngle")] @@ -149,7 +147,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components protected override void OnRemove() { base.OnRemove(); - if (IoCManager.Resolve().TryGetComponent(Owner, out ServerRangedWeaponComponent? rangedWeaponComponent)) + if (_entities.TryGetComponent(Owner, out ServerRangedWeaponComponent? rangedWeaponComponent)) { rangedWeaponComponent.Barrel = null; rangedWeaponComponent.FireHandler -= Fire; @@ -195,7 +193,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// Entity that is operating the weapon, usually the player. /// Target position on the map to shoot at. - private void Fire(IEntity shooter, Vector2 targetPos) + private void Fire(EntityUid shooter, Vector2 targetPos) { if (ShotsLeft == 0) { @@ -204,30 +202,30 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components } var ammo = PeekAmmo(); - var projectile = TakeProjectile(IoCManager.Resolve().GetComponent(shooter).Coordinates); - if (projectile == null) + var projectile = TakeProjectile(_entities.GetComponent(shooter).Coordinates); + if (projectile == default) { SoundSystem.Play(Filter.Broadcast(), SoundEmpty.GetSound(), Owner); return; } // At this point firing is confirmed - var direction = (targetPos - IoCManager.Resolve().GetComponent(shooter).WorldPosition).ToAngle(); + var direction = (targetPos - _entities.GetComponent(shooter).WorldPosition).ToAngle(); var angle = GetRecoilAngle(direction); // This should really be client-side but for now we'll just leave it here - if (IoCManager.Resolve().TryGetComponent(shooter, out CameraRecoilComponent? recoilComponent)) + if (_entities.TryGetComponent(shooter, out CameraRecoilComponent? recoilComponent)) { recoilComponent.Kick(-angle.ToVec() * 0.15f); } // This section probably needs tweaking so there can be caseless hitscan etc. - if (IoCManager.Resolve().TryGetComponent(projectile, out HitscanComponent? hitscan)) + if (_entities.TryGetComponent(projectile, out HitscanComponent? hitscan)) { FireHitscan(shooter, hitscan, angle); } - else if (IoCManager.Resolve().HasComponent(projectile) && - ammo != null && - IoCManager.Resolve().TryGetComponent(ammo, out AmmoComponent? ammoComponent)) + else if (_entities.HasComponent(projectile) && + ammo != default && + _entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent)) { FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo); @@ -238,7 +236,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components if (ammoComponent.Caseless) { - IoCManager.Resolve().DeleteEntity((EntityUid) ammo); + _entities.DeleteEntity(ammo); } } else @@ -261,8 +259,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// /// - public static void EjectCasing( - IEntity entity, + public void EjectCasing( + EntityUid entity, bool playSound = true, IRobustRandom? robustRandom = null, IPrototypeManager? prototypeManager = null, @@ -273,12 +271,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components {Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West}; const float ejectOffset = 1.8f; - var ammo = IoCManager.Resolve().GetComponent(entity); + var ammo = _entities.GetComponent(entity); var offsetPos = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset); - IoCManager.Resolve().GetComponent(entity).Coordinates = IoCManager.Resolve().GetComponent(entity).Coordinates.Offset(offsetPos); - IoCManager.Resolve().GetComponent(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle(); + _entities.GetComponent(entity).Coordinates = _entities.GetComponent(entity).Coordinates.Offset(offsetPos); + _entities.GetComponent(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle(); - SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), IoCManager.Resolve().GetComponent(entity).Coordinates, AudioParams.Default.WithVolume(-1)); + SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), _entities.GetComponent(entity).Coordinates, AudioParams.Default.WithVolume(-1)); } /// @@ -286,7 +284,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// Wraps EjectCasing to make it less toxic for bulk ejections /// /// - public static void EjectCasings(IEnumerable entities) + public void EjectCasings(IEnumerable entities) { var robustRandom = IoCManager.Resolve(); var prototypeManager = IoCManager.Resolve(); @@ -309,7 +307,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// Handles firing one or many projectiles /// - private void FireProjectiles(IEntity shooter, IEntity baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity, IEntity ammo) + private void FireProjectiles(EntityUid shooter, EntityUid baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity, EntityUid ammo) { List? sprayAngleChange = null; if (count > 1) @@ -321,7 +319,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components var firedProjectiles = new EntityUid[count]; for (var i = 0; i < count; i++) { - IEntity projectile; + EntityUid projectile; if (i == 0) { @@ -329,8 +327,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components } else { - projectile = - IoCManager.Resolve().SpawnEntity(IoCManager.Resolve().GetComponent(baseProjectile).EntityPrototype?.ID, IoCManager.Resolve().GetComponent(baseProjectile).Coordinates); + projectile = _entities.SpawnEntity( + _entities.GetComponent(baseProjectile).EntityPrototype?.ID, + _entities.GetComponent(baseProjectile).Coordinates); } firedProjectiles[i] = projectile; @@ -346,10 +345,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components projectileAngle = angle; } - var physics = IoCManager.Resolve().GetComponent(projectile); + var physics = _entities.GetComponent(projectile); physics.BodyStatus = BodyStatus.InAir; - var projectileComponent = IoCManager.Resolve().GetComponent(projectile); + var projectileComponent = _entities.GetComponent(projectile); projectileComponent.IgnoreEntity(shooter); // FIXME: Work around issue where inserting and removing an entity from a container, @@ -357,16 +356,16 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components // See SharedBroadphaseSystem.HandleContainerInsert()... It sets Awake to false, which causes this. projectile.SpawnTimer(TimeSpan.FromMilliseconds(25), () => { - IoCManager.Resolve().GetComponent(projectile) + _entities.GetComponent(projectile) .LinearVelocity = projectileAngle.ToVec() * velocity; }); - IoCManager.Resolve().GetComponent(projectile).WorldRotation = projectileAngle + MathHelper.PiOver2; + _entities.GetComponent(projectile).WorldRotation = projectileAngle + MathHelper.PiOver2; } - IoCManager.Resolve().EventBus.RaiseLocalEvent(((IComponent) this).Owner, new GunShotEvent(firedProjectiles)); - IoCManager.Resolve().EventBus.RaiseLocalEvent(ammo, new AmmoShotEvent(firedProjectiles)); + _entities.EventBus.RaiseLocalEvent(((IComponent) this).Owner, new GunShotEvent(firedProjectiles)); + _entities.EventBus.RaiseLocalEvent(ammo, new AmmoShotEvent(firedProjectiles)); } /// @@ -388,11 +387,11 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components /// /// Fires hitscan entities and then displays their effects /// - private void FireHitscan(IEntity shooter, HitscanComponent hitscan, Angle angle) + private void FireHitscan(EntityUid shooter, HitscanComponent hitscan, Angle angle) { - var ray = new CollisionRay(IoCManager.Resolve().GetComponent(Owner).Coordinates.ToMapPos(IoCManager.Resolve()), angle.ToVec(), (int) hitscan.CollisionMask); + var ray = new CollisionRay(_entities.GetComponent(Owner).Coordinates.ToMapPos(_entities), angle.ToVec(), (int) hitscan.CollisionMask); var physicsManager = EntitySystem.Get(); - var rayCastResults = physicsManager.IntersectRay(IoCManager.Resolve().GetComponent(Owner).MapID, ray, hitscan.MaxLength, shooter, false).ToList(); + var rayCastResults = physicsManager.IntersectRay(_entities.GetComponent(Owner).MapID, ray, hitscan.MaxLength, shooter, false).ToList(); if (rayCastResults.Count >= 1) { diff --git a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs index 86e9183b2c..94bf293b89 100644 --- a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs +++ b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs @@ -4,14 +4,12 @@ using Content.Server.CombatMode; using Content.Server.Hands.Components; using Content.Server.Interaction.Components; using Content.Server.Stunnable; -using Content.Server.Stunnable.Components; using Content.Server.Weapon.Ranged.Barrels.Components; using Content.Shared.ActionBlocker; using Content.Shared.Damage; using Content.Shared.Hands; using Content.Shared.Popups; using Content.Shared.Sound; -using Content.Shared.Stunnable; using Content.Shared.Weapons.Ranged.Components; using Robust.Shared.Audio; using Robust.Shared.GameObjects; @@ -60,8 +58,8 @@ namespace Content.Server.Weapon.Ranged public DamageSpecifier? ClumsyDamage; public Func? WeaponCanFireHandler; - public Func? UserCanFireHandler; - public Action? FireHandler; + public Func? UserCanFireHandler; + public Action? FireHandler; public ServerRangedBarrelComponent? Barrel { @@ -87,7 +85,7 @@ namespace Content.Server.Weapon.Ranged return WeaponCanFireHandler == null || WeaponCanFireHandler(); } - private bool UserCanFire(IEntity user) + private bool UserCanFire(EntityUid user) { return (UserCanFireHandler == null || UserCanFireHandler(user)) && EntitySystem.Get().CanInteract(user); } @@ -144,7 +142,7 @@ namespace Content.Server.Weapon.Ranged /// /// Entity that is operating the weapon, usually the player. /// Target position on the map to shoot at. - private void TryFire(IEntity user, Vector2 targetPos) + private void TryFire(EntityUid user, Vector2 targetPos) { if (!IoCManager.Resolve().TryGetComponent(user, out HandsComponent? hands) || hands.GetActiveHand?.Owner != Owner) { @@ -187,7 +185,7 @@ namespace Content.Server.Weapon.Ranged user.PopupMessage(Loc.GetString("server-ranged-weapon-component-try-fire-clumsy")); - IoCManager.Resolve().DeleteEntity((EntityUid) Owner); + IoCManager.Resolve().DeleteEntity(Owner); return; } diff --git a/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs b/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs index 67450eeab5..0407634442 100644 --- a/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs +++ b/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs @@ -17,13 +17,13 @@ namespace Content.Server.Weapon { public override string Name => "WeaponCapacitorCharger"; - public override bool IsEntityCompatible(IEntity entity) + public override bool IsEntityCompatible(EntityUid entity) { return IoCManager.Resolve().TryGetComponent(entity, out ServerBatteryBarrelComponent? battery) && battery.PowerCell != null || IoCManager.Resolve().TryGetComponent(entity, out PowerCellSlotComponent? slot) && slot.HasCell; } - protected override BatteryComponent? GetBatteryFrom(IEntity entity) + protected override BatteryComponent? GetBatteryFrom(EntityUid entity) { if (IoCManager.Resolve().TryGetComponent(entity, out PowerCellSlotComponent? slot)) { diff --git a/Content.Server/Wieldable/WieldableSystem.cs b/Content.Server/Wieldable/WieldableSystem.cs index 51d38dbb67..1095095be7 100644 --- a/Content.Server/Wieldable/WieldableSystem.cs +++ b/Content.Server/Wieldable/WieldableSystem.cs @@ -43,12 +43,14 @@ namespace Content.Server.Wieldable // TODO VERB TOOLTIPS Make CanWield or some other function return string, set as verb tooltip and disable // verb. Or just don't add it to the list if the action is not executable. - Verb verb = new(); // TODO VERBS ICON + localization - verb.Text = component.Wielded ? "Unwield" : "Wield"; - verb.Act = component.Wielded - ? () => AttemptUnwield(component.Owner, component, args.User) - : () => AttemptWield(component.Owner, component, args.User); + Verb verb = new() + { + Text = component.Wielded ? "Unwield" : "Wield", + Act = component.Wielded + ? () => AttemptUnwield(component.Owner, component, args.User) + : () => AttemptWield(component.Owner, component, args.User) + }; args.Verbs.Add(verb); } @@ -63,7 +65,7 @@ namespace Content.Server.Wieldable AttemptUnwield(uid, component, args.User); } - public bool CanWield(EntityUid uid, WieldableComponent component, IEntity user, bool quiet=false) + public bool CanWield(EntityUid uid, WieldableComponent component, EntityUid user, bool quiet=false) { // Do they have enough hands free? if (!EntityManager.TryGetComponent(user, out var hands)) @@ -80,19 +82,18 @@ namespace Content.Server.Wieldable { user.PopupMessage(Loc.GetString("wieldable-component-not-enough-free-hands", ("number", component.FreeHandsRequired), - ("item", EntityManager.GetEntity(uid)))); + ("item", uid))); } return false; } // Is it.. actually in one of their hands? - if (!hands.TryGetHandHoldingEntity(EntityManager.GetEntity(uid), out var _)) + if (!hands.TryGetHandHoldingEntity(uid, out _)) { if (!quiet) { - user.PopupMessage(Loc.GetString("wieldable-component-not-in-hands", - ("item", EntityManager.GetEntity(uid)))); + user.PopupMessage(Loc.GetString("wieldable-component-not-in-hands", ("item", uid))); } return false; @@ -105,13 +106,12 @@ namespace Content.Server.Wieldable /// /// Attempts to wield an item, creating a DoAfter.. /// - public void AttemptWield(EntityUid uid, WieldableComponent component, IEntity user) + public void AttemptWield(EntityUid used, WieldableComponent component, EntityUid user) { - if (!CanWield(uid, component, user)) + if (!CanWield(used, component, user)) return; var ev = new BeforeWieldEvent(); - RaiseLocalEvent(uid, ev, false); - var used = EntityManager.GetEntity(uid); + RaiseLocalEvent(used, ev, false); if (ev.Cancelled) return; @@ -119,8 +119,7 @@ namespace Content.Server.Wieldable user, component.WieldTime, default, - used - ) + used) { BreakOnUserMove = false, BreakOnDamage = true, @@ -136,24 +135,23 @@ namespace Content.Server.Wieldable /// /// Attempts to unwield an item, with no DoAfter. /// - public void AttemptUnwield(EntityUid uid, WieldableComponent component, IEntity user) + public void AttemptUnwield(EntityUid used, WieldableComponent component, EntityUid user) { var ev = new BeforeUnwieldEvent(); - RaiseLocalEvent(uid, ev, false); - var used = EntityManager.GetEntity(uid); + RaiseLocalEvent(used, ev, false); if (ev.Cancelled) return; var targEv = new ItemUnwieldedEvent(user); var userEv = new UnwieldedItemEvent(used); - RaiseLocalEvent(uid, targEv, false); + RaiseLocalEvent(used, targEv, false); RaiseLocalEvent(user, userEv, false); } private void OnItemWielded(EntityUid uid, WieldableComponent component, ItemWieldedEvent args) { - if (args.User == null) + if (args.User == default) return; if (!CanWield(uid, component, args.User) || component.Wielded) return; @@ -168,7 +166,7 @@ namespace Content.Server.Wieldable if (component.WieldSound != null) { - SoundSystem.Play(Filter.Pvs(EntityManager.GetEntity(uid)), component.WieldSound.GetSound()); + SoundSystem.Play(Filter.Pvs(uid), component.WieldSound.GetSound()); } for (var i = 0; i < component.FreeHandsRequired; i++) @@ -177,12 +175,12 @@ namespace Content.Server.Wieldable } args.User.PopupMessage(Loc.GetString("wieldable-component-successful-wield", - ("item", EntityManager.GetEntity(uid)))); + ("item", uid))); } private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args) { - if (args.User == null) + if (args.User == default) return; if (!component.Wielded) return; @@ -198,12 +196,12 @@ namespace Content.Server.Wieldable { if (component.UnwieldSound != null) { - SoundSystem.Play(Filter.Pvs(EntityManager.GetEntity(uid)), + SoundSystem.Play(Filter.Pvs(uid), component.UnwieldSound.GetSound()); } args.User.PopupMessage(Loc.GetString("wieldable-component-failed-wield", - ("item", EntityManager.GetEntity(uid)))); + ("item", uid))); } _virtualItemSystem.DeleteInHandsMatching(args.User, uid); @@ -218,8 +216,8 @@ namespace Content.Server.Wieldable private void OnVirtualItemDeleted(EntityUid uid, WieldableComponent component, VirtualItemDeletedEvent args) { - if(args.BlockingEntity == uid && component.Wielded) - AttemptUnwield(args.BlockingEntity, component, EntityManager.GetEntity(args.User)); + if (args.BlockingEntity == uid && component.Wielded) + AttemptUnwield(args.BlockingEntity, component, args.User); } private void OnMeleeHit(EntityUid uid, IncreaseDamageOnWieldComponent component, MeleeHitEvent args) @@ -247,9 +245,9 @@ namespace Content.Server.Wieldable /// public class ItemWieldedEvent : EntityEventArgs { - public IEntity? User; + public EntityUid User; - public ItemWieldedEvent(IEntity? user=null) + public ItemWieldedEvent(EntityUid user = default) { User = user; } @@ -260,9 +258,9 @@ namespace Content.Server.Wieldable /// public class WieldedItemEvent : EntityEventArgs { - public IEntity Item; + public EntityUid Item; - public WieldedItemEvent(IEntity item) + public WieldedItemEvent(EntityUid item) { Item = item; } @@ -277,13 +275,13 @@ namespace Content.Server.Wieldable /// public class ItemUnwieldedEvent : EntityEventArgs { - public IEntity? User; + public EntityUid User; /// /// Whether the item is being forced to be unwielded, or if the player chose to unwield it themselves. /// public bool Force; - public ItemUnwieldedEvent(IEntity? user=null, bool force=false) + public ItemUnwieldedEvent(EntityUid user = default, bool force=false) { User = user; Force = force; @@ -295,9 +293,9 @@ namespace Content.Server.Wieldable /// public class UnwieldedItemEvent : EntityEventArgs { - public IEntity Item; + public EntityUid Item; - public UnwieldedItemEvent(IEntity item) + public UnwieldedItemEvent(EntityUid item) { Item = item; } diff --git a/Content.Server/Window/WindowComponent.cs b/Content.Server/Window/WindowComponent.cs index 76c2de0e62..d1f4669a9f 100644 --- a/Content.Server/Window/WindowComponent.cs +++ b/Content.Server/Window/WindowComponent.cs @@ -9,7 +9,6 @@ using Content.Shared.Interaction; using Content.Shared.Rounding; using Content.Shared.Sound; using Content.Shared.Window; -using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -71,7 +70,7 @@ namespace Content.Server.Window var fraction = damage == 0 || damageThreshold == 0 ? 0f : (float) damage / damageThreshold; - var level = Math.Min(ContentHelpers.RoundToLevels((double) fraction, 1, 7), 5); + var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5); switch (level) { diff --git a/Content.Server/WireHacking/WiresComponent.cs b/Content.Server/WireHacking/WiresComponent.cs index 974af84504..4e0c6c8bd6 100644 --- a/Content.Server/WireHacking/WiresComponent.cs +++ b/Content.Server/WireHacking/WiresComponent.cs @@ -9,12 +9,9 @@ using Content.Server.UserInterface; using Content.Server.VendingMachines; using Content.Shared.Examine; using Content.Shared.Interaction; -using Content.Shared.Interaction.Helpers; -using Content.Shared.Popups; using Content.Shared.Sound; using Content.Shared.Tools; using Content.Shared.Wires; -using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Audio; @@ -36,8 +33,7 @@ namespace Content.Server.WireHacking #pragma warning restore 618 { [Dependency] private readonly IRobustRandom _random = default!; - - private AudioSystem _audioSystem = default!; + [Dependency] private readonly IEntityManager _entities = default!; private bool _isPanelOpen; @@ -117,7 +113,7 @@ namespace Content.Server.WireHacking private void UpdateAppearance() { - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(WiresVisuals.MaintenancePanelState, IsPanelOpen && IsPanelVisible); } @@ -173,9 +169,8 @@ namespace Content.Server.WireHacking protected override void Initialize() { base.Initialize(); - _audioSystem = EntitySystem.Get(); - if (IoCManager.Resolve().TryGetComponent(Owner, out AppearanceComponent? appearance)) + if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(WiresVisuals.MaintenancePanelState, IsPanelOpen); } @@ -230,7 +225,7 @@ namespace Content.Server.WireHacking hackingSystem.TryGetLayout(_layoutId, out layout); } - foreach (var wiresProvider in IoCManager.Resolve().GetComponents(Owner)) + foreach (var wiresProvider in _entities.GetComponents(Owner)) { var builder = new WiresBuilder(this, wiresProvider, layout); wiresProvider.RegisterWires(builder); @@ -334,8 +329,8 @@ namespace Content.Server.WireHacking /// public class WiresBuilder { - [NotNull] private readonly WiresComponent _wires; - [NotNull] private readonly IWires _owner; + private readonly WiresComponent _wires; + private readonly IWires _owner; private readonly WireLayout? _layout; public WiresBuilder(WiresComponent wires, IWires owner, WireLayout? layout) @@ -411,12 +406,12 @@ namespace Content.Server.WireHacking case WiresActionMessage msg: var wire = WiresList.Find(x => x.Id == msg.Id); var player = serverMsg.Session.AttachedEntity; - if (wire == null || player == null) + if (wire == null || player == default) { return; } - if (!IoCManager.Resolve().TryGetComponent(player, out HandsComponent? handsComponent)) + if (!_entities.TryGetComponent(player, out HandsComponent? handsComponent)) { Owner.PopupMessage(player, Loc.GetString("wires-component-ui-on-receive-message-no-hands")); return; @@ -428,10 +423,9 @@ namespace Content.Server.WireHacking return; } - var activeHandEntity = handsComponent.GetActiveHand?.Owner; ToolComponent? tool = null; - if(activeHandEntity != null) - IoCManager.Resolve().TryGetComponent(activeHandEntity, out tool); + if (handsComponent.GetActiveHand?.Owner is {Valid: true} activeHandEntity) + _entities.TryGetComponent(activeHandEntity, out tool); var toolSystem = EntitySystem.Get(); switch (msg.Action) @@ -443,8 +437,7 @@ namespace Content.Server.WireHacking return; } - // activeHandEntity cannot be null because tool is not null. - toolSystem.PlayToolSound(activeHandEntity!, tool); + toolSystem.PlayToolSound(tool.Owner, tool); wire.IsCut = true; UpdateUserInterface(); break; @@ -455,8 +448,7 @@ namespace Content.Server.WireHacking return; } - // activeHandEntity cannot be null because tool is not null. - toolSystem.PlayToolSound(activeHandEntity!, tool); + toolSystem.PlayToolSound(tool.Owner, tool); wire.IsCut = false; UpdateUserInterface(); break; @@ -502,7 +494,7 @@ namespace Content.Server.WireHacking async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { - if (!IoCManager.Resolve().TryGetComponent(eventArgs.Using, out var tool)) + if (!_entities.TryGetComponent(eventArgs.Using, out var tool)) { return false; } @@ -514,7 +506,7 @@ namespace Content.Server.WireHacking (tool.Qualities.Contains(_cuttingQuality) || tool.Qualities.Contains(_pulsingQuality))) { - if (IoCManager.Resolve().TryGetComponent(eventArgs.User, out ActorComponent? actor)) + if (_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor)) { OpenInterface(actor.PlayerSession); return true; diff --git a/Content.Shared/Body/Components/SharedBodyComponent.cs b/Content.Shared/Body/Components/SharedBodyComponent.cs index e8ff4886ba..b9dcbbd644 100644 --- a/Content.Shared/Body/Components/SharedBodyComponent.cs +++ b/Content.Shared/Body/Components/SharedBodyComponent.cs @@ -468,7 +468,7 @@ namespace Content.Shared.Body.Components var i = 0; foreach (var (part, slot) in SlotParts) { - parts[i] = (slot.Id, OwnerUid: ((IComponent) part).Owner); + parts[i] = (slot.Id, Owner: ((IComponent) part).Owner); i++; } @@ -542,12 +542,12 @@ namespace Content.Shared.Body.Components foreach (var (slot, partId) in PartIds) { - if (!entityManager.TryGetEntity(partId, out var entity)) + if (!entityManager.EntityExists(partId)) { continue; } - if (!IoCManager.Resolve().TryGetComponent(entity.Value, out SharedBodyPartComponent? part)) + if (!entityManager.TryGetComponent(partId, out SharedBodyPartComponent? part)) { continue; } diff --git a/Content.Shared/Body/Components/SharedBodyPartComponent.cs b/Content.Shared/Body/Components/SharedBodyPartComponent.cs index 4e42a05f5f..f2d70c6bdb 100644 --- a/Content.Shared/Body/Components/SharedBodyPartComponent.cs +++ b/Content.Shared/Body/Components/SharedBodyPartComponent.cs @@ -8,7 +8,6 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; @@ -293,7 +292,7 @@ namespace Content.Shared.Body.Components return false; } - IoCManager.Resolve().DeleteEntity((EntityUid) mechanism.Owner); + IoCManager.Resolve().DeleteEntity(mechanism.Owner); return true; } @@ -365,12 +364,12 @@ namespace Content.Shared.Body.Components foreach (var id in MechanismIds) { - if (!entityManager.TryGetEntity(id, out var entity)) + if (!entityManager.EntityExists(id)) { continue; } - if (!IoCManager.Resolve().TryGetComponent(entity.Value, out SharedMechanismComponent? mechanism)) + if (!entityManager.TryGetComponent(id, out SharedMechanismComponent? mechanism)) { continue; } diff --git a/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs b/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs index abb6b9b500..587fd4b1cf 100644 --- a/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs +++ b/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs @@ -144,7 +144,7 @@ namespace Content.Shared.Chemistry.Reaction /// Perform a reaction on a solution. This assumes all reaction criteria are met. /// Removes the reactants from the solution, then returns a solution with all products. /// - private Solution PerformReaction(Solution solution, EntityUid ownerUid, ReactionPrototype reaction, FixedPoint2 unitReactions) + private Solution PerformReaction(Solution solution, EntityUid Owner, ReactionPrototype reaction, FixedPoint2 unitReactions) { // We do this so that ReagentEffect can have something to work with, even if it's // a little meaningless. @@ -167,14 +167,14 @@ namespace Content.Shared.Chemistry.Reaction } // Trigger reaction effects - OnReaction(solution, reaction, randomReagent, ownerUid, unitReactions); + OnReaction(solution, reaction, randomReagent, Owner, unitReactions); return products; } - protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid ownerUid, FixedPoint2 unitReactions) + protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid Owner, FixedPoint2 unitReactions) { - var args = new ReagentEffectArgs(ownerUid, null, solution, + var args = new ReagentEffectArgs(Owner, null, solution, randomReagent, unitReactions, EntityManager, null); @@ -185,9 +185,9 @@ namespace Content.Shared.Chemistry.Reaction if (effect.ShouldLog) { - var entity = EntityManager.GetEntity(args.SolutionEntity); + var entity = args.SolutionEntity; _logSystem.Add(LogType.ReagentEffect, effect.LogImpact, - $"Reaction effect {effect.GetType().Name} of reaction ${reaction.ID:reaction} applied on entity {entity} at {IoCManager.Resolve().GetComponent(entity).Coordinates}"); + $"Reaction effect {effect.GetType().Name} of reaction ${reaction.ID:reaction} applied on entity {entity} at {EntityManager.GetComponent(entity).Coordinates}"); } effect.Effect(args); @@ -199,7 +199,7 @@ namespace Content.Shared.Chemistry.Reaction /// Removes the reactants from the solution, then returns a solution with all products. /// WARNING: Does not trigger reactions between solution and new products. /// - private bool ProcessReactions(Solution solution, EntityUid ownerUid, [MaybeNullWhen(false)] out Solution productSolution) + private bool ProcessReactions(Solution solution, EntityUid Owner, [MaybeNullWhen(false)] out Solution productSolution) { foreach(var reactant in solution.Contents) { @@ -211,7 +211,7 @@ namespace Content.Shared.Chemistry.Reaction if (!CanReact(solution, reaction, out var unitReactions)) continue; - productSolution = PerformReaction(solution, ownerUid, reaction, unitReactions); + productSolution = PerformReaction(solution, Owner, reaction, unitReactions); return true; } } @@ -223,11 +223,11 @@ namespace Content.Shared.Chemistry.Reaction /// /// Continually react a solution until no more reactions occur. /// - public void FullyReactSolution(Solution solution, EntityUid ownerUid) + public void FullyReactSolution(Solution solution, EntityUid Owner) { for (var i = 0; i < MaxReactionIterations; i++) { - if (!ProcessReactions(solution, ownerUid, out var products)) + if (!ProcessReactions(solution, Owner, out var products)) return; if (products.TotalVolume <= 0) @@ -235,18 +235,18 @@ namespace Content.Shared.Chemistry.Reaction solution.AddSolution(products); } - Logger.Error($"{nameof(Solution)} {ownerUid} could not finish reacting in under {MaxReactionIterations} loops."); + Logger.Error($"{nameof(Solution)} {Owner} could not finish reacting in under {MaxReactionIterations} loops."); } /// /// Continually react a solution until no more reactions occur, with a volume constraint. /// If a reaction's products would exceed the max volume, some product is deleted. /// - public void FullyReactSolution(Solution solution, EntityUid ownerUid, FixedPoint2 maxVolume) + public void FullyReactSolution(Solution solution, EntityUid Owner, FixedPoint2 maxVolume) { for (var i = 0; i < MaxReactionIterations; i++) { - if (!ProcessReactions(solution, ownerUid, out var products)) + if (!ProcessReactions(solution, Owner, out var products)) return; if (products.TotalVolume <= 0) @@ -262,7 +262,7 @@ namespace Content.Shared.Chemistry.Reaction solution.AddSolution(products); } - Logger.Error($"{nameof(Solution)} {ownerUid} could not finish reacting in under {MaxReactionIterations} loops."); + Logger.Error($"{nameof(Solution)} {Owner} could not finish reacting in under {MaxReactionIterations} loops."); } } } diff --git a/Content.Shared/Chemistry/ReactiveSystem.cs b/Content.Shared/Chemistry/ReactiveSystem.cs index ff22f73b5a..53da3ae6d6 100644 --- a/Content.Shared/Chemistry/ReactiveSystem.cs +++ b/Content.Shared/Chemistry/ReactiveSystem.cs @@ -64,9 +64,9 @@ namespace Content.Shared.Chemistry if (effect.ShouldLog) { - var entity = EntityManager.GetEntity(args.SolutionEntity); + var entity = args.SolutionEntity; _logSystem.Add(LogType.ReagentEffect, effect.LogImpact, - $"Reactive effect {effect.GetType().Name} of reagent {reagent.ID:reagent} with method {method} applied on entity {entity} at {IoCManager.Resolve().GetComponent(entity).Coordinates}"); + $"Reactive effect {effect.GetType().Name} of reagent {reagent.ID:reagent} with method {method} applied on entity {entity} at {EntityManager.GetComponent(entity).Coordinates}"); } effect.Effect(args); @@ -92,9 +92,9 @@ namespace Content.Shared.Chemistry if (effect.ShouldLog) { - var entity = EntityManager.GetEntity(args.SolutionEntity); + var entity = args.SolutionEntity; _logSystem.Add(LogType.ReagentEffect, effect.LogImpact, - $"Reactive effect {effect.GetType().Name} of {entity} using reagent {reagent.ID} with method {method} at {IoCManager.Resolve().GetComponent(entity).Coordinates}"); + $"Reactive effect {effect.GetType().Name} of {entity} using reagent {reagent.ID} with method {method} at {EntityManager.GetComponent(entity).Coordinates}"); } effect.Effect(args); diff --git a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs index 5b235c7890..71076ff794 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Content.Shared.Administration.Logs; using Content.Shared.Body.Prototypes; -using Content.Shared.Botany; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Database; @@ -16,7 +15,6 @@ using Robust.Shared.Random; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; using Robust.Shared.ViewVariables; namespace Content.Shared.Chemistry.Reagent @@ -123,7 +121,7 @@ namespace Content.Shared.Chemistry.Reagent if (plantMetabolizable.ShouldLog) { - var entity = entMan.GetEntity(args.SolutionEntity); + var entity = args.SolutionEntity; EntitySystem.Get().Add(LogType.ReagentEffect, plantMetabolizable.LogImpact, $"Plant metabolism effect {plantMetabolizable.GetType().Name:effect} of reagent {ID} applied on entity {entity} at {IoCManager.Resolve().GetComponent(entity).Coordinates}"); plantMetabolizable.Effect(args); diff --git a/Content.Shared/CombatMode/SharedCombatModeSystem.cs b/Content.Shared/CombatMode/SharedCombatModeSystem.cs index 259ce11d6c..4592dd7546 100644 --- a/Content.Shared/CombatMode/SharedCombatModeSystem.cs +++ b/Content.Shared/CombatMode/SharedCombatModeSystem.cs @@ -1,5 +1,4 @@ using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Shared.CombatMode { @@ -15,7 +14,7 @@ namespace Content.Shared.CombatMode private void CombatModeActiveHandler(CombatModeSystemMessages.SetCombatModeActiveMessage ev, EntitySessionEventArgs eventArgs) { - var entity = eventArgs.SenderSession.AttachedEntityUid; + var entity = eventArgs.SenderSession.AttachedEntity; if (entity == null || !EntityManager.TryGetComponent(entity.Value, out SharedCombatModeComponent? combatModeComponent)) { diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 92d1ee0a72..c6d3d5cf5c 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -35,7 +35,7 @@ namespace Content.Shared.Cuffs private void HandleStopPull(EntityUid uid, SharedCuffableComponent component, StopPullingEvent args) { - if (args.User == null || !EntityManager.TryGetEntity(args.User.Value, out var user)) return; + if (args.User == null || !EntityManager.EntityExists(args.User.Value) return; if (user == component.Owner && !component.CanStillInteract) { diff --git a/Content.Shared/Flash/SharedFlashSystem.cs b/Content.Shared/Flash/SharedFlashSystem.cs index 0360a07ae4..ad107690d9 100644 --- a/Content.Shared/Flash/SharedFlashSystem.cs +++ b/Content.Shared/Flash/SharedFlashSystem.cs @@ -16,7 +16,7 @@ namespace Content.Shared.Flash private void OnGetStateAttempt(EntityUid uid, SharedFlashableComponent component, ComponentGetStateAttemptEvent args) { // Only send state to the player attached to the entity. - if (args.Player.AttachedEntityUid != uid) + if (args.Player.AttachedEntity != uid) args.Cancel(); } diff --git a/Content.Shared/Gravity/SharedGravitySystem.cs b/Content.Shared/Gravity/SharedGravitySystem.cs index 4601e6bbac..8f5741e215 100644 --- a/Content.Shared/Gravity/SharedGravitySystem.cs +++ b/Content.Shared/Gravity/SharedGravitySystem.cs @@ -12,7 +12,7 @@ namespace Content.Shared.Gravity private void HandleGridInitialize(GridInitializeEvent ev) { - var gridEnt = EntityManager.GetEntity(ev.EntityUid); + var gridev.EntityUid gridEnt.EnsureComponent(); } } diff --git a/Content.Shared/Hands/Components/SharedHandsComponent.cs b/Content.Shared/Hands/Components/SharedHandsComponent.cs index 0eff6297f4..ec2bc45be6 100644 --- a/Content.Shared/Hands/Components/SharedHandsComponent.cs +++ b/Content.Shared/Hands/Components/SharedHandsComponent.cs @@ -14,7 +14,6 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -216,23 +215,23 @@ namespace Content.Shared.Hands.Components if (!TryGetActiveHand(out var hand)) return false; - return hand.HeldEntity != null; + return hand.HeldEntity != default; } - public bool TryGetHeldEntity(string handName, [NotNullWhen(true)] out EntityUid? heldEntity) + public bool TryGetHeldEntity(string handName, out EntityUid heldEntity) { - heldEntity = null; + heldEntity = default; if (!TryGetHand(handName, out var hand)) return false; heldEntity = hand.HeldEntity; - return heldEntity != null; + return heldEntity != default; } - public bool TryGetActiveHeldEntity([NotNullWhen(true)] out EntityUid? heldEntity) + public bool TryGetActiveHeldEntity(out EntityUid heldEntity) { - heldEntity = GetActiveHand()?.HeldEntity; + heldEntity = GetActiveHand()?.HeldEntity ?? default; return heldEntity != null; } @@ -250,7 +249,7 @@ namespace Content.Shared.Hands.Components { foreach (var hand in Hands) { - if (hand.HeldEntity != null) + if (hand.HeldEntity != default) yield return hand.HeldEntity.Value; } } @@ -264,7 +263,7 @@ namespace Content.Shared.Hands.Components int acc = 0; foreach (var hand in Hands) { - if (hand.HeldEntity == null) + if (hand.HeldEntity == default) acc += 1; } @@ -892,9 +891,9 @@ namespace Content.Shared.Hands.Components public IContainer? Container { get; set; } [ViewVariables] - public EntityUid? HeldEntity => Container?.ContainedEntities?.FirstOrDefault(); + public EntityUid HeldEntity => Container?.ContainedEntities.FirstOrDefault() ?? EntityUid.Invalid; - public bool IsEmpty => HeldEntity == null; + public bool IsEmpty => HeldEntity == default; public Hand(string name, HandLocation location, IContainer? container = null) { diff --git a/Content.Shared/Hands/SharedHandsSystem.cs b/Content.Shared/Hands/SharedHandsSystem.cs index dc8829c822..eed8c4e5c4 100644 --- a/Content.Shared/Hands/SharedHandsSystem.cs +++ b/Content.Shared/Hands/SharedHandsSystem.cs @@ -1,9 +1,8 @@ +using System; using Content.Shared.Hands.Components; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; -using System; -using Robust.Shared.IoC; namespace Content.Shared.Hands { @@ -21,9 +20,9 @@ namespace Content.Shared.Hands private void HandleSetHand(RequestSetHandEvent msg, EntitySessionEventArgs eventArgs) { - var entity = eventArgs.SenderSession.AttachedEntityUid; + var entity = eventArgs.SenderSession.AttachedEntity; - if (entity == null || !EntityManager.TryGetComponent(entity.Value, out SharedHandsComponent? hands)) + if (entity == default || !EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands)) return; hands.ActiveHand = msg.HandName; diff --git a/Content.Shared/Interaction/Helpers/SharedUnobstructedExtensions.cs b/Content.Shared/Interaction/Helpers/SharedUnobstructedExtensions.cs index 6f334c5579..ae640e2538 100644 --- a/Content.Shared/Interaction/Helpers/SharedUnobstructedExtensions.cs +++ b/Content.Shared/Interaction/Helpers/SharedUnobstructedExtensions.cs @@ -24,10 +24,7 @@ namespace Content.Shared.Interaction.Helpers bool popup = false, IEntityManager? entityManager = null) { - entityManager ??= IoCManager.Resolve(); - - return InRangeUnobstructed(entityManager.GetEntity(origin), entityManager.GetEntity(other), - range, collisionMask, predicate, ignoreInsideBlocker, popup); + return SharedInteractionSystem.InRangeUnobstructed(origin, other, range, collisionMask, predicate, ignoreInsideBlocker, popup); } public static bool InRangeUnobstructed( diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 34ad79f71c..1f15f1b9e1 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -154,7 +154,7 @@ namespace Content.Shared.Interaction foreach (var result in rayResults) { - if (!IoCManager.Resolve().TryGetComponent(result.HitEntity, out IPhysBody? p)) + if (!EntityManager.TryGetComponent(result.HitEntity, out IPhysBody? p)) { continue; } @@ -213,7 +213,7 @@ namespace Content.Shared.Interaction bool popup = false) { predicate ??= e => e == origin || e == other; - return InRangeUnobstructed(origin, IoCManager.Resolve().GetComponent(other).MapPosition, range, collisionMask, predicate, ignoreInsideBlocker, popup); + return InRangeUnobstructed(origin, EntityManager.GetComponent(other).MapPosition, range, collisionMask, predicate, ignoreInsideBlocker, popup); } /// @@ -345,7 +345,7 @@ namespace Content.Shared.Interaction bool ignoreInsideBlocker = false, bool popup = false) { - var originPosition = IoCManager.Resolve().GetComponent(origin).MapPosition; + var originPosition = EntityManager.GetComponent(origin).MapPosition; predicate ??= e => e == origin; var inRange = InRangeUnobstructed(originPosition, other, range, collisionMask, predicate, ignoreInsideBlocker); @@ -392,7 +392,7 @@ namespace Content.Shared.Interaction var interactUsingEventArgs = new InteractUsingEventArgs(user, clickLocation, used, target); - var interactUsings = IoCManager.Resolve().GetComponents(target).OrderByDescending(x => x.Priority); + var interactUsings = EntityManager.GetComponents(target).OrderByDescending(x => x.Priority); foreach (var interactUsing in interactUsings) { // If an InteractUsing returns a status completion we finish our interaction @@ -415,7 +415,7 @@ namespace Content.Shared.Interaction return true; var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, target, canReach); - var afterInteracts = IoCManager.Resolve().GetComponents(used).OrderByDescending(x => x.Priority).ToList(); + var afterInteracts = EntityManager.GetComponents(used).OrderByDescending(x => x.Priority).ToList(); foreach (var afterInteract in afterInteracts) { @@ -441,7 +441,7 @@ namespace Content.Shared.Interaction protected void InteractionActivate(EntityUid user, EntityUid used) { - if (IoCManager.Resolve().TryGetComponent(used, out var delayComponent)) + if (EntityManager.TryGetComponent(used, out var delayComponent)) { if (delayComponent.ActiveDelay) return; @@ -469,7 +469,7 @@ namespace Content.Shared.Interaction return; } - if (!IoCManager.Resolve().TryGetComponent(used, out IActivate? activateComp)) + if (!EntityManager.TryGetComponent(used, out IActivate? activateComp)) return; var activateEventArgs = new ActivateEventArgs(user, used); @@ -503,7 +503,7 @@ namespace Content.Shared.Interaction /// public void UseInteraction(EntityUid user, EntityUid used) { - if (IoCManager.Resolve().TryGetComponent(used, out var delayComponent)) + if (EntityManager.TryGetComponent(used, out var delayComponent)) { if (delayComponent.ActiveDelay) return; @@ -516,7 +516,7 @@ namespace Content.Shared.Interaction if (useMsg.Handled) return; - var uses = IoCManager.Resolve().GetComponents(used).ToList(); + var uses = EntityManager.GetComponents(used).ToList(); // Try to use item on any components which have the interface foreach (var use in uses) @@ -557,7 +557,7 @@ namespace Content.Shared.Interaction return; } - var comps = IoCManager.Resolve().GetComponents(thrown).ToList(); + var comps = EntityManager.GetComponents(thrown).ToList(); var args = new ThrownEventArgs(user); // Call Thrown on all components that implement the interface @@ -581,7 +581,7 @@ namespace Content.Shared.Interaction if (equipMsg.Handled) return; - var comps = IoCManager.Resolve().GetComponents(equipped).ToList(); + var comps = EntityManager.GetComponents(equipped).ToList(); // Call Thrown on all components that implement the interface foreach (var comp in comps) @@ -601,7 +601,7 @@ namespace Content.Shared.Interaction if (unequipMsg.Handled) return; - var comps = IoCManager.Resolve().GetComponents(equipped).ToList(); + var comps = EntityManager.GetComponents(equipped).ToList(); // Call Thrown on all components that implement the interface foreach (var comp in comps) @@ -622,7 +622,7 @@ namespace Content.Shared.Interaction if (equippedHandMessage.Handled) return; - var comps = IoCManager.Resolve().GetComponents(item).ToList(); + var comps = EntityManager.GetComponents(item).ToList(); foreach (var comp in comps) { @@ -641,7 +641,7 @@ namespace Content.Shared.Interaction if (unequippedHandMessage.Handled) return; - var comps = IoCManager.Resolve().GetComponents(item).ToList(); + var comps = EntityManager.GetComponents(item).ToList(); foreach (var comp in comps) { @@ -678,9 +678,9 @@ namespace Content.Shared.Interaction return; } - IoCManager.Resolve().GetComponent(item).LocalRotation = Angle.Zero; + EntityManager.GetComponent(item).LocalRotation = Angle.Zero; - var comps = IoCManager.Resolve().GetComponents(item).ToList(); + var comps = EntityManager.GetComponents(item).ToList(); // Call Land on all components that implement the interface foreach (var comp in comps) @@ -703,7 +703,7 @@ namespace Content.Shared.Interaction if (handSelectedMsg.Handled) return; - var comps = IoCManager.Resolve().GetComponents(item).ToList(); + var comps = EntityManager.GetComponents(item).ToList(); // Call Land on all components that implement the interface foreach (var comp in comps) @@ -723,7 +723,7 @@ namespace Content.Shared.Interaction if (handDeselectedMsg.Handled) return; - var comps = IoCManager.Resolve().GetComponents(item).ToList(); + var comps = EntityManager.GetComponents(item).ToList(); // Call Land on all components that implement the interface foreach (var comp in comps) diff --git a/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs b/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs index 07fc45be59..74f54aeeab 100644 --- a/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs +++ b/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs @@ -16,13 +16,15 @@ namespace Content.Shared.Movement.Components { public static bool IsWeightless(this EntityUid entity, PhysicsComponent? body = null, EntityCoordinates? coords = null, IMapManager? mapManager = null, IEntityManager? entityManager = null) { - if (body == null) - IoCManager.Resolve().TryGetComponent(entity, out body); + entityManager ??= IoCManager.Resolve(); - if (IoCManager.Resolve().HasComponent(entity) || + if (body == null) + entityManager.TryGetComponent(entity, out body); + + if (entityManager.HasComponent(entity) || (body?.BodyType & (BodyType.Static | BodyType.Kinematic)) != 0) return false; - var transform = IoCManager.Resolve().GetComponent(entity); + var transform = entityManager.GetComponent(entity); var gridId = transform.GridID; if (!gridId.IsValid()) @@ -34,18 +36,15 @@ namespace Content.Shared.Movement.Components mapManager ??= IoCManager.Resolve(); var grid = mapManager.GetGrid(gridId); - var gridEntityId = grid.GridEntityId; - entityManager ??= IoCManager.Resolve(); - var gridEntity = entityManager.GetEntity(gridEntityId); - if (!IoCManager.Resolve().GetComponent(gridEntity).Enabled) + if (!entityManager.GetComponent(grid.GridEntityId).Enabled) { return true; } coords ??= transform.Coordinates; - if (!coords.Value.IsValid(IoCManager.Resolve())) + if (!coords.Value.IsValid(entityManager)) { return true; } diff --git a/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs b/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs index 7731b13a60..bc634059ae 100644 --- a/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs +++ b/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs @@ -46,7 +46,7 @@ namespace Content.Shared.Movement.EntitySystems if (!TryGetAttachedComponent(session, out var moverComp)) return; - var owner = session?.AttachedEntityUid; + var owner = session?.AttachedEntity; if (owner != null && session != null) { @@ -80,7 +80,7 @@ namespace Content.Shared.Movement.EntitySystems { component = default; - var ent = session?.AttachedEntityUid; + var ent = session?.AttachedEntity; if (ent == null || !IoCManager.Resolve().EntityExists(ent.Value)) return false; diff --git a/Content.Shared/Pulling/Components/PullableComponent.cs b/Content.Shared/Pulling/Components/PullableComponent.cs index 0bdee013fd..0aa80c48c1 100644 --- a/Content.Shared/Pulling/Components/PullableComponent.cs +++ b/Content.Shared/Pulling/Components/PullableComponent.cs @@ -1,15 +1,11 @@ using System; -using Content.Shared.Physics.Pull; using Robust.Shared.Analyzers; -using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; -using Robust.Shared.Physics; using Robust.Shared.Physics.Dynamics.Joints; -using Robust.Shared.Players; using Robust.Shared.Serialization; namespace Content.Shared.Pulling.Components @@ -28,14 +24,14 @@ namespace Content.Shared.Pulling.Components /// The current entity pulling this component. /// SharedPullingStateManagementSystem should be writing this. This means definitely not you. /// - public EntityUid? Puller { get; set; } + public EntityUid Puller { get; set; } /// /// The pull joint. /// SharedPullingStateManagementSystem should be writing this. This means probably not you. /// public DistanceJoint? PullJoint { get; set; } - public bool BeingPulled => Puller != null; + public bool BeingPulled => Puller != default; public EntityCoordinates? MovingTo { get; set; } @@ -53,25 +49,25 @@ namespace Content.Shared.Pulling.Components return; } - if (state.Puller == null) + if (!state.Puller.HasValue) { EntitySystem.Get().ForceDisconnectPullable(this); return; } - if (!IoCManager.Resolve().TryGetEntity(state.Puller.Value, out var entity)) + if (!state.Puller.Value.IsValid()) { Logger.Error($"Invalid entity {state.Puller.Value} for pulling"); return; } - if (Puller == entity) + if (Puller == state.Puller) { // don't disconnect and reconnect a puller for no reason return; } - if (!IoCManager.Resolve().TryGetComponent(entity.Value, out var comp)) + if (!IoCManager.Resolve().TryGetComponent(state.Puller.Value, out var comp)) { Logger.Error($"Entity {state.Puller.Value} for pulling had no Puller component"); // ensure it disconnects from any different puller, still @@ -90,7 +86,7 @@ namespace Content.Shared.Pulling.Components protected override void OnRemove() { - if (Puller != null) + if (Puller != default) { // This is absolute paranoia but it's also absolutely necessary. Too many puller state bugs. - 20kdc Logger.ErrorS("c.go.c.pulling", "PULLING STATE CORRUPTION IMMINENT IN PULLABLE {0} - OnRemove called when Puller is set!", Owner); diff --git a/Content.Shared/Pulling/Components/SharedPullerComponent.cs b/Content.Shared/Pulling/Components/SharedPullerComponent.cs index 0a5f3cae10..793137cf53 100644 --- a/Content.Shared/Pulling/Components/SharedPullerComponent.cs +++ b/Content.Shared/Pulling/Components/SharedPullerComponent.cs @@ -1,10 +1,7 @@ -using Content.Shared.Pulling; -using Content.Shared.Movement.Components; -using Robust.Shared.Analyzers; +using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; -using Robust.Shared.ViewVariables; using Robust.Shared.Log; -using Component = Robust.Shared.GameObjects.Component; +using Robust.Shared.ViewVariables; namespace Content.Shared.Pulling.Components { @@ -15,12 +12,12 @@ namespace Content.Shared.Pulling.Components public override string Name => "Puller"; // Before changing how this is updated, please see SharedPullerSystem.RefreshMovementSpeed - public float WalkSpeedModifier => Pulling == null ? 1.0f : 0.75f; + public float WalkSpeedModifier => Pulling == default ? 1.0f : 0.75f; - public float SprintSpeedModifier => Pulling == null ? 1.0f : 0.75f; + public float SprintSpeedModifier => Pulling == default ? 1.0f : 0.75f; [ViewVariables] - public EntityUid? Pulling { get; set; } + public EntityUid Pulling { get; set; } protected override void Shutdown() { @@ -30,7 +27,7 @@ namespace Content.Shared.Pulling.Components protected override void OnRemove() { - if (Pulling != null) + if (Pulling != default) { // This is absolute paranoia but it's also absolutely necessary. Too many puller state bugs. - 20kdc Logger.ErrorS("c.go.c.pulling", "PULLING STATE CORRUPTION IMMINENT IN PULLER {0} - OnRemove called when Pulling is set!", Owner); diff --git a/Content.Shared/Pulling/Systems/SharedPullableSystem.cs b/Content.Shared/Pulling/Systems/SharedPullableSystem.cs index 03b8c48d57..c5b698b8d5 100644 --- a/Content.Shared/Pulling/Systems/SharedPullableSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullableSystem.cs @@ -19,8 +19,8 @@ namespace Content.Shared.Pulling.Systems private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args) { - var entity = args.Session.AttachedEntityUid; - if (entity == null || !_blocker.CanMove(entity.Value)) return; + var entity = args.Session.AttachedEntity; + if (!entity.IsValid() || !_blocker.CanMove(entity)) return; _pullSystem.TryStopPull(component); } } diff --git a/Content.Shared/Pulling/Systems/SharedPullerSystem.cs b/Content.Shared/Pulling/Systems/SharedPullerSystem.cs index e3f59b3d57..bbe212ce9e 100644 --- a/Content.Shared/Pulling/Systems/SharedPullerSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullerSystem.cs @@ -1,6 +1,5 @@ using Content.Shared.Alert; using Content.Shared.Hands; -using Content.Shared.Movement.Components; using Content.Shared.Movement.EntitySystems; using Content.Shared.Physics.Pull; using Content.Shared.Pulling.Components; @@ -31,11 +30,11 @@ namespace Content.Shared.Pulling.Systems if (component.Pulling == null) return; - if (component.Pulling == EntityManager.GetEntity(args.BlockingEntity)) + if (component.Pulling == args.BlockingEntity) { if (EntityManager.TryGetComponent(args.BlockingEntity, out var comp)) { - _pullSystem.TryStopPull(comp, EntityManager.GetEntity(uid)); + _pullSystem.TryStopPull(comp, uid); } } } diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs index aa2a64e8a3..77437d1f27 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs @@ -6,19 +6,18 @@ using Content.Shared.GameTicking; using Content.Shared.Input; using Content.Shared.Physics.Pull; using Content.Shared.Pulling.Components; -using Content.Shared.Pulling.Events; using Content.Shared.Rotatable; +using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Input.Binding; +using Robust.Shared.IoC; +using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Players; -using Robust.Shared.IoC; -using Content.Shared.Verbs; -using Robust.Shared.Localization; namespace Content.Shared.Pulling { @@ -203,11 +202,10 @@ namespace Content.Shared.Pulling private bool HandleMovePulledObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid) { - if (session?.AttachedEntityUid == null) + if (session?.AttachedEntity is not { } player || + !player.IsValid()) return false; - var player = session.AttachedEntityUid.Value; - if (!TryGetPulled(player, out var pulled)) { return false; @@ -233,7 +231,7 @@ namespace Content.Shared.Pulling return _pullers.Remove(puller); } - public EntityUid? GetPulled(EntityUid by) + public EntityUid GetPulled(EntityUid by) { return _pullers.GetValueOrDefault(by); } diff --git a/Content.Shared/Shuttles/Components/PilotComponent.cs b/Content.Shared/Shuttles/Components/PilotComponent.cs index 2e71591334..9477bcc689 100644 --- a/Content.Shared/Shuttles/Components/PilotComponent.cs +++ b/Content.Shared/Shuttles/Components/PilotComponent.cs @@ -4,7 +4,6 @@ using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; -using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -32,7 +31,8 @@ namespace Content.Shared.Shuttles.Components base.HandleComponentState(curState, nextState); if (curState is not PilotComponentState state) return; - if (state.Console == null) + var console = state.Console.GetValueOrDefault(); + if (!console.IsValid()) { Console = null; return; @@ -40,10 +40,9 @@ namespace Content.Shared.Shuttles.Components var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetEntity(state.Console.Value, out var consoleEnt) || - !entityManager.TryGetComponent(consoleEnt.Value, out SharedShuttleConsoleComponent? shuttleConsoleComponent)) + if (!entityManager.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent)) { - Logger.Warning($"Unable to set Helmsman console to {state.Console.Value}"); + Logger.Warning($"Unable to set Helmsman console to {console}"); return; } diff --git a/Content.Shared/Slippery/SharedSlipperySystem.cs b/Content.Shared/Slippery/SharedSlipperySystem.cs index 12407835fe..a02edda17d 100644 --- a/Content.Shared/Slippery/SharedSlipperySystem.cs +++ b/Content.Shared/Slippery/SharedSlipperySystem.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.Administration.Logs; using Content.Shared.Database; @@ -122,7 +121,7 @@ namespace Content.Shared.Slippery foreach (var uid in component.Colliding.ToArray()) { - if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var entity)) + if (!uid.IsValid()) { component.Colliding.Remove(uid); component.Slipped.Remove(uid); @@ -130,7 +129,7 @@ namespace Content.Shared.Slippery continue; } - if (!EntityManager.TryGetComponent(entity.Value, out PhysicsComponent? otherPhysics) || + if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? otherPhysics) || !body.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB())) { component.Colliding.Remove(uid); diff --git a/Content.Shared/StatusEffect/StatusEffectsSystem.cs b/Content.Shared/StatusEffect/StatusEffectsSystem.cs index 8bb30b5187..61c3c94300 100644 --- a/Content.Shared/StatusEffect/StatusEffectsSystem.cs +++ b/Content.Shared/StatusEffect/StatusEffectsSystem.cs @@ -119,7 +119,7 @@ namespace Content.Shared.StatusEffect { // Fuck this shit I hate it var newComponent = (Component) _componentFactory.GetComponent(component); - newComponent.Owner = EntityManager.GetEntity(uid); + newComponent.Owner = uid; EntityManager.AddComponent(uid, newComponent); status.ActiveEffects[key].RelevantComponent = component; diff --git a/Content.Shared/Throwing/ThrownItemSystem.cs b/Content.Shared/Throwing/ThrownItemSystem.cs index 642f5f8662..bcc1384ffd 100644 --- a/Content.Shared/Throwing/ThrownItemSystem.cs +++ b/Content.Shared/Throwing/ThrownItemSystem.cs @@ -1,5 +1,4 @@ using Content.Shared.Administration.Logs; -using Content.Shared.CCVar; using Content.Shared.Database; using Content.Shared.Hands.Components; using Content.Shared.Physics; @@ -44,11 +43,13 @@ namespace Content.Shared.Throwing private void OnHandleState(EntityUid uid, ThrownItemComponent component, ref ComponentHandleState args) { - if (args.Current is not ThrownItemComponentState state || state.Thrower == null) + if (args.Current is not ThrownItemComponentState {Thrower: not null } state || + !state.Thrower.Value.IsValid()) + { return; + } - if(EntityManager.TryGetEntity(state.Thrower.Value, out var entity)) - component.Thrower = entity; + component.Thrower = state.Thrower.Value; } private void ThrowItem(EntityUid uid, ThrownItemComponent component, ThrownEvent args) diff --git a/Content.Shared/Verbs/SharedVerbSystem.cs b/Content.Shared/Verbs/SharedVerbSystem.cs index 236adf6f9c..e6457e200c 100644 --- a/Content.Shared/Verbs/SharedVerbSystem.cs +++ b/Content.Shared/Verbs/SharedVerbSystem.cs @@ -51,7 +51,7 @@ namespace Content.Shared.Verbs // their sprite. if (@using != null && EntityManager.TryGetComponent(@using.Value, out var pull)) { - @using = EntityManager.GetEntity(pull.BlockingEntity); + @using = pull.BlockingEntity } } @@ -113,23 +113,22 @@ namespace Content.Shared.Verbs public void LogVerb(Verb verb, EntityUid userUid, EntityUid targetUid, bool forced) { // first get the held item. again. - EntityUid? usedUid = null; - if (EntityManager.TryGetComponent(userUid, out SharedHandsComponent? hands)) + EntityUid usedUid = default; + if (EntityManager.TryGetComponent(userUid, out SharedHandsComponent? hands) && + hands.TryGetActiveHeldEntity(out var heldEntity)) { - hands.TryGetActiveHeldEntity(out var useEntityd); - usedUid = useEntityd; + usedUid = heldEntity; if (usedUid != null && EntityManager.TryGetComponent(usedUid.Value, out HandVirtualItemComponent? pull)) usedUid = pull.BlockingEntity; } // get all the entities - if (!EntityManager.TryGetEntity(userUid, out var user) || - !EntityManager.TryGetEntity(targetUid, out var target)) + if (!userUid.IsValid() || !targetUid.IsValid()) return; EntityUid? used = null; if (usedUid != null) - EntityManager.TryGetEntity(usedUid.Value, out used); + EntityManager.EntityExists(usedUid.Value); // then prepare the basic log message body var verbText = $"{verb.Category?.Text} {verb.Text}".Trim(); @@ -138,7 +137,7 @@ namespace Content.Shared.Verbs : $"executed '{verbText}' verb targeting "; // then log with entity information - if (used != null) + if (usedUidused != null) _logSystem.Add(LogType.Verb, verb.Impact, $"{user} {logText} {target} while holding {used}"); else diff --git a/Content.Shared/Weapons/Melee/AttackEvent.cs b/Content.Shared/Weapons/Melee/AttackEvent.cs index dda7b419f8..b55bef6b0c 100644 --- a/Content.Shared/Weapons/Melee/AttackEvent.cs +++ b/Content.Shared/Weapons/Melee/AttackEvent.cs @@ -41,8 +41,7 @@ namespace Content.Shared.Weapons.Melee ClickLocation = clickLocation; Target = target; - IoCManager.Resolve().TryGetEntity(Target, out var targetEntity); - TargetEntity = targetEntity; + TargetEntity = IoCManager.Resolve().EntityExists(Target) ? Target : default(EntityUid?); } } diff --git a/Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs b/Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs index b4e4c9772b..dae9806e63 100644 --- a/Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs +++ b/Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs @@ -1,6 +1,4 @@ using System; -using Content.Shared.Chemistry; -using Content.Shared.Chemistry.Reagent; using Content.Shared.FixedPoint; using NUnit.Framework; @@ -108,7 +106,7 @@ namespace Content.Tests.Shared.Chemistry [TestCase(2.005f, 201)] public void FloatRoundingTest(float a, int expected) { - var result = (int) MathF.Round(a * (float) MathF.Pow(10, 2), MidpointRounding.AwayFromZero); + var result = (int) MathF.Round(a * MathF.Pow(10, 2), MidpointRounding.AwayFromZero); Assert.That(result, Is.EqualTo(expected)); }