2012-06-21 19:54:20 +02:00
|
|
|
/*
|
2017-01-13 11:47:07 +01:00
|
|
|
* Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
|
2012-06-21 19:54:20 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef THINGTYPEMANAGER_H
|
|
|
|
#define THINGTYPEMANAGER_H
|
|
|
|
|
|
|
|
#include <framework/global.h>
|
|
|
|
#include <framework/core/declarations.h>
|
|
|
|
|
2012-07-19 23:22:52 +02:00
|
|
|
#include "thingtype.h"
|
|
|
|
#include "itemtype.h"
|
2012-06-21 19:54:20 +02:00
|
|
|
|
|
|
|
class ThingTypeManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void init();
|
|
|
|
void terminate();
|
|
|
|
|
2013-01-09 20:29:58 +01:00
|
|
|
bool loadDat(std::string file);
|
|
|
|
bool loadOtml(std::string file);
|
2012-07-15 01:20:38 +02:00
|
|
|
void loadOtb(const std::string& file);
|
|
|
|
void loadXml(const std::string& file);
|
2012-07-18 13:46:58 +02:00
|
|
|
void parseItemType(uint16 id, TiXmlElement *elem);
|
2012-06-21 19:54:20 +02:00
|
|
|
|
2014-01-21 11:10:02 +01:00
|
|
|
void saveDat(std::string fileName);
|
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
void addItemType(const ItemTypePtr& itemType);
|
2012-07-30 17:08:21 +02:00
|
|
|
const ItemTypePtr& findItemTypeByClientId(uint16 id);
|
2013-08-17 15:09:10 +02:00
|
|
|
const ItemTypePtr& findItemTypeByName(std::string name);
|
2013-08-29 19:53:21 +02:00
|
|
|
ItemTypeList findItemTypesByName(std::string name);
|
|
|
|
ItemTypeList findItemTypesByString(std::string str);
|
2012-06-21 19:54:20 +02:00
|
|
|
|
2012-07-19 23:22:52 +02:00
|
|
|
const ThingTypePtr& getNullThingType() { return m_nullThingType; }
|
|
|
|
const ItemTypePtr& getNullItemType() { return m_nullItemType; }
|
2012-06-21 19:54:20 +02:00
|
|
|
|
2012-07-20 07:45:11 +02:00
|
|
|
const ThingTypePtr& getThingType(uint16 id, ThingCategory category);
|
2012-07-19 23:22:52 +02:00
|
|
|
const ItemTypePtr& getItemType(uint16 id);
|
2012-07-20 07:45:11 +02:00
|
|
|
ThingType* rawGetThingType(uint16 id, ThingCategory category) { return m_thingTypes[category][id].get(); }
|
|
|
|
ItemType* rawGetItemType(uint16 id) { return m_itemTypes[id].get(); }
|
|
|
|
|
|
|
|
ThingTypeList findThingTypeByAttr(ThingAttr attr, ThingCategory category);
|
|
|
|
ItemTypeList findItemTypeByCategory(ItemCategory category);
|
|
|
|
|
|
|
|
const ThingTypeList& getThingTypes(ThingCategory category);
|
|
|
|
const ItemTypeList& getItemTypes() { return m_itemTypes; }
|
2012-06-21 19:54:20 +02:00
|
|
|
|
|
|
|
uint32 getDatSignature() { return m_datSignature; }
|
|
|
|
uint32 getOtbMajorVersion() { return m_otbMajorVersion; }
|
|
|
|
uint32 getOtbMinorVersion() { return m_otbMinorVersion; }
|
2014-12-29 18:08:13 +01:00
|
|
|
uint16 getContentRevision() { return m_contentRevision; }
|
2012-06-21 19:54:20 +02:00
|
|
|
|
|
|
|
bool isDatLoaded() { return m_datLoaded; }
|
|
|
|
bool isXmlLoaded() { return m_xmlLoaded; }
|
|
|
|
bool isOtbLoaded() { return m_otbLoaded; }
|
|
|
|
|
2012-07-20 07:45:11 +02:00
|
|
|
bool isValidDatId(uint16 id, ThingCategory category) { return id >= 1 && id < m_thingTypes[category].size(); }
|
|
|
|
bool isValidOtbId(uint16 id) { return id >= 1 && id < m_itemTypes.size(); }
|
2012-06-21 19:54:20 +02:00
|
|
|
|
|
|
|
private:
|
2012-07-20 07:45:11 +02:00
|
|
|
ThingTypeList m_thingTypes[ThingLastCategory];
|
2012-08-19 23:49:24 +02:00
|
|
|
ItemTypeList m_reverseItemTypes;
|
2012-07-20 07:45:11 +02:00
|
|
|
ItemTypeList m_itemTypes;
|
2012-06-21 19:54:20 +02:00
|
|
|
|
2012-07-19 23:22:52 +02:00
|
|
|
ThingTypePtr m_nullThingType;
|
|
|
|
ItemTypePtr m_nullItemType;
|
2012-06-21 19:54:20 +02:00
|
|
|
|
|
|
|
bool m_datLoaded;
|
|
|
|
bool m_xmlLoaded;
|
|
|
|
bool m_otbLoaded;
|
|
|
|
|
|
|
|
uint32 m_otbMinorVersion;
|
|
|
|
uint32 m_otbMajorVersion;
|
|
|
|
uint32 m_datSignature;
|
2014-12-29 18:08:13 +01:00
|
|
|
uint16 m_contentRevision;
|
2012-06-21 19:54:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern ThingTypeManager g_things;
|
|
|
|
|
|
|
|
#endif
|