diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 7e964ba9c83..98abe7a444e 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -110,6 +110,9 @@ void GameFunctions::init(lua_State* L) { Lua::registerMethod(L, "Game", "getAchievements", GameFunctions::luaGameGetAchievements); Lua::registerMethod(L, "Game", "getSoulCoreItems", GameFunctions::luaGameGetSoulCoreItems); + + Lua::registerMethod(L, "Game", "getMonstersByRace", GameFunctions::luaGameGetMonstersByRace); + Lua::registerMethod(L, "Game", "getMonstersByBestiaryStars", GameFunctions::luaGameGetMonstersByBestiaryStars); } // Game @@ -1055,3 +1058,33 @@ int GameFunctions::luaGameGetSoulCoreItems(lua_State* L) { return 1; } + +int GameFunctions::luaGameGetMonstersByRace(lua_State* L) { + // Game.getMonstersByRace(race) + const BestiaryType_t race = Lua::getNumber(L, 1); + const auto monstersByRace = g_monsters().getMonstersByRace(race); + + lua_createtable(L, monstersByRace.size(), 0); + int index = 0; + for (const auto &monsterType : monstersByRace) { + Lua::pushUserdata(L, monsterType); + Lua::setMetatable(L, -1, "MonsterType"); + lua_rawseti(L, -2, ++index); + } + return 1; +} + +int GameFunctions::luaGameGetMonstersByBestiaryStars(lua_State* L) { + // Game.getMonstersByBestiaryStars(stars) + const uint8_t stars = Lua::getNumber(L, 1); + const auto monstersByStars = g_monsters().getMonstersByBestiaryStars(stars); + + lua_createtable(L, monstersByStars.size(), 0); + int index = 0; + for (const auto &monsterType : monstersByStars) { + Lua::pushUserdata(L, monsterType); + Lua::setMetatable(L, -1, "MonsterType"); + lua_rawseti(L, -2, ++index); + } + return 1; +} diff --git a/src/lua/functions/core/game/game_functions.hpp b/src/lua/functions/core/game/game_functions.hpp index e70c7c0f6f1..b24b960368c 100644 --- a/src/lua/functions/core/game/game_functions.hpp +++ b/src/lua/functions/core/game/game_functions.hpp @@ -91,4 +91,7 @@ class GameFunctions { static int luaGameGetAchievements(lua_State* L); static int luaGameGetSoulCoreItems(lua_State* L); + + static int luaGameGetMonstersByRace(lua_State* L); + static int luaGameGetMonstersByBestiaryStars(lua_State* L); };