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); } }
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, SoundKitPlayType playType = SoundKitPlayType.Normal, 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(); 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; SoundKitPlayType finalPlayType = textEntry.SoundPlayType; if (sound != 0) { finalSound = sound; finalPlayType = playType; } else { BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(textEntry.BroadcastTextId); if (bct != null) { uint broadcastTextSoundId = bct.SoundKitID[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, textEntry.BroadcastTextId, finalPlayType); } Unit finalSource = source; if (srcPlr) { finalSource = srcPlr; } if (textEntry.emote != 0) { SendEmote(finalSource, textEntry.emote); } if (srcPlr) { PlayerTextBuilder builder = new(source, finalSource, finalSource.GetGender(), finalType, textEntry.groupId, textEntry.id, finalLang, whisperTarget); SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly); } else { CreatureTextBuilder builder = new(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); }