mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-19 14:39:43 -04:00
Core/Player: Move TradeData to its own file
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "Opcodes.h"
|
||||
#include "WorldSession.h"
|
||||
#include "ItemPackets.h"
|
||||
#include "TradeData.h"
|
||||
|
||||
void AddItemsSetItem(Player* player, Item* item)
|
||||
{
|
||||
|
||||
@@ -130,133 +130,6 @@ uint32 const MasterySpells[MAX_CLASSES] =
|
||||
|
||||
uint64 const MAX_MONEY_AMOUNT = 9999999999ULL;
|
||||
|
||||
//== TradeData =================================================
|
||||
|
||||
TradeData* TradeData::GetTraderData() const
|
||||
{
|
||||
return m_trader->GetTradeData();
|
||||
}
|
||||
|
||||
Item* TradeData::GetItem(TradeSlots slot) const
|
||||
{
|
||||
return !m_items[slot].IsEmpty() ? m_player->GetItemByGuid(m_items[slot]) : NULL;
|
||||
}
|
||||
|
||||
bool TradeData::HasItem(ObjectGuid itemGuid) const
|
||||
{
|
||||
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||
if (m_items[i] == itemGuid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TradeSlots TradeData::GetTradeSlotForItem(ObjectGuid itemGuid) const
|
||||
{
|
||||
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||
if (m_items[i] == itemGuid)
|
||||
return TradeSlots(i);
|
||||
|
||||
return TRADE_SLOT_INVALID;
|
||||
}
|
||||
|
||||
Item* TradeData::GetSpellCastItem() const
|
||||
{
|
||||
return !m_spellCastItem.IsEmpty() ? m_player->GetItemByGuid(m_spellCastItem) : NULL;
|
||||
}
|
||||
|
||||
void TradeData::SetItem(TradeSlots slot, Item* item, bool update /*= false*/)
|
||||
{
|
||||
ObjectGuid itemGuid;
|
||||
if (item)
|
||||
itemGuid = item->GetGUID();
|
||||
|
||||
if (m_items[slot] == itemGuid && !update)
|
||||
return;
|
||||
|
||||
m_items[slot] = itemGuid;
|
||||
|
||||
SetAccepted(false);
|
||||
GetTraderData()->SetAccepted(false);
|
||||
|
||||
UpdateServerStateIndex();
|
||||
|
||||
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*/)
|
||||
{
|
||||
ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty;
|
||||
|
||||
if (m_spell == spell_id && m_spellCastItem == itemGuid)
|
||||
return;
|
||||
|
||||
m_spell = spell_id;
|
||||
m_spellCastItem = itemGuid;
|
||||
|
||||
SetAccepted(false);
|
||||
GetTraderData()->SetAccepted(false);
|
||||
|
||||
UpdateServerStateIndex();
|
||||
|
||||
Update(true); // send spell info to item owner
|
||||
Update(false); // send spell info to caster self
|
||||
}
|
||||
|
||||
void TradeData::SetMoney(uint64 money)
|
||||
{
|
||||
if (m_money == money)
|
||||
return;
|
||||
|
||||
if (!m_player->HasEnoughMoney(money))
|
||||
{
|
||||
WorldPackets::Trade::TradeStatus info;
|
||||
info.Status = TRADE_STATUS_FAILED;
|
||||
info.BagResult = EQUIP_ERR_NOT_ENOUGH_MONEY;
|
||||
m_player->GetSession()->SendTradeStatus(info);
|
||||
return;
|
||||
}
|
||||
|
||||
m_money = money;
|
||||
|
||||
SetAccepted(false);
|
||||
GetTraderData()->SetAccepted(false);
|
||||
|
||||
UpdateServerStateIndex();
|
||||
|
||||
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)
|
||||
{
|
||||
WorldPackets::Trade::TradeStatus info;
|
||||
info.Status = TRADE_STATUS_UNACCEPTED;
|
||||
if (crosssend)
|
||||
m_trader->GetSession()->SendTradeStatus(info);
|
||||
else
|
||||
m_player->GetSession()->SendTradeStatus(info);
|
||||
}
|
||||
}
|
||||
|
||||
// == KillRewarder ====================================================
|
||||
// KillRewarder incapsulates logic of rewarding player upon kill with:
|
||||
// * XP;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "Opcodes.h"
|
||||
#include "WorldSession.h"
|
||||
#include "PlayerTaxi.h"
|
||||
#include "TradeData.h"
|
||||
|
||||
struct CreatureTemplate;
|
||||
struct Mail;
|
||||
@@ -834,14 +835,6 @@ struct ItemPosCount
|
||||
};
|
||||
typedef std::vector<ItemPosCount> ItemPosCountVec;
|
||||
|
||||
enum TradeSlots
|
||||
{
|
||||
TRADE_SLOT_COUNT = 7,
|
||||
TRADE_SLOT_TRADED_COUNT = 6,
|
||||
TRADE_SLOT_NONTRADED = 6,
|
||||
TRADE_SLOT_INVALID = -1
|
||||
};
|
||||
|
||||
enum TransferAbortReason
|
||||
{
|
||||
TRANSFER_ABORT_NONE = 0,
|
||||
@@ -1133,65 +1126,6 @@ struct VoidStorageItem
|
||||
std::vector<int32> BonusListIDs;
|
||||
};
|
||||
|
||||
class TradeData
|
||||
{
|
||||
public: // constructors
|
||||
TradeData(Player* player, Player* trader) :
|
||||
m_player(player), m_trader(trader), m_accepted(false), m_acceptProccess(false),
|
||||
m_money(0), m_spell(0), m_spellCastItem(), m_clientStateIndex(1), m_serverStateIndex(1) { }
|
||||
|
||||
Player* GetTrader() const { return m_trader; }
|
||||
TradeData* GetTraderData() const;
|
||||
|
||||
Item* GetItem(TradeSlots slot) const;
|
||||
bool HasItem(ObjectGuid itemGuid) const;
|
||||
TradeSlots GetTradeSlotForItem(ObjectGuid itemGuid) const;
|
||||
void SetItem(TradeSlots slot, Item* item, bool update = false);
|
||||
|
||||
uint32 GetSpell() const { return m_spell; }
|
||||
void SetSpell(uint32 spell_id, Item* castItem = NULL);
|
||||
|
||||
Item* GetSpellCastItem() const;
|
||||
bool HasSpellCastItem() const { return !m_spellCastItem.IsEmpty(); }
|
||||
|
||||
uint64 GetMoney() const { return m_money; }
|
||||
void SetMoney(uint64 money);
|
||||
|
||||
bool IsAccepted() const { return m_accepted; }
|
||||
void SetAccepted(bool state, bool crosssend = false);
|
||||
|
||||
bool IsInAcceptProcess() const { return m_acceptProccess; }
|
||||
void SetInAcceptProcess(bool state) { m_acceptProccess = state; }
|
||||
|
||||
uint32 GetClientStateIndex() const { return m_clientStateIndex; }
|
||||
void UpdateClientStateIndex() { ++m_clientStateIndex; }
|
||||
|
||||
uint32 GetServerStateIndex() const { return m_serverStateIndex; }
|
||||
void UpdateServerStateIndex() { m_serverStateIndex = rand32(); }
|
||||
|
||||
private: // internal functions
|
||||
|
||||
void Update(bool for_trader = true);
|
||||
|
||||
private: // fields
|
||||
|
||||
Player* m_player; // Player who own of this TradeData
|
||||
Player* m_trader; // Player who trade with m_player
|
||||
|
||||
bool m_accepted; // m_player press accept for trade list
|
||||
bool m_acceptProccess; // one from player/trader press accept and this processed
|
||||
|
||||
uint64 m_money; // m_player place money to trade
|
||||
|
||||
uint32 m_spell; // m_player apply spell to non-traded slot item
|
||||
ObjectGuid m_spellCastItem; // applied spell cast by item use
|
||||
|
||||
ObjectGuid m_items[TRADE_SLOT_COUNT]; // traded items from m_player side including non-traded slot
|
||||
|
||||
uint32 m_clientStateIndex;
|
||||
uint32 m_serverStateIndex;
|
||||
};
|
||||
|
||||
struct ResurrectionData
|
||||
{
|
||||
ObjectGuid GUID;
|
||||
@@ -1529,7 +1463,7 @@ class Player : public Unit, public GridObject<Player>
|
||||
|
||||
float GetReputationPriceDiscount(Creature const* creature) const;
|
||||
|
||||
Player* GetTrader() const { return m_trade ? m_trade->GetTrader() : NULL; }
|
||||
Player* GetTrader() const { return m_trade ? m_trade->GetTrader() : nullptr; }
|
||||
TradeData* GetTradeData() const { return m_trade; }
|
||||
void TradeCancel(bool sendback);
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TradeData.h"
|
||||
#include "Player.h"
|
||||
#include "TradePackets.h"
|
||||
|
||||
TradeData* TradeData::GetTraderData() const
|
||||
{
|
||||
return _trader->GetTradeData();
|
||||
}
|
||||
|
||||
Item* TradeData::GetItem(TradeSlots slot) const
|
||||
{
|
||||
return !_items[slot].IsEmpty() ? _player->GetItemByGuid(_items[slot]) : nullptr;
|
||||
}
|
||||
|
||||
bool TradeData::HasItem(ObjectGuid itemGuid) const
|
||||
{
|
||||
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||
if (_items[i] == itemGuid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TradeSlots TradeData::GetTradeSlotForItem(ObjectGuid itemGuid) const
|
||||
{
|
||||
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
|
||||
if (_items[i] == itemGuid)
|
||||
return TradeSlots(i);
|
||||
|
||||
return TRADE_SLOT_INVALID;
|
||||
}
|
||||
|
||||
Item* TradeData::GetSpellCastItem() const
|
||||
{
|
||||
return !_spellCastItem.IsEmpty() ? _player->GetItemByGuid(_spellCastItem) : nullptr;
|
||||
}
|
||||
|
||||
void TradeData::SetItem(TradeSlots slot, Item* item, bool update /*= false*/)
|
||||
{
|
||||
ObjectGuid itemGuid;
|
||||
if (item)
|
||||
itemGuid = item->GetGUID();
|
||||
|
||||
if (_items[slot] == itemGuid && !update)
|
||||
return;
|
||||
|
||||
_items[slot] = itemGuid;
|
||||
|
||||
SetAccepted(false);
|
||||
GetTraderData()->SetAccepted(false);
|
||||
|
||||
UpdateServerStateIndex();
|
||||
|
||||
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 /*= nullptr*/)
|
||||
{
|
||||
ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty;
|
||||
|
||||
if (_spell == spell_id && _spellCastItem == itemGuid)
|
||||
return;
|
||||
|
||||
_spell = spell_id;
|
||||
_spellCastItem = itemGuid;
|
||||
|
||||
SetAccepted(false);
|
||||
GetTraderData()->SetAccepted(false);
|
||||
|
||||
UpdateServerStateIndex();
|
||||
|
||||
Update(true); // send spell info to item owner
|
||||
Update(false); // send spell info to caster self
|
||||
}
|
||||
|
||||
void TradeData::SetMoney(uint64 money)
|
||||
{
|
||||
if (_money == money)
|
||||
return;
|
||||
|
||||
if (!_player->HasEnoughMoney(money))
|
||||
{
|
||||
WorldPackets::Trade::TradeStatus info;
|
||||
info.Status = TRADE_STATUS_FAILED;
|
||||
info.BagResult = EQUIP_ERR_NOT_ENOUGH_MONEY;
|
||||
_player->GetSession()->SendTradeStatus(info);
|
||||
return;
|
||||
}
|
||||
|
||||
_money = money;
|
||||
|
||||
SetAccepted(false);
|
||||
GetTraderData()->SetAccepted(false);
|
||||
|
||||
UpdateServerStateIndex();
|
||||
|
||||
Update(true);
|
||||
}
|
||||
|
||||
void TradeData::Update(bool forTrader /*= true*/) const
|
||||
{
|
||||
if (forTrader)
|
||||
_trader->GetSession()->SendUpdateTrade(true); // player state for trader
|
||||
else
|
||||
_player->GetSession()->SendUpdateTrade(false); // player state for player
|
||||
}
|
||||
|
||||
void TradeData::SetAccepted(bool state, bool forTrader /*= false*/)
|
||||
{
|
||||
_accepted = state;
|
||||
|
||||
if (!state)
|
||||
{
|
||||
WorldPackets::Trade::TradeStatus info;
|
||||
info.Status = TRADE_STATUS_UNACCEPTED;
|
||||
if (forTrader)
|
||||
_trader->GetSession()->SendTradeStatus(info);
|
||||
else
|
||||
_player->GetSession()->SendTradeStatus(info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TradeData_h__
|
||||
#define TradeData_h__
|
||||
|
||||
#include "ObjectGuid.h"
|
||||
|
||||
enum TradeSlots
|
||||
{
|
||||
TRADE_SLOT_COUNT = 7,
|
||||
TRADE_SLOT_TRADED_COUNT = 6,
|
||||
TRADE_SLOT_NONTRADED = 6,
|
||||
TRADE_SLOT_INVALID = -1
|
||||
};
|
||||
|
||||
class Item;
|
||||
class Player;
|
||||
|
||||
class TradeData
|
||||
{
|
||||
public:
|
||||
TradeData(Player* player, Player* trader) :
|
||||
_player(player), _trader(trader), _accepted(false), _acceptProccess(false),
|
||||
_money(0), _spell(0), _spellCastItem(), _clientStateIndex(1), _serverStateIndex(1) { }
|
||||
|
||||
Player* GetTrader() const { return _trader; }
|
||||
TradeData* GetTraderData() const;
|
||||
|
||||
Item* GetItem(TradeSlots slot) const;
|
||||
bool HasItem(ObjectGuid itemGuid) const;
|
||||
TradeSlots GetTradeSlotForItem(ObjectGuid itemGuid) const;
|
||||
void SetItem(TradeSlots slot, Item* item, bool update = false);
|
||||
|
||||
uint32 GetSpell() const { return _spell; }
|
||||
void SetSpell(uint32 spell_id, Item* castItem = nullptr);
|
||||
|
||||
Item* GetSpellCastItem() const;
|
||||
bool HasSpellCastItem() const { return !_spellCastItem.IsEmpty(); }
|
||||
|
||||
uint64 GetMoney() const { return _money; }
|
||||
void SetMoney(uint64 money);
|
||||
|
||||
bool IsAccepted() const { return _accepted; }
|
||||
void SetAccepted(bool state, bool forTrader = false);
|
||||
|
||||
bool IsInAcceptProcess() const { return _acceptProccess; }
|
||||
void SetInAcceptProcess(bool state) { _acceptProccess = state; }
|
||||
|
||||
uint32 GetClientStateIndex() const { return _clientStateIndex; }
|
||||
void UpdateClientStateIndex() { ++_clientStateIndex; }
|
||||
|
||||
uint32 GetServerStateIndex() const { return _serverStateIndex; }
|
||||
void UpdateServerStateIndex() { _serverStateIndex = rand32(); }
|
||||
|
||||
private:
|
||||
void Update(bool for_trader = true) const;
|
||||
|
||||
Player* _player; // Player who own of this TradeData
|
||||
Player* _trader; // Player who trade with _player
|
||||
|
||||
bool _accepted; // _player press accept for trade list
|
||||
bool _acceptProccess; // one from player/trader press accept and this processed
|
||||
|
||||
uint64 _money; // _player place money to trade
|
||||
|
||||
uint32 _spell; // _player apply spell to non-traded slot item
|
||||
ObjectGuid _spellCastItem; // applied spell cast by item use
|
||||
|
||||
ObjectGuid _items[TRADE_SLOT_COUNT]; // traded items from _player side including non-traded slot
|
||||
|
||||
uint32 _clientStateIndex;
|
||||
uint32 _serverStateIndex;
|
||||
};
|
||||
|
||||
#endif // TradeData_h__
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "Language.h"
|
||||
#include "AccountMgr.h"
|
||||
#include "TradePackets.h"
|
||||
#include "TradeData.h"
|
||||
|
||||
void WorldSession::SendTradeStatus(WorldPackets::Trade::TradeStatus& info)
|
||||
{
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "SpellPackets.h"
|
||||
#include "CombatLogPackets.h"
|
||||
#include "SpellHistory.h"
|
||||
#include "TradeData.h"
|
||||
|
||||
extern pEffect SpellEffects[TOTAL_SPELL_EFFECTS];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user