diff --git a/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json b/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json index d8cf525..fc14eb8 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json @@ -24,7 +24,12 @@ "Path": "resource/map/tileMaps/Test1/outlet/End1" } ], - "BossList": [], + "BossList": [ + { + "ErrorType": 0, + "Path": "resource/map/tileMaps/Test1/boss/Boss1" + } + ], "RewardList": [ { "ErrorType": 0, diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preinstall.json b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preinstall.json new file mode 100644 index 0000000..a9f951a --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preinstall.json @@ -0,0 +1 @@ +[{"Name":"Preinstall1","Weight":100,"Remark":"","AutoFill":true,"WaveList":[[]]}] \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preview.png b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preview.png new file mode 100644 index 0000000..7a6c9c2 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preview.png Binary files differ diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preview.png.import b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preview.png.import new file mode 100644 index 0000000..b80c33b --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/Preview.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dp0vxdpgngsj8" +path="res://.godot/imported/Preview.png-46acff5fa2872af249169769a17dd53e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/map/tileMaps/Test1/boss/Boss1/Preview.png" +dest_files=["res://.godot/imported/Preview.png-46acff5fa2872af249169769a17dd53e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/RoomInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/RoomInfo.json new file mode 100644 index 0000000..adba4d9 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/RoomInfo.json @@ -0,0 +1 @@ +{"Position":{"X":-7,"Y":-13},"Size":{"X":24,"Y":20},"DoorAreaInfos":[],"GroupName":"Test1","RoomType":3,"RoomName":"Boss1","Weight":100,"Remark":""} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/TileInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/TileInfo.json new file mode 100644 index 0000000..59630cf --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/boss/Boss1/TileInfo.json @@ -0,0 +1 @@ +{"NavigationVertices":[{"X":198,"Y":-30},{"X":170,"Y":-30},{"X":22,"Y":-42},{"X":22,"Y":-78},{"X":234,"Y":-154},{"X":234,"Y":82},{"X":198,"Y":38},{"X":-74,"Y":82},{"X":138,"Y":38},{"X":-74,"Y":-154},{"X":-10,"Y":-110},{"X":-10,"Y":-78},{"X":170,"Y":2},{"X":138,"Y":2},{"X":-38,"Y":-42},{"X":-38,"Y":-110}],"NavigationPolygon":[[0,1,2,3],[4,5,6,0],[6,5,7,8],[9,4,0,10],[3,11,10],[1,12,13,2],[2,13,8,7,14],[14,7,9,15],[10,15,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0,3,12,2,0,3,12,3,0,3,13,-10,0,3,13,-9,0,3,13,-8,0,3,13,-7,0,3,13,-6,0,3,13,-5,0,3,13,-4,0,3,13,-3,0,3,13,-2,0,3,13,-1,0,3,13,0,0,3,13,1,0,3,13,2,0,3,13,3,0,3,7,0,0,3,7,1,0,3,-5,4,0,3,-4,4,0,3,-3,4,0,3,-2,4,0,3,-1,4,0,3,0,4,0,3,1,4,0,3,2,4,0,3,3,4,0,3,4,4,0,3,5,4,0,3,6,4,0,3,7,4,0,3,8,4,0,3,9,4,0,3,10,4,0,3,11,4,0,3,12,4,0,3,13,4,0,3,14,-10,0,3,14,-9,0,3,14,-8,0,3,14,-7,0,3,14,-6,0,3,14,-5,0,3,14,-4,0,3,14,-3,0,3,14,-2,0,3,14,-1,0,3,14,0,0,3,14,1,0,3,14,2,0,3,14,3,0,3,14,4,0,3,10,-2,0,3,10,-1,0,3,-1,-7,0,3,-1,-6,0,3,8,0,0,3,8,1,0,3],"Middle":[-5,-12,63,1,-5,-11,2,2,-4,-12,63,1,-4,-11,2,2,-3,-12,63,1,-3,-11,2,2,-2,-12,63,1,-2,-11,2,2,-2,-5,50,1,-2,-4,1,2,-1,-12,63,1,-1,-11,2,2,-1,-5,56,1,-1,-4,2,2,0,-12,63,1,0,-11,2,2,0,-5,24,1,0,-4,3,2,1,-12,63,1,1,-11,2,2,2,-12,63,1,2,-11,2,2,3,-12,63,1,3,-11,2,2,4,-12,63,1,4,-11,2,2,5,-12,63,1,5,-11,2,2,6,-12,63,1,6,-11,2,2,7,-12,63,1,7,-11,2,2,8,-12,63,1,8,-11,2,2,9,-12,63,1,9,-11,2,2,9,0,48,1,9,1,1,2,10,-12,63,1,10,-11,2,2,10,0,56,1,10,1,2,2,11,-12,63,1,11,-11,2,2,11,0,26,1,11,1,3,2,12,-12,63,1,12,-11,2,2,13,-12,63,1,13,-11,2,2,14,-12,63,1,14,-11,2,2],"Top":[-7,-13,511,1,-7,-12,511,1,-7,-11,511,1,-7,-10,511,1,-7,-9,511,1,-7,-8,511,1,-7,-7,511,1,-7,-6,511,1,-7,-5,511,1,-7,-4,511,1,-7,-3,511,1,-7,-2,511,1,-7,-1,511,1,-7,0,511,1,-7,1,511,1,-7,2,511,1,-7,3,511,1,-7,4,511,1,-7,5,511,1,-7,6,511,1,-6,-13,511,1,-6,-12,255,1,-6,-11,219,1,-6,-10,219,1,-6,-9,219,1,-6,-8,219,1,-6,-7,219,1,-6,-6,219,1,-6,-5,219,1,-6,-4,219,1,-6,-3,219,1,-6,-2,219,1,-6,-1,219,1,-6,0,219,1,-6,1,219,1,-6,2,219,1,-6,3,219,1,-6,4,219,1,-6,5,507,1,-6,6,511,1,-5,-13,511,1,-5,5,504,1,-5,6,511,1,-4,-13,511,1,-4,5,504,1,-4,6,511,1,-3,-13,511,1,-3,5,504,1,-3,6,511,1,-2,-13,511,1,-2,-7,144,1,-2,-6,146,1,-2,5,504,1,-2,6,511,1,-1,-13,511,1,-1,5,504,1,-1,6,511,1,0,-13,511,1,0,5,504,1,0,6,511,1,1,-13,511,1,1,5,504,1,1,6,511,1,2,-13,511,1,2,5,504,1,2,6,511,1,3,-13,511,1,3,5,504,1,3,6,511,1,4,-13,511,1,4,5,504,1,4,6,511,1,5,-13,511,1,5,5,504,1,5,6,511,1,6,-13,511,1,6,5,504,1,6,6,511,1,7,-13,511,1,7,5,504,1,7,6,511,1,8,-13,511,1,8,5,504,1,8,6,511,1,9,-13,511,1,9,5,504,1,9,6,511,1,10,-13,511,1,10,5,504,1,10,6,511,1,11,-13,511,1,11,-2,144,1,11,-1,146,1,11,5,504,1,11,6,511,1,12,-13,511,1,12,5,504,1,12,6,511,1,13,-13,511,1,13,5,504,1,13,6,511,1,14,-13,511,1,14,5,504,1,14,6,511,1,15,-13,511,1,15,-12,447,1,15,-11,438,1,15,-10,438,1,15,-9,438,1,15,-8,438,1,15,-7,438,1,15,-6,438,1,15,-5,438,1,15,-4,438,1,15,-3,438,1,15,-2,438,1,15,-1,438,1,15,0,438,1,15,1,438,1,15,2,438,1,15,3,438,1,15,4,438,1,15,5,510,1,15,6,511,1,16,-13,511,1,16,-12,511,1,16,-11,511,1,16,-10,511,1,16,-9,511,1,16,-8,511,1,16,-7,511,1,16,-6,511,1,16,-5,511,1,16,-4,511,1,16,-3,511,1,16,-2,511,1,16,-1,511,1,16,0,511,1,16,1,511,1,16,2,511,1,16,3,511,1,16,4,511,1,16,5,511,1,16,6,511,1],"CustomFloor1":[],"CustomFloor2":[],"CustomFloor3":[],"CustomMiddle1":[],"CustomMiddle2":[],"CustomTop":[]} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/reward/Award1/Preview.png.import b/DungeonShooting_Godot/resource/map/tileMaps/Test1/reward/Award1/Preview.png.import index cb3cc03..f4902eb 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/Test1/reward/Award1/Preview.png.import +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/reward/Award1/Preview.png.import @@ -2,7 +2,11 @@ importer="texture" type="CompressedTexture2D" +<<<<<<< HEAD uid="uid://wew7xnxc4d50" +======= +uid="uid://c08d7xo84ssqp" +>>>>>>> faff39f870b1097c233b529865b4f3ee2311c8a3 path="res://.godot/imported/Preview.png-e48e389971aff40736b911be53ae62ea.ctex" metadata={ "vram_texture": false diff --git a/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs b/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs index 24516bd..313e874 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs @@ -12,20 +12,44 @@ public string GroupName; /// + /// 战斗房间数量 + /// + public int BattleRoomCount = 15; + + /// + /// 奖励房间数量 + /// + public int RewardRoomCount = 2; + + /// + /// 商店数量 + /// + public int ShopRoomCount = 1; + + /// + /// 出口房间数量 + /// + public int OutRoomCount = 1; + + /// + /// Boss房间数量 + /// + public int BossRoomCount = 1; + + /// /// 房间数量 /// - public int RoomCount = 15; - + public int RoomCount => BattleRoomCount + RewardRoomCount + ShopRoomCount + OutRoomCount + BossRoomCount; + + //----------------------- 地牢编辑使用 ------------------------- /// /// 是否指定了房间 /// public bool HasDesignatedRoom => DesignatedRoom != null && DesignatedRoom.Count > 0; - /// /// 指定房间类型 /// public DungeonRoomType DesignatedType; - /// /// 指定房间列表 /// diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs index 5ff6d7c..1b400f8 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs @@ -18,27 +18,49 @@ /// 起始房间 /// 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; } + /// + /// 所属地牢组 + /// + public DungeonRoomGroup RoomGroup { get; } /// /// 随机数对象 /// - private SeedRandom _random; + public SeedRandom Random; //用于标记地图上的坐标是否被占用 private InfiniteGrid _roomGrid { get; } = new InfiniteGrid(); - //当前房间数量 - private int _count = 0; //房间id private int _id; @@ -73,9 +95,8 @@ private int _maxTryCount = 10; private int _currMaxLayer = 0; - //地牢配置 - private DungeonConfig _config; - private DungeonRoomGroup _roomGroup; + //地牢房间规则处理类 + private DungeonRule _rule; private enum GenerateRoomErrorCode { @@ -92,9 +113,9 @@ public DungeonGenerator(DungeonConfig config, SeedRandom seedRandom) { - _config = config; - _random = seedRandom; - _roomGroup = GameApplication.Instance.RoomConfig[config.GroupName]; + Config = config; + Random = seedRandom; + RoomGroup = GameApplication.Instance.RoomConfig[config.GroupName]; //验证该组是否满足生成地牢的条件 var result = DungeonManager.CheckDungeon(config.GroupName); @@ -103,8 +124,8 @@ throw new Exception("当前组'" + config.GroupName + "'" + result.ErrorMessage + ", 不能生成地牢!"); } - Debug.Log("创建地牢生成器, 随机种子: " + _random.Seed); - _roomGroup.InitWeight(_random); + Debug.Log("创建地牢生成器, 随机种子: " + Random.Seed); + RoomGroup.InitWeight(Random); } /// @@ -154,11 +175,12 @@ /// /// 生成房间 /// - public bool Generate() + public bool Generate(DungeonRule rule) { if (StartRoomInfo != null) return false; + _rule = rule; - CalcNextRoomType(null); + _nextRoomType = _rule.GetNextRoomType(null); //用于排除上一级房间 var excludePrevRoom = new List(); //上一个房间 @@ -174,9 +196,9 @@ var currTryCount = 0; //如果房间数量不够, 就一直生成 - while (_count < _config.RoomCount || EndRoomInfo == null) + while (!_rule.CanOverGenerator() || EndRoomInfos.Count == 0) { - var nextRoomType = GetNextRoomType(); + var nextRoomType = _nextRoomType; //上一个房间 RoomInfo tempPrevRoomInfo; @@ -188,11 +210,7 @@ { tempPrevRoomInfo = FindMaxLayerRoom(excludePrevRoom); } - else if (nextRoomType == DungeonRoomType.Outlet) - { - tempPrevRoomInfo = prevRoomInfo; - } - else if (nextRoomType == DungeonRoomType.Reward) + else if (nextRoomType == DungeonRoomType.Outlet || nextRoomType == DungeonRoomType.Reward || nextRoomType == DungeonRoomType.Shop || nextRoomType == DungeonRoomType.Event) { tempPrevRoomInfo = prevRoomInfo; } @@ -211,12 +229,12 @@ } else { - tempPrevRoomInfo = _random.RandomChoose(RoomInfos); + tempPrevRoomInfo = Random.RandomChoose(RoomInfos); } } else { - tempPrevRoomInfo = _random.RandomChoose(RoomInfos); + tempPrevRoomInfo = Random.RandomChoose(RoomInfos); } //生成下一个房间 @@ -231,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); + 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 //生成失败 { @@ -264,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; } } @@ -313,21 +340,21 @@ // } DungeonRoomSplit roomSplit; - if (_config.HasDesignatedRoom && _config.DesignatedType == roomType) //执行指定了房间 + if (Config.HasDesignatedRoom && Config.DesignatedType == roomType) //执行指定了房间 { - roomSplit = _random.RandomChoose(_config.DesignatedRoom); + roomSplit = Random.RandomChoose(Config.DesignatedRoom); } else //没有指定房间 { //随机选择一个房间 - var list = _roomGroup.GetRoomList(roomType); + var list = RoomGroup.GetRoomList(roomType); if (list.Count == 0) //如果没有指定类型的房间, 就生成战斗房间 { - roomSplit = _roomGroup.GetRandomRoom(DungeonRoomType.Battle); + roomSplit = RoomGroup.GetRandomRoom(DungeonRoomType.Battle); } else { - roomSplit = _roomGroup.GetRandomRoom(roomType); + roomSplit = RoomGroup.GetRandomRoom(roomType); } } @@ -357,9 +384,9 @@ for (; tryCount < maxTryCount; tryCount++) { //下一个房间方向 - var direction = _random.RandomRangeInt(0, 3); + var direction = Random.RandomRangeInt(0, 3); //房间间隔 - var space = _random.RandomRangeInt(_roomMinInterval, _roomMaxInterval); + var space = Random.RandomRangeInt(_roomMinInterval, _roomMaxInterval); if (direction == 0 || direction == 2) { space += 1; @@ -368,12 +395,12 @@ int offset; if (direction == 0 || direction == 2) { - offset = _random.RandomRangeInt((int)(prevRoomInfo.Size.X * _roomVerticalMinDispersion), + offset = Random.RandomRangeInt((int)(prevRoomInfo.Size.X * _roomVerticalMinDispersion), (int)(prevRoomInfo.Size.X * _roomVerticalMaxDispersion)); } else { - offset = _random.RandomRangeInt((int)(prevRoomInfo.Size.Y * _roomHorizontalMinDispersion), + offset = Random.RandomRangeInt((int)(prevRoomInfo.Size.Y * _roomHorizontalMinDispersion), (int)(prevRoomInfo.Size.Y * _roomHorizontalMaxDispersion)); } @@ -445,11 +472,6 @@ room.Layer = 0; _roomGrid.SetRect(room.Position, room.Size, true); } - - if (IsParticipateCounting(room)) - { - _count++; - } _id++; room.Prev = prevRoomInfo; @@ -461,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.RoomCount - 1) //最后一个房间是boss房间 - { - _nextRoomType = DungeonRoomType.Boss; - } - else if (_count >= _config.RoomCount) //结束房间 - { - _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) { @@ -532,12 +513,6 @@ RoomInfos.Remove(roomInfo); roomInfo.Destroy(); - - if (IsParticipateCounting(roomInfo)) - { - _count--; - } - _id--; return true; } @@ -577,7 +552,7 @@ } } - return _random.RandomChoose(list); + return Random.RandomChoose(list); } /// @@ -597,7 +572,7 @@ nextRoomDoor.ConnectDoor = roomDoor; //先寻找直通门 - if (_random.RandomBoolean()) + if (Random.RandomBoolean()) { //直行通道, 优先横轴 if (TryConnectHorizontalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor) @@ -637,8 +612,8 @@ while (rangeList.Count > 0) { //找到重叠区域 - var range = _random.RandomChooseAndRemove(rangeList); - var x = _random.RandomRangeInt(range.X, range.Y) + 2; + var range = Random.RandomChooseAndRemove(rangeList); + var x = Random.RandomRangeInt(range.X, range.Y) + 2; if (roomInfo.GetVerticalStart() < nextRoomInfo.GetVerticalStart()) //room在上, nextRoom在下 { @@ -689,8 +664,8 @@ while (rangeList.Count > 0) { //找到重叠区域 - var range = _random.RandomChooseAndRemove(rangeList); - var y = _random.RandomRangeInt(range.X, range.Y) + 3; + var range = Random.RandomChooseAndRemove(rangeList); + var y = Random.RandomRangeInt(range.X, range.Y) + 3; if (roomInfo.GetHorizontalStart() < nextRoomInfo.GetHorizontalStart()) //room在左, nextRoom在右 { @@ -736,7 +711,7 @@ { if (roomInfo.GetVerticalStart() > nextRoomInfo.GetVerticalStart()) { - if (_random.RandomBoolean()) //↑ //→ + if (Random.RandomBoolean()) //↑ //→ { if (!TryConnect_NE_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross) && !TryConnect_WS_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross)) @@ -755,7 +730,7 @@ } else { - if (_random.RandomBoolean()) //↓ //→ + if (Random.RandomBoolean()) //↓ //→ { if (!TryConnect_SE_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross) && !TryConnect_WN_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross)) @@ -777,7 +752,7 @@ { if (roomInfo.GetVerticalStart() > nextRoomInfo.GetVerticalStart()) //→ //↓ { - if (_random.RandomBoolean()) + if (Random.RandomBoolean()) { if (!TryConnect_ES_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross) && !TryConnect_NW_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross)) @@ -796,7 +771,7 @@ } else { - if (_random.RandomBoolean()) //→ //↑ + if (Random.RandomBoolean()) //→ //↑ { if (!TryConnect_EN_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross) && !TryConnect_SW_Door(roomInfo, nextRoomInfo, roomDoor, nextRoomDoor, ref cross)) diff --git a/DungeonShooting_Godot/src/framework/map/DungeonRule.cs b/DungeonShooting_Godot/src/framework/map/DungeonRule.cs new file mode 100644 index 0000000..7357120 --- /dev/null +++ b/DungeonShooting_Godot/src/framework/map/DungeonRule.cs @@ -0,0 +1,29 @@ + +/// +/// 用于自定义地牢房间生成规则 +/// +public abstract class DungeonRule +{ + public DungeonGenerator Generator { get; } + + public DungeonConfig Config { get; } + + public SeedRandom Random { get; } + + public DungeonRule(DungeonGenerator generator) + { + Generator = generator; + Config = generator.Config; + Random = generator.Random; + } + + /// + /// 是否可以结束生成了 + /// + public abstract bool CanOverGenerator(); + + /// + /// 计算下一个房间类型 + /// + public abstract DungeonRoomType GetNextRoomType(RoomInfo prev); +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index 9e97a76..32add5e 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -106,7 +106,7 @@ DungeonConfig = new DungeonConfig(); DungeonConfig.GroupName = "Test1"; - DungeonConfig.RoomCount = 20; + DungeonConfig.BattleRoomCount = 20; } public override void _EnterTree() diff --git a/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs b/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs index 2bb7f0e..44aa66a 100644 --- a/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs +++ b/DungeonShooting_Godot/src/game/common/ui/EditorGridBg.cs @@ -3,7 +3,7 @@ /// /// 通用Ui网格背景组件, 包含可拖拽的容器根节点 /// -public abstract partial class EditorGridBg : ColorRect, IUiNodeScript where T : IUiNode +public abstract partial class EditorGridBg : ColorRect, IUiNodeScript { /// /// 可拖拽容器根节点 @@ -16,7 +16,7 @@ /// /// 当前对象绑定的Ui节点 /// - public T UiNode { get; private set; } + public IUiNode UiNode { get; private set; } private ShaderMaterial _gridMaterial; private bool _dragMoveFlag = false; @@ -40,7 +40,7 @@ public virtual void SetUiNode(IUiNode uiNode) { - UiNode = (T)uiNode; + UiNode = uiNode; this.AddDragListener(DragButtonEnum.Middle, OnDrag); Resized += RefreshGridTrans; //打开Ui时刷新网格 diff --git a/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs b/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs index fea4640..42ed8cb 100644 --- a/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs +++ b/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs @@ -177,6 +177,7 @@ preinstallInfo.Name = "Preinstall1"; preinstallInfo.Weight = 100; preinstallInfo.Remark = ""; + preinstallInfo.AutoFill = true; preinstallInfo.InitWaveList(); preinstallInfo.InitSpecialMark(roomSplit.RoomInfo.RoomType); roomSplit.Preinstall.Add(preinstallInfo); diff --git a/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs b/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs new file mode 100644 index 0000000..d092b84 --- /dev/null +++ b/DungeonShooting_Godot/src/game/room/DefaultDungeonRule.cs @@ -0,0 +1,40 @@ + +/// +/// 默认实现地牢房间规则 +/// +public class DefaultDungeonRule : DungeonRule +{ + public DefaultDungeonRule(DungeonGenerator generator) : base(generator) + { + } + + 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 032bc8d..9172f1e 100644 --- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs +++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs @@ -198,7 +198,8 @@ //生成地牢房间 var random = new SeedRandom(); _dungeonGenerator = new DungeonGenerator(CurrConfig, random); - if (!_dungeonGenerator.Generate()) //生成房间失败 + var rule = new DefaultDungeonRule(_dungeonGenerator); + if (!_dungeonGenerator.Generate(rule)) //生成房间失败 { _dungeonGenerator.EachRoom(DisposeRoomInfo); _dungeonGenerator = null; @@ -218,7 +219,7 @@ { UiManager.Open_Main(); } - EditorWindowManager.ShowTips("错误", "生成房间尝试次数过多,生成地牢房间失败,请加大房间门连接区域!"); + EditorWindowManager.ShowTips("错误", "生成房间尝试次数过多,生成地牢房间失败,请加大房间门连接区域,或者修改地牢生成规则!"); yield break; } yield return 0; diff --git a/DungeonShooting_Godot/src/game/ui/editorTileImage/ImageBg.cs b/DungeonShooting_Godot/src/game/ui/editorTileImage/ImageBg.cs index 55bd620..0a8adf6 100644 --- a/DungeonShooting_Godot/src/game/ui/editorTileImage/ImageBg.cs +++ b/DungeonShooting_Godot/src/game/ui/editorTileImage/ImageBg.cs @@ -2,8 +2,10 @@ namespace UI.EditorTileImage; -public partial class ImageBg : EditorGridBg +public partial class ImageBg : EditorGridBg { + public new EditorTileImage.Bg UiNode => (EditorTileImage.Bg)base.UiNode; + public override void SetUiNode(IUiNode uiNode) { base.SetUiNode(uiNode); diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/FreeTileTab.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/FreeTileTab.cs index 1771702..8f5fe6b 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/FreeTileTab.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapTile/FreeTileTab.cs @@ -6,8 +6,10 @@ /// /// 自由笔刷页签 /// -public partial class FreeTileTab : EditorGridBg +public partial class FreeTileTab : EditorGridBg { + public new MapEditorMapTile.Tab1 UiNode => (MapEditorMapTile.Tab1)base.UiNode; + private ImageTexture _texture; private Sprite2D _sprite; private Control _brush; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs index 8c83f4f..3dda271 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftBottom/TileEditArea.cs @@ -3,8 +3,10 @@ namespace UI.TileSetEditorCombination; -public partial class TileEditArea : EditorGridBg +public partial class TileEditArea : EditorGridBg { + public new TileSetEditorCombination.LeftBottomBg UiNode => (TileSetEditorCombination.LeftBottomBg)base.UiNode; + private UiGrid _maskGrid; private readonly HashSet _useMask = new HashSet(); diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs index 13c4d18..dc67131 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorCombination/leftTop/TileEditCombination.cs @@ -5,8 +5,10 @@ namespace UI.TileSetEditorCombination; -public partial class TileEditCombination : EditorGridBg +public partial class TileEditCombination : EditorGridBg { + public new TileSetEditorCombination.LeftTopBg UiNode => (TileSetEditorCombination.LeftTopBg)base.UiNode; + // ------------------------------- 笔刷相关 ------------------------------- //笔刷数据, kay: 代表原图中的坐标, 单位: 格 private Dictionary _brushData = new Dictionary(); diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs index 6f5cd7e..45c0023 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/TileEditArea.cs @@ -2,8 +2,10 @@ namespace UI.TileSetEditorTerrain; -public partial class TileEditArea : EditorGridBg +public partial class TileEditArea : EditorGridBg { + public new TileSetEditorTerrain.BottomBg UiNode => (TileSetEditorTerrain.BottomBg)base.UiNode; + private bool _dragMoveFlag = false; private MaskCell _hoverCell = null; diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs index ca1fc31..5a0b01a 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/up/TileEditTerrain.cs @@ -2,8 +2,10 @@ namespace UI.TileSetEditorTerrain; -public partial class TileEditTerrain : EditorGridBg +public partial class TileEditTerrain : EditorGridBg { + public new TileSetEditorTerrain.TopBg UiNode => (TileSetEditorTerrain.TopBg)base.UiNode; + private bool _dragMoveFlag = false; private TerrainCell _hoverCell = null;