diff --git a/Game/Dungeon/DungeonGeneratorV3.cs b/Game/Dungeon/DungeonGeneratorV3.cs index bde2a9a..6059a7b 100644 --- a/Game/Dungeon/DungeonGeneratorV3.cs +++ b/Game/Dungeon/DungeonGeneratorV3.cs @@ -2072,4 +2072,5 @@ public class TemplateTilePlacement public int SheetId { get; set; } public int FrameIndex { get; set; } public int? TileDefId { get; set; } + public int Layer { get; set; } } \ No newline at end of file diff --git a/Game/Dungeon/DungeonHandlerAdmin.cs b/Game/Dungeon/DungeonHandlerAdmin.cs index cc8e58c..d9f2349 100644 --- a/Game/Dungeon/DungeonHandlerAdmin.cs +++ b/Game/Dungeon/DungeonHandlerAdmin.cs @@ -27,24 +27,18 @@ public partial class DungeonHandler /// /// Force close a dungeon (admin action) - /// Removes all players and destroys the instance /// public bool ForceCloseDungeon(Guid dungeonId) { if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) return false; - // Remove all players from the dungeon foreach (var player in dungeon.Simulation.Players.Values.ToList()) { - try - { - Console.WriteLine("Remove Player - Not Implemented."); - } - catch { /* Ignore errors during cleanup */ } + try { Console.WriteLine("Remove Player - Not Implemented."); } + catch { } } - // Remove the dungeon return _dungeons.TryRemove(dungeonId, out _); } @@ -87,7 +81,6 @@ public partial class DungeonHandler /// /// Spawn a mob in a dungeon (admin action) - /// Uses the same sprite config system as dungeon generation /// public MobInstance? SpawnMobInDungeon(Guid dungeonId, int mobDefinitionId, float x, float y) { @@ -97,22 +90,14 @@ public partial class DungeonHandler if (!_mobDefinitions.TryGetValue(mobDefinitionId, out var mobDef)) return null; - // Get sprite config from pre-built cache (same as dungeon generation uses) string? spriteConfig = null; if (_mobSpriteConfigs.TryGetValue(mobDefinitionId, out var cachedConfig) && !string.IsNullOrEmpty(cachedConfig)) - { spriteConfig = cachedConfig; - } else - { spriteConfig = mobDef.SpriteConfigJson; - } - // Generate unique mob ID var maxId = dungeon.Simulation.Mobs.Keys.DefaultIfEmpty(0).Max(); var newMobId = maxId + 1; - - // Use bracket-aware stat scaling var stats = mobDef.GetStatsForBracket(dungeon.LevelBracketMin); var mob = new MobInstance @@ -143,7 +128,6 @@ public partial class DungeonHandler FacingDirection = "down" }; - // Add basic attack ability (same as DungeonSimulation fallback) mob.Abilities.Add(new MobAbilityState { AbilityId = 0, @@ -164,14 +148,13 @@ public partial class DungeonHandler }); dungeon.Simulation.Mobs[newMobId] = mob; - return mob; } // ==================== TILE EDITING ==================== /// - /// Set a tile's walkability (admin action) + /// Set a tile's walkability (simple mode) /// public bool SetTileWalkable(Guid dungeonId, int x, int y, bool walkable) { @@ -179,46 +162,15 @@ public partial class DungeonHandler return false; var layout = dungeon.LayoutV2; - if (layout == null) - return false; - + if (layout == null) return false; if (x < 0 || x >= layout.Width || y < 0 || y >= layout.Height) return false; layout.Walkable[x, y] = walkable; - - // Also update the Tiles array (0 = wall, 1 = floor typically) layout.Tiles[x, y] = walkable ? 1 : 0; - return true; } - /// - /// Set multiple tiles at once (for painting) - /// - public int SetTilesWalkable(Guid dungeonId, List<(int x, int y, bool walkable)> tiles) - { - if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) - return 0; - - var layout = dungeon.LayoutV2; - if (layout == null) - return 0; - - int count = 0; - foreach (var (x, y, walkable) in tiles) - { - if (x >= 0 && x < layout.Width && y >= 0 && y < layout.Height) - { - layout.Walkable[x, y] = walkable; - layout.Tiles[x, y] = walkable ? 1 : 0; - count++; - } - } - - return count; - } - /// /// Fill a rectangle with walkable or wall tiles /// @@ -228,8 +180,7 @@ public partial class DungeonHandler return 0; var layout = dungeon.LayoutV2; - if (layout == null) - return 0; + if (layout == null) return 0; int minX = Math.Max(0, Math.Min(x1, x2)); int maxX = Math.Min(layout.Width - 1, Math.Max(x1, x2)); @@ -246,51 +197,218 @@ public partial class DungeonHandler count++; } } - return count; } - // ==================== PLAYER MANIPULATION ==================== + /// + /// Place a visual tile at a position (full tile editing with graphics) + /// + public bool PlaceVisualTile(Guid dungeonId, int x, int y, int sheetId, int frameIndex, + int layer = 0, bool walkable = true, int rotation = 0, bool flipX = false, bool flipY = false) + { + if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) + return false; + + var layout = dungeon.LayoutV2; + if (layout == null) return false; + if (x < 0 || x >= layout.Width || y < 0 || y >= layout.Height) + return false; + + // Update walkability + layout.Walkable[x, y] = walkable; + layout.Tiles[x, y] = walkable ? 1 : 0; + + // Find existing tile at this position and layer, or create new + var existingTile = layout.TileDetails.FirstOrDefault(t => t.X == x && t.Y == y && t.Layer == layer); + + if (existingTile != null) + { + existingTile.SheetId = sheetId; + existingTile.FrameIndex = frameIndex; + existingTile.Rotation = rotation; + existingTile.FlipX = flipX; + existingTile.FlipY = flipY; + } + else + { + layout.TileDetails.Add(new PlacedTile + { + X = x, + Y = y, + SheetId = sheetId, + FrameIndex = frameIndex, + Layer = layer, + Rotation = rotation, + FlipX = flipX, + FlipY = flipY, + TileDefinitionId = 0 + }); + } + + // Mark dungeon as having pending tile updates + dungeon.HasPendingTileUpdates = true; + + return true; + } /// - /// Get detailed player info (admin) + /// Place a tile template at a position /// - public PlayerInstance? GetPlayer(Guid dungeonId, ulong characterId) + public bool PlaceTileTemplate(Guid dungeonId, int x, int y, TileTemplate template) + { + if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) + return false; + + var layout = dungeon.LayoutV2; + if (layout == null) return false; + + // For multi-tile templates, parse TilesJson + if (!string.IsNullOrEmpty(template.TilesJson)) + { + try + { + var tiles = System.Text.Json.JsonSerializer.Deserialize>(template.TilesJson); + if (tiles != null) + { + foreach (var tile in tiles) + { + int tileX = x + tile.X; + int tileY = y + tile.Y; + + if (tileX >= 0 && tileX < layout.Width && tileY >= 0 && tileY < layout.Height) + { + layout.Walkable[tileX, tileY] = template.IsWalkable; + layout.Tiles[tileX, tileY] = template.IsWalkable ? 1 : 0; + + // Add visual tile + var existingTile = layout.TileDetails.FirstOrDefault(t => t.X == tileX && t.Y == tileY && t.Layer == tile.Layer); + if (existingTile != null) + { + existingTile.SheetId = tile.SheetId; + existingTile.FrameIndex = tile.FrameIndex; + existingTile.TileDefinitionId = (int)tile.TileDefId; + } + else + { + layout.TileDetails.Add(new PlacedTile + { + X = tileX, + Y = tileY, + SheetId = tile.SheetId, + FrameIndex = tile.FrameIndex, + Layer = tile.Layer, + TileDefinitionId = (int)tile.TileDefId + }); + } + } + } + } + } + catch { return false; } + } + else if (template.PrimaryTileDefinition != null) + { + // Simple 1x1 template + var tileDef = template.PrimaryTileDefinition; + if (x >= 0 && x < layout.Width && y >= 0 && y < layout.Height) + { + layout.Walkable[x, y] = template.IsWalkable; + layout.Tiles[x, y] = template.IsWalkable ? 1 : 0; + + var existingTile = layout.TileDetails.FirstOrDefault(t => t.X == x && t.Y == y && t.Layer == 0); + if (existingTile != null) + { + existingTile.SheetId = tileDef.TileMapSheetId; + existingTile.FrameIndex = tileDef.FrameIndex; + existingTile.TileDefinitionId = tileDef.Id; + } + else + { + layout.TileDetails.Add(new PlacedTile + { + X = x, + Y = y, + SheetId = tileDef.TileMapSheetId, + FrameIndex = tileDef.FrameIndex, + Layer = 0, + TileDefinitionId = tileDef.Id + }); + } + } + } + + dungeon.HasPendingTileUpdates = true; + return true; + } + + /// + /// Remove a tile at a position (makes it empty/wall) + /// + public bool RemoveTile(Guid dungeonId, int x, int y, int? layer = null) + { + if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) + return false; + + var layout = dungeon.LayoutV2; + if (layout == null) return false; + + if (layer.HasValue) + { + layout.TileDetails.RemoveAll(t => t.X == x && t.Y == y && t.Layer == layer.Value); + } + else + { + layout.TileDetails.RemoveAll(t => t.X == x && t.Y == y); + layout.Walkable[x, y] = false; + layout.Tiles[x, y] = 0; + } + + dungeon.HasPendingTileUpdates = true; + return true; + } + + /// + /// Get tiles that have been updated since last broadcast + /// + public List? GetPendingTileUpdates(Guid dungeonId) { if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) return null; + if (!dungeon.HasPendingTileUpdates) + return null; + + dungeon.HasPendingTileUpdates = false; + return dungeon.LayoutV2?.TileDetails; + } + + // ==================== PLAYER MANIPULATION ==================== + + public PlayerInstance? GetPlayer(Guid dungeonId, ulong characterId) + { + if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) + return null; dungeon.Simulation.Players.TryGetValue(characterId, out var player); return player; } - /// - /// Teleport a player to a position - /// public bool TeleportPlayer(Guid dungeonId, ulong characterId, float x, float y) { if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) return false; - if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player)) return false; - player.X = x; player.Y = y; return true; } - /// - /// Heal a player to full - /// public bool HealPlayer(Guid dungeonId, ulong characterId) { if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) return false; - if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player)) return false; - player.Health = player.MaxHealth; player.Mana = player.MaxMana; player.Stamina = player.MaxStamina; @@ -298,68 +416,41 @@ public partial class DungeonHandler return true; } - /// - /// Kill a player (admin action) - /// public bool KillPlayer(Guid dungeonId, ulong characterId) { if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) return false; - if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player)) return false; - player.Health = 0; player.IsAlive = false; return true; } - /// - /// Set player health to a specific value - /// - public bool SetPlayerHealth(Guid dungeonId, ulong characterId, float health) - { - if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) - return false; - - if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player)) - return false; - - player.Health = Math.Clamp(health, 0, player.MaxHealth); - if (player.Health <= 0) - player.IsAlive = false; - return true; - } - - /// - /// Remove a player from the dungeon (kick) - /// - public bool KickPlayer(Guid dungeonId, ulong characterId) - { - if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) - return false; - - return dungeon.Simulation.Players.TryRemove(characterId, out _); - } - - /// - /// Give player invulnerability (god mode) - /// public bool SetPlayerInvulnerable(Guid dungeonId, ulong characterId, bool invulnerable) { if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) return false; - if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player)) return false; - - // Use a very high armor value for invulnerability - // This is a simple approach - a proper implementation would add an Invulnerable flag player.Armor = invulnerable ? 999999 : 0; return true; } } +///// +///// Helper class for parsing template tile placements +///// +//public class TemplateTilePlacement +//{ +// public int X { get; set; } +// public int Y { get; set; } +// public int TileDefinitionId { get; set; } +// public int SheetId { get; set; } +// public int FrameIndex { get; set; } +// public int Layer { get; set; } +//} + /// /// Statistics for admin dashboard /// diff --git a/Game/Dungeon/DungeonInstance.cs b/Game/Dungeon/DungeonInstance.cs index 1e6b872..08cd4d2 100644 --- a/Game/Dungeon/DungeonInstance.cs +++ b/Game/Dungeon/DungeonInstance.cs @@ -31,6 +31,9 @@ public class DungeonInstance public bool IsPersisted { get; set; } = false; public bool BossKilled { get; set; } = false; + // Admin editing + public bool HasPendingTileUpdates { get; set; } = false; + /// /// Check if a player level is within the bracket range /// diff --git a/Services/Admin/Pages/Dungeons/View.cshtml b/Services/Admin/Pages/Dungeons/View.cshtml index bd49c64..168c5e3 100644 --- a/Services/Admin/Pages/Dungeons/View.cshtml +++ b/Services/Admin/Pages/Dungeons/View.cshtml @@ -5,102 +5,47 @@ }
@@ -112,7 +57,6 @@
❌

Dungeon Not Found

-

This dungeon may have been closed or doesn't exist.

Back to Dungeons
} @@ -124,66 +68,81 @@ else

Live Dungeon Map

-
-
- 500ms - +
+ +
+ + 100% + + +
+
+
+ +
-
- Edit Mode: - - - - - Click/drag on map to edit +
+ Mode: + + + + + + + Click/drag on map
-
- -
- + + + +
+
+ +
+
-
-
- Players (click) -
-
-
- Mobs (click) -
-
-
- Boss -
-
-
- Floor -
-
-
- Wall -
+
Players
+
Mobs
+
Boss
@@ -191,12 +150,12 @@ else @@ -208,36 +167,16 @@ else

Dungeon Info

-
- ID - @Model.Dungeon.Id.ToString()[..12]... -
-
- Tier - @Model.Dungeon.Tier -
-
- Level Bracket - @Model.Dungeon.LevelBracketMin - @Model.Dungeon.LevelBracketMax -
-
- Size - @Model.MapWidth × @Model.MapHeight -
-
- Phase - - @Model.Dungeon.Simulation.Phase - -
-
- Duration - @Model.Duration -
+
ID@Model.Dungeon.Id.ToString()[..12]...
+
Tier@Model.Dungeon.Tier
+
Bracket@Model.Dungeon.LevelBracketMin-@Model.Dungeon.LevelBracketMax
+
Size@Model.MapWidth × @Model.MapHeight
+
Tiles@Model.VisualTileCount placed
+
Duration@Model.Duration
- +

Live Stats

@@ -260,67 +199,53 @@ else @foreach (var mob in Model.MobDefinitions) { - + }
- -

Right-click map to set position

-
-
- - -
-

Players

-
- @foreach (var player in Model.Dungeon.Simulation.Players.Values) - { - var healthPct = player.MaxHealth > 0 ? (player.Health * 100 / player.MaxHealth) : 0; -
-
- @player.CharacterName - @((int)player.Health)/@((int)player.MaxHealth) -
-
-
-
-
- } - @if (!Model.Dungeon.Simulation.Players.Any()) - { -
No players
- } +
-

Dungeon Actions

+

Actions

@Html.AntiForgeryToken() - +
@Html.AntiForgeryToken() - -
-
- @Html.AntiForgeryToken() - - +
+ +
+
+
+
+ + +