From 75447899c48653f9b32e119e366f8ff0478f1afe Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Tue, 20 Dec 2022 09:52:14 +0100 Subject: [PATCH] Core/GameObjects: implement allowMounted for GAMEOBJECT_TYPE_SPELLCASTER and only count uses if the spell has actually been cast * this fixes Cauldrons of Battle to no longer prematurely despawn when a player attempted to pick up multiple flasks while already carrying one in his inventory --- .../game/Entities/GameObject/GameObject.cpp | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 9e748aa7e2..682c46c2a9 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -2215,25 +2215,30 @@ void GameObject::Use(Unit* user) } case GAMEOBJECT_TYPE_SPELLCASTER: //22 { - GameObjectTemplate const* info = GetGOInfo(); - if (!info) - return; - - if (info->spellcaster.partyOnly) + if (m_goInfo->spellcaster.partyOnly) { - Unit* caster = GetOwner(); - if (!caster || caster->GetTypeId() != TYPEID_PLAYER) - return; - - if (user->GetTypeId() != TYPEID_PLAYER || !user->ToPlayer()->IsInSameRaidWith(caster->ToPlayer())) + Unit const* caster = GetOwner(); + if (!caster || !caster->IsPlayer() || !user->IsPlayer() || !user->ToPlayer()->IsInSameRaidWith(caster->ToPlayer())) return; } - user->RemoveAurasByType(SPELL_AURA_MOUNTED); - spellId = info->spellcaster.spellId; + if (!m_goInfo->spellcaster.allowMounted) + user->RemoveAurasByType(SPELL_AURA_MOUNTED); - AddUse(); - break; + spellId = m_goInfo->spellcaster.spellId; + if (!sSpellMgr->GetSpellInfo(spellId)) + { + TC_LOG_ERROR("misc", "SpellCaster gameobject (Entry: %u) attempted to cast a non-existant spell (ID: %u).", GetEntry(), spellId); + return; + } + + if (Player* player = user->ToPlayer()) + sOutdoorPvPMgr->HandleCustomSpell(player, spellId, this); + + // Only count successful spell casts as uses + if (CastSpell(user, spellId) == SPELL_CAST_OK) + AddUse(); + return; } case GAMEOBJECT_TYPE_MEETINGSTONE: //23 {