Beispiel #1
0
        public void Execute(Mobile mobile, Map map, Tile nonPlayerCharacterTile)
        {
            if (mobile.CanAttack(map, nonPlayerCharacterTile))
            {
                mobile.Event = Transition.Attack;
                return;
            }

            var playerTile = map.GetPlayerTile();

            var tileToMoveTo = map.GetShortestDistanceDirectionToPlayer(mobile, playerTile.Location, nonPlayerCharacterTile.Location);

            //if null, don't move
            if (tileToMoveTo != null)
            {
                if (tileToMoveTo.TypeId == Constants.TypeIds.Door)
                {
                    map.ToggleDoor(tileToMoveTo, false);
                }
                else
                {
                    var tile = map.MoveMobile(nonPlayerCharacterTile, tileToMoveTo);
                }
            }
        }
Beispiel #2
0
        public bool CanAttack(Map map, Tile nonPlayerCharacterTile)
        {
            var topStart  = nonPlayerCharacterTile.Location.Top - 1 < 1 ? 1 : nonPlayerCharacterTile.Location.Top - 1;
            var leftStart = nonPlayerCharacterTile.Location.Left - 1 < 1 ? 1 : nonPlayerCharacterTile.Location.Left - 1;

            var playerTile = map.GetPlayerTile();

            for (int top = topStart; top <= nonPlayerCharacterTile.Location.Top + 1; top++)
            {
                for (int left = leftStart; left <= nonPlayerCharacterTile.Location.Left + 1; left++)
                {
                    if (playerTile.Location.Top == top && playerTile.Location.Left == left)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        public bool execute(LocalKeyInfo keyInfo)
        {
            Status.ClearInfo();
            Status.Info = "Which direction?";
            Status.WriteToStatus();

            ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(true);
            var            localKeyInfo   = new LocalKeyInfo(consoleKeyInfo);

            //TODO -- Taking key input exists in more than one place now, REFACTOR

            var mapTile = map.GetPlayerTile();

            var mapLocation = new Location(mapTile.Location.Left, mapTile.Location.Top);

            var tileToUse = this.map.GetTileInDirection(localKeyInfo, mapLocation);

            if (tileToUse.TypeId == Constants.TypeIds.Door)
            {
                this.map.ToggleDoor(tileToUse, false);
            }
            else if (tileToUse.TypeId == Constants.TypeIds.OpenDoor)
            {
                this.map.ToggleDoor(tileToUse, true);
            }
            else
            {
                Status.Info = "That can't be opened or closed.  Press any key to continue.";
                Status.WriteToStatus();
                Console.ReadKey(true);
            }

            Status.ClearInfo();

            this.map.Outdated = true;

            return(false);
        }
Beispiel #4
0
        public bool execute(LocalKeyInfo keyInfo)
        {
            Status.ClearInfo();
            Status.Info = "Which direction?";
            Status.WriteToStatus();

            ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(true);
            var            localKeyInfo   = new LocalKeyInfo(consoleKeyInfo);

            //TODO -- Taking key input exists in more than one place now, REFACTOR

            var mapTile     = map.GetPlayerTile();
            var mapLocation = new Location(mapTile.Location.Left, mapTile.Location.Top);
            var tile        = this.map.GetTileInDirection(localKeyInfo, mapLocation);

            if (tile.Mobile is INonPlayerCharacter)
            {
                tile.Mobile.HitPoints -= 5;
                var message = "You hit " + tile.Mobile.HitMessage + ".";
                if (tile.Mobile.IsDead())
                {
                    //TODO -- This logic should probably be moved.
                    //TODO -- The death message should be moved to the specific mobile (and then later to config)
                    message     += "You killed it!!!";
                    tile.Mobile  = null;
                    map.Outdated = true;
                }

                Status.Info = message;
            }
            else
            {
                Status.Info = "Not a valid target.";
            }

            return(false);
        }
Beispiel #5
0
        public void Execute(Mobile mobile, Map map, Tile nonPlayerCharacterTile)
        {
            if (mobile.CanAttack(map, nonPlayerCharacterTile))
            {
                mobile.Event = Transition.Attack;
                return;
            }

            var playerTile = map.GetPlayerTile();

            var tileToMoveTo = map.GetShortestDistanceDirectionToPlayer(mobile, playerTile.Location, nonPlayerCharacterTile.Location);
            //if null, don't move
            if (tileToMoveTo != null)
            {
                if (tileToMoveTo.TypeId == Constants.TypeIds.Door)
                {
                    map.ToggleDoor(tileToMoveTo, false);
                }
                else
                {
                    var tile = map.MoveMobile(nonPlayerCharacterTile, tileToMoveTo);
                }
            }
        }
Beispiel #6
0
        public bool CanAttack(Map map, Tile nonPlayerCharacterTile)
        {
            var topStart = nonPlayerCharacterTile.Location.Top - 1 < 1 ? 1 : nonPlayerCharacterTile.Location.Top - 1;
            var leftStart = nonPlayerCharacterTile.Location.Left - 1 < 1 ? 1 : nonPlayerCharacterTile.Location.Left - 1;

            var playerTile = map.GetPlayerTile();

            for (int top = topStart; top <= nonPlayerCharacterTile.Location.Top + 1; top++)
            {
                for (int left = leftStart; left <= nonPlayerCharacterTile.Location.Left + 1; left++)
                {
                    if (playerTile.Location.Top == top && playerTile.Location.Left == left)
                    {
                        return true;
                    }
                }
            }

            return false;
        }