AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
TradeData Class Reference

#include "TradeData.h"

Public Member Functions

 TradeData (Player *player, Player *trader)
 
PlayerGetTrader () const
 
TradeDataGetTraderData () const
 
ItemGetItem (TradeSlots slot) const
 
bool HasItem (ObjectGuid itemGuid) const
 
TradeSlots GetTradeSlotForItem (ObjectGuid itemGuid) const
 
void SetItem (TradeSlots slot, Item *item)
 
uint32 GetSpell () const
 
void SetSpell (uint32 spell_id, Item *castItem=nullptr)
 
ItemGetSpellCastItem () const
 
bool HasSpellCastItem () const
 
uint32 GetMoney () const
 
void SetMoney (uint32 money)
 
bool IsAccepted () const
 
void SetAccepted (bool state, bool crosssend=false)
 
bool IsInAcceptProcess () const
 
void SetInAcceptProcess (bool state)
 

Private Member Functions

void Update (bool for_trader=true)
 

Private Attributes

Playerm_player
 
Playerm_trader
 
bool m_accepted
 
bool m_acceptProccess
 
uint32 m_money
 
uint32 m_spell
 
ObjectGuid m_spellCastItem
 
ObjectGuid m_items [TRADE_SLOT_COUNT]
 

Detailed Description

Constructor & Destructor Documentation

◆ TradeData()

TradeData::TradeData ( Player player,
Player trader 
)
inline
38 :
39 m_player(player), m_trader(trader), m_accepted(false), m_acceptProccess(false), m_money(0), m_spell(0) { }
bool m_acceptProccess
Definition: TradeData.h:72
uint32 m_spell
Definition: TradeData.h:76
Player * m_player
Definition: TradeData.h:68
uint32 m_money
Definition: TradeData.h:74
Player * m_trader
Definition: TradeData.h:69
bool m_accepted
Definition: TradeData.h:71

Member Function Documentation

◆ GetItem()

Item * TradeData::GetItem ( TradeSlots  slot) const
27{
28 return m_items[slot] ? m_player->GetItemByGuid(m_items[slot]) : nullptr;
29}
Item * GetItemByGuid(ObjectGuid guid) const
Definition: PlayerStorage.cpp:413
ObjectGuid m_items[TRADE_SLOT_COUNT]
Definition: TradeData.h:79

References Player::GetItemByGuid(), m_items, and m_player.

Referenced by WorldSession::HandleAcceptTradeOpcode(), WorldSession::SendUpdateTrade(), and setAcceptTradeMode().

◆ GetMoney()

uint32 TradeData::GetMoney ( ) const
inline

◆ GetSpell()

uint32 TradeData::GetSpell ( ) const
inline

◆ GetSpellCastItem()

Item * TradeData::GetSpellCastItem ( ) const
50{
52}
ObjectGuid m_spellCastItem
Definition: TradeData.h:77

References Player::GetItemByGuid(), m_player, and m_spellCastItem.

Referenced by WorldSession::HandleAcceptTradeOpcode().

◆ GetTrader()

◆ GetTraderData()

TradeData * TradeData::GetTraderData ( ) const
22{
23 return m_trader->GetTradeData();
24}
TradeData * GetTradeData() const
Definition: Player.h:1368

References Player::GetTradeData(), and m_trader.

Referenced by WorldSession::SendUpdateTrade(), SetItem(), SetMoney(), and SetSpell().

◆ GetTradeSlotForItem()

TradeSlots TradeData::GetTradeSlotForItem ( ObjectGuid  itemGuid) const
41{
42 for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
43 if (m_items[i] == itemGuid)
44 return TradeSlots(i);
45
46 return TRADE_SLOT_INVALID;
47}
std::uint8_t uint8
Definition: Define.h:109
TradeSlots
Definition: TradeData.h:28
@ TRADE_SLOT_COUNT
Definition: TradeData.h:29
@ TRADE_SLOT_INVALID
Definition: TradeData.h:32

References m_items, TRADE_SLOT_COUNT, and TRADE_SLOT_INVALID.

◆ HasItem()

bool TradeData::HasItem ( ObjectGuid  itemGuid) const
32{
33 for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
34 if (m_items[i] == itemGuid)
35 return true;
36
37 return false;
38}

References m_items, and TRADE_SLOT_COUNT.

Referenced by WorldSession::HandleSetTradeItemOpcode().

◆ HasSpellCastItem()

bool TradeData::HasSpellCastItem ( ) const
inline

◆ IsAccepted()

bool TradeData::IsAccepted ( ) const
inline

◆ IsInAcceptProcess()

bool TradeData::IsInAcceptProcess ( ) const
inline
61{ return m_acceptProccess; }

◆ SetAccepted()

void TradeData::SetAccepted ( bool  state,
bool  crosssend = false 
)
121{
122 m_accepted = state;
123
124 if (!state)
125 {
126 if (crosssend)
128 else
130 }
131}
@ TRADE_STATUS_BACK_TO_TRADE
Definition: SharedDefines.h:3557
WorldSession * GetSession() const
Definition: Player.h:1978
void SendTradeStatus(TradeStatus status)
Definition: TradeHandler.cpp:33

References Player::GetSession(), m_accepted, m_player, m_trader, WorldSession::SendTradeStatus(), and TRADE_STATUS_BACK_TO_TRADE.

Referenced by WorldSession::HandleAcceptTradeOpcode(), WorldSession::HandleUnacceptTradeOpcode(), SetItem(), SetMoney(), and SetSpell().

◆ SetInAcceptProcess()

void TradeData::SetInAcceptProcess ( bool  state)
inline
62{ m_acceptProccess = state; }

Referenced by clearAcceptTradeMode(), and setAcceptTradeMode().

◆ SetItem()

void TradeData::SetItem ( TradeSlots  slot,
Item item 
)
55{
56 ObjectGuid itemGuid = item ? item->GetGUID() : ObjectGuid::Empty;
57
58 if (m_items[slot] == itemGuid)
59 return;
60
61 m_items[slot] = itemGuid;
62
63 SetAccepted(false);
64 GetTraderData()->SetAccepted(false);
65
66 Update();
67
68 // need remove possible trader spell applied to changed item
69 if (slot == TRADE_SLOT_NONTRADED)
71
72 // need remove possible player spell applied (possible move reagent)
73 SetSpell(0);
74}
@ TRADE_SLOT_NONTRADED
Definition: TradeData.h:31
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
Definition: ObjectGuid.h:118
static ObjectGuid const Empty
Definition: ObjectGuid.h:120
void SetSpell(uint32 spell_id, Item *castItem=nullptr)
Definition: TradeData.cpp:76
TradeData * GetTraderData() const
Definition: TradeData.cpp:21
void Update(bool for_trader=true)
Definition: TradeData.cpp:112
void SetAccepted(bool state, bool crosssend=false)
Definition: TradeData.cpp:120

References ObjectGuid::Empty, Object::GetGUID(), GetTraderData(), m_items, SetAccepted(), SetSpell(), TRADE_SLOT_NONTRADED, and Update().

Referenced by WorldSession::HandleClearTradeItemOpcode(), and WorldSession::HandleSetTradeItemOpcode().

◆ SetMoney()

void TradeData::SetMoney ( uint32  money)
94{
95 if (m_money == money)
96 return;
97
98 if (!m_player->HasEnoughMoney(money))
99 {
101 return;
102 }
103
104 m_money = money;
105
106 SetAccepted(false);
107 GetTraderData()->SetAccepted(false);
108
109 Update(true);
110}
@ TRADE_STATUS_BUSY
Definition: SharedDefines.h:3550
bool HasEnoughMoney(uint32 amount) const
Definition: Player.h:1598

References Player::GetSession(), GetTraderData(), Player::HasEnoughMoney(), m_money, m_player, WorldSession::SendTradeStatus(), SetAccepted(), TRADE_STATUS_BUSY, and Update().

Referenced by WorldSession::HandleSetTradeGoldOpcode().

◆ SetSpell()

void TradeData::SetSpell ( uint32  spell_id,
Item castItem = nullptr 
)
77{
78 ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty;
79
80 if (m_spell == spell_id && m_spellCastItem == itemGuid)
81 return;
82
83 m_spell = spell_id;
84 m_spellCastItem = itemGuid;
85
86 SetAccepted(false);
87 GetTraderData()->SetAccepted(false);
88
89 Update(true); // send spell info to item owner
90 Update(false); // send spell info to caster self
91}

References ObjectGuid::Empty, Object::GetGUID(), GetTraderData(), m_spell, m_spellCastItem, SetAccepted(), and Update().

Referenced by WorldSession::HandleAcceptTradeOpcode(), and SetItem().

◆ Update()

void TradeData::Update ( bool  for_trader = true)
private
113{
114 if (forTarget)
115 m_trader->GetSession()->SendUpdateTrade(true); // player state for trader
116 else
117 m_player->GetSession()->SendUpdateTrade(false); // player state for player
118}
void SendUpdateTrade(bool trader_data=true)
Definition: TradeHandler.cpp:83

References Player::GetSession(), m_player, m_trader, and WorldSession::SendUpdateTrade().

Referenced by SetItem(), SetMoney(), and SetSpell().

Member Data Documentation

◆ m_accepted

bool TradeData::m_accepted
private

Referenced by SetAccepted().

◆ m_acceptProccess

bool TradeData::m_acceptProccess
private

◆ m_items

ObjectGuid TradeData::m_items[TRADE_SLOT_COUNT]
private

◆ m_money

uint32 TradeData::m_money
private

Referenced by SetMoney().

◆ m_player

Player* TradeData::m_player
private

◆ m_spell

uint32 TradeData::m_spell
private

Referenced by SetSpell().

◆ m_spellCastItem

ObjectGuid TradeData::m_spellCastItem
private

Referenced by GetSpellCastItem(), and SetSpell().

◆ m_trader

Player* TradeData::m_trader
private

Referenced by GetTraderData(), SetAccepted(), and Update().