Skip to content

Commit

Permalink
Core/DB: Update all locales to actual TrinityCore (#1160)
Browse files Browse the repository at this point in the history
* Core/Misc Update all locales table structure to simple system. Port from TrinityCore
Co-Authored-By: Winfidonarleyan <dowlandtop@yandex.com>
* Core/Db/Gossip Update structure gossip_menu and gossip_menu_action to actual TrinityCore
* Core/DB Update Broadcast system to actual TC
* Core/Mail: implement Quest Mail Sender
* Core/Quest Split quest template locales
  • Loading branch information
Winfidonarleyan authored and Viste(Кирилл) committed Jan 12, 2019
1 parent 76772e4 commit b34bc28
Show file tree
Hide file tree
Showing 26 changed files with 59,395 additions and 523 deletions.
58,795 changes: 58,795 additions & 0 deletions data/sql/updates/pending_db_world/rev_1546089286503990300.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/common/Database/Implementation/WorldDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void WorldDatabaseConnection::DoPrepareStatements()
PrepareStatement(WORLD_SEL_QUEST_POOLS, "SELECT entry, pool_entry FROM pool_quest", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_CRELINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_REP_CREATURE_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT entry, groupid, id, text, type, language, probability, emote, duration, sound, BroadcastTextID, TextRange FROM creature_text", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?", CONNECTION_ASYNC);
Expand Down
32 changes: 17 additions & 15 deletions src/server/game/Achievements/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2878,13 +2878,12 @@ void AchievementGlobalMgr::LoadRewardLocales()

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

QueryResult result = WorldDatabase.Query("SELECT entry, subject_loc1, text_loc1, subject_loc2, text_loc2, subject_loc3, text_loc3, subject_loc4, text_loc4, "
"subject_loc5, text_loc5, subject_loc6, text_loc6, subject_loc7, text_loc7, subject_loc8, text_loc8"
" FROM locales_achievement_reward");
// 0 1 2 3
QueryResult result = WorldDatabase.Query("SELECT ID, Locale, Subject, Text FROM achievement_reward_locale");

if (!result)
{
sLog->outString(">> Loaded 0 achievement reward locale strings. DB table `locales_achievement_reward` is empty");
sLog->outErrorDb(">> Loaded 0 achievement reward locale strings. DB table `achievement_reward_locale` is empty");
sLog->outString();
return;
}
Expand All @@ -2893,24 +2892,27 @@ void AchievementGlobalMgr::LoadRewardLocales()
{
Field* fields = result->Fetch();

uint32 entry = fields[0].GetUInt32();
uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Subject = fields[2].GetString();
std::string Text = fields[3].GetString();

if (m_achievementRewards.find(entry) == m_achievementRewards.end())
if (m_achievementRewards.find(ID) == m_achievementRewards.end())
{
sLog->outErrorDb("Table `locales_achievement_reward` (Entry: %u) has locale strings for non-existing achievement reward.", entry);
sLog->outErrorDb("Table `achievement_reward_locale` (Entry: %u) has locale strings for non-existing achievement reward.", ID);
continue;
}

AchievementRewardLocale& data = m_achievementRewardLocales[entry];
AchievementRewardLocale& data = m_achievementRewardLocales[ID];
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS)
continue;

ObjectMgr::AddLocaleString(Subject, locale, data.Subject);
ObjectMgr::AddLocaleString(Text, locale, data.Text);

for (int i = 1; i < TOTAL_LOCALES; ++i)
{
LocaleConstant locale = (LocaleConstant) i;
ObjectMgr::AddLocaleString(fields[1 + 2 * (i - 1)].GetString(), locale, data.subject);
ObjectMgr::AddLocaleString(fields[1 + 2 * (i - 1) + 1].GetString(), locale, data.text);
}
} while (result->NextRow());

sLog->outString(">> Loaded %lu achievement reward locale strings in %u ms", (unsigned long)m_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime));
sLog->outString(">> Loaded %lu Achievement Reward Locale strings in %u ms", (unsigned long)m_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
4 changes: 2 additions & 2 deletions src/server/game/Achievements/AchievementMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ typedef std::map<uint32, AchievementReward> AchievementRewards;

struct AchievementRewardLocale
{
StringVector subject;
StringVector text;
StringVector Subject;
StringVector Text;
};

typedef std::map<uint32, AchievementRewardLocale> AchievementRewardLocales;
Expand Down
20 changes: 10 additions & 10 deletions src/server/game/Battlegrounds/Battleground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Trinity
class BattlegroundChatBuilder
{
public:
BattlegroundChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, va_list* args = NULL)
BattlegroundChatBuilder(ChatMsg msgtype, uint32 textId, Player const* source, va_list* args = NULL)
: _msgtype(msgtype), _textId(textId), _source(source), _args(args) { }

void operator()(WorldPacket& data, LocaleConstant loc_idx)
Expand Down Expand Up @@ -70,15 +70,15 @@ namespace Trinity
}

ChatMsg _msgtype;
int32 _textId;
uint32 _textId;
Player const* _source;
va_list* _args;
};

class Battleground2ChatBuilder
{
public:
Battleground2ChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, int32 arg1, int32 arg2)
Battleground2ChatBuilder(ChatMsg msgtype, uint32 textId, Player const* source, int32 arg1, int32 arg2)
: _msgtype(msgtype), _textId(textId), _source(source), _arg1(arg1), _arg2(arg2) {}

void operator()(WorldPacket& data, LocaleConstant loc_idx)
Expand All @@ -95,10 +95,10 @@ namespace Trinity

private:
ChatMsg _msgtype;
int32 _textId;
uint32 _textId;
Player const* _source;
int32 _arg1;
int32 _arg2;
uint32 _arg1;
uint32 _arg2;
};
} // namespace Trinity

Expand Down Expand Up @@ -1693,7 +1693,7 @@ bool Battleground::AddSpiritGuide(uint32 type, float x, float y, float z, float
return false;
}

void Battleground::SendMessageToAll(int32 entry, ChatMsg type, Player const* source)
void Battleground::SendMessageToAll(uint32 entry, ChatMsg type, Player const* source)
{
if (!entry)
return;
Expand All @@ -1703,7 +1703,7 @@ void Battleground::SendMessageToAll(int32 entry, ChatMsg type, Player const* sou
BroadcastWorker(bg_do);
}

void Battleground::PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...)
void Battleground::PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...)
{
if (!entry)
return;
Expand All @@ -1718,7 +1718,7 @@ void Battleground::PSendMessageToAll(int32 entry, ChatMsg type, Player const* so
va_end(ap);
}

void Battleground::SendWarningToAll(int32 entry, ...)
void Battleground::SendWarningToAll(uint32 entry, ...)
{
if (!entry)
return;
Expand All @@ -1743,7 +1743,7 @@ void Battleground::SendWarningToAll(int32 entry, ...)
}
}

void Battleground::SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 arg1, int32 arg2)
void Battleground::SendMessage2ToAll(uint32 entry, ChatMsg type, Player const* source, uint32 arg1, uint32 arg2)
{
Trinity::Battleground2ChatBuilder bg_builder(type, entry, source, arg1, arg2);
Trinity::LocalizedPacketDo<Trinity::Battleground2ChatBuilder> bg_do(bg_builder);
Expand Down
8 changes: 4 additions & 4 deletions src/server/game/Battlegrounds/Battleground.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,12 @@ class Battleground
void EndBattleground(TeamId winnerTeamId);
void BlockMovement(Player* player);

void SendWarningToAll(int32 entry, ...);
void SendMessageToAll(int32 entry, ChatMsg type, Player const* source = NULL);
void PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...);
void SendWarningToAll(uint32 entry, ...);
void SendMessageToAll(uint32 entry, ChatMsg type, Player const* source = NULL);
void PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...);

// specialized version with 2 string id args
void SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 strId1 = 0, int32 strId2 = 0);
void SendMessage2ToAll(uint32 entry, ChatMsg type, Player const* source, uint32 strId1 = 0, uint32 strId2 = 0);

// Raid Group
Group* GetBgRaid(TeamId teamId) const { return m_BgRaids[teamId]; }
Expand Down
10 changes: 5 additions & 5 deletions src/server/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::vector<ChatCommand> const& ChatHandler::getCommandTable()
return commandTableCache;
}

std::string ChatHandler::PGetParseString(int32 entry, ...) const
std::string ChatHandler::PGetParseString(uint32 entry, ...) const
{
const char *format = GetTrinityString(entry);
char str[1024];
Expand All @@ -70,7 +70,7 @@ std::string ChatHandler::PGetParseString(int32 entry, ...) const
return std::string(str);
}

const char *ChatHandler::GetTrinityString(int32 entry) const
char const* ChatHandler::GetTrinityString(uint32 entry) const
{
return m_session->GetTrinityString(entry);
}
Expand Down Expand Up @@ -209,12 +209,12 @@ void ChatHandler::SendGlobalGMSysMessage(const char *str)
free(buf);
}

void ChatHandler::SendSysMessage(int32 entry)
void ChatHandler::SendSysMessage(uint32 entry)
{
SendSysMessage(GetTrinityString(entry));
}

void ChatHandler::PSendSysMessage(int32 entry, ...)
void ChatHandler::PSendSysMessage(uint32 entry, ...)
{
const char *format = GetTrinityString(entry);
va_list ap;
Expand Down Expand Up @@ -1217,7 +1217,7 @@ std::string ChatHandler::GetNameLink(Player* chr) const
return playerLink(chr->GetName());
}

const char *CliHandler::GetTrinityString(int32 entry) const
char const* CliHandler::GetTrinityString(uint32 entry) const
{
return sObjectMgr->GetTrinityStringForDBCLocale(entry);
}
Expand Down
26 changes: 13 additions & 13 deletions src/server/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class ChatHandler
static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = NULL; return start; }

// function with different implementation for chat/console
virtual const char *GetTrinityString(int32 entry) const;
virtual void SendSysMessage(const char *str);
virtual char const* GetTrinityString(uint32 entry) const;
virtual void SendSysMessage(char const* str);

void SendSysMessage(int32 entry);
void PSendSysMessage(const char *format, ...) ATTR_PRINTF(2, 3);
void PSendSysMessage(int32 entry, ...);
std::string PGetParseString(int32 entry, ...) const;
void SendSysMessage(uint32 entry);
void PSendSysMessage(char const* format, ...) ATTR_PRINTF(2, 3);
void PSendSysMessage(uint32 entry, ...);
std::string PGetParseString(uint32 entry, ...) const;

bool ParseCommands(const char* text);

Expand Down Expand Up @@ -139,13 +139,13 @@ class CliHandler : public ChatHandler
explicit CliHandler(void* callbackArg, Print* zprint) : m_callbackArg(callbackArg), m_print(zprint) {}

// overwrite functions
const char *GetTrinityString(int32 entry) const;
bool isAvailable(ChatCommand const& cmd) const;
void SendSysMessage(const char *str);
std::string GetNameLink() const;
bool needReportToTarget(Player* chr) const;
LocaleConstant GetSessionDbcLocale() const;
int GetSessionDbLocaleIndex() const;
char const* GetTrinityString(uint32 entry) const override;
bool isAvailable(ChatCommand const& cmd) const override;
void SendSysMessage(const char *str) override;
std::string GetNameLink() const override;
bool needReportToTarget(Player* chr) const override;
LocaleConstant GetSessionDbcLocale() const override;
int GetSessionDbLocaleIndex() const override;

private:
void* m_callbackArg;
Expand Down
6 changes: 3 additions & 3 deletions src/server/game/Conditions/ConditionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,9 +1117,9 @@ bool ConditionMgr::addToGossipMenus(Condition* cond)
{
for (GossipMenusContainer::iterator itr = pMenuBounds.first; itr != pMenuBounds.second; ++itr)
{
if ((*itr).second.entry == cond->SourceGroup && (*itr).second.text_id == uint32(cond->SourceEntry))
if ((*itr).second.MenuID == cond->SourceGroup && (*itr).second.TextID == uint32(cond->SourceEntry))
{
(*itr).second.conditions.push_back(cond);
(*itr).second.Conditions.push_back(cond);
return true;
}
}
Expand All @@ -1136,7 +1136,7 @@ bool ConditionMgr::addToGossipMenuItems(Condition* cond)
{
for (GossipMenuItemsContainer::iterator itr = pMenuItemBounds.first; itr != pMenuItemBounds.second; ++itr)
{
if ((*itr).second.MenuId == cond->SourceGroup && (*itr).second.OptionIndex == uint32(cond->SourceEntry))
if ((*itr).second.MenuID == cond->SourceGroup && (*itr).second.OptionID == uint32(cond->SourceEntry))
{
(*itr).second.Conditions.push_back(cond);
return true;
Expand Down
53 changes: 37 additions & 16 deletions src/server/game/Entities/Creature/GossipDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,44 @@ void GossipMenu::AddMenuItem(uint32 menuId, uint32 menuItemId, uint32 sender, ui
for (GossipMenuItemsContainer::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
/// Find the one with the given menu item id.
if (itr->second.OptionIndex != menuItemId)
if (itr->second.OptionID != menuItemId)
continue;

/// Store texts for localization.
std::string strOptionText = itr->second.OptionText;
std::string strBoxText = itr->second.BoxText;
std::string strOptionText, strBoxText;
BroadcastText const* optionBroadcastText = sObjectMgr->GetBroadcastText(itr->second.OptionBroadcastTextID);
BroadcastText const* boxBroadcastText = sObjectMgr->GetBroadcastText(itr->second.BoxBroadcastTextID);

/// OptionText
if (optionBroadcastText)
ObjectMgr::GetLocaleString(optionBroadcastText->MaleText, GetLocale(), strOptionText);
else
strOptionText = itr->second.OptionText;

/// BoxText
if (boxBroadcastText)
ObjectMgr::GetLocaleString(boxBroadcastText->MaleText, GetLocale(), strBoxText);
else
strBoxText = itr->second.BoxText;

/// Check need of localization.
if (GetLocale() != DEFAULT_LOCALE)
/// Find localizations from database.
if (GossipMenuItemsLocale const* no = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
{
if (!optionBroadcastText)
{
/// Translate texts if there are any.
ObjectMgr::GetLocaleString(no->OptionText, GetLocale(), strOptionText);
ObjectMgr::GetLocaleString(no->BoxText, GetLocale(), strBoxText);
/// Find localizations from database.
if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
ObjectMgr::GetLocaleString(gossipMenuLocale->OptionText, GetLocale(), strOptionText);
}

if (!boxBroadcastText)
{
/// Find localizations from database.
if (GossipMenuItemsLocale const* gossipMenuLocale = sObjectMgr->GetGossipMenuItemsLocale(MAKE_PAIR32(menuId, menuItemId)))
ObjectMgr::GetLocaleString(gossipMenuLocale->BoxText, GetLocale(), strBoxText);
}
}

/// Add menu item with existing method. Menu item id -1 is also used in ADD_GOSSIP_ITEM macro.
AddMenuItem(-1, itr->second.OptionIcon, strOptionText, sender, action, strBoxText, itr->second.BoxMoney, itr->second.BoxCoded);
}
Expand Down Expand Up @@ -588,23 +609,23 @@ void PlayerMenu::SendQuestQueryResponse(Quest const* quest) const
void PlayerMenu::SendQuestGiverOfferReward(Quest const* quest, uint64 npcGUID, bool enableNext) const
{
std::string questTitle = quest->GetTitle();
std::string questOfferRewardText = quest->GetOfferRewardText();
std::string RewardText = quest->GetOfferRewardText();

int32 locale = _session->GetSessionDbLocaleIndex();
if (locale >= 0)
{
if (QuestLocale const* localeData = sObjectMgr->GetQuestLocale(quest->GetQuestId()))
{
ObjectMgr::GetLocaleString(localeData->Title, locale, questTitle);
ObjectMgr::GetLocaleString(localeData->OfferRewardText, locale, questOfferRewardText);
}

if (QuestOfferRewardLocale const* questOfferRewardLocale = sObjectMgr->GetQuestOfferRewardLocale(quest->GetQuestId()))
ObjectMgr::GetLocaleString(questOfferRewardLocale->RewardText, locale, RewardText);
}

WorldPacket data(SMSG_QUESTGIVER_OFFER_REWARD, 400); // guess size
data << uint64(npcGUID);
data << uint32(quest->GetQuestId());
data << questTitle;
data << questOfferRewardText;
data << RewardText;

data << uint8(enableNext ? 1 : 0); // Auto Finish
data << uint32(quest->GetFlags()); // 3.3.3 questFlags
Expand Down Expand Up @@ -690,10 +711,10 @@ void PlayerMenu::SendQuestGiverRequestItems(Quest const* quest, uint64 npcGUID,
if (locale >= 0)
{
if (QuestLocale const* localeData = sObjectMgr->GetQuestLocale(quest->GetQuestId()))
{
ObjectMgr::GetLocaleString(localeData->Title, locale, questTitle);
ObjectMgr::GetLocaleString(localeData->RequestItemsText, locale, requestItemsText);
}

if (QuestRequestItemsLocale const* questRequestItemsLocale = sObjectMgr->GetQuestRequestItemsLocale(quest->GetQuestId()))
ObjectMgr::GetLocaleString(questRequestItemsLocale->CompletionText, locale, requestItemsText);
}

if (!quest->GetReqItemsCount() && canComplete)
Expand Down
Loading

0 comments on commit b34bc28

Please sign in to comment.