From 7e1e1651e4461b6979d3c96abcbc6410c7881d3d Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Sat, 16 Jan 2021 17:59:38 -0500 Subject: [PATCH] Add GetClassBitmask(), GetClassName(), GetRaceBitmask(), and GetRaceName() to Perl/Lua. --- zone/lua_client.cpp | 12 ++++++++++ zone/lua_client.h | 4 +++- zone/lua_mob.cpp | 12 ++++++++++ zone/lua_mob.h | 2 ++ zone/perl_client.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++ zone/perl_mob.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 139 insertions(+), 1 deletion(-) diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index b0cc62467..c04345cc6 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -134,6 +134,16 @@ void Lua_Client::SetBaseGender(int v) { self->SetBaseGender(v); } +int Lua_Client::GetClassBitmask() { + Lua_Safe_Call_Int(); + return GetPlayerClassBit(self->GetClass()); +} + +int Lua_Client::GetRaceBitmask() { + Lua_Safe_Call_Int(); + return GetPlayerRaceBit(self->GetBaseRace()); +} + int Lua_Client::GetBaseFace() { Lua_Safe_Call_Int(); return self->GetBaseFace(); @@ -1933,6 +1943,8 @@ luabind::scope lua_register_client() { .def("SetBaseClass", (void(Lua_Client::*)(int))&Lua_Client::SetBaseClass) .def("SetBaseRace", (void(Lua_Client::*)(int))&Lua_Client::SetBaseRace) .def("SetBaseGender", (void(Lua_Client::*)(int))&Lua_Client::SetBaseGender) + .def("GetClassBitmask", (int(Lua_Client::*)(void))&Lua_Client::GetClassBitmask) + .def("GetRaceBitmask", (int(Lua_Client::*)(void))&Lua_Client::GetRaceBitmask) .def("GetBaseFace", (int(Lua_Client::*)(void))&Lua_Client::GetBaseFace) .def("GetLanguageSkill", (int(Lua_Client::*)(int))&Lua_Client::GetLanguageSkill) .def("GetLastName", (const char *(Lua_Client::*)(void))&Lua_Client::GetLastName) diff --git a/zone/lua_client.h b/zone/lua_client.h index 7162bfd6b..50043ab77 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -52,7 +52,9 @@ public: bool GetGM(); void SetBaseClass(int v); void SetBaseRace(int v); - void SetBaseGender(int v); + void SetBaseGender(int v); + int GetClassBitmask(); + int GetRaceBitmask(); int GetBaseFace(); int GetLanguageSkill(int skill_id); const char *GetLastName(); diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 53658e63d..f8379b82e 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -372,6 +372,11 @@ int Lua_Mob::GetRace() { return self->GetRace(); } +const char *Lua_Mob::GetRaceName() { + Lua_Safe_Call_String(); + return GetRaceIDName(self->GetRace()); +} + int Lua_Mob::GetGender() { Lua_Safe_Call_Int(); return self->GetGender(); @@ -442,6 +447,11 @@ int Lua_Mob::GetClass() { return self->GetClass(); } +const char *Lua_Mob::GetClassName() { + Lua_Safe_Call_String(); + return GetClassIDName(self->GetClass()); +} + int Lua_Mob::GetLevel() { Lua_Safe_Call_Int(); return self->GetLevel(); @@ -2316,6 +2326,7 @@ luabind::scope lua_register_mob() { .def("GetBaseGender", &Lua_Mob::GetBaseGender) .def("GetDeity", &Lua_Mob::GetDeity) .def("GetRace", &Lua_Mob::GetRace) + .def("GetRaceName", &Lua_Mob::GetRaceName) .def("GetGender", &Lua_Mob::GetGender) .def("GetTexture", &Lua_Mob::GetTexture) .def("GetHelmTexture", &Lua_Mob::GetHelmTexture) @@ -2330,6 +2341,7 @@ luabind::scope lua_register_mob() { .def("GetDrakkinTattoo", &Lua_Mob::GetDrakkinTattoo) .def("GetDrakkinDetails", &Lua_Mob::GetDrakkinDetails) .def("GetClass", &Lua_Mob::GetClass) + .def("GetClassName", &Lua_Mob::GetClassName) .def("GetLevel", &Lua_Mob::GetLevel) .def("GetCleanName", &Lua_Mob::GetCleanName) .def("GetTarget", &Lua_Mob::GetTarget) diff --git a/zone/lua_mob.h b/zone/lua_mob.h index e2dbf9e24..426ac01af 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -92,6 +92,8 @@ public: int GetBaseGender(); int GetDeity(); int GetRace(); + const char *GetClassName(); + const char *GetRaceName(); int GetGender(); int GetTexture(); int GetHelmTexture(); diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index 1dc9f2128..de30d0c50 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -7086,6 +7086,58 @@ XS(XS_Client_Fling) { XSRETURN_EMPTY; } +XS(XS_Client_GetClassBitmask); +XS(XS_Client_GetClassBitmask) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: Client::GetClassBitmask(THIS)"); + { + Client* THIS; + int client_bitmask = 0; + dXSTARG; + + if (sv_derived_from(ST(0), "Client")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Client*, tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Client"); + if (THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + client_bitmask = GetPlayerClassBit(THIS->GetClass()); + XSprePUSH; + PUSHu((UV) client_bitmask); + } + XSRETURN(1); +} + +XS(XS_Client_GetRaceBitmask); +XS(XS_Client_GetRaceBitmask) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: Client::GetRaceBitmask(THIS)"); + { + Client* THIS; + int client_bitmask = 0; + dXSTARG; + + if (sv_derived_from(ST(0), "Client")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Client*, tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Client"); + if (THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + client_bitmask = GetPlayerRaceBit(THIS->GetBaseRace()); + XSprePUSH; + PUSHu((UV) client_bitmask); + } + XSRETURN(1); +} + #ifdef __cplusplus extern "C" #endif @@ -7174,6 +7226,7 @@ XS(boot_Client) { newXSproto(strcpy(buf, "GetBindZoneID"), XS_Client_GetBindZoneID, file, "$$"); newXSproto(strcpy(buf, "GetCarriedMoney"), XS_Client_GetCarriedMoney, file, "$"); newXSproto(strcpy(buf, "GetCharacterFactionLevel"), XS_Client_GetCharacterFactionLevel, file, "$$"); + newXSproto(strcpy(buf, "GetClassBitmask"), XS_Client_GetClassBitmask, file, "$"); newXSproto(strcpy(buf, "GetClientMaxLevel"), XS_Client_GetClientMaxLevel, file, "$"); newXSproto(strcpy(buf, "GetClientVersion"), XS_Client_GetClientVersion, file, "$"); newXSproto(strcpy(buf, "GetClientVersionBit"), XS_Client_GetClientVersionBit, file, "$"); @@ -7218,6 +7271,7 @@ XS(boot_Client) { newXSproto(strcpy(buf, "GetMoney"), XS_Client_GetMoney, file, "$$$"); newXSproto(strcpy(buf, "GetPVP"), XS_Client_GetPVP, file, "$"); newXSproto(strcpy(buf, "GetPVPPoints"), XS_Client_GetPVPPoints, file, "$"); + newXSproto(strcpy(buf, "GetRaceBitmask"), XS_Client_GetRaceBitmask, file, "$"); newXSproto(strcpy(buf, "GetRadiantCrystals"), XS_Client_GetRadiantCrystals, file, "$"); newXSproto(strcpy(buf, "GetRaid"), XS_Client_GetRaid, file, "$"); newXSproto(strcpy(buf, "GetRaidPoints"), XS_Client_GetRaidPoints, file, "$"); diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index f90435887..132719195 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -8594,6 +8594,60 @@ XS(XS_Mob_TryMoveAlong) { XSRETURN_EMPTY; } +XS(XS_Mob_GetClassName); +XS(XS_Mob_GetClassName) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: Mob::GetClassName(THIS)"); + { + Mob* THIS; + Const_char *class_name; + dXSTARG; + + if (sv_derived_from(ST(0), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Mob*, tmp); + } else + Perl_croak(aTHX_ "THIS is not of type Mob"); + + if (THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + class_name = GetClassIDName(THIS->GetClass()); + sv_setpv(TARG, class_name); + XSprePUSH; + PUSHTARG; + } + XSRETURN(1); +} + +XS(XS_Mob_GetRaceName); +XS(XS_Mob_GetRaceName) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: Mob::GetRaceName(THIS)"); + { + Mob* THIS; + Const_char *race_name; + dXSTARG; + + if (sv_derived_from(ST(0), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Mob*, tmp); + } else + Perl_croak(aTHX_ "THIS is not of type Mob"); + + if (THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + race_name = GetRaceIDName(THIS->GetRace()); + sv_setpv(TARG, race_name); + XSprePUSH; + PUSHTARG; + } + XSRETURN(1); +} + #ifdef __cplusplus extern "C" #endif @@ -8668,6 +8722,7 @@ XS(boot_Mob) { newXSproto(strcpy(buf, "GetBaseGender"), XS_Mob_GetBaseGender, file, "$"); newXSproto(strcpy(buf, "GetDeity"), XS_Mob_GetDeity, file, "$"); newXSproto(strcpy(buf, "GetRace"), XS_Mob_GetRace, file, "$"); + newXSproto(strcpy(buf, "GetRaceName"), XS_Mob_GetRaceName, file, "$"); newXSproto(strcpy(buf, "GetGender"), XS_Mob_GetGender, file, "$"); newXSproto(strcpy(buf, "GetTexture"), XS_Mob_GetTexture, file, "$"); newXSproto(strcpy(buf, "GetHelmTexture"), XS_Mob_GetHelmTexture, file, "$"); @@ -8682,6 +8737,7 @@ XS(boot_Mob) { newXSproto(strcpy(buf, "GetDrakkinTattoo"), XS_Mob_GetDrakkinTattoo, file, "$"); newXSproto(strcpy(buf, "GetDrakkinDetails"), XS_Mob_GetDrakkinDetails, file, "$"); newXSproto(strcpy(buf, "GetClass"), XS_Mob_GetClass, file, "$"); + newXSproto(strcpy(buf, "GetClassName"), XS_Mob_GetClassName, file, "$"); newXSproto(strcpy(buf, "GetLevel"), XS_Mob_GetLevel, file, "$"); newXSproto(strcpy(buf, "GetCleanName"), XS_Mob_GetCleanName, file, "$"); newXSproto(strcpy(buf, "GetTarget"), XS_Mob_GetTarget, file, "$");