Core/SAI: Make SMART_ACTION_RANDOM_MOVE also work with SMART_TARGET_NONE and non-creature targets (if a non-creature target_type is specified and no creature target was found, the action is fired at the source)

Ref. #7431
This commit is contained in:
Discover-
2013-09-21 11:21:29 +02:00
parent 6f9851ec13
commit 69b0a009c4

View File

@@ -1770,10 +1770,14 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!targets)
break;
bool foundTarget = false;
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsCreature((*itr)))
{
foundTarget = true;
if (e.action.moveRandom.distance)
(*itr)->ToCreature()->GetMotionMaster()->MoveRandom((float)e.action.moveRandom.distance);
else
@@ -1781,6 +1785,14 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
}
if (!foundTarget && me && IsCreature(me))
{
if (e.action.moveRandom.distance)
me->GetMotionMaster()->MoveRandom((float)e.action.moveRandom.distance);
else
me->GetMotionMaster()->MoveIdle();
}
delete targets;
break;
}
@@ -2287,8 +2299,9 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
l->push_back(baseObject);
break;
case SMART_TARGET_VICTIM:
if (me && me->GetVictim())
l->push_back(me->GetVictim());
if (me)
if (Unit* victim = me->GetVictim())
l->push_back(victim);
break;
case SMART_TARGET_HOSTILE_SECOND_AGGRO:
if (me)