Admin
This commit is contained in:
@@ -8,6 +8,18 @@ namespace GameServer.Dungeon;
|
||||
/// </summary>
|
||||
public partial class DungeonHandler
|
||||
{
|
||||
// Track changed tiles per dungeon for differential updates
|
||||
private readonly ConcurrentDictionary<Guid, ConcurrentBag<(int x, int y, int layer)>> _changedTiles = new();
|
||||
|
||||
/// <summary>
|
||||
/// Mark a tile as changed for differential updates
|
||||
/// </summary>
|
||||
public void MarkTileChanged(Guid dungeonId, int x, int y, int layer = 0)
|
||||
{
|
||||
var bag = _changedTiles.GetOrAdd(dungeonId, _ => new ConcurrentBag<(int, int, int)>());
|
||||
bag.Add((x, y, layer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all active dungeon instances (for admin viewing)
|
||||
/// </summary>
|
||||
@@ -246,6 +258,7 @@ public partial class DungeonHandler
|
||||
}
|
||||
|
||||
// Mark dungeon as having pending tile updates
|
||||
MarkTileChanged(dungeonId, x, y, layer);
|
||||
dungeon.HasPendingTileUpdates = true;
|
||||
|
||||
return true;
|
||||
@@ -300,6 +313,9 @@ public partial class DungeonHandler
|
||||
TileDefinitionId = (int)tile.TileDefId
|
||||
});
|
||||
}
|
||||
|
||||
// Track change for differential update
|
||||
MarkTileChanged(dungeonId, tileX, tileY, tile.Layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,6 +350,9 @@ public partial class DungeonHandler
|
||||
TileDefinitionId = tileDef.Id
|
||||
});
|
||||
}
|
||||
|
||||
// Track change for differential update
|
||||
MarkTileChanged(dungeonId, x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,12 +374,30 @@ public partial class DungeonHandler
|
||||
if (layer.HasValue)
|
||||
{
|
||||
layout.TileDetails.RemoveAll(t => t.X == x && t.Y == y && t.Layer == layer.Value);
|
||||
MarkTileChanged(dungeonId, x, y, layer.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove all layers at this position
|
||||
var removedLayers = layout.TileDetails
|
||||
.Where(t => t.X == x && t.Y == y)
|
||||
.Select(t => t.Layer)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
layout.TileDetails.RemoveAll(t => t.X == x && t.Y == y);
|
||||
layout.Walkable[x, y] = false;
|
||||
layout.Tiles[x, y] = 0;
|
||||
|
||||
// Mark all removed layers as changed
|
||||
foreach (var l in removedLayers)
|
||||
{
|
||||
MarkTileChanged(dungeonId, x, y, l);
|
||||
}
|
||||
if (removedLayers.Count == 0)
|
||||
{
|
||||
MarkTileChanged(dungeonId, x, y, 0); // At least mark ground layer
|
||||
}
|
||||
}
|
||||
|
||||
dungeon.HasPendingTileUpdates = true;
|
||||
@@ -436,6 +473,66 @@ public partial class DungeonHandler
|
||||
player.Armor = invulnerable ? 999999 : 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get dungeons with pending tile updates (for tick loop)
|
||||
/// </summary>
|
||||
public IEnumerable<DungeonInstance> GetDungeonsWithPendingTileUpdates()
|
||||
{
|
||||
return _dungeons.Values.Where(d => d.HasPendingTileUpdates);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build tile update payload for broadcasting to clients
|
||||
/// </summary>
|
||||
public object? BuildTileUpdatePayload(Guid dungeonId)
|
||||
{
|
||||
if (!_dungeons.TryGetValue(dungeonId, out var dungeon))
|
||||
return null;
|
||||
|
||||
if (!dungeon.HasPendingTileUpdates)
|
||||
return null;
|
||||
|
||||
dungeon.HasPendingTileUpdates = false;
|
||||
|
||||
var layout = dungeon.LayoutV2;
|
||||
if (layout == null)
|
||||
return null;
|
||||
|
||||
// Build walkability data
|
||||
var walkable = new List<bool>();
|
||||
for (int y = 0; y < layout.Height; y++)
|
||||
for (int x = 0; x < layout.Width; x++)
|
||||
walkable.Add(layout.Walkable[x, y]);
|
||||
|
||||
return new
|
||||
{
|
||||
width = layout.Width,
|
||||
height = layout.Height,
|
||||
walkable = walkable,
|
||||
tiles = layout.TileDetails.Select(t => new
|
||||
{
|
||||
x = t.X,
|
||||
y = t.Y,
|
||||
sid = t.SheetId,
|
||||
frame = t.FrameIndex,
|
||||
l = t.Layer,
|
||||
r = t.Rotation,
|
||||
fx = t.FlipX,
|
||||
fy = t.FlipY
|
||||
}),
|
||||
sheets = layout.TileMapSheets.Select(s => new
|
||||
{
|
||||
id = s.Id,
|
||||
path = s.CdnPath,
|
||||
tileW = s.TileWidth,
|
||||
tileH = s.TileHeight,
|
||||
sheetW = s.SheetWidth,
|
||||
sheetH = s.SheetHeight,
|
||||
cols = s.Columns
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
@@ -462,3 +559,31 @@ public class DungeonStats
|
||||
public int CompletedCount { get; set; }
|
||||
public int BossesKilled { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tile update payload for broadcasting to clients
|
||||
/// </summary>
|
||||
public class TileUpdatePayload
|
||||
{
|
||||
public List<TileUpdateData> Tiles { get; set; } = new();
|
||||
public List<WalkableUpdateData> Walkable { get; set; } = new();
|
||||
}
|
||||
|
||||
public class TileUpdateData
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public int SheetId { get; set; }
|
||||
public int Frame { get; set; }
|
||||
public int Layer { get; set; }
|
||||
public int Rotation { get; set; }
|
||||
public bool FlipX { get; set; }
|
||||
public bool FlipY { get; set; }
|
||||
}
|
||||
|
||||
public class WalkableUpdateData
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public bool Walkable { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user