Example #1
0
        public static FloorState BuildFloor(DungeonState dungeon, int width, int height, string mapID, int level)
        {
            var           distributions = FloorBuilder.levelDefinitions[level];
            List <Entity> mapEntities   = new List <Entity>();
            var           placementRand = new DotNetRandom(Int32.Parse(mapID));
            int           d             = 0;

            foreach (var dist in distributions)
            {
                var numToAdd = placementRand.Next(dist.Min, dist.Max);
                for (int i = 0; i < numToAdd; i++)
                {
                    mapEntities.Add(EntityBuilder_Enemies.BuildRandomLevelledEntity(placementRand, d.ToString(), dist.EntityLevel));
                    d++;
                }
            }
            return(FloorBuilder.BuildArena(dungeon, width, height, mapID, mapEntities, level));
        }
Example #2
0
        private static FloorState BuildArena(DungeonState dungeon, int width, int height, string mapID, IEnumerable <Entity> entities, int level)
        {
            if (!seedsToMaps.ContainsKey(mapID))
            {
                var map = Map.Create(new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy <Map>(width, height,
                                                                                                     2000, 9, 5, new DotNetRandom(Int32.Parse(mapID))));
                var pathFinder = new PathFinder(map);
                seedsToMaps[mapID] = new Tuple <IMap, PathFinder>(map, pathFinder);
            }

            var mapEntities = new List <Entity>();

            foreach (var e in entities)
            {
                mapEntities.Add(e);
            }
            FloorState floorState = new FloorState(dungeon, mapEntities, mapID, seedsToMaps[mapID].Item1, seedsToMaps[mapID].Item2, level);

            var openCells     = floorState.FloorMap.GetAllCells().Where(c => c.IsWalkable).ToList();
            var placementRand = new DotNetRandom(Int32.Parse(mapID));

            foreach (var e in mapEntities)
            {
                while (!e.HasComponentOfType <Component_Position>())
                {
                    var cell = openCells[placementRand.Next(openCells.Count - 1)];

                    Component_AI ai = e.GetComponentOfType <Component_AI>();
                    if (ai != null && !FloorBuilder.InScanRangeOfPlayer(floorState.Player, e, cell))
                    {
                        floorState.PlaceEntityNear(e, cell.X, cell.Y);
                        ai.DeterminePatrolPath(floorState, placementRand);
                    }
                    else if (ai == null)
                    {
                        floorState.PlaceEntityNear(e, cell.X, cell.Y);
                    }
                }
            }

            return(floorState);
        }