From 9d4096991c9e819971bc7814cffeef088ad93c71 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 17 Feb 2022 17:05:24 -0500 Subject: [PATCH] Core/Spells: Fixed checking free inventory space for some spells that have bad dbc data Port From (https://github.com/TrinityCore/TrinityCore/commit/ba69c91f4bfec9999d151ef42f0b522924496264) --- Source/Game/Spells/Spell.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 41dbb67ed..089a8dd02 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -6240,13 +6240,18 @@ namespace Game.Spells if (spellEffectInfo.ItemType != 0) { + ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(spellEffectInfo.ItemType); + if (itemTemplate == null) + return SpellCastResult.ItemNotFound; + + uint createCount = (uint)Math.Clamp(spellEffectInfo.CalcValue(), 1u, itemTemplate.GetMaxStackSize()); + List dest = new(); - InventoryResult msg = target.ToPlayer().CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, spellEffectInfo.ItemType, (uint)spellEffectInfo.CalcValue()); + InventoryResult msg = target.ToPlayer().CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, spellEffectInfo.ItemType, createCount); if (msg != InventoryResult.Ok) { - ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(spellEffectInfo.ItemType); /// @todo Needs review - if (itemTemplate != null && itemTemplate.GetItemLimitCategory() == 0) + if (itemTemplate.GetItemLimitCategory() == 0) { player.SendEquipError(msg, null, null, spellEffectInfo.ItemType); return SpellCastResult.DontReport; @@ -6256,7 +6261,7 @@ namespace Game.Spells // Conjure Food/Water/Refreshment spells if (m_spellInfo.SpellFamilyName != SpellFamilyNames.Mage || (!m_spellInfo.SpellFamilyFlags[0].HasAnyFlag(0x40000000u))) return SpellCastResult.TooManyOfItem; - else if (!(target.ToPlayer().HasItemCount(spellEffectInfo.ItemType))) + else if (!target.ToPlayer().HasItemCount(spellEffectInfo.ItemType)) { player.SendEquipError(msg, null, null, spellEffectInfo.ItemType); return SpellCastResult.DontReport;