From 496536baadfa3950ab3be61fc94269c4ddf83f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB?= Date: Wed, 5 Apr 2017 18:28:54 +0300 Subject: [PATCH] Core/Text: Locales for npc_text. Closes https://github.com/azerothcore/azerothcore-wotlk/issues/452#issuecomment-291891686 --- src/game/Globals/ObjectMgr.h | 6 +++++ src/game/Handlers/NPCHandler.h | 1 + src/game/Handlers/QueryHandler.cpp | 42 +++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/game/Globals/ObjectMgr.h b/src/game/Globals/ObjectMgr.h index 06689df0e..85572634a 100644 --- a/src/game/Globals/ObjectMgr.h +++ b/src/game/Globals/ObjectMgr.h @@ -1170,6 +1170,12 @@ class ObjectMgr if (itr == _pointOfInterestLocaleStore.end()) return NULL; return &itr->second; } + NpcTextLocale const* GetNpcTextLocale(uint32 entry) const + { + NpcTextLocaleContainer::const_iterator itr = _npcTextLocaleStore.find(entry); + if (itr == _npcTextLocaleStore.end()) return NULL; + return &itr->second; + } GameObjectData& NewGOData(uint32 guid) { return _gameObjectDataStore[guid]; } void DeleteGOData(uint32 guid); diff --git a/src/game/Handlers/NPCHandler.h b/src/game/Handlers/NPCHandler.h index 6727f6010..efd2cb254 100644 --- a/src/game/Handlers/NPCHandler.h +++ b/src/game/Handlers/NPCHandler.h @@ -19,6 +19,7 @@ struct GossipTextOption { std::string Text_0; std::string Text_1; + uint32 BroadcastTextID; uint32 Language; float Probability; QEmote Emotes[MAX_GOSSIP_TEXT_EMOTES]; diff --git a/src/game/Handlers/QueryHandler.cpp b/src/game/Handlers/QueryHandler.cpp index 6389b3510..bb0df7fa5 100644 --- a/src/game/Handlers/QueryHandler.cpp +++ b/src/game/Handlers/QueryHandler.cpp @@ -274,7 +274,7 @@ void WorldSession::HandleNpcTextQueryOpcode(WorldPacket & recvData) if (!pGossip) { - for (uint32 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i) + for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i) { data << float(0); data << "Greetings $N"; @@ -290,23 +290,47 @@ void WorldSession::HandleNpcTextQueryOpcode(WorldPacket & recvData) } else { - for (int i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i) + std::string text0[MAX_GOSSIP_TEXT_OPTIONS], text1[MAX_GOSSIP_TEXT_OPTIONS]; + LocaleConstant locale = GetSessionDbLocaleIndex(); + + for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i) { + BroadcastText const* bct = sObjectMgr->GetBroadcastText(pGossip->Options[i].BroadcastTextID); + if (bct) + { + text0[i] = bct->GetText(locale, GENDER_MALE, true); + text1[i] = bct->GetText(locale, GENDER_FEMALE, true); + } + else + { + text0[i] = pGossip->Options[i].Text_0; + text1[i] = pGossip->Options[i].Text_1; + } + + if (locale != DEFAULT_LOCALE && !bct) + { + if (NpcTextLocale const* npcTextLocale = sObjectMgr->GetNpcTextLocale(textID)) + { + ObjectMgr::GetLocaleString(npcTextLocale->Text_0[i], locale, text0[i]); + ObjectMgr::GetLocaleString(npcTextLocale->Text_1[i], locale, text1[i]); + } + } + data << pGossip->Options[i].Probability; - if (pGossip->Options[i].Text_0.empty()) - data << pGossip->Options[i].Text_1; + if (text0[i].empty()) + data << text1[i]; else - data << pGossip->Options[i].Text_0; + data << text0[i]; - if (pGossip->Options[i].Text_1.empty()) - data << pGossip->Options[i].Text_0; + if (text1[i].empty()) + data << text0[i]; else - data << pGossip->Options[i].Text_1; + data << text1[i]; data << pGossip->Options[i].Language; - for (int j = 0; j < MAX_GOSSIP_TEXT_EMOTES; ++j) + for (uint8 j = 0; j < MAX_GOSSIP_TEXT_EMOTES; ++j) { data << pGossip->Options[i].Emotes[j]._Delay; data << pGossip->Options[i].Emotes[j]._Emote;