fix(Core/Creature): quest_greeting_locale (#19615)

* fix(Core/Creature): quest_greeting_locale

* closes https://github.com/azerothcore/azerothcore-wotlk/issues/14845
This commit is contained in:
Kitzunu
2024-08-13 21:09:36 +02:00
committed by GitHub
parent 7fbc655da6
commit 2e02c76399
6 changed files with 53 additions and 83 deletions

View File

@@ -6213,7 +6213,7 @@ void ObjectMgr::LoadQuestAreaTriggers()
QuestGreeting const* ObjectMgr::GetQuestGreeting(TypeID type, uint32 id) const
{
uint32 typeIndex;
uint8 typeIndex;
if (type == TYPEID_UNIT)
typeIndex = 0;
else if (type == TYPEID_GAMEOBJECT)
@@ -6221,15 +6221,19 @@ QuestGreeting const* ObjectMgr::GetQuestGreeting(TypeID type, uint32 id) const
else
return nullptr;
return Acore::Containers::MapGetValuePtr(_questGreetingStore[typeIndex], id);
std::pair<uint32, uint8> pairKey = std::make_pair(id, typeIndex);
QuestGreetingContainer::const_iterator itr = _questGreetingStore.find(pairKey);
if (itr == _questGreetingStore.end())
return nullptr;
return &itr->second;
}
void ObjectMgr::LoadQuestGreetings()
{
uint32 oldMSTime = getMSTime();
for (std::size_t i = 0; i < _questGreetingStore.size(); ++i)
_questGreetingStore[i].clear();
_questGreetingStore.clear(); // For reload case
// 0 1 2 3 4
QueryResult result = WorldDatabase.Query("SELECT ID, Type, GreetEmoteType, GreetEmoteDelay, Greeting FROM quest_greeting");
@@ -6239,8 +6243,6 @@ void ObjectMgr::LoadQuestGreetings()
return;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
@@ -6249,35 +6251,35 @@ void ObjectMgr::LoadQuestGreetings()
uint8 type = fields[1].Get<uint8>();
switch (type)
{
case 0: // Creature
if (!sObjectMgr->GetCreatureTemplate(id))
{
LOG_ERROR("sql.sql", "Table `quest_greeting`: creature template entry {} does not exist.", id);
case 0: // Creature
if (!sObjectMgr->GetCreatureTemplate(id))
{
LOG_ERROR("sql.sql", "Table `quest_greeting`: creature template entry {} does not exist.", id);
continue;
}
break;
case 1: // GameObject
if (!sObjectMgr->GetGameObjectTemplate(id))
{
LOG_ERROR("sql.sql", "Table `quest_greeting`: gameobject template entry {} does not exist.", id);
continue;
}
break;
default:
LOG_ERROR("sql.sql", "Table `quest_greeting` has unknown type {} for id {}, skipped.", type, id);
continue;
}
break;
case 1: // GameObject
if (!sObjectMgr->GetGameObjectTemplate(id))
{
LOG_ERROR("sql.sql", "Table `quest_greeting`: gameobject template entry {} does not exist.", id);
continue;
}
break;
default:
continue;
}
uint16 greetEmoteType = fields[2].Get<uint16>();
uint32 greetEmoteDelay = fields[3].Get<uint32>();
std::string greeting = fields[4].Get<std::string>();
std::pair<uint32, uint8> pairKey = std::make_pair(id, type);
QuestGreeting& data = _questGreetingStore[pairKey];
_questGreetingStore[type].emplace(std::piecewise_construct, std::forward_as_tuple(id), std::forward_as_tuple(greetEmoteType, greetEmoteDelay, std::move(greeting)));
++count;
data.EmoteType = fields[2].Get<uint16>();
data.EmoteDelay = fields[3].Get<uint32>();
AddLocaleString(fields[4].Get<std::string>(), LOCALE_enUS, data.Greeting);
}
while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded {} quest_greeting in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", ">> Loaded {} quest_greeting in {} ms", _questGreetingStore.size(), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
@@ -6285,8 +6287,6 @@ void ObjectMgr::LoadQuestGreetingsLocales()
{
uint32 oldMSTime = getMSTime();
_questGreetingLocaleStore.clear();
// 0 1 2 3
QueryResult result = WorldDatabase.Query("SELECT ID, Type, Locale, Greeting FROM quest_greeting_locale");
if (!result)
@@ -6295,6 +6295,7 @@ void ObjectMgr::LoadQuestGreetingsLocales()
return;
}
uint32 localeCount = 0;
do
{
Field* fields = result->Fetch();
@@ -6321,17 +6322,25 @@ void ObjectMgr::LoadQuestGreetingsLocales()
continue;
}
std::string localeName = fields[2].Get<std::string>();
std::pair<uint32, uint8> pairKey = std::make_pair(id, type);
QuestGreeting& data = _questGreetingStore[pairKey];
LocaleConstant locale = GetLocaleByName(localeName);
QuestGreetingContainer::iterator qgc = _questGreetingStore.find(pairKey);
if (qgc == _questGreetingStore.end())
{
LOG_ERROR("sql.sql", "QuestGreeting (Id: {} Type: {}) found in table `quest_greeting_locale` but does not exist in `quest_greeting`. Skipped!", id, type);
continue;
}
LocaleConstant locale = GetLocaleByName(fields[2].Get<std::string>());
if (locale == LOCALE_enUS)
continue;
QuestGreetingLocale& data = _questGreetingLocaleStore[MAKE_PAIR32(type, id)];
AddLocaleString(fields[3].Get<std::string>(), locale, data.Greeting);
localeCount++;
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded {} quest greeting Locale Strings in {} ms", (uint32)_questGreetingLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", ">> Loaded {} quest greeting Locale Strings in {} ms", localeCount, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}