GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/marketrecv.cpp Lines: 1 31 3.2 %
Date: 2018-09-20 Branches: 0 36 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2018  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
extern int itemIdLen;
46
47
namespace EAthena
48
{
49
50
namespace MarketRecv
51
{
52
    BuyDialog *mBuyDialog = nullptr;
53
}  // namespace MarketRecv
54
55
56
void MarketRecv::processMarketOpen(Net::MessageIn &msg)
57
{
58
    const int len = (msg.readInt16("len") - 4) / (11 + itemIdLen);
59
60
    const BeingTypeId npcId = NpcRecv::mNpcTypeId;
61
    std::string currency;
62
63
    if (npcId != BeingTypeId_zero)
64
    {
65
        const BeingInfo *const info = NPCDB::get(npcId);
66
        if (info != nullptr)
67
            currency = info->getCurrency();
68
        else
69
            currency = DEFAULT_CURRENCY;
70
    }
71
    else
72
    {
73
        currency = DEFAULT_CURRENCY;
74
    }
75
76
    CREATEWIDGETV(mBuyDialog, BuyDialog,
77
        fromInt(BuyDialog::Market, BeingId),
78
        currency);
79
    mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY));
80
81
    for (int f = 0; f < len; f ++)
82
    {
83
        const int itemId = msg.readItemId("item id");
84
        const ItemTypeT type = static_cast<ItemTypeT>(msg.readUInt8("type"));
85
        const int value = msg.readInt32("price");
86
        const int amount = msg.readInt32("amount");
87
        msg.readInt16("view");
88
        const ItemColor color = ItemColor_one;
89
        mBuyDialog->addItem(itemId, type, color, amount, value);
90
    }
91
    mBuyDialog->sort();
92
}
93
94
void MarketRecv::processMarketBuyAck(Net::MessageIn &msg)
95
{
96
    const int len = (msg.readInt16("len") - 5) / (6 + itemIdLen);
97
    const int res = msg.readUInt8("result");
98
    for (int f = 0; f < len; f ++)
99
    {
100
        msg.readItemId("item id");
101
        msg.readInt16("amount");
102
        msg.readInt32("price");
103
    }
104
    if (res != 0)
105
        NotifyManager::notify(NotifyTypes::BUY_DONE);
106
    else
107
        NotifyManager::notify(NotifyTypes::BUY_FAILED);
108
}
109
110
2
}  // namespace EAthena