Dungeon fixes
This commit is contained in:
@@ -40,6 +40,7 @@ public class DungeonGeneratorVNext
|
|||||||
int targetRooms = 10 + (_tier * 2);
|
int targetRooms = 10 + (_tier * 2);
|
||||||
if (_tier >= 6) targetRooms += _tier;
|
if (_tier >= 6) targetRooms += _tier;
|
||||||
targetRooms = Math.Clamp(targetRooms, 12, 80);
|
targetRooms = Math.Clamp(targetRooms, 12, 80);
|
||||||
|
int minExpectedRooms = Math.Max(8, targetRooms / 2);
|
||||||
|
|
||||||
var layout = new DungeonLayoutV2(mapWidth, mapHeight)
|
var layout = new DungeonLayoutV2(mapWidth, mapHeight)
|
||||||
{
|
{
|
||||||
@@ -58,9 +59,9 @@ public class DungeonGeneratorVNext
|
|||||||
}
|
}
|
||||||
|
|
||||||
var rooms = GenerateRooms(mapWidth, mapHeight, targetRooms);
|
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)
|
foreach (var room in rooms)
|
||||||
@@ -83,8 +84,15 @@ public class DungeonGeneratorVNext
|
|||||||
layout.TotalChests = layout.ChestSpawns.Count;
|
layout.TotalChests = layout.ChestSpawns.Count;
|
||||||
|
|
||||||
_logger?.LogInformation(
|
_logger?.LogInformation(
|
||||||
"VNext generated seed {Seed}, tier {Tier}: {Width}x{Height}, rooms={RoomCount}, mobs={MobCount}, chests={ChestCount}",
|
"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);
|
_seed,
|
||||||
|
_tier,
|
||||||
|
mapWidth,
|
||||||
|
mapHeight,
|
||||||
|
rooms.Count,
|
||||||
|
layout.TotalMobs,
|
||||||
|
layout.TotalChests,
|
||||||
|
layout.MobSpawns.Count(m => m.MobType == DungeonMobSpawnType.Boss));
|
||||||
|
|
||||||
return Task.FromResult(layout);
|
return Task.FromResult(layout);
|
||||||
}
|
}
|
||||||
@@ -152,16 +160,18 @@ public class DungeonGeneratorVNext
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DungeonRoom> GenerateFallbackRooms(int mapWidth, int mapHeight)
|
private List<DungeonRoom> GenerateFallbackRooms(int mapWidth, int mapHeight, int desiredCount)
|
||||||
{
|
{
|
||||||
var rooms = new List<DungeonRoom>();
|
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;
|
int attempts = 0;
|
||||||
|
|
||||||
while (rooms.Count < count && attempts++ < count * 30)
|
while (rooms.Count < count && attempts++ < count * 60)
|
||||||
{
|
{
|
||||||
int width = _rng.Next(8, 16);
|
int maxRoom = Math.Min(24, 10 + _tier);
|
||||||
int height = _rng.Next(8, 16);
|
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 x = _rng.Next(2, mapWidth - width - 2);
|
||||||
int y = _rng.Next(2, mapHeight - height - 2);
|
int y = _rng.Next(2, mapHeight - height - 2);
|
||||||
var room = new DungeonRoom(x, y, width, height);
|
var room = new DungeonRoom(x, y, width, height);
|
||||||
@@ -309,7 +319,7 @@ public class DungeonGeneratorVNext
|
|||||||
|
|
||||||
rooms[entranceIndex].Type = DungeonRoomType.Entrance;
|
rooms[entranceIndex].Type = DungeonRoomType.Entrance;
|
||||||
|
|
||||||
int bossCount = _tier >= 6 ? Math.Min(1 + (_tier / 4), 3) : 1;
|
int bossCount = GetRequiredBossCount();
|
||||||
var candidates = rooms
|
var candidates = rooms
|
||||||
.Select((r, i) => (room: r, idx: i))
|
.Select((r, i) => (room: r, idx: i))
|
||||||
.Where(p => p.idx != entranceIndex)
|
.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);
|
int fallbackRoomIndex = rooms.FindIndex(r => r.Type != DungeonRoomType.Entrance);
|
||||||
if (fallbackRoomIndex < 0) fallbackRoomIndex = 0;
|
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)
|
private (int x, int y) RandomPointInRoom(DungeonRoom room)
|
||||||
{
|
{
|
||||||
int x = _rng.Next(room.X + 1, room.X + room.Width - 1);
|
int x = _rng.Next(room.X + 1, room.X + room.Width - 1);
|
||||||
|
|||||||
@@ -3041,17 +3041,17 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
|
|
||||||
if (session.CurrentDungeonId.HasValue)
|
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)
|
// and to prevent abuse (disconnecting to avoid combat)
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromSeconds(25));
|
await Task.Delay(TimeSpan.FromMinutes(5));
|
||||||
await RemoveFromDungeonAsync(session, false, CancellationToken.None);
|
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");
|
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");
|
session.Character?.Name ?? "Unknown");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ public sealed class NetworkManager
|
|||||||
: 20;
|
: 20;
|
||||||
_tickInterval = TimeSpan.FromMilliseconds(1000.0 / tickHz);
|
_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(
|
_idleTimeout = TimeSpan.FromSeconds(
|
||||||
int.TryParse(Environment.GetEnvironmentVariable("IDLE_TIMEOUT_S"), out var idle)
|
int.TryParse(Environment.GetEnvironmentVariable("IDLE_TIMEOUT_S"), out var idle)
|
||||||
? Math.Clamp(idle, 10, 300)
|
? Math.Clamp(idle, 300, 1800)
|
||||||
: 90
|
: 300
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ping interval should be less than half of idle timeout to ensure keepalive
|
// Ping interval should be less than half of idle timeout to ensure keepalive
|
||||||
|
|||||||
Reference in New Issue
Block a user