TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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, bool update=false)
 
uint32 GetSpell () const
 
void SetSpell (uint32 spell_id, Item *castItem=nullptr)
 
ItemGetSpellCastItem () const
 
bool HasSpellCastItem () const
 
uint64 GetMoney () const
 
void SetMoney (uint64 money)
 
bool IsAccepted () const
 
void SetAccepted (bool state, bool forTrader=false)
 
bool IsInAcceptProcess () const
 
void SetInAcceptProcess (bool state)
 
uint32 GetClientStateIndex () const
 
void UpdateClientStateIndex ()
 
uint32 GetServerStateIndex () const
 
void UpdateServerStateIndex ()
 

Private Member Functions

void Update (bool for_trader=true) const
 

Private Attributes

Player_player
 
Player_trader
 
bool _accepted
 
bool _acceptProccess
 
uint64 _money
 
uint32 _spell
 
ObjectGuid _spellCastItem
 
ObjectGuid _items [TRADE_SLOT_COUNT]
 
uint32 _clientStateIndex
 
uint32 _serverStateIndex
 

Constructor & Destructor Documentation

TradeData::TradeData ( Player player,
Player trader 
)
inline
37  :
38  _player(player), _trader(trader), _accepted(false), _acceptProccess(false),
uint32 _spell
Definition: TradeData.h:81
bool _acceptProccess
Definition: TradeData.h:77
ObjectGuid _spellCastItem
Definition: TradeData.h:82
uint64 _money
Definition: TradeData.h:79
Player * _trader
Definition: TradeData.h:74
Player * _player
Definition: TradeData.h:73
uint32 _serverStateIndex
Definition: TradeData.h:87
uint32 _clientStateIndex
Definition: TradeData.h:86
bool _accepted
Definition: TradeData.h:76

Member Function Documentation

uint32 TradeData::GetClientStateIndex ( ) const
inline
64 { return _clientStateIndex; }
uint32 _clientStateIndex
Definition: TradeData.h:86

+ Here is the caller graph for this function:

Item * TradeData::GetItem ( TradeSlots  slot) const
28 {
29  return !_items[slot].IsEmpty() ? _player->GetItemByGuid(_items[slot]) : nullptr;
30 }
ObjectGuid _items[TRADE_SLOT_COUNT]
Definition: TradeData.h:84
Player * _player
Definition: TradeData.h:73
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint64 TradeData::GetMoney ( ) const
inline
55 { return _money; }
uint64 _money
Definition: TradeData.h:79

+ Here is the caller graph for this function:

uint32 TradeData::GetServerStateIndex ( ) const
inline
67 { return _serverStateIndex; }
uint32 _serverStateIndex
Definition: TradeData.h:87

+ Here is the caller graph for this function:

uint32 TradeData::GetSpell ( ) const
inline
49 { return _spell; }
uint32 _spell
Definition: TradeData.h:81

+ Here is the caller graph for this function:

Item * TradeData::GetSpellCastItem ( ) const
51 {
52  return !_spellCastItem.IsEmpty() ? _player->GetItemByGuid(_spellCastItem) : nullptr;
53 }
ObjectGuid _spellCastItem
Definition: TradeData.h:82
Player * _player
Definition: TradeData.h:73
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Player* TradeData::GetTrader ( ) const
inline
41 { return _trader; }
Player * _trader
Definition: TradeData.h:74

+ Here is the caller graph for this function:

TradeData * TradeData::GetTraderData ( ) const
23 {
24  return _trader->GetTradeData();
25 }
Player * _trader
Definition: TradeData.h:74

+ Here is the caller graph for this function:

TradeSlots TradeData::GetTradeSlotForItem ( ObjectGuid  itemGuid) const
42 {
43  for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
44  if (_items[i] == itemGuid)
45  return TradeSlots(i);
46 
47  return TRADE_SLOT_INVALID;
48 }
TradeSlots
Definition: TradeData.h:23
ObjectGuid _items[TRADE_SLOT_COUNT]
Definition: TradeData.h:84
Definition: TradeData.h:25
uint8_t uint8
Definition: Define.h:152
Definition: TradeData.h:28
bool TradeData::HasItem ( ObjectGuid  itemGuid) const
33 {
34  for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
35  if (_items[i] == itemGuid)
36  return true;
37 
38  return false;
39 }
ObjectGuid _items[TRADE_SLOT_COUNT]
Definition: TradeData.h:84
Definition: TradeData.h:25
uint8_t uint8
Definition: Define.h:152

+ Here is the caller graph for this function:

bool TradeData::HasSpellCastItem ( ) const
inline
53 { return !_spellCastItem.IsEmpty(); }
ObjectGuid _spellCastItem
Definition: TradeData.h:82
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the caller graph for this function:

bool TradeData::IsAccepted ( ) const
inline
58 { return _accepted; }
bool _accepted
Definition: TradeData.h:76

+ Here is the caller graph for this function:

bool TradeData::IsInAcceptProcess ( ) const
inline
61 { return _acceptProccess; }
bool _acceptProccess
Definition: TradeData.h:77
void TradeData::SetAccepted ( bool  state,
bool  forTrader = false 
)
133 {
134  _accepted = state;
135 
136  if (!state)
137  {
140  if (forTrader)
141  _trader->GetSession()->SendTradeStatus(info);
142  else
143  _player->GetSession()->SendTradeStatus(info);
144  }
145 }
Definition: SharedDefines.h:4655
Player * _trader
Definition: TradeData.h:74
Definition: TradePackets.h:130
Player * _player
Definition: TradeData.h:73
::TradeStatus Status
Definition: TradePackets.h:137
bool _accepted
Definition: TradeData.h:76

+ Here is the caller graph for this function:

void TradeData::SetInAcceptProcess ( bool  state)
inline
62 { _acceptProccess = state; }
bool _acceptProccess
Definition: TradeData.h:77

+ Here is the caller graph for this function:

void TradeData::SetItem ( TradeSlots  slot,
Item item,
bool  update = false 
)
56 {
57  ObjectGuid itemGuid;
58  if (item)
59  itemGuid = item->GetGUID();
60 
61  if (_items[slot] == itemGuid && !update)
62  return;
63 
64  _items[slot] = itemGuid;
65 
66  SetAccepted(false);
67  GetTraderData()->SetAccepted(false);
68 
70 
71  Update();
72 
73  // need remove possible trader spell applied to changed item
74  if (slot == TRADE_SLOT_NONTRADED)
75  GetTraderData()->SetSpell(0);
76 
77  // need remove possible player spell applied (possible move reagent)
78  SetSpell(0);
79 }
void UpdateServerStateIndex()
Definition: TradeData.h:68
Definition: TradeData.h:27
TradeData * GetTraderData() const
Definition: TradeData.cpp:22
ObjectGuid _items[TRADE_SLOT_COUNT]
Definition: TradeData.h:84
void SetSpell(uint32 spell_id, Item *castItem=nullptr)
Definition: TradeData.cpp:81
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: ObjectGuid.h:189
void SetAccepted(bool state, bool forTrader=false)
Definition: TradeData.cpp:132
void Update(bool for_trader=true) const
Definition: TradeData.cpp:124

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TradeData::SetMoney ( uint64  money)
101 {
102  if (_money == money)
103  return;
104 
105  if (!_player->HasEnoughMoney(money))
106  {
110  _player->GetSession()->SendTradeStatus(info);
111  return;
112  }
113 
114  _money = money;
115 
116  SetAccepted(false);
117  GetTraderData()->SetAccepted(false);
118 
120 
121  Update(true);
122 }
void UpdateServerStateIndex()
Definition: TradeData.h:68
Definition: SharedDefines.h:4660
Definition: Item.h:77
TradeData * GetTraderData() const
Definition: TradeData.cpp:22
uint64 _money
Definition: TradeData.h:79
Definition: TradePackets.h:130
Player * _player
Definition: TradeData.h:73
::TradeStatus Status
Definition: TradePackets.h:137
int32 BagResult
Definition: TradePackets.h:144
void SetAccepted(bool state, bool forTrader=false)
Definition: TradeData.cpp:132
void Update(bool for_trader=true) const
Definition: TradeData.cpp:124

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TradeData::SetSpell ( uint32  spell_id,
Item castItem = nullptr 
)
82 {
83  ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty;
84 
85  if (_spell == spell_id && _spellCastItem == itemGuid)
86  return;
87 
88  _spell = spell_id;
89  _spellCastItem = itemGuid;
90 
91  SetAccepted(false);
92  GetTraderData()->SetAccepted(false);
93 
95 
96  Update(true); // send spell info to item owner
97  Update(false); // send spell info to caster self
98 }
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
void UpdateServerStateIndex()
Definition: TradeData.h:68
uint32 _spell
Definition: TradeData.h:81
ObjectGuid _spellCastItem
Definition: TradeData.h:82
TradeData * GetTraderData() const
Definition: TradeData.cpp:22
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: ObjectGuid.h:189
void SetAccepted(bool state, bool forTrader=false)
Definition: TradeData.cpp:132
void Update(bool for_trader=true) const
Definition: TradeData.cpp:124

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TradeData::Update ( bool  for_trader = true) const
private
125 {
126  if (forTrader)
127  _trader->GetSession()->SendUpdateTrade(true); // player state for trader
128  else
129  _player->GetSession()->SendUpdateTrade(false); // player state for player
130 }
Player * _trader
Definition: TradeData.h:74
Player * _player
Definition: TradeData.h:73

+ Here is the caller graph for this function:

void TradeData::UpdateClientStateIndex ( )
inline
65 { ++_clientStateIndex; }
uint32 _clientStateIndex
Definition: TradeData.h:86

+ Here is the caller graph for this function:

void TradeData::UpdateServerStateIndex ( )
inline
uint32 rand32()
Definition: Random.cpp:64
uint32 _serverStateIndex
Definition: TradeData.h:87

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool TradeData::_accepted
private
bool TradeData::_acceptProccess
private
uint32 TradeData::_clientStateIndex
private
ObjectGuid TradeData::_items[TRADE_SLOT_COUNT]
private
uint64 TradeData::_money
private
Player* TradeData::_player
private
uint32 TradeData::_serverStateIndex
private
uint32 TradeData::_spell
private
ObjectGuid TradeData::_spellCastItem
private
Player* TradeData::_trader
private

The documentation for this class was generated from the following files: