GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/marketrecv.cpp Lines: 1 30 3.3 %
Date: 2017-11-29 Branches: 2 40 5.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "net/eathena/marketrecv.h"
22
23
#include "notifymanager.h"
24
25
#include "being/playerinfo.h"
26
27
#include "const/resources/currency.h"
28
29
#include "enums/resources/notifytypes.h"
30
31
#include "gui/windows/buydialog.h"
32
33
#include "gui/widgets/createwidget.h"
34
35
#include "net/messagein.h"
36
37
#include "net/eathena/npcrecv.h"
38
39
#include "resources/beinginfo.h"
40
41
#include "resources/db/npcdb.h"
42
43
#include "debug.h"
44
45
namespace EAthena
46
{
47
48
namespace MarketRecv
49
{
50
    BuyDialog *mBuyDialog = nullptr;
51
}  // namespace MarketRecv
52
53
54
void MarketRecv::processMarketOpen(Net::MessageIn &msg)
55
{
56
    const int len = (msg.readInt16("len") - 4) / 13;
57
58
    const BeingTypeId npcId = NpcRecv::mNpcTypeId;
59
    std::string currency;
60
61
    if (npcId != BeingTypeId_zero)
62
    {
63
        const BeingInfo *const info = NPCDB::get(npcId);
64
        if (info != nullptr)
65
            currency = info->getCurrency();
66
        else
67
            currency = DEFAULT_CURRENCY;
68
    }
69
    else
70
    {
71
        currency = DEFAULT_CURRENCY;
72
    }
73
74
    CREATEWIDGETV(mBuyDialog, BuyDialog,
75
        fromInt(BuyDialog::Market, BeingId),
76
        currency);
77
    mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY));
78
79
    for (int f = 0; f < len; f ++)
80
    {
81
        const int itemId = msg.readInt16("item id");
82
        const ItemTypeT type = static_cast<ItemTypeT>(msg.readUInt8("type"));
83
        const int value = msg.readInt32("price");
84
        const int amount = msg.readInt32("amount");
85
        msg.readInt16("view");
86
        const ItemColor color = ItemColor_one;
87
        mBuyDialog->addItem(itemId, type, color, amount, value);
88
    }
89
    mBuyDialog->sort();
90
}
91
92
void MarketRecv::processMarketBuyAck(Net::MessageIn &msg)
93
{
94
    const int len = (msg.readInt16("len") - 5) / 8;
95
    const int res = msg.readUInt8("result");
96
    for (int f = 0; f < len; f ++)
97
    {
98
        msg.readInt16("item id");
99
        msg.readInt16("amount");
100
        msg.readInt32("price");
101
    }
102
    if (res != 0)
103
        NotifyManager::notify(NotifyTypes::BUY_DONE);
104
    else
105
        NotifyManager::notify(NotifyTypes::BUY_FAILED);
106
}
107
108

6
}  // namespace EAthena