[10372] Implement EFLAG_RANDOM_ACTION

It allow execute one random action from EventAI event actions
instead each action from event actions.
This commit is contained in:
VladimirMangos 2010-08-18 14:23:45 +04:00
parent dbe9c6f190
commit a17450047b
4 changed files with 40 additions and 13 deletions

View file

@ -350,10 +350,35 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
if (pHolder.Event.event_chance <= rnd % 100)
return false;
//Process actions
for (uint32 j = 0; j < MAX_ACTIONS; j++)
ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker);
//Process actions, normal case
if (!(pHolder.Event.event_flags & EFLAG_RANDOM_ACTION))
{
for (uint32 j = 0; j < MAX_ACTIONS; ++j)
ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker);
}
//Process actions, random case
else
{
// amount of real actions
uint32 count = 0;
for (uint32 j = 0; j < MAX_ACTIONS; j++)
if (pHolder.Event.action[j].type != ACTION_T_NONE)
++count;
if (count)
{
// select action number from found amount
uint32 idx = urand(0,count-1);
// find selected action, skipping not used
uint32 j = 0;
for (; idx; ++j)
if (pHolder.Event.action[j].type != ACTION_T_NONE)
--idx;
ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker);
}
}
return true;
}