Move trade data to dynamic structure and added support for applying enchant after trade ends, based on Vladimir's commits

--HG--
branch : trunk
This commit is contained in:
Shauren
2010-06-25 13:15:51 +02:00
parent eb79fb91a6
commit 456c6291ab
7 changed files with 555 additions and 274 deletions
+119 -31
View File
@@ -280,6 +280,105 @@ std::ostringstream& operator<< (std::ostringstream& ss, PlayerTaxi const& taxi)
return ss;
}
//== TradeData =================================================
TradeData* TradeData::GetTraderData() const
{
return m_trader->GetTradeData();
}
Item* TradeData::GetItem(TradeSlots slot) const
{
return m_items[slot] ? m_player->GetItemByGuid(m_items[slot]) : NULL;
}
bool TradeData::HasItem(uint64 item_guid) const
{
for(uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (m_items[i] == item_guid)
return true;
return false;
}
Item* TradeData::GetSpellCastItem() const
{
return m_spellCastItem ? m_player->GetItemByGuid(m_spellCastItem) : NULL;
}
void TradeData::SetItem(TradeSlots slot, Item* item)
{
uint64 itemGuid = item ? item->GetGUID() : 0;
if (m_items[slot] == itemGuid)
return;
m_items[slot] = itemGuid;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update();
// need remove possible trader spell applied to changed item
if (slot == TRADE_SLOT_NONTRADED)
GetTraderData()->SetSpell(0);
// need remove possible player spell applied (possible move reagent)
SetSpell(0);
}
void TradeData::SetSpell(uint32 spell_id, Item* castItem /*= NULL*/)
{
uint64 itemGuid = castItem ? castItem->GetGUID() : 0;
if (m_spell == spell_id && m_spellCastItem == itemGuid)
return;
m_spell = spell_id;
m_spellCastItem = itemGuid;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update(true); // send spell info to item owner
Update(false); // send spell info to caster self
}
void TradeData::SetMoney(uint32 money)
{
if (m_money == money)
return;
m_money = money;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update(true);
}
void TradeData::Update(bool forTarget /*= true*/)
{
if (forTarget)
m_trader->GetSession()->SendUpdateTrade(true); // player state for trader
else
m_player->GetSession()->SendUpdateTrade(false); // player state for player
}
void TradeData::SetAccepted(bool state, bool crosssend /*= false*/)
{
m_accepted = state;
if (!state)
{
if (crosssend)
m_trader->GetSession()->SendTradeStatus(TRADE_STATUS_BACK_TO_TRADE);
else
m_player->GetSession()->SendTradeStatus(TRADE_STATUS_BACK_TO_TRADE);
}
}
// == Player ====================================================
UpdateMask Player::updateVisualBits;
@@ -354,8 +453,7 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
m_bHasDelayedTeleport = false;
m_teleport_options = 0;
pTrader = 0;
ClearTrade();
m_trade = NULL;
m_cinematic = 0;
@@ -9539,7 +9637,7 @@ bool Player::HasItemCount(uint32 item, uint32 count, bool inBankAlso) const
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; i++)
{
Item *pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (pItem && pItem->GetEntry() == item)
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
{
tempcount += pItem->GetCount();
if (tempcount >= count)
@@ -9549,7 +9647,7 @@ bool Player::HasItemCount(uint32 item, uint32 count, bool inBankAlso) const
for (uint8 i = KEYRING_SLOT_START; i < CURRENCYTOKEN_SLOT_END; ++i)
{
Item *pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (pItem && pItem->GetEntry() == item)
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
{
tempcount += pItem->GetCount();
if (tempcount >= count)
@@ -9563,7 +9661,7 @@ bool Player::HasItemCount(uint32 item, uint32 count, bool inBankAlso) const
for (uint32 j = 0; j < pBag->GetBagSize(); j++)
{
Item* pItem = GetItemByPos(i, j);
if (pItem && pItem->GetEntry() == item)
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
{
tempcount += pItem->GetCount();
if (tempcount >= count)
@@ -9578,7 +9676,7 @@ bool Player::HasItemCount(uint32 item, uint32 count, bool inBankAlso) const
for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; i++)
{
Item *pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (pItem && pItem->GetEntry() == item)
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
{
tempcount += pItem->GetCount();
if (tempcount >= count)
@@ -9592,7 +9690,7 @@ bool Player::HasItemCount(uint32 item, uint32 count, bool inBankAlso) const
for (uint32 j = 0; j < pBag->GetBagSize(); j++)
{
Item* pItem = GetItemByPos(i, j);
if (pItem && pItem->GetEntry() == item)
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
{
tempcount += pItem->GetCount();
if (tempcount >= count)
@@ -11813,7 +11911,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (pItem->GetEntry() == item)
if (pItem->GetEntry() == item && !pItem->IsInTrade())
{
if (pItem->GetCount() + remcount <= count)
{
@@ -11841,7 +11939,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (pItem->GetEntry() == item)
if (pItem->GetEntry() == item && !pItem->IsInTrade())
{
if (pItem->GetCount() + remcount <= count)
{
@@ -11874,7 +11972,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
{
if (Item* pItem = pBag->GetItemByPos(j))
{
if (pItem->GetEntry() == item)
if (pItem->GetEntry() == item && !pItem->IsInTrade())
{
// all items in bags can be unequipped
if (pItem->GetCount() + remcount <= count)
@@ -11905,7 +12003,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (pItem && pItem->GetEntry() == item)
if (pItem && pItem->GetEntry() == item && !pItem->IsInTrade())
{
if (pItem->GetCount() + remcount <= count)
{
@@ -12663,33 +12761,23 @@ void Player::SendSellError(uint8 msg, Creature* pCreature, uint64 guid, uint32 p
GetSession()->SendPacket(&data);
}
void Player::ClearTrade()
{
tradeGold = 0;
acceptTrade = false;
for (uint8 i = 0; i < TRADE_SLOT_COUNT; i++)
tradeItems[i] = 0;
}
void Player::TradeCancel(bool sendback)
{
if (pTrader)
if (m_trade)
{
Player* trader = m_trade->GetTrader();
// send yellow "Trade canceled" message to both traders
WorldSession* ws;
ws = GetSession();
if (sendback)
ws->SendCancelTrade();
ws = pTrader->GetSession();
if (!ws->PlayerLogout())
ws->SendCancelTrade();
GetSession()->SendCancelTrade();
trader->GetSession()->SendCancelTrade();
// cleanup
ClearTrade();
pTrader->ClearTrade();
// prevent loss of reference
pTrader->pTrader = NULL;
pTrader = NULL;
delete m_trade;
m_trade = NULL;
delete trader->m_trade;
trader->m_trade = NULL;
}
}