示例#1
0
        private static bool FloodFillInDirection(Dungeon dungeon, DungeonTheme theme, int2 start, int2 end, List <int2> closed,
                                                 BuilderDirection dir)
        {
            var key = DungeonRoom.GetAdjacentKey(dungeon, start, dir);

            if (key.x == end.x && key.y == end.y)
            {
                return(true);
            }

            if (closed.Contains(key))
            {
                return(false);
            }

            closed.Add(key);

            if (IsValid(dungeon, theme, key))
            {
                return(Floodfill(dungeon, theme, key, end, closed));
            }

            return(false);
        }
示例#2
0
        private void Start()
        {
            _areaColors.Enqueue(Color.red);
            _areaColors.Enqueue(Color.green);
            _areaColors.Enqueue(Color.blue);
            _areaColors.Enqueue(Color.yellow);

            _agent.Generate(0);
            foreach (var meta in _agent.Context.AllRooms)
            {
                var room = GameObject.Instantiate(_dungeonRoomPrefab);
                room.Init();
                room.SetMeta(meta);
                room.GenerateMapValues(this, 0);
                Rooms.Add(room);
            }

            foreach (var room in Rooms)
            {
                room.GenerateMapValues(this, 1);
            }

            var splitThemes = new List <DungeonTheme>
            {
                DungeonTheme.Forest,
            };

            SplitDisconnectedRooms(splitThemes);

            DungeonRoom.WallIn(this, DungeonTheme.Cave);
            DungeonRoom.WallIn(this, DungeonTheme.Forest);

            DungeonRoom.WallOutTheVoid(this);

            foreach (var room in Rooms)
            {
                var foundArea = false;
                foreach (var area in Areas)
                {
                    if (area.Theme == room.Meta.Theme && area.IsConnectedTo(this, room))
                    {
                        area.Add(room);
                        foundArea = true;
                    }
                }

                if (!foundArea)
                {
                    var area = new GameObject(room.Meta.Theme.ToString()).AddComponent <DungeonArea>();
                    area.Theme      = room.Meta.Theme;
                    area.DebugColor = _areaColors.Count > 0 ? _areaColors.Dequeue() : Color.black;
                    area.Add(room);
                    Areas.Add(area);
                }
            }

            DungeonRoom.AddAreaConnections(this);

            Rooms[0].AddTilesForAllMapValues(this);

            StartCoroutine(SpawnContext());
        }
示例#3
0
        private void SplitDisconnectedRooms(List <DungeonTheme> splitThemes)
        {
            List <int2> closed = new List <int2>();

            for (var i = 0; i < Rooms.Count; i++)
            {
                if (splitThemes.Contains(Rooms[i].Meta.Theme) == false)
                {
                    continue;
                }

                closed.Clear();
                List <int2> splitTiles = null;
                var         room       = Rooms[i];
                foreach (var tile in room.ValueMap)
                {
                    if (tile.Value.Index != DungeonTile.Index.Floor)
                    {
                        continue;
                    }

                    if (closed.Contains(tile.Key))
                    {
                        continue;
                    }

                    closed.Add(tile.Key);

                    foreach (var tile2 in room.ValueMap)
                    {
                        if (closed.Contains(tile2.Key))
                        {
                            continue;
                        }

                        if (tile2.Value.Index != DungeonTile.Index.Floor)
                        {
                            continue;
                        }

                        var connected = DungeonRoom.IsConnected(this, room.Meta.Theme, tile.Key, tile2.Key);
                        if (!connected)
                        {
                            if (splitTiles == null)
                            {
                                splitTiles = new List <int2>();
                            }

                            splitTiles.Add(tile2.Key);
                        }
                    }
                }

                if (splitTiles != null)
                {
                    var splitRoom = GameObject.Instantiate(_dungeonRoomPrefab);
                    splitRoom.Init();
                    splitRoom.SetMeta(room.Meta);
                    foreach (var key in splitTiles)
                    {
                        if (room.ValueMap.ContainsKey(key))
                        {
                            var tile = room.ValueMap[key];
                            if (tile != null)
                            {
                                room.ValueMap.Remove(key);
                                splitRoom.ValueMap.Add(key, tile);
                                tile.Room = splitRoom;
                            }
                        }
                    }
                    Rooms.Add(splitRoom);

                    // Add some treasure here if possible
                    if (splitRoom.GetValidSpawnPosition(this, out var spawnPosition))
                    {
                        SpawnItemInWorld("Tier1 Container 1", spawnPosition);
                    }
                }
            }
        }
示例#4
0
 public bool IsInArea(DungeonRoom room)
 {
     return(Rooms.Contains(room));
 }
示例#5
0
 public void Add(DungeonRoom room)
 {
     room.transform.SetParent(transform, true);
     Rooms.Add(room);
 }