From 0116a7efa58d247f3f914c5d6840951103cd8106 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 3 Mar 2022 13:51:22 -0500 Subject: [PATCH] Core/ChatCommands: Add support for enum type arguments Port From (https://github.com/TrinityCore/TrinityCore/commit/3923650aeb75611023aa1d46a4328838c8e0a33c) --- Source/Game/Chat/CommandArgs.cs | 3 +++ Source/Game/Chat/Commands/NPCCommands.cs | 13 ++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/Game/Chat/CommandArgs.cs b/Source/Game/Chat/CommandArgs.cs index 7b76ac710..73fa617ed 100644 --- a/Source/Game/Chat/CommandArgs.cs +++ b/Source/Game/Chat/CommandArgs.cs @@ -66,6 +66,9 @@ namespace Game.Chat if (Hyperlink.TryConsume(out value, type, args)) return value; + if (type.IsEnum) + type = type.GetEnumUnderlyingType(); + switch (Type.GetTypeCode(type)) { case TypeCode.SByte: diff --git a/Source/Game/Chat/Commands/NPCCommands.cs b/Source/Game/Chat/Commands/NPCCommands.cs index 1c5ece315..b77eb00c7 100644 --- a/Source/Game/Chat/Commands/NPCCommands.cs +++ b/Source/Game/Chat/Commands/NPCCommands.cs @@ -1122,13 +1122,8 @@ namespace Game.Chat } [Command("flag", RBACPermissions.CommandNpcSetFlag)] - static bool HandleNpcSetFlagCommand(CommandHandler handler, StringArguments args) + static bool HandleNpcSetFlagCommand(CommandHandler handler, NPCFlags npcFlags, NPCFlags2 npcFlags2) { - if (args.Empty()) - return false; - - ulong npcFlags = args.NextUInt64(); - Creature creature = handler.GetSelectedCreature(); if (!creature) { @@ -1136,11 +1131,11 @@ namespace Game.Chat return false; } - creature.SetNpcFlags((NPCFlags)(npcFlags & 0xFFFFFFFF)); - creature.SetNpcFlags2((NPCFlags2)(npcFlags >> 32)); + creature.SetNpcFlags(npcFlags); + creature.SetNpcFlags2(npcFlags2); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_NPCFLAG); - stmt.AddValue(0, npcFlags); + stmt.AddValue(0, (ulong)npcFlags | ((ulong)npcFlags2 << 32)); stmt.AddValue(1, creature.GetEntry()); DB.World.Execute(stmt);