Beispiel #1
0
    public virtual void MakeAction()
    {
        switch (movementSettings.typeOfMovement)
        {
        case TypeOfMovement.None:
            break;

        case TypeOfMovement.Constant:
            Move(movementSettings.movementDirection);
            break;

        case TypeOfMovement.Random:
            AssignRandomDirection();
            Move(movementSettings.movementDirection);
            break;

        case TypeOfMovement.DefinedArea:
            movementSettings.movementDirection =
                movementSettings.definedArea.GetMovementDirectionWithinArea(currentPosition);
            Move(movementSettings.movementDirection);
            break;

        case TypeOfMovement.FollowPlayer:
            var(canMove, nextStep) = pathfinder.FindPath(Player.Instance.CurrentPosition, currentPosition);
            if (canMove)
            {
                movementSettings.movementDirection =
                    MovementDirectionUtilities.DirectionFromDifference(currentPosition, nextStep);
                Move(movementSettings.movementDirection);
            }
            else
            {
                (canMove, nextStep) = pathfinder.FindPath(Player.Instance.CurrentPosition, currentPosition, true);
                if (canMove &&
                    GameSessionManager.Instance.currentSceneObjects.currentWorld.CanWalk(nextStep).Item1 ==
                    GameTile.CantMoveReason.None)
                {
                    movementSettings.movementDirection =
                        MovementDirectionUtilities.DirectionFromDifference(currentPosition, nextStep);
                    Move(movementSettings.movementDirection);
                }
            }

            break;

        case TypeOfMovement.SpecificArea:
            movementSettings.movementDirection =
                movementSettings.specificArea.GetNextMovementDirection(CurrentPosition);
            Move(movementSettings.movementDirection);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Beispiel #2
0
        public MovementDirectionUtilities.MovementDirection GetNextMovementDirection(Vector2Int currentPosition)
        {
            var nextMoveLocation = GetNextMoveLocation(currentPosition);

            return(MovementDirectionUtilities.DirectionFromDifference(currentPosition, nextMoveLocation));
        }