예제 #1
0
        protected override GameAction PrepareNextActionOverride(out JobStatus progress)
        {
            var random = this.Worker.World.Random;

            int rand = random.Next(100);

            GameAction action = null;

            Direction dir = m_dir;

            if (rand < 25)
            {
                dir = Direction.None;
            }
            else if (rand < 50)
            {
            }
            else if (rand < 75)
            {
                var v = new IntVector3(dir);
                v = v.FastRotate(random.Next() % 2 == 0 ? 1 : -1);
                dir = v.ToDirection();
            }
            else
            {
                var v = new IntVector3(dir);
                v = v.FastRotate(random.Next() % 2 == 0 ? 2 : -2);
                dir = v.ToDirection();
            }

            if (dir == Direction.None)
            {
                action = new WaitAction(random.Next(4) + 1);
            }
            else
            {
                var env = this.Worker.Environment;
                m_dir = dir;

                IntVector2 ov = new IntVector2(dir);

                for (int i = 0; i < 7; ++i)
                {
                    var v = ov.FastRotate(((i + 1) >> 1) * (((i % 2) << 1) - 1));
                    var d = EnvironmentHelpers.AdjustMoveDir(env, this.Worker.Location, v.ToDirection());

                    if (d != Direction.None)
                        action = new MoveAction(d);
                }

                if (action == null && EnvironmentHelpers.CanMoveFromTo(this.Worker, Direction.Up))
                    action = new MoveAction(Direction.Up);

                if (action == null && EnvironmentHelpers.CanMoveFromTo(this.Worker, Direction.Down))
                    action = new MoveAction(Direction.Down);

                if (action == null)
                    action = new WaitAction(random.Next(4) + 1);
            }

            progress = JobStatus.Ok;
            return action;
        }