I have been adding TaskScheduler
to a ScriptedAI (Raliq the Drunk for reference). Whilst out of combat he should repeatedly animate drinking/eating every 5 seconds.
Current non-working code is:
void UpdateAI(uint32 diff) override
{
if (!me->IsInCombat())
{
_scheduler.Schedule(5s, [this](TaskContext context)
{
me->HandleEmoteCommand(EMOTE_DRINK);
context.Repeat(5s);
});
}
if (!UpdateVictim())
return;
_scheduler.Update(diff, [this] {
DoMeleeAttackIfReady();
});
}
What I think is very similar code which I have confirmed DOES work is:
void JustEngagedWith(Unit* /*who*/) override
{
_scheduler
.Schedule(5s, [this](TaskContext context)
{
DoCastVictim(SPELL_UPPERCUT);
context.Repeat(15s);
});
};
UpdateAI does fire.
So far I have tried to follow the debugger stepping through the scheduler code, as it does reach it. I have not been able to determine from that why/where it is failing.
I cannot see why the JustEngagedWith() code block works, whilst the near identical usage within UpdateAI() does not.
Any thoughts or recommendations would be greatly appreciated!
_schedule.Update()
was not being reached, so the scheduled task(s) were not being updated. Do not schedule tasks inside UpdateAI - it's not designed for that.