Admin updates, dungeon viewer
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
@page "/admin/dungeons"
|
||||
@model Admin.Pages.Dungeons.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Dungeon Management";
|
||||
}
|
||||
|
||||
<style>
|
||||
.dungeon-card {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
.dungeon-card:hover {
|
||||
border-color: rgba(99, 102, 241, 0.5);
|
||||
}
|
||||
.phase-active { color: #4ade80; }
|
||||
.phase-completed { color: #60a5fa; }
|
||||
.phase-failed { color: #f87171; }
|
||||
.stat-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.live-indicator {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: #4ade80;
|
||||
border-radius: 50%;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
@@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="space-y-6">
|
||||
<!-- Header -->
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Dungeon Management</h1>
|
||||
<p class="text-gray-400 mt-1">View and manage active dungeon instances</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button onclick="refreshDungeons()" class="btn btn-secondary">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
|
||||
</svg>
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (TempData["Message"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-green-900/50 border border-green-700 text-green-300">
|
||||
@TempData["Message"]
|
||||
</div>
|
||||
}
|
||||
@if (TempData["Error"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-red-900/50 border border-red-700 text-red-300">
|
||||
@TempData["Error"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Stats Overview -->
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div class="card p-4">
|
||||
<div class="text-2xl font-bold text-white">@Model.ActiveCount</div>
|
||||
<div class="text-gray-400 text-sm">Active Dungeons</div>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<div class="text-2xl font-bold text-green-400">@Model.TotalPlayers</div>
|
||||
<div class="text-gray-400 text-sm">Players In Dungeons</div>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<div class="text-2xl font-bold text-blue-400">@Model.CompletedToday</div>
|
||||
<div class="text-gray-400 text-sm">Completed Today</div>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<div class="text-2xl font-bold text-yellow-400">@Model.AverageDuration</div>
|
||||
<div class="text-gray-400 text-sm">Avg Duration (min)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4">
|
||||
<form method="get" class="flex flex-wrap gap-3 items-end">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400 mb-1 block">Status</label>
|
||||
<select name="status" class="input text-sm">
|
||||
<option value="">All Status</option>
|
||||
<option value="active" selected="@(Model.StatusFilter == "active")">Active</option>
|
||||
<option value="completed" selected="@(Model.StatusFilter == "completed")">Completed</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400 mb-1 block">Tier</label>
|
||||
<select name="tier" class="input text-sm">
|
||||
<option value="">All Tiers</option>
|
||||
@for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
<option value="@i" selected="@(Model.TierFilter == i)">Tier @i</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400 mb-1 block">Level Bracket</label>
|
||||
<select name="bracket" class="input text-sm">
|
||||
<option value="">All Brackets</option>
|
||||
<option value="1" selected="@(Model.BracketFilter == 1)">1-10</option>
|
||||
<option value="2" selected="@(Model.BracketFilter == 2)">11-20</option>
|
||||
<option value="3" selected="@(Model.BracketFilter == 3)">21-30</option>
|
||||
<option value="4" selected="@(Model.BracketFilter == 4)">31-40</option>
|
||||
<option value="5" selected="@(Model.BracketFilter == 5)">41-50</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary text-sm">Filter</button>
|
||||
<a href="/admin/dungeons" class="btn btn-ghost text-sm">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Active Dungeons -->
|
||||
<div class="space-y-4">
|
||||
<h2 class="text-xl font-semibold text-white flex items-center gap-2">
|
||||
<div class="live-indicator"></div>
|
||||
Active Dungeons (@Model.Dungeons.Count)
|
||||
</h2>
|
||||
|
||||
@if (Model.Dungeons.Count > 0)
|
||||
{
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
@foreach (var dungeon in Model.Dungeons)
|
||||
{
|
||||
<div class="dungeon-card card p-4">
|
||||
<div class="flex items-start justify-between mb-3">
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-lg font-semibold text-white">Tier @dungeon.Tier</span>
|
||||
<span class="stat-badge bg-indigo-500/20 text-indigo-300">Lvl @dungeon.LevelBracketMin-@dungeon.LevelBracketMax</span>
|
||||
@if (dungeon.BossKilled)
|
||||
{
|
||||
<span class="stat-badge bg-green-500/20 text-green-300">Boss Killed</span>
|
||||
}
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 mt-1 font-mono">@dungeon.Id.ToString()[..8]...</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<span class="@GetPhaseClass(dungeon.Phase)">@dungeon.Phase</span>
|
||||
<div class="text-xs text-gray-500">@dungeon.Duration</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-2 text-sm mb-3">
|
||||
<div class="bg-gray-800/50 rounded p-2 text-center">
|
||||
<div class="text-white font-semibold">@dungeon.PlayerCount</div>
|
||||
<div class="text-xs text-gray-400">Players</div>
|
||||
</div>
|
||||
<div class="bg-gray-800/50 rounded p-2 text-center">
|
||||
<div class="text-white font-semibold">@dungeon.MobsAlive / @dungeon.TotalMobs</div>
|
||||
<div class="text-xs text-gray-400">Mobs</div>
|
||||
</div>
|
||||
<div class="bg-gray-800/50 rounded p-2 text-center">
|
||||
<div class="text-white font-semibold">@dungeon.RoomCount</div>
|
||||
<div class="text-xs text-gray-400">Rooms</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-xs text-gray-400 mb-3">
|
||||
<span>Created by: <span class="text-white">@dungeon.CreatorName</span></span>
|
||||
<span class="mx-2">•</span>
|
||||
<span>Seed: <span class="font-mono text-gray-300">@dungeon.Seed</span></span>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/dungeons/view?id=@dungeon.Id" class="btn btn-sm btn-secondary flex-1">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
|
||||
</svg>
|
||||
View
|
||||
</a>
|
||||
<form method="post" asp-page-handler="Delete" onsubmit="return confirm('Delete this dungeon? All players will be removed.')">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@dungeon.Id" />
|
||||
<button type="submit" class="btn btn-sm btn-danger">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card p-8 text-center text-gray-500">
|
||||
<div class="text-4xl mb-2">🏰</div>
|
||||
<p>No active dungeons at the moment.</p>
|
||||
<p class="text-sm mt-1">Dungeons are created when players enter them.</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function refreshDungeons() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
// Auto-refresh every 30 seconds
|
||||
setInterval(() => {
|
||||
// Only refresh if page is visible
|
||||
if (!document.hidden) {
|
||||
refreshDungeons();
|
||||
}
|
||||
}, 30000);
|
||||
</script>
|
||||
}
|
||||
|
||||
@functions {
|
||||
string GetPhaseClass(string phase)
|
||||
{
|
||||
return phase.ToLower() switch
|
||||
{
|
||||
"active" => "phase-active",
|
||||
"completed" => "phase-completed",
|
||||
"failed" => "phase-failed",
|
||||
_ => "text-gray-400"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Server.Game.Dungeon;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Dungeons;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly DungeonHandler _dungeonHandler;
|
||||
|
||||
public IndexModel(DungeonHandler dungeonHandler)
|
||||
{
|
||||
_dungeonHandler = dungeonHandler;
|
||||
}
|
||||
|
||||
public List<DungeonSummary> Dungeons { get; set; } = new();
|
||||
|
||||
// Stats
|
||||
public int ActiveCount { get; set; }
|
||||
public int TotalPlayers { get; set; }
|
||||
public int CompletedToday { get; set; }
|
||||
public string AverageDuration { get; set; } = "0";
|
||||
|
||||
// Filters
|
||||
public string? StatusFilter { get; set; }
|
||||
public int? TierFilter { get; set; }
|
||||
public int? BracketFilter { get; set; }
|
||||
|
||||
public void OnGet(string? status, int? tier, int? bracket)
|
||||
{
|
||||
StatusFilter = status;
|
||||
TierFilter = tier;
|
||||
BracketFilter = bracket;
|
||||
|
||||
// Get all active dungeons from the handler
|
||||
var allDungeons = _dungeonHandler.GetActiveDungeons();
|
||||
|
||||
// Apply filters
|
||||
var filtered = allDungeons.AsEnumerable();
|
||||
|
||||
if (!string.IsNullOrEmpty(status))
|
||||
{
|
||||
if (status == "active")
|
||||
filtered = filtered.Where(d => d.Simulation.Phase == DungeonPhase.Active);
|
||||
else if (status == "completed")
|
||||
filtered = filtered.Where(d => d.Simulation.Phase == DungeonPhase.Cleared);
|
||||
}
|
||||
|
||||
if (tier.HasValue)
|
||||
{
|
||||
filtered = filtered.Where(d => d.Tier == tier.Value);
|
||||
}
|
||||
|
||||
if (bracket.HasValue)
|
||||
{
|
||||
int minLevel = (bracket.Value - 1) * 10 + 1;
|
||||
int maxLevel = bracket.Value * 10;
|
||||
filtered = filtered.Where(d => d.LevelBracketMin >= minLevel && d.LevelBracketMax <= maxLevel);
|
||||
}
|
||||
|
||||
// Transform to summary
|
||||
Dungeons = filtered.Select(d => new DungeonSummary
|
||||
{
|
||||
Id = d.Id,
|
||||
Tier = d.Tier,
|
||||
Seed = d.Seed,
|
||||
LevelBracketMin = d.LevelBracketMin,
|
||||
LevelBracketMax = d.LevelBracketMax,
|
||||
CreatorName = d.CreatorName,
|
||||
CreatedAt = d.CreatedAt,
|
||||
Phase = d.Simulation.Phase.ToString(),
|
||||
PlayerCount = d.Simulation.Players.Count,
|
||||
MobsAlive = d.Simulation.Mobs.Values.Count(m => m.IsAlive),
|
||||
TotalMobs = d.Simulation.Mobs.Count,
|
||||
RoomCount = d.LayoutV2?.Rooms?.Count ?? d.Simulation.Layout.Rooms.Count,
|
||||
BossKilled = d.BossKilled,
|
||||
Duration = FormatDuration(DateTime.UtcNow - d.CreatedAt)
|
||||
}).OrderByDescending(d => d.CreatedAt).ToList();
|
||||
|
||||
// Calculate stats
|
||||
ActiveCount = allDungeons.Count;
|
||||
TotalPlayers = allDungeons.Sum(d => d.Simulation.Players.Count);
|
||||
|
||||
// Average duration of completed dungeons (simplified)
|
||||
var completedDungeons = allDungeons.Where(d => d.Simulation.Phase == DungeonPhase.Cleared).ToList();
|
||||
if (completedDungeons.Any())
|
||||
{
|
||||
var avgMinutes = completedDungeons.Average(d => (DateTime.UtcNow - d.CreatedAt).TotalMinutes);
|
||||
AverageDuration = avgMinutes.ToString("F1");
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnPostDelete(Guid id)
|
||||
{
|
||||
var result = _dungeonHandler.ForceCloseDungeon(id);
|
||||
if (result)
|
||||
{
|
||||
TempData["Message"] = "Dungeon deleted successfully.";
|
||||
}
|
||||
else
|
||||
{
|
||||
TempData["Error"] = "Failed to delete dungeon. It may have already been closed.";
|
||||
}
|
||||
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
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";
|
||||
return $"{(int)duration.TotalSeconds}s";
|
||||
}
|
||||
}
|
||||
|
||||
public class DungeonSummary
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public int Tier { get; set; }
|
||||
public int Seed { get; set; }
|
||||
public int LevelBracketMin { get; set; }
|
||||
public int LevelBracketMax { get; set; }
|
||||
public string CreatorName { get; set; } = "";
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public string Phase { get; set; } = "";
|
||||
public int PlayerCount { get; set; }
|
||||
public int MobsAlive { get; set; }
|
||||
public int TotalMobs { get; set; }
|
||||
public int RoomCount { get; set; }
|
||||
public bool BossKilled { get; set; }
|
||||
public string Duration { get; set; } = "";
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
@page "/admin/dungeons/view"
|
||||
@model Admin.Pages.Dungeons.ViewModel
|
||||
@{
|
||||
ViewData["Title"] = $"Dungeon View - Tier {Model.Dungeon?.Tier}";
|
||||
}
|
||||
|
||||
<style>
|
||||
.dungeon-map {
|
||||
background: #0a0a15;
|
||||
border: 2px solid #374151;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
.map-canvas {
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
.entity-dot {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
.player-dot {
|
||||
background: #4ade80;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
box-shadow: 0 0 6px #4ade80;
|
||||
}
|
||||
.mob-dot {
|
||||
background: #f87171;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
}
|
||||
.boss-dot {
|
||||
background: #fbbf24;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
box-shadow: 0 0 8px #fbbf24;
|
||||
}
|
||||
.stat-card {
|
||||
background: rgba(30, 30, 50, 0.8);
|
||||
border: 1px solid #374151;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
}
|
||||
.player-list-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
background: rgba(30, 30, 50, 0.5);
|
||||
border-radius: 6px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.health-bar {
|
||||
height: 4px;
|
||||
background: #374151;
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.health-bar-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #ef4444, #22c55e);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeons" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Dungeons</a>
|
||||
</div>
|
||||
|
||||
@if (Model.Dungeon == null)
|
||||
{
|
||||
<div class="card p-8 text-center">
|
||||
<div class="text-4xl mb-2">❌</div>
|
||||
<h2 class="text-xl font-semibold text-white mb-2">Dungeon Not Found</h2>
|
||||
<p class="text-gray-400">This dungeon may have been closed or doesn't exist.</p>
|
||||
<a href="/admin/dungeons" class="btn btn-primary mt-4">Back to Dungeons</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="flex flex-col lg:flex-row gap-6">
|
||||
<!-- Left: Map View -->
|
||||
<div class="flex-1">
|
||||
<div class="card p-4">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="text-xl font-semibold text-white">Live Dungeon Map</h2>
|
||||
<div class="flex items-center gap-2 text-sm text-gray-400">
|
||||
<div class="w-2 h-2 bg-green-400 rounded-full animate-pulse"></div>
|
||||
<span>Live</span>
|
||||
<button onclick="toggleAutoRefresh()" id="autoRefreshBtn" class="btn btn-sm btn-ghost ml-2">
|
||||
Auto: ON
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dungeon-map" id="mapContainer" style="height: 500px;">
|
||||
<canvas id="mapCanvas" class="map-canvas"></canvas>
|
||||
<div id="entityOverlay"></div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-center gap-6 mt-3 text-xs text-gray-400">
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-3 h-3 rounded-full bg-green-400"></div>
|
||||
<span>Players</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-2 h-2 rounded-full bg-red-400"></div>
|
||||
<span>Mobs</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-3 h-3 rounded-full bg-yellow-400"></div>
|
||||
<span>Boss</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-3 h-3 bg-blue-400"></div>
|
||||
<span>Floor</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-3 h-3 bg-gray-700"></div>
|
||||
<span>Wall</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Info Panel -->
|
||||
<div class="w-full lg:w-80 space-y-4">
|
||||
<!-- Dungeon Info -->
|
||||
<div class="stat-card">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Dungeon Info</h3>
|
||||
<div class="space-y-2 text-sm">
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">ID</span>
|
||||
<span class="text-white font-mono text-xs">@Model.Dungeon.Id.ToString()[..12]...</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Tier</span>
|
||||
<span class="text-white">@Model.Dungeon.Tier</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Level Bracket</span>
|
||||
<span class="text-white">@Model.Dungeon.LevelBracketMin - @Model.Dungeon.LevelBracketMax</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Seed</span>
|
||||
<span class="text-white font-mono">@Model.Dungeon.Seed</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Phase</span>
|
||||
<span class="@(Model.Dungeon.Simulation.Phase == DungeonPhase.Active ? "text-green-400" : "text-blue-400")">
|
||||
@Model.Dungeon.Simulation.Phase
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Creator</span>
|
||||
<span class="text-white">@Model.Dungeon.CreatorName</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Created</span>
|
||||
<span class="text-white">@Model.Dungeon.CreatedAt.ToString("HH:mm:ss")</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-400">Duration</span>
|
||||
<span class="text-white" id="duration">@Model.Duration</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stats -->
|
||||
<div class="stat-card">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Stats</h3>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="text-center p-2 bg-gray-800/50 rounded">
|
||||
<div class="text-2xl font-bold text-green-400" id="playerCount">@Model.Dungeon.Simulation.Players.Count</div>
|
||||
<div class="text-xs text-gray-400">Players</div>
|
||||
</div>
|
||||
<div class="text-center p-2 bg-gray-800/50 rounded">
|
||||
<div class="text-2xl font-bold text-red-400" id="mobCount">@Model.Dungeon.Simulation.Mobs.Values.Count(m => m.IsAlive)</div>
|
||||
<div class="text-xs text-gray-400">Mobs Alive</div>
|
||||
</div>
|
||||
<div class="text-center p-2 bg-gray-800/50 rounded">
|
||||
<div class="text-2xl font-bold text-blue-400">@Model.RoomCount</div>
|
||||
<div class="text-xs text-gray-400">Rooms</div>
|
||||
</div>
|
||||
<div class="text-center p-2 bg-gray-800/50 rounded">
|
||||
<div class="text-2xl font-bold @(Model.Dungeon.BossKilled ? "text-yellow-400" : "text-gray-500")">
|
||||
@(Model.Dungeon.BossKilled ? "✓" : "✗")
|
||||
</div>
|
||||
<div class="text-xs text-gray-400">Boss Killed</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Players -->
|
||||
<div class="stat-card">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Players (@Model.Dungeon.Simulation.Players.Count)</h3>
|
||||
<div id="playerList" class="space-y-1 max-h-48 overflow-y-auto">
|
||||
@foreach (var player in Model.Dungeon.Simulation.Players.Values)
|
||||
{
|
||||
var healthPct = player.MaxHealth > 0 ? (player.Health * 100 / player.MaxHealth) : 0;
|
||||
<div class="player-list-item">
|
||||
<div class="w-2 h-2 rounded-full bg-green-400"></div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-white text-sm truncate">@player.CharacterName</div>
|
||||
<div class="health-bar mt-1">
|
||||
<div class="health-bar-fill" style="width: @healthPct%"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-xs text-gray-400">@player.Health/@player.MaxHealth</div>
|
||||
</div>
|
||||
}
|
||||
@if (Model.Dungeon.Simulation.Players.Count == 0)
|
||||
{
|
||||
<div class="text-gray-500 text-sm text-center py-2">No players</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="stat-card">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Actions</h3>
|
||||
<div class="space-y-2">
|
||||
<form method="post" asp-page-handler="KillAllMobs">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@Model.Dungeon.Id" />
|
||||
<button type="submit" class="btn btn-secondary w-full text-sm" onclick="return confirm('Kill all mobs in this dungeon?')">
|
||||
Kill All Mobs
|
||||
</button>
|
||||
</form>
|
||||
<form method="post" asp-page-handler="CompleteDungeon">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@Model.Dungeon.Id" />
|
||||
<button type="submit" class="btn btn-secondary w-full text-sm" onclick="return confirm('Force complete this dungeon?')">
|
||||
Force Complete
|
||||
</button>
|
||||
</form>
|
||||
<form method="post" asp-page-handler="Delete">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@Model.Dungeon.Id" />
|
||||
<button type="submit" class="btn btn-danger w-full text-sm" onclick="return confirm('Delete this dungeon? All players will be removed.')">
|
||||
Delete Dungeon
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const dungeonId = '@Model.Dungeon?.Id';
|
||||
const mapWidth = @(Model.MapWidth);
|
||||
const mapHeight = @(Model.MapHeight);
|
||||
const walkableData = @Html.Raw(Model.WalkableJson);
|
||||
|
||||
let autoRefresh = true;
|
||||
let refreshInterval;
|
||||
|
||||
function initMap() {
|
||||
const canvas = document.getElementById('mapCanvas');
|
||||
const container = document.getElementById('mapContainer');
|
||||
if (!canvas || !container) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
const scale = Math.min(
|
||||
(container.clientWidth - 20) / mapWidth,
|
||||
(container.clientHeight - 20) / mapHeight,
|
||||
8 // Max scale
|
||||
);
|
||||
|
||||
canvas.width = mapWidth * scale;
|
||||
canvas.height = mapHeight * scale;
|
||||
canvas.style.width = canvas.width + 'px';
|
||||
canvas.style.height = canvas.height + 'px';
|
||||
|
||||
// Draw tiles
|
||||
for (let y = 0; y < mapHeight; y++) {
|
||||
for (let x = 0; x < mapWidth; x++) {
|
||||
const idx = y * mapWidth + x;
|
||||
const walkable = walkableData[idx];
|
||||
|
||||
ctx.fillStyle = walkable ? '#1e3a5f' : '#1a1a2e';
|
||||
ctx.fillRect(x * scale, y * scale, scale, scale);
|
||||
|
||||
// Grid lines
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
|
||||
ctx.strokeRect(x * scale, y * scale, scale, scale);
|
||||
}
|
||||
}
|
||||
|
||||
// Store scale for entity positioning
|
||||
canvas.dataset.scale = scale;
|
||||
}
|
||||
|
||||
function updateEntities(players, mobs) {
|
||||
const canvas = document.getElementById('mapCanvas');
|
||||
const overlay = document.getElementById('entityOverlay');
|
||||
if (!canvas || !overlay) return;
|
||||
|
||||
const scale = parseFloat(canvas.dataset.scale) || 4;
|
||||
const tileSize = 32; // Game tile size
|
||||
|
||||
overlay.innerHTML = '';
|
||||
|
||||
// Draw players
|
||||
players.forEach(p => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'entity-dot player-dot';
|
||||
div.style.left = (p.x / tileSize * scale) + 'px';
|
||||
div.style.top = (p.y / tileSize * scale) + 'px';
|
||||
div.title = p.name;
|
||||
overlay.appendChild(div);
|
||||
});
|
||||
|
||||
// Draw mobs
|
||||
mobs.forEach(m => {
|
||||
if (!m.alive) return;
|
||||
const div = document.createElement('div');
|
||||
div.className = 'entity-dot ' + (m.isBoss ? 'boss-dot' : 'mob-dot');
|
||||
div.style.left = (m.x / tileSize * scale) + 'px';
|
||||
div.style.top = (m.y / tileSize * scale) + 'px';
|
||||
div.title = m.name;
|
||||
overlay.appendChild(div);
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchUpdate() {
|
||||
try {
|
||||
const resp = await fetch(`/admin/dungeons/view?handler=Status&id=${dungeonId}`);
|
||||
if (resp.ok) {
|
||||
const data = await resp.json();
|
||||
document.getElementById('playerCount').textContent = data.playerCount;
|
||||
document.getElementById('mobCount').textContent = data.mobsAlive;
|
||||
document.getElementById('duration').textContent = data.duration;
|
||||
updateEntities(data.players, data.mobs);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch update:', e);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAutoRefresh() {
|
||||
autoRefresh = !autoRefresh;
|
||||
document.getElementById('autoRefreshBtn').textContent = 'Auto: ' + (autoRefresh ? 'ON' : 'OFF');
|
||||
|
||||
if (autoRefresh) {
|
||||
refreshInterval = setInterval(fetchUpdate, 2000);
|
||||
} else {
|
||||
clearInterval(refreshInterval);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initMap();
|
||||
|
||||
// Initial entity positions
|
||||
const initialPlayers = @Html.Raw(Model.PlayersJson);
|
||||
const initialMobs = @Html.Raw(Model.MobsJson);
|
||||
updateEntities(initialPlayers, initialMobs);
|
||||
|
||||
// Start auto-refresh
|
||||
refreshInterval = setInterval(fetchUpdate, 2000);
|
||||
});
|
||||
|
||||
// Handle resize
|
||||
window.addEventListener('resize', initMap);
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Server.Game.Dungeon;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Dungeons;
|
||||
|
||||
public class ViewModel : AdminPageModel
|
||||
{
|
||||
private readonly DungeonHandler _dungeonHandler;
|
||||
|
||||
public ViewModel(DungeonHandler dungeonHandler)
|
||||
{
|
||||
_dungeonHandler = dungeonHandler;
|
||||
}
|
||||
|
||||
public 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 void OnGet(Guid id)
|
||||
{
|
||||
Dungeon = _dungeonHandler.GetDungeon(id);
|
||||
|
||||
if (Dungeon == null) return;
|
||||
|
||||
Duration = FormatDuration(DateTime.UtcNow - Dungeon.CreatedAt);
|
||||
RoomCount = Dungeon.LayoutV2?.Rooms?.Count ?? Dungeon.Simulation.Layout.Rooms.Count;
|
||||
|
||||
// Get map dimensions
|
||||
var layout = Dungeon.LayoutV2 ?? (DungeonLayoutV2?)null;
|
||||
if (layout != null)
|
||||
{
|
||||
MapWidth = layout.Width;
|
||||
MapHeight = layout.Height;
|
||||
|
||||
// Flatten walkable array
|
||||
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]);
|
||||
}
|
||||
}
|
||||
WalkableJson = JsonSerializer.Serialize(walkable);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback for V1 layouts
|
||||
MapWidth = 100;
|
||||
MapHeight = 100;
|
||||
WalkableJson = "[]";
|
||||
}
|
||||
|
||||
// Serialize entity positions
|
||||
PlayersJson = JsonSerializer.Serialize(
|
||||
Dungeon.Simulation.Players.Values.Select(p => new
|
||||
{
|
||||
name = p.CharacterName,
|
||||
x = p.X,
|
||||
y = p.Y,
|
||||
health = p.Health,
|
||||
maxHealth = p.MaxHealth
|
||||
})
|
||||
);
|
||||
|
||||
MobsJson = JsonSerializer.Serialize(
|
||||
Dungeon.Simulation.Mobs.Values.Select(m => new
|
||||
{
|
||||
name = m.Name,
|
||||
x = m.X,
|
||||
y = m.Y,
|
||||
alive = m.IsAlive,
|
||||
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public IActionResult OnGetStatus(Guid id)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon == null)
|
||||
return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
|
||||
|
||||
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
|
||||
{
|
||||
name = p.CharacterName,
|
||||
x = p.X,
|
||||
y = p.Y
|
||||
}),
|
||||
mobs = dungeon.Simulation.Mobs.Values.Where(m => m.IsAlive).Select(m => new
|
||||
{
|
||||
name = m.Name,
|
||||
x = m.X,
|
||||
y = m.Y,
|
||||
alive = m.IsAlive,
|
||||
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
TempData["Message"] = "All mobs killed.";
|
||||
}
|
||||
|
||||
return RedirectToPage(new { id });
|
||||
}
|
||||
|
||||
public IActionResult OnPostCompleteDungeon(Guid id)
|
||||
{
|
||||
var dungeon = _dungeonHandler.GetDungeon(id);
|
||||
if (dungeon != null)
|
||||
{
|
||||
dungeon.Simulation.ForceComplete();
|
||||
TempData["Message"] = "Dungeon marked as completed.";
|
||||
}
|
||||
|
||||
return RedirectToPage(new { id });
|
||||
}
|
||||
|
||||
public IActionResult OnPostDelete(Guid id)
|
||||
{
|
||||
var result = _dungeonHandler.ForceCloseDungeon(id);
|
||||
if (result)
|
||||
{
|
||||
TempData["Message"] = "Dungeon deleted.";
|
||||
}
|
||||
else
|
||||
{
|
||||
TempData["Error"] = "Failed to delete dungeon.";
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user