diff --git a/src/otclient/creatures.cpp b/src/otclient/creatures.cpp index 27c952cb..864b75bf 100644 --- a/src/otclient/creatures.cpp +++ b/src/otclient/creatures.cpp @@ -144,6 +144,7 @@ CreaturePtr CreatureType::cast() CreatureManager::CreatureManager() { m_nullCreature = CreatureTypePtr(new CreatureType); + m_nullSpawn = SpawnPtr(new Spawn); } void CreatureManager::clearSpawns() @@ -330,3 +331,20 @@ const CreatureTypePtr& CreatureManager::getCreatureByLook(int look) g_logger.warning(stdext::format("could not find creature with looktype: %d", look)); return m_nullCreature; } + +const SpawnPtr& CreatureManager::getSpawn(const Position& centerPos) +{ + // TODO instead of a list, a map could do better... + auto findFun = [=] (const SpawnPtr& sp) -> bool + { + const Position& center = sp->getCenterPos(); + return center == centerPos; + }; + auto it = std::find_if(m_spawns.begin(), m_spawns.end(), findFun); + if(it != m_spawns.end()) + return *it; + // Let it be debug so in release versions it shouldn't annoy the user + g_logger.debug(stdext::format("failed to find spawn at center %s",stdext::to_string(centerPos))); + return m_nullSpawn; +} + diff --git a/src/otclient/creatures.h b/src/otclient/creatures.h index 7f11e269..02ed7746 100644 --- a/src/otclient/creatures.h +++ b/src/otclient/creatures.h @@ -80,7 +80,7 @@ public: void setSpawnTime(int32 spawnTime) { m_attribs.set(CreatureAttrSpawnTime, spawnTime); } int32 getSpawnTime() { return m_attribs.get(CreatureAttrSpawnTime); } - void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); dump << "set"<(CreatureAttrName); } void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttrOutfit, o); } @@ -111,6 +111,7 @@ public: const CreatureTypePtr& getCreatureByName(std::string name); const CreatureTypePtr& getCreatureByLook(int look); + const SpawnPtr& getSpawn(const Position& centerPos); bool isLoaded() { return m_loaded; } bool isSpawnLoaded() { return m_spawnLoaded; } @@ -126,6 +127,7 @@ private: std::vector m_spawns; stdext::boolean m_loaded, m_spawnLoaded; CreatureTypePtr m_nullCreature; + SpawnPtr m_nullSpawn; }; extern CreatureManager g_creatures; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index a9d35aa4..cd295b2f 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -110,12 +110,14 @@ void OTClient::registerLuaFunctions() g_lua.bindSingletonFunction("g_map", "saveOtcm", &Map::saveOtcm, &g_map); g_lua.bindSingletonFunction("g_map", "getHouseFile", &Map::getHouseFile, &g_map); g_lua.bindSingletonFunction("g_map", "getSpawnFile", &Map::getSpawnFile, &g_map); + g_lua.bindSingletonFunction("g_map", "createTile", &Map::createTile, &g_map); g_lua.registerSingletonClass("g_creatures"); g_lua.bindSingletonFunction("g_creatures", "getCreatures", &CreatureManager::getCreatures, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "getSpawns", &CreatureManager::getSpawns, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "getCreatureByName", &CreatureManager::getCreatureByName, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "getCreatureByLook", &CreatureManager::getCreatureByLook, &g_creatures); + g_lua.bindSingletonFunction("g_creatures", "getSpawn", &CreatureManager::getSpawns, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "loadMonsters", &CreatureManager::loadMonsters, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "loadNpcs", &CreatureManager::loadNpcs, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "loadSingleCreature", &CreatureManager::loadSingleCreature, &g_creatures); @@ -376,6 +378,7 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &Item::create); + g_lua.bindClassStaticFunction("createOtb", &Item::createFromOtb); g_lua.bindClassMemberFunction("clone", &Item::clone); g_lua.bindClassMemberFunction("setCount", &Item::setCount); g_lua.bindClassMemberFunction("getCount", &Item::getCount); diff --git a/src/otclient/map.h b/src/otclient/map.h index 5f98cd47..8ac0bcdd 100644 --- a/src/otclient/map.h +++ b/src/otclient/map.h @@ -197,7 +197,6 @@ private: std::unordered_map m_tileBlocks[Otc::MAX_Z+1]; std::unordered_map m_knownCreatures; - std::unordered_map m_creatureTypes; std::array, Otc::MAX_Z+1> m_floorMissiles; std::vector m_animatedTexts; std::vector m_staticTexts;