Skip to content

Commit

Permalink
Core/Misc: Update locales_creature_text to simple system
Browse files Browse the repository at this point in the history
  • Loading branch information
ChazyTheBest authored and Aokromes committed May 4, 2017
1 parent 4a0e51a commit d17a45e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 25 deletions.
56 changes: 56 additions & 0 deletions sql/updates/world/3.3.5/2017_05_04_00_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- creature_text
ALTER TABLE `creature_text` CHANGE `entry` `CreatureID` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `groupid` `GroupID` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `id` `ID` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `text` `Text` LONGTEXT;
ALTER TABLE `creature_text` CHANGE `type` `Type` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `language` `Language` TINYINT(3) NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `probability` `Probability` FLOAT UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `emote` `Emote` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `duration` `Duration` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `creature_text` CHANGE `sound` `Sound` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0';

-- creature_text_locale
DROP TABLE IF EXISTS `creature_text_locale`;
CREATE TABLE IF NOT EXISTS `creature_text_locale` (
`CreatureID` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`GroupID` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`ID` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`Locale` VARCHAR(4) NOT NULL,
`Text` TEXT,
PRIMARY KEY (`CreatureID`, `GroupID`, `ID`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;

-- koKR
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "koKR", `text_loc1` FROM `locales_creature_text` WHERE LENGTH(text_loc1) > 0);

-- frFR
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "frFR", `text_loc2` FROM `locales_creature_text` WHERE LENGTH(text_loc2) > 0);

-- deDE
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "deDE", `text_loc3` FROM `locales_creature_text` WHERE LENGTH(text_loc3) > 0);

-- zhCN
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "zhCN", `text_loc4` FROM `locales_creature_text` WHERE LENGTH(text_loc4) > 0);

-- zhTW
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "zhTW", `text_loc5` FROM `locales_creature_text` WHERE LENGTH(text_loc5) > 0);

-- esES
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "esES", `text_loc6` FROM `locales_creature_text` WHERE LENGTH(text_loc6) > 0);

-- esMX
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "esMX", `text_loc7` FROM `locales_creature_text` WHERE LENGTH(text_loc7) > 0);

-- ruRU
INSERT INTO `creature_text_locale` (`CreatureID`, `GroupID`, `ID`, `Locale`, `Text`)
(SELECT `entry`, `groupid`, `id`, "ruRU", `text_loc8` FROM `locales_creature_text` WHERE LENGTH(text_loc8) > 0);

DROP TABLE IF EXISTS `locales_creature_text`;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
48 changes: 26 additions & 22 deletions src/server/game/Texts/CreatureTextMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void CreatureTextMgr::LoadCreatureTexts()
Field* fields = result->Fetch();
CreatureTextEntry temp;

temp.entry = fields[0].GetUInt32();
temp.group = fields[1].GetUInt8();
temp.creatureId = fields[0].GetUInt32();
temp.groupId = fields[1].GetUInt8();
temp.id = fields[2].GetUInt8();
temp.text = fields[3].GetString();
temp.type = ChatMsg(fields[4].GetUInt8());
Expand All @@ -119,28 +119,28 @@ void CreatureTextMgr::LoadCreatureTexts()
{
if (!sSoundEntriesStore.LookupEntry(temp.sound))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Sound %u but sound does not exist.", temp.entry, temp.group, temp.sound);
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Sound %u but sound does not exist.", temp.creatureId, temp.groupId, temp.sound);
temp.sound = 0;
}
}

if (!GetLanguageDescByID(temp.lang))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` using Language %u but Language does not exist.", temp.entry, temp.group, uint32(temp.lang));
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` using Language %u but Language does not exist.", temp.creatureId, temp.groupId, uint32(temp.lang));
temp.lang = LANG_UNIVERSAL;
}

if (temp.type >= MAX_CHAT_MSG_TYPE)
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Type %u but this Chat Type does not exist.", temp.entry, temp.group, uint32(temp.type));
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Type %u but this Chat Type does not exist.", temp.creatureId, temp.groupId, uint32(temp.type));
temp.type = CHAT_MSG_SAY;
}

if (temp.emote)
{
if (!sEmotesStore.LookupEntry(temp.emote))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Emote %u but emote does not exist.", temp.entry, temp.group, uint32(temp.emote));
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Emote %u but emote does not exist.", temp.creatureId, temp.groupId, uint32(temp.emote));
temp.emote = EMOTE_ONESHOT_NONE;
}
}
Expand All @@ -149,19 +149,19 @@ void CreatureTextMgr::LoadCreatureTexts()
{
if (!sObjectMgr->GetBroadcastText(temp.BroadcastTextId))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has non-existing or incompatible BroadcastTextId %u.", temp.entry, temp.group, temp.id, temp.BroadcastTextId);
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has non-existing or incompatible BroadcastTextId %u.", temp.creatureId, temp.groupId, temp.id, temp.BroadcastTextId);
temp.BroadcastTextId = 0;
}
}

if (temp.TextRange > TEXT_RANGE_WORLD)
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect TextRange %u.", temp.entry, temp.group, temp.id, temp.TextRange);
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect TextRange %u.", temp.creatureId, temp.groupId, temp.id, temp.TextRange);
temp.TextRange = TEXT_RANGE_NORMAL;
}

// add the text into our entry's group
mTextMap[temp.entry][temp.group].push_back(temp);
mTextMap[temp.creatureId][temp.groupId].push_back(temp);

++textCount;
}
Expand All @@ -176,27 +176,31 @@ void CreatureTextMgr::LoadCreatureTextLocales()

mLocaleTextMap.clear(); // for reload case

QueryResult result = WorldDatabase.Query("SELECT entry, groupid, id, text_loc1, text_loc2, text_loc3, text_loc4, text_loc5, text_loc6, text_loc7, text_loc8 FROM locales_creature_text");
// 0 1 2 3 4
QueryResult result = WorldDatabase.Query("SELECT CreatureID, GroupID, ID, Locale, Text FROM creature_text_locale");

if (!result)
return;

uint32 textCount = 0;

do
{
Field* fields = result->Fetch();
CreatureTextLocale& loc = mLocaleTextMap[CreatureTextId(fields[0].GetUInt32(), uint32(fields[1].GetUInt8()), uint32(fields[2].GetUInt8()))];
for (uint8 i = TOTAL_LOCALES - 1; i > 0; --i)
{
LocaleConstant locale = LocaleConstant(i);
ObjectMgr::AddLocaleString(fields[3 + i - 1].GetString(), locale, loc.Text);
}

++textCount;
uint32 creatureId = fields[0].GetUInt32();
uint32 groupId = fields[1].GetUInt8();
uint32 id = fields[2].GetUInt8();
std::string localeName = fields[3].GetString();
std::string text = fields[4].GetString();

CreatureTextLocale& data = mLocaleTextMap[CreatureTextId(creatureId, groupId, id)];
LocaleConstant locale = GetLocaleByName(localeName);
if (locale == LOCALE_enUS)
continue;

ObjectMgr::AddLocaleString(text, locale, data.Text);
} while (result->NextRow());

TC_LOG_INFO("server.loading", ">> Loaded %u creature localized texts in %u ms", textCount, GetMSTimeDiffToNow(oldMSTime));
TC_LOG_INFO("server.loading", ">> Loaded %u creature localized texts in %u ms", uint32(mLocaleTextMap.size()), GetMSTimeDiffToNow(oldMSTime));
}

uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject const* whisperTarget /*= nullptr*/, ChatMsg msgType /*= CHAT_MSG_ADDON*/, Language language /*= LANG_ADDON*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/, uint32 sound /*= 0*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/, Player* srcPlr /*= nullptr*/)
Expand Down Expand Up @@ -257,12 +261,12 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject

if (srcPlr)
{
PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, whisperTarget);
PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->groupId, iter->id, finalLang, whisperTarget);
SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
}
else
{
CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, whisperTarget);
CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->groupId, iter->id, finalLang, whisperTarget);
SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Texts/CreatureTextMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ enum CreatureTextRange

struct CreatureTextEntry
{
uint32 entry;
uint8 group;
uint32 creatureId;
uint8 groupId;
uint8 id;
std::string text;
ChatMsg type;
Expand Down

0 comments on commit d17a45e

Please sign in to comment.