TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TradeData.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TradeData_h__
19 #define TradeData_h__
20 
21 #include "ObjectGuid.h"
22 
24 {
29 };
30 
31 class Item;
32 class Player;
33 
35 {
36 public:
37  TradeData(Player* player, Player* trader) :
38  _player(player), _trader(trader), _accepted(false), _acceptProccess(false),
39  _money(0), _spell(0), _spellCastItem(), _clientStateIndex(1), _serverStateIndex(1) { }
40 
41  Player* GetTrader() const { return _trader; }
42  TradeData* GetTraderData() const;
43 
44  Item* GetItem(TradeSlots slot) const;
45  bool HasItem(ObjectGuid itemGuid) const;
46  TradeSlots GetTradeSlotForItem(ObjectGuid itemGuid) const;
47  void SetItem(TradeSlots slot, Item* item, bool update = false);
48 
49  uint32 GetSpell() const { return _spell; }
50  void SetSpell(uint32 spell_id, Item* castItem = nullptr);
51 
52  Item* GetSpellCastItem() const;
53  bool HasSpellCastItem() const { return !_spellCastItem.IsEmpty(); }
54 
55  uint64 GetMoney() const { return _money; }
56  void SetMoney(uint64 money);
57 
58  bool IsAccepted() const { return _accepted; }
59  void SetAccepted(bool state, bool forTrader = false);
60 
61  bool IsInAcceptProcess() const { return _acceptProccess; }
62  void SetInAcceptProcess(bool state) { _acceptProccess = state; }
63 
64  uint32 GetClientStateIndex() const { return _clientStateIndex; }
65  void UpdateClientStateIndex() { ++_clientStateIndex; }
66 
67  uint32 GetServerStateIndex() const { return _serverStateIndex; }
68  void UpdateServerStateIndex() { _serverStateIndex = rand32(); }
69 
70 private:
71  void Update(bool for_trader = true) const;
72 
73  Player* _player; // Player who own of this TradeData
74  Player* _trader; // Player who trade with _player
75 
76  bool _accepted; // _player press accept for trade list
77  bool _acceptProccess; // one from player/trader press accept and this processed
78 
79  uint64 _money; // _player place money to trade
80 
81  uint32 _spell; // _player apply spell to non-traded slot item
82  ObjectGuid _spellCastItem; // applied spell cast by item use
83 
84  ObjectGuid _items[TRADE_SLOT_COUNT]; // traded items from _player side including non-traded slot
85 
88 };
89 
90 #endif // TradeData_h__
void UpdateServerStateIndex()
Definition: TradeData.h:68
uint32 _spell
Definition: TradeData.h:81
void SetInAcceptProcess(bool state)
Definition: TradeData.h:62
bool _acceptProccess
Definition: TradeData.h:77
#define false
Definition: CascPort.h:18
ObjectGuid _spellCastItem
Definition: TradeData.h:82
bool IsInAcceptProcess() const
Definition: TradeData.h:61
uint32 GetSpell() const
Definition: TradeData.h:49
Definition: TradeData.h:34
TradeSlots
Definition: TradeData.h:23
Definition: TradeData.h:27
Definition: Item.h:259
uint32 GetClientStateIndex() const
Definition: TradeData.h:64
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
uint64 _money
Definition: TradeData.h:79
Player * GetTrader() const
Definition: TradeData.h:41
Player * _trader
Definition: TradeData.h:74
TradeData(Player *player, Player *trader)
Definition: TradeData.h:37
Definition: TradeData.h:25
#define TC_GAME_API
Definition: Define.h:134
uint32 GetServerStateIndex() const
Definition: TradeData.h:67
Player * _player
Definition: TradeData.h:73
uint32 rand32()
Definition: Random.cpp:64
uint32 _serverStateIndex
Definition: TradeData.h:87
bool IsAccepted() const
Definition: TradeData.h:58
uint32 _clientStateIndex
Definition: TradeData.h:86
bool HasSpellCastItem() const
Definition: TradeData.h:53
Definition: ObjectGuid.h:189
bool _accepted
Definition: TradeData.h:76
Definition: TradeData.h:26
void UpdateClientStateIndex()
Definition: TradeData.h:65
uint64 GetMoney() const
Definition: TradeData.h:55
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
Definition: TradeData.h:28