public static bool Random_Walk(MapServer.BaseObject obj, ref byte dir, ref short x, ref short y) { byte index = 0; x = obj.GetCurrentX(); y = obj.GetCurrentY(); while (true) { if (index >= 10) break; dir = Random_Dir(); switch (dir) { case LEFT_DOWN: { x -= 1; y += 1; break; } case LEFT: { x -= 1; break; } case LEFT_UP: { x -= 1; y -= 1; break; } case UP: { y -= 1; break; } case RIGHT_UP: { x += 1; y -= 1; break; } case RIGHT: { x += 1; break; } case RIGHT_DOWN: { x += 1; y += 1; break; } case DOWN: { y += 1; break; } } if (obj.GetGameMap().CanMove(x, y)) { return true; } index++; } return false; }
//取下一个坐标点-- public static bool GetNexPoint(MapServer.BaseObject obj, ref short x, ref short y) { byte dir = obj.GetDir(); short srcx = obj.GetCurrentX(); short srcy = obj.GetCurrentY(); x = (short)(srcx + _DELTA_X[dir]); y = (short)(srcy + _DELTA_Y[dir]); if (!obj.GetGameMap().CanMove(x, y)) return false; //不能行走 if (x == srcx && y == srcy) return false; return true; }