diff options
-rw-r--r-- | src/game/Item.cpp | 7 | ||||
-rw-r--r-- | src/game/Player.cpp | 48 | ||||
-rw-r--r-- | src/game/Player.h | 1 |
3 files changed, 56 insertions, 0 deletions
diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 0197de1d3ff..1633885d382 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -285,8 +285,15 @@ void Item::UpdateDuration(Player* owner, uint32 diff) if (GetUInt32Value(ITEM_FIELD_DURATION)<=diff) { + // variables to hold item location and entry data after item gets destroyed + uint32 itemEntry = GetEntry(); + uint8 bagSlot = GetBagSlot(); + uint8 slot = GetSlot(); + uint16 pos = GetPos(); + Script->ItemExpire(owner, GetProto()); owner->DestroyItem(GetBagSlot(), GetSlot(), true); + owner->HandleDestroyItemReplace(itemEntry, bagSlot, slot, pos); return; } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index d578a243a01..afc39c93bb2 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -11396,6 +11396,54 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update) } } + +void Player::HandleDestroyItemReplace( uint32 itemEntry, uint8 bag ,uint8 slot, uint16 pos ) +{ + if(!itemEntry || !slot || !bag) + return; + + uint32 newItemEntry = 0; + switch(itemEntry) + { + case 39878: // Mysterious Unhatched Egg + newItemEntry = 39883; + break; + case 44717: // Disgusting Jar + newItemEntry = 44718; + break; + default: + return; + } + + Item *pNewItem = Item::CreateItem( newItemEntry, 1, this); + if( !pNewItem ) + return; + + if( IsInventoryPos( pos ) ) + { + ItemPosCountVec dest; + uint8 msg = CanStoreItem( bag, slot, dest, pNewItem, true ); + if( msg == EQUIP_ERR_OK ) + { + StoreItem( dest, pNewItem, true); + return; + } + } + else if( IsBankPos ( pos ) ) + { + ItemPosCountVec dest; + uint8 msg = CanBankItem( bag, slot, dest, pNewItem, true ); + if( msg == EQUIP_ERR_OK ) + { + BankItem( dest, pNewItem, true); + return; + } + } + + // fail + delete pNewItem; +} + 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 cdc19d47408..ed7f1f3e7d6 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1192,6 +1192,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player> void MoveItemToInventory(ItemPosCountVec const& dest, Item* pItem, bool update, bool in_characterInventoryDB = false); // in trade, guild bank, mail.... void RemoveItemDependentAurasAndCasts( Item * pItem ); + void HandleDestroyItemReplace( uint32 itemEntry, uint8 bag , uint8 slot , uint16 pos); void DestroyItem( uint8 bag, uint8 slot, bool update ); void DestroyItemCount( uint32 item, uint32 count, bool update, bool unequip_check = false); void DestroyItemCount( Item* item, uint32& count, bool update ); |