//Returns the number of enemies visible within the player's view. Just realised includes dead ones, so you could spawnproof an area by leaving corpses. OOPS!
        private static int VisibleEnemies()
        {
            int num       = 0;
            var coordList = new List <Coordinate>();
            var nearby    = new List <Entity>();

            for (int i = -5; i < 6; i++)
            {
                for (int j = -5; j < 6; j++)
                {
                    var coord = new Coordinate(Player.position.x + i, Player.position.y + j);       //For each coordinate in the view
                    if (MainBoard.GetFromBoard(coord) != null)                                      //If there are entities there
                    {
                        foreach (Entity ent in MainBoard.GetFromBoard(coord))                       //Add each entity to the nearby list
                        {
                            nearby.Add(ent);
                        }
                    }
                }
            }

            if (nearby.Exists(x => x.GetType().IsSubclassOf(typeof(Enemy))))                        //If there is one or more enemy in the nearby list
            {
                num += nearby.FindAll(x => x.GetType().IsSubclassOf(typeof(Enemy))).Count;          //Count them and return that number
            }
            return(num);
        }
        //Attempt to move the player
        public static void Move(MoveCommand direction)
        {
            InventoryView = false;          //Disable inventory view
            MapDraw       = true;           //Request a fresh map draw

            //Get a list of the entities at the goal position
            List <Entity> goalSquareEntities = MainBoard.GetFromBoard(new Coordinate(Player.position.x + direction.x, Player.position.y + direction.y));

            //If there is something impassable there, fail the move
            if (goalSquareEntities != null && goalSquareEntities.Exists(x => x.Passable == false))
            {
                WriteLine("Can't walk there!");
                return;
            }

            //If you fail a combat check (can't beat an aggressor in the square), fail the move.
            if (!CombatCheck(goalSquareEntities))
            {
                return;
            }

            //Remove the player from its current coordinates, update the position, readd it to the coordinate map.
            MainBoard.entityPos[Player.position].Remove(Player);
            Player.position.x += direction.x;
            Player.position.y += direction.y;
            MainBoard.AddToBoard(Player);

            //Call a cleanup function to remove any dead entities and their inventories if the inventories are empty, and clear their
            //coordinates from the map if there are no more entities there.
            CleanUp(MainBoard);

            //Attempt to generate monsters, likelihood increases with distance from (0,0) (Bugged to not do it in the right way)
            MonsterGen(direction, Player.DistanceFromCenter());

            //List the entities you see in your new square
            foreach (Entity ent in EntityManager.GetLocalEntities(Player, MainBoard).FindAll(x => (x.Name != "Player")))
            {
                WriteLine("You see a " + ent.Name + ent.Status + "\b");
            }
        }
Exemple #3
0
 //Gets the inventories of all entities in the player's square.
 public static List <Inventory> GetLocalInventories() => GetInventories(MainBoard.GetFromBoard(Player.position));