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 0bde28561..4daebd009 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; @@ -838,6 +854,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; @@ -2858,6 +2890,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; @@ -3279,6 +3327,22 @@ XS(XS__getcurrencyitemid) { XSprePUSH; PUSHi((IV)RETVAL); + 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); } @@ -4124,9 +4188,11 @@ 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); + 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, "getcurrencyitemid"), XS__getcurrencyitemid, file); @@ -4134,7 +4200,9 @@ 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, "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 cc320ab63..866ceb3ee 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -393,10 +393,18 @@ 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); } +std::string lua_get_skill_name(int skill_id) { + return quest_manager.getskillname(skill_id); +} + void lua_safe_move() { quest_manager.safemove(); } @@ -878,6 +886,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) +} + int lua_get_currency_item_id(int currency_id) { return quest_manager.getcurrencyitemid(currency_id); } @@ -894,6 +906,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); } @@ -1676,7 +1692,9 @@ 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("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), @@ -1777,10 +1795,12 @@ 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_currency_item_id", &lua_get_currency_item_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), + 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 7560678e1..d2f4fea58 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"; @@ -915,6 +919,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()) @@ -2725,6 +2741,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(); @@ -2939,6 +2962,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; +} + int QuestManager::getcurrencyitemid(int currency_id) { if (currency_id > 0) { auto iter = zone->AlternateCurrencies.begin(); @@ -2948,7 +2982,6 @@ int QuestManager::getcurrencyitemid(int currency_id) { } ++iter; } - } return 0; } diff --git a/zone/questmgr.h b/zone/questmgr.h index a4743b2ad..4cf8b85dc 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -107,7 +107,9 @@ 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); + std::string getskillname(int skill_id); void safemove(); void rain(int weather); void snow(int weather); @@ -257,10 +259,12 @@ 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); int getcurrencyitemid(int currency_id); 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();