mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 22:37:02 +00:00
[10046] Store guids instead slot data for trade items.
Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
e1766a3adb
commit
6986ecbd9b
5 changed files with 73 additions and 83 deletions
|
|
@ -11994,7 +11994,7 @@ void Player::ClearTrade()
|
||||||
tradeGold = 0;
|
tradeGold = 0;
|
||||||
acceptTrade = false;
|
acceptTrade = false;
|
||||||
for(int i = 0; i < TRADE_SLOT_COUNT; ++i)
|
for(int i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||||
tradeItems[i] = NULL_SLOT;
|
m_tradeItems[i].Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::TradeCancel(bool sendback)
|
void Player::TradeCancel(bool sendback)
|
||||||
|
|
|
||||||
|
|
@ -1283,7 +1283,7 @@ class MANGOS_DLL_SPEC Player : public Unit
|
||||||
Player* GetTrader() const { return pTrader; }
|
Player* GetTrader() const { return pTrader; }
|
||||||
void ClearTrade();
|
void ClearTrade();
|
||||||
void TradeCancel(bool sendback);
|
void TradeCancel(bool sendback);
|
||||||
uint16 GetItemPosByTradeSlot(uint32 slot) const { return tradeItems[slot]; }
|
Item* GetItemByTradeSlot(uint32 slot) const { return !m_tradeItems[slot].IsEmpty() ? GetItemByGuid(m_tradeItems[slot]) : NULL; }
|
||||||
|
|
||||||
void UpdateEnchantTime(uint32 time);
|
void UpdateEnchantTime(uint32 time);
|
||||||
void UpdateItemDuration(uint32 time, bool realtimeonly=false);
|
void UpdateItemDuration(uint32 time, bool realtimeonly=false);
|
||||||
|
|
@ -2465,7 +2465,7 @@ class MANGOS_DLL_SPEC Player : public Unit
|
||||||
|
|
||||||
Player *pTrader;
|
Player *pTrader;
|
||||||
bool acceptTrade;
|
bool acceptTrade;
|
||||||
uint16 tradeItems[TRADE_SLOT_COUNT];
|
ObjectGuid m_tradeItems[TRADE_SLOT_COUNT];
|
||||||
uint32 tradeGold;
|
uint32 tradeGold;
|
||||||
|
|
||||||
bool m_DailyQuestChanged;
|
bool m_DailyQuestChanged;
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ void SpellCastTargets::Update(Unit* caster)
|
||||||
{
|
{
|
||||||
Player* pTrader = ((Player*)caster)->GetTrader();
|
Player* pTrader = ((Player*)caster)->GetTrader();
|
||||||
if(pTrader && m_itemTargetGUID.GetRawValue() < TRADE_SLOT_COUNT)
|
if(pTrader && m_itemTargetGUID.GetRawValue() < TRADE_SLOT_COUNT)
|
||||||
m_itemTarget = pTrader->GetItemByPos(pTrader->GetItemPosByTradeSlot(uint32(m_itemTargetGUID.GetRawValue())));
|
m_itemTarget = pTrader->GetItemByTradeSlot(uint32(m_itemTargetGUID.GetRawValue()));
|
||||||
}
|
}
|
||||||
if(m_itemTarget)
|
if(m_itemTarget)
|
||||||
m_itemTargetEntry = m_itemTarget->GetEntry();
|
m_itemTargetEntry = m_itemTarget->GetEntry();
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,6 @@ void WorldSession::HandleBusyTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
|
|
||||||
void WorldSession::SendUpdateTrade()
|
void WorldSession::SendUpdateTrade()
|
||||||
{
|
{
|
||||||
Item *item = NULL;
|
|
||||||
|
|
||||||
if( !_player || !_player->pTrader )
|
if( !_player || !_player->pTrader )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -134,11 +132,9 @@ void WorldSession::SendUpdateTrade()
|
||||||
|
|
||||||
for(uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
|
for(uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||||
{
|
{
|
||||||
item = (_player->pTrader->tradeItems[i] != NULL_SLOT ? _player->pTrader->GetItemByPos( _player->pTrader->tradeItems[i] ) : NULL);
|
|
||||||
|
|
||||||
data << (uint8) i; // trade slot number, if not specified, then end of packet
|
data << (uint8) i; // trade slot number, if not specified, then end of packet
|
||||||
|
|
||||||
if(item)
|
if(Item* item = _player->pTrader->GetItemByTradeSlot(i))
|
||||||
{
|
{
|
||||||
data << (uint32) item->GetProto()->ItemId; // entry
|
data << (uint32) item->GetProto()->ItemId; // entry
|
||||||
// display id
|
// display id
|
||||||
|
|
@ -165,7 +161,7 @@ void WorldSession::SendUpdateTrade()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(uint8 j = 0; j < 18; j++)
|
for(uint8 j = 0; j < 18; ++j)
|
||||||
data << uint32(0);
|
data << uint32(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +187,7 @@ void WorldSession::moveItems(Item* myItems[], Item* hisItems[])
|
||||||
if (myItems[i])
|
if (myItems[i])
|
||||||
{
|
{
|
||||||
// logging
|
// logging
|
||||||
DEBUG_LOG("partner storing: %u",myItems[i]->GetGUIDLow());
|
DEBUG_LOG("partner storing: %s", myItems[i]->GetObjectGuid().GetString().c_str());
|
||||||
if (_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE))
|
if (_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE))
|
||||||
{
|
{
|
||||||
sLog.outCommand(_player->GetSession()->GetAccountId(),"GM %s (Account: %u) trade: %s (Entry: %d Count: %u) to player: %s (Account: %u)",
|
sLog.outCommand(_player->GetSession()->GetAccountId(),"GM %s (Account: %u) trade: %s (Entry: %d Count: %u) to player: %s (Account: %u)",
|
||||||
|
|
@ -203,10 +199,11 @@ void WorldSession::moveItems(Item* myItems[], Item* hisItems[])
|
||||||
// store
|
// store
|
||||||
_player->pTrader->MoveItemToInventory( traderDst, myItems[i], true, true);
|
_player->pTrader->MoveItemToInventory( traderDst, myItems[i], true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hisItems[i])
|
if (hisItems[i])
|
||||||
{
|
{
|
||||||
// logging
|
// logging
|
||||||
DEBUG_LOG("player storing: %u",hisItems[i]->GetGUIDLow());
|
DEBUG_LOG("player storing: %s", hisItems[i]->GetObjectGuid().GetString().c_str());
|
||||||
if (_player->pTrader->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE))
|
if (_player->pTrader->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE))
|
||||||
{
|
{
|
||||||
sLog.outCommand(_player->pTrader->GetSession()->GetAccountId(),"GM %s (Account: %u) trade: %s (Entry: %d Count: %u) to player: %s (Account: %u)",
|
sLog.outCommand(_player->pTrader->GetSession()->GetAccountId(),"GM %s (Account: %u) trade: %s (Entry: %d Count: %u) to player: %s (Account: %u)",
|
||||||
|
|
@ -226,21 +223,21 @@ void WorldSession::moveItems(Item* myItems[], Item* hisItems[])
|
||||||
if (myItems[i])
|
if (myItems[i])
|
||||||
{
|
{
|
||||||
if (!traderCanTrade)
|
if (!traderCanTrade)
|
||||||
sLog.outError("trader can't store item: %u",myItems[i]->GetGUIDLow());
|
sLog.outError("trader can't store item: %s", myItems[i]->GetObjectGuid().GetString().c_str());
|
||||||
if (_player->CanStoreItem( NULL_BAG, NULL_SLOT, playerDst, myItems[i], false ) == EQUIP_ERR_OK)
|
if (_player->CanStoreItem( NULL_BAG, NULL_SLOT, playerDst, myItems[i], false ) == EQUIP_ERR_OK)
|
||||||
_player->MoveItemToInventory(playerDst, myItems[i], true, true);
|
_player->MoveItemToInventory(playerDst, myItems[i], true, true);
|
||||||
else
|
else
|
||||||
sLog.outError("player can't take item back: %u",myItems[i]->GetGUIDLow());
|
sLog.outError("player can't take item back: %s", myItems[i]->GetObjectGuid().GetString().c_str());
|
||||||
}
|
}
|
||||||
// return the already removed items to the original owner
|
// return the already removed items to the original owner
|
||||||
if (hisItems[i])
|
if (hisItems[i])
|
||||||
{
|
{
|
||||||
if (!playerCanTrade)
|
if (!playerCanTrade)
|
||||||
sLog.outError("player can't store item: %u",hisItems[i]->GetGUIDLow());
|
sLog.outError("player can't store item: %s", hisItems[i]->GetObjectGuid().GetString().c_str());
|
||||||
if (_player->pTrader->CanStoreItem( NULL_BAG, NULL_SLOT, traderDst, hisItems[i], false ) == EQUIP_ERR_OK)
|
if (_player->pTrader->CanStoreItem( NULL_BAG, NULL_SLOT, traderDst, hisItems[i], false ) == EQUIP_ERR_OK)
|
||||||
_player->pTrader->MoveItemToInventory(traderDst, hisItems[i], true, true);
|
_player->pTrader->MoveItemToInventory(traderDst, hisItems[i], true, true);
|
||||||
else
|
else
|
||||||
sLog.outError("trader can't take item back: %u",hisItems[i]->GetGUIDLow());
|
sLog.outError("trader can't take item back: %s", hisItems[i]->GetObjectGuid().GetString().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -278,9 +275,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
// not accept if some items now can't be trade (cheating)
|
// not accept if some items now can't be trade (cheating)
|
||||||
for(int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
for(int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if(_player->tradeItems[i] != NULL_SLOT )
|
if (Item* item =_player->GetItemByTradeSlot(i))
|
||||||
{
|
|
||||||
if(Item* item =_player->GetItemByPos( _player->tradeItems[i] ))
|
|
||||||
{
|
{
|
||||||
if (!item->CanBeTraded())
|
if (!item->CanBeTraded())
|
||||||
{
|
{
|
||||||
|
|
@ -288,10 +283,8 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(_player->pTrader->tradeItems[i] != NULL_SLOT)
|
if (Item* item =_player->pTrader->GetItemByTradeSlot(i))
|
||||||
{
|
|
||||||
if(Item* item =_player->pTrader->GetItemByPos( _player->pTrader->tradeItems[i]) )
|
|
||||||
{
|
{
|
||||||
if (!item->CanBeTraded())
|
if (!item->CanBeTraded())
|
||||||
{
|
{
|
||||||
|
|
@ -300,7 +293,6 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_player->acceptTrade = true;
|
_player->acceptTrade = true;
|
||||||
if (_player->pTrader->acceptTrade )
|
if (_player->pTrader->acceptTrade )
|
||||||
|
|
@ -311,20 +303,18 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
// store items in local list and set 'in-trade' flag
|
// store items in local list and set 'in-trade' flag
|
||||||
for(int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
for(int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if(_player->tradeItems[i] != NULL_SLOT )
|
if (Item* item = _player->GetItemByTradeSlot(i))
|
||||||
{
|
{
|
||||||
DEBUG_LOG("player trade item bag: %u slot: %u",_player->tradeItems[i] >> 8, _player->tradeItems[i] & 255 );
|
DEBUG_LOG("player trade item %s bag: %u slot: %u", item->GetObjectGuid().GetString().c_str(), item->GetBagSlot(), item->GetSlot());
|
||||||
//Can return NULL
|
//Can return NULL
|
||||||
myItems[i]=_player->GetItemByPos( _player->tradeItems[i] );
|
myItems[i] = item;
|
||||||
if (myItems[i])
|
|
||||||
myItems[i]->SetInTrade();
|
myItems[i]->SetInTrade();
|
||||||
}
|
}
|
||||||
if(_player->pTrader->tradeItems[i] != NULL_SLOT)
|
|
||||||
|
if (Item* item = _player->pTrader->GetItemByTradeSlot(i))
|
||||||
{
|
{
|
||||||
DEBUG_LOG("partner trade item bag: %u slot: %u",_player->pTrader->tradeItems[i] >> 8,_player->pTrader->tradeItems[i] & 255);
|
DEBUG_LOG("partner trade item %s bag: %u slot: %u", item->GetObjectGuid().GetString().c_str(), item->GetBagSlot(), item->GetSlot());
|
||||||
//Can return NULL
|
hisItems[i] = item;
|
||||||
hisItems[i]=_player->pTrader->GetItemByPos( _player->pTrader->tradeItems[i]);
|
|
||||||
if(hisItems[i])
|
|
||||||
hisItems[i]->SetInTrade();
|
hisItems[i]->SetInTrade();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -336,8 +326,10 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
// clear 'in-trade' flag
|
// clear 'in-trade' flag
|
||||||
for (int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
for (int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if(myItems[i]) myItems[i]->SetInTrade(false);
|
if (myItems[i])
|
||||||
if(hisItems[i]) hisItems[i]->SetInTrade(false);
|
myItems[i]->SetInTrade(false);
|
||||||
|
if (hisItems[i])
|
||||||
|
hisItems[i]->SetInTrade(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of missing space report error
|
// in case of missing space report error
|
||||||
|
|
@ -361,15 +353,15 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
|
||||||
// execute trade: 1. remove
|
// execute trade: 1. remove
|
||||||
for(int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
for(int i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if(myItems[i])
|
if (Item* item = myItems[i])
|
||||||
{
|
{
|
||||||
myItems[i]->SetUInt64Value( ITEM_FIELD_GIFTCREATOR,_player->GetGUID());
|
item->SetUInt64Value( ITEM_FIELD_GIFTCREATOR,_player->GetGUID());
|
||||||
_player->MoveItemFromInventory(_player->tradeItems[i] >> 8, _player->tradeItems[i] & 255, true);
|
_player->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true);
|
||||||
}
|
}
|
||||||
if(hisItems[i])
|
if (Item* item = hisItems[i])
|
||||||
{
|
{
|
||||||
hisItems[i]->SetUInt64Value( ITEM_FIELD_GIFTCREATOR,_player->pTrader->GetGUID());
|
item->SetUInt64Value( ITEM_FIELD_GIFTCREATOR,_player->pTrader->GetGUID());
|
||||||
_player->pTrader->MoveItemFromInventory(_player->pTrader->tradeItems[i] >> 8, _player->pTrader->tradeItems[i] & 255, true);
|
_player->pTrader->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -598,12 +590,10 @@ void WorldSession::HandleSetTradeItemOpcode(WorldPacket& recvPacket)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 pos = (bag << 8) | slot;
|
|
||||||
|
|
||||||
// prevent place single item into many trade slots using cheating and client bugs
|
// prevent place single item into many trade slots using cheating and client bugs
|
||||||
for(int i = 0; i < TRADE_SLOT_COUNT; ++i)
|
for(int i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if(_player->tradeItems[i]==pos)
|
if (_player->m_tradeItems[i]==item->GetObjectGuid())
|
||||||
{
|
{
|
||||||
// cheating attempt
|
// cheating attempt
|
||||||
SendTradeStatus(TRADE_STATUS_TRADE_CANCELED);
|
SendTradeStatus(TRADE_STATUS_TRADE_CANCELED);
|
||||||
|
|
@ -611,7 +601,7 @@ void WorldSession::HandleSetTradeItemOpcode(WorldPacket& recvPacket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_player->tradeItems[tradeSlot] = pos;
|
_player->m_tradeItems[tradeSlot] = item->GetObjectGuid();
|
||||||
|
|
||||||
_player->pTrader->GetSession()->SendUpdateTrade();
|
_player->pTrader->GetSession()->SendUpdateTrade();
|
||||||
}
|
}
|
||||||
|
|
@ -628,7 +618,7 @@ void WorldSession::HandleClearTradeItemOpcode(WorldPacket& recvPacket)
|
||||||
if (tradeSlot >= TRADE_SLOT_COUNT)
|
if (tradeSlot >= TRADE_SLOT_COUNT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_player->tradeItems[tradeSlot] = NULL_SLOT;
|
_player->m_tradeItems[tradeSlot].Clear();
|
||||||
|
|
||||||
_player->pTrader->GetSession()->SendUpdateTrade();
|
_player->pTrader->GetSession()->SendUpdateTrade();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10045"
|
#define REVISION_NR "10046"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue