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, "DELETE FROM linked_respawn WHERE guid = ? AND linkType = ?");
PrepareStatement(WorldStatements.DEL_LINKED_RESPAWN_MASTER, "DELETE FROM linked_respawn WHERE linkedGuid = ? 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.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_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.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 = ?"); 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) else if (IsPlayer(target) && _me != null)
{ {
Unit templastInvoker = GetLastInvoker(); 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}", 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); target.GetName(), target.GetGUID().ToString(), e.Action.talk.textGroupId);
@@ -629,7 +629,7 @@ namespace Game.BattleFields
killer.CastSpell(killer, WGSpells.Corporal, true); killer.CastSpell(killer, WGSpells.Corporal, true);
Creature stalker = GetCreature(StalkerGuid); Creature stalker = GetCreature(StalkerGuid);
if (stalker) 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 else
killer.CastSpell(killer, WGSpells.Recruit, true); killer.CastSpell(killer, WGSpells.Recruit, true);
@@ -642,7 +642,7 @@ namespace Game.BattleFields
killer.CastSpell(killer, WGSpells.Lieutenant, true); killer.CastSpell(killer, WGSpells.Lieutenant, true);
Creature stalker = GetCreature(StalkerGuid); Creature stalker = GetCreature(StalkerGuid);
if (stalker) 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 else
killer.CastSpell(killer, WGSpells.Corporal, true); killer.CastSpell(killer, WGSpells.Corporal, true);
+41 -12
View File
@@ -67,32 +67,38 @@ namespace Game
temp.emote = (Emote)result.Read<uint>(7); temp.emote = (Emote)result.Read<uint>(7);
temp.duration = result.Read<uint>(8); temp.duration = result.Read<uint>(8);
temp.sound = result.Read<uint>(9); temp.sound = result.Read<uint>(9);
temp.BroadcastTextId = result.Read<uint>(10); temp.SoundPlayType = (SoundKitPlayType)result.Read<byte>(10);
temp.TextRange = (CreatureTextRange)result.Read<byte>(11); temp.BroadcastTextId = result.Read<uint>(11);
temp.TextRange = (CreatureTextRange)result.Read<byte>(12);
if (temp.sound != 0) if (temp.sound != 0)
{ {
if (!CliDB.SoundKitStorage.ContainsKey(temp.sound)) 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; 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)) 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; temp.lang = Language.Universal;
} }
if (temp.type >= ChatMsg.Max) 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; temp.type = ChatMsg.Say;
} }
if (temp.emote != 0) if (temp.emote != 0)
{ {
if (!CliDB.EmotesStorage.ContainsKey((uint)temp.emote)) 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; temp.emote = Emote.OneshotNone;
} }
} }
@@ -101,14 +107,14 @@ namespace Game
{ {
if (!CliDB.BroadcastTextStorage.ContainsKey(temp.BroadcastTextId)) 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; temp.BroadcastTextId = 0;
} }
} }
if (temp.TextRange > CreatureTextRange.Personal) 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; temp.TextRange = CreatureTextRange.Normal;
} }
@@ -122,7 +128,7 @@ namespace Game
++textCount; ++textCount;
} while (result.NextRow()); } 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() 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, 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) if (source == null)
return 0; return 0;
@@ -196,8 +202,12 @@ namespace Game
ChatMsg finalType = (msgType == ChatMsg.Addon) ? textEntry.type : msgType; ChatMsg finalType = (msgType == ChatMsg.Addon) ? textEntry.type : msgType;
Language finalLang = (language == Language.Addon) ? textEntry.lang : language; Language finalLang = (language == Language.Addon) ? textEntry.lang : language;
uint finalSound = textEntry.sound; uint finalSound = textEntry.sound;
SoundKitPlayType finalPlayType = textEntry.SoundPlayType;
if (sound != 0) if (sound != 0)
{
finalSound = sound; finalSound = sound;
finalPlayType = playType;
}
else else
{ {
BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(textEntry.BroadcastTextId); BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(textEntry.BroadcastTextId);
@@ -213,7 +223,7 @@ namespace Game
range = textEntry.TextRange; range = textEntry.TextRange;
if (finalSound != 0) 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; Unit finalSource = source;
if (srcPlr) if (srcPlr)
@@ -256,11 +266,22 @@ namespace Game
return dist; 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) if (sound == 0 || !source)
return; 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); SendNonChatPacket(source, new PlaySound(source.GetGUID(), sound, keyBroadcastTextId), msgType, whisperTarget, range, team, gmOnly);
} }
@@ -523,6 +544,7 @@ namespace Game
public Emote emote; public Emote emote;
public uint duration; public uint duration;
public uint sound; public uint sound;
public SoundKitPlayType SoundPlayType;
public uint BroadcastTextId; public uint BroadcastTextId;
public CreatureTextRange TextRange; public CreatureTextRange TextRange;
} }
@@ -556,6 +578,13 @@ namespace Game
Personal = 5 Personal = 5
} }
public enum SoundKitPlayType
{
Normal = 0,
ObjectSound = 1,
Max = 2,
}
public class CreatureTextLocalizer : IDoWork<Player> public class CreatureTextLocalizer : IDoWork<Player>
{ {
public CreatureTextLocalizer(MessageBuilder builder, ChatMsg msgType) public CreatureTextLocalizer(MessageBuilder builder, ChatMsg msgType)
+3 -2
View File
@@ -16,6 +16,7 @@
*/ */
using Framework.Constants; using Framework.Constants;
using Game;
using Game.Entities; using Game.Entities;
using Game.Maps; using Game.Maps;
using Game.Scripting; using Game.Scripting;
@@ -1071,9 +1072,9 @@ namespace Scripts.Spells.Quest
Creature trigger = target.FindNearestCreature(CreatureIds.IceSpikeBunny, 25.0f); Creature trigger = target.FindNearestCreature(CreatureIds.IceSpikeBunny, 25.0f);
if (trigger) 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); 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);
} }
} }
} }
@@ -0,0 +1,12 @@
--
ALTER TABLE `creature_text` ADD `SoundPlayType` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `Sound`;
UPDATE `creature_text` SET `SoundPlayType`=1 WHERE `CreatureID`=130986;
DELETE FROM `creature_text` WHERE `CreatureID`=130986 AND ((`GroupID`=0 AND `ID` IN(1, 2)) OR (`GroupID`=2 AND `ID` IN(1, 2)) OR (`GroupID`=3 AND `ID`=1));
INSERT INTO `creature_text` (`CreatureID`, `GroupID`, `ID`, `Text`, `Type`, `Language`, `Probability`, `Emote`, `Duration`, `Sound`, `SoundPlayType`, `BroadcastTextId`, `TextRange`, `comment`) VALUES
(130986, 0, 1, 'Oh, you made it.', 12, 0, 100, 0, 0, 96040, 1, 146007, 5, 'Vigilant Quoram to Player'),
(130986, 0, 2, 'Wonderful.', 12, 0, 100, 0, 0, 96041, 1, 146008, 5, 'Vigilant Quoram to Player'),
(130986, 2, 1, 'I imagine it is quite painful.', 12, 0, 100, 0, 0, 96045, 1, 146012, 5, 'Vigilant Quoram to Player'),
(130986, 2, 2, 'It is designed to kill you.', 12, 0, 100, 0, 0, 96044, 1, 146011, 5, 'Vigilant Quoram to Player'),
(130986, 3, 1, 'Perhaps.', 12, 0, 100, 0, 0, 96048, 1, 146015, 5, 'Vigilant Quoram to Player'); -- BroadcastTextID: 133363 - 146015