Skip to content

Commit

Permalink
remove redundant getExperienceForLevel implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed May 16, 2024
1 parent 481e9f9 commit f09580a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 1 addition & 5 deletions data/scripts/talkactions/god/add_skill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ local function getSkillId(skillName)
end
end

local function getExpForLevel(level)
return math.floor((((level - 6) * level + 17) * level - 12) / 6) * 100
end

local addSkill = TalkAction("/addskill")

function addSkill.onSay(player, words, param)
Expand Down Expand Up @@ -53,7 +49,7 @@ function addSkill.onSay(player, words, param)
local ch = split[2]:sub(1, 1)
if ch == "l" or ch == "e" then
targetLevel = target:getLevel() + count
targetExp = getExpForLevel(targetLevel)
targetExp = Game.getExperienceForLevel(targetLevel)
addExp = targetExp - target:getExperience()
target:addExperience(addExp, false)
elseif ch == "m" then
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
void addList() override;
void removePlayer(bool displayEffect, bool forced = true);

static uint64_t getExpForLevel(uint64_t lv) {
static uint64_t getExpForLevel(const uint64_t lv) {
return (((lv - 6ULL) * lv + 17ULL) * lv - 12ULL) / 6ULL * 100ULL;
}

Expand Down
11 changes: 11 additions & 0 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ int GameFunctions::luaGameloadMapChunk(lua_State* L) {
return 0;
}

int GameFunctions::luaGameGetExperienceForLevel(lua_State* L) {
// Game.getExperienceForLevel(level)
const uint32_t level = getNumber<uint32_t>(L, 1);
if (level == 0) {
lua_pushnumber(L, 0);
} else {
lua_pushnumber(L, Player::getExpForLevel(level));
}
return 1;
}

int GameFunctions::luaGameGetMonsterCount(lua_State* L) {
// Game.getMonsterCount()
lua_pushnumber(L, g_game().getMonstersOnline());
Expand Down
2 changes: 2 additions & 0 deletions src/lua/functions/core/game/game_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GameFunctions final : LuaScriptInterface {
registerMethod(L, "Game", "loadMap", GameFunctions::luaGameLoadMap);
registerMethod(L, "Game", "loadMapChunk", GameFunctions::luaGameloadMapChunk);

registerMethod(L, "Game", "getExperienceForLevel", GameFunctions::luaGameGetExperienceForLevel);
registerMethod(L, "Game", "getMonsterCount", GameFunctions::luaGameGetMonsterCount);
registerMethod(L, "Game", "getPlayerCount", GameFunctions::luaGameGetPlayerCount);
registerMethod(L, "Game", "getNpcCount", GameFunctions::luaGameGetNpcCount);
Expand Down Expand Up @@ -103,6 +104,7 @@ class GameFunctions final : LuaScriptInterface {
static int luaGameLoadMap(lua_State* L);
static int luaGameloadMapChunk(lua_State* L);

static int luaGameGetExperienceForLevel(lua_State* L);
static int luaGameGetMonsterCount(lua_State* L);
static int luaGameGetPlayerCount(lua_State* L);
static int luaGameGetNpcCount(lua_State* L);
Expand Down

0 comments on commit f09580a

Please sign in to comment.