Skip to content

Commit

Permalink
Core/SAI: added SMART_ACTION_RANDOM_SOUND
Browse files Browse the repository at this point in the history
Closes #16376
  • Loading branch information
Lopfest authored and DDuarte committed Jan 26, 2016
1 parent e6a7818 commit e4af2ba
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Expand Up @@ -2305,6 +2305,36 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
break;
}
case SMART_ACTION_RANDOM_SOUND:
{
std::vector<uint32> sounds;

for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT - 1; i++)
{
if (e.action.randomSound.sound[i])
sounds.push_back(e.action.randomSound.sound[i]);
}

bool onlySelf = e.action.randomSound.onlySelf != 0;

ObjectList* targets = GetTargets(e, unit);
if (targets)
{
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsUnit(*itr))
{
uint32 sound = sounds[urand(0, sounds.size() - 1)];
(*itr)->PlayDirectSound(sound, e.action.randomSound.onlySelf ? (*itr)->ToPlayer() : nullptr);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_SOUND: target: %s (%s), sound: %u, onlyself: %u",
(*itr)->GetName().c_str(), (*itr)->GetGUID().ToString().c_str(), sound, e.action.randomSound.onlySelf);
}
}

delete targets;
break;
}
}
default:
TC_LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry %d SourceType %u, Event %u, Unhandled Action type %u", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
break;
Expand Down
7 changes: 7 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
Expand Up @@ -827,6 +827,13 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
if (e.action.randomEmote.emote6 && !IsEmoteValid(e, e.action.randomEmote.emote6))
return false;
break;
case SMART_ACTION_RANDOM_SOUND:
for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT - 1; i++)
{
if (e.action.randomSound.sound[i] && !IsSoundValid(e, e.action.randomSound.sound[i]))
return false;
}
break;
case SMART_ACTION_CAST:
{
if (!IsSpellValid(e, e.action.cast.spell))
Expand Down
9 changes: 8 additions & 1 deletion src/server/game/AI/SmartScripts/SmartScriptMgr.h
Expand Up @@ -540,8 +540,9 @@ enum SMART_ACTION
SMART_ACTION_GAME_EVENT_START = 112, // GameEventId
SMART_ACTION_START_CLOSEST_WAYPOINT = 113, // wp1, wp2, wp3, wp4, wp5, wp6, wp7
SMART_ACTION_RISE_UP = 114, // distance
SMART_ACTION_RANDOM_SOUND = 115, // SoundId1, SoundId2, SoundId3, SoundId4, SoundId5, onlySelf

SMART_ACTION_END = 115
SMART_ACTION_END = 116
};

struct SmartAction
Expand Down Expand Up @@ -1017,6 +1018,12 @@ struct SmartAction
uint32 wp6;
} closestWaypointFromList;

struct
{
uint32 sound[5];
uint32 onlySelf;
} randomSound;

//! Note for any new future actions
//! All parameters must have type uint32

Expand Down

0 comments on commit e4af2ba

Please sign in to comment.