int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type) {
struct unit_data *ud = unit->bl2ud(bl);
if (delay <= 0 || !ud) return 0;
if (type) {
if (DIFF_TICK(ud->canmove_tick, tick+delay) > 0)
return 0;
} else {
//Don't set walk delays when already trapped.
if (!unit->can_move(bl))
return 0;
//Immune to being stopped for double the flinch time
if (DIFF_TICK(ud->canmove_tick, tick-delay) > 0)
return 0;
}
ud->canmove_tick = tick + delay;
if (ud->walktimer != INVALID_TIMER) {
//Stop walking, if chasing, readjust timers.
if (delay == 1) {
//Minimal delay (walk-delay) disabled. Just stop walking.
unit->stop_walking(bl,4);
} else {
//Resume running after can move again [Kevin]
if(ud->state.running)
{
timer->add(ud->canmove_tick, unit->resume_running, bl->id, (intptr_t)ud);
}
else
{
unit->stop_walking(bl,2|4);
if(ud->target)
timer->add(ud->canmove_tick+1, unit->walktobl_sub, bl->id, ud->target);
}
}
}
return 1;
}