diff --git a/Content.Server/Administration/Commands/ControlMob.cs b/Content.Server/Administration/Commands/ControlMob.cs index 317461a373..9d39cb9dde 100644 --- a/Content.Server/Administration/Commands/ControlMob.cs +++ b/Content.Server/Administration/Commands/ControlMob.cs @@ -33,15 +33,15 @@ namespace Content.Server.Administration.Commands return; } - var target = new EntityUid(targetId); + var targetNet = new NetEntity(targetId); - if (!target.IsValid() || !_entities.EntityExists(target)) + if (!_entities.TryGetEntity(targetNet, out var target)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } - _entities.System().ControlMob(player.UserId, target); + _entities.System().ControlMob(player.UserId, target.Value); } } } diff --git a/Content.Server/Administration/Commands/OwoifyCommand.cs b/Content.Server/Administration/Commands/OwoifyCommand.cs index 73a1236d19..8ca35b1b42 100644 --- a/Content.Server/Administration/Commands/OwoifyCommand.cs +++ b/Content.Server/Administration/Commands/OwoifyCommand.cs @@ -8,6 +8,8 @@ namespace Content.Server.Administration.Commands; [AdminCommand(AdminFlags.Fun)] public sealed class OwoifyCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entManager = default!; + public string Command => "owoify"; public string Description => "For when you need everything to be cat. Uses OwOAccent's formatting on the name and description of an entity."; @@ -22,22 +24,25 @@ public sealed class OwoifyCommand : IConsoleCommand 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 nent = new NetEntity(targetId); - var meta = entityManager.GetComponent(eUid); + if (!_entManager.TryGetEntity(nent, out var eUid)) + { + return; + } - var owoSys = entityManager.System(); - var metaDataSys = entityManager.System(); + var meta = _entManager.GetComponent(eUid.Value); - metaDataSys.SetEntityName(eUid, owoSys.Accentuate(meta.EntityName), meta); - metaDataSys.SetEntityDescription(eUid, owoSys.Accentuate(meta.EntityDescription), meta); + var owoSys = _entManager.System(); + var metaDataSys = _entManager.System(); + + metaDataSys.SetEntityName(eUid.Value, owoSys.Accentuate(meta.EntityName), meta); + metaDataSys.SetEntityDescription(eUid.Value, owoSys.Accentuate(meta.EntityDescription), meta); } } diff --git a/Content.Server/Administration/Commands/SetMindCommand.cs b/Content.Server/Administration/Commands/SetMindCommand.cs index 5310c2dd7f..a7b6849423 100644 --- a/Content.Server/Administration/Commands/SetMindCommand.cs +++ b/Content.Server/Administration/Commands/SetMindCommand.cs @@ -11,6 +11,7 @@ namespace Content.Server.Administration.Commands [AdminCommand(AdminFlags.Admin)] sealed class SetMindCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entManager = default!; public string Command => "setmind"; @@ -26,7 +27,7 @@ namespace Content.Server.Administration.Commands return; } - if (!int.TryParse(args[0], out var entityUid)) + if (!int.TryParse(args[0], out var entInt)) { shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number")); return; @@ -38,17 +39,15 @@ namespace Content.Server.Administration.Commands ghostOverride = bool.Parse(args[2]); } - var entityManager = IoCManager.Resolve(); + var nent = new NetEntity(entInt); - var eUid = new EntityUid(entityUid); - - if (!eUid.IsValid() || !entityManager.EntityExists(eUid)) + if (!_entManager.TryGetEntity(nent, out var eUid)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } - if (!entityManager.HasComponent(eUid)) + if (!_entManager.HasComponent(eUid)) { shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-mind-message")); return; @@ -68,8 +67,8 @@ namespace Content.Server.Administration.Commands return; } - var mindSystem = entityManager.System(); - var metadata = entityManager.GetComponent(eUid); + var mindSystem = _entManager.System(); + var metadata = _entManager.GetComponent(eUid.Value); var mind = playerCData.Mind ?? mindSystem.CreateMind(session.UserId, metadata.EntityName); diff --git a/Content.Server/Administration/Commands/SetOutfitCommand.cs b/Content.Server/Administration/Commands/SetOutfitCommand.cs index 72ff9ff9b6..79e73ce3d9 100644 --- a/Content.Server/Administration/Commands/SetOutfitCommand.cs +++ b/Content.Server/Administration/Commands/SetOutfitCommand.cs @@ -34,21 +34,21 @@ namespace Content.Server.Administration.Commands return; } - if (!int.TryParse(args[0], out var entityUid)) + if (!int.TryParse(args[0], out var entInt)) { shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number")); return; } - var target = new EntityUid(entityUid); + var nent = new NetEntity(entInt); - if (!target.IsValid() || !_entities.EntityExists(target)) + if (!_entities.TryGetEntity(nent, out var target)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } - if (!_entities.HasComponent(target)) + if (!_entities.HasComponent(target)) { shell.WriteLine(Loc.GetString("shell-target-entity-does-not-have-message", ("missing", "inventory"))); return; @@ -63,12 +63,12 @@ namespace Content.Server.Administration.Commands } var eui = IoCManager.Resolve(); - var ui = new SetOutfitEui(target); + var ui = new SetOutfitEui(nent); eui.OpenEui(ui, player); return; } - if (!SetOutfit(target, args[1], _entities)) + if (!SetOutfit(target.Value, args[1], _entities)) shell.WriteLine(Loc.GetString("set-outfit-command-invalid-outfit-id-error")); } diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.cs b/Content.Server/Administration/Systems/AdminVerbSystem.cs index cfd8311d8e..b476477ab7 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.cs @@ -385,7 +385,7 @@ namespace Content.Server.Administration.Systems Text = Loc.GetString("set-outfit-verb-get-data-text"), Category = VerbCategory.Debug, Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/outfit.svg.192dpi.png")), - Act = () => _euiManager.OpenEui(new SetOutfitEui(args.Target), player), + Act = () => _euiManager.OpenEui(new SetOutfitEui(GetNetEntity(args.Target)), player), Impact = LogImpact.Medium }; args.Verbs.Add(verb); diff --git a/Content.Server/Administration/UI/SetOutfitEui.cs b/Content.Server/Administration/UI/SetOutfitEui.cs index 6243657c32..2812975f4d 100644 --- a/Content.Server/Administration/UI/SetOutfitEui.cs +++ b/Content.Server/Administration/UI/SetOutfitEui.cs @@ -10,10 +10,9 @@ namespace Content.Server.Administration.UI public sealed class SetOutfitEui : BaseEui { [Dependency] private readonly IAdminManager _adminManager = default!; - [Dependency] private readonly IEntityManager _entManager = default!; - private readonly EntityUid _target; + private readonly NetEntity _target; - public SetOutfitEui(EntityUid entity) + public SetOutfitEui(NetEntity entity) { _target = entity; IoCManager.InjectDependencies(this); @@ -31,7 +30,7 @@ namespace Content.Server.Administration.UI { return new SetOutfitEuiState { - TargetNetEntity = _entManager.GetNetEntity(_target) + TargetNetEntity = _target, }; } diff --git a/Content.Server/Commands/ActionCommands.cs b/Content.Server/Commands/ActionCommands.cs index 280bf75a61..5ce29b6d8e 100644 --- a/Content.Server/Commands/ActionCommands.cs +++ b/Content.Server/Commands/ActionCommands.cs @@ -31,13 +31,13 @@ internal sealed class UpgradeActionCommand : IConsoleCommand var actionUpgrade = _entMan.EntitySysManager.GetEntitySystem(); var id = args[0]; - if (!EntityUid.TryParse(id, out var uid)) + if (!NetEntity.TryParse(id, out var nuid)) { shell.WriteLine(Loc.GetString("upgradeaction-command-incorrect-entityuid-format")); return; } - if (!_entMan.EntityExists(uid)) + if (!_entMan.TryGetEntity(nuid, out var uid)) { shell.WriteLine(Loc.GetString("upgradeaction-command-entity-does-not-exist")); return; diff --git a/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs b/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs index 6a17a52c3d..872df8eae8 100644 --- a/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs +++ b/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs @@ -52,7 +52,8 @@ public sealed class RandomHumanoidSystem : EntitySystem { var comp = (Component) _serialization.CreateCopy(entry.Component, notNullableOverride: true); comp.Owner = humanoid; // This .owner must survive for now. - EntityManager.AddComponent(humanoid, comp, true); + EntityManager.RemoveComponent(humanoid, comp.GetType()); + EntityManager.AddComponent(humanoid, comp); } } diff --git a/Content.Server/Jobs/AddComponentSpecial.cs b/Content.Server/Jobs/AddComponentSpecial.cs index 1b183c5c3f..c57d734354 100644 --- a/Content.Server/Jobs/AddComponentSpecial.cs +++ b/Content.Server/Jobs/AddComponentSpecial.cs @@ -27,7 +27,8 @@ namespace Content.Server.Jobs var temp = (object) component; serializationManager.CopyTo(data.Component, ref temp); - entityManager.AddComponent(mob, (Component) temp!, true); + entityManager.RemoveComponent(mob, temp!.GetType()); + entityManager.AddComponent(mob, (Component) temp); } } } diff --git a/Content.Server/NPC/Commands/AddNPCCommand.cs b/Content.Server/NPC/Commands/AddNPCCommand.cs index 070b9f35d3..c5582b7b4c 100644 --- a/Content.Server/NPC/Commands/AddNPCCommand.cs +++ b/Content.Server/NPC/Commands/AddNPCCommand.cs @@ -24,11 +24,11 @@ namespace Content.Server.NPC.Commands return; } - var entId = new EntityUid(int.Parse(args[0])); + var nent = new NetEntity(int.Parse(args[0])); - if (!_entities.EntityExists(entId)) + if (!_entities.TryGetEntity(nent, out var entId)) { - shell.WriteError($"Unable to find entity with uid {entId}"); + shell.WriteError($"Unable to find entity {nent}"); return; } @@ -38,7 +38,7 @@ namespace Content.Server.NPC.Commands return; } - var comp = _entities.AddComponent(entId); + var comp = _entities.AddComponent(entId.Value); comp.RootTask = new HTNCompoundTask() { Task = args[1] diff --git a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs index cc20b71946..2ab29d1b2f 100644 --- a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs +++ b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs @@ -11,6 +11,9 @@ namespace Content.Server.Sandbox.Commands [AnyCommand] public sealed class ColorNetworkCommand : IConsoleCommand { + [Dependency] private readonly IAdminManager _adminManager = default!; + [Dependency] private readonly IEntityManager _entManager = default!; + public string Command => "colornetwork"; public string Description => Loc.GetString("color-network-command-description"); public string Help => Loc.GetString("color-network-command-help-text", ("command",Command)); @@ -30,25 +33,21 @@ namespace Content.Server.Sandbox.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 nent = new NetEntity(targetId); - if (!eUid.IsValid() || !entityManager.EntityExists(eUid)) + if (!_entManager.TryGetEntity(nent, out var eUid)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; } - if (!entityManager.TryGetComponent(eUid, out NodeContainerComponent? nodeContainerComponent)) + if (!_entManager.TryGetComponent(eUid, out NodeContainerComponent? nodeContainerComponent)) { shell.WriteLine(Loc.GetString("shell-entity-is-not-node-container")); return; @@ -74,13 +73,15 @@ namespace Content.Server.Sandbox.Commands { var group = nodeContainerComponent.Nodes[nodeGroupId.ToString().ToLower()].NodeGroup; - if (group == null) return; + if (group == null) + return; foreach (var x in group.Nodes) { - if (!IoCManager.Resolve().TryGetComponent(x.Owner, out AtmosPipeColorComponent? atmosPipeColorComponent)) continue; + if (!_entManager.TryGetComponent(x.Owner, out AtmosPipeColorComponent? atmosPipeColorComponent)) + continue; - EntitySystem.Get().SetColor(x.Owner, atmosPipeColorComponent, color); + _entManager.System().SetColor(x.Owner, atmosPipeColorComponent, color); } } } diff --git a/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs b/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs index fd656a9f71..cdaed3f928 100644 --- a/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs +++ b/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs @@ -12,6 +12,10 @@ namespace Content.Server.Traitor.Uplink.Commands [AdminCommand(AdminFlags.Admin)] public sealed class AddUplinkCommand : IConsoleCommand { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; + [Dependency] private readonly IEntityManager _entManager = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + public string Command => "adduplink"; public string Description => Loc.GetString("add-uplink-command-description"); @@ -41,7 +45,7 @@ namespace Content.Server.Traitor.Uplink.Commands if (args.Length > 0) { // Get player entity - if (!IoCManager.Resolve().TryGetSessionByUsername(args[0], out session)) + if (!_playerManager.TryGetSessionByUsername(args[0], out session)) { shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist")); return; @@ -60,7 +64,6 @@ namespace Content.Server.Traitor.Uplink.Commands // Get target item EntityUid? uplinkEntity = null; - var entityManager = IoCManager.Resolve(); if (args.Length >= 2) { if (!int.TryParse(args[1], out var itemID)) @@ -69,8 +72,9 @@ namespace Content.Server.Traitor.Uplink.Commands return; } - var eUid = new EntityUid(itemID); - if (!eUid.IsValid() || !entityManager.EntityExists(eUid)) + var eNet = new NetEntity(itemID); + + if (!_entManager.TryGetEntity(eNet, out var eUid)) { shell.WriteLine(Loc.GetString("shell-invalid-entity-id")); return; @@ -80,11 +84,10 @@ namespace Content.Server.Traitor.Uplink.Commands } // Get TC count - var configManager = IoCManager.Resolve(); - var tcCount = configManager.GetCVar(CCVars.TraitorStartingBalance); - Logger.Debug(entityManager.ToPrettyString(user)); + var tcCount = _cfgManager.GetCVar(CCVars.TraitorStartingBalance); + Logger.Debug(_entManager.ToPrettyString(user)); // Finally add uplink - var uplinkSys = entityManager.EntitySysManager.GetEntitySystem(); + var uplinkSys = _entManager.System(); if (!uplinkSys.AddUplink(user, FixedPoint2.New(tcCount), uplinkEntity: uplinkEntity)) { shell.WriteLine(Loc.GetString("add-uplink-command-error-2")); diff --git a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs index af2131fb55..7d87f685f7 100644 --- a/Content.Server/Verbs/Commands/InvokeVerbCommand.cs +++ b/Content.Server/Verbs/Commands/InvokeVerbCommand.cs @@ -9,6 +9,8 @@ namespace Content.Server.Verbs.Commands [AdminCommand(AdminFlags.Admin)] public sealed class InvokeVerbCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entManager = default!; + public string Command => "invokeverb"; public string Description => Loc.GetString("invoke-verb-command-description"); public string Help => Loc.GetString("invoke-verb-command-help"); @@ -21,8 +23,7 @@ namespace Content.Server.Verbs.Commands return; } - var entityManager = IoCManager.Resolve(); - var verbSystem = entityManager.System(); + var verbSystem = _entManager.System(); // get the 'player' entity (defaulting to command user, otherwise uses a uid) EntityUid? playerEntity = null; @@ -40,7 +41,7 @@ namespace Content.Server.Verbs.Commands } else { - entityManager.EntityExists(new EntityUid(intPlayerUid)); + _entManager.TryGetEntity(new NetEntity(intPlayerUid), out playerEntity); } // gets the target entity @@ -56,16 +57,16 @@ namespace Content.Server.Verbs.Commands return; } - var target = new EntityUid(intUid); - if (!entityManager.EntityExists(target)) + var targetNet = new NetEntity(intUid); + + if (!_entManager.TryGetEntity(targetNet, out var target)) { shell.WriteError(Loc.GetString("invoke-verb-command-invalid-target-entity")); return; } var verbName = args[2].ToLowerInvariant(); - var verbs = verbSystem.GetLocalVerbs(target, playerEntity.Value, Verb.VerbTypes, true); - + var verbs = verbSystem.GetLocalVerbs(target.Value, playerEntity.Value, Verb.VerbTypes, true); // if the "verb name" is actually a verb-type, try run any verb of that type. var verbType = Verb.VerbTypes.FirstOrDefault(x => x.Name == verbName); @@ -74,7 +75,7 @@ namespace Content.Server.Verbs.Commands var verb = verbs.FirstOrDefault(v => v.GetType() == verbType); if (verb != null) { - verbSystem.ExecuteVerb(verb, playerEntity.Value, target, forced: true); + verbSystem.ExecuteVerb(verb, playerEntity.Value, target.Value, forced: true); shell.WriteLine(Loc.GetString("invoke-verb-command-success", ("verb", verbName), ("target", target), ("player", playerEntity))); return; } @@ -84,7 +85,7 @@ namespace Content.Server.Verbs.Commands { if (verb.Text.ToLowerInvariant() == verbName) { - verbSystem.ExecuteVerb(verb, playerEntity.Value, target, forced: true); + verbSystem.ExecuteVerb(verb, playerEntity.Value, target.Value, forced: true); shell.WriteLine(Loc.GetString("invoke-verb-command-success", ("verb", verb.Text), ("target", target), ("player", playerEntity))); return; } diff --git a/Content.Server/Verbs/Commands/ListVerbsCommand.cs b/Content.Server/Verbs/Commands/ListVerbsCommand.cs index dc56cffb44..7b541afa66 100644 --- a/Content.Server/Verbs/Commands/ListVerbsCommand.cs +++ b/Content.Server/Verbs/Commands/ListVerbsCommand.cs @@ -8,6 +8,8 @@ namespace Content.Server.Verbs.Commands [AdminCommand(AdminFlags.Admin)] public sealed class ListVerbsCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entManager = default!; + public string Command => "listverbs"; public string Description => Loc.GetString("list-verbs-command-description"); public string Help => Loc.GetString("list-verbs-command-help"); @@ -20,11 +22,11 @@ namespace Content.Server.Verbs.Commands return; } - var entityManager = IoCManager.Resolve(); - var verbSystem = EntitySystem.Get(); + var verbSystem = _entManager.System(); // get the 'player' entity (defaulting to command user, otherwise uses a uid) EntityUid? playerEntity = null; + if (!int.TryParse(args[0], out var intPlayerUid)) { if (args[0] == "self" && shell.Player?.AttachedEntity != null) @@ -39,7 +41,7 @@ namespace Content.Server.Verbs.Commands } else { - entityManager.EntityExists(new EntityUid(intPlayerUid)); + _entManager.TryGetEntity(new NetEntity(intPlayerUid), out playerEntity); } // gets the target entity @@ -55,14 +57,15 @@ namespace Content.Server.Verbs.Commands return; } - var target = new EntityUid(intUid); - if (!entityManager.EntityExists(target)) + var targetNet = new NetEntity(intUid); + + if (!_entManager.TryGetEntity(targetNet, out var target)) { shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-entity")); return; } - var verbs = verbSystem.GetLocalVerbs(target, playerEntity.Value, Verb.VerbTypes); + var verbs = verbSystem.GetLocalVerbs(target.Value, playerEntity.Value, Verb.VerbTypes); foreach (var verb in verbs) { diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs index af1f74dde8..70ae7dcf0f 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs @@ -199,8 +199,8 @@ public sealed partial class ArtifactSystem var temp = (object) comp; _serialization.CopyTo(entry.Component, ref temp); - - EntityManager.AddComponent(uid, (Component) temp!, true); + EntityManager.RemoveComponent(uid, temp!.GetType()); + EntityManager.AddComponent(uid, (Component) temp!); } node.Discovered = true; @@ -234,7 +234,8 @@ public sealed partial class ArtifactSystem comp.Owner = uid; var temp = (object) comp; _serialization.CopyTo(entry, ref temp); - EntityManager.AddComponent(uid, (Component) temp!, true); + EntityManager.RemoveComponent(uid, temp!.GetType()); + EntityManager.AddComponent(uid, (Component) temp); continue; }