GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/buyingstoreselldialog.cpp Lines: 4 17 23.5 %
Date: 2017-11-29 Branches: 0 12 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 "gui/windows/buyingstoreselldialog.h"
24
25
#include "actormanager.h"
26
27
#include "being/playerinfo.h"
28
29
#include "gui/models/shopitems.h"
30
31
#include "gui/widgets/shoplistbox.h"
32
33
#include "net/buyingstorehandler.h"
34
35
#include "resources/inventory/inventory.h"
36
37
#include "resources/item/shopitem.h"
38
39
#include "debug.h"
40
41
2
BuyingStoreSellDialog::BuyingStoreSellDialog(const BeingId accountId,
42
2
                                             const int storeId) :
43
    SellDialog(IsSell_true, Advanced_false),
44
    mAccountId(accountId),
45
2
    mStoreId(storeId)
46
{
47
2
}
48
49
void BuyingStoreSellDialog::sellAction(const ActionEvent &event A_UNUSED)
50
{
51
    if (mAmountItems <= 0 || mAmountItems > mMaxItems)
52
        return;
53
54
    const int selectedItem = mShopItemList->getSelected();
55
    const ShopItem *const item1 = mShopItems->at(selectedItem);
56
    if ((item1 == nullptr) || PlayerInfo::isItemProtected(item1->getId()))
57
        return;
58
    const Being *const being = actorManager->findBeing(mAccountId);
59
    if (being == nullptr)
60
        return;
61
    const Item *const item2 = PlayerInfo::getInventory()->findItem(
62
        item1->getId(),
63
        item1->getColor());
64
    if (item2 == nullptr)
65
        return;
66
67
    mPlayerMoney += mAmountItems * item1->getPrice();
68
    mMaxItems -= mAmountItems;
69
    buyingStoreHandler->sell(being, mStoreId, item2, mAmountItems);
70
}