Otclient  14/8/2020
thingtypemanager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef THINGTYPEMANAGER_H
24 #define THINGTYPEMANAGER_H
25 
26 #include <framework/global.h>
28 
29 #include "thingtype.h"
30 #include "itemtype.h"
31 
33 {
34 public:
35  void init();
36  void terminate();
37 
38  bool loadDat(std::string file);
39  bool loadOtml(std::string file);
40  void loadOtb(const std::string& file);
41  void loadXml(const std::string& file);
42  void parseItemType(uint16 id, TiXmlElement *elem);
43 
44  void saveDat(std::string fileName);
45 
46  void addItemType(const ItemTypePtr& itemType);
48  const ItemTypePtr& findItemTypeByName(std::string name);
49  ItemTypeList findItemTypesByName(std::string name);
50  ItemTypeList findItemTypesByString(std::string name);
51 
52  const ThingTypePtr& getNullThingType() { return m_nullThingType; }
53  const ItemTypePtr& getNullItemType() { return m_nullItemType; }
54 
55  const ThingTypePtr& getThingType(uint16 id, ThingCategory category);
56  const ItemTypePtr& getItemType(uint16 id);
57  ThingType* rawGetThingType(uint16 id, ThingCategory category) { return m_thingTypes[category][id].get(); }
58  ItemType* rawGetItemType(uint16 id) { return m_itemTypes[id].get(); }
59 
62 
63  const ThingTypeList& getThingTypes(ThingCategory category);
64  const ItemTypeList& getItemTypes() { return m_itemTypes; }
65 
66  uint32 getDatSignature() { return m_datSignature; }
67  uint32 getOtbMajorVersion() { return m_otbMajorVersion; }
68  uint32 getOtbMinorVersion() { return m_otbMinorVersion; }
69  uint16 getContentRevision() { return m_contentRevision; }
70 
71  bool isDatLoaded() { return m_datLoaded; }
72  bool isXmlLoaded() { return m_xmlLoaded; }
73  bool isOtbLoaded() { return m_otbLoaded; }
74 
75  bool isValidDatId(uint16 id, ThingCategory category) { return id >= 1 && id < m_thingTypes[category].size(); }
76  bool isValidOtbId(uint16 id) { return id >= 1 && id < m_itemTypes.size(); }
77 
78 private:
79  ThingTypeList m_thingTypes[ThingLastCategory];
80  ItemTypeList m_reverseItemTypes;
81  ItemTypeList m_itemTypes;
82 
83  ThingTypePtr m_nullThingType;
84  ItemTypePtr m_nullItemType;
85 
86  bool m_datLoaded;
87  bool m_xmlLoaded;
88  bool m_otbLoaded;
89 
90  uint32 m_otbMinorVersion;
91  uint32 m_otbMajorVersion;
92  uint32 m_datSignature;
93  uint16 m_contentRevision;
94 };
95 
97 
98 #endif
ItemTypeList
std::vector< ItemTypePtr > ItemTypeList
Definition: declarations.h:82
ThingTypeManager::rawGetThingType
ThingType * rawGetThingType(uint16 id, ThingCategory category)
Definition: thingtypemanager.h:57
ThingTypeManager::getDatSignature
uint32 getDatSignature()
Definition: thingtypemanager.h:66
ThingTypeManager::loadDat
bool loadDat(std::string file)
Definition: thingtypemanager.cpp:100
ThingTypeManager::findItemTypesByString
ItemTypeList findItemTypesByString(std::string name)
Definition: thingtypemanager.cpp:368
ThingTypeManager::findItemTypeByName
const ItemTypePtr & findItemTypeByName(std::string name)
Definition: thingtypemanager.cpp:351
ThingTypeManager::loadOtml
bool loadOtml(std::string file)
Definition: thingtypemanager.cpp:139
uint32
uint32_t uint32
Definition: types.h:35
ThingTypeManager::isDatLoaded
bool isDatLoaded()
Definition: thingtypemanager.h:71
ThingLastCategory
@ ThingLastCategory
Definition: thingtype.h:48
ThingTypeManager::getItemType
const ItemTypePtr & getItemType(uint16 id)
Definition: thingtypemanager.cpp:386
ThingTypeManager::isXmlLoaded
bool isXmlLoaded()
Definition: thingtypemanager.h:72
ThingTypeManager::getNullThingType
const ThingTypePtr & getNullThingType()
Definition: thingtypemanager.h:52
g_things
ThingTypeManager g_things
Definition: thingtypemanager.cpp:38
ThingTypeManager::getItemTypes
const ItemTypeList & getItemTypes()
Definition: thingtypemanager.h:64
ThingTypeManager::getThingTypes
const ThingTypeList & getThingTypes(ThingCategory category)
Definition: thingtypemanager.cpp:413
uint16
uint16_t uint16
Definition: types.h:36
ThingTypeManager::getContentRevision
uint16 getContentRevision()
Definition: thingtypemanager.h:69
ThingTypeManager::loadXml
void loadXml(const std::string &file)
Definition: thingtypemanager.cpp:225
declarations.h
ThingTypeManager::rawGetItemType
ItemType * rawGetItemType(uint16 id)
Definition: thingtypemanager.h:58
ThingTypeManager::isValidOtbId
bool isValidOtbId(uint16 id)
Definition: thingtypemanager.h:76
ItemCategory
ItemCategory
Definition: itemtype.h:31
ThingTypeManager::isOtbLoaded
bool isOtbLoaded()
Definition: thingtypemanager.h:73
ThingTypeManager::findItemTypeByClientId
const ItemTypePtr & findItemTypeByClientId(uint16 id)
Definition: thingtypemanager.cpp:340
ThingTypeManager::findItemTypeByCategory
ItemTypeList findItemTypeByCategory(ItemCategory category)
Definition: thingtypemanager.cpp:404
ThingTypeManager::getNullItemType
const ItemTypePtr & getNullItemType()
Definition: thingtypemanager.h:53
ThingTypeManager::getThingType
const ThingTypePtr & getThingType(uint16 id, ThingCategory category)
Definition: thingtypemanager.cpp:377
ItemType
Definition: itemtype.h:130
ThingTypeManager::init
void init()
Definition: thingtypemanager.cpp:40
ThingAttr
ThingAttr
Definition: thingtype.h:51
ThingTypeManager::getOtbMinorVersion
uint32 getOtbMinorVersion()
Definition: thingtypemanager.h:68
ThingType
Definition: thingtype.h:123
ThingTypeManager
Definition: thingtypemanager.h:32
ThingTypeManager::loadOtb
void loadOtb(const std::string &file)
Definition: thingtypemanager.cpp:174
stdext::shared_object_ptr< ItemType >
ThingTypeList
std::vector< ThingTypePtr > ThingTypeList
Definition: declarations.h:81
itemtype.h
ThingTypeManager::addItemType
void addItemType(const ItemTypePtr &itemType)
Definition: thingtypemanager.cpp:332
ThingTypeManager::getOtbMajorVersion
uint32 getOtbMajorVersion()
Definition: thingtypemanager.h:67
ThingTypeManager::parseItemType
void parseItemType(uint16 id, TiXmlElement *elem)
Definition: thingtypemanager.cpp:276
ThingTypeManager::findThingTypeByAttr
ThingTypeList findThingTypeByAttr(ThingAttr attr, ThingCategory category)
Definition: thingtypemanager.cpp:395
ThingCategory
ThingCategory
Definition: thingtype.h:42
TiXmlElement
Definition: tinyxml.h:943
ThingTypeManager::findItemTypesByName
ItemTypeList findItemTypesByName(std::string name)
Definition: thingtypemanager.cpp:359
thingtype.h
global.h
ThingTypeManager::terminate
void terminate()
Definition: thingtypemanager.cpp:56
ThingTypeManager::saveDat
void saveDat(std::string fileName)
Definition: thingtypemanager.cpp:66
ThingTypeManager::isValidDatId
bool isValidDatId(uint16 id, ThingCategory category)
Definition: thingtypemanager.h:75