Core/CreatureTexts: Added new field SoundPlayType to enable usage of ObjectSounds within creature_text

Port From (https://github.com/TrinityCore/TrinityCore/commit/437fb2aaba8850dd81a15d661c82403be9170c4e)
This commit is contained in:
hondacrx
2021-11-02 14:00:01 -04:00
parent 55746b1007
commit 6f27d79873
6 changed files with 61 additions and 19 deletions
@@ -25,7 +25,7 @@ namespace Framework.Database
PrepareStatement(WorldStatements.DEL_LINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ? AND linkType = ?");
PrepareStatement(WorldStatements.DEL_LINKED_RESPAWN_MASTER, "DELETE FROM linked_respawn WHERE linkedGuid = ? AND linkType = ?");
PrepareStatement(WorldStatements.REP_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid, linkType) VALUES (?, ?, ?)");
PrepareStatement(WorldStatements.SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, BroadcastTextId, TextRange FROM creature_text");
PrepareStatement(WorldStatements.SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, SoundPlayType, BroadcastTextId, TextRange FROM creature_text");
PrepareStatement(WorldStatements.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, event_param5, event_param_string, 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");
PrepareStatement(WorldStatements.SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid");
PrepareStatement(WorldStatements.DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?");
+1 -1
View File
@@ -185,7 +185,7 @@ namespace Game.AI
else if (IsPlayer(target) && _me != null)
{
Unit templastInvoker = GetLastInvoker();
Global.CreatureTextMgr.SendChat(_me, (byte)e.Action.talk.textGroupId, IsPlayer(templastInvoker) ? templastInvoker : null, ChatMsg.Addon, Language.Addon, CreatureTextRange.Normal, 0, Team.Other, false, target.ToPlayer());
Global.CreatureTextMgr.SendChat(_me, (byte)e.Action.talk.textGroupId, IsPlayer(templastInvoker) ? templastInvoker : null, ChatMsg.Addon, Language.Addon, CreatureTextRange.Normal, 0, SoundKitPlayType.Normal, Team.Other, false, target.ToPlayer());
}
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.ProcessAction. SMART_ACTION_SIMPLE_TALK: talker: {0} (GuidLow: {1}), textGroupId: {2}",
target.GetName(), target.GetGUID().ToString(), e.Action.talk.textGroupId);
@@ -629,7 +629,7 @@ namespace Game.BattleFields
killer.CastSpell(killer, WGSpells.Corporal, true);
Creature stalker = GetCreature(StalkerGuid);
if (stalker)
Global.CreatureTextMgr.SendChat(stalker, WintergraspText.RankCorporal, killer, ChatMsg.Addon, Language.Addon, CreatureTextRange.Normal, 0, Team.Other, false, killer);
Global.CreatureTextMgr.SendChat(stalker, WintergraspText.RankCorporal, killer, ChatMsg.Addon, Language.Addon, CreatureTextRange.Normal, 0, SoundKitPlayType.Normal, Team.Other, false, killer);
}
else
killer.CastSpell(killer, WGSpells.Recruit, true);
@@ -642,7 +642,7 @@ namespace Game.BattleFields
killer.CastSpell(killer, WGSpells.Lieutenant, true);
Creature stalker = GetCreature(StalkerGuid);
if (stalker)
Global.CreatureTextMgr.SendChat(stalker, WintergraspText.RankFirstLieutenant, killer, ChatMsg.Addon, Language.Addon, CreatureTextRange.Normal, 0, Team.Other, false, killer);
Global.CreatureTextMgr.SendChat(stalker, WintergraspText.RankFirstLieutenant, killer, ChatMsg.Addon, Language.Addon, CreatureTextRange.Normal, 0, SoundKitPlayType.Normal, Team.Other, false, killer);
}
else
killer.CastSpell(killer, WGSpells.Corporal, true);
+42 -13
View File
@@ -67,32 +67,38 @@ namespace Game
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);
temp.SoundPlayType = (SoundKitPlayType)result.Read<byte>(10);
temp.BroadcastTextId = result.Read<uint>(11);
temp.TextRange = (CreatureTextRange)result.Read<byte>(12);
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);
Log.outError(LogFilter.Sql, $"GossipManager: Entry {temp.creatureId}, Group {temp.groupId} in table `creature_texts` has Sound {temp.sound} but sound does not exist.");
temp.sound = 0;
}
}
if (temp.SoundPlayType >= SoundKitPlayType.Max)
{
Log.outError(LogFilter.Sql, $"CreatureTextMgr: Entry {temp.creatureId}, Group {temp.groupId} in table `creature_text` has PlayType {temp.SoundPlayType} but does not exist.");
temp.SoundPlayType = SoundKitPlayType.Normal;
}
if (temp.lang != Language.Universal && !Global.LanguageMgr.IsLanguageExist(temp.lang))
{
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);
Log.outError(LogFilter.Sql, $"CreatureTextMgr: Entry {temp.creatureId}, Group {temp.groupId} in table `creature_texts` using Language {temp.lang} but Language does not exist.");
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);
Log.outError(LogFilter.Sql, $"CreatureTextMgr: Entry {temp.creatureId}, Group {temp.groupId} in table `creature_texts` has Type {temp.type} but this Chat Type does not exist.");
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);
Log.outError(LogFilter.Sql, $"CreatureTextMgr: Entry {temp.creatureId}, Group {temp.groupId} in table `creature_texts` has Emote {temp.emote} but emote does not exist.");
temp.emote = Emote.OneshotNone;
}
}
@@ -101,14 +107,14 @@ namespace Game
{
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);
Log.outError(LogFilter.Sql, $"CreatureTextMgr: Entry {temp.creatureId}, Group {temp.groupId}, Id {temp.id} in table `creature_texts` has non-existing or incompatible BroadcastTextId {temp.BroadcastTextId}.");
temp.BroadcastTextId = 0;
}
}
if (temp.TextRange > CreatureTextRange.Personal)
{
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);
Log.outError(LogFilter.Sql, $"CreatureTextMgr: Entry {temp.creatureId}, Group {temp.groupId}, Id {temp.id} in table `creature_text` has incorrect TextRange {temp.TextRange}.");
temp.TextRange = CreatureTextRange.Normal;
}
@@ -122,7 +128,7 @@ namespace Game
++textCount;
} while (result.NextRow());
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} creature texts for {1} creatures in {2} ms", textCount, creatureCount, Time.GetMSTimeDiffToNow(oldMSTime));
Log.outInfo(LogFilter.ServerLoading, $"Loaded {textCount} creature texts for {creatureCount} creatures in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
}
public void LoadCreatureTextLocales()
@@ -159,7 +165,7 @@ namespace Game
}
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)
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;
@@ -196,8 +202,12 @@ namespace Game
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);
@@ -213,7 +223,7 @@ namespace Game
range = textEntry.TextRange;
if (finalSound != 0)
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly, textEntry.BroadcastTextId);
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly, textEntry.BroadcastTextId, finalPlayType);
Unit finalSource = source;
if (srcPlr)
@@ -256,12 +266,23 @@ namespace Game
return dist;
}
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)
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;
SendNonChatPacket(source, new PlaySound(source.GetGUID(), sound, keyBroadcastTextId), msgType, whisperTarget, range, team, gmOnly);
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);
}
void SendNonChatPacket(WorldObject source, ServerPacket data, ChatMsg msgType, WorldObject whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
@@ -523,6 +544,7 @@ namespace Game
public Emote emote;
public uint duration;
public uint sound;
public SoundKitPlayType SoundPlayType;
public uint BroadcastTextId;
public CreatureTextRange TextRange;
}
@@ -556,6 +578,13 @@ namespace Game
Personal = 5
}
public enum SoundKitPlayType
{
Normal = 0,
ObjectSound = 1,
Max = 2,
}
public class CreatureTextLocalizer : IDoWork<Player>
{
public CreatureTextLocalizer(MessageBuilder builder, ChatMsg msgType)
+3 -2
View File
@@ -16,6 +16,7 @@
*/
using Framework.Constants;
using Game;
using Game.Entities;
using Game.Maps;
using Game.Scripting;
@@ -1071,9 +1072,9 @@ namespace Scripts.Spells.Quest
Creature trigger = target.FindNearestCreature(CreatureIds.IceSpikeBunny, 25.0f);
if (trigger)
{
Global.CreatureTextMgr.SendChat(trigger, Misc.Say1, target, ChatMsg.Addon, Language.Addon, Game.CreatureTextRange.Normal, 0, Team.Other, false, target);
Global.CreatureTextMgr.SendChat(trigger, Misc.Say1, target, ChatMsg.Addon, Language.Addon, Game.CreatureTextRange.Normal, 0, SoundKitPlayType.Normal, Team.Other, false, target);
target.KilledMonsterCredit(CreatureIds.Killcredit);
Global.CreatureTextMgr.SendChat(trigger, Misc.Say2, target, ChatMsg.Addon, Language.Addon, Game.CreatureTextRange.Normal, 0, Team.Other, false, target);
Global.CreatureTextMgr.SendChat(trigger, Misc.Say2, target, ChatMsg.Addon, Language.Addon, Game.CreatureTextRange.Normal, 0, SoundKitPlayType.Normal, Team.Other, false, target);
}
}
}