Mana
Loading...
Searching...
No Matches
itemshortcut.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2007-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
22#include "itemshortcut.h"
23
24#include "configuration.h"
25#include "event.h"
26#include "inventory.h"
27#include "item.h"
28#include "playerinfo.h"
29
31
36
41
43{
44 for (int &item : mItems)
45 item = -1;
46
47 for (auto &shortcut : config.itemShortcuts)
48 {
49 if (shortcut.index >= 0 && shortcut.index < SHORTCUT_ITEMS)
50 mItems[shortcut.index] = shortcut.itemId;
51 }
52}
53
55{
56 config.itemShortcuts.clear();
57
58 for (int i = 0; i < SHORTCUT_ITEMS; i++)
59 {
60 if (mItems[i] >= 0)
61 config.itemShortcuts.push_back({ i, mItems[i] });
62 }
63}
64
65void ItemShortcut::useItem(int index)
66{
67 if (!mItems[index])
68 return;
69
71 if (item && item->getQuantity())
72 {
73 if (item->isEquippable())
74 {
75 if (item->isEquipped())
77 else
79 }
80 else
81 {
82 item->doEvent(Event::DoUse);
83 }
84 }
85}
@ DoUse
Definition event.h:79
@ DoEquip
Definition event.h:76
@ DoUnequip
Definition event.h:78
Item * findItem(int itemId) const
Searches for the specified item by it's id.
Definition inventory.cpp:52
The class which keeps track of the item shortcuts.
void useItem(int index)
Try to use the item specified by the index.
void load()
Load the configuration information.
int mItems[SHORTCUT_ITEMS]
The items stored.
void save()
Save the configuration information.
Represents one or more instances of a certain item type.
Definition item.h:35
void doEvent(Event::Type eventType)
Definition item.cpp:54
bool isEquipped() const
Returns whether this item is equipped.
Definition item.h:79
int getQuantity() const
Returns the number of items.
Definition item.h:69
bool isEquippable() const
Returns whether this item is equippable.
Definition item.cpp:69
Config config
Global settings (config.xml)
Definition client.cpp:97
ItemShortcut * itemShortcut
#define SHORTCUT_ITEMS
Inventory * getInventory()
Returns the player's inventory.
std::vector< ItemShortcutEntry > itemShortcuts