Skip to content

Commit

Permalink
feat(Core/GameLocale): implement separated manager for game locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Winfidonarleyan committed Mar 4, 2022
1 parent 065e3b9 commit 78400ef
Show file tree
Hide file tree
Showing 142 changed files with 3,336 additions and 2,394 deletions.
2 changes: 0 additions & 2 deletions src/common/Define.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
#define UI64LIT(N) UINT64_C(N)
#define SI64LIT(N) INT64_C(N)

#define STRING_VIEW_FMT_ARG(str) static_cast<int>((str).length()), (str).data()

typedef std::int64_t int64;
typedef std::int32_t int32;
typedef std::int16_t int16;
Expand Down
2 changes: 1 addition & 1 deletion src/server/authserver/Server/AuthSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "Log.h"
#include "RealmList.h"
#include "SecretMgr.h"
#include "StringConvert.h"
#include "TOTP.h"
#include "Timer.h"
#include "Util.h"
#include "StringConvert.h"
#include <boost/lexical_cast.hpp>
#include <openssl/crypto.h>

Expand Down
2 changes: 1 addition & 1 deletion src/server/database/Database/DatabaseWorkerPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "SQLOperation.h"
#include "Transaction.h"
#include "WorldDatabase.h"
#include <mysqld_error.h>
#include <limits>
#include <mysqld_error.h>

#ifdef ACORE_DEBUG
#include <boost/stacktrace.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/ScriptedAI/ScriptedCreature.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "Creature.h"
#include "CreatureAI.h"
#include "CreatureAIImpl.h"
#include "InstanceScript.h"
#include "EventMap.h"
#include "InstanceScript.h"

#define CAST_AI(a, b) (dynamic_cast<a*>(b))

Expand Down
3 changes: 2 additions & 1 deletion src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ChatTextBuilder.h"
#include "CreatureTextMgr.h"
#include "GameEventMgr.h"
#include "GameLocale.h"
#include "GossipDef.h"
#include "GridDefines.h"
#include "GridNotifiers.h"
Expand Down Expand Up @@ -3092,7 +3093,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
case SMART_ACTION_PLAYER_TALK:
{
ObjectList* targets = GetTargets(e, unit);
char const* text = sObjectMgr->GetAcoreString(e.action.playerTalk.textId, DEFAULT_LOCALE);
char const* text = sGameLocale->GetAcoreString(e.action.playerTalk.textId, DEFAULT_LOCALE);

if (targets)
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
Expand Down
47 changes: 4 additions & 43 deletions src/server/game/Achievements/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "DatabaseEnv.h"
#include "DisableMgr.h"
#include "GameEventMgr.h"
#include "GameLocale.h"
#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Guild.h"
Expand Down Expand Up @@ -2262,10 +2263,10 @@ void AchievementMgr::CompletedAchievement(AchievementEntry const* achievement)
LocaleConstant localeConstant = GetPlayer()->GetSession()->GetSessionDbLocaleIndex();
if (localeConstant != LOCALE_enUS)
{
if(AchievementRewardLocale const* loc = sAchievementMgr->GetAchievementRewardLocale(achievement))
if (AchievementRewardLocale const* loc = sGameLocale->GetAchievementRewardLocale(achievement->ID))
{
ObjectMgr::GetLocaleString(loc->Subject, localeConstant, subject);
ObjectMgr::GetLocaleString(loc->Text, localeConstant, text);
GameLocale::GetLocaleString(loc->Subject, localeConstant, subject);
GameLocale::GetLocaleString(loc->Text, localeConstant, text);
}
}

Expand Down Expand Up @@ -2928,46 +2929,6 @@ void AchievementGlobalMgr::LoadRewards()
LOG_INFO("server.loading", " ");
}

void AchievementGlobalMgr::LoadRewardLocales()
{
uint32 oldMSTime = getMSTime();

m_achievementRewardLocales.clear(); // need for reload case

// 0 1 2 3
QueryResult result = WorldDatabase.Query("SELECT ID, Locale, Subject, Text FROM achievement_reward_locale");

if (!result)
{
LOG_INFO("server.loading", ">> Loaded 0 achievement reward locale strings. DB table `achievement_reward_locale` is empty");
LOG_INFO("server.loading", " ");
return;
}

do
{
Field* fields = result->Fetch();

uint32 ID = fields[0].Get<uint32>();
if (m_achievementRewards.find(ID) == m_achievementRewards.end())
{
LOG_ERROR("sql.sql", "Table `achievement_reward_locale` (Entry: {}) has locale strings for non-existing achievement reward.", ID);
continue;
}

LocaleConstant locale = GetLocaleByName(fields[1].Get<std::string>());
if (locale == LOCALE_enUS)
continue;

AchievementRewardLocale& data = m_achievementRewardLocales[ID];
ObjectMgr::AddLocaleString(fields[2].Get<std::string>(), locale, data.Subject);
ObjectMgr::AddLocaleString(fields[3].Get<std::string>(), locale, data.Text);
} while (result->NextRow());

LOG_INFO("server.loading", ">> Loaded {} Achievement Reward Locale strings in {} ms", (unsigned long)m_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}

AchievementEntry const* AchievementGlobalMgr::GetAchievement(uint32 achievementId) const
{
return sAchievementStore.LookupEntry(achievementId);
Expand Down
16 changes: 0 additions & 16 deletions src/server/game/Achievements/AchievementMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,6 @@ struct AchievementReward

typedef std::map<uint32, AchievementReward> AchievementRewards;

struct AchievementRewardLocale
{
std::vector<std::string> Subject;
std::vector<std::string> Text;
};

typedef std::map<uint32, AchievementRewardLocale> AchievementRewardLocales;

struct CompletedAchievementData
{
time_t date;
Expand Down Expand Up @@ -365,12 +357,6 @@ class AchievementGlobalMgr
return iter != m_achievementRewards.end() ? &iter->second : nullptr;
}

AchievementRewardLocale const* GetAchievementRewardLocale(AchievementEntry const* achievement) const
{
AchievementRewardLocales::const_iterator iter = m_achievementRewardLocales.find(achievement->ID);
return iter != m_achievementRewardLocales.end() ? &iter->second : nullptr;
}

AchievementCriteriaDataSet const* GetCriteriaDataSet(AchievementCriteriaEntry const* achievementCriteria) const
{
AchievementCriteriaDataMap::const_iterator iter = m_criteriaDataMap.find(achievementCriteria->ID);
Expand All @@ -385,7 +371,6 @@ class AchievementGlobalMgr
void LoadAchievementReferenceList();
void LoadCompletedAchievements();
void LoadRewards();
void LoadRewardLocales();

[[nodiscard]] AchievementEntry const* GetAchievement(uint32 achievementId) const;

Expand All @@ -404,7 +389,6 @@ class AchievementGlobalMgr
AllCompletedAchievements m_allCompletedAchievements;

AchievementRewards m_achievementRewards;
AchievementRewardLocales m_achievementRewardLocales;

// pussywizard:
std::map<uint32, AchievementCriteriaEntryList> m_SpecialList[ACHIEVEMENT_CRITERIA_TYPE_TOTAL];
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/ArenaSpectator/ArenaSpectator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool ArenaSpectator::HandleSpectatorSpectateCommand(ChatHandler* handler, std::s
{
handler->PSendSysMessage("To spectate, please fix the following:");
for (std::list<std::string>::const_iterator itr = errors.begin(); itr != errors.end(); ++itr)
handler->PSendSysMessage("- %s", (*itr).c_str());
handler->PSendSysMessage("- {}", (*itr));

return true;
}
Expand Down
17 changes: 9 additions & 8 deletions src/server/game/AuctionHouse/AuctionHouseMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include "Common.h"
#include "DBCStores.h"
#include "DatabaseEnv.h"
#include "GameLocale.h"
#include "GameTime.h"
#include "Item.h"
#include "Logging/Log.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
Expand All @@ -37,7 +38,7 @@ constexpr auto AH_MINIMUM_DEPOSIT = 100;
// Proof of concept, we should shift the info we're obtaining in here into AuctionEntry probably
static bool SortAuction(AuctionEntry* left, AuctionEntry* right, AuctionSortOrderVector& sortOrder, Player* player, bool checkMinBidBuyout)
{
for (auto thisOrder : sortOrder)
for (auto const& thisOrder : sortOrder)
{
switch (thisOrder.sortOrder)
{
Expand Down Expand Up @@ -99,14 +100,14 @@ static bool SortAuction(AuctionEntry* left, AuctionEntry* right, AuctionSortOrde

if (locale > LOCALE_enUS)
{
if (ItemLocale const* leftIl = sObjectMgr->GetItemLocale(protoLeft->ItemId))
if (ItemLocale const* leftIl = sGameLocale->GetItemLocale(protoLeft->ItemId))
{
ObjectMgr::GetLocaleString(leftIl->Name, locale, leftName);
GameLocale::GetLocaleString(leftIl->Name, locale, leftName);
}

if (ItemLocale const* rightIl = sObjectMgr->GetItemLocale(protoRight->ItemId))
if (ItemLocale const* rightIl = sGameLocale->GetItemLocale(protoRight->ItemId))
{
ObjectMgr::GetLocaleString(rightIl->Name, locale, rightName);
GameLocale::GetLocaleString(rightIl->Name, locale, rightName);
}
}

Expand Down Expand Up @@ -831,8 +832,8 @@ bool AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player

// local name
if (loc_idx >= 0)
if (ItemLocale const* il = sObjectMgr->GetItemLocale(proto->ItemId))
ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
if (ItemLocale const* il = sGameLocale->GetItemLocale(proto->ItemId))
GameLocale::GetLocaleString(il->Name, loc_idx, name);

// DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result
// that matches the search but it may not equal item->GetItemRandomPropertyId()
Expand Down
Loading

0 comments on commit 78400ef

Please sign in to comment.