Dungeon viewer changes
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
+199
-108
@@ -27,24 +27,18 @@ public partial class DungeonHandler
|
||||
|
||||
/// <summary>
|
||||
/// Force close a dungeon (admin action)
|
||||
/// Removes all players and destroys the instance
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Spawn a mob in a dungeon (admin action)
|
||||
/// Uses the same sprite config system as dungeon generation
|
||||
/// </summary>
|
||||
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 ====================
|
||||
|
||||
/// <summary>
|
||||
/// Set a tile's walkability (admin action)
|
||||
/// Set a tile's walkability (simple mode)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set multiple tiles at once (for painting)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill a rectangle with walkable or wall tiles
|
||||
/// </summary>
|
||||
@@ -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 ====================
|
||||
/// <summary>
|
||||
/// Place a visual tile at a position (full tile editing with graphics)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get detailed player info (admin)
|
||||
/// Place a tile template at a position
|
||||
/// </summary>
|
||||
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<List<TemplateTilePlacement>>(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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a tile at a position (makes it empty/wall)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get tiles that have been updated since last broadcast
|
||||
/// </summary>
|
||||
public List<PlacedTile>? 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Teleport a player to a position
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Heal a player to full
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kill a player (admin action)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set player health to a specific value
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a player from the dungeon (kick)
|
||||
/// </summary>
|
||||
public bool KickPlayer(Guid dungeonId, ulong characterId)
|
||||
{
|
||||
if (!_dungeons.TryGetValue(dungeonId, out var dungeon))
|
||||
return false;
|
||||
|
||||
return dungeon.Simulation.Players.TryRemove(characterId, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Give player invulnerability (god mode)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Helper class for parsing template tile placements
|
||||
///// </summary>
|
||||
//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; }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Statistics for admin dashboard
|
||||
/// </summary>
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Check if a player level is within the bracket range
|
||||
/// </summary>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,12 +20,14 @@ public class ViewModel : AdminPageModel
|
||||
|
||||
public GameServer.Dungeon.DungeonInstance? Dungeon { get; set; }
|
||||
public string Duration { get; set; } = "";
|
||||
public int RoomCount { get; set; }
|
||||
public int MapWidth { get; set; }
|
||||
public int MapHeight { get; set; }
|
||||
public string WalkableJson { get; set; } = "[]";
|
||||
public string PlayersJson { get; set; } = "[]";
|
||||
public string MobsJson { get; set; } = "[]";
|
||||
public string VisualTilesJson { get; set; } = "[]";
|
||||
public string TileSheetsJson { get; set; } = "[]";
|
||||
public int VisualTileCount { get; set; }
|
||||
public List<DungeonMobDefinition> MobDefinitions { get; set; } = new();
|
||||
|
||||
public async Task OnGetAsync(Guid id)
|
||||
@@ -33,14 +35,11 @@ public class ViewModel : AdminPageModel
|
||||
Dungeon = _dungeonHandler.GetDungeon(id);
|
||||
|
||||
MobDefinitions = await _db.DungeonMobDefinitions
|
||||
.Where(m => m.IsEnabled)
|
||||
.OrderBy(m => m.Name)
|
||||
.ToListAsync();
|
||||
.Where(m => m.IsEnabled).OrderBy(m => m.Name).ToListAsync();
|
||||
|
||||
if (Dungeon == null) return;
|
||||
|
||||
Duration = FormatDuration(DateTime.UtcNow - Dungeon.CreatedAt);
|
||||
RoomCount = Dungeon.LayoutV2?.Rooms?.Count ?? Dungeon.Simulation.Layout.Rooms.Count;
|
||||
|
||||
var layout = Dungeon.LayoutV2;
|
||||
if (layout != null)
|
||||
@@ -53,203 +52,139 @@ public class ViewModel : AdminPageModel
|
||||
for (int x = 0; x < layout.Width; x++)
|
||||
walkable.Add(layout.Walkable[x, y]);
|
||||
WalkableJson = JsonSerializer.Serialize(walkable);
|
||||
|
||||
VisualTileCount = layout.TileDetails.Count;
|
||||
VisualTilesJson = JsonSerializer.Serialize(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
|
||||
}));
|
||||
|
||||
TileSheetsJson = JsonSerializer.Serialize(layout.TileMapSheets.Select(s => new {
|
||||
id = s.Id, name = s.CdnPath?.Split('/').LastOrDefault() ?? $"Sheet {s.Id}",
|
||||
path = s.CdnPath, tileW = s.TileWidth, tileH = s.TileHeight,
|
||||
sheetW = s.SheetWidth, sheetH = s.SheetHeight, cols = s.Columns
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
MapWidth = 100;
|
||||
MapHeight = 100;
|
||||
WalkableJson = "[]";
|
||||
}
|
||||
else { MapWidth = 100; MapHeight = 100; }
|
||||
|
||||
PlayersJson = JsonSerializer.Serialize(
|
||||
Dungeon.Simulation.Players.Values.Select(p => new
|
||||
{
|
||||
id = p.CharacterId.ToString(),
|
||||
name = p.CharacterName,
|
||||
x = p.X,
|
||||
y = p.Y,
|
||||
health = p.Health,
|
||||
maxHealth = p.MaxHealth,
|
||||
mana = p.Mana,
|
||||
maxMana = p.MaxMana,
|
||||
isAlive = p.IsAlive,
|
||||
isInCombat = p.IsInCombat
|
||||
})
|
||||
);
|
||||
PlayersJson = JsonSerializer.Serialize(Dungeon.Simulation.Players.Values.Select(p => new {
|
||||
id = p.CharacterId.ToString(), name = p.CharacterName, x = p.X, y = p.Y,
|
||||
health = p.Health, maxHealth = p.MaxHealth, isAlive = p.IsAlive
|
||||
}));
|
||||
|
||||
MobsJson = JsonSerializer.Serialize(
|
||||
Dungeon.Simulation.Mobs.Values.Select(m => new
|
||||
{
|
||||
id = m.Id,
|
||||
name = m.Name,
|
||||
x = m.X,
|
||||
y = m.Y,
|
||||
health = m.Health,
|
||||
maxHealth = m.MaxHealth,
|
||||
alive = m.IsAlive,
|
||||
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss,
|
||||
type = m.Type.ToString(),
|
||||
state = m.State.ToString(),
|
||||
definitionId = m.DefinitionId
|
||||
})
|
||||
);
|
||||
MobsJson = JsonSerializer.Serialize(Dungeon.Simulation.Mobs.Values.Select(m => new {
|
||||
id = m.Id, name = m.Name, x = m.X, y = m.Y, health = m.Health, maxHealth = m.MaxHealth,
|
||||
alive = m.IsAlive, isBoss = m.Type == DataServer.Data.Enums.MobType.Boss, state = m.State.ToString()
|
||||
}));
|
||||
}
|
||||
|
||||
public IActionResult OnGetStatus(Guid id)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon == null)
|
||||
return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
|
||||
if (dungeon == null) return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
|
||||
|
||||
return new JsonResult(new
|
||||
{
|
||||
return new JsonResult(new {
|
||||
playerCount = dungeon.Simulation.Players.Count,
|
||||
mobsAlive = dungeon.Simulation.Mobs.Values.Count(m => m.IsAlive),
|
||||
duration = FormatDuration(DateTime.UtcNow - dungeon.CreatedAt),
|
||||
players = dungeon.Simulation.Players.Values.Select(p => new
|
||||
{
|
||||
id = p.CharacterId.ToString(),
|
||||
name = p.CharacterName,
|
||||
x = p.X,
|
||||
y = p.Y,
|
||||
health = p.Health,
|
||||
maxHealth = p.MaxHealth,
|
||||
mana = p.Mana,
|
||||
maxMana = p.MaxMana,
|
||||
isAlive = p.IsAlive,
|
||||
isInCombat = p.IsInCombat
|
||||
players = dungeon.Simulation.Players.Values.Select(p => new {
|
||||
id = p.CharacterId.ToString(), name = p.CharacterName, x = p.X, y = p.Y,
|
||||
health = p.Health, maxHealth = p.MaxHealth
|
||||
}),
|
||||
mobs = dungeon.Simulation.Mobs.Values.Select(m => new
|
||||
{
|
||||
id = m.Id,
|
||||
name = m.Name,
|
||||
x = m.X,
|
||||
y = m.Y,
|
||||
health = m.Health,
|
||||
maxHealth = m.MaxHealth,
|
||||
alive = m.IsAlive,
|
||||
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss,
|
||||
type = m.Type.ToString(),
|
||||
state = m.State.ToString(),
|
||||
definitionId = m.DefinitionId
|
||||
mobs = dungeon.Simulation.Mobs.Values.Select(m => new {
|
||||
id = m.Id, name = m.Name, x = m.X, y = m.Y, health = m.Health, maxHealth = m.MaxHealth,
|
||||
alive = m.IsAlive, isBoss = m.Type == DataServer.Data.Enums.MobType.Boss, state = m.State.ToString()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== MOB HANDLERS ====================
|
||||
public IActionResult OnPostSetTile(Guid id, int x, int y, bool walkable)
|
||||
{
|
||||
return new JsonResult(new { success = _dungeonHandler.SetTileWalkable(id, x, y, walkable) });
|
||||
}
|
||||
|
||||
public IActionResult OnPostPlaceVisualTile(Guid id, int x, int y, int sheetId, int frameIndex, int layer = 0, bool walkable = true)
|
||||
{
|
||||
return new JsonResult(new { success = _dungeonHandler.PlaceVisualTile(id, x, y, sheetId, frameIndex, layer, walkable) });
|
||||
}
|
||||
|
||||
public IActionResult OnPostRemoveTile(Guid id, int x, int y, int? layer = null)
|
||||
{
|
||||
return new JsonResult(new { success = _dungeonHandler.RemoveTile(id, x, y, layer) });
|
||||
}
|
||||
|
||||
public IActionResult OnPostFillRect(Guid id, int x1, int y1, int x2, int y2, bool walkable)
|
||||
{
|
||||
return new JsonResult(new { success = _dungeonHandler.FillTileRect(id, x1, y1, x2, y2, walkable) > 0 });
|
||||
}
|
||||
|
||||
public IActionResult OnPostBroadcastTiles(Guid id)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon == null) return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
|
||||
dungeon.HasPendingTileUpdates = true;
|
||||
return new JsonResult(new { success = true });
|
||||
}
|
||||
|
||||
public IActionResult OnPostKillMob(Guid id, int mobId)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon == null)
|
||||
return new JsonResult(new { error = "Dungeon not found" }) { StatusCode = 404 };
|
||||
|
||||
if (dungeon.Simulation.Mobs.TryGetValue(mobId, out var mob))
|
||||
if (dungeon?.Simulation.Mobs.TryGetValue(mobId, out var mob) == true)
|
||||
{
|
||||
mob.Health = 0;
|
||||
mob.IsAlive = false;
|
||||
mob.Health = 0; mob.IsAlive = false;
|
||||
return new JsonResult(new { success = true });
|
||||
}
|
||||
|
||||
return new JsonResult(new { error = "Mob not found" }) { StatusCode = 404 };
|
||||
return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
|
||||
}
|
||||
|
||||
public IActionResult OnPostSpawnMob(Guid id, int mobDefId, float x, float y)
|
||||
{
|
||||
var mob = _dungeonHandler.SpawnMobInDungeon(id, mobDefId, x, y);
|
||||
if (mob == null)
|
||||
return new JsonResult(new { error = "Failed to spawn mob" }) { StatusCode = 400 };
|
||||
return new JsonResult(new { success = true, mobId = mob.Id });
|
||||
return mob != null
|
||||
? new JsonResult(new { success = true, mobId = mob.Id })
|
||||
: new JsonResult(new { error = "Failed" }) { StatusCode = 400 };
|
||||
}
|
||||
|
||||
public IActionResult OnPostKillAllMobs(Guid id)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon != null)
|
||||
{
|
||||
foreach (var mob in dungeon.Simulation.Mobs.Values)
|
||||
{
|
||||
mob.Health = 0;
|
||||
mob.IsAlive = false;
|
||||
}
|
||||
}
|
||||
foreach (var mob in dungeon.Simulation.Mobs.Values) { mob.Health = 0; mob.IsAlive = false; }
|
||||
return RedirectToPage(new { id });
|
||||
}
|
||||
|
||||
// ==================== TILE EDITING HANDLERS ====================
|
||||
|
||||
public IActionResult OnPostSetTile(Guid id, int x, int y, bool walkable)
|
||||
{
|
||||
var result = _dungeonHandler.SetTileWalkable(id, x, y, walkable);
|
||||
return new JsonResult(new { success = result });
|
||||
}
|
||||
|
||||
public IActionResult OnPostFillRect(Guid id, int x1, int y1, int x2, int y2, bool walkable)
|
||||
{
|
||||
var count = _dungeonHandler.FillTileRect(id, x1, y1, x2, y2, walkable);
|
||||
return new JsonResult(new { success = count > 0, count });
|
||||
}
|
||||
|
||||
// ==================== PLAYER HANDLERS ====================
|
||||
|
||||
public IActionResult OnPostHealPlayer(Guid id, string playerId)
|
||||
{
|
||||
if (!ulong.TryParse(playerId, out var charId))
|
||||
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
|
||||
|
||||
var result = _dungeonHandler.HealPlayer(id, charId);
|
||||
return new JsonResult(new { success = result });
|
||||
if (!ulong.TryParse(playerId, out var charId)) return new JsonResult(new { error = "Invalid ID" }) { StatusCode = 400 };
|
||||
return new JsonResult(new { success = _dungeonHandler.HealPlayer(id, charId) });
|
||||
}
|
||||
|
||||
public IActionResult OnPostTeleportPlayer(Guid id, string playerId, float x, float y)
|
||||
{
|
||||
if (!ulong.TryParse(playerId, out var charId))
|
||||
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
|
||||
|
||||
var result = _dungeonHandler.TeleportPlayer(id, charId, x, y);
|
||||
return new JsonResult(new { success = result });
|
||||
if (!ulong.TryParse(playerId, out var charId)) return new JsonResult(new { error = "Invalid ID" }) { StatusCode = 400 };
|
||||
return new JsonResult(new { success = _dungeonHandler.TeleportPlayer(id, charId, x, y) });
|
||||
}
|
||||
|
||||
public IActionResult OnPostKillPlayer(Guid id, string playerId)
|
||||
{
|
||||
if (!ulong.TryParse(playerId, out var charId))
|
||||
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
|
||||
|
||||
var result = _dungeonHandler.KillPlayer(id, charId);
|
||||
return new JsonResult(new { success = result });
|
||||
if (!ulong.TryParse(playerId, out var charId)) return new JsonResult(new { error = "Invalid ID" }) { StatusCode = 400 };
|
||||
return new JsonResult(new { success = _dungeonHandler.KillPlayer(id, charId) });
|
||||
}
|
||||
|
||||
public IActionResult OnPostSetGodMode(Guid id, string playerId, bool enabled)
|
||||
{
|
||||
if (!ulong.TryParse(playerId, out var charId))
|
||||
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
|
||||
|
||||
var result = _dungeonHandler.SetPlayerInvulnerable(id, charId, enabled);
|
||||
return new JsonResult(new { success = result });
|
||||
if (!ulong.TryParse(playerId, out var charId)) return new JsonResult(new { error = "Invalid ID" }) { StatusCode = 400 };
|
||||
return new JsonResult(new { success = _dungeonHandler.SetPlayerInvulnerable(id, charId, enabled) });
|
||||
}
|
||||
|
||||
// ==================== DUNGEON HANDLERS ====================
|
||||
|
||||
public IActionResult OnPostCompleteDungeon(Guid id)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon != null)
|
||||
dungeon.Simulation.ForceComplete();
|
||||
dungeon?.Simulation.ForceComplete();
|
||||
return RedirectToPage(new { id });
|
||||
}
|
||||
|
||||
public IActionResult OnPostDelete(Guid id)
|
||||
{
|
||||
_dungeonHandler.ForceCloseDungeon(id);
|
||||
return RedirectToPage("/Dungeons/Index");
|
||||
}
|
||||
|
||||
private static string FormatDuration(TimeSpan duration)
|
||||
{
|
||||
if (duration.TotalHours >= 1)
|
||||
return $"{(int)duration.TotalHours}h {duration.Minutes}m";
|
||||
if (duration.TotalMinutes >= 1)
|
||||
return $"{(int)duration.TotalMinutes}m {duration.Seconds}s";
|
||||
return $"{(int)duration.TotalSeconds}s";
|
||||
}
|
||||
private static string FormatDuration(TimeSpan d) =>
|
||||
d.TotalHours >= 1 ? $"{(int)d.TotalHours}h {d.Minutes}m" :
|
||||
d.TotalMinutes >= 1 ? $"{(int)d.TotalMinutes}m {d.Seconds}s" : $"{(int)d.TotalSeconds}s";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user