Core/Creature: Localization creatures. (#224)

This commit is contained in:
HeartWell
2016-11-05 17:28:49 +03:00
committed by Shin
parent a52fbb398f
commit 55873c1891
7 changed files with 218087 additions and 13 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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();
}

View File

@@ -218,7 +218,7 @@ typedef UNORDERED_MAP<uint16, CreatureBaseStats> CreatureBaseStatsContainer;
struct CreatureLocale
{
StringVector Name;
StringVector SubName;
StringVector Title;
};
struct GossipMenuItemsLocale

View File

@@ -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));

View File

@@ -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);

View File

@@ -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)",

View File

@@ -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())