diff options
author | HeartWell <heartwell@list.ru> | 2016-11-05 17:28:49 +0300 |
---|---|---|
committer | Shin <borzifrancesco@gmail.com> | 2016-11-05 15:28:49 +0100 |
commit | 55873c18918bc7ce0f93815e6c62f760428ec194 (patch) | |
tree | 3669ca803db7fd8b27ef6844a4acbdb89fa36e92 /src | |
parent | a52fbb398f7785a0982bab283168544cce8cb29c (diff) |
Core/Creature: Localization creatures. (#224)
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Entities/Creature/Creature.cpp | 13 | ||||
-rw-r--r-- | src/game/Entities/Creature/Creature.h | 2 | ||||
-rw-r--r-- | src/game/Globals/ObjectMgr.cpp | 24 | ||||
-rw-r--r-- | src/game/Globals/ObjectMgr.h | 6 | ||||
-rw-r--r-- | src/game/Handlers/QueryHandler.cpp | 40 | ||||
-rw-r--r-- | src/scripts/Commands/cs_lookup.cpp | 27 |
6 files changed, 99 insertions, 13 deletions
diff --git a/src/game/Entities/Creature/Creature.cpp b/src/game/Entities/Creature/Creature.cpp index dab9c7ec1a..ce35ea72c4 100644 --- a/src/game/Entities/Creature/Creature.cpp +++ b/src/game/Entities/Creature/Creature.cpp @@ -2538,7 +2538,18 @@ TrainerSpellData const* Creature::GetTrainerSpells() const // overwrite WorldObject function for proper name localization std::string const& Creature::GetNameForLocaleIdx(LocaleConstant loc_idx) const -{ +{ + if (loc_idx != DEFAULT_LOCALE) + { + uint8 uloc_idx = uint8(loc_idx); + CreatureLocale const* cl = sObjectMgr->GetCreatureLocale(GetEntry()); + if (cl) + { + if (cl->Name.size() > uloc_idx && !cl->Name[uloc_idx].empty()) + return cl->Name[uloc_idx]; + } + } + return GetName(); } diff --git a/src/game/Entities/Creature/Creature.h b/src/game/Entities/Creature/Creature.h index 02b3ad9497..804da70e8a 100644 --- a/src/game/Entities/Creature/Creature.h +++ b/src/game/Entities/Creature/Creature.h @@ -218,7 +218,7 @@ typedef UNORDERED_MAP<uint16, CreatureBaseStats> CreatureBaseStatsContainer; struct CreatureLocale { StringVector Name; - StringVector SubName; + StringVector Title; }; struct GossipMenuItemsLocale diff --git a/src/game/Globals/ObjectMgr.cpp b/src/game/Globals/ObjectMgr.cpp index 92de260af6..085be3cca5 100644 --- a/src/game/Globals/ObjectMgr.cpp +++ b/src/game/Globals/ObjectMgr.cpp @@ -296,8 +296,8 @@ void ObjectMgr::LoadCreatureLocales() _creatureLocaleStore.clear(); // need for reload case - QueryResult result = WorldDatabase.Query("SELECT entry, name_loc1, subname_loc1, name_loc2, subname_loc2, name_loc3, subname_loc3, name_loc4, subname_loc4, name_loc5, subname_loc5, name_loc6, subname_loc6, name_loc7, subname_loc7, name_loc8, subname_loc8 FROM locales_creature"); - + // 0 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT entry, locale, Name, Title FROM creature_template_locale"); if (!result) return; @@ -305,16 +305,20 @@ void ObjectMgr::LoadCreatureLocales() { Field* fields = result->Fetch(); - uint32 entry = fields[0].GetUInt32(); + uint32 id = fields[0].GetUInt32(); + std::string localeName = fields[1].GetString(); - CreatureLocale& data = _creatureLocaleStore[entry]; + std::string name = fields[2].GetString(); + std::string title = fields[3].GetString(); + + CreatureLocale& data = _creatureLocaleStore[id]; + LocaleConstant locale = GetLocaleByName(localeName); + if (locale == LOCALE_enUS) + continue; + + AddLocaleString(name, locale, data.Name); + AddLocaleString(title, locale, data.Title); - for (uint8 i = 1; i < TOTAL_LOCALES; ++i) - { - LocaleConstant locale = (LocaleConstant) i; - AddLocaleString(fields[1 + 2 * (i - 1)].GetString(), locale, data.Name); - AddLocaleString(fields[1 + 2 * (i - 1) + 1].GetString(), locale, data.SubName); - } } while (result->NextRow()); sLog->outString(">> Loaded %lu creature locale strings in %u ms", (unsigned long)_creatureLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); diff --git a/src/game/Globals/ObjectMgr.h b/src/game/Globals/ObjectMgr.h index f38a431aa9..fb0b5a811d 100644 --- a/src/game/Globals/ObjectMgr.h +++ b/src/game/Globals/ObjectMgr.h @@ -1050,6 +1050,12 @@ class ObjectMgr if (itr == _gameObjectDataStore.end()) return NULL; return &itr->second; } + CreatureLocale const* GetCreatureLocale(uint32 entry) const + { + CreatureLocaleContainer::const_iterator itr = _creatureLocaleStore.find(entry); + if (itr == _creatureLocaleStore.end()) return NULL; + return &itr->second; + } ItemLocale const* GetItemLocale(uint32 entry) const { ItemLocaleContainer::const_iterator itr = _itemLocaleStore.find(entry); diff --git a/src/game/Handlers/QueryHandler.cpp b/src/game/Handlers/QueryHandler.cpp index b5fe9d21cf..50ffc4597d 100644 --- a/src/game/Handlers/QueryHandler.cpp +++ b/src/game/Handlers/QueryHandler.cpp @@ -87,7 +87,45 @@ void WorldSession::HandleCreatureQueryOpcode(WorldPacket & recvData) CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(entry); if (ci) - SendPacket(&ci->queryData); + { + std::string Name, Title; + Name = ci->Name; + Title = ci->SubName; + + LocaleConstant loc_idx = GetSessionDbLocaleIndex(); + if (loc_idx >= 0) + { + if (CreatureLocale const* cl = sObjectMgr->GetCreatureLocale(entry)) + { + ObjectMgr::GetLocaleString(cl->Name, loc_idx, Name); + ObjectMgr::GetLocaleString(cl->Title, loc_idx, Title); + } + } + // guess size + WorldPacket data(SMSG_CREATURE_QUERY_RESPONSE, 100); + data << uint32(entry); // creature entry + data << Name; + data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4, always empty + data << Title; + data << ci->IconName; // "Directions" for guard, string for Icons 2.3.0 + data << uint32(ci->type_flags); // flags + data << uint32(ci->type); // CreatureType.dbc + data << uint32(ci->family); // CreatureFamily.dbc + data << uint32(ci->rank); // Creature Rank (elite, boss, etc) + data << uint32(ci->KillCredit[0]); // new in 3.1, kill credit + data << uint32(ci->KillCredit[1]); // new in 3.1, kill credit + data << uint32(ci->Modelid1); // Modelid1 + data << uint32(ci->Modelid2); // Modelid2 + data << uint32(ci->Modelid3); // Modelid3 + data << uint32(ci->Modelid4); // Modelid4 + data << float(ci->ModHealth); // dmg/hp modifier + data << float(ci->ModMana); // dmg/mana modifier + data << uint8(ci->RacialLeader); + for (uint32 i = 0; i < MAX_CREATURE_QUEST_ITEMS; ++i) + data << uint32(ci->questItems[i]); // itemId[6], quest drop + data << uint32(ci->movementId); // CreatureMovementInfo.dbc + SendPacket(&data); + } else { ;//sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CREATURE_QUERY - NO CREATURE INFO! (GUID: %u, ENTRY: %u)", diff --git a/src/scripts/Commands/cs_lookup.cpp b/src/scripts/Commands/cs_lookup.cpp index c8f72068d1..fda4b5e7c6 100644 --- a/src/scripts/Commands/cs_lookup.cpp +++ b/src/scripts/Commands/cs_lookup.cpp @@ -164,6 +164,33 @@ public: for (CreatureTemplateContainer::const_iterator itr = ctc->begin(); itr != ctc->end(); ++itr) { uint32 id = itr->second.Entry; + uint8 localeIndex = handler->GetSessionDbLocaleIndex(); + if (CreatureLocale const* creatureLocale = sObjectMgr->GetCreatureLocale(id)) + { + if (creatureLocale->Name.size() > localeIndex && !creatureLocale->Name[localeIndex].empty()) + { + std::string name = creatureLocale->Name[localeIndex]; + + if (Utf8FitTo(name, wNamePart)) + { + if (maxResults && count++ == maxResults) + { + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } + + if (handler->GetSession()) + handler->PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str()); + else + handler->PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str()); + + if (!found) + found = true; + + continue; + } + } + } std::string name = itr->second.Name; if (name.empty()) |