[Quest API] Add GetBodyTypeName() to Perl/Lua. (#1863)

* [Quest API] Add GetBodyTypeName() to Perl/Lua.
- Add GetBodyTypeName() and GetBodyTypeMap() helper methods.
- Add quest::getbodytypename(bodytype_id) to Perl.
- Add eq.get_body_type_name(bodytype_id) to Lua.

* ShowStats() cleanup.
This commit is contained in:
Kinglykrab 2021-12-03 19:52:42 -05:00 committed by GitHub
parent e09f28c62c
commit 01a671918a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 119 additions and 10 deletions

View File

@ -19,6 +19,8 @@
#include "emu_constants.h"
#include "languages.h"
#include "data_verification.h"
#include "bodytypes.h"
int16 EQ::invtype::GetInvTypeSize(int16 inv_type) {
@ -148,8 +150,9 @@ const char *EQ::constants::GetStanceName(StanceType stance_type) {
}
int EQ::constants::ConvertStanceTypeToIndex(StanceType stance_type) {
if (stance_type >= EQ::constants::stancePassive && stance_type <= EQ::constants::stanceBurnAE)
if (EQ::ValueWithin(stance_type, EQ::constants::stancePassive, EQ::constants::stanceBurnAE)) {
return (stance_type - EQ::constants::stancePassive);
}
return 0;
}
@ -191,7 +194,7 @@ const std::map<int, std::string>& EQ::constants::GetLanguageMap()
std::string EQ::constants::GetLanguageName(int language_id)
{
if (language_id >= LANG_COMMON_TONGUE && language_id <= LANG_UNKNOWN) {
if (EQ::ValueWithin(language_id, LANG_COMMON_TONGUE, LANG_UNKNOWN)) {
auto languages = EQ::constants::GetLanguageMap();
return languages[language_id];
}
@ -213,7 +216,7 @@ const std::map<uint32, std::string>& EQ::constants::GetLDoNThemeMap()
std::string EQ::constants::GetLDoNThemeName(uint32 theme_id)
{
if (theme_id >= LDoNThemes::Unused && theme_id <= LDoNThemes::TAK) {
if (EQ::ValueWithin(theme_id, LDoNThemes::Unused, LDoNThemes::TAK)) {
auto ldon_themes = EQ::constants::GetLDoNThemeMap();
return ldon_themes[theme_id];
}
@ -235,12 +238,64 @@ const std::map<uint8, std::string>& EQ::constants::GetFlyModeMap()
std::string EQ::constants::GetFlyModeName(uint8 flymode_id)
{
if (
flymode_id >= GravityBehavior::Ground &&
flymode_id <= GravityBehavior::LevitateWhileRunning
) {
if (EQ::ValueWithin(flymode_id, GravityBehavior::Ground, GravityBehavior::LevitateWhileRunning)) {
auto flymodes = EQ::constants::GetFlyModeMap();
return flymodes[flymode_id];
}
return std::string();
}
const std::map<bodyType, std::string>& EQ::constants::GetBodyTypeMap()
{
static const std::map<bodyType, std::string> bodytype_map = {
{ BT_Humanoid, "Humanoid" },
{ BT_Lycanthrope, "Lycanthrope" },
{ BT_Undead, "Undead" },
{ BT_Giant, "Giant" },
{ BT_Construct, "Construct" },
{ BT_Extraplanar, "Extraplanar" },
{ BT_Magical, "Magical" },
{ BT_SummonedUndead, "Summoned Undead" },
{ BT_RaidGiant, "Raid Giant" },
{ BT_RaidColdain, "Raid Coldain" },
{ BT_NoTarget, "Untargetable" },
{ BT_Vampire, "Vampire" },
{ BT_Atenha_Ra, "Aten Ha Ra" },
{ BT_Greater_Akheva, "Greater Akheva" },
{ BT_Khati_Sha, "Khati Sha" },
{ BT_Seru, "Seru" },
{ BT_Grieg_Veneficus, "Grieg Veneficus" },
{ BT_Draz_Nurakk, "Draz Nurakk" },
{ BT_Zek, "Zek" },
{ BT_Luggald, "Luggald" },
{ BT_Animal, "Animal" },
{ BT_Insect, "Insect" },
{ BT_Monster, "Monster" },
{ BT_Summoned, "Summoned" },
{ BT_Plant, "Plant" },
{ BT_Dragon, "Dragon" },
{ BT_Summoned2, "Summoned 2" },
{ BT_Summoned3, "Summoned 3" },
{ BT_Dragon2, "Dragon 2" },
{ BT_VeliousDragon, "Velious Dragon" },
{ BT_Familiar, "Familiar" },
{ BT_Dragon3, "Dragon 3" },
{ BT_Boxes, "Boxes" },
{ BT_Muramite, "Muramite" },
{ BT_NoTarget2, "Untargetable 2" },
{ BT_SwarmPet, "Swarm Pet" },
{ BT_MonsterSummon, "Monster Summon" },
{ BT_InvisMan, "Invisible Man" },
{ BT_Special, "Special" },
};
return bodytype_map;
}
std::string EQ::constants::GetBodyTypeName(bodyType bodytype_id)
{
auto bodytypes = EQ::constants::GetBodyTypeMap();
if (!bodytypes[bodytype_id].empty()) {
return bodytypes[bodytype_id];
}
return std::string();
}

View File

@ -22,6 +22,7 @@
#include "eq_limits.h"
#include "emu_versions.h"
#include "bodytypes.h"
#include <string.h>
@ -241,6 +242,9 @@ namespace EQ
extern const std::map<uint8, std::string>& GetFlyModeMap();
std::string GetFlyModeName(uint8 flymode_id);
extern const std::map<bodyType, std::string>& GetBodyTypeMap();
std::string GetBodyTypeName(bodyType bodytype_id);
const int STANCE_TYPE_FIRST = stancePassive;
const int STANCE_TYPE_LAST = stanceBurnAE;
const int STANCE_TYPE_COUNT = stanceBurnAE;

View File

@ -8057,6 +8057,23 @@ XS(XS__getlanguagename) {
}
}
XS(XS__getbodytypename);
XS(XS__getbodytypename) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::getbodytypename(uint32 bodytype_id)");
{
dXSTARG;
uint32 bodytype_id = (uint32) SvUV(ST(0));
std::string bodytype_name = quest_manager.getbodytypename(bodytype_id);
sv_setpv(TARG, bodytype_name.c_str());
XSprePUSH;
PUSHTARG;
XSRETURN(1);
}
}
/*
This is the callback perl will look for to setup the
quest package's XSUBs
@ -8337,6 +8354,7 @@ EXTERN_C XS(boot_quest) {
newXS(strcpy(buf, "forcedoorclose"), XS__forcedoorclose, file);
newXS(strcpy(buf, "forcedooropen"), XS__forcedooropen, file);
newXS(strcpy(buf, "getaaexpmodifierbycharid"), XS__getaaexpmodifierbycharid, file);
newXS(strcpy(buf, "getbodytypename"), XS__getbodytypename, file);
newXS(strcpy(buf, "getcharidbyname"), XS__getcharidbyname, file);
newXS(strcpy(buf, "getclassname"), XS__getclassname, file);
newXS(strcpy(buf, "getcleannpcnamebyid"), XS__getcleannpcnamebyid, file);

View File

@ -215,8 +215,18 @@ void command_npcedit(Client *c, const Seperator *sep)
if (strcasecmp(sep->arg[1], "bodytype") == 0) {
c->Message(
Chat::Yellow,
fmt::format("NPC ID {} is now using Bodytype {} .", npc_id, atoi(sep->arg[2])).c_str());
std::string query = fmt::format("UPDATE npc_types SET bodytype = {} WHERE id = {}", atoi(sep->arg[2]), npc_id);
fmt::format(
"NPC ID {} is now using Bodytype {} ({}).",
npc_id,
EQ::constants::GetBodyTypeName(static_cast<bodyType>(std::stoul(sep->arg[2]))),
std::stoul(sep->arg[2])
).c_str()
);
std::string query = fmt::format(
"UPDATE npc_types SET bodytype = {} WHERE id = {}",
std::stoul(sep->arg[2]),
npc_id
);
content_db.QueryDatabase(query);
return;
}

View File

@ -3359,6 +3359,10 @@ std::string lua_get_language_name(int language_id) {
return quest_manager.getlanguagename(language_id);
}
std::string lua_get_body_type_name(uint32 bodytype_id) {
return quest_manager.getbodytypename(bodytype_id);
}
#define LuaCreateNPCParse(name, c_type, default_value) do { \
cur = table[#name]; \
if(luabind::type(cur) != LUA_TNIL) { \
@ -3804,6 +3808,7 @@ luabind::scope lua_register_general() {
luabind::def("get_spell", &lua_get_spell),
luabind::def("get_faction_name", &lua_get_faction_name),
luabind::def("get_language_name", &lua_get_language_name),
luabind::def("get_body_type_name", &lua_get_body_type_name),
/*
Cross Zone

View File

@ -1765,12 +1765,24 @@ void Mob::ShowStats(Client* client)
}
// Body
auto bodytype_name = EQ::constants::GetBodyTypeName(target->GetBodyType());
client->Message(
Chat::White,
fmt::format(
"Body | Size: {:.2f} Type: {}",
target->GetSize(),
target->GetBodyType()
(
bodytype_name.empty() ?
fmt::format(
"{}",
target->GetBodyType()
) :
fmt::format(
"{} ({})",
bodytype_name,
target->GetBodyType()
)
)
).c_str()
);

View File

@ -1044,6 +1044,10 @@ std::string QuestManager::getlanguagename(int language_id) {
return EQ::constants::GetLanguageName(language_id);
}
std::string QuestManager::getbodytypename(uint32 bodytype_id) {
return EQ::constants::GetBodyTypeName(static_cast<bodyType>(bodytype_id));
}
void QuestManager::safemove() {
QuestManagerCurrentQuestVars();
if (initiator && initiator->IsClient())

View File

@ -117,6 +117,7 @@ public:
std::string getskillname(int skill_id);
std::string getfactionname(int faction_id);
std::string getlanguagename(int language_id);
std::string getbodytypename(uint32 bodytype_id);
void safemove();
void rain(int weather);
void snow(int weather);