Dungeon fixes

This commit is contained in:
dingo
2026-02-09 07:46:13 -05:00
parent 469f1976bd
commit fb17d1c16b
3 changed files with 66 additions and 18 deletions
+59 -11
View File
@@ -40,6 +40,7 @@ public class DungeonGeneratorVNext
int targetRooms = 10 + (_tier * 2);
if (_tier >= 6) targetRooms += _tier;
targetRooms = Math.Clamp(targetRooms, 12, 80);
int minExpectedRooms = Math.Max(8, targetRooms / 2);
var layout = new DungeonLayoutV2(mapWidth, mapHeight)
{
@@ -58,9 +59,9 @@ public class DungeonGeneratorVNext
}
var rooms = GenerateRooms(mapWidth, mapHeight, targetRooms);
if (rooms.Count < 2)
if (rooms.Count < minExpectedRooms)
{
rooms = GenerateFallbackRooms(mapWidth, mapHeight);
rooms = GenerateFallbackRooms(mapWidth, mapHeight, targetRooms);
}
foreach (var room in rooms)
@@ -83,8 +84,15 @@ public class DungeonGeneratorVNext
layout.TotalChests = layout.ChestSpawns.Count;
_logger?.LogInformation(
"VNext generated seed {Seed}, tier {Tier}: {Width}x{Height}, rooms={RoomCount}, mobs={MobCount}, chests={ChestCount}",
_seed, _tier, mapWidth, mapHeight, rooms.Count, layout.TotalMobs, layout.TotalChests);
"VNext generated seed {Seed}, tier {Tier}: {Width}x{Height}, rooms={RoomCount}, mobs={MobCount}, chests={ChestCount}, bosses={BossCount}",
_seed,
_tier,
mapWidth,
mapHeight,
rooms.Count,
layout.TotalMobs,
layout.TotalChests,
layout.MobSpawns.Count(m => m.MobType == DungeonMobSpawnType.Boss));
return Task.FromResult(layout);
}
@@ -152,16 +160,18 @@ public class DungeonGeneratorVNext
.ToList();
}
private List<DungeonRoom> GenerateFallbackRooms(int mapWidth, int mapHeight)
private List<DungeonRoom> GenerateFallbackRooms(int mapWidth, int mapHeight, int desiredCount)
{
var rooms = new List<DungeonRoom>();
int count = Math.Max(6, Math.Min(12, 4 + _tier));
int count = Math.Clamp(desiredCount, 12, 80);
int attempts = 0;
while (rooms.Count < count && attempts++ < count * 30)
while (rooms.Count < count && attempts++ < count * 60)
{
int width = _rng.Next(8, 16);
int height = _rng.Next(8, 16);
int maxRoom = Math.Min(24, 10 + _tier);
int width = _rng.Next(8, maxRoom + 1);
int height = _rng.Next(8, maxRoom + 1);
if (width >= mapWidth - 4 || height >= mapHeight - 4) continue;
int x = _rng.Next(2, mapWidth - width - 2);
int y = _rng.Next(2, mapHeight - height - 2);
var room = new DungeonRoom(x, y, width, height);
@@ -309,7 +319,7 @@ public class DungeonGeneratorVNext
rooms[entranceIndex].Type = DungeonRoomType.Entrance;
int bossCount = _tier >= 6 ? Math.Min(1 + (_tier / 4), 3) : 1;
int bossCount = GetRequiredBossCount();
var candidates = rooms
.Select((r, i) => (room: r, idx: i))
.Where(p => p.idx != entranceIndex)
@@ -398,7 +408,39 @@ public class DungeonGeneratorVNext
}
}
if (!layout.MobSpawns.Any(m => m.MobType == DungeonMobSpawnType.Boss) && rooms.Count > 0)
int requiredBossCount = Math.Min(GetRequiredBossCount(), Math.Max(1, rooms.Count - 1));
int bossSpawnCount = layout.MobSpawns.Count(m => m.MobType == DungeonMobSpawnType.Boss);
if (bossSpawnCount < requiredBossCount && rooms.Count > 1)
{
var entranceRoom = rooms.FirstOrDefault(r => r.Type == DungeonRoomType.Entrance) ?? rooms[0];
var candidateRooms = rooms
.Select((room, idx) => (room, idx))
.Where(p => p.room.Type != DungeonRoomType.Entrance)
.OrderByDescending(p => Distance(entranceRoom.CenterX, entranceRoom.CenterY, p.room.CenterX, p.room.CenterY))
.ToList();
foreach (var candidate in candidateRooms)
{
if (bossSpawnCount >= requiredBossCount) break;
bool roomAlreadyHasBoss = layout.MobSpawns.Any(m => m.RoomIndex == candidate.idx && m.MobType == DungeonMobSpawnType.Boss);
if (roomAlreadyHasBoss) continue;
var pos = RandomPointInRoom(candidate.room);
layout.MobSpawns.Add(new DungeonMobSpawn
{
Id = mobId++,
X = pos.x,
Y = pos.y,
MobType = DungeonMobSpawnType.Boss,
RoomIndex = candidate.idx
});
candidate.room.Type = DungeonRoomType.Boss;
bossSpawnCount++;
}
}
if (bossSpawnCount == 0 && rooms.Count > 0)
{
int fallbackRoomIndex = rooms.FindIndex(r => r.Type != DungeonRoomType.Entrance);
if (fallbackRoomIndex < 0) fallbackRoomIndex = 0;
@@ -415,6 +457,12 @@ public class DungeonGeneratorVNext
}
}
private int GetRequiredBossCount()
{
if (_tier < 6) return 1;
return Math.Clamp(1 + (_tier / 4), 2, 4);
}
private (int x, int y) RandomPointInRoom(DungeonRoom room)
{
int x = _rng.Next(room.X + 1, room.X + room.Width - 1);
+4 -4
View File
@@ -3041,17 +3041,17 @@ public sealed partial class DungeonHandler : IClientMessageHandler
if (session.CurrentDungeonId.HasValue)
{
// Delay removal from dungeon by 25 seconds to allow for reconnection
// Delay removal from dungeon by 5 minutes to allow for reconnection
// and to prevent abuse (disconnecting to avoid combat)
_ = Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(25));
await Task.Delay(TimeSpan.FromMinutes(5));
await RemoveFromDungeonAsync(session, false, CancellationToken.None);
_log.LogInformation("Player {CharacterName} removed from dungeon after 25s disconnect timeout",
_log.LogInformation("Player {CharacterName} removed from dungeon after 5m disconnect timeout",
session.Character?.Name ?? "Unknown");
});
_log.LogInformation("Dungeon session for {CharacterName} will be removed in 25s after disconnect",
_log.LogInformation("Dungeon session for {CharacterName} will be removed in 5m after disconnect",
session.Character?.Name ?? "Unknown");
}
else
+3 -3
View File
@@ -52,11 +52,11 @@ public sealed class NetworkManager
: 20;
_tickInterval = TimeSpan.FromMilliseconds(1000.0 / tickHz);
// Parse idle timeout from environment variable (default: 90 seconds to allow for ping delays)
// Parse idle timeout from environment variable (default: 5 minutes)
_idleTimeout = TimeSpan.FromSeconds(
int.TryParse(Environment.GetEnvironmentVariable("IDLE_TIMEOUT_S"), out var idle)
? Math.Clamp(idle, 10, 300)
: 90
? Math.Clamp(idle, 300, 1800)
: 300
);
// Ping interval should be less than half of idle timeout to ensure keepalive