From 02cac686b63ec407193c726181418f0b185e6945 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 00:09:57 -0400 Subject: [PATCH 1/4] Add getnpcnamebyid(npc_id) to Perl/Lua. --- common/database.cpp | 17 +++++++++++++++++ common/database.h | 1 + zone/embparser_api.cpp | 17 +++++++++++++++++ zone/lua_general.cpp | 5 +++++ zone/questmgr.cpp | 7 +++++++ zone/questmgr.h | 1 + 6 files changed, 48 insertions(+) diff --git a/common/database.cpp b/common/database.cpp index ab9b1ce84..1935406a2 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -941,6 +941,22 @@ const char* Database::GetCharNameByID(uint32 char_id) { return row[0]; } +const char* Database::GetNPCNameByID(uint32 npc_id) { + std::string query = fmt::format("SELECT `name` FROM `npc_types` WHERE id = {}", npc_id); + auto results = QueryDatabase(query); + + if (!results.Success()) { + return ""; + } + + if (results.RowCount() == 0) { + return ""; + } + + auto row = results.begin(); + return row[0]; +} + bool Database::LoadVariables() { auto results = QueryDatabase(StringFormat("SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache.last_update)); @@ -2389,3 +2405,4 @@ int Database::GetInstanceID(uint32 char_id, uint32 zone_id) { return 0; } + diff --git a/common/database.h b/common/database.h index 44c264dfd..cf85acf9c 100644 --- a/common/database.h +++ b/common/database.h @@ -139,6 +139,7 @@ public: void GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID = 0); void GetCharName(uint32 char_id, char* name); const char *GetCharNameByID(uint32 char_id); + const char *GetNPCNameByID(uint32 npc_id); void LoginIP(uint32 AccountID, const char* LoginIP); /* Instancing */ diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index dfb23ddc8..d926ffcbb 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -2858,6 +2858,22 @@ XS(XS__getitemname) { XSRETURN(1); } +XS(XS__getnpcnamebyid); +XS(XS__getnpcnamebyid) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::getnpcnamebyid(uint32 npc_id)"); + + dXSTARG; + uint32 npc_id = (int) SvIV(ST(0)); + const char *npc_name = quest_manager.getnpcnamebyid(npc_id); + + sv_setpv(TARG, npc_name); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + XS(XS__UpdateSpawnTimer); XS(XS__UpdateSpawnTimer) { dXSARGS; @@ -4110,6 +4126,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "getinventoryslotid"), XS__getinventoryslotid, file); newXS(strcpy(buf, "getitemname"), XS__getitemname, file); newXS(strcpy(buf, "getItemName"), XS_qc_getItemName, file); + newXS(strcpy(buf, "getnpcnamebyid"), XS__getnpcnamebyid, file); newXS(strcpy(buf, "get_spawn_condition"), XS__get_spawn_condition, file); newXS(strcpy(buf, "getcharnamebyid"), XS__getcharnamebyid, file); newXS(strcpy(buf, "getguildnamebyid"), XS__getguildnamebyid, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 848348fbf..07b200315 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -890,6 +890,10 @@ int lua_get_group_id_by_char_id(uint32 char_id) { return database.GetGroupIDByCharID(char_id); } +const char *lua_get_npc_name_by_id(uint32 npc_id) { + return quest_manager.getnpcnamebyid(npc_id); +} + int lua_get_raid_id_by_char_id(uint32 char_id) { return database.GetRaidIDByCharID(char_id); } @@ -1776,6 +1780,7 @@ luabind::scope lua_register_general() { luabind::def("get_guild_name_by_id", &lua_get_guild_name_by_id), luabind::def("get_guild_id_by_char_id", &lua_get_guild_id_by_char_id), luabind::def("get_group_id_by_char_id", &lua_get_group_id_by_char_id), + luabind::def("get_npc_name_by_id", &lua_get_npc_name_by_id), luabind::def("get_raid_id_by_char_id", &lua_get_raid_id_by_char_id), luabind::def("create_instance", &lua_create_instance), luabind::def("destroy_instance", &lua_destroy_instance), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 0a61361c6..e2006222c 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -2725,6 +2725,13 @@ std::string QuestManager::getitemname(uint32 item_id) { return item_name; } +const char *QuestManager::getnpcnamebyid(uint32 npc_id) { + if (npc_id > 0) { + return database.GetNPCNameByID(npc_id); + } + return ""; +} + uint16 QuestManager::CreateInstance(const char *zone, int16 version, uint32 duration) { QuestManagerCurrentQuestVars(); diff --git a/zone/questmgr.h b/zone/questmgr.h index a3c7eab3d..934dd148a 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -260,6 +260,7 @@ public: const char* getguildnamebyid(int guild_id); int getguildidbycharid(uint32 char_id); int getgroupidbycharid(uint32 char_id); + const char* getnpcnamebyid(uint32 npc_id); int getraididbycharid(uint32 char_id); void SetRunning(bool val); bool IsRunning(); From 6ddcc2bb8a5412baa41b402edc9edef792e4adaa Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 00:49:57 -0400 Subject: [PATCH 2/4] Add getcurrencyid(item_id) to Perl/Lua. --- zone/embparser_api.cpp | 18 ++++++++++++++++++ zone/lua_general.cpp | 5 +++++ zone/questmgr.cpp | 11 +++++++++++ zone/questmgr.h | 1 + 4 files changed, 35 insertions(+) diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index dfb23ddc8..2c8ebb54b 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -3265,6 +3265,23 @@ XS(XS__getcharidbyname) { XSRETURN(1); } +XS(XS__getcurrencyid); +XS(XS__getcurrencyid) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::getcurrencyid(uint32 item_id)"); + dXSTARG; + + int RETVAL; + uint32 item_id = (int) SvUV(ST(0));; + + RETVAL = quest_manager.getcurrencyid(item_id); + XSprePUSH; + PUSHi((IV)RETVAL); + + XSRETURN(1); +} + XS(XS__getguildnamebyid); XS(XS__getguildnamebyid) { dXSARGS; @@ -4107,6 +4124,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "forcedoorclose"), XS__forcedoorclose, file); newXS(strcpy(buf, "forcedooropen"), XS__forcedooropen, file); newXS(strcpy(buf, "getcharidbyname"), XS__getcharidbyname, file); + newXS(strcpy(buf, "getcurrencyid"), XS__getcurrencyid, file); newXS(strcpy(buf, "getinventoryslotid"), XS__getinventoryslotid, file); newXS(strcpy(buf, "getitemname"), XS__getitemname, file); newXS(strcpy(buf, "getItemName"), XS_qc_getItemName, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 848348fbf..3525a74ad 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -878,6 +878,10 @@ uint32 lua_get_char_id_by_name(const char* name) { return quest_manager.getcharidbyname(name); } +int lua_get_currency_id(uint32 item_id) { + return quest_manager.getcurrencyid(item_id); +} + const char *lua_get_guild_name_by_id(uint32 guild_id) { return quest_manager.getguildnamebyid(guild_id); } @@ -1773,6 +1777,7 @@ luabind::scope lua_register_general() { luabind::def("delete_data", (bool(*)(std::string))&lua_delete_data), luabind::def("get_char_name_by_id", &lua_get_char_name_by_id), luabind::def("get_char_id_by_name", (uint32(*)(const char*))&lua_get_char_id_by_name), + luabind::def("get_currency_id", &lua_get_currency_id), luabind::def("get_guild_name_by_id", &lua_get_guild_name_by_id), luabind::def("get_guild_id_by_char_id", &lua_get_guild_id_by_char_id), luabind::def("get_group_id_by_char_id", &lua_get_group_id_by_char_id), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 0a61361c6..c6afdb46e 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -2939,6 +2939,17 @@ uint32 QuestManager::getcharidbyname(const char* name) { return database.GetCharacterID(name); } +int QuestManager::getcurrencyid(uint32 item_id) { + auto iter = zone->AlternateCurrencies.begin(); + while (iter != zone->AlternateCurrencies.end()) { + if (item_id == (*iter).item_id) { + return (*iter).id; + } + ++iter; + } + return 0; +} + const char* QuestManager::getguildnamebyid(int guild_id) { if (guild_id > 0) return guild_mgr.GetGuildName(guild_id); diff --git a/zone/questmgr.h b/zone/questmgr.h index a3c7eab3d..f3d95ff8a 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -257,6 +257,7 @@ public: std::string saylink(char *saylink_text, bool silent, const char *link_name); const char* getcharnamebyid(uint32 char_id); uint32 getcharidbyname(const char* name); + int getcurrencyid(uint32 item_id); const char* getguildnamebyid(int guild_id); int getguildidbycharid(uint32 char_id); int getgroupidbycharid(uint32 char_id); From 358bd60716a152dba6a1d051f14c589fd75fa988 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 01:36:46 -0400 Subject: [PATCH 3/4] Add getskillname(skill_id) to Perl/Lua. --- zone/embparser_api.cpp | 17 +++++++++++++++++ zone/lua_general.cpp | 5 +++++ zone/questmgr.cpp | 12 ++++++++++++ zone/questmgr.h | 1 + 4 files changed, 35 insertions(+) diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index dfb23ddc8..0ddfb289a 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -838,6 +838,22 @@ XS(XS__getspellname) { XSRETURN(1); } +XS(XS__getskillname); +XS(XS__getskillname) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::getskillname(int skill_id)"); + + dXSTARG; + int skill_id = (int) SvIV(ST(0)); + std::string skill_name = quest_manager.getskillname(skill_id); + + sv_setpv(TARG, skill_name.c_str()); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + XS(XS__safemove); XS(XS__safemove) { dXSARGS; @@ -4117,6 +4133,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "getgroupidbycharid"), XS__getgroupidbycharid, file); newXS(strcpy(buf, "getraididbycharid"), XS__getraididbycharid, file); newXS(strcpy(buf, "getspellname"), XS__getspellname, file); + newXS(strcpy(buf, "getskillname"), XS__getskillname, file); newXS(strcpy(buf, "getlevel"), XS__getlevel, file); newXS(strcpy(buf, "getplayerburiedcorpsecount"), XS__getplayerburiedcorpsecount, file); newXS(strcpy(buf, "getplayercorpsecount"), XS__getplayercorpsecount, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 848348fbf..a3ed7b04a 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -397,6 +397,10 @@ std::string lua_get_spell_name(uint32 spell_id) { return quest_manager.getspellname(spell_id); } +std::string lua_get_skill_name(int skill_id) { + return quest_manager.getskillname(skill_id); +} + void lua_safe_move() { quest_manager.safemove(); } @@ -1673,6 +1677,7 @@ luabind::scope lua_register_general() { luabind::def("repop_zone", &lua_repop_zone), luabind::def("is_disc_tome", &lua_is_disc_tome), luabind::def("get_spell_name", (std::string(*)(uint32))&lua_get_spell_name), + luabind::def("get_skill_name", (std::string(*)(int))&lua_get_skill_name), luabind::def("safe_move", &lua_safe_move), luabind::def("rain", &lua_rain), luabind::def("snow", &lua_snow), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 0a61361c6..6a568466e 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -915,6 +915,18 @@ std::string QuestManager::getspellname(uint32 spell_id) { return spell_name; } +std::string QuestManager::getskillname(int skill_id) { + if (skill_id >= 0 && skill_id < EQEmu::skills::SkillCount) { + std::map Skills = EQEmu::skills::GetSkillTypeMap(); + for (auto skills_iter : Skills) { + if (skill_id == skills_iter.first) { + return skills_iter.second; + } + } + } + return std::string(); +} + void QuestManager::safemove() { QuestManagerCurrentQuestVars(); if (initiator && initiator->IsClient()) diff --git a/zone/questmgr.h b/zone/questmgr.h index a3c7eab3d..50f077298 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -108,6 +108,7 @@ public: void traindisc(int discipline_tome_item_id); bool isdisctome(int item_id); std::string getspellname(uint32 spell_id); + std::string getskillname(int skill_id); void safemove(); void rain(int weather); void snow(int weather); From fab071d9da4617f9c60f4154394820e4579b0bff Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 02:02:20 -0400 Subject: [PATCH 4/4] Add getracename(race_id) to Perl/Lua. --- zone/embparser_api.cpp | 17 +++++++++++++++++ zone/lua_general.cpp | 5 +++++ zone/questmgr.cpp | 4 ++++ zone/questmgr.h | 1 + 4 files changed, 27 insertions(+) diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index dfb23ddc8..9e7b11b52 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -822,6 +822,22 @@ XS(XS__isdisctome) { XSRETURN(1); } +XS(XS__getracename); +XS(XS__getracename) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::getracename(uint16 race_id)"); + + dXSTARG; + uint16 race_id = (int) SvIV(ST(0)); + std::string race_name = quest_manager.getracename(race_id); + + sv_setpv(TARG, race_name.c_str()); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + XS(XS__getspellname); XS(XS__getspellname) { dXSARGS; @@ -4116,6 +4132,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "getguildidbycharid"), XS__getguildidbycharid, file); newXS(strcpy(buf, "getgroupidbycharid"), XS__getgroupidbycharid, file); newXS(strcpy(buf, "getraididbycharid"), XS__getraididbycharid, file); + newXS(strcpy(buf, "getracename"), XS__getracename, file); newXS(strcpy(buf, "getspellname"), XS__getspellname, file); newXS(strcpy(buf, "getlevel"), XS__getlevel, file); newXS(strcpy(buf, "getplayerburiedcorpsecount"), XS__getplayerburiedcorpsecount, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 848348fbf..0659605e3 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -393,6 +393,10 @@ bool lua_is_disc_tome(int item_id) { return quest_manager.isdisctome(item_id); } +std::string lua_get_race_name(uint32 race_id) { + return quest_manager.getracename(race_id); +} + std::string lua_get_spell_name(uint32 spell_id) { return quest_manager.getspellname(spell_id); } @@ -1672,6 +1676,7 @@ luabind::scope lua_register_general() { luabind::def("depop_zone", &lua_depop_zone), luabind::def("repop_zone", &lua_repop_zone), luabind::def("is_disc_tome", &lua_is_disc_tome), + luabind::def("get_race_name", (std::string(*)(uint16))&lua_get_race_name), luabind::def("get_spell_name", (std::string(*)(uint32))&lua_get_spell_name), luabind::def("safe_move", &lua_safe_move), luabind::def("rain", &lua_rain), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 0a61361c6..c4de76f14 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -906,6 +906,10 @@ bool QuestManager::isdisctome(int item_id) { return(true); } +std::string QuestManager::getracename(uint16 race_id) { + return GetRaceIDName(race_id); +} + std::string QuestManager::getspellname(uint32 spell_id) { if (!IsValidSpell(spell_id)) { return "INVALID SPELL ID IN GETSPELLNAME"; diff --git a/zone/questmgr.h b/zone/questmgr.h index a3c7eab3d..24cbcc825 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -107,6 +107,7 @@ public: void level(int newlevel); void traindisc(int discipline_tome_item_id); bool isdisctome(int item_id); + std::string getracename(uint16 race_id); std::string getspellname(uint32 spell_id); void safemove(); void rain(int weather);