// Use this for initialization
        void Start()
        {
            DungeonConfig[] dungeonConfigs = _gameConfig.DungeonConfigs;
            for (var dungeonIndex = 0; dungeonIndex < dungeonConfigs.Length; dungeonIndex++)
            {
                DungeonConfig dungeonConfig = dungeonConfigs[dungeonIndex];
                Dungeon       dungeon;
                while (true)
                {
                    dungeon = GenerateDungeon(dungeonIndex * 60, 0, dungeonConfig.Size.x, dungeonConfig.Size.y);
                    if (dungeon.StairsLocation != Vector2Int.zero)
                    {
                        break;
                    }
                    Debug.LogError("dungeon was created without stairs! trying to recreate");
                }
                _gameContext.Dungeons.Add(dungeon);
                GenerateActorsInDungeon(dungeon, dungeonConfig, isFirstDungeon: dungeonIndex == 0);
            }

            GenerateActorsAndItemsOutside();

            _gameContext.CurrentDungeonIndex = 0;

            //GenerateWilderness();
            InitializeVisibilityOfTiles();
            //_pathfinder.InitializeNavigationGrid();

            //GenerateAnimals(6);
        }
Exemple #2
0
        void DrawCursor(DungeonConfig config, bool mode2D, int size)
        {
            size = Mathf.Max(1, size);
            var cursorSize = config.GridCellSize * size;

            DrawRect(cursorPosition, cursorSize, Color.red, 0.25f, 0.8f, mode2D);
        }
Exemple #3
0
    public void EneterDungeonGroup(int dungeonId)
    {
        if (!DungeonConfig.Has(dungeonId))
        {
            DebugEx.LogFormat("查无此副本,别开玩笑了:{0}", dungeonId);
            return;
        }

        var config = DungeonConfig.Get(dungeonId);
    }
Exemple #4
0
    public void Display(int dungeonId)
    {
        if (!DungeonConfig.Has(dungeonId))
        {
            return;
        }

        DisplayBaseInfo(dungeonId);
        DisplaySurplusTimes(dungeonId);
    }
Exemple #5
0
    private void DisplayBaseInfo()
    {
        var config = DungeonConfig.Get(NormalDungeon.Instance.dungeonId);

        m_DungeonInfo.Display(NormalDungeon.Instance.dungeonId);
        m_SingleChallenge.SetActive(NormalDungeon.Instance.showSingleEnterance.Fetch());
        m_TeamChallenge.SetActive(NormalDungeon.Instance.showMultipEnterance.Fetch());

        m_BossModel.Display(config.boss, Vector3.zero, Vector3.zero, Vector3.one);
    }
Exemple #6
0
 public int GetDailySurplusTimes(int dungeonId)
 {
     if (DungeonConfig.Has(dungeonId))
     {
         return(DungeonConfig.Get(dungeonId).dailyTimes - GetEnterTimes(dungeonId));
     }
     else
     {
         return(0);
     }
 }
Exemple #7
0
 public int GetDailyTotalTimes(int dungeonId)
 {
     if (DungeonConfig.Has(dungeonId))
     {
         return(DungeonConfig.Get(dungeonId).dailyTimes);
     }
     else
     {
         return(0);
     }
 }
Exemple #8
0
 public int GetWeekTotalTimes(int dungeonId)
 {
     if (DungeonConfig.Has(dungeonId))
     {
         return(DungeonConfig.Get(dungeonId).weekTimes);
     }
     else
     {
         return(0);
     }
 }
Exemple #9
0
 public int GetWeekSurplusTimes(int dungeonId)
 {
     if (DungeonConfig.Has(dungeonId))
     {
         return(DungeonConfig.Get(dungeonId).weekTimes - GetEnterTimes(dungeonId));
     }
     else
     {
         return(0);
     }
 }
Exemple #10
0
    public void OpenWindow(object @object)
    {
        this.dungeonId = (int)@object;
        var config = DungeonConfig.Get(this.dungeonId);

        bossId.value              = config.boss;
        surplurTime.value         = Dungeon.Instance.GetDailySurplusTimes(dungeonId);
        showSweep.value           = Dungeon.Instance.GetDungeonHighestStar(dungeonId) > 0;
        showSingleEnterance.value = config.type == 1 || config.type == 3;
        showMultipEnterance.value = config.type == 2 || config.type == 3;
        Windows.Instance.Open(WindowType.NormalDungeon);
    }
        //new System.Random random;

        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            base.BuildDungeon(config, model);

            //random = new System.Random((int)config.Seed);

            // We know that the dungeon prefab would have the appropriate config and models attached to it
            // Cast and save it for future reference
            snapConfig       = config as SnapConfig;
            snapModel        = model as SnapModel;
            snapModel.Config = snapConfig;

            propSockets.Clear();
        }
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            base.BuildDungeon(config, model);

            random = new System.Random((int)config.Seed);

            // We know that the dungeon prefab would have the appropriate config and models attached to it
            // Cast and save it for future reference
            isaacConfig       = config as IsaacDungeonConfig;
            isaacModel        = model as IsaacDungeonModel;
            isaacModel.config = isaacConfig;

            // Generate the city layout and save it in a model.   No markers are emitted here.
            GenerateLevelLayout();
        }
Exemple #13
0
    public void DisplaySurplusTimes(int dungeonId)
    {
        var config       = DungeonConfig.Get(dungeonId);
        var surplusTimes = 0;

        if (config.dailyTimes > 0)
        {
            surplusTimes = Dungeon.Instance.GetDailySurplusTimes(dungeonId);
        }
        else
        {
            surplusTimes = Dungeon.Instance.GetWeekSurplusTimes(dungeonId);
        }
        m_SurplusTimes.SetText(surplusTimes);
    }
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            base.BuildDungeon(config, model);

            random = new System.Random((int)config.Seed);

            // We know that the dungeon prefab would have the appropriate config and models attached to it
            // Cast and save it for future reference
            floorPlanConfig       = config as FloorPlanConfig;
            floorPlanModel        = model as FloorPlanModel;
            floorPlanModel.Config = floorPlanConfig;

            // Generate the city layout and save it in a model.   No markers are emitted here.
            BuildLayout();

            propSockets.Clear();
        }
        public string CreateDungeon(DungeonConfig configuration)
        {
            //use a child container for this request which will dispose everything
            using (TinyIoCContainer requestContainer = _container.GetChildContainer())
            {
                //register the requested config for others to find it
                requestContainer.Register <DungeonConfig>(configuration);

                string id = requestContainer.Resolve <IIdGenerator>().GetNextId(configuration.Name);
                DungeonConfigEntity dungeonConfig = requestContainer.Resolve <DungeonConfigEntity>();
                IDungeonDepot       depot         = requestContainer.Resolve <IDungeonDepot>();

                depot.Add(id, dungeonConfig);

                return(id);
            }
        }
Exemple #16
0
        void DrawOverlayData(DungeonConfig config, GridDungeonModel model, bool mode2D)
        {
            var mode                 = target as DungeonPaintModeGrid;
            var opacity              = mode.overlayOpacity;
            var gridSize             = config.GridCellSize;
            var cellColorProcedural  = Color.blue;
            var cellColorUserDefined = Color.cyan;

            // Visualize the user defined cells defined by the paint tool
            foreach (var cell in model.Cells)
            {
                var size     = Vector3.Scale(DMathUtils.ToVector3(cell.Bounds.Size), gridSize);
                var location = Vector3.Scale(DMathUtils.ToVector3(cell.Bounds.Location), gridSize);
                var color    = cell.UserDefined ? cellColorUserDefined : cellColorProcedural;
                DrawRect(location, size, color, opacity, 0.3f, mode2D);
            }
        }
Exemple #17
0
 public static void Init()
 {
     ItemConfig.Init();
     TestConfig.Init();
     WindowConfig.Init();
     EffectConfig.Init();
     EquipConfig.Init();
     IconConfig.Init();
     LanguageConfig.Init();
     WorldBossConfig.Init();
     NpcConfig.Init();
     MapConfig.Init();
     DungeonConfig.Init();
     DamageNumConfig.Init();
     SkillConfig.Init();
     MobAssetConfig.Init();
     //初始化结束
 }
Exemple #18
0
    /// <summary>
    /// Creates the dungeon in an async way.
    /// </summary>
    /// <param name="seed">The random seed for the dungeon.</param>
    /// <param name="levelNumber">The current level number.</param>
    /// <param name="config">The config to load and use during generation.</param>
    /// <param name="tileset">The tileset to use for the tilemap generation.</param>
    public IEnumerator CreateDungeon(int seed, int levelNumber, DungeonConfig config, Tileset tileset, Dungeon dungeonToLoad = null)
    {
        timer = new DungeonTimer();
        timer.Start();

        yield return(DestroyPreviousGameObjects());

        dungeon = dungeonToLoad;
        if (dungeon == null)
        {
            Debug.Log("Creating dungeon with seed: " + seed);
            // Load all room types
            List <Fast2DArray <int> > roomLayouts = new List <Fast2DArray <int> >();
            List <List <TiledImporter.PrefabLocations> > roomGameObjects = new List <List <TiledImporter.PrefabLocations> >();
            List <RoomType> roomTypes = new List <RoomType>();
            yield return(LoadRoomTypes(roomLayouts, roomGameObjects, roomTypes));

            //seed = -1304249244;
            seed    = "I wanna go home".GetHashCode();
            dungeon = new Dungeon(roomLayouts.ToArray(), roomGameObjects.ToArray(), roomTypes.ToArray(), seed, config);
        }
        DungeonDict.Instance.dungeon = dungeon;

        AdjustMask();

        yield return(ClearPreviousTiles());

        yield return(SetTiles(tileset));

        yield return(SetBorderTiles(tileset));

        yield return(roomCreator.CreateRooms(dungeon, levelNumber, config, timer));

        MiniMapManager.Instance.OnNewLevelGenerated();

        SetLoadStatus(1.0f);

        position = transform.position;

        if (Player.LocalPlayer) // check to allow for debugging if a localplayer is not scene
        {
            Player.LocalPlayer.StateCommunicator.LevelSetLoaded(true);
        }
    }
Exemple #19
0
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            base.BuildDungeon(config, model);

            random = new System.Random((int)config.Seed);

            // We know that the dungeon prefab would have the appropriate config and models attached to it
            // Cast and save it for future reference
            cityConfig       = config as CircularCityDungeonConfig;
            cityModel        = model as CircularCityDungeonModel;
            cityModel.Config = cityConfig;

            // Generate the city layout and save it in a model.   No markers are emitted here.
            GenerateCityLayout();

            sw.Stop();
            Debug.Log("Time elapsed: " + (sw.ElapsedMilliseconds / 1000.0f) + " s");
        }
Exemple #20
0
    private void DisplayBaseInfo(int dungeonId)
    {
        var config = DungeonConfig.Get(dungeonId);

        m_DungeonName.SetLanguage(config.name);
        m_Introduce.SetLanguage(config.description);
        m_TimeLimit.SetText(config.timeLimit);
        m_RecommenLevel.SetText(StringUtil.Contact(config.recommendLevel.x, "--", config.recommendLevel.y));

        var items = new List <Item>();

        foreach (var reward in config.rewards)
        {
            items.Add(new Item()
            {
                id    = reward.x,
                count = reward.y
            });
        }

        m_Rewards.Display(items);
    }
Exemple #21
0
    public static DungeonConfig Get(int id)
    {
        if (!inited)
        {
            Debug.Log("DungeonConfigConfig 还未完成初始化。");
            return(null);
        }

        if (configs.ContainsKey(id))
        {
            return(configs[id]);
        }

        DungeonConfig config = null;

        if (rawDatas.ContainsKey(id))
        {
            config = configs[id] = new DungeonConfig(rawDatas[id]);
            rawDatas.Remove(id);
        }

        return(config);
    }
Exemple #22
0
    private IEnumerator Start()
    {
        yield return(new WaitForSeconds(0.1f));

        UIManager.Instance.ShowLevelLoadScreen();
        DungeonDict.Instance.ClearRooms();
        RegionSceneLoader loader = RegionSceneLoader.Instance;

        yield return(loader.LoadScene(Region.EnemyTestRoom));

        Vector2Int weaponSize   = new Vector2Int(30, 30);
        Vector2Int corridorSize = new Vector2Int(10, 2);
        Vector2Int enemySize    = new Vector2Int(20, 20);
        Vector2Int startSize    = new Vector2Int(10, 10);

        Vector2Int weaponPos    = new Vector2Int(1, 3);
        Vector2Int startPos     = new Vector2Int(weaponPos.x + weaponSize.x + corridorSize.x - 2, 3);
        Vector2Int corridor1Pos = startPos + new Vector2Int(0, 2);// - new Vector2Int(corridorSize.x, -2);
        Vector2Int corridor2Pos = startPos + new Vector2Int(startSize.x - 1, 2);
        Vector2Int enemyPos     = startPos + new Vector2Int(startSize.x - 1, 0) + new Vector2Int(corridorSize.x - 1, 0);

        Fast2DArray <TileType> layout = new Fast2DArray <TileType>(startSize.x, startSize.y);

        FillRoomWithBounds(layout);
        layout.Set(TileType.CorridorAccess, layout.XSize - 1, 2);
        layout.Set(TileType.CorridorAccess, layout.XSize - 1, 3);

        List <TiledImporter.PrefabLocations> gameObjects = new List <TiledImporter.PrefabLocations>();
        Room startRoom = new Room(startPos.x, startPos.y, layout, gameObjects, RoomType.Start);

        layout = new Fast2DArray <TileType>(weaponSize.x, weaponSize.y);
        FillRoomWithBounds(layout);
        layout.Set(TileType.CorridorAccess, layout.XSize - 1, 2);
        layout.Set(TileType.CorridorAccess, layout.XSize - 1, 3);
        Room weaponRoom = new Room(weaponPos.x, weaponPos.y, layout, gameObjects, RoomType.Empty);

        Corridor corridor1 = new Corridor(corridor1Pos.x, corridor1Pos.y, corridorSize.x, Direction.Left);
        Corridor corridor2 = new Corridor(corridor2Pos.x, corridor2Pos.y, corridorSize.x, Direction.Right);

        layout = new Fast2DArray <TileType>(enemySize.x, enemySize.y);
        FillRoomWithBounds(layout);
        for (int x = 3; x < enemySize.x - 2; x++)
        {
            for (int y = 5; y < enemySize.y - 2; y += 5)
            {
                layout.Set(TileType.Wall, x, y);
            }
        }
        layout.Set(TileType.CorridorAccess, 0, 2);
        layout.Set(TileType.CorridorAccess, 0, 3);

        Room enemyRoom = new Room(enemyPos.x, enemyPos.y, layout, gameObjects, RoomType.Combat);

        Room[]     rooms     = { startRoom, enemyRoom, weaponRoom };
        Corridor[] corridors = { corridor1, corridor2 };

        if (Player.LocalPlayer.isServer)
        {
            GlobalsDict.Instance.GameStateManagerObject.AddComponent <GameManager>();
        }

        Dungeon       dungeon = new Dungeon(rooms, corridors, enemyPos + new Vector2Int(layout.XSize, layout.YSize));
        DungeonConfig config  = DungeonConfig.StandardConfig;

        yield return(DungeonCreator.Instance.CreateDungeon(-1, 1, config, RegionDict.Instance.Tileset, dungeon));

        CombatRoom combatRoom = DungeonDict.Instance.Rooms.First(x => x.RoomType == RoomType.Combat) as CombatRoom;

        combatRoom.enemiesToSpawn = enemiesToSpawn;

        Destroy(gameObject);
    }
        private void GenerateActorsInDungeon(Dungeon currentDungeon, DungeonConfig dungeonConfig, bool isFirstDungeon)
        {
            BoundsInt playerRoom = new BoundsInt();

            if (isFirstDungeon)
            {
                BoundsInt furthestRoomToStairs = FurthestRoomToStairsResolver.GetFurthestRoomToStairs(currentDungeon);

                playerRoom = furthestRoomToStairs;

                BoundsInt  roomToSpawnPlayerIn = playerRoom;
                Vector2Int playerPosition      = BoundsIntUtilities.Center(roomToSpawnPlayerIn);
                Vector2Int breadPosition       = Vector2Int.zero;
                var        neighboursRebourse  = Vector2IntUtilities.Neighbours8(playerPosition).ToList();
                neighboursRebourse.Reverse();
                foreach (var neighbour in neighboursRebourse)
                {
                    if (_gridInfoProvider.IsWalkable(neighbour) && neighbour != playerPosition)
                    {
                        _entitySpawner.SpawnItem(BreadItem, neighbour);
                        breadPosition = neighbour;
                        break;
                    }
                }
                foreach (var neighbour in neighboursRebourse)
                {
                    if (neighbour != breadPosition && _gridInfoProvider.IsWalkable(neighbour))
                    {
                        _entitySpawner.SpawnItem(KeyItem, neighbour);
                        break;
                    }
                }
                BoundsInt aroundPlayerRoom = new BoundsInt(playerRoom.position - new Vector3Int(1, 1, 0),
                                                           playerRoom.size + new Vector3Int(2, 2, 0));
                foreach (Vector3Int positionInPlayerRoom in aroundPlayerRoom.allPositionsWithin)
                {
                    if (_gameContext.WallsTilemap.GetTile(positionInPlayerRoom) == DoorsVerticalClosed ||
                        _gameContext.EnvironmentTilemap.GetTile(positionInPlayerRoom) == DoorsVerticalOpen)
                    {
                        _gameContext.WallsTilemap.SetTile(positionInPlayerRoom, HeavyDoorsVerticalClosed);
                        _gameContext.EnvironmentTilemap.SetTile(positionInPlayerRoom, null);
                    }
                    if (_gameContext.WallsTilemap.GetTile(positionInPlayerRoom) == DoorsHorizontalClosed ||
                        _gameContext.EnvironmentTilemap.GetTile(positionInPlayerRoom) == DoorsHorizontalOpen)
                    {
                        _gameContext.WallsTilemap.SetTile(positionInPlayerRoom, HeavyDoorsHorizontalClosed);
                        _gameContext.EnvironmentTilemap.SetTile(positionInPlayerRoom, null);
                    }
                }
                var playerActorBehaviour = _entitySpawner.SpawnActor(ActorType.Player, playerPosition);

                playerActorBehaviour.ActorData.ControlledByPlayer = true;
                _gameContext.PlayerActor = playerActorBehaviour;
                _gameConfig.FollowPlayerCamera.Follow    = playerActorBehaviour.transform;
                _uiConfig.Arrows.transform.parent        = playerActorBehaviour.transform;
                _uiConfig.Arrows.transform.localPosition = new Vector3(0, -0.1f, 0);
            }

            foreach (BoundsInt room in currentDungeon.Rooms.Skip(isFirstDungeon ? 1 :0))
            {
                if (room == playerRoom)
                {
                    continue;
                }
                float populationValue  = _rng.NextFloat();
                int   populationInRoom = Mathf.RoundToInt(dungeonConfig.ChanceToRoomPopulation.Evaluate(populationValue));
                for (int i = 0; i < populationInRoom; i++)
                {
                    ActorDefinition[] actorTypesAvailable = dungeonConfig.EnemiesToSpawn;
                    ActorType         actorTypeChosen     = _rng.Choice(actorTypesAvailable).ActorType;
                    Vector2Int        centralPosition     = BoundsIntUtilities.Center(room);
                    _entitySpawner.SpawnActor(actorTypeChosen, centralPosition);
                }
            }

            _entitySpawner.SpawnActor(dungeonConfig.BossToSpawn.ActorType, currentDungeon.StairsLocation, true);
        }
Exemple #24
0
 public DungeonConfigEntity(DungeonConfig baseConfig, ISeedGenerator seedGenerator)
     : base(baseConfig.Name, baseConfig.Size.Length, baseConfig.Size.Width)
 {
     GenerationSeed = seedGenerator.GetNextSeed();
 }
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            base.BuildDungeon(config, model);

            propSockets.Clear();
        }