Skip to content

Commit

Permalink
Implement a command for destroying indestructible items
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypto137 committed Sep 3, 2024
1 parent 599dac2 commit e49b43c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/MHServerEmu/Commands/Implementations/ItemCommands.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Item> indestructibleItemList = new();
foreach (var entry in general)
{
Item item = player.Game.EntityManager.GetEntity<Item>(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.";
Expand Down

0 comments on commit e49b43c

Please sign in to comment.