aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp24
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h2
2 files changed, 19 insertions, 7 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 70dd9e9d1ee..ba1e59e0cc9 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -411,11 +411,17 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
}
+ if (count == 0)
+ {
+ delete targets;
+ break;
+ }
+
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsUnit(*itr))
{
- uint32 emote = temp[urand(0, count)];
+ uint32 emote = temp[urand(0, count - 1)];
(*itr)->ToUnit()->HandleEmoteCommand(emote);
TC_LOG_DEBUG(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_EMOTE: Creature guidLow %u handle random emote %u",
(*itr)->GetGUIDLow(), emote);
@@ -835,7 +841,10 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
}
- uint32 phase = temp[urand(0, count)];
+ if (count == 0)
+ break;
+
+ uint32 phase = temp[urand(0, count - 1)];
SetPhase(phase);
TC_LOG_DEBUG(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction: SMART_ACTION_RANDOM_PHASE: Creature %u sets event phase to %u",
GetBaseObject()->GetGUIDLow(), phase);
@@ -1475,7 +1484,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_CREATE_TIMED_EVENT:
{
- SmartEvent ne;
+ SmartEvent ne = SmartEvent();
ne.type = (SMART_EVENT)SMART_EVENT_UPDATE;
ne.event_chance = e.action.timeEvent.chance;
if (!ne.event_chance) ne.event_chance = 100;
@@ -1489,11 +1498,11 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!ne.minMaxRepeat.repeatMin && !ne.minMaxRepeat.repeatMax)
ne.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
- SmartAction ac;
+ SmartAction ac = SmartAction();
ac.type = (SMART_ACTION)SMART_ACTION_TRIGGER_TIMED_EVENT;
ac.timeEvent.id = e.action.timeEvent.id;
- SmartScriptHolder ev;
+ SmartScriptHolder ev = SmartScriptHolder();
ev.event = ne;
ev.event_id = e.action.timeEvent.id;
ev.target = e.target;
@@ -1693,7 +1702,10 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
}
- uint32 id = temp[urand(0, count)];
+ if (count == 0)
+ break;
+
+ uint32 id = temp[urand(0, count - 1)];
if (e.GetTargetType() == SMART_TARGET_NONE)
{
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartScript: Entry %d SourceType %u Event %u Action %u is using TARGET_NONE(0) for Script9 target. Please correct target_type in database.", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index 0bb559dfe3c..0619392d3fb 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -1288,7 +1288,7 @@ enum SmartCastFlags
struct SmartScriptHolder
{
SmartScriptHolder() : entryOrGuid(0), source_type(SMART_SCRIPT_TYPE_CREATURE)
- , event_id(0), link(0), timer(0), active(false), runOnce(false)
+ , event_id(0), link(0), event(), action(), target(), timer(0), active(false), runOnce(false)
, enableTimed(false) {}
int32 entryOrGuid;