Mana
Loading...
Searching...
No Matches
item.h
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#pragma once
23
24#include "event.h"
25
26#include "resources/image.h"
27#include "resources/itemdb.h"
28
29const int ITEM_ICON_SIZE = 32;
30
34class Item
35{
36 public:
37 Item(int id = -1, int quantity = 0, bool equipped = false);
38
39 virtual ~Item() = default;
40
44 void setId(int id);
45
49 int getId() const { return mId; }
50
54 Image *getImage() const { return mImage; }
55
59 void setQuantity(int quantity) { mQuantity = quantity; }
60
64 void increaseQuantity(int amount) { mQuantity += amount; }
65
69 int getQuantity() const { return mQuantity; }
70
74 void setEquipped(bool equipped) { mEquipped = equipped; }
75
79 bool isEquipped() const { return mEquipped; }
80
84 bool isEquippable() const;
85
89 void setInvIndex(int index) { mInvIndex = index; }
90
94 int getInvIndex() const { return mInvIndex; }
95
96 void doEvent(Event::Type eventType);
97
98 void doEvent(Event::Type eventType, int amount);
99
103 const ItemInfo &getInfo() const { return itemDb->get(mId); }
104
105 protected:
106 int mId;
111};
Type
Definition event.h:61
Defines a class for loading and storing images.
Definition image.h:45
const ItemInfo & get(int id) const
Definition itemdb.cpp:145
Defines a class for storing generic item infos.
Definition iteminfo.h:100
Represents one or more instances of a certain item type.
Definition item.h:35
void setQuantity(int quantity)
Sets the number of items.
Definition item.h:59
int mQuantity
Number of items.
Definition item.h:108
bool mEquipped
Item is equipped.
Definition item.h:109
int mInvIndex
Inventory index.
Definition item.h:110
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
int getInvIndex() const
Returns the inventory index of this item.
Definition item.h:94
int mId
Item type id.
Definition item.h:106
void increaseQuantity(int amount)
Increases the number of items by the given amount.
Definition item.h:64
void setEquipped(bool equipped)
Sets whether this item is equipped.
Definition item.h:74
ResourceRef< Image > mImage
Item image.
Definition item.h:107
int getId() const
Returns the item id.
Definition item.h:49
Image * getImage() const
Returns the item image.
Definition item.h:54
void setId(int id)
Sets the item id, identifying the item type.
Definition item.cpp:38
void setInvIndex(int index)
Sets the inventory index of this item.
Definition item.h:89
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
virtual ~Item()=default
Automatically counting Resource reference.
Definition resource.h:74
ItemDB * itemDb
Items info database.
Definition client.cpp:106
const int ITEM_ICON_SIZE
Definition item.h:29