GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/item/item.h Lines: 3 30 10.0 %
Date: 2021-03-17 Branches: 0 26 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-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef RESOURCES_ITEM_ITEM_H
25
#define RESOURCES_ITEM_ITEM_H
26
27
#include "const/resources/item/cards.h"
28
29
#include "enums/resources/item/itemtype.h"
30
31
#include "enums/simpletypes/damaged.h"
32
#include "enums/simpletypes/equipm.h"
33
#include "enums/simpletypes/equipped.h"
34
#include "enums/simpletypes/favorite.h"
35
#include "enums/simpletypes/identified.h"
36
#include "enums/simpletypes/itemcolor.h"
37
38
#include "resources/db/itemdb.h"
39
40
#include "localconsts.h"
41
42
class Image;
43
44
struct ItemOptionsList;
45
46
/**
47
 * Represents one or more instances of a certain item type.
48
 */
49
class Item notfinal
50
{
51
    public:
52
        /**
53
         * Constructor.
54
         */
55
        Item(const int id,
56
             const ItemTypeT type,
57
             const int quantity,
58
             const uint8_t refine,
59
             const ItemColor color,
60
             const Identified identified,
61
             const Damaged damaged,
62
             const Favorite favorite,
63
             const Equipm equipment,
64
             const Equipped equipped);
65
66
        A_DELETE_COPY(Item)
67
68
        /**
69
         * Destructor.
70
         */
71
        virtual ~Item();
72
73
        /**
74
         * Sets the item id, color the item type.
75
         */
76
        void setId(const int id, const ItemColor color);
77
78
        /**
79
         * Returns the item id.
80
         */
81
        int getId() const noexcept2 A_WARN_UNUSED
82
        { return mId; }
83
84
        /**
85
         * Returns the item image.
86
         */
87
        Image *getImage() const noexcept2 A_WARN_UNUSED
88
1
        { return mImage; }
89
90
        /**
91
         * Sets the number of items.
92
         */
93
        void setQuantity(const int quantity) noexcept2
94
        { mQuantity = quantity; }
95
96
        /**
97
         * Increases the number of items by the given amount.
98
         */
99
        void increaseQuantity(const int amount) noexcept2
100
        { mQuantity += amount; }
101
102
        /**
103
         * Returns the number of items.
104
         */
105
        int getQuantity() const noexcept2 A_WARN_UNUSED
106
1
        { return mQuantity; }
107
108
        /**
109
         * Sets whether this item is considered equipment.
110
         */
111
        void setEquipment(const Equipm equipment) noexcept2
112
        { mEquipment = equipment; }
113
114
        /**
115
         * Returns whether this item is considered equipment.
116
         */
117
        Equipm isEquipment() const noexcept2 A_WARN_UNUSED
118
        { return mEquipment; }
119
120
        /**
121
         * Sets whether this item is equipped.
122
         */
123
        void setEquipped(const Equipped equipped) noexcept2
124
        { mEquipped = equipped; }
125
126
        /**
127
         * Returns whether this item is equipped.
128
         */
129
        Equipped isEquipped() const noexcept2 A_WARN_UNUSED
130
        { return mEquipped; }
131
132
        /**
133
         * Sets this item refine level.
134
         */
135
        void setRefine(const uint8_t refine) noexcept2
136
        { mRefine = refine; }
137
138
        /**
139
         * Returns this item refine level.
140
         */
141
        uint8_t getRefine() const noexcept2 A_WARN_UNUSED
142
        { return mRefine; }
143
144
        /**
145
         * Sets whether this item is in equipment.
146
         */
147
        void setInEquipment(const bool inEquipment) noexcept2
148
        { mInEquipment = inEquipment; }
149
150
        /**
151
         * Returns whether this item is in equipment.
152
         */
153
        bool isInEquipment() const noexcept2 A_WARN_UNUSED
154
        { return mInEquipment; }
155
156
        /**
157
         * Sets the inventory index of this item.
158
         */
159
        void setInvIndex(const int index) noexcept2
160
        { mInvIndex = index; }
161
162
        /**
163
         * Returns the inventory index of this item.
164
         */
165
        int getInvIndex() const noexcept2 A_WARN_UNUSED
166
        { return mInvIndex; }
167
168
        /**
169
         * Returns information about this item type.
170
         */
171
        const ItemInfo &getInfo() const A_WARN_UNUSED
172




4
        { return ItemDB::get(mId); }
173
174
        std::string getName() const A_WARN_UNUSED;
175
176
        static Image *getImage(const int id,
177
                               const ItemColor color) A_WARN_UNUSED;
178
179
        bool isHaveTag(const int tagId) const A_WARN_UNUSED;
180
181
        ItemColor getColor() const noexcept2 A_WARN_UNUSED
182
        { return mColor; }
183
184
        void setColor(const ItemColor color) noexcept2
185
        { mColor = color; }
186
187
        const std::string &getDescription() const noexcept2 A_WARN_UNUSED
188
        { return mDescription; }
189
190
        void setIdentified(const Identified b) noexcept2
191
        { mIdentified = b; }
192
193
        Identified getIdentified() const noexcept2 A_WARN_UNUSED
194
        { return mIdentified; }
195
196
        void setDamaged(const Damaged b) noexcept2
197
        { mDamaged = b; }
198
199
        Damaged getDamaged() const noexcept2 A_WARN_UNUSED
200
        { return mDamaged; }
201
202
        void setFavorite(const Favorite b) noexcept2
203
        { mFavorite = b; }
204
205
        Favorite getFavorite() const noexcept2 A_WARN_UNUSED
206
        { return mFavorite; }
207
208
        void setCard(const int index, const int id);
209
210
        int getCard(const int index) const;
211
212
        void setCards(const int *const cards, const int size);
213
214
        const int *getCards() const noexcept2 A_WARN_UNUSED
215
        { return mCards; }
216
217
        void setOptions(const ItemOptionsList *const options);
218
219
        const ItemOptionsList *getOptions() const noexcept2 A_WARN_UNUSED
220
        { return mOptions; }
221
222
        void setType(const ItemTypeT type) noexcept2
223
        { mType = type; }
224
225
        ItemTypeT getType() const noexcept2 A_WARN_UNUSED
226
        { return mType; }
227
228
        void setTag(const int tag) noexcept2
229
        { mTag = tag; }
230
231
        int getTag() const noexcept2 A_WARN_UNUSED
232
        { return mTag; }
233
234
        void addCard(const int card);
235
236
        void updateColor();
237
238
        static constexpr bool isItem(const int id) noexcept2 A_WARN_UNUSED
239
        {
240
            return id != 0 &&
241
                id != CARD0_FORGE &&
242
                id != CARD0_CREATE &&
243
                id != CARD0_PET;
244
        }
245
246
        int mId;              /**< Item id. */
247
        ItemColor mColor;
248
        int mQuantity;        /**< Number of items. */
249
        int mTag;
250
251
    protected:
252
        Image *mImage;        /**< Item image. */
253
        std::string mDescription;
254
        std::map <int, int> mTags;
255
        int mCards[maxCards];
256
        const ItemOptionsList *mOptions;
257
        uint8_t mRefine;      /**< Item refine level. */
258
        int mInvIndex;        /**< Inventory index. */
259
        ItemTypeT mType;      /**< Item type. */
260
        Equipm mEquipment;    /**< Item is equipment. */
261
        Equipped mEquipped;   /**< Item is equipped. */
262
        bool mInEquipment;    /**< Item is in equipment */
263
        Identified mIdentified;
264
        Damaged mDamaged;
265
        Favorite mFavorite;
266
};
267
268
#endif  // RESOURCES_ITEM_ITEM_H