fix(DB/Core): play event after quest "Hero of the Mag'har"; extend SAI to play music (#1570)

This commit is contained in:
Stoabrogga
2019-03-19 09:04:40 +01:00
committed by GitHub
parent 306615e71a
commit 54b23ce209
6 changed files with 2316 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -308,6 +308,131 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
delete targets;
break;
}
case SMART_ACTION_MUSIC:
{
ObjectList* targets = NULL;
if (e.action.music.type > 0)
{
if (me && me->FindMap())
{
Map::PlayerList const &players = me->GetMap()->GetPlayers();
targets = new ObjectList();
if (!players.isEmpty())
{
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
if (Player* player = i->GetSource())
{
if (player->GetZoneId() == me->GetZoneId())
{
if (e.action.music.type > 1)
{
if (player->GetAreaId() == me->GetAreaId())
targets->push_back(player);
}
else
targets->push_back(player);
}
}
}
}
}
else
targets = GetTargets(e, unit);
if (targets)
{
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsUnit(*itr))
{
(*itr)->SendPlayMusic(e.action.music.sound, e.action.music.onlySelf > 0);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction:: SMART_ACTION_MUSIC: target: %s (GuidLow: %u), sound: %u, onlySelf: %u, type: %u",
(*itr)->GetName().c_str(), (*itr)->GetGUIDLow(), e.action.music.sound, e.action.music.onlySelf, e.action.music.type);
#endif
}
}
delete targets;
}
break;
}
case SMART_ACTION_RANDOM_MUSIC:
{
ObjectList* targets = NULL;
if (e.action.randomMusic.type > 0)
{
if (me && me->FindMap())
{
Map::PlayerList const &players = me->GetMap()->GetPlayers();
targets = new ObjectList();
if (!players.isEmpty())
{
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
if (Player* player = i->GetSource())
{
if (player->GetZoneId() == me->GetZoneId())
{
if (e.action.randomMusic.type > 1)
{
if (player->GetAreaId() == me->GetAreaId())
targets->push_back(player);
}
else
targets->push_back(player);
}
}
}
}
}
else
targets = GetTargets(e, unit);
if (!targets)
break;
uint32 sounds[4];
sounds[0] = e.action.randomMusic.sound1;
sounds[1] = e.action.randomMusic.sound2;
sounds[2] = e.action.randomMusic.sound3;
sounds[3] = e.action.randomMusic.sound4;
uint32 temp[4];
uint32 count = 0;
for (uint8 i = 0; i < 4; i++)
{
if (sounds[i])
{
temp[count] = sounds[i];
++count;
}
}
if (count == 0)
{
delete targets;
break;
}
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsUnit(*itr))
{
uint32 sound = temp[urand(0, count - 1)];
(*itr)->SendPlayMusic(sound, e.action.randomMusic.onlySelf > 0);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_MUSIC: target: %s (GuidLow: %u), sound: %u, onlyself: %u, type: %u",
(*itr)->GetName().c_str(), (*itr)->GetGUIDLow(), sound, e.action.randomMusic.onlySelf, e.action.randomMusic.type);
#endif
}
}
delete targets;
break;
}
case SMART_ACTION_SET_FACTION:
{
ObjectList* targets = GetTargets(e, unit);

View File

@@ -793,6 +793,23 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
if (e.action.randomSound.sound4 && !IsSoundValid(e, e.action.randomSound.sound4))
return false;
break;
case SMART_ACTION_MUSIC:
if (!IsSoundValid(e, e.action.music.sound))
return false;
break;
case SMART_ACTION_RANDOM_MUSIC:
if (e.action.randomMusic.sound1 && !IsSoundValid(e, e.action.randomMusic.sound1))
return false;
if (e.action.randomMusic.sound2 && !IsSoundValid(e, e.action.randomMusic.sound2))
return false;
if (e.action.randomMusic.sound3 && !IsSoundValid(e, e.action.randomMusic.sound3))
return false;
if (e.action.randomMusic.sound4 && !IsSoundValid(e, e.action.randomMusic.sound4))
return false;
break;
case SMART_ACTION_SET_EMOTE_STATE:
case SMART_ACTION_PLAY_EMOTE:
if (!IsEmoteValid(e, e.action.emote.emote))

View File

@@ -586,8 +586,10 @@ enum SMART_ACTION
SMART_ACTION_NO_ENVIRONMENT_UPDATE = 213,
SMART_ACTION_ZONE_UNDER_ATTACK = 214,
SMART_ACTION_LOAD_GRID = 215,
SMART_ACTION_MUSIC = 216, // SoundId, onlySelf, type
SMART_ACTION_RANDOM_MUSIC = 217, // SoundId1, SoundId2, SoundId3, SoundId4, onlySelf, type
SMART_ACTION_AC_END = 216, // placeholder
SMART_ACTION_AC_END = 218, // placeholder
};
struct SmartAction
@@ -629,6 +631,23 @@ struct SmartAction
uint32 onlySelf;
} randomSound;
struct
{
uint32 sound;
uint32 onlySelf;
uint32 type;
} music;
struct
{
uint32 sound1;
uint32 sound2;
uint32 sound3;
uint32 sound4;
uint32 onlySelf;
uint32 type;
} randomMusic;
struct
{
uint32 emote;

View File

@@ -1825,6 +1825,16 @@ void WorldObject::SendPlaySound(uint32 Sound, bool OnlySelf)
SendMessageToSet(&data, true); // ToSelf ignored in this case
}
void WorldObject::SendPlayMusic(uint32 Music, bool OnlySelf)
{
WorldPacket data(SMSG_PLAY_MUSIC, 4);
data << Music;
if (OnlySelf && GetTypeId() == TYPEID_PLAYER)
this->ToPlayer()->GetSession()->SendPacket(&data);
else
SendMessageToSet(&data, true); // ToSelf ignored in this case
}
void Object::ForceValuesUpdateAtIndex(uint32 i)
{
_changesMask.SetBit(i);

View File

@@ -920,6 +920,7 @@ class WorldObject : public Object, public WorldLocation
// Low Level Packets
void SendPlaySound(uint32 Sound, bool OnlySelf);
void SendPlayMusic(uint32 Music, bool OnlySelf);
virtual void SetMap(Map* map);
virtual void ResetMap();