Mana
Loading...
Searching...
No Matches
item.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
22#include "item.h"
23
24#include "configuration.h"
25#include "event.h"
26
27#include "resources/iteminfo.h"
29#include "resources/theme.h"
30
31Item::Item(int id, int quantity, bool equipped):
32 mQuantity(quantity),
33 mEquipped(equipped)
34{
35 setId(id);
36}
37
38void Item::setId(int id)
39{
40 mId = id;
41
42 // Load the associated image
44 const SpriteDisplay &display = getInfo().display;
45 mImage = resman->getImage(paths.getStringValue("itemIcons") + display.image);
46
47 if (!mImage)
48 {
50 "unknown-item.png"));
51 }
52}
53
55{
56 Event event(eventName);
57 event.setItem("item", this);
58 event.trigger(Event::ItemChannel);
59}
60
61void Item::doEvent(Event::Type eventName, int amount)
62{
63 Event event(eventName);
64 event.setItem("item", this);
65 event.setInt("amount", amount);
66 event.trigger(Event::ItemChannel);
67}
68
70{
71 return getInfo().equippable;
72}
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
std::string getStringValue(const std::string &key) const
Definition event.h:42
Type
Definition event.h:61
@ ItemChannel
Definition event.h:53
SpriteDisplay display
Display info (like icon)
Definition iteminfo.h:114
bool equippable
Whether this item can be equipped.
Definition iteminfo.h:133
void doEvent(Event::Type eventType)
Definition item.cpp:54
int mId
Item type id.
Definition item.h:106
ResourceRef< Image > mImage
Item image.
Definition item.h:107
void setId(int id)
Sets the item id, identifying the item type.
Definition item.cpp:38
bool isEquippable() const
Returns whether this item is equippable.
Definition item.cpp:69
const ItemInfo & getInfo() const
Returns information about this item type.
Definition item.h:103
Item(int id=-1, int quantity=0, bool equipped=false)
Definition item.cpp:31
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
static ResourceRef< Image > getImageFromTheme(const std::string &path)
Definition theme.cpp:308
Configuration paths
XML default paths information reader.
Definition client.cpp:99
std::string image
Definition spritedef.h:43