diff --git a/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs b/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs index 90075e0..313e874 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs @@ -36,6 +36,11 @@ /// public int BossRoomCount = 1; + /// + /// 房间数量 + /// + public int RoomCount => BattleRoomCount + RewardRoomCount + ShopRoomCount + OutRoomCount + BossRoomCount; + //----------------------- 地牢编辑使用 ------------------------- /// /// 是否指定了房间 diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs index ebb8306..1b400f8 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs @@ -18,18 +18,33 @@ /// 起始房间 /// public RoomInfo StartRoomInfo { get; private set; } + + /// + /// 战斗房间 + /// + public List BattleRoomInfos { get; } = new List(); /// /// 结束房间 /// - public RoomInfo EndRoomInfo { get; private set; } + public List EndRoomInfos { get; } = new List(); /// /// boss房间 /// - public List BossRoom { get; } = new List(); + public List BossRoomInfos { get; } = new List(); + + /// + /// 奖励房间 + /// + public List RewardRoomInfos { get; } = new List(); /// + /// 商店房间 + /// + public List ShopRoomInfos { get; } = new List(); + + /// /// 地牢配置数据 /// public DungeonConfig Config { get; } @@ -46,8 +61,6 @@ //用于标记地图上的坐标是否被占用 private InfiniteGrid _roomGrid { get; } = new InfiniteGrid(); - //当前房间数量 - private int _count = 0; //房间id private int _id; @@ -167,7 +180,7 @@ if (StartRoomInfo != null) return false; _rule = rule; - CalcNextRoomType(null); + _nextRoomType = _rule.GetNextRoomType(null); //用于排除上一级房间 var excludePrevRoom = new List(); //上一个房间 @@ -183,9 +196,9 @@ var currTryCount = 0; //如果房间数量不够, 就一直生成 - while (_count < Config.BattleRoomCount || EndRoomInfo == null) + while (!_rule.CanOverGenerator() || EndRoomInfos.Count == 0) { - var nextRoomType = GetNextRoomType(); + var nextRoomType = _nextRoomType; //上一个房间 RoomInfo tempPrevRoomInfo; @@ -236,20 +249,29 @@ } else if (nextRoomType == DungeonRoomType.Boss) //boss房间 { - BossRoom.Add(nextRoom); + BossRoomInfos.Add(nextRoom); excludePrevRoom.Clear(); } else if (nextRoomType == DungeonRoomType.Outlet) { - EndRoomInfo = nextRoom; + EndRoomInfos.Add(nextRoom); } else if (nextRoomType == DungeonRoomType.Battle) { + BattleRoomInfos.Add(nextRoom); chainTryCount = 0; chainMaxTryCount = Random.RandomRangeInt(1, 3); } + else if (nextRoomType == DungeonRoomType.Reward) + { + RewardRoomInfos.Add(nextRoom); + } + else if (nextRoomType == DungeonRoomType.Shop) + { + ShopRoomInfos.Add(nextRoom); + } prevRoomInfo = nextRoom; - CalcNextRoomType(prevRoomInfo); + _nextRoomType = _rule.GetNextRoomType(prevRoomInfo); } else //生成失败 { @@ -269,9 +291,9 @@ if (prevRoomInfo != null) { var bossPrev = prevRoomInfo.Prev; - BossRoom.Remove(prevRoomInfo); + BossRoomInfos.Remove(prevRoomInfo); RollbackRoom(prevRoomInfo); - CalcNextRoomType(bossPrev); + _nextRoomType = _rule.GetNextRoomType(bossPrev); prevRoomInfo = null; } } @@ -450,11 +472,6 @@ room.Layer = 0; _roomGrid.SetRect(room.Position, room.Size, true); } - - if (IsParticipateCounting(room)) - { - _count++; - } _id++; room.Prev = prevRoomInfo; @@ -466,47 +483,6 @@ return GenerateRoomErrorCode.NoError; } - //判断房间是否参与计数 - private bool IsParticipateCounting(RoomInfo roomInfo) - { - return roomInfo.RoomType == DungeonRoomType.Battle || roomInfo.RoomType == DungeonRoomType.Boss || roomInfo.RoomType == DungeonRoomType.Reward; - } - - //计算下一个房间类型 - private void CalcNextRoomType(RoomInfo prev) - { - if (prev == null) //生成第一个房间 - { - _nextRoomType = DungeonRoomType.Inlet; - } - else if (_count == 0) //奖励房间 - { - _nextRoomType = DungeonRoomType.Reward; - } - else if (_count == Config.BattleRoomCount - 1) //最后一个房间是boss房间 - { - _nextRoomType = DungeonRoomType.Boss; - } - else if (_count >= Config.BattleRoomCount) //结束房间 - { - _nextRoomType = DungeonRoomType.Outlet; - } - else if (prev.RoomType == DungeonRoomType.Boss) //生成结束房间 - { - _nextRoomType = DungeonRoomType.Outlet; - } - else - { - _nextRoomType = DungeonRoomType.Battle; - } - } - - //获取下一个房间类型 - private DungeonRoomType GetNextRoomType() - { - return _nextRoomType; - } - //回滚一个房间 private bool RollbackRoom(RoomInfo roomInfo) { @@ -537,12 +513,6 @@ RoomInfos.Remove(roomInfo); roomInfo.Destroy(); - - if (IsParticipateCounting(roomInfo)) - { - _count--; - } - _id--; return true; } diff --git a/DungeonShooting_Godot/src/framework/map/DungeonRule.cs b/DungeonShooting_Godot/src/framework/map/DungeonRule.cs index c4d7238..7357120 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonRule.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonRule.cs @@ -16,9 +16,14 @@ Config = generator.Config; Random = generator.Random; } + + /// + /// 是否可以结束生成了 + /// + public abstract bool CanOverGenerator(); /// /// 计算下一个房间类型 /// - public abstract DungeonRoomType CalcNextRoomType(RoomInfo prev); + public abstract DungeonRoomType GetNextRoomType(RoomInfo prev); } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs b/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs index 601ad26..d092b84 100644 --- a/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs +++ b/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs @@ -8,8 +8,33 @@ { } - public override DungeonRoomType CalcNextRoomType(RoomInfo prev) + public override bool CanOverGenerator() { + return Generator.BattleRoomInfos.Count >= Config.BattleRoomCount; + } + + public override DungeonRoomType GetNextRoomType(RoomInfo prev) + { + if (Generator.StartRoomInfo == null) //生成第一个房间 + { + return DungeonRoomType.Inlet; + } + // else if (Generator.BattleRoomInfos.Count == 0) //奖励房间 + // { + // return DungeonRoomType.Reward; + // } + else if (Generator.BattleRoomInfos.Count == Config.BattleRoomCount - 1) //最后一个房间是boss房间 + { + return DungeonRoomType.Boss; + } + else if (Generator.BattleRoomInfos.Count >= Config.BattleRoomCount) //结束房间 + { + return DungeonRoomType.Outlet; + } + else if (prev.RoomType == DungeonRoomType.Boss) //生成结束房间 + { + return DungeonRoomType.Outlet; + } return DungeonRoomType.Battle; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs index 3a8f4c8..9172f1e 100644 --- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs +++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs @@ -219,7 +219,7 @@ { UiManager.Open_Main(); } - EditorWindowManager.ShowTips("错误", "生成房间尝试次数过多,生成地牢房间失败,请加大房间门连接区域!"); + EditorWindowManager.ShowTips("错误", "生成房间尝试次数过多,生成地牢房间失败,请加大房间门连接区域,或者修改地牢生成规则!"); yield break; } yield return 0;