public string GetLocalizedChatString(uint entry, Gender gender, byte textGroup, uint id, Locale locale = Locale.enUS)
        {
            var multiMap = mTextMap.LookupByKey(entry);

            if (multiMap == null)
            {
                return("");
            }

            var creatureTextEntryList = multiMap.LookupByKey(textGroup);

            if (creatureTextEntryList.Empty())
            {
                return("");
            }

            CreatureTextEntry creatureTextEntry = null;

            for (var i = 0; i != creatureTextEntryList.Count; ++i)
            {
                creatureTextEntry = creatureTextEntryList[i];
                if (creatureTextEntry.id == id)
                {
                    break;
                }
            }

            if (creatureTextEntry == null)
            {
                return("");
            }

            if (locale >= Locale.Total)
            {
                locale = Locale.enUS;
            }

            string baseText         = "";
            BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(creatureTextEntry.BroadcastTextId);

            if (bct != null)
            {
                baseText = Global.DB2Mgr.GetBroadcastTextValue(bct, locale, gender);
            }
            else
            {
                baseText = creatureTextEntry.text;
            }

            if (locale != Locale.enUS && bct == null)
            {
                var creatureTextLocale = mLocaleTextMap.LookupByKey(new CreatureTextId(entry, textGroup, id));
                if (creatureTextLocale != null)
                {
                    ObjectManager.GetLocaleString(creatureTextLocale.Text, locale, ref baseText);
                }
            }

            return(baseText);
        }
 public void AddText(uint group, CreatureTextEntry entry)
 {
     Groups.Add(group, entry);
 }
        public void LoadCreatureTexts()
        {
            uint oldMSTime = Time.GetMSTime();

            mTextMap.Clear(); // for reload case
            //all currently used temp texts are NOT reset

            PreparedStatement stmt   = DB.World.GetPreparedStatement(WorldStatements.SEL_CREATURE_TEXT);
            SQLResult         result = DB.World.Query(stmt);

            if (result.IsEmpty())
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 ceature texts. DB table `creature_texts` is empty.");
                return;
            }

            uint textCount     = 0;
            uint creatureCount = 0;

            do
            {
                CreatureTextEntry temp = new CreatureTextEntry();

                temp.creatureId      = result.Read <uint>(0);
                temp.groupId         = result.Read <byte>(1);
                temp.id              = result.Read <byte>(2);
                temp.text            = result.Read <string>(3);
                temp.type            = (ChatMsg)result.Read <byte>(4);
                temp.lang            = (Language)result.Read <byte>(5);
                temp.probability     = result.Read <float>(6);
                temp.emote           = (Emote)result.Read <uint>(7);
                temp.duration        = result.Read <uint>(8);
                temp.sound           = result.Read <uint>(9);
                temp.BroadcastTextId = result.Read <uint>(10);
                temp.TextRange       = (CreatureTextRange)result.Read <byte>(11);

                if (temp.sound != 0)
                {
                    if (!CliDB.SoundKitStorage.ContainsKey(temp.sound))
                    {
                        Log.outError(LogFilter.Sql, "GossipManager:  Entry {0}, Group {1} in table `creature_texts` has Sound {2} but sound does not exist.", temp.creatureId, temp.groupId, temp.sound);
                        temp.sound = 0;
                    }
                }
                if (ObjectManager.GetLanguageDescByID(temp.lang) == null)
                {
                    Log.outError(LogFilter.Sql, "GossipManager:  Entry {0}, Group {1} in table `creature_texts` using Language {2} but Language does not exist.", temp.creatureId, temp.groupId, temp.lang);
                    temp.lang = Language.Universal;
                }
                if (temp.type >= ChatMsg.Max)
                {
                    Log.outError(LogFilter.Sql, "GossipManager:  Entry {0}, Group {1} in table `creature_texts` has Type {2} but this Chat Type does not exist.", temp.creatureId, temp.groupId, temp.type);
                    temp.type = ChatMsg.Say;
                }
                if (temp.emote != 0)
                {
                    if (!CliDB.EmotesStorage.ContainsKey((uint)temp.emote))
                    {
                        Log.outError(LogFilter.Sql, "GossipManager:  Entry {0}, Group {1} in table `creature_texts` has Emote {2} but emote does not exist.", temp.creatureId, temp.groupId, temp.emote);
                        temp.emote = Emote.OneshotNone;
                    }
                }

                if (temp.BroadcastTextId != 0)
                {
                    if (!CliDB.BroadcastTextStorage.ContainsKey(temp.BroadcastTextId))
                    {
                        Log.outError(LogFilter.Sql, "CreatureTextMgr: Entry {0}, Group {1}, Id {2} in table `creature_texts` has non-existing or incompatible BroadcastTextId {3}.", temp.creatureId, temp.groupId, temp.id, temp.BroadcastTextId);
                        temp.BroadcastTextId = 0;
                    }
                }

                if (temp.TextRange > CreatureTextRange.World)
                {
                    Log.outError(LogFilter.Sql, "CreatureTextMgr: Entry {0}, Group {1}, Id {2} in table `creature_text` has incorrect TextRange {3}.", temp.creatureId, temp.groupId, temp.id, temp.TextRange);
                    temp.TextRange = CreatureTextRange.Normal;
                }

                if (!mTextMap.ContainsKey(temp.creatureId))
                {
                    mTextMap[temp.creatureId] = new MultiMap <byte, CreatureTextEntry>();
                    ++creatureCount;
                }

                mTextMap[temp.creatureId].Add(temp.groupId, temp);
                ++textCount;
            } while (result.NextRow());

            Log.outInfo(LogFilter.ServerLoading, "Loaded {0} creature texts for {1} creatures in {2} ms", textCount, creatureCount, Time.GetMSTimeDiffToNow(oldMSTime));
        }