Skip to content

Commit

Permalink
fix: bestiary race and stars monsterType to export in Game instead of…
Browse files Browse the repository at this point in the history
… MonsterType
  • Loading branch information
phacUFPE committed Jan 7, 2025
1 parent 03d578c commit 6e993db
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<BestiaryType_t>(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<MonsterType>(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<uint8_t>(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<MonsterType>(L, monsterType);
Lua::setMetatable(L, -1, "MonsterType");
lua_rawseti(L, -2, ++index);
}
return 1;
}
3 changes: 3 additions & 0 deletions src/lua/functions/core/game/game_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 6e993db

Please sign in to comment.