コード例 #1
0
        /// <summary>
        /// Attempts to push (or pull!) a map item
        /// </summary>
        /// <param name="avatarXy">the avatar's current map position</param>
        /// <param name="direction">the direction of the thing the avatar wants to push</param>
        /// <param name="bPushedAThing">was a thing actually pushed?</param>
        /// <returns>the string to output to the user</returns>
        public string PushAThing(Point2D avatarXy, VirtualMap.Direction direction, out bool bPushedAThing)
        {
            bPushedAThing = false;
            Point2D adjustedPos = NonPlayerCharacterMovement.GetAdjustedPos(avatarXy, direction);

            TileReference adjustedTileReference = State.TheVirtualMap.GetTileReference(adjustedPos);

            // it's not pushable OR if an NPC occupies the tile -so let's bail
            if (!adjustedTileReference.IsPushable || State.TheVirtualMap.IsNPCTile(adjustedPos))
            {
                return(DataOvlRef.StringReferences.GetString(DataOvlReference.ExclaimStrings.WONT_BUDGE_BANG_N));
            }

            bPushedAThing = true;

            // we get the thing one tile further than the thing to see if we have room to push it forward
            Point2D       oneMoreTileAdjusted  = NonPlayerCharacterMovement.GetAdjustedPos(adjustedPos, direction);
            TileReference oneMoreTileReference = State.TheVirtualMap.GetTileReference(oneMoreTileAdjusted);

            // if I'm sitting and the proceeding tile is an upright tile then I can't swap things
            if (State.TheVirtualMap.IsAvatarSitting() && oneMoreTileReference.IsUpright)
            {
                return(DataOvlRef.StringReferences.GetString(DataOvlReference.ExclaimStrings.WONT_BUDGE_BANG_N));
            }

            // if you are pushing a chair then change the direction of chair when it's pushed
            if (SpriteTileReferences.IsChair(adjustedTileReference.Index))
            {
                adjustedTileReference = GetChairNewDirection(direction);
                State.TheVirtualMap.SetOverridingTileReferece(adjustedTileReference, adjustedPos);
            }

            // is there an NPC on the tile? if so, we won't move anything into them
            bool bIsNPCOneMoreTile = State.TheVirtualMap.IsNPCTile(oneMoreTileAdjusted);

            // is the next tile walkable and is there NOT an NPC on it
            if (oneMoreTileReference.IsWalking_Passable && !bIsNPCOneMoreTile)
            {
                State.TheVirtualMap.SwapTiles(adjustedPos, oneMoreTileAdjusted);
            }
            else // the next tile isn't walkable so we just swap the avatar and the push tile
            {
                // we will pull (swap) the thing
                State.TheVirtualMap.SwapTiles(avatarXy, adjustedPos);
            }

            // move the avatar to the new spot
            State.TheVirtualMap.CurrentPosition = adjustedPos.Copy();

            PassTime();

            return(DataOvlRef.StringReferences.GetString(DataOvlReference.ExclaimStrings.PUSHED_BANG_N));
        }
コード例 #2
0
ファイル: VirtualMap.cs プロジェクト: The-Pupil/Ultima5Redux
        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);
        }
コード例 #3
0
        public MapCharacter(NonPlayerCharacterReference npcRef, MapCharacterAnimationState mapCharacterAnimationState, MapCharacterState mapCharacterState,
                            NonPlayerCharacterMovement nonPlayerCharacterMovement, TimeOfDay timeOfDay)
        {
            NPCRef         = npcRef;
            AnimationState = mapCharacterAnimationState;
            CharacterState = mapCharacterState;
            Movement       = nonPlayerCharacterMovement;

            CurrentCharacterPosition.Floor = CharacterState == null? 0: CharacterState.TheCharacterPosition.Floor;

            if (CharacterState == null)
            {
                if (npcRef != null)
                {
                    MoveNPCToDefaultScheduledPosition(timeOfDay);
                }
            }
            else
            {
                CurrentCharacterPosition.XY = new Point2D(CharacterState.TheCharacterPosition.X, CharacterState.TheCharacterPosition.Y);
            }
        }