Mana
Loading...
Searching...
No Matches
itemdb.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 <list>
25#include <map>
26#include <string>
27
28#include "utils/xml.h"
29
30#define ITEMS_DB_FILE "items.xml"
31
32class ItemInfo;
33class SpriteDisplay;
34
35namespace TmwAthena {
36class TaItemDB;
37}
38
39namespace ManaServ {
40class ManaServItemDB;
41}
42
47{
48 friend class ItemDB;
49 friend class TmwAthena::TaItemDB;
51
52 public:
53 ItemStat(const std::string &tag,
54 const std::string &format):
55 mTag(tag), mFormat(format) {}
56
57 bool operator ==(const std::string &name) const
58 { return mTag == name; }
59
60 private:
61 std::string mTag;
62 std::string mFormat;
63};
64
65// Used to set nano-description
66static std::list<ItemStat> extraStats;
67void setStatsList(std::list<ItemStat> stats);
68
72class ItemDB
73{
74 public:
75 ItemDB() = default;
76 virtual ~ItemDB() = default;
77
81 virtual void unload();
82
86 bool isLoaded() const
87 { return mLoaded; }
88
89 bool exists(int id) const;
90
91 const ItemInfo &get(int id) const;
92 const ItemInfo &get(const std::string &name) const;
93
94 virtual void init() = 0;
95
96 virtual void readItemNode(XML::Node node, const std::string &filename) = 0;
97
98 virtual void checkStatus() = 0;
99
100 protected:
105 void loadCommonRef(ItemInfo &itemInfo, XML::Node node, const std::string &filename);
106
110 virtual void checkItemInfo(ItemInfo &itemInfo);
111
115 void addItem(ItemInfo *itemInfo);
116
121
122 // Default unknown reference
123 ItemInfo *mUnknown = nullptr;
124
125 bool mLoaded = false;
126
127 private:
131 void loadSpriteRef(ItemInfo &itemInfo, XML::Node node);
132
136 void loadSoundRef(ItemInfo &itemInfo, XML::Node node);
137
141 void loadFloorSprite(SpriteDisplay &display, XML::Node node);
142
146 void loadReplacement(ItemInfo &info, XML::Node replaceNode);
147
148 // Items database
149 std::map<int, ItemInfo *> mItemInfos;
150 std::map<std::string, ItemInfo *> mNamedItemInfos;
151};
152
153namespace TmwAthena {
154
158class TaItemDB : public ItemDB
159{
160 public:
161 TaItemDB() = default;
162
163 ~TaItemDB() override
164 { unload(); }
165
166 void init() override;
167
168 void readItemNode(XML::Node node, const std::string &filename) override;
169
170 void checkStatus() override;
171
172 private:
179
180 void checkItemInfo(ItemInfo &itemInfo) override;
181};
182
183} // namespace TmwAthena
184
185namespace ManaServ {
186
190class ManaServItemDB : public ItemDB
191{
192 public:
193 ManaServItemDB() = default;
194
196 { unload(); }
197
198 void init() override;
199
200 void readItemNode(XML::Node node, const std::string &filename) override;
201
202 void checkStatus() override;
203
204 private:
205 void checkItemInfo(ItemInfo &itemInfo) override;
206};
207
208} // namespace ManaServ
209
210extern ItemDB *itemDb;
Item information database generic definition.
Definition itemdb.h:73
void addItem(ItemInfo *itemInfo)
Registers the item to mItemInfos and mNamedItemsInfos.
Definition itemdb.cpp:337
virtual void checkStatus()=0
bool isLoaded() const
Tells whether the item database is loaded.
Definition itemdb.h:86
virtual void readItemNode(XML::Node node, const std::string &filename)=0
virtual void init()=0
void loadSoundRef(ItemInfo &itemInfo, XML::Node node)
Loads the sound references contained in a <sound> tag.
Definition itemdb.cpp:191
virtual void unload()
Frees item data.
Definition itemdb.cpp:268
ItemDB()=default
std::map< std::string, ItemInfo * > mNamedItemInfos
Definition itemdb.h:150
void loadReplacement(ItemInfo &info, XML::Node replaceNode)
Loads the <replace> tag.
Definition itemdb.cpp:228
void loadCommonRef(ItemInfo &itemInfo, XML::Node node, const std::string &filename)
Permits to load item definitions which are common for each protocols to avoid code duplication.
Definition itemdb.cpp:281
bool exists(int id) const
Definition itemdb.cpp:138
virtual ~ItemDB()=default
std::map< int, ItemInfo * > mItemInfos
Definition itemdb.h:149
void loadSpriteRef(ItemInfo &itemInfo, XML::Node node)
Loads the sprite references contained in a <sprite> tag.
Definition itemdb.cpp:177
const ItemInfo & get(int id) const
Definition itemdb.cpp:145
void loadFloorSprite(SpriteDisplay &display, XML::Node node)
Loads the floor item references contained in a <floor> tag.
Definition itemdb.cpp:211
ItemInfo * mUnknown
Definition itemdb.h:123
void loadEmptyItemDefinition()
Loads the empty item definition.
Definition itemdb.cpp:122
virtual void checkItemInfo(ItemInfo &itemInfo)
Checks the items parameters consistency.
Definition itemdb.cpp:367
bool mLoaded
Definition itemdb.h:125
Defines a class for storing generic item infos.
Definition iteminfo.h:100
Nano-description functions.
Definition itemdb.h:47
ItemStat(const std::string &tag, const std::string &format)
Definition itemdb.h:53
bool operator==(const std::string &name) const
Definition itemdb.h:57
std::string mTag
Definition itemdb.h:61
std::string mFormat
Definition itemdb.h:62
Item information database TmwAthena specific class.
Definition itemdb.h:191
void readItemNode(XML::Node node, const std::string &filename) override
Definition itemdb.cpp:471
void init() override
Definition itemdb.cpp:465
~ManaServItemDB() override
Definition itemdb.h:195
void checkStatus() override
Definition itemdb.cpp:578
void checkItemInfo(ItemInfo &itemInfo) override
Checks the items parameters consistency.
Definition itemdb.cpp:586
Item information database TmwAthena specific class.
Definition itemdb.h:159
~TaItemDB() override
Definition itemdb.h:163
void init() override
Definition itemdb.cpp:395
void checkStatus() override
Definition itemdb.cpp:443
void readItemNode(XML::Node node, const std::string &filename) override
Definition itemdb.cpp:401
void checkHairWeaponsRacesSpecialIds()
Check items id specific hard limits and log errors found.
Definition itemdb.h:177
void checkItemInfo(ItemInfo &itemInfo) override
Checks the items parameters consistency.
Definition itemdb.cpp:453
void setStatsList(std::list< ItemStat > stats)
Definition itemdb.cpp:40
ItemDB * itemDb
Items info database.
Definition client.cpp:106
Warning: buffers and other variables are shared, so there can be only one connection active at a time...