aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Spells/Spell.cpp
diff options
context:
space:
mode:
authorWyrserth <43747507+Wyrserth@users.noreply.github.com>2019-06-15 15:11:49 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-11 13:29:39 +0100
commit59da957165ef7d7529db30f90a30dc401d682052 (patch)
treedd9985c6f699edae30b123e7b965e43db1cd229c /src/server/game/Spells/Spell.cpp
parent264373bb656352a0cdf9b18bad4f3929c7376a9c (diff)
Core/Spells: don't allow spells with SPELL_EFFECT_CREATE_LOOT to be cast if there isn't enough space in inventory (#23404)
* Core/Spells: don't allow spells with SPELL_EFFECT_CREATE_LOOT to be cast if there isn't enough space in inventory, * Move GetFreeInventorySpace() to a better place, thanks ccrs! (cherry picked from commit 218055280af4563f28643e2683eafe40808f90db)
Diffstat (limited to 'src/server/game/Spells/Spell.cpp')
-rw-r--r--src/server/game/Spells/Spell.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 0526c512dc1..74baf6338c8 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -6847,33 +6847,45 @@ SpellCastResult Spell::CheckItems(int32* param1 /*= nullptr*/, int32* param2 /*=
{
// m_targets.GetUnitTarget() means explicit cast, otherwise we dont check for possible equip error
Unit* target = m_targets.GetUnitTarget() ? m_targets.GetUnitTarget() : player;
- if (target->GetTypeId() == TYPEID_PLAYER && !IsTriggered() && spellEffectInfo.ItemType)
+ if (target->GetTypeId() == TYPEID_PLAYER && !IsTriggered())
{
- ItemPosCountVec dest;
- InventoryResult msg = target->ToPlayer()->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, spellEffectInfo.ItemType, 1);
- if (msg != EQUIP_ERR_OK)
- {
- ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(spellEffectInfo.ItemType);
- /// @todo Needs review
- if (itemTemplate && !(itemTemplate->GetItemLimitCategory()))
+ // SPELL_EFFECT_CREATE_ITEM_2 differs from SPELL_EFFECT_CREATE_ITEM in that it picks the random item to create from a pool of potential items,
+ // so we need to make sure there is at least one free space in the player's inventory
+ if (spellEffectInfo.Effect == SPELL_EFFECT_CREATE_LOOT)
+ if (target->ToPlayer()->GetFreeInventorySpace() == 0)
{
- player->SendEquipError(msg, nullptr, nullptr, spellEffectInfo.ItemType);
+ player->SendEquipError(EQUIP_ERR_INV_FULL, nullptr, nullptr, spellEffectInfo.ItemType);
return SPELL_FAILED_DONT_REPORT;
}
- else
+
+ if (spellEffectInfo.ItemType)
+ {
+ ItemPosCountVec dest;
+ InventoryResult msg = target->ToPlayer()->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, spellEffectInfo.ItemType, 1);
+ if (msg != EQUIP_ERR_OK)
{
- // Conjure Food/Water/Refreshment spells
- if (m_spellInfo->SpellFamilyName != SPELLFAMILY_MAGE || (!(m_spellInfo->SpellFamilyFlags[0] & 0x40000000)))
- return SPELL_FAILED_TOO_MANY_OF_ITEM;
- else if (!(target->ToPlayer()->HasItemCount(spellEffectInfo.ItemType)))
+ ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(spellEffectInfo.ItemType);
+ /// @todo Needs review
+ if (itemTemplate && !itemTemplate->GetItemLimitCategory())
{
player->SendEquipError(msg, nullptr, nullptr, spellEffectInfo.ItemType);
return SPELL_FAILED_DONT_REPORT;
}
- else if (m_spellInfo->GetEffects().size() > EFFECT_1)
- player->CastSpell(player, m_spellInfo->GetEffect(EFFECT_1).CalcValue(), CastSpellExtraArgs()
- .SetOriginalCastId(m_castId)); // move this to anywhere
- return SPELL_FAILED_DONT_REPORT;
+ else
+ {
+ // Conjure Food/Water/Refreshment spells
+ if (m_spellInfo->SpellFamilyName != SPELLFAMILY_MAGE || (!(m_spellInfo->SpellFamilyFlags[0] & 0x40000000)))
+ return SPELL_FAILED_TOO_MANY_OF_ITEM;
+ else if (!(target->ToPlayer()->HasItemCount(spellEffectInfo.ItemType)))
+ {
+ player->SendEquipError(msg, nullptr, nullptr, spellEffectInfo.ItemType);
+ return SPELL_FAILED_DONT_REPORT;
+ }
+ else if (m_spellInfo->GetEffects().size() > EFFECT_1)
+ player->CastSpell(player, m_spellInfo->GetEffect(EFFECT_1).CalcValue(), CastSpellExtraArgs()
+ .SetOriginalCastId(m_castId)); // move this to anywhere
+ return SPELL_FAILED_DONT_REPORT;
+ }
}
}
}