Working on the world
This commit is contained in:
@@ -105,6 +105,7 @@ public sealed partial class WorldHandler : IClientMessageHandler
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
var mobs = await db.Set<DungeonMobDefinition>()
|
||||
.AsNoTracking()
|
||||
.Where(m => m.IsEnabled)
|
||||
.Include(m => m.AbilityAssignments)
|
||||
.ThenInclude(a => a.AbilityDefinition)
|
||||
@@ -112,9 +113,20 @@ public sealed partial class WorldHandler : IClientMessageHandler
|
||||
_mobDefinitions = mobs.ToDictionary(m => m.Id);
|
||||
|
||||
var npcs = await db.Set<DungeonNpcDefinition>()
|
||||
.AsNoTracking()
|
||||
.Where(n => n.IsEnabled)
|
||||
.ToListAsync();
|
||||
_npcDefinitions = npcs.ToDictionary(n => n.Id);
|
||||
|
||||
// Log mob stats for debugging
|
||||
foreach (var mob in mobs.Take(5))
|
||||
{
|
||||
var stats = mob.GetStatsForBracket(1);
|
||||
_log.LogInformation(
|
||||
"MobDef {Id} '{Name}': MoveSpeed={MoveSpeed}, AggroRange={AggroRange}, LeashRange={LeashRange}, Behavior={Behavior}, Abilities={AbilityCount}",
|
||||
mob.Id, mob.Name, stats.MoveSpeed, stats.AggroRange, stats.LeashRange, mob.Behavior,
|
||||
mob.AbilityAssignments?.Count(a => a.IsEnabled) ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleAsync(int opCode, IConnection connection, ReadOnlyMemory<byte> payload, CancellationToken ct)
|
||||
@@ -593,8 +605,17 @@ public sealed partial class WorldHandler : IClientMessageHandler
|
||||
if (_activeZones.TryAdd(zoneKey, zoneSim))
|
||||
{
|
||||
_log.LogInformation(
|
||||
"Activated zone simulation {ZoneKey}: {MobCount} mobs, {NpcCount} NPCs",
|
||||
zoneKey, zoneSim.Mobs.Count, zoneSim.Npcs.Count);
|
||||
"Activated zone simulation {ZoneKey}: {MobCount} mobs, {NpcCount} NPCs, {SpawnPoints} spawn points",
|
||||
zoneKey, zoneSim.Mobs.Count, zoneSim.Npcs.Count,
|
||||
zoneSim.MobSpawnTracker?.SpawnPointCount ?? 0);
|
||||
|
||||
// Log mob details for debugging
|
||||
foreach (var mob in zoneSim.Mobs.Values.Take(3))
|
||||
{
|
||||
_log.LogInformation(
|
||||
" Mob {Id} '{Name}' at ({X:F0},{Y:F0}): MoveSpeed={MoveSpeed}, Behavior={Behavior}, State={State}, Abilities={AbilityCount}",
|
||||
mob.Id, mob.Name, mob.X, mob.Y, mob.Stats.MoveSpeed, mob.Behavior, mob.State, mob.Abilities.Count);
|
||||
}
|
||||
return zoneSim;
|
||||
}
|
||||
|
||||
@@ -680,6 +701,19 @@ public sealed partial class WorldHandler : IClientMessageHandler
|
||||
try
|
||||
{
|
||||
zoneSim.Tick(tick, TickDeltaSeconds);
|
||||
|
||||
// Periodic debug log every ~10 seconds (100 ticks)
|
||||
if (tick % 100 == 0 && zoneSim.Mobs.Count > 0)
|
||||
{
|
||||
var sample = zoneSim.Mobs.Values.FirstOrDefault();
|
||||
if (sample != null)
|
||||
{
|
||||
_log.LogDebug(
|
||||
"Zone {ZoneKey} tick {Tick}: {MobCount} mobs, {PlayerCount} players. Sample mob {Id} '{Name}' state={State} pos=({X:F0},{Y:F0}) speed={Speed}",
|
||||
zoneKey, tick, zoneSim.Mobs.Count, zoneSim.Players.Count,
|
||||
sample.Id, sample.Name, sample.State, sample.X, sample.Y, sample.Stats.MoveSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -751,10 +785,18 @@ public sealed partial class WorldHandler : IClientMessageHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
_log.LogInformation(
|
||||
"Persisting location for character {CharacterId}: Region={RegionId} Zone=({ZoneX},{ZoneY},{ZoneZ}) Chunk=({ChunkX},{ChunkY}) Pos=({X:F1},{Y:F1})",
|
||||
s.CharacterId, s.RegionId, s.ZoneX, s.ZoneY, s.ZoneZ, s.ChunkX, s.ChunkY, s.X, s.Y);
|
||||
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
var character = await db.DungeonCharacters.FirstOrDefaultAsync(c => c.Id == s.CharacterId);
|
||||
if (character == null) return;
|
||||
if (character == null)
|
||||
{
|
||||
_log.LogWarning("Character {CharacterId} not found for position persist", s.CharacterId);
|
||||
return;
|
||||
}
|
||||
|
||||
character.WorldRegionId = s.RegionId;
|
||||
character.WorldZoneX = s.ZoneX;
|
||||
@@ -766,10 +808,12 @@ public sealed partial class WorldHandler : IClientMessageHandler
|
||||
character.WorldY = s.Y;
|
||||
character.LastPlayedAt = DateTime.UtcNow;
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
_log.LogInformation("Successfully persisted location for character {CharacterId}", s.CharacterId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogWarning(ex, "Failed to persist world location for character {CharacterId}", s.CharacterId);
|
||||
_log.LogError(ex, "Failed to persist world location for character {CharacterId}", s.CharacterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user