From 96063436135b2bf269a3d5646e9e653d2e5fd682 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Mon, 19 Aug 2024 19:26:00 -0400 Subject: [PATCH] Core/Creatures: Allow profession tools to be used as equipment Port From (https://github.com/TrinityCore/TrinityCore/commit/2238844f567b63de1edd394b654b62ac4ddeb666) --- Source/Framework/Constants/ItemConst.cs | 14 ++++++++++ Source/Game/AI/SmartScripts/SmartAIManager.cs | 28 +++++++++++++++++++ Source/Game/Globals/ObjectManager.cs | 13 ++------- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Source/Framework/Constants/ItemConst.cs b/Source/Framework/Constants/ItemConst.cs index b1b0f58f3..9c09f8fe1 100644 --- a/Source/Framework/Constants/ItemConst.cs +++ b/Source/Framework/Constants/ItemConst.cs @@ -94,6 +94,20 @@ namespace Framework.Constants ItemModifier.TransmogSecondaryAppearanceSpec4, ItemModifier.TransmogSecondaryAppearanceSpec5 }; + + public static InventoryType[] InventoryTypesEquipable = + { + InventoryType.Weapon, + InventoryType.Shield, + InventoryType.Ranged, + InventoryType.Weapon2Hand, + InventoryType.WeaponMainhand, + InventoryType.WeaponOffhand, + InventoryType.Holdable, + InventoryType.Thrown, + InventoryType.RangedRight, + InventoryType.ProfessionTool + }; } public struct ProfessionSlots diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index 34873b851..3f99624b7 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -9,6 +9,7 @@ using Game.Movement; using Game.Spells; using System; using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -1805,6 +1806,33 @@ namespace Game.AI return false; } } + + bool isValidEquipmentSlot(uint itemEntry, byte slot) + { + ItemRecord dbcItem = CliDB.ItemStorage.LookupByKey(itemEntry); + if (dbcItem == null) + { + Log.outError(LogFilter.Sql, $"SmartScript: SMART_ACTION_EQUIP uses unknown item {itemEntry} (slot {slot}) for creature {e.EntryOrGuid}, skipped."); + return false; + } + + if (ItemConst.InventoryTypesEquipable.All(inventoryType => inventoryType != dbcItem.inventoryType)) + { + Log.outError(LogFilter.Sql, $"SmartScript: SMART_ACTION_EQUIP uses item {itemEntry} (slot {slot}) not equipable in a hand for creature {e.EntryOrGuid}, skipped."); + return false; + } + + return true; + }; + + if (e.Action.equip.slot1 != 0 && !isValidEquipmentSlot(e.Action.equip.slot1, 0)) + return false; + + if (e.Action.equip.slot2 != 0 && !isValidEquipmentSlot(e.Action.equip.slot2, 1)) + return false; + + if (e.Action.equip.slot3 != 0 && !isValidEquipmentSlot(e.Action.equip.slot3, 2)) + return false; break; } case SmartActions.SetInstData: diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 8511f57e9..380129251 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -2481,18 +2481,9 @@ namespace Game continue; } - if (dbcItem.inventoryType != InventoryType.Weapon && - dbcItem.inventoryType != InventoryType.Shield && - dbcItem.inventoryType != InventoryType.Ranged && - dbcItem.inventoryType != InventoryType.Weapon2Hand && - dbcItem.inventoryType != InventoryType.WeaponMainhand && - dbcItem.inventoryType != InventoryType.WeaponOffhand && - dbcItem.inventoryType != InventoryType.Holdable && - dbcItem.inventoryType != InventoryType.Thrown && - dbcItem.inventoryType != InventoryType.RangedRight) + if (ItemConst.InventoryTypesEquipable.All(inventoryType => inventoryType != dbcItem.inventoryType)) { - Log.outError(LogFilter.Sql, "Item (ID {0}) in creature_equip_template.ItemID{1} for CreatureID = {2} is not equipable in a hand, forced to 0.", - equipmentInfo.Items[i].ItemId, i + 1, entry); + Log.outError(LogFilter.Sql, $"Item (ID {equipmentInfo.Items[i].ItemId}) in creature_equip_template.ItemID{i + 1} for CreatureID = {entry} is not equipable in a hand, forced to 0."); equipmentInfo.Items[i].ItemId = 0; } }