From b14748b6aaca1311f51ceaa42d49837bf45776ac Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Tue, 25 Feb 2020 01:05:55 +0200 Subject: [PATCH] Add new bindings: getJobLevel & hasJob (#386) * Add getJobLevel() binding * Add hasJob binding --- src/map/lua/lua_baseentity.cpp | 48 ++++++++++++++++++++++++++++++++++ src/map/lua/lua_baseentity.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/src/map/lua/lua_baseentity.cpp b/src/map/lua/lua_baseentity.cpp index afe5889091a..4b367beea5c 100644 --- a/src/map/lua/lua_baseentity.cpp +++ b/src/map/lua/lua_baseentity.cpp @@ -5339,6 +5339,29 @@ inline int32 CLuaBaseEntity::unlockJob(lua_State *L) return 0; } +/************************************************************************ +* Function: hasJob() +* Purpose : Check to see if JOBTYPE is unlocked +* Example : player:hasJob(BRD) +* Notes : +************************************************************************/ + +inline int32 CLuaBaseEntity::hasJob(lua_State *L) +{ + TPZ_DEBUG_BREAK_IF(m_PBaseEntity == nullptr); + TPZ_DEBUG_BREAK_IF(m_PBaseEntity->objtype != TYPE_PC); + TPZ_DEBUG_BREAK_IF(lua_isnil(L, 1) || !lua_isnumber(L, 1)); + + JOBTYPE JobID = (JOBTYPE)lua_tointeger(L, 1); + + TPZ_DEBUG_BREAK_IF(JobID > MAX_JOBTYPE || JobID < 0); + + CCharEntity* PChar = (CCharEntity*)m_PBaseEntity; + + lua_pushinteger(L, (PChar->jobs.unlocked >> JobID) & 1); + return 1; +} + /************************************************************************ * Function: getMainLvl() * Purpose : Returns the main level of entity's current job @@ -5371,6 +5394,29 @@ inline int32 CLuaBaseEntity::getSubLvl(lua_State *L) return 1; } +/************************************************************************ +* Function: getJobLevel() +* Purpose : Return the levle of job specified by JOBTYPE +* Example : player:getJobLevel(BRD) +* Notes : +************************************************************************/ + +inline int32 CLuaBaseEntity::getJobLevel(lua_State *L) +{ + TPZ_DEBUG_BREAK_IF(m_PBaseEntity == nullptr); + TPZ_DEBUG_BREAK_IF(m_PBaseEntity->objtype != TYPE_PC); + TPZ_DEBUG_BREAK_IF(lua_isnil(L, 1) || !lua_isnumber(L, 1)); + + JOBTYPE JobID = (JOBTYPE)lua_tointeger(L, 1); + + TPZ_DEBUG_BREAK_IF(JobID > MAX_JOBTYPE || JobID < 0); + + CCharEntity* PChar = (CCharEntity*)m_PBaseEntity; + lua_pushinteger(L, PChar->jobs.job[JobID]); + + return 1; +} + /************************************************************************ * Function: setLevel() * Purpose : Updates the level of the entity's main job @@ -14202,9 +14248,11 @@ Lunar::Register_t CLuaBaseEntity::methods[] = LUNAR_DECLARE_METHOD(CLuaBaseEntity,changeJob), LUNAR_DECLARE_METHOD(CLuaBaseEntity,changesJob), LUNAR_DECLARE_METHOD(CLuaBaseEntity,unlockJob), + LUNAR_DECLARE_METHOD(CLuaBaseEntity,hasJob), LUNAR_DECLARE_METHOD(CLuaBaseEntity,getMainLvl), LUNAR_DECLARE_METHOD(CLuaBaseEntity,getSubLvl), + LUNAR_DECLARE_METHOD(CLuaBaseEntity,getJobLevel), LUNAR_DECLARE_METHOD(CLuaBaseEntity,setLevel), LUNAR_DECLARE_METHOD(CLuaBaseEntity,setsLevel), LUNAR_DECLARE_METHOD(CLuaBaseEntity,levelCap), diff --git a/src/map/lua/lua_baseentity.h b/src/map/lua/lua_baseentity.h index 9458caceb2e..0de7ed9ba01 100644 --- a/src/map/lua/lua_baseentity.h +++ b/src/map/lua/lua_baseentity.h @@ -268,9 +268,11 @@ class CLuaBaseEntity int32 changeJob(lua_State*); // changes the job of a char (testing only!) int32 changesJob(lua_State*); // changes the sub job of a char (testing only!) int32 unlockJob(lua_State*); // Unlocks a job for the entity, sets job level to 1 + int32 hasJob(lua_State*); // Check to see if JOBTYPE is unlocked for a character int32 getMainLvl(lua_State*); // Gets Entity Main Job Level int32 getSubLvl(lua_State*); // Get Entity Sub Job Level + int32 getJobLevel(lua_State*); // Gets character job level for specified JOBTYPE int32 setLevel(lua_State*); // sets the character's level int32 setsLevel(lua_State*); // sets the character's level int32 levelCap(lua_State*); // genkai