diff --git a/Content.Server/AI/Utils/Visibility.cs b/Content.Server/AI/Utils/Visibility.cs index 90cb4e5c18..c374b6534a 100644 --- a/Content.Server/AI/Utils/Visibility.cs +++ b/Content.Server/AI/Utils/Visibility.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Content.Server.AI.Components; @@ -58,7 +58,7 @@ namespace Content.Server.AI.Utils public static IEnumerable GetEntitiesInRange(EntityCoordinates grid, Type component, float range) { var entityManager = IoCManager.Resolve(); - foreach (var entity in entityManager.GetEntities(new TypeEntityQuery(component))) + foreach (var entity in entityManager.ComponentManager.GetAllComponents(component).Select(c => c.Owner)) { if (entity.Transform.Coordinates.GetGridId(entityManager) != grid.GetGridId(entityManager)) { diff --git a/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs b/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs index a2e76c22c8..7d4dd506f7 100644 --- a/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs +++ b/Content.Server/Administration/Commands/DeleteEntitiesWithComponent.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Content.Shared.Administration; using Robust.Shared.Console; using Robust.Shared.GameObjects; @@ -34,9 +35,12 @@ namespace Content.Server.Administration.Commands } var entityManager = IoCManager.Resolve(); - var entities = entityManager.GetEntities(new MultipleTypeEntityQuery(components)); + + var entitiesWithComponents = components.Select(c => entityManager.ComponentManager.GetAllComponents(c).Select(x => x.Owner)); + var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; }); + var count = 0; - foreach (var entity in entities) + foreach (var entity in entitiesWithAllComponents) { entity.Delete(); count += 1; diff --git a/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs b/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs index 167a98c751..08551517cd 100644 --- a/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs +++ b/Content.Server/Administration/Commands/DeleteEntitiesWithId.cs @@ -1,8 +1,9 @@ -#nullable enable +#nullable enable using Content.Shared.Administration; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using System.Linq; namespace Content.Server.Administration.Commands { @@ -23,8 +24,7 @@ namespace Content.Server.Administration.Commands var id = args[0].ToLower(); var entityManager = IoCManager.Resolve(); - var query = new PredicateEntityQuery(e => e.Prototype?.ID.ToLower() == id); - var entities = entityManager.GetEntities(query); + var entities = entityManager.GetEntities().Where(e => e.Prototype?.ID.ToLower() == id); var i = 0; foreach (var entity in entities) diff --git a/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs b/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs index 5321465bde..0e4b0b6190 100644 --- a/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs +++ b/Content.Server/Administration/Commands/FindEntitiesWithComponents.cs @@ -1,6 +1,7 @@ -#nullable enable +#nullable enable using System; using System.Collections.Generic; +using System.Linq; using Content.Shared.Administration; using Robust.Shared.Console; using Robust.Shared.GameObjects; @@ -45,10 +46,12 @@ namespace Content.Server.Administration.Commands } var entityManager = IoCManager.Resolve(); - var query = new MultipleTypeEntityQuery(components); var entityIds = new HashSet(); - foreach (var entity in entityManager.GetEntities(query)) + var entitiesWithComponents = components.Select(c => entityManager.ComponentManager.GetAllComponents(c).Select(x => x.Owner)); + var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; }); + + foreach (var entity in entitiesWithAllComponents) { if (entity.Prototype == null) { diff --git a/Content.Server/Battery/DrainAllBatteriesCommand.cs b/Content.Server/Battery/DrainAllBatteriesCommand.cs index fb7329e783..561d171d5b 100644 --- a/Content.Server/Battery/DrainAllBatteriesCommand.cs +++ b/Content.Server/Battery/DrainAllBatteriesCommand.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using Content.Server.Administration; using Content.Server.Battery.Components; using Content.Shared.Administration; @@ -24,10 +24,11 @@ namespace Content.Server.Battery } var entityManager = IoCManager.Resolve(); - foreach (var ent in entityManager.GetEntities(new TypeEntityQuery(typeof(BatteryComponent)))) + foreach (var batteryComp in entityManager.ComponentManager.EntityQuery()) { - ent.GetComponent().CurrentCharge = 0; + batteryComp.CurrentCharge = 0; } + shell.WriteLine("Done!"); } } diff --git a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs index 684769beac..a4a8bb6e06 100644 --- a/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs +++ b/Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Content.Server.Atmos; using Content.Server.Chat.Managers; using Content.Server.GameTicking.Rules; @@ -11,7 +12,6 @@ using Content.Server.Players; using Content.Server.Spawners.Components; using Content.Server.Traitor; using Content.Server.TraitorDeathMatch.Components; -using Content.Shared; using Content.Shared.CCVar; using Content.Shared.Damage; using Content.Shared.Damage.Components; @@ -158,7 +158,7 @@ namespace Content.Server.GameTicking.Presets // On failure, the returned target is the location that we're already at. var bestTargetDistanceFromNearest = -1.0f; // Need the random shuffle or it stuffs the first person into Atmospherics pretty reliably - var ents = new List(_entityManager.GetEntities(new TypeEntityQuery(typeof(SpawnPointComponent)))); + var ents = _entityManager.ComponentManager.EntityQuery().Select(x => x.Owner).ToList(); _robustRandom.Shuffle(ents); var foundATarget = false; bestTarget = EntityCoordinates.Invalid; @@ -215,9 +215,8 @@ namespace Content.Server.GameTicking.Presets { var lines = new List(); lines.Add("traitor-death-match-end-round-description-first-line"); - foreach (var entity in _entityManager.GetEntities(new TypeEntityQuery(typeof(PDAComponent)))) + foreach (var pda in _entityManager.ComponentManager.EntityQuery()) { - var pda = entity.GetComponent(); var uplink = pda.SyndicateUplinkAccount; if (uplink != null && _allOriginalNames.ContainsKey(uplink)) { diff --git a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs index 8737c503bd..41d40c471c 100644 --- a/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs +++ b/Content.Server/Morgue/Components/MorgueEntityStorageComponent.cs @@ -7,7 +7,6 @@ using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Morgue; -using Content.Shared.Notification; using Content.Shared.Notification.Managers; using Content.Shared.Physics; using Robust.Server.GameObjects; @@ -93,7 +92,6 @@ namespace Content.Server.Morgue.Components _tray = Owner.EntityManager.SpawnEntity(_trayPrototypeId, Owner.Transform.Coordinates); var trayComp = _tray.EnsureComponent(); trayComp.Morgue = Owner; - EntityQuery = new IntersectingEntityQuery(_tray); } else { diff --git a/Content.Server/Singularity/StartSingularityEngineCommand.cs b/Content.Server/Singularity/StartSingularityEngineCommand.cs index 3b99e1e407..6a479f5fa1 100644 --- a/Content.Server/Singularity/StartSingularityEngineCommand.cs +++ b/Content.Server/Singularity/StartSingularityEngineCommand.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using Content.Server.Administration; using Content.Server.ParticleAccelerator.Components; using Content.Server.Singularity.Components; @@ -26,20 +26,19 @@ namespace Content.Server.Singularity } var entityManager = IoCManager.Resolve(); - foreach (var ent in entityManager.GetEntities(new TypeEntityQuery(typeof(EmitterComponent)))) + foreach (var comp in entityManager.ComponentManager.EntityQuery()) { - ent.GetComponent().SwitchOn(); + comp.SwitchOn(); } - foreach (var ent in entityManager.GetEntities(new TypeEntityQuery(typeof(RadiationCollectorComponent)))) + foreach (var comp in entityManager.ComponentManager.EntityQuery()) { - ent.GetComponent().Collecting = true; + comp.Collecting = true; } - foreach (var ent in entityManager.GetEntities(new TypeEntityQuery(typeof(ParticleAcceleratorControlBoxComponent)))) + foreach (var comp in entityManager.ComponentManager.EntityQuery()) { - var pacb = ent.GetComponent(); - pacb.RescanParts(); - pacb.SetStrength(ParticleAcceleratorPowerState.Level0); - pacb.SwitchOn(); + comp.RescanParts(); + comp.SetStrength(ParticleAcceleratorPowerState.Level0); + comp.SwitchOn(); } shell.WriteLine("Done!"); } diff --git a/Content.Server/Storage/Components/CursedEntityStorageComponent.cs b/Content.Server/Storage/Components/CursedEntityStorageComponent.cs index 5753efd0c1..6bceb104c4 100644 --- a/Content.Server/Storage/Components/CursedEntityStorageComponent.cs +++ b/Content.Server/Storage/Components/CursedEntityStorageComponent.cs @@ -26,7 +26,7 @@ namespace Content.Server.Storage.Components // No contents, we do nothing if (Contents.ContainedEntities.Count == 0) return; - var lockers = Owner.EntityManager.GetEntities(new TypeEntityQuery(typeof(EntityStorageComponent))).ToList(); + var lockers = Owner.EntityManager.ComponentManager.EntityQuery().Select(c => c.Owner).ToList(); if (lockers.Contains(Owner)) lockers.Remove(Owner); diff --git a/Content.Server/Storage/Components/EntityStorageComponent.cs b/Content.Server/Storage/Components/EntityStorageComponent.cs index 3b5ecd277b..44993c0c19 100644 --- a/Content.Server/Storage/Components/EntityStorageComponent.cs +++ b/Content.Server/Storage/Components/EntityStorageComponent.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Content.Server.Hands.Components; @@ -11,7 +12,6 @@ using Content.Shared.Body.Components; using Content.Shared.Interaction; using Content.Shared.Item; using Content.Shared.Movement; -using Content.Shared.Notification; using Content.Shared.Notification.Managers; using Content.Shared.Physics; using Content.Shared.Storage; @@ -25,6 +25,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Physics; +using Robust.Shared.Physics.Broadphase; using Robust.Shared.Player; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; @@ -59,9 +60,6 @@ namespace Content.Server.Storage.Components [DataField("IsCollidableWhenOpen")] private bool _isCollidableWhenOpen; - [ViewVariables] - protected IEntityQuery? EntityQuery; - [DataField("showContents")] private bool _showContents; @@ -150,8 +148,6 @@ namespace Content.Server.Storage.Components { base.Initialize(); Contents = Owner.EnsureContainer(nameof(EntityStorageComponent)); - EntityQuery = new IntersectingEntityQuery(Owner); - Contents.ShowContents = _showContents; Contents.OccludesLight = _occludesLight; @@ -198,13 +194,12 @@ namespace Content.Server.Storage.Components protected virtual void CloseStorage() { Open = false; - EntityQuery ??= new IntersectingEntityQuery(Owner); - var entities = Owner.EntityManager.GetEntities(EntityQuery); + var count = 0; - foreach (var entity in entities) + foreach (var entity in DetermineCollidingEntities()) { // prevents taking items out of inventories, out of containers, and orphaning child entities - if(!entity.Transform.IsMapTransform) + if (entity.IsInContainer()) continue; // only items that can be stored in an inventory, or a mob, can be eaten by a locker @@ -442,6 +437,12 @@ namespace Content.Server.Storage.Components EmptyContents(); } + protected IEnumerable DetermineCollidingEntities() + { + var entityLookup = IoCManager.Resolve(); + return entityLookup.GetEntitiesIntersecting(Owner); + } + [Verb] private sealed class OpenToggleVerb : Verb {