mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
fix(Core/Items): Item sell prices are affected by durability loss. So… (#13801)
...urce: Vmangos.
This commit is contained in:
@@ -1316,7 +1316,7 @@ public:
|
||||
void DestroyZoneLimitedItem(bool update, uint32 new_zone);
|
||||
void SplitItem(uint16 src, uint16 dst, uint32 count);
|
||||
void SwapItem(uint16 src, uint16 dst);
|
||||
void AddItemToBuyBackSlot(Item* pItem);
|
||||
void AddItemToBuyBackSlot(Item* pItem, uint32 money);
|
||||
Item* GetItemFromBuyBackSlot(uint32 slot);
|
||||
void RemoveItemFromBuyBackSlot(uint32 slot, bool del);
|
||||
[[nodiscard]] uint32 GetMaxKeyringSize() const { return KEYRING_SLOT_END - KEYRING_SLOT_START; }
|
||||
|
||||
@@ -3961,7 +3961,7 @@ void Player::SwapItem(uint16 src, uint16 dst)
|
||||
AutoUnequipOffhandIfNeed();
|
||||
}
|
||||
|
||||
void Player::AddItemToBuyBackSlot(Item* pItem)
|
||||
void Player::AddItemToBuyBackSlot(Item* pItem, uint32 money)
|
||||
{
|
||||
if (pItem)
|
||||
{
|
||||
@@ -4003,10 +4003,7 @@ void Player::AddItemToBuyBackSlot(Item* pItem)
|
||||
uint32 eslot = slot - BUYBACK_SLOT_START;
|
||||
|
||||
SetGuidValue(PLAYER_FIELD_VENDORBUYBACK_SLOT_1 + (eslot * 2), pItem->GetGUID());
|
||||
if (ItemTemplate const* proto = pItem->GetTemplate())
|
||||
SetUInt32Value(PLAYER_FIELD_BUYBACK_PRICE_1 + eslot, proto->SellPrice * pItem->GetCount());
|
||||
else
|
||||
SetUInt32Value(PLAYER_FIELD_BUYBACK_PRICE_1 + eslot, 0);
|
||||
SetUInt32Value(PLAYER_FIELD_BUYBACK_PRICE_1 + eslot, money);
|
||||
SetUInt32Value(PLAYER_FIELD_BUYBACK_TIMESTAMP_1 + eslot, (uint32)etime);
|
||||
|
||||
// move to next (for non filled list is move most optimized choice)
|
||||
|
||||
@@ -818,6 +818,51 @@ void WorldSession::HandleSellItemOpcode(WorldPacket& recvData)
|
||||
if (sWorld->getBoolConfig(CONFIG_ITEMDELETE_VENDOR))
|
||||
recoveryItem(pItem);
|
||||
|
||||
uint32 maxDurability = pItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY);
|
||||
if (maxDurability)
|
||||
{
|
||||
uint32 curDurability = pItem->GetUInt32Value(ITEM_FIELD_DURABILITY);
|
||||
uint32 LostDurability = maxDurability - curDurability;
|
||||
|
||||
if (LostDurability > 0)
|
||||
{
|
||||
DurabilityCostsEntry const* dcost = sDurabilityCostsStore.LookupEntry(pProto->ItemLevel);
|
||||
if (!dcost)
|
||||
{
|
||||
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, itemguid, 0);
|
||||
LOG_ERROR("network.opcode", "WORLD: HandleSellItemOpcode - Wrong item lvl {} for item {} count = {}", pProto->ItemLevel, pItem->GetEntry(), count);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 dQualitymodEntryId = (pProto->Quality + 1) * 2;
|
||||
DurabilityQualityEntry const* dQualitymodEntry = sDurabilityQualityStore.LookupEntry(dQualitymodEntryId);
|
||||
if (!dQualitymodEntry)
|
||||
{
|
||||
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, itemguid, 0);
|
||||
LOG_ERROR("network.opcode", "WORLD: HandleSellItemOpcode - Wrong dQualityModEntry {} for item {} count = {}", dQualitymodEntryId, pItem->GetEntry(), count);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 dmultiplier = dcost->multiplier[ItemSubClassToDurabilityMultiplierId(pProto->Class, pProto->SubClass)];
|
||||
uint32 refund = uint32(std::ceil(LostDurability * dmultiplier * double(dQualitymodEntry->quality_mod)));
|
||||
|
||||
if (!refund)
|
||||
{
|
||||
refund = 1;
|
||||
}
|
||||
|
||||
//starter items can cost more to refund than vendorprice
|
||||
if (refund > money)
|
||||
{
|
||||
money = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
money -= refund;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count < pItem->GetCount()) // need split items
|
||||
{
|
||||
Item* pNewItem = pItem->CloneItem(count, _player);
|
||||
@@ -828,13 +873,15 @@ void WorldSession::HandleSellItemOpcode(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
pNewItem->SetUInt32Value(ITEM_FIELD_DURABILITY, pItem->GetUInt32Value(ITEM_FIELD_DURABILITY));
|
||||
|
||||
pItem->SetCount(pItem->GetCount() - count);
|
||||
_player->ItemRemovedQuestCheck(pItem->GetEntry(), count);
|
||||
if (_player->IsInWorld())
|
||||
pItem->SendUpdateToPlayer(_player);
|
||||
pItem->SetState(ITEM_CHANGED, _player);
|
||||
|
||||
_player->AddItemToBuyBackSlot(pNewItem);
|
||||
_player->AddItemToBuyBackSlot(pNewItem, money);
|
||||
if (_player->IsInWorld())
|
||||
pNewItem->SendUpdateToPlayer(_player);
|
||||
}
|
||||
@@ -843,7 +890,7 @@ void WorldSession::HandleSellItemOpcode(WorldPacket& recvData)
|
||||
_player->ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
|
||||
_player->RemoveItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
|
||||
pItem->RemoveFromUpdateQueueOf(_player);
|
||||
_player->AddItemToBuyBackSlot(pItem);
|
||||
_player->AddItemToBuyBackSlot(pItem, money);
|
||||
_player->UpdateTitansGrip();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user