Exemplo n.º 1
0
 public TextEntry(string text, CreatureTextType type, uint language, uint emote, uint sound)
 {
     Text             = text;
     Type             = type;
     Language         = language;
     Emote            = emote;
     Sound            = sound;
     Probability      = 100;
     Range            = CreatureTextRange.Normal;
     IsInSniffText    = true;
     IsInDatabaseText = false;
 }
Exemplo n.º 2
0
 public TextEntry(ICreatureText text)
 {
     IsInSniffText    = false;
     IsInDatabaseText = true;
     Text             = text.Text ?? "";
     Type             = text.Type;
     Language         = text.Language;
     Emote            = text.Emote;
     Sound            = text.Sound;
     GroupId          = text.GroupId;
     Probability      = text.Probability;
     Duration         = text.Duration;
     Range            = text.TextRange;
     Id = text.Id;
     BroadcastTextId = text.BroadcastTextId;
     Comment         = text.Comment;
 }
Exemplo n.º 3
0
        public void SendChatPacket(WorldObject source, MessageBuilder builder, ChatMsg msgType, WorldObject whisperTarget = null, CreatureTextRange range = CreatureTextRange.Normal, Team team = Team.Other, bool gmOnly = false)
        {
            if (source == null)
            {
                return;
            }

            var localizer = new CreatureTextLocalizer(builder, msgType);

            switch (msgType)
            {
            case ChatMsg.MonsterWhisper:
            case ChatMsg.RaidBossWhisper:
            {
                if (range == CreatureTextRange.Normal)         //ignores team and gmOnly
                {
                    if (!whisperTarget || !whisperTarget.IsTypeId(TypeId.Player))
                    {
                        return;
                    }

                    localizer.Invoke(whisperTarget.ToPlayer());
                    return;
                }
                break;
            }

            default:
                break;
            }

            switch (range)
            {
            case CreatureTextRange.Area:
            {
                uint areaId  = source.GetAreaId();
                var  players = source.GetMap().GetPlayers();
                foreach (var pl in players)
                {
                    if (pl.GetAreaId() == areaId && (team == 0 || pl.GetTeam() == team) && (!gmOnly || pl.IsGameMaster()))
                    {
                        localizer.Invoke(pl);
                    }
                }
                return;
            }

            case CreatureTextRange.Zone:
            {
                uint zoneId  = source.GetZoneId();
                var  players = source.GetMap().GetPlayers();
                foreach (var pl in players)
                {
                    if (pl.GetZoneId() == zoneId && (team == 0 || pl.GetTeam() == team) && (!gmOnly || pl.IsGameMaster()))
                    {
                        localizer.Invoke(pl);
                    }
                }
                return;
            }

            case CreatureTextRange.Map:
            {
                var players = source.GetMap().GetPlayers();
                foreach (var pl in players)
                {
                    if ((team == 0 || pl.GetTeam() == team) && (!gmOnly || pl.IsGameMaster()))
                    {
                        localizer.Invoke(pl);
                    }
                }
                return;
            }

            case CreatureTextRange.World:
            {
                var smap = Global.WorldMgr.GetAllSessions();
                foreach (var session in smap)
                {
                    Player player = session.GetPlayer();
                    if (player != null)
                    {
                        if ((team == 0 || player.GetTeam() == team) && (!gmOnly || player.IsGameMaster()))
                        {
                            localizer.Invoke(player);
                        }
                    }
                }
                return;
            }

            case CreatureTextRange.Normal:
            default:
                break;
            }

            float dist   = GetRangeForChatType(msgType);
            var   worker = new PlayerDistWorker(source, dist, localizer);

            Cell.VisitWorldObjects(source, worker, dist);
        }
Exemplo n.º 4
0
        void SendNonChatPacket(WorldObject source, ServerPacket data, ChatMsg msgType, WorldObject whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
        {
            float dist = GetRangeForChatType(msgType);

            switch (msgType)
            {
            case ChatMsg.MonsterParty:
                if (!whisperTarget)
                {
                    return;
                }

                Player whisperPlayer = whisperTarget.ToPlayer();
                if (whisperPlayer)
                {
                    Group group = whisperPlayer.GetGroup();
                    if (group)
                    {
                        group.BroadcastWorker(player => player.SendPacket(data));
                    }
                }
                return;

            case ChatMsg.MonsterWhisper:
            case ChatMsg.RaidBossWhisper:
            {
                if (range == CreatureTextRange.Normal)        //ignores team and gmOnly
                {
                    if (!whisperTarget || !whisperTarget.IsTypeId(TypeId.Player))
                    {
                        return;
                    }

                    whisperTarget.ToPlayer().SendPacket(data);
                    return;
                }
                break;
            }

            default:
                break;
            }

            switch (range)
            {
            case CreatureTextRange.Area:
            {
                uint areaId  = source.GetAreaId();
                var  players = source.GetMap().GetPlayers();
                foreach (var pl in players)
                {
                    if (pl.GetAreaId() == areaId && (team == 0 || pl.GetTeam() == team) && (!gmOnly || pl.IsGameMaster()))
                    {
                        pl.SendPacket(data);
                    }
                }
                return;
            }

            case CreatureTextRange.Zone:
            {
                uint zoneId  = source.GetZoneId();
                var  players = source.GetMap().GetPlayers();
                foreach (var pl in players)
                {
                    if (pl.GetZoneId() == zoneId && (team == 0 || pl.GetTeam() == team) && (!gmOnly || pl.IsGameMaster()))
                    {
                        pl.SendPacket(data);
                    }
                }
                return;
            }

            case CreatureTextRange.Map:
            {
                var players = source.GetMap().GetPlayers();
                foreach (var pl in players)
                {
                    if ((team == 0 || pl.GetTeam() == team) && (!gmOnly || pl.IsGameMaster()))
                    {
                        pl.SendPacket(data);
                    }
                }
                return;
            }

            case CreatureTextRange.World:
            {
                var smap = Global.WorldMgr.GetAllSessions();
                foreach (var session in smap)
                {
                    Player player = session.GetPlayer();
                    if (player != null)
                    {
                        if ((team == 0 || player.GetTeam() == team) && (!gmOnly || player.IsGameMaster()))
                        {
                            player.SendPacket(data);
                        }
                    }
                }
                return;
            }

            case CreatureTextRange.Normal:
            default:
                break;
            }

            source.SendMessageToSetInRange(data, dist, true);
        }
Exemplo n.º 5
0
        public void SendSound(Creature source, uint sound, ChatMsg msgType, WorldObject whisperTarget = null, CreatureTextRange range = CreatureTextRange.Normal, Team team = Team.Other, bool gmOnly = false)
        {
            if (sound == 0 || !source)
            {
                return;
            }

            SendNonChatPacket(source, new PlaySound(source.GetGUID(), sound), msgType, whisperTarget, range, team, gmOnly);
        }
Exemplo n.º 6
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.º 7
0
        public void SendSound(Creature source, uint sound, ChatMsg msgType, WorldObject whisperTarget = null, CreatureTextRange range = CreatureTextRange.Normal, Team team = Team.Other, bool gmOnly = false, uint keyBroadcastTextId = 0, SoundKitPlayType playType = SoundKitPlayType.Normal)
        {
            if (sound == 0 || !source)
            {
                return;
            }

            if (playType == SoundKitPlayType.ObjectSound)
            {
                PlayObjectSound pkt = new();
                pkt.TargetObjectGUID = whisperTarget.GetGUID();
                pkt.SourceObjectGUID = source.GetGUID();
                pkt.SoundKitID       = sound;
                pkt.Position         = whisperTarget.GetWorldLocation();
                pkt.BroadcastTextID  = (int)keyBroadcastTextId;
                SendNonChatPacket(source, pkt, msgType, whisperTarget, range, team, gmOnly);
            }
            else if (playType == SoundKitPlayType.Normal)
            {
                SendNonChatPacket(source, new PlaySound(source.GetGUID(), sound, keyBroadcastTextId), msgType, whisperTarget, range, team, gmOnly);
            }
        }