diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
index b9b8ad9..cba1da9 100644
--- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
+++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
@@ -205,14 +205,13 @@
{
ShopRoomInfos.Add(nextRoom);
}
- var prev = prevRoomInfo;
prevRoomInfo = nextRoom;
- _rule.GenerateRoomSuccess(prev, nextRoom);
+ _rule.GenerateRoomSuccess(tempPrevRoomInfo, nextRoom);
_nextRoomType = _rule.GetNextRoomType(nextRoom);
}
else //生成失败
{
- _rule.GenerateRoomFail(prevRoomInfo, nextRoomType);
+ _rule.GenerateRoomFail(tempPrevRoomInfo, nextRoomType);
//Debug.Log("生成第" + (_count + 1) + "个房间失败! 失败原因: " + errorCode);
if (errorCode == GenerateRoomErrorCode.OutArea)
@@ -238,7 +237,7 @@
_roomGrid.Clear();
Debug.Log("房间总数: " + RoomInfos.Count);
-
+ Debug.Log("尝试次数: " + currTryCount);
return true;
}
@@ -466,8 +465,9 @@
///
/// 寻找层级最高的房间
///
+ /// 指定房间类型, 如果传 None 则表示选择所有类型房间
/// 排除的房间
- public RoomInfo FindMaxLayerRoom(List exclude = null)
+ public RoomInfo FindMaxLayerRoom(DungeonRoomType roomType, List exclude = null)
{
RoomInfo temp = null;
foreach (var roomInfo in RoomInfos)
@@ -476,12 +476,9 @@
{
continue;
}
- if (temp == null || roomInfo.Layer > temp.Layer)
+ if ((temp == null || roomInfo.Layer > temp.Layer) && (roomType == DungeonRoomType.None || (roomInfo.RoomType & roomType) != DungeonRoomType.None) && (exclude == null || !exclude.Contains(roomInfo)))
{
- if (exclude == null || !exclude.Contains(roomInfo))
- {
- temp = roomInfo;
- }
+ temp = roomInfo;
}
}
@@ -491,7 +488,10 @@
///
/// 随机抽取层级小于 layer 的房间
///
- public RoomInfo RandomRoomLessThanLayer(int layer)
+ /// 指定房间类型, 如果传 None 则表示选择所有类型房间
+ ///
+ /// 排除的房间
+ public RoomInfo RandomRoomLessThanLayer(DungeonRoomType roomType, int layer, List exclude = null)
{
_tempList.Clear();
foreach (var roomInfo in RoomInfos)
@@ -500,7 +500,31 @@
{
continue;
}
- if (roomInfo.Layer < layer)
+ if (roomInfo.Layer < layer && (roomType == DungeonRoomType.None || (roomInfo.RoomType & roomType) != DungeonRoomType.None) && (exclude == null || !exclude.Contains(roomInfo)))
+ {
+ _tempList.Add(roomInfo);
+ }
+ }
+
+ return Random.RandomChoose(_tempList);
+ }
+
+ ///
+ /// 随机抽取层级大于 layer 的房间
+ ///
+ /// 指定房间类型, 如果传 None 则表示选择所有类型房间
+ ///
+ /// 排除的房间
+ public RoomInfo RandomRoomGreaterThanLayer(DungeonRoomType roomType, int layer, List exclude = null)
+ {
+ _tempList.Clear();
+ foreach (var roomInfo in RoomInfos)
+ {
+ if (roomInfo.CanRollback)
+ {
+ continue;
+ }
+ if (roomInfo.Layer > layer && (roomType == DungeonRoomType.None || (roomInfo.RoomType & roomType) != DungeonRoomType.None) && (exclude == null || !exclude.Contains(roomInfo)))
{
_tempList.Add(roomInfo);
}
@@ -512,7 +536,8 @@
///
/// 随机抽取房间
///
- public RoomInfo GetRandomRoom()
+ /// 指定房间类型, 如果传 None 则表示选择所有类型房间
+ public RoomInfo GetRandomRoom(DungeonRoomType roomType)
{
_tempList.Clear();
foreach (var roomInfo in RoomInfos)
@@ -521,7 +546,11 @@
{
continue;
}
- _tempList.Add(roomInfo);
+
+ if (roomType == DungeonRoomType.None || (roomInfo.RoomType & roomType) != DungeonRoomType.None)
+ {
+ _tempList.Add(roomInfo);
+ }
}
return Random.RandomChoose(_tempList);
diff --git a/DungeonShooting_Godot/src/framework/map/DungeonRoomType.cs b/DungeonShooting_Godot/src/framework/map/DungeonRoomType.cs
index 7b822c7..64bf354 100644
--- a/DungeonShooting_Godot/src/framework/map/DungeonRoomType.cs
+++ b/DungeonShooting_Godot/src/framework/map/DungeonRoomType.cs
@@ -1,39 +1,42 @@
+using System;
+
///
/// 模板房间类型
///
+[Flags]
public enum DungeonRoomType
{
///
/// 无
///
- None,
+ None = 0,
///
/// 普通战斗房间, 进入该房间时会关上门, 并刷出若干波敌人, 消灭所有敌人后开门
///
- Battle,
+ Battle = 0b1,
///
/// 起始房间, 由上一层地牢的结束房间进入该房间, 每层包含一个起始房间
///
- Inlet,
+ Inlet = 0b10,
///
/// 结束房间, 进入另一层地牢, 每层只是包含一个结束房间
///
- Outlet,
+ Outlet = 0b100,
///
/// boss战房间, 进入房间时会关上没, 刷出boss, 消灭boss后开门
///
- Boss,
+ Boss = 0b1000,
///
/// 奖励房间, 给予玩家武器或者道具奖励的房间
///
- Reward,
+ Reward = 0b10000,
///
/// 商店, 玩家买卖道具装备的房间
///
- Shop,
+ Shop = 0b100000,
///
/// 事件房间, 触发剧情或者解锁NPC的房间
///
- Event,
+ Event = 0b1000000,
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs
index 7d82ea4..5fd28f9 100644
--- a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs
@@ -61,7 +61,7 @@
ActivePropsPack.SetCapacity(1);
// debug用
- //DebugSet();
+ DebugSet();
//注册状态机
StateController.Register(new PlayerIdleState());
diff --git a/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs b/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs
index 8820212..64b9a7e 100644
--- a/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs
+++ b/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs
@@ -16,6 +16,8 @@
//结束房间尝试链接次数
private int outletTryCount = 0;
+ //奖励房间绑定的上一个房间
+ private List rewardBindRoom = new List();
private readonly RoomDirection[] _roomDirections = new []{ RoomDirection.Up, RoomDirection.Down, RoomDirection.Left, RoomDirection.Right };
@@ -36,26 +38,39 @@
}
else if (nextRoomType == DungeonRoomType.Boss)
{
- return Generator.FindMaxLayerRoom(excludePrevRoom);
+ return Generator.FindMaxLayerRoom(DungeonRoomType.Battle | DungeonRoomType.Shop, excludePrevRoom);
}
- else if (nextRoomType == DungeonRoomType.Outlet || nextRoomType == DungeonRoomType.Reward || nextRoomType == DungeonRoomType.Shop || nextRoomType == DungeonRoomType.Event)
+ else if (nextRoomType == DungeonRoomType.Outlet || nextRoomType == DungeonRoomType.Shop || nextRoomType == DungeonRoomType.Event)
{
return prevRoom;
}
+ else if (nextRoomType == DungeonRoomType.Reward)
+ {
+ foreach (var temp in rewardBindRoom)
+ {
+ if (!excludePrevRoom.Contains(temp))
+ {
+ excludePrevRoom.Add(temp);
+ }
+ }
+
+ return Generator.FindMaxLayerRoom(DungeonRoomType.Battle | DungeonRoomType.Shop | DungeonRoomType.Event, excludePrevRoom);
+ }
else if (nextRoomType == DungeonRoomType.Battle)
{
if (battleTryCount < battleMaxTryCount)
{
- if (prevRoom != null && prevRoom.Layer >= Config.MaxLayer - 1) //层数太高, 下一个房间生成在低层级
+ if (prevRoom == null || prevRoom.Layer >= Config.MaxLayer - 1) //层数太高, 下一个房间生成在低层级
{
- return Generator.RandomRoomLessThanLayer(Mathf.Max(1, Config.MaxLayer / 2));
+ return Generator.RandomRoomLessThanLayer(DungeonRoomType.Battle | DungeonRoomType.Shop | DungeonRoomType.Event | DungeonRoomType.Inlet, Mathf.Max(1, Config.MaxLayer / 2));
}
return prevRoom;
}
+ return Generator.GetRandomRoom(DungeonRoomType.Battle | DungeonRoomType.Shop | DungeonRoomType.Event | DungeonRoomType.Inlet);
}
- return Generator.GetRandomRoom();
+ return Generator.GetRandomRoom(DungeonRoomType.None);
}
public override DungeonRoomType GetNextRoomType(RoomInfo prevRoom)
@@ -64,15 +79,24 @@
{
return DungeonRoomType.Inlet;
}
- // else if (Generator.BattleRoomInfos.Count == 0) //奖励房间
- // {
- // return DungeonRoomType.Reward;
- // }
- else if (prevRoom.RoomType == DungeonRoomType.Boss) //boss房间后生成结束房间
+
+ if (prevRoom != null)
{
- return DungeonRoomType.Outlet;
+ if (prevRoom.RoomType == DungeonRoomType.Boss) //boss房间后生成结束房间
+ {
+ return DungeonRoomType.Outlet;
+ }
+
+ if (Generator.RewardRoomInfos.Count < Config.RewardRoomCount)
+ {
+ if (prevRoom.Id == Config.BattleRoomCount / (Config.RewardRoomCount + 1) * (Generator.RewardRoomInfos.Count + 1)) //奖励房间
+ {
+ return DungeonRoomType.Reward;
+ }
+ }
}
- else if (Generator.BattleRoomInfos.Count >= Config.BattleRoomCount) //战斗房间已满
+
+ if (Generator.BattleRoomInfos.Count >= Config.BattleRoomCount) //战斗房间已满
{
if (Generator.BossRoomInfos.Count < Config.BossRoomCount) //最后一个房间是boss房间
{
@@ -104,6 +128,11 @@
outletTryCount = 0;
Generator.SubmitCanRollbackRoom();
}
+ else if (roomInfo.RoomType == DungeonRoomType.Reward)
+ {
+ rewardBindRoom.Add(prevRoom);
+ excludePrevRoom.Clear();
+ }
if (prevRoom != null && prevRoom.CanRollback)
{
@@ -113,9 +142,9 @@
public override void GenerateRoomFail(RoomInfo prevRoom, DungeonRoomType roomType)
{
- if (roomType == DungeonRoomType.Boss)
+ if (roomType == DungeonRoomType.Boss || roomType == DungeonRoomType.Reward)
{
- //生成boss房间成功
+ //生成房间失败
excludePrevRoom.Add(prevRoom);
if (excludePrevRoom.Count >= Generator.RoomInfos.Count)
{