From 06511cfb8cfa2233580f07406a5e34eb950d8154 Mon Sep 17 00:00:00 2001 From: JoLan Date: Thu, 6 Nov 2008 08:08:53 +0100 Subject: [PATCH] Delay DestroyItemCount() in TakeCastItem() for opening GOs destroy it at CMSG_LOOT_RELEASE instead of at GO opening fix non-lootable GOs requiting an item to open. --- src/game/LootHandler.cpp | 1 + src/game/Player.cpp | 21 +++++++++++++++++++++ src/game/Player.h | 6 ++++++ src/game/Spell.cpp | 11 ++++++++--- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/game/LootHandler.cpp b/src/game/LootHandler.cpp index 9731442..ef04fc2 100644 --- a/src/game/LootHandler.cpp +++ b/src/game/LootHandler.cpp @@ -270,6 +270,7 @@ void WorldSession::DoLootRelease( uint64 lguid ) player->SendLootRelease(lguid); player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING); + player->TakePendingCastItem(); if (IS_GAMEOBJECT_GUID(lguid)) { diff --git a/src/game/Player.cpp b/src/game/Player.cpp index ad5b350..af2c7e2 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -272,6 +272,7 @@ Player::Player (WorldSession *session): Unit() m_curSelection = 0; m_lootGuid = 0; + m_pendingCastItem = NULL; m_comboTarget = 0; m_comboPoints = 0; @@ -7057,6 +7058,10 @@ void Player::SendLoot(uint64 guid, LootType loot_type) // And permit out of range GO with no owner in case fishing hole if (!go || (loot_type != LOOT_FISHINGHOLE && (loot_type != LOOT_FISHING || go->GetOwnerGUID() != GetGUID()) && !go->IsWithinDistInMap(this,INTERACTION_DISTANCE))) { + if (go->IsWithinDistInMap(this,INTERACTION_DISTANCE)) + sLog.outDebug(" release : ukn"); + else + sLog.outDebug(" release : out of range"); SendLootRelease(guid); return; } @@ -10293,6 +10298,22 @@ void Player::DestroyItem( uint8 bag, uint8 slot, bool update ) } } +void Player::SetPendingCastItem( Item* item ) +{ + m_pendingCastItem = item; +} + +void Player::TakePendingCastItem() +{ + if (m_pendingCastItem) + { + uint32 count=1; + DestroyItemCount(m_pendingCastItem, count, true); + } + m_pendingCastItem = NULL; +} + + void Player::DestroyItemCount( uint32 item, uint32 count, bool update, bool unequip_check) { sLog.outDebug( "STORAGE: DestroyItemCount item = %u, count = %u", item, count); diff --git a/src/game/Player.h b/src/game/Player.h index b45ec7a..c5c0a19 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1096,6 +1096,10 @@ class MANGOS_DLL_SPEC Player : public Unit // in trade, guild bank, mail.... void RemoveItemDependentAurasAndCasts( Item * pItem ); void DestroyItem( uint8 bag, uint8 slot, bool update ); + + void SetPendingCastItem( Item* item ); + void TakePendingCastItem(); + void DestroyItemCount( uint32 item, uint32 count, bool update, bool unequip_check = false); void DestroyItemCount( Item* item, uint32& count, bool update ); void DestroyConjuredItems( bool update ); @@ -2145,6 +2149,8 @@ class MANGOS_DLL_SPEC Player : public Unit bool _removeSpell(uint16 spell_id); uint64 m_lootGuid; + Item* m_pendingCastItem; + uint32 m_race; uint32 m_class; uint32 m_team; diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index a18a8cd..2a7ec31 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -2995,14 +2995,19 @@ void Spell::TakeCastItem() if (expendable && withoutCharges) { - uint32 count = 1; - ((Player*)m_caster)->DestroyItemCount(m_CastItem, count, true); - + if (((Player*)m_caster)->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING)) + ((Player*)m_caster)->SetPendingCastItem(m_CastItem); + else + { + uint32 count=1; + ((Player*)m_caster)->DestroyItemCount(m_CastItem, count, true); + } // prevent crash at access to deleted m_targets.getItemTarget if(m_CastItem==m_targets.getItemTarget()) m_targets.setItemTarget(NULL); m_CastItem = NULL; + } } -- 1.5.6.5