diff options
author | Lopfest <lopfest@gmail.com> | 2016-01-26 03:26:41 +0000 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-04-02 14:51:13 +0200 |
commit | c457de1e80fdf250a529d6069d9262227de5a781 (patch) | |
tree | 41b079c1bfe4600da74d95f969b7b68ec285685f /src | |
parent | 6e5a129d91d548ac21578b3373ad08e610ed6348 (diff) |
Core/SAI: added SMART_ACTION_RANDOM_SOUND
Closes #16376
(cherry picked from commit e4af2baa7e5162b984172d54488137d4c5576d7d)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 30 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.cpp | 7 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.h | 9 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 519d48c5e6e..662ccf4ca7f 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -2337,6 +2337,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 " SI64FMTD " SourceType %u, Event %u, Unhandled Action type %u", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType()); break; diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index d249bf8c42c..b5317f64401 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -840,6 +840,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)) diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index 87d23b077b1..7bcf875b961 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -541,8 +541,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 @@ -1025,6 +1026,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 |