Пример #1
0
        /// <summary>
        /// Provides an adjust xy coordinate based on a given direction
        /// </summary>
        /// <param name="xy"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        internal static Point2D GetAdjustedPos(Point2D xy, NonPlayerCharacterMovement.MovementCommandDirection direction,
                                               int nSpaces = 1)
        {
            Point2D adjustedPos = new Point2D(xy.X, xy.Y);

            switch (direction)
            {
            case MovementCommandDirection.None:
                // no movement
                break;

            case MovementCommandDirection.East:
                adjustedPos.X += nSpaces;
                break;

            case MovementCommandDirection.North:
                adjustedPos.Y -= nSpaces;
                break;

            case MovementCommandDirection.West:
                adjustedPos.X -= nSpaces;
                break;

            case MovementCommandDirection.South:
                adjustedPos.Y += nSpaces;
                break;
            }
            return(adjustedPos);
        }
Пример #2
0
        internal bool MoveNPCs()
        {
            // if not on small map - then no NPCs!
            if (IsLargeMap)
            {
                return(false);
            }

            // go through each of the NPCs on the map
            foreach (MapCharacter mapChar in TheMapCharacters.Characters)
            {
                if (!mapChar.IsActive)
                {
                    continue;
                }

                // this NPC has a command in the buffer, so let's execute!
                if (mapChar.Movement.IsNextCommandAvailable())
                {
                    // peek and see what we have before we pop it off
                    NonPlayerCharacterMovement.MovementCommandDirection direction = mapChar.Movement.GetNextMovementCommandDirection(true);
                    Point2D adjustedPos = NonPlayerCharacterMovement.GetAdjustedPos(mapChar.CurrentCharacterPosition.XY, direction);
                    // need to evaluate if I can even move to the next tile before actually popping out of the queue
                    bool          bIsNPCOnSpace = IsNPCTile(adjustedPos);
                    TileReference adjustedTile  = GetTileReference(adjustedPos);
                    if (GetTileReference(adjustedPos).IsNPCCapableSpace&& !bIsNPCOnSpace)
                    {
                        // pop the direction from the queue
                        direction = mapChar.Movement.GetNextMovementCommandDirection(false);
                        mapChar.Move(adjustedPos, mapChar.CurrentCharacterPosition.Floor);
                    }
                }
                else
                {
                    mapChar.CalculateNextPath();
                }
            }

            return(true);
        }
        static internal Point2D GetAdjustedPos(Point2D xy, NonPlayerCharacterMovement.MovementCommandDirection direction)
        {
            Point2D adjustedPos = new Point2D(xy.X, xy.Y);

            switch (direction)
            {
            case NonPlayerCharacterMovement.MovementCommandDirection.East:
                adjustedPos.X += 1;
                break;

            case NonPlayerCharacterMovement.MovementCommandDirection.North:
                adjustedPos.Y -= 1;
                break;

            case NonPlayerCharacterMovement.MovementCommandDirection.West:
                adjustedPos.X -= 1;
                break;

            case NonPlayerCharacterMovement.MovementCommandDirection.South:
                adjustedPos.Y += 1;
                break;
            }
            return(adjustedPos);
        }