Mana
Loading...
Searching...
No Matches
shopitems.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "shopitem.h"
25
26#include "utils/dtor.h"
27
28ShopItems::ShopItems(bool mergeDuplicates) :
29 mMergeDuplicates(mergeDuplicates)
30{
31}
32
37
39{
40 return mShopItems.size();
41}
42
43std::string ShopItems::getElementAt(int i)
44{
45 return mShopItems.at(i)->getDisplayName();
46}
47
48void ShopItems::addItem(int id, int amount, int price)
49{
50 mShopItems.push_back(new ShopItem(-1, id, amount, price));
51}
52
53void ShopItems::addItem(int inventoryIndex, int id, int quantity, int price)
54{
55 ShopItem *item = nullptr;
57 {
58 item = findItem(id);
59 }
60
61 if (item)
62 {
63 item->addDuplicate(inventoryIndex, quantity);
64 }
65 else
66 {
67 item = new ShopItem(inventoryIndex, id, quantity, price);
68 mShopItems.push_back(item);
69 }
70}
71
73{
74 return mShopItems.at(i);
75}
76
78{
79 mShopItems.erase(mShopItems.begin() + i);
80}
81
83{
85 mShopItems.clear();
86}
87
89{
90 for (auto shopItem : mShopItems)
91 {
92 if (shopItem->getId() == id)
93 {
94 return shopItem;
95 }
96 }
97
98 return nullptr;
99}
Represents an item in a shop inventory.
Definition shopitem.h:33
void addDuplicate(int inventoryIndex, int quantity)
Add a duplicate.
Definition shopitem.cpp:41
std::string getElementAt(int i) override
Returns the name of item number i in the shop.
Definition shopitems.cpp:43
bool mMergeDuplicates
Look for duplicate entries on addition.
Definition shopitems.h:111
ShopItems(bool mergeDuplicates=false)
Constructor.
Definition shopitems.cpp:28
void addItem(int id, int amount, int price)
Adds an item to the list.
Definition shopitems.cpp:48
ShopItem * at(int i) const
Returns the item number i in the shop.
Definition shopitems.cpp:72
int getNumberOfElements() override
Returns the number of items in the shop.
Definition shopitems.cpp:38
void erase(int i)
Removes an element from the shop.
Definition shopitems.cpp:77
std::vector< ShopItem * > mShopItems
The list of items in the shop.
Definition shopitems.h:108
ShopItem * findItem(int id)
Searches the current items in the shop for the specified id and returns the item if found,...
Definition shopitems.cpp:88
~ShopItems() override
Definition shopitems.cpp:33
void clear()
Clears the list of items in the shop.
Definition shopitems.cpp:82
void delete_all(Container &c)
Definition dtor.h:46