Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Add new bindings: getJobLevel & isJobUnlocked #386

Merged
merged 4 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/map/lua/lua_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -14202,9 +14248,11 @@ Lunar<CLuaBaseEntity>::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),
Expand Down
2 changes: 2 additions & 0 deletions src/map/lua/lua_baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down