Core/Texts: allow creature texts to play sounds via different opcodes (Direct Sound, Object Sound and Music)

This commit is contained in:
Ovahlord
2020-05-01 18:35:53 +02:00
parent 1a85f82edd
commit 6aa8e4389c
7 changed files with 42 additions and 9 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE `creature_text` ADD COLUMN `SoundType` MEDIUMINT(8) UNSIGNED DEFAULT 0 NOT NULL AFTER `Sound`;

View File

@@ -26,7 +26,7 @@ void WorldDatabaseConnection::DoPrepareStatements()
PrepareStatement(WORLD_SEL_QUEST_POOLS, "SELECT entry, pool_entry FROM pool_quest", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_CRELINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_REP_CREATURE_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, SoundType, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH);
PrepareStatement(WORLD_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, 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", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?", CONNECTION_ASYNC);

View File

@@ -172,6 +172,8 @@ namespace WorldPackets
{
public:
PlayObjectSound() : ServerPacket(SMSG_PLAY_OBJECT_SOUND, 8 + 8 + 4) { }
PlayObjectSound(ObjectGuid sourceObjectGuid, ObjectGuid targetObjectGuid, uint32 soundKitID) : ServerPacket(SMSG_PLAY_OBJECT_SOUND, 8 + 8 + 4),
SourceObjectGUID(sourceObjectGuid), TargetObjectGUID(targetObjectGuid), SoundKitID(soundKitID) { }
WorldPacket const* Write() override;

View File

@@ -115,8 +115,9 @@ void CreatureTextMgr::LoadCreatureTexts()
temp.emote = Emote(fields[7].GetUInt32());
temp.duration = fields[8].GetUInt32();
temp.sound = fields[9].GetUInt32();
temp.BroadcastTextId = fields[10].GetUInt32();
temp.TextRange = CreatureTextRange(fields[11].GetUInt8());
temp.soundType = CreatureTextSoundType(fields[10].GetUInt32());
temp.BroadcastTextId = fields[11].GetUInt32();
temp.TextRange = CreatureTextRange(fields[12].GetUInt8());
if (temp.sound)
{
@@ -163,6 +164,12 @@ void CreatureTextMgr::LoadCreatureTexts()
temp.TextRange = TEXT_RANGE_NORMAL;
}
if (temp.soundType > CreatureTextSoundType::Music)
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect SoundType %u.", temp.creatureId, temp.groupId, temp.id, AsUnderlyingType(temp.TextRange));
temp.soundType = CreatureTextSoundType::DirectSound;
}
// add the text into our entry's group
mTextMap[temp.creatureId][temp.groupId].push_back(temp);
@@ -247,7 +254,9 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject
ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
CreatureTextSoundType soundType = iter->soundType;
uint32 finalSound = iter->sound;
if (sound)
finalSound = sound;
else if (BroadcastText const* bct = sObjectMgr->GetBroadcastText(iter->BroadcastTextId))
@@ -258,7 +267,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject
range = iter->TextRange;
if (finalSound)
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly);
SendSound(source, finalSound, soundType, finalType, whisperTarget, range, team, gmOnly);
Unit* finalSource = source;
if (srcPlr)
@@ -301,12 +310,25 @@ float CreatureTextMgr::GetRangeForChatType(ChatMsg msgType) const
return dist;
}
void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
void CreatureTextMgr::SendSound(Creature* source, uint32 sound, CreatureTextSoundType soundType, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly)
{
if (!sound || !source)
return;
SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly);
switch (soundType)
{
case CreatureTextSoundType::DirectSound:
SendNonChatPacket(source, WorldPackets::Misc::PlaySound(source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly);
break;
case CreatureTextSoundType::ObjectSound:
SendNonChatPacket(source, WorldPackets::Misc::PlayObjectSound(source->GetGUID(), whisperTarget ? whisperTarget->GetGUID() : source->GetGUID(), sound).Write(), msgType, whisperTarget, range, team, gmOnly);
break;
case CreatureTextSoundType::Music:
SendNonChatPacket(source, WorldPackets::Misc::PlayMusic(sound, source->GetGUID()).Write(), msgType, whisperTarget, range, team, gmOnly);
break;
default:
break;
}
}
void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket const* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly) const

View File

@@ -39,6 +39,13 @@ enum CreatureTextRange
TEXT_RANGE_WORLD = 4
};
enum class CreatureTextSoundType : uint32
{
DirectSound = 0,
ObjectSound = 1,
Music = 2
};
struct CreatureTextEntry
{
uint32 creatureId;
@@ -51,6 +58,7 @@ struct CreatureTextEntry
Emote emote;
uint32 duration;
uint32 sound;
CreatureTextSoundType soundType;
uint32 BroadcastTextId;
CreatureTextRange TextRange;
};
@@ -93,7 +101,7 @@ class TC_GAME_API CreatureTextMgr
void LoadCreatureTextLocales();
CreatureTextMap const& GetTextMap() const { return mTextMap; }
void SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly);
void SendSound(Creature* source, uint32 sound, CreatureTextSoundType soundType, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly);
void SendEmote(Unit* source, uint32 emote);
//if sent, returns the 'duration' of the text else 0 if error

View File

@@ -1102,7 +1102,7 @@ class boss_the_lich_king : public CreatureScript
break;
case EVENT_OUTRO_SOUL_BARRAGE:
me->CastSpell((Unit*)nullptr, SPELL_SOUL_BARRAGE, TRIGGERED_IGNORE_CAST_IN_PROGRESS);
sCreatureTextMgr->SendSound(me, SOUND_PAIN, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false);
sCreatureTextMgr->SendSound(me, SOUND_PAIN, CreatureTextSoundType::DirectSound, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false);
// set flight
me->SetDisableGravity(true);
me->SetByteFlag(UNIT_FIELD_BYTES_1, UNIT_BYTES_1_OFFSET_ANIM_TIER, UNIT_BYTE1_FLAG_ALWAYS_STAND | UNIT_BYTE1_FLAG_HOVER);

View File

@@ -988,7 +988,7 @@ class boss_yogg_saron : public CreatureScript
break;
case EVENT_LUNATIC_GAZE:
DoCast(me, SPELL_LUNATIC_GAZE);
sCreatureTextMgr->SendSound(me, SOUND_LUNATIC_GAZE, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false);
sCreatureTextMgr->SendSound(me, SOUND_LUNATIC_GAZE, CreatureTextSoundType::DirectSound, CHAT_MSG_MONSTER_YELL, 0, TEXT_RANGE_NORMAL, TEAM_OTHER, false);
_events.ScheduleEvent(EVENT_LUNATIC_GAZE, 12000, 0, PHASE_THREE);
break;
case EVENT_DEAFENING_ROAR: