GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/buysellrecv.cpp Lines: 0 18 0.0 %
Date: 2017-11-29 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "net/ea/buysellrecv.h"
24
25
#include "notifymanager.h"
26
27
#include "being/playerinfo.h"
28
29
#include "const/net/inventory.h"
30
31
#include "enums/resources/notifytypes.h"
32
33
#include "gui/windows/buyselldialog.h"
34
#include "gui/windows/npcselldialog.h"
35
36
#include "gui/widgets/createwidget.h"
37
38
#include "net/messagein.h"
39
40
#include "resources/inventory/inventory.h"
41
42
#include "resources/item/item.h"
43
44
#include "debug.h"
45
46
namespace Ea
47
{
48
49
namespace BuySellRecv
50
{
51
    BeingId mNpcId = BeingId_zero;
52
    BuyDialog *mBuyDialog = nullptr;
53
}  // namespace BuySellRecv
54
55
void BuySellRecv::processNpcBuySellChoice(Net::MessageIn &msg)
56
{
57
    if (!BuySellDialog::isActive())
58
    {
59
        mNpcId = msg.readBeingId("npc id");
60
        CREATEWIDGET(BuySellDialog, mNpcId);
61
    }
62
}
63
64
void BuySellRecv::processNpcSell(Net::MessageIn &msg)
65
{
66
    msg.readInt16("len");
67
    const int n_items = (msg.getLength() - 4) / 10;
68
    if (n_items > 0)
69
    {
70
        SellDialog *const dialog = CREATEWIDGETR(NpcSellDialog, mNpcId);
71
        dialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY));
72
73
        for (int k = 0; k < n_items; k++)
74
        {
75
            const int index = msg.readInt16("index") - INVENTORY_OFFSET;
76
            const int value = msg.readInt32("value");
77
            msg.readInt32("value?");
78
79
            const Item *const item = PlayerInfo::getInventory()
80
                ->getItem(index);
81
82
            if ((item != nullptr) && item->isEquipped() == Equipped_false)
83
                dialog->addItem(item, value);
84
        }
85
    }
86
    else
87
    {
88
        NotifyManager::notify(NotifyTypes::SELL_LIST_EMPTY);
89
    }
90
}
91
92
}  // namespace Ea