void Bot::Walk(Direction direction)
{
if(clock() - last_walk < 500) return;
if(clock() - last_attack < 690) return;
int xoff[4] = { 0, -1, 0, 1 };
int yoff[4] = { 1, 0, -1, 0 };
int walk_x = client.me->x;
walk_x += xoff[(int)direction];
int walk_y = client.me->y;
walk_y += yoff[(int)direction];
bool can_walk = true;
if(!client.Walkable(walk_x, walk_y))
can_walk = false;
if(client.OccupiedByNPC(walk_x, walk_y))
can_walk = false;
bool ghost = false;
if(can_walk && client.OccupiedByCharacter(walk_x, walk_y))
{
ghost = true;
}
else if(!can_walk)
{
return;
}
if(ghost && clock() - last_ghost_walk < 7000) // check if it can ghost walk
return;
client.Walk(direction, ghost); // it will replace WALK_PLAYER with WALK_SPEC if ghost == true
last_walk = clock();
if(ghost) last_ghost_walk = clock(); // update the time of last ghost walk
}