From 51b31b5e531cb6ebb44bc8bad5241ac37e34b40b Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 31 Mar 2020 19:31:04 -0400 Subject: [PATCH] Add getitemname(item_id) to Perl/Lua. --- zone/embparser_api.cpp | 17 +++++++++++++++++ zone/lua_general.cpp | 5 +++++ zone/questmgr.cpp | 10 ++++++++++ zone/questmgr.h | 1 + 4 files changed, 33 insertions(+) diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index cf55925b8..901d25ce2 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -2810,6 +2810,22 @@ XS(XS__countitem) { XSRETURN_IV(quantity); } +XS(XS__getitemname); +XS(XS__getitemname) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::getitemname(uint32 item_id)"); + + dXSTARG; + uint32 item_id = (int) SvIV(ST(0)); + std::string item_name = quest_manager.getitemname(item_id); + + sv_setpv(TARG, item_name.c_str()); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + XS(XS__UpdateSpawnTimer); XS(XS__UpdateSpawnTimer) { dXSARGS; @@ -4005,6 +4021,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "forcedoorclose"), XS__forcedoorclose, file); newXS(strcpy(buf, "forcedooropen"), XS__forcedooropen, 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, "get_spawn_condition"), XS__get_spawn_condition, file); newXS(strcpy(buf, "getguildnamebyid"), XS__getguildnamebyid, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 9367cef21..15fc3d3e1 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -807,6 +807,10 @@ std::string lua_item_link(int item_id) { return quest_manager.varlink(text, item_id); } +std::string lua_get_item_name(uint32 item_id) { + return quest_manager.getitemname(item_id); +} + std::string lua_say_link(const char *phrase, bool silent, const char *link_name) { char text[256] = { 0 }; strncpy(text, phrase, 255); @@ -1734,6 +1738,7 @@ luabind::scope lua_register_general() { luabind::def("merchant_set_item", (void(*)(uint32,uint32,uint32))&lua_merchant_set_item), luabind::def("merchant_count_item", &lua_merchant_count_item), luabind::def("item_link", &lua_item_link), + luabind::def("get_item_name", (std::string(*)(uint32))&lua_get_item_name), luabind::def("say_link", (std::string(*)(const char*,bool,const char*))&lua_say_link), luabind::def("say_link", (std::string(*)(const char*,bool))&lua_say_link), luabind::def("say_link", (std::string(*)(const char*))&lua_say_link), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 0c36b876a..a1ec7d959 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -2696,6 +2696,16 @@ const char* QuestManager::varlink(char* perltext, int item_id) { return perltext; } +std::string QuestManager::getitemname(uint32 item_id) { + const EQEmu::ItemData* item_data = database.GetItem(item_id); + if (!item_data) { + return "INVALID ITEM ID IN GETITEMNAME"; + } + + std::string item_name = item_data->Name; + return item_name; +} + uint16 QuestManager::CreateInstance(const char *zone, int16 version, uint32 duration) { QuestManagerCurrentQuestVars(); diff --git a/zone/questmgr.h b/zone/questmgr.h index 21d5b5db1..cde58fc0d 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -220,6 +220,7 @@ public: int collectitems(uint32 item_id, bool remove); int collectitems_processSlot(int16 slot_id, uint32 item_id, bool remove); int countitem(uint32 item_id); + std::string getitemname(uint32 item_id); void enabletitle(int titleset); bool checktitle(int titlecheck); void removetitle(int titlecheck);