Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public override ServerPacket Invoke(Locale locale)
        {
            BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(_textId);
            var packet = new ChatPkt();

            packet.Initialize(_msgType, bct != null ? (Language)bct.LanguageID : Language.Universal, _source, _target, bct != null ? Global.DB2Mgr.GetBroadcastTextValue(bct, locale, _gender) : "", _achievementId, "", locale);
            return(packet);
        }
Exemplo n.º 3
0
        public string GetDefenseMessage(uint zoneId, uint id, Locale locale)
        {
            BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(id);

            if (bct != null)
            {
                return(Global.DB2Mgr.GetBroadcastTextValue(bct, locale));
            }

            Log.outError(LogFilter.Outdoorpvp, "Can not find DefenseMessage (Zone: {0}, Id: {1}). BroadcastText (Id: {2}) does not exist.", zoneId, id, id);
            return("");
        }
Exemplo n.º 4
0
        public uint SendChat(Creature source, byte textGroup, WorldObject whisperTarget = null, ChatMsg msgType = ChatMsg.Addon, Language language = Language.Addon,
                             CreatureTextRange range = CreatureTextRange.Normal, uint sound = 0, Team team = Team.Other, bool gmOnly = false, Player srcPlr = null)
        {
            if (source == null)
            {
                return(0);
            }

            var sList = mTextMap.LookupByKey(source.GetEntry());

            if (sList == null)
            {
                Log.outError(LogFilter.Sql, "GossipManager: Could not find Text for Creature({0}) Entry {1} in 'creature_text' table. Ignoring.", source.GetName(), source.GetEntry());
                return(0);
            }

            var textGroupContainer = sList.LookupByKey(textGroup);

            if (textGroupContainer.Empty())
            {
                Log.outError(LogFilter.ChatSystem, "GossipManager: Could not find TextGroup {0} for Creature({1}) GuidLow {2} Entry {3}. Ignoring.", textGroup, source.GetName(), source.GetGUID().ToString(), source.GetEntry());
                return(0);
            }

            List <CreatureTextEntry> tempGroup = new List <CreatureTextEntry>();
            var repeatGroup = source.GetTextRepeatGroup(textGroup);

            foreach (var entry in textGroupContainer)
            {
                if (!repeatGroup.Contains(entry.id))
                {
                    tempGroup.Add(entry);
                }
            }

            if (tempGroup.Empty())
            {
                source.ClearTextRepeatGroup(textGroup);
                tempGroup = textGroupContainer;
            }

            var textEntry = tempGroup.SelectRandomElementByWeight(t => t.probability);

            ChatMsg  finalType  = (msgType == ChatMsg.Addon) ? textEntry.type : msgType;
            Language finalLang  = (language == Language.Addon) ? textEntry.lang : language;
            uint     finalSound = textEntry.sound;

            if (sound != 0)
            {
                finalSound = sound;
            }
            else
            {
                BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(textEntry.BroadcastTextId);
                if (bct != null)
                {
                    uint broadcastTextSoundId = bct.SoundEntriesID[source.GetGender() == Gender.Female ? 1 : 0];
                    if (broadcastTextSoundId != 0)
                    {
                        finalSound = broadcastTextSoundId;
                    }
                }
            }

            if (range == CreatureTextRange.Normal)
            {
                range = textEntry.TextRange;
            }

            if (finalSound != 0)
            {
                SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly);
            }

            Unit finalSource = source;

            if (srcPlr)
            {
                finalSource = srcPlr;
            }

            if (textEntry.emote != 0)
            {
                SendEmote(finalSource, textEntry.emote);
            }

            if (srcPlr)
            {
                PlayerTextBuilder builder = new PlayerTextBuilder(source, finalSource, finalSource.GetGender(), finalType, textEntry.groupId, textEntry.id, finalLang, whisperTarget);
                SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
            }
            else
            {
                CreatureTextBuilder builder = new CreatureTextBuilder(finalSource, finalSource.GetGender(), finalType, textEntry.groupId, textEntry.id, finalLang, whisperTarget);
                SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
            }

            source.SetTextRepeatId(textGroup, textEntry.id);
            return(textEntry.duration);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a localized gossip menu item from db by menu id and menu item id.
        /// </summary>
        /// <param name="menuId">menuId Gossip menu id.</param>
        /// <param name="optionIndex">menuItemId Gossip menu item id.</param>
        /// <param name="sender">sender Identifier of the current menu.</param>
        /// <param name="action">action Custom action given to OnGossipHello.</param>
        public void AddMenuItem(uint menuId, uint optionIndex, uint sender, uint action)
        {
            // Find items for given menu id.
            var bounds = Global.ObjectMgr.GetGossipMenuItemsMapBounds(menuId);

            // Return if there are none.
            if (bounds.Empty())
            {
                return;
            }

            // Iterate over each of them.
            foreach (var item in bounds)
            {
                // Find the one with the given menu item id.
                if (item.OptionIndex != optionIndex)
                {
                    continue;
                }

                // Store texts for localization.
                string strOptionText = "", strBoxText = "";
                BroadcastTextRecord optionBroadcastText = CliDB.BroadcastTextStorage.LookupByKey(item.OptionBroadcastTextId);
                BroadcastTextRecord boxBroadcastText    = CliDB.BroadcastTextStorage.LookupByKey(item.BoxBroadcastTextId);

                // OptionText
                if (optionBroadcastText != null)
                {
                    strOptionText = Global.DB2Mgr.GetBroadcastTextValue(optionBroadcastText, GetLocale());
                }
                else
                {
                    strOptionText = item.OptionText;
                }

                // BoxText
                if (boxBroadcastText != null)
                {
                    strBoxText = Global.DB2Mgr.GetBroadcastTextValue(boxBroadcastText, GetLocale());
                }
                else
                {
                    strBoxText = item.BoxText;
                }

                // Check need of localization.
                if (GetLocale() != Locale.enUS)
                {
                    if (optionBroadcastText == null)
                    {
                        // Find localizations from database.
                        GossipMenuItemsLocale gossipMenuLocale = Global.ObjectMgr.GetGossipMenuItemsLocale(menuId, optionIndex);
                        if (gossipMenuLocale != null)
                        {
                            ObjectManager.GetLocaleString(gossipMenuLocale.OptionText, GetLocale(), ref strOptionText);
                        }
                    }

                    if (boxBroadcastText == null)
                    {
                        // Find localizations from database.
                        GossipMenuItemsLocale gossipMenuLocale = Global.ObjectMgr.GetGossipMenuItemsLocale(menuId, optionIndex);
                        if (gossipMenuLocale != null)
                        {
                            ObjectManager.GetLocaleString(gossipMenuLocale.BoxText, GetLocale(), ref strBoxText);
                        }
                    }
                }

                // Add menu item with existing method. Menu item id -1 is also used in ADD_GOSSIP_ITEM macro.
                uint newOptionIndex = AddMenuItem(-1, item.OptionIcon, strOptionText, sender, action, strBoxText, item.BoxMoney, item.BoxCoded);
                AddGossipMenuItemData(newOptionIndex, item.ActionMenuId, item.ActionPoiId);
            }
        }