예제 #1
0
        public static TimedPath Create(Path path, double hVelocity, double vVelocity, double lVelocity, DateTime referenceDate)
        {
            var cells = path.Cells;
            var result = new List<TimedPathElement>();

            var lastCellTime = referenceDate;
            for (int i = 0; i < cells.Length; i++)
            {
                int direction;

                if (i + 1 < cells.Length)
                    direction = (int)cells[i].OrientationToAdjacent(cells[i + 1]);
                else
                    direction = (int)cells[i - 1].OrientationToAdjacent(cells[i]);

                double velocity;
                if (direction % 4 == 0)
                    velocity = hVelocity;
                else if (direction % 2 == 0)
                    velocity = vVelocity;
                else
                    velocity = lVelocity;

                var end = lastCellTime + TimeSpan.FromMilliseconds(1 / velocity);

                result.Add(new TimedPathElement(cells[i], i + 1 < cells.Length ? cells[i + 1] : null, lastCellTime, end, velocity, (DirectionsEnum)direction));

                lastCellTime = end;
            }

            return new TimedPath(result.ToArray());
        }
예제 #2
0
        public virtual bool NotifyStartMoving(Path path)
        {
            if (path.IsEmpty())
            {
                logger.Warn("Try to start moving with an empty path");
                return false;
            }

            Movement = new MovementBehavior(path, GetAdaptedVelocity(path));
            Movement.Start();


            return NotifyStartMoving(Movement);
        }
예제 #3
0
        public bool Move(Path path, Cell dest, bool cancelMove = true)
        {
            if (IsMoving())
                if (cancelMove)
                    CancelMove(false);
                else
                {
                    if (_actionAfterMove != null) return false; // Can't remember this move
                    _actionAfterMove = () => Move(path, dest, cancelMove);
                    return true;
                }

            // DEBUG
            //SendMessage(String.Format("Move {0} => {1} : {2}", Cell, dest, String.Join<Cell>(",", path.Cells)));
            //ResetCellsHighlight();
            //HighlightCells(path.Cells, Color.YellowGreen);
            if (path.IsEmpty())
            {
                SendMessage("Empty path skipped", Color.Gray);
                return false;
            }
            else
                if (path.Start.Id != Cell.Id)
                {
                    SendMessage(String.Format("Path start with {0} instead of {1}", path.Start, Cell), Color.Red);
                    return false;
                }

            Bot.SendToServer(new GameMapMovementRequestMessage(path.GetClientPathKeys(), Map.Id));
            return true;

        }
예제 #4
0
 public MovementBehavior(Path path, VelocityConfiguration velocityConfiguration)
 {
     MovementPath = path;
     VelocityConfiguration = velocityConfiguration;
 }
예제 #5
0
 public virtual VelocityConfiguration GetAdaptedVelocity(Path path)
 {
     return MovementBehavior.WalkingMovementBehavior;
 }
예제 #6
0
        public virtual void NotifyStartMoving(Path path)
        {
            MovePath = path;
            MoveStartTime = DateTime.Now;

            if (MovePath.Start != Position.Cell)
            {
                logger.Warn("Actor start cell incorrect for this moving path Position={0}, StartPath={1}", Position.Cell, MovePath.Start);
                Position.Cell = MovePath.Start;
            }

            var handler = StartMoving;
            if (handler != null) handler(this, path);
        }
예제 #7
0
        public bool Move(Path path)
        {
            if (!IsPlaying())
                return false;

            if (Stats.CurrentMP < 1)
            {
                Character.SendMessage(String.Format("Can't move with {0} MP", Stats.CurrentMP), Color.Red);
                return false;
            }

            // DEBUG
            //Character.SendMessage(String.Format("Move {0} => {1} ({3} PM): {2}", Cell, cell, String.Join<Cell>(",", path.Cells), mp));
            //Character.ResetCellsHighlight();
            //Character.HighlightCells(path.Cells, Color.YellowGreen);
            if (path == null || path.IsEmpty())
            {
                Character.SendMessage("Empty path skipped", Color.Red);
                return false;
            }
            else
                if (path.Start.Id != Cell.Id)
                {
                    Character.SendMessage(String.Format("Path starts with {0} instead of {1}", path.Start, Cell), Color.Red);
                    return false;
                }

            if (NotifyStartMoving(path))
                Character.Bot.SendToServer(new GameMapMovementRequestMessage(path.GetClientPathKeys(), Map.Id));

            return true;
        }