diff --git a/src/otclient/creatures.cpp b/src/otclient/creatures.cpp index f10214c9..e7276617 100644 --- a/src/otclient/creatures.cpp +++ b/src/otclient/creatures.cpp @@ -51,10 +51,10 @@ void Creatures::loadMonsters(const std::string& file) void Creatures::loadSingleCreature(const std::string& file) { - return loadCreatureBuffer(g_resources.loadFile(file)); + loadCreatureBuffer(g_resources.loadFile(file)); } -void Creatures::loadNpcs(const std::string &folder) +void Creatures::loadNpcs(const std::string& folder) { boost::filesystem::path npcPath(folder); if(!boost::filesystem::exists(npcPath)) @@ -77,14 +77,14 @@ void Creatures::loadCreatureBuffer(const std::string &buffer) stdext::throw_exception(stdext::format("cannot load creature buffer: %s", doc.ErrorDesc())); TiXmlElement* root = doc.FirstChildElement(); - if(!root || root->ValueStr() != "npc") + if(!root || (root->ValueStr() != "monster" && root->ValueStr() != "npc")) stdext::throw_exception("invalid root tag name"); + CreatureTypePtr newType(new CreatureType(stdext::trim(stdext::tolower(root->Attribute("name"))))); for(TiXmlElement* attrib = root->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) { - if(attrib->ValueStr() != "npc" && attrib->ValueStr() != "monster") - stdext::throw_exception(stdext::format("invalid attribute '%s'", attrib->ValueStr())); + if(attrib->ValueStr() != "look") + continue; - CreatureTypePtr newType(nullptr); if(m_loadCreatureBuffer(attrib, newType)) break; } @@ -92,26 +92,20 @@ void Creatures::loadCreatureBuffer(const std::string &buffer) doc.Clear(); } -bool Creatures::m_loadCreatureBuffer(TiXmlElement* attrib, CreatureTypePtr& m) +bool Creatures::m_loadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m) { - if(m || std::find(m_creatures.begin(), m_creatures.end(), m) != m_creatures.end()) + if(std::find(m_creatures.begin(), m_creatures.end(), m) != m_creatures.end()) return true; - m = CreatureTypePtr(new CreatureType(stdext::trim(stdext::tolower(attrib->Attribute("name"))))); Outfit out; - int32 type; - bool isTypeEx=false; if(!attrib->Attribute("type").empty()) type = attrib->readType("type"); - else { + else type = attrib->readType("typeex"); - isTypeEx = true; - } out.setId(type); - - if(!isTypeEx) { + { out.setHead(attrib->readType(("head"))); out.setBody(attrib->readType(("body"))); out.setLegs(attrib->readType(("legs"))); @@ -119,9 +113,9 @@ bool Creatures::m_loadCreatureBuffer(TiXmlElement* attrib, CreatureTypePtr& m) out.setAddons(attrib->readType(("addons"))); out.setMount(attrib->readType(("mount"))); } + m->setOutfit(out); m_creatures.push_back(m); - return type >= 0; } @@ -131,10 +125,3 @@ CreatureTypePtr Creatures::getCreature(const std::string& name) [=] (const CreatureTypePtr& m) -> bool { return m->getName() == stdext::trim(stdext::tolower(name)); }); return it != m_creatures.end() ? *it : nullptr; } - -CreatureTypePtr Creatures::getCreature(const Position& pos) -{ - auto it = std::find_if(m_creatures.begin(), m_creatures.end(), - [=] (const CreatureTypePtr& m) -> bool { return m->getPos() == pos; }); - return it != m_creatures.end() ? *it : nullptr; -} diff --git a/src/otclient/creatures.h b/src/otclient/creatures.h index bf0e8189..65af229d 100644 --- a/src/otclient/creatures.h +++ b/src/otclient/creatures.h @@ -42,13 +42,11 @@ public: CreatureType() { } CreatureType(const std::string& name) { setName(name); } - void setPos(const Position& pos) { m_attribs.set(CreatureAttrPosition, pos); } void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); } void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttrOutfit, o); } void setSpawnTime(int spawnTime) { m_attribs.set(CreatureAttrSpawnTime, spawnTime); } std::string getName() { return m_attribs.get(CreatureAttrName); } - Position getPos() { return m_attribs.get(CreatureAttrPosition); } Outfit getOutfit() { return m_attribs.get(CreatureAttrOutfit); } int getSpawnTime() { return m_attribs.get(CreatureAttrSpawnTime); } @@ -67,12 +65,10 @@ public: void loadCreatureBuffer(const std::string& buffer); CreatureTypePtr getCreature(const std::string& name); - CreatureTypePtr getCreature(const Position& pos); - bool isLoaded() const { return m_loaded; } protected: - bool m_loadCreatureBuffer(TiXmlElement* elem, CreatureTypePtr& m); + bool m_loadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m); private: std::vector m_creatures; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index cfcc0471..03f897e1 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -305,11 +305,9 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return CreatureTypePtr(new CreatureType); }); - g_lua.bindClassMemberFunction("setPos", &CreatureType::setPos); g_lua.bindClassMemberFunction("setName", &CreatureType::setName); g_lua.bindClassMemberFunction("setOutfit", &CreatureType::setOutfit); g_lua.bindClassMemberFunction("setSpawnTime", &CreatureType::setSpawnTime); - g_lua.bindClassMemberFunction("getPos", &CreatureType::getPos); g_lua.bindClassMemberFunction("getName", &CreatureType::getName); g_lua.bindClassMemberFunction("getOutfit", &CreatureType::getOutfit); g_lua.bindClassMemberFunction("getSpawnTime", &CreatureType::getSpawnTime); diff --git a/src/otclient/map.cpp b/src/otclient/map.cpp index 8d1daa94..5698f3b0 100644 --- a/src/otclient/map.cpp +++ b/src/otclient/map.cpp @@ -403,22 +403,26 @@ void Map::loadSpawns(const std::string &fileName) if(!root || root->ValueStr() != "spawns") stdext::throw_exception("malformed spawns file"); + CreatureTypePtr cType(nullptr); for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) { if(node->ValueTStr() != "spawn") stdext::throw_exception("invalid spawn node"); Position centerPos = node->readPos("center"); - for(TiXmlElement* mType = node->FirstChildElement(); mType; mType = mType->NextSiblingElement()) { - if(mType->ValueStr() != "monster" && mType->ValueStr() != "npc") - stdext::throw_exception(stdext::format("invalid spawn-subnode %s", mType->ValueStr())); + for(TiXmlElement* cNode = node->FirstChildElement(); cNode; cNode = cNode->NextSiblingElement()) { + if(cNode->ValueStr() != "monster" && cNode->ValueStr() != "npc") + stdext::throw_exception(stdext::format("invalid spawn-subnode %s", cNode->ValueStr())); - std::string mName = mType->Attribute("name"); - CreatureTypePtr m = getCreature(mName); - if (!m) - stdext::throw_exception(stdext::format("unkown monster '%s'", stdext::trim(stdext::tolower(mName)))); + std::string cName = stdext::trim(stdext::tolower(cNode->Attribute("name"))); + if (!(cType = m_creatures.getCreature(cName))) + continue; - m->setPos(centerPos + mType->readPoint()); - m->setSpawnTime(mType->readType("spawntime")); + cType->setSpawnTime(cNode->readType("spawntime")); + CreaturePtr creature(new Creature); + creature->setOutfit(cType->getOutfit()); + creature->setName(cType->getName()); + + addThing(creature, centerPos + cNode->readPoint()); } } diff --git a/src/otclient/map.h b/src/otclient/map.h index 10b2cd7a..5cde3ba6 100644 --- a/src/otclient/map.h +++ b/src/otclient/map.h @@ -83,6 +83,52 @@ enum OTBM_NodeTypes_t OTBM_WAYPOINT = 16 }; +enum clientVersion_t +{ + CLIENT_VERSION_750 = 1, + CLIENT_VERSION_755 = 2, + CLIENT_VERSION_760 = 3, + CLIENT_VERSION_770 = 3, + CLIENT_VERSION_780 = 4, + CLIENT_VERSION_790 = 5, + CLIENT_VERSION_792 = 6, + CLIENT_VERSION_800 = 7, + CLIENT_VERSION_810 = 8, + CLIENT_VERSION_811 = 9, + CLIENT_VERSION_820 = 10, + CLIENT_VERSION_830 = 11, + CLIENT_VERSION_840 = 12, + CLIENT_VERSION_841 = 13, + CLIENT_VERSION_842 = 14, + CLIENT_VERSION_850 = 15, + CLIENT_VERSION_854_OLD = 16, + CLIENT_VERSION_854 = 17, + CLIENT_VERSION_855 = 18, + CLIENT_VERSION_860_OLD = 19, + CLIENT_VERSION_860 = 20, + CLIENT_VERSION_861 = 21, + CLIENT_VERSION_862 = 22, + CLIENT_VERSION_870 = 23, + CLIENT_VERSION_871 = 24, + CLIENT_VERSION_872 = 25, + CLIENT_VERSION_873 = 26, + CLIENT_VERSION_900 = 27, + CLIENT_VERSION_910 = 28, + CLIENT_VERSION_920 = 29, + CLIENT_VERSION_940 = 30, + CLIENT_VERSION_944_V1 = 31, + CLIENT_VERSION_944_V2 = 32, + CLIENT_VERSION_944_V3 = 33, + CLIENT_VERSION_944_V4 = 34, + CLIENT_VERSION_946 = 35, + CLIENT_VERSION_950 = 36, + CLIENT_VERSION_952 = 37, + CLIENT_VERSION_953 = 38, + CLIENT_VERSION_954 = 39, + CLIENT_VERSION_960 = 40 +}; + + enum { OTCM_SIGNATURE = 0x4D43544F, OTCM_VERSION = 1