2021-06-21 02:13:54 +02:00
|
|
|
using System;
|
2020-08-13 14:40:27 +02:00
|
|
|
using System.Collections.Generic;
|
2021-06-27 05:40:03 +02:00
|
|
|
using System.Linq;
|
2020-10-30 16:06:48 +01:00
|
|
|
using Content.Shared.Administration;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2020-06-24 10:52:52 -07:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
|
2020-10-30 16:06:48 +01:00
|
|
|
namespace Content.Server.Administration.Commands
|
2020-06-24 10:52:52 -07:00
|
|
|
{
|
2021-10-08 02:41:30 -05:00
|
|
|
[AdminCommand(AdminFlags.VarEdit)]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed class DeleteEntitiesWithComponent : IConsoleCommand
|
2020-06-24 10:52:52 -07:00
|
|
|
{
|
|
|
|
|
public string Command => "deleteewc";
|
2021-06-21 02:13:54 +02:00
|
|
|
|
|
|
|
|
public string Description => Loc.GetString("delete-entities-with-component-command-description");
|
|
|
|
|
|
|
|
|
|
public string Help => Loc.GetString("delete-entities-with-component-command-help-text");
|
2020-06-24 10:52:52 -07:00
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-06-24 10:52:52 -07:00
|
|
|
{
|
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine(Help);
|
2020-06-24 10:52:52 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var factory = IoCManager.Resolve<IComponentFactory>();
|
|
|
|
|
|
|
|
|
|
var components = new List<Type>();
|
|
|
|
|
foreach (var arg in args)
|
|
|
|
|
{
|
|
|
|
|
components.Add(factory.GetRegistration(arg).Type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
2021-06-27 05:40:03 +02:00
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner));
|
2021-12-05 18:09:01 +01:00
|
|
|
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
|
2021-06-27 05:40:03 +02:00
|
|
|
|
2020-06-24 10:52:52 -07:00
|
|
|
var count = 0;
|
2021-06-27 05:40:03 +02:00
|
|
|
foreach (var entity in entitiesWithAllComponents)
|
2020-06-24 10:52:52 -07:00
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
entityManager.DeleteEntity(entity);
|
2020-06-24 10:52:52 -07:00
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("delete-entities-with-component-command-deleted-components",("count", count)));
|
2020-06-24 10:52:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|