summaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Player/TradeData.h
blob: 5eb57e5fbc3ae66d8d0d56c2c7af32e711d9ec16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
 *
 * 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 __TRADE_DATA_H__
#define __TRADE_DATA_H__

#include "Define.h"

class Item;
class ObjectGuid;
class Player;

enum TradeSlots
{
    TRADE_SLOT_COUNT            = 7,
    TRADE_SLOT_TRADED_COUNT     = 6,
    TRADE_SLOT_NONTRADED        = 6,
    TRADE_SLOT_INVALID          = -1,
};

class AC_GAME_API 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) { }

    [[nodiscard]] Player* GetTrader() const { return m_trader; }
    [[nodiscard]] TradeData* GetTraderData() const;

    [[nodiscard]] Item* GetItem(TradeSlots slot) const;
    [[nodiscard]] bool HasItem(ObjectGuid itemGuid) const;
    [[nodiscard]] TradeSlots GetTradeSlotForItem(ObjectGuid itemGuid) const;
    void SetItem(TradeSlots slot, Item* item);

    [[nodiscard]] uint32 GetSpell() const { return m_spell; }
    void SetSpell(uint32 spell_id, Item* castItem = nullptr);

    [[nodiscard]] Item*  GetSpellCastItem() const;
    [[nodiscard]] bool HasSpellCastItem() const { return m_spellCastItem; }

    [[nodiscard]] uint32 GetMoney() const { return m_money; }
    void SetMoney(uint32 money);

    [[nodiscard]] bool IsAccepted() const { return m_accepted; }
    void SetAccepted(bool state, bool crosssend = false);

    [[nodiscard]] bool IsInAcceptProcess() const { return m_acceptProccess; }
    void SetInAcceptProcess(bool state) { m_acceptProccess = state; }

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

    uint32     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 casted by item use

    ObjectGuid m_items[TRADE_SLOT_COUNT];               // traded itmes from m_player side including non-traded slot
};

#endif