From e49b43c0e60c5258930226ab84f308d056946ecd Mon Sep 17 00:00:00 2001 From: Crypto137 Date: Tue, 3 Sep 2024 17:30:10 +0300 Subject: [PATCH] Implement a command for destroying indestructible items --- .../Commands/Implementations/ItemCommands.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/MHServerEmu/Commands/Implementations/ItemCommands.cs b/src/MHServerEmu/Commands/Implementations/ItemCommands.cs index 4bf7bb057..da9cad3ec 100644 --- a/src/MHServerEmu/Commands/Implementations/ItemCommands.cs +++ b/src/MHServerEmu/Commands/Implementations/ItemCommands.cs @@ -1,8 +1,11 @@ using MHServerEmu.Commands.Attributes; using MHServerEmu.Core.Logging; +using MHServerEmu.DatabaseAccess.Models; using MHServerEmu.Frontend; using MHServerEmu.Games.Entities; using MHServerEmu.Games.Entities.Avatars; +using MHServerEmu.Games.Entities.Inventories; +using MHServerEmu.Games.Entities.Items; using MHServerEmu.Games.GameData; using MHServerEmu.Games.GameData.Calligraphy; using MHServerEmu.Games.Loot; @@ -60,7 +63,32 @@ public string Give(string[] @params, FrontendClient client) return string.Empty; } - [Command("roll", "Test rolls a loot table.\nUsage: item testloottable")] + [Command("destroyindestructible", "Destroys indestructible items contained in the player's general inventory.\nUsage: item destroyindestructible")] + public string DestroyIndestructible(string[] @params, FrontendClient client) + { + if (client == null) return "You can only invoke this command from the game."; + + CommandHelper.TryGetPlayerConnection(client, out PlayerConnection playerConnection); + Player player = playerConnection.Player; + Inventory general = player.GetInventory(InventoryConvenienceLabel.General); + + List indestructibleItemList = new(); + foreach (var entry in general) + { + Item item = player.Game.EntityManager.GetEntity(entry.Id); + if (item == null) continue; + + if (item.ItemPrototype.CanBeDestroyed == false) + indestructibleItemList.Add(item); + } + + foreach (Item item in indestructibleItemList) + item.Destroy(); + + return $"Destroyed {indestructibleItemList.Count} indestructible items."; + } + + [Command("roll", "Test rolls a loot table.\nUsage: item testloottable", AccountUserLevel.Admin)] public string RollLootTable(string[] @params, FrontendClient client) { if (client == null) return "You can only invoke this command from the game.";