Core/Items: Fix item sell price not scaling with item level (#29972)

This commit is contained in:
Bloodtigress
2024-05-12 14:31:49 +02:00
committed by GitHub
parent ef22003a56
commit 500301b962
3 changed files with 42 additions and 42 deletions

View File

@@ -2210,7 +2210,7 @@ uint32 Item::GetBuyPrice(ItemTemplate const* proto, uint32 quality, uint32 itemL
typeFactor = weaponPrice->Data;
}
standardPrice = false;
standardPrice = true;
return uint32(proto->GetPriceVariance() * typeFactor * baseFactor * qualityFactor * proto->GetPriceRandomValue());
}

View File

@@ -13162,10 +13162,7 @@ void Player::AddItemToBuyBackSlot(Item* pItem)
uint32 eslot = slot - BUYBACK_SLOT_START;
SetInvSlot(slot, pItem->GetGUID());
if (ItemTemplate const* proto = pItem->GetTemplate())
SetBuybackPrice(eslot, proto->GetSellPrice() * pItem->GetCount());
else
SetBuybackPrice(eslot, 0);
SetBuybackPrice(eslot, pItem->GetSellPrice(this) * pItem->GetCount());
SetBuybackTimestamp(eslot, (uint32)etime);

View File

@@ -450,54 +450,57 @@ void WorldSession::HandleSellItemOpcode(WorldPackets::Item::SellItem& packet)
}
}
ItemTemplate const* pProto = pItem->GetTemplate();
if (pProto)
if (uint32 sellPrice = pItem->GetSellPrice(_player); sellPrice > 0)
{
if (pProto->GetSellPrice() > 0)
{
uint64 money = uint64(pProto->GetSellPrice()) * packet.Amount;
uint64 money = uint64(sellPrice) * packet.Amount;
if (!_player->ModifyMoney(money)) // ensure player doesn't exceed gold limit
using BuybackStorageType = std::remove_cvref_t<decltype(_player->m_activePlayerData->BuybackPrice[0])>;
if (money > std::numeric_limits<BuybackStorageType>::max()) // ensure sell price * amount doesn't overflow buyback price
{
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
return;
}
if (!_player->ModifyMoney(money)) // ensure player doesn't exceed gold limit
{
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
return;
}
_player->UpdateCriteria(CriteriaType::MoneyEarnedFromSales, money);
_player->UpdateCriteria(CriteriaType::SellItemsToVendors, 1);
if (packet.Amount < pItem->GetCount()) // need split items
{
Item* pNewItem = pItem->CloneItem(packet.Amount, _player);
if (!pNewItem)
{
TC_LOG_ERROR("network", "WORLD: HandleSellItemOpcode - could not create clone of item {}; count = {}", pItem->GetEntry(), packet.Amount);
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
return;
}
_player->UpdateCriteria(CriteriaType::MoneyEarnedFromSales, money);
_player->UpdateCriteria(CriteriaType::SellItemsToVendors, 1);
pItem->SetCount(pItem->GetCount() - packet.Amount);
_player->ItemRemovedQuestCheck(pItem->GetEntry(), packet.Amount);
if (_player->IsInWorld())
pItem->SendUpdateToPlayer(_player);
pItem->SetState(ITEM_CHANGED, _player);
if (packet.Amount < pItem->GetCount()) // need split items
{
Item* pNewItem = pItem->CloneItem(packet.Amount, _player);
if (!pNewItem)
{
TC_LOG_ERROR("network", "WORLD: HandleSellItemOpcode - could not create clone of item {}; count = {}", pItem->GetEntry(), packet.Amount);
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
return;
}
pItem->SetCount(pItem->GetCount() - packet.Amount);
_player->ItemRemovedQuestCheck(pItem->GetEntry(), packet.Amount);
if (_player->IsInWorld())
pItem->SendUpdateToPlayer(_player);
pItem->SetState(ITEM_CHANGED, _player);
_player->AddItemToBuyBackSlot(pNewItem);
if (_player->IsInWorld())
pNewItem->SendUpdateToPlayer(_player);
}
else
{
_player->RemoveItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
_player->ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
RemoveItemFromUpdateQueueOf(pItem, _player);
_player->AddItemToBuyBackSlot(pItem);
}
_player->AddItemToBuyBackSlot(pNewItem);
if (_player->IsInWorld())
pNewItem->SendUpdateToPlayer(_player);
}
else
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
return;
{
_player->RemoveItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
_player->ItemRemovedQuestCheck(pItem->GetEntry(), pItem->GetCount());
RemoveItemFromUpdateQueueOf(pItem, _player);
_player->AddItemToBuyBackSlot(pItem);
}
}
else
_player->SendSellError(SELL_ERR_CANT_SELL_ITEM, creature, packet.ItemGUID);
return;
}
_player->SendSellError(SELL_ERR_CANT_FIND_ITEM, creature, packet.ItemGUID);
return;