diff --git a/zone/client.cpp b/zone/client.cpp index cc8b9f8cb..49b9090da 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -10530,6 +10530,33 @@ void Client::SetDoorToolEntityId(uint16 door_tool_entity_id) Client::m_door_tool_entity_id = door_tool_entity_id; } +void Client::ReadBookByName(std::string book_name, uint8 book_type) +{ + int16 book_language = 0; + std::string book_text = content_db.GetBook(book_name.c_str(), &book_language); + int length = book_text.length(); + + if (book_text[0] != '\0') { + LogDebug("Client::ReadBookByName() Book Name: [{}] Text: [{}]", book_name, book_text.c_str()); + auto outapp = new EQApplicationPacket(OP_ReadBook, length + sizeof(BookText_Struct)); + BookText_Struct *out = (BookText_Struct *) outapp->pBuffer; + out->window = 0xFF; + out->type = book_type; + out->invslot = 0; + + memcpy(out->booktext, book_text.c_str(), length); + + if (book_language > 0 && book_language < MAX_PP_LANGUAGE) { + if (m_pp.languages[book_language] < 100) { + GarbleMessage(out->booktext, (100 - m_pp.languages[book_language])); + } + } + + QueuePacket(outapp); + safe_delete(outapp); + } +} + // this will fetch raid clients if exists // fallback to group if raid doesn't exist // fallback to self if group doesn't exist diff --git a/zone/client.h b/zone/client.h index 952c52fca..34249cbbe 100644 --- a/zone/client.h +++ b/zone/client.h @@ -728,6 +728,7 @@ public: void Stun(int duration); void UnStun(); void ReadBook(BookRequest_Struct *book); + void ReadBookByName(std::string book_name, uint8 book_type); void QuestReadBook(const char* text, uint8 type); void SendClientMoneyUpdate(uint8 type,uint32 amount); void SendMoneyUpdate(); diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 66fb2f47d..a44a3f1f7 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -2229,6 +2229,11 @@ void Lua_Client::UntrainDiscBySpellID(uint16 spell_id, bool update_client) { self->UntrainDiscBySpellID(spell_id, update_client); } +void Lua_Client::ReadBookByName(std::string book_name, uint8 book_type) { + Lua_Safe_Call_Void(); + self->ReadBookByName(book_name, book_type); +} + void Lua_Client::SummonBaggedItems(uint32 bag_item_id, luabind::adl::object bag_items_table) { Lua_Safe_Call_Void(); if (luabind::type(bag_items_table) != LUA_TTABLE) { @@ -2627,6 +2632,7 @@ luabind::scope lua_register_client() { .def("CountItem", (int(Lua_Client::*)(uint32))&Lua_Client::CountItem) .def("RemoveItem", (void(Lua_Client::*)(uint32))&Lua_Client::RemoveItem) .def("RemoveItem", (void(Lua_Client::*)(uint32,uint32))&Lua_Client::RemoveItem) + .def("ReadBookByName", (void(Lua_Client::*)(std::string,uint8))&Lua_Client::ReadBookByName) .def("SetGMStatus", (void(Lua_Client::*)(int32))&Lua_Client::SetGMStatus) .def("UntrainDiscBySpellID", (void(Lua_Client::*)(uint16))&Lua_Client::UntrainDiscBySpellID) .def("UntrainDiscBySpellID", (void(Lua_Client::*)(uint16,bool))&Lua_Client::UntrainDiscBySpellID) diff --git a/zone/lua_client.h b/zone/lua_client.h index 0e1f1be9e..9efb6c00b 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -273,6 +273,7 @@ public: uint32 GetRadiantCrystals(); uint32 GetEbonCrystals(); void QuestReadBook(const char *text, int type); + void ReadBookByName(std::string book_name, uint8 book_type); void UpdateGroupAAs(int points, uint32 type); uint32 GetGroupPoints(); uint32 GetRaidPoints(); diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index 81c20917e..be530ff5f 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -5693,6 +5693,21 @@ XS(XS_Client_DiaWind) { XSRETURN_EMPTY; } +XS(XS_Client_ReadBookByName); +XS(XS_Client_ReadBookByName) { + dXSARGS; + if (items != 3) + Perl_croak(aTHX_ "Usage: Client::ReadBookByName(THIS, string book_name, uint8 book_type)"); // @categories Script Utility + { + Client *THIS; + std::string book_name(SvPV_nolen(ST(1))); + uint8 book_type = (uint8) SvUV(ST(2)); + VALIDATE_THIS_IS_CLIENT; + THIS->ReadBookByName(book_name, book_type); + } + XSRETURN_EMPTY; +} + XS(XS_Client_UntrainDiscBySpellID); /* prototype to pass -Wmissing-prototypes */ XS(XS_Client_UntrainDiscBySpellID) { dXSARGS; @@ -6078,6 +6093,7 @@ XS(boot_Client) { newXSproto(strcpy(buf, "UpdateWho"), XS_Client_UpdateWho, file, "$;$"); newXSproto(strcpy(buf, "UseDiscipline"), XS_Client_UseDiscipline, file, "$$$"); newXSproto(strcpy(buf, "WorldKick"), XS_Client_WorldKick, file, "$"); + newXSproto(strcpy(buf, "ReadBookByName"), XS_Client_ReadBookByName, file, "$$$"); XSRETURN_YES; }