Admin Panel v6

This commit is contained in:
dingo
2025-12-25 13:11:34 -05:00
parent b2a1735358
commit 30b7d89a70
10 changed files with 1372 additions and 12 deletions
+18 -6
View File
@@ -281,15 +281,25 @@
@section Scripts {
<script>
const cdnBase = '@Model.CdnBaseUrl';
const cdnBase = '@Html.Raw(Model.CdnBaseUrl)';
function updatePreview() {
const path = document.getElementById('spritePath').value;
const img = document.getElementById('spritePreview');
const placeholder = document.getElementById('spritePlaceholder');
if (path) {
img.src = cdnBase + '/' + path;
placeholder.classList.add('hidden');
if (path && path.trim()) {
const fullUrl = cdnBase + '/' + path.trim();
console.log('Loading preview:', fullUrl);
img.onload = function() {
img.classList.remove('hidden');
placeholder.classList.add('hidden');
};
img.onerror = function() {
console.log('Failed to load:', fullUrl);
img.classList.add('hidden');
placeholder.classList.remove('hidden');
};
img.src = fullUrl;
} else {
img.classList.add('hidden');
placeholder.classList.remove('hidden');
@@ -304,7 +314,9 @@
}
// Init
updatePreview();
toggleMaxStack();
document.addEventListener('DOMContentLoaded', function() {
updatePreview();
toggleMaxStack();
});
</script>
}
+257
View File
@@ -0,0 +1,257 @@
@page "/admin/loottables/edit"
@model LootTables.EditModel
@{
ViewData["Title"] = Model.IsNew ? "Create Loot Table" : $"Edit: {Model.LootTable.Name}";
}
<div class="space-y-6 max-w-5xl">
<!-- Header -->
<div class="flex items-center gap-4">
<a href="/admin/loottables" class="p-2 hover:bg-gray-800 rounded-lg">
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
</a>
<div>
<h1 class="text-3xl font-bold text-white">@(Model.IsNew ? "Create Loot Table" : "Edit Loot Table")</h1>
<p class="text-gray-400 mt-1">@(Model.IsNew ? "Add a new loot table" : $"ID: {Model.LootTable.Id}")</p>
</div>
</div>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-200" : "bg-green-900/50 border border-green-700 text-green-200")">
@Model.Message
</div>
}
<form method="post" class="space-y-6">
@Html.AntiForgeryToken()
<input type="hidden" name="LootTable.Id" value="@Model.LootTable.Id" />
<!-- Basic Info -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Basic Information</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div class="lg:col-span-2">
<label class="label">Name *</label>
<input type="text" name="LootTable.Name" value="@Model.LootTable.Name" class="input" required maxlength="64" />
</div>
<div class="flex items-center gap-6 pt-6">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" name="LootTable.IsEnabled" value="true" checked="@Model.LootTable.IsEnabled" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
<span class="text-gray-300">Enabled</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" name="LootTable.GuaranteedDrop" value="true" checked="@Model.LootTable.GuaranteedDrop" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
<span class="text-gray-300">Guaranteed Drop</span>
</label>
</div>
<div class="lg:col-span-3">
<label class="label">Description</label>
<textarea name="LootTable.Description" class="input" rows="2" maxlength="256">@Model.LootTable.Description</textarea>
</div>
</div>
</div>
<!-- Drop Settings -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Drop Settings</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
<div>
<label class="label">Min Tier</label>
<input type="number" name="LootTable.MinTier" value="@Model.LootTable.MinTier" class="input" min="1" />
</div>
<div>
<label class="label">Max Tier</label>
<input type="number" name="LootTable.MaxTier" value="@Model.LootTable.MaxTier" class="input" min="1" />
</div>
<div>
<label class="label">Min Drops</label>
<input type="number" name="LootTable.MinDrops" value="@Model.LootTable.MinDrops" class="input" min="0" />
</div>
<div>
<label class="label">Max Drops</label>
<input type="number" name="LootTable.MaxDrops" value="@Model.LootTable.MaxDrops" class="input" min="1" />
</div>
<div>
<label class="label">Drop Chance Mult</label>
<input type="number" name="LootTable.DropChanceMultiplier" value="@Model.LootTable.DropChanceMultiplier" class="input" min="0" step="0.1" />
</div>
</div>
</div>
<!-- Save Loot Table First -->
<div class="flex items-center gap-4">
<button type="submit" class="btn btn-primary">@(Model.IsNew ? "Create Loot Table" : "Save Changes")</button>
<a href="/admin/loottables" class="btn btn-secondary">Cancel</a>
</div>
</form>
<!-- Entries Section - Only show for existing loot tables -->
@if (!Model.IsNew)
{
<div class="card">
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
<h2 class="text-lg font-semibold text-white">Loot Entries (@Model.Entries.Count)</h2>
<button type="button" onclick="showAddEntryModal()" class="btn btn-primary text-sm">+ Add Entry</button>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-900/50">
<tr>
<th class="table-header w-16">Icon</th>
<th class="table-header">Item</th>
<th class="table-header w-24">Chance</th>
<th class="table-header w-24">Qty</th>
<th class="table-header w-20">Weight</th>
<th class="table-header w-20">Guar.</th>
<th class="table-header w-20">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
@foreach (var entry in Model.Entries)
{
<tr class="hover:bg-gray-700/30">
<td class="table-cell">
@if (entry.ItemDefinition != null && !string.IsNullOrEmpty(entry.ItemDefinition.SpritePath))
{
<img src="@Model.CdnBaseUrl/@entry.ItemDefinition.SpritePath"
alt="@entry.ItemDefinition.Name"
class="w-8 h-8 object-contain bg-gray-900 rounded border border-gray-700"
onerror="this.style.display='none'" />
}
else
{
<div class="w-8 h-8 bg-gray-900 rounded border border-gray-700 flex items-center justify-center text-gray-600">
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
</svg>
</div>
}
</td>
<td class="table-cell">
<span class="font-medium text-white">@entry.ItemDefinition?.Name</span>
<span class="text-xs text-gray-500 ml-2">(ID: @entry.ItemDefinitionId)</span>
</td>
<td class="table-cell">
<span class="@(entry.DropChance >= 0.5 ? "text-green-400" : entry.DropChance >= 0.1 ? "text-yellow-400" : "text-red-400")">
@((entry.DropChance * 100).ToString("0.##"))%
</span>
</td>
<td class="table-cell text-gray-400">@entry.MinQuantity - @entry.MaxQuantity</td>
<td class="table-cell text-gray-400">@entry.Weight</td>
<td class="table-cell">
@if (entry.Guaranteed)
{
<span class="text-green-400">✓</span>
}
else
{
<span class="text-gray-600">-</span>
}
</td>
<td class="table-cell">
<form method="post" asp-page-handler="DeleteEntry" class="inline">
@Html.AntiForgeryToken()
<input type="hidden" name="entryId" value="@entry.Id" />
<input type="hidden" name="tableId" value="@Model.LootTable.Id" />
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-red-400" title="Remove" onclick="return confirm('Remove this entry?')">
<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>
</td>
</tr>
}
@if (!Model.Entries.Any())
{
<tr>
<td colspan="7" class="table-cell text-center text-gray-500 py-8">
No entries yet. Add items to this loot table.
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<!-- Add Entry Modal -->
<div id="addEntryModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-lg w-full mx-4 border border-gray-700">
<h3 class="text-lg font-semibold text-white mb-4">Add Loot Entry</h3>
<form method="post" asp-page-handler="AddEntry" class="space-y-4">
@Html.AntiForgeryToken()
<input type="hidden" name="tableId" value="@Model.LootTable.Id" />
<div>
<label class="label">Item *</label>
<select name="itemId" class="input" required>
<option value="">Select an item...</option>
@foreach (var item in Model.AllItems)
{
<option value="@item.Id">@item.Name (@item.Type - @item.Rarity)</option>
}
</select>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="label">Drop Chance (0-1)</label>
<input type="number" name="dropChance" value="0.1" class="input" min="0" max="1" step="0.01" />
</div>
<div>
<label class="label">Weight</label>
<input type="number" name="weight" value="100" class="input" min="1" />
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="label">Min Quantity</label>
<input type="number" name="minQty" value="1" class="input" min="1" />
</div>
<div>
<label class="label">Max Quantity</label>
<input type="number" name="maxQty" value="1" class="input" min="1" />
</div>
</div>
<div>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" name="guaranteed" value="true" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
<span class="text-gray-300">Guaranteed Drop</span>
</label>
</div>
<div class="flex justify-end gap-3 pt-4">
<button type="button" onclick="closeAddEntryModal()" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-primary">Add Entry</button>
</div>
</form>
</div>
</div>
}
</div>
@section Scripts {
<script>
function showAddEntryModal() {
document.getElementById('addEntryModal').classList.remove('hidden');
document.getElementById('addEntryModal').classList.add('flex');
}
function closeAddEntryModal() {
document.getElementById('addEntryModal').classList.add('hidden');
document.getElementById('addEntryModal').classList.remove('flex');
}
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeAddEntryModal(); });
</script>
}
@@ -0,0 +1,165 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Data.Entities;
namespace VoidScavengers.Services.Admin.Pages.LootTables;
public class EditModel : AdminPageModel
{
private readonly GameDbContext _db;
public EditModel(GameDbContext db)
{
_db = db;
}
[BindProperty]
public DungeonLootTable LootTable { get; set; } = new();
public List<DungeonLootTableEntry> Entries { get; set; } = new();
public List<DungeonItemDefinition> AllItems { get; set; } = new();
public bool IsNew => LootTable.Id == 0;
public string? Message { get; set; }
public bool IsError { get; set; }
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
public async Task OnGetAsync(int? id)
{
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
AllItems = await _db.DungeonItemDefinitions
.Where(i => i.IsEnabled)
.OrderBy(i => i.Name)
.ToListAsync();
if (id.HasValue)
{
var table = await _db.DungeonLootTables
.FirstOrDefaultAsync(t => t.Id == id.Value);
if (table != null)
{
LootTable = table;
Entries = await _db.DungeonLootTableEntries
.Include(e => e.ItemDefinition)
.Where(e => e.LootTableId == id.Value)
.OrderByDescending(e => e.Guaranteed)
.ThenByDescending(e => e.DropChance)
.ToListAsync();
}
}
else
{
// Defaults
LootTable.IsEnabled = true;
LootTable.MinTier = 1;
LootTable.MaxTier = 99;
LootTable.MinDrops = 1;
LootTable.MaxDrops = 3;
LootTable.DropChanceMultiplier = 1.0f;
}
}
public async Task<IActionResult> OnPostAsync()
{
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
AllItems = await _db.DungeonItemDefinitions.Where(i => i.IsEnabled).OrderBy(i => i.Name).ToListAsync();
// Handle checkbox binding
LootTable.IsEnabled = Request.Form.ContainsKey("LootTable.IsEnabled");
LootTable.GuaranteedDrop = Request.Form.ContainsKey("LootTable.GuaranteedDrop");
if (string.IsNullOrWhiteSpace(LootTable.Name))
{
Message = "Name is required.";
IsError = true;
return Page();
}
try
{
if (LootTable.Id == 0)
{
_db.DungeonLootTables.Add(LootTable);
await _db.SaveChangesAsync();
Message = $"Loot table '{LootTable.Name}' created. Now add entries below.";
return RedirectToPage("/LootTables/Edit", new { id = LootTable.Id });
}
else
{
var existing = await _db.DungeonLootTables.FindAsync(LootTable.Id);
if (existing == null)
{
Message = "Loot table not found.";
IsError = true;
return Page();
}
existing.Name = LootTable.Name;
existing.Description = LootTable.Description;
existing.MinTier = LootTable.MinTier;
existing.MaxTier = LootTable.MaxTier;
existing.MinDrops = LootTable.MinDrops;
existing.MaxDrops = LootTable.MaxDrops;
existing.DropChanceMultiplier = LootTable.DropChanceMultiplier;
existing.GuaranteedDrop = LootTable.GuaranteedDrop;
existing.IsEnabled = LootTable.IsEnabled;
await _db.SaveChangesAsync();
LootTable = existing;
Entries = await _db.DungeonLootTableEntries
.Include(e => e.ItemDefinition)
.Where(e => e.LootTableId == LootTable.Id)
.OrderByDescending(e => e.Guaranteed)
.ThenByDescending(e => e.DropChance)
.ToListAsync();
Message = "Changes saved successfully.";
}
}
catch (Exception ex)
{
Message = $"Error: {ex.Message}";
IsError = true;
}
return Page();
}
public async Task<IActionResult> OnPostAddEntryAsync(int tableId, int itemId, float dropChance, int weight, int minQty, int maxQty, bool guaranteed)
{
var entry = new DungeonLootTableEntry
{
LootTableId = tableId,
ItemDefinitionId = itemId,
DropChance = dropChance,
Weight = weight,
MinQuantity = minQty,
MaxQuantity = maxQty,
Guaranteed = guaranteed
};
_db.DungeonLootTableEntries.Add(entry);
await _db.SaveChangesAsync();
return RedirectToPage("/LootTables/Edit", new { id = tableId });
}
public async Task<IActionResult> OnPostDeleteEntryAsync(int entryId, int tableId)
{
var entry = await _db.DungeonLootTableEntries.FindAsync(entryId);
if (entry != null)
{
_db.DungeonLootTableEntries.Remove(entry);
await _db.SaveChangesAsync();
}
return RedirectToPage("/LootTables/Edit", new { id = tableId });
}
}
@@ -0,0 +1,140 @@
@page "/admin/loottables"
@model LootTables.IndexModel
@{
ViewData["Title"] = "Loot Tables";
}
<div class="space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Loot Tables</h1>
<p class="text-gray-400 mt-1">Manage loot table definitions</p>
</div>
<a href="/admin/loottables/edit" class="btn btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Create Loot Table
</a>
</div>
<!-- Filters -->
<div class="card p-4">
<form method="get" class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<label class="label">Search</label>
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Search by name..." />
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/loottables" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Loot Tables List -->
<div class="card overflow-hidden">
<table class="w-full">
<thead class="bg-gray-900/50">
<tr>
<th class="table-header w-16">ID</th>
<th class="table-header">Name</th>
<th class="table-header w-24">Tier</th>
<th class="table-header w-24">Drops</th>
<th class="table-header w-24">Entries</th>
<th class="table-header w-20">Enabled</th>
<th class="table-header w-24">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
@foreach (var table in Model.LootTables)
{
<tr class="hover:bg-gray-700/30">
<td class="table-cell font-mono text-gray-500">@table.Id</td>
<td class="table-cell">
<span class="font-medium text-white">@table.Name</span>
@if (!string.IsNullOrEmpty(table.Description))
{
<p class="text-xs text-gray-500 truncate max-w-xs">@table.Description</p>
}
</td>
<td class="table-cell">
<span class="text-gray-400">@table.MinTier - @table.MaxTier</span>
</td>
<td class="table-cell">
<span class="text-gray-400">@table.MinDrops - @table.MaxDrops</span>
@if (table.GuaranteedDrop)
{
<span class="ml-1 text-green-400 text-xs">✓</span>
}
</td>
<td class="table-cell">
<span class="badge badge-common">@table.Entries.Count</span>
</td>
<td class="table-cell">
@if (table.IsEnabled)
{
<span class="w-3 h-3 bg-green-500 rounded-full inline-block" title="Enabled"></span>
}
else
{
<span class="w-3 h-3 bg-red-500 rounded-full inline-block" title="Disabled"></span>
}
</td>
<td class="table-cell">
<div class="flex items-center gap-1">
<a href="/admin/loottables/edit?id=@table.Id" class="p-1.5 hover:bg-gray-700 rounded" title="Edit">
<svg class="w-4 h-4 text-indigo-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
</a>
<button type="button" onclick="confirmDelete(@table.Id, '@table.Name.Replace("'", "\\'"))" class="p-1.5 hover:bg-gray-700 rounded" title="Delete">
<svg class="w-4 h-4 text-red-400" 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>
</div>
</td>
</tr>
}
@if (!Model.LootTables.Any())
{
<tr>
<td colspan="7" class="table-cell text-center text-gray-500 py-12">
No loot tables found. <a href="/admin/loottables/edit" class="text-indigo-400 hover:underline">Create one?</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<!-- Delete Modal -->
<div id="deleteModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-md w-full mx-4 border border-gray-700">
<h3 class="text-lg font-semibold text-white mb-2">Delete Loot Table</h3>
<p class="text-gray-400 mb-4">Are you sure you want to delete "<span id="deleteItemName" class="text-white"></span>"? All entries will be deleted.</p>
<form method="post" asp-page-handler="Delete" class="flex justify-end gap-3">
@Html.AntiForgeryToken()
<input type="hidden" name="id" id="deleteItemId" />
<button type="button" onclick="closeDeleteModal()" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</div>
</div>
@section Scripts {
<script>
function confirmDelete(id, name) {
document.getElementById('deleteItemId').value = id;
document.getElementById('deleteItemName').textContent = name;
document.getElementById('deleteModal').classList.remove('hidden');
document.getElementById('deleteModal').classList.add('flex');
}
function closeDeleteModal() {
document.getElementById('deleteModal').classList.add('hidden');
document.getElementById('deleteModal').classList.remove('flex');
}
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeDeleteModal(); });
</script>
}
@@ -0,0 +1,51 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Data.Entities;
namespace VoidScavengers.Services.Admin.Pages.LootTables;
public class IndexModel : AdminPageModel
{
private readonly GameDbContext _db;
public IndexModel(GameDbContext db)
{
_db = db;
}
public List<DungeonLootTable> LootTables { get; set; } = new();
public string? Search { get; set; }
public async Task OnGetAsync(string? search)
{
Search = search;
var query = _db.DungeonLootTables
.Include(t => t.Entries)
.AsQueryable();
if (!string.IsNullOrWhiteSpace(search))
query = query.Where(t => t.Name.Contains(search) || t.Description.Contains(search));
LootTables = await query
.OrderBy(t => t.Id)
.ToListAsync();
}
public async Task<IActionResult> OnPostDeleteAsync(int id)
{
var table = await _db.DungeonLootTables
.Include(t => t.Entries)
.FirstOrDefaultAsync(t => t.Id == id);
if (table != null)
{
// Delete all entries first
_db.DungeonLootTableEntries.RemoveRange(table.Entries);
_db.DungeonLootTables.Remove(table);
await _db.SaveChangesAsync();
}
return RedirectToPage();
}
}
+334
View File
@@ -0,0 +1,334 @@
@page "/admin/mobs/edit"
@model Mobs.EditModel
@using Server.Data.Enums
@{
ViewData["Title"] = Model.IsNew ? "Create Mob" : $"Edit: {Model.Mob.Name}";
}
<div class="space-y-6 max-w-5xl">
<!-- Header -->
<div class="flex items-center gap-4">
<a href="/admin/mobs" class="p-2 hover:bg-gray-800 rounded-lg">
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
</a>
<div>
<h1 class="text-3xl font-bold text-white">@(Model.IsNew ? "Create Mob" : "Edit Mob")</h1>
<p class="text-gray-400 mt-1">@(Model.IsNew ? "Add a new mob definition" : $"ID: {Model.Mob.Id}")</p>
</div>
</div>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-200" : "bg-green-900/50 border border-green-700 text-green-200")">
@Model.Message
</div>
}
<form method="post" class="space-y-6">
@Html.AntiForgeryToken()
<input type="hidden" name="Mob.Id" value="@Model.Mob.Id" />
<!-- Basic Info -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Basic Information</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div class="lg:col-span-2">
<label class="label">Name *</label>
<input type="text" name="Mob.Name" value="@Model.Mob.Name" class="input" required maxlength="64" />
</div>
<div>
<label class="label">Type</label>
<select name="Mob.Type" class="input">
@foreach (var t in Enum.GetValues<MobType>())
{
<option value="@t" selected="@(Model.Mob.Type == t)">@t</option>
}
</select>
</div>
<div>
<label class="label">Category</label>
<select name="Mob.Category" class="input">
@foreach (var c in Enum.GetValues<MobCategory>())
{
<option value="@c" selected="@(Model.Mob.Category == c)">@c</option>
}
</select>
</div>
<div class="lg:col-span-4">
<label class="label">Description</label>
<textarea name="Mob.Description" class="input" rows="2" maxlength="256">@Model.Mob.Description</textarea>
</div>
<div>
<label class="label">Min Tier</label>
<input type="number" name="Mob.MinTier" value="@Model.Mob.MinTier" class="input" min="1" />
</div>
<div>
<label class="label">Max Tier</label>
<input type="number" name="Mob.MaxTier" value="@Model.Mob.MaxTier" class="input" min="1" />
</div>
<div class="flex items-center pt-6">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" name="Mob.IsEnabled" value="true" checked="@Model.Mob.IsEnabled" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
<span class="text-gray-300">Enabled</span>
</label>
</div>
</div>
</div>
<!-- Combat Stats -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Base Combat Stats</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4">
<div>
<label class="label">Health</label>
<input type="number" name="Mob.BaseHealth" value="@Model.Mob.BaseHealth" class="input" min="1" />
</div>
<div>
<label class="label">Mana</label>
<input type="number" name="Mob.BaseMana" value="@Model.Mob.BaseMana" class="input" min="0" />
</div>
<div>
<label class="label">Phys Damage</label>
<input type="number" name="Mob.BasePhysicalDamage" value="@Model.Mob.BasePhysicalDamage" class="input" min="0" />
</div>
<div>
<label class="label">Magic Damage</label>
<input type="number" name="Mob.BaseMagicDamage" value="@Model.Mob.BaseMagicDamage" class="input" min="0" />
</div>
<div>
<label class="label">Armor</label>
<input type="number" name="Mob.BaseArmor" value="@Model.Mob.BaseArmor" class="input" min="0" />
</div>
<div>
<label class="label">Magic Resist</label>
<input type="number" name="Mob.BaseMagicResist" value="@Model.Mob.BaseMagicResist" class="input" min="0" />
</div>
</div>
</div>
<!-- Movement & Behavior -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Movement & Behavior</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
<div>
<label class="label">Move Speed</label>
<input type="number" name="Mob.MoveSpeed" value="@Model.Mob.MoveSpeed" class="input" min="0" step="1" />
</div>
<div>
<label class="label">Attack Range</label>
<input type="number" name="Mob.AttackRange" value="@Model.Mob.AttackRange" class="input" min="0" step="1" />
</div>
<div>
<label class="label">Attack Speed</label>
<input type="number" name="Mob.AttackSpeed" value="@Model.Mob.AttackSpeed" class="input" min="0.1" step="0.1" />
</div>
<div>
<label class="label">Aggro Range</label>
<input type="number" name="Mob.AggroRange" value="@Model.Mob.AggroRange" class="input" min="0" step="1" />
</div>
<div>
<label class="label">Leash Range</label>
<input type="number" name="Mob.LeashRange" value="@Model.Mob.LeashRange" class="input" min="0" step="1" />
</div>
</div>
</div>
<!-- Scaling -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Tier Scaling (Multipliers)</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
<div>
<label class="label">Health/Tier</label>
<input type="number" name="Mob.HealthPerTier" value="@Model.Mob.HealthPerTier" class="input" min="1" step="0.05" />
</div>
<div>
<label class="label">Damage/Tier</label>
<input type="number" name="Mob.DamagePerTier" value="@Model.Mob.DamagePerTier" class="input" min="1" step="0.05" />
</div>
<div>
<label class="label">Armor/Tier</label>
<input type="number" name="Mob.ArmorPerTier" value="@Model.Mob.ArmorPerTier" class="input" min="1" step="0.05" />
</div>
<div>
<label class="label">Base XP</label>
<input type="number" name="Mob.BaseXp" value="@Model.Mob.BaseXp" class="input" min="0" />
</div>
<div>
<label class="label">XP/Tier</label>
<input type="number" name="Mob.XpPerTier" value="@Model.Mob.XpPerTier" class="input" min="1" step="0.05" />
</div>
</div>
</div>
<!-- Visual -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Visual</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="label">Tint Color</label>
<div class="flex gap-2">
<input type="color" value="@Model.Mob.TintColor" class="w-10 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer" oninput="document.getElementById('tintColor').value=this.value" />
<input type="text" id="tintColor" name="Mob.TintColor" value="@Model.Mob.TintColor" class="input flex-1" />
</div>
</div>
<div>
<label class="label">Scale</label>
<input type="number" name="Mob.Scale" value="@Model.Mob.Scale" class="input" min="0.1" step="0.1" />
</div>
<div>
<label class="label">Animation Speed</label>
<input type="number" name="Mob.AnimationSpeed" value="@Model.Mob.AnimationSpeed" class="input" min="1" />
</div>
<div class="md:col-span-3">
<label class="label">Sprite Config JSON</label>
<textarea name="Mob.SpriteConfigJson" class="input font-mono text-sm" rows="4" placeholder='{"sprites":{"idle_front":"path.png"},"frameWidth":64,"frameHeight":64}'>@Model.Mob.SpriteConfigJson</textarea>
</div>
</div>
</div>
<!-- Save -->
<div class="flex items-center gap-4">
<button type="submit" class="btn btn-primary">@(Model.IsNew ? "Create Mob" : "Save Changes")</button>
<a href="/admin/mobs" class="btn btn-secondary">Cancel</a>
@if (!Model.IsNew)
{
<div class="flex-1"></div>
<button type="submit" name="action" value="duplicate" class="btn btn-secondary">Duplicate</button>
}
</div>
</form>
<!-- Loot Tables Section -->
@if (!Model.IsNew)
{
<div class="card">
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
<h2 class="text-lg font-semibold text-white">Loot Tables (@Model.MobLootTables.Count)</h2>
<button type="button" onclick="showAddLootModal()" class="btn btn-primary text-sm">+ Assign Loot Table</button>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-900/50">
<tr>
<th class="table-header">Loot Table</th>
<th class="table-header w-24">Priority</th>
<th class="table-header w-24">Roll %</th>
<th class="table-header w-24">Entries</th>
<th class="table-header w-20">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
@foreach (var mlt in Model.MobLootTables)
{
<tr class="hover:bg-gray-700/30">
<td class="table-cell">
<a href="/admin/loottables/edit?id=@mlt.LootTableId" class="text-indigo-400 hover:underline">
@mlt.LootTable?.Name
</a>
<span class="text-xs text-gray-500 ml-2">(ID: @mlt.LootTableId)</span>
</td>
<td class="table-cell text-gray-400">@mlt.Priority</td>
<td class="table-cell">
<span class="@(mlt.RollChance >= 0.5 ? "text-green-400" : "text-yellow-400")">
@((mlt.RollChance * 100).ToString("0"))%
</span>
</td>
<td class="table-cell">
<span class="badge badge-common">@(mlt.LootTable?.Entries?.Count ?? 0)</span>
</td>
<td class="table-cell">
<form method="post" asp-page-handler="RemoveLoot" class="inline">
@Html.AntiForgeryToken()
<input type="hidden" name="mappingId" value="@mlt.Id" />
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-red-400" title="Remove" onclick="return confirm('Remove this loot table?')">
<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>
</td>
</tr>
}
@if (!Model.MobLootTables.Any())
{
<tr>
<td colspan="5" class="table-cell text-center text-gray-500 py-8">
No loot tables assigned. This mob won't drop items.
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<!-- Add Loot Table Modal -->
<div id="addLootModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-lg w-full mx-4 border border-gray-700">
<h3 class="text-lg font-semibold text-white mb-4">Assign Loot Table</h3>
<form method="post" asp-page-handler="AddLoot" class="space-y-4">
@Html.AntiForgeryToken()
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
<div>
<label class="label">Loot Table *</label>
<select name="lootTableId" class="input" required>
<option value="">Select a loot table...</option>
@foreach (var lt in Model.AllLootTables)
{
<option value="@lt.Id">@lt.Name (Tier @lt.MinTier-@lt.MaxTier)</option>
}
</select>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="label">Priority (lower = first)</label>
<input type="number" name="priority" value="0" class="input" min="0" />
</div>
<div>
<label class="label">Roll Chance (0-1)</label>
<input type="number" name="rollChance" value="1.0" class="input" min="0" max="1" step="0.1" />
</div>
</div>
<div class="flex justify-end gap-3 pt-4">
<button type="button" onclick="closeAddLootModal()" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-primary">Assign</button>
</div>
</form>
</div>
</div>
}
</div>
@section Scripts {
<script>
function showAddLootModal() {
document.getElementById('addLootModal').classList.remove('hidden');
document.getElementById('addLootModal').classList.add('flex');
}
function closeAddLootModal() {
document.getElementById('addLootModal').classList.add('hidden');
document.getElementById('addLootModal').classList.remove('flex');
}
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeAddLootModal(); });
</script>
}
+221
View File
@@ -0,0 +1,221 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Data.Entities;
namespace VoidScavengers.Services.Admin.Pages.Mobs;
public class EditModel : AdminPageModel
{
private readonly GameDbContext _db;
public EditModel(GameDbContext db)
{
_db = db;
}
[BindProperty]
public DungeonMobDefinition Mob { get; set; } = new();
public List<DungeonMobLootTable> MobLootTables { get; set; } = new();
public List<DungeonLootTable> AllLootTables { get; set; } = new();
public bool IsNew => Mob.Id == 0;
public string? Message { get; set; }
public bool IsError { get; set; }
public async Task OnGetAsync(int? id)
{
AllLootTables = await _db.DungeonLootTables
.Where(t => t.IsEnabled)
.OrderBy(t => t.Name)
.ToListAsync();
if (id.HasValue)
{
var mob = await _db.DungeonMobDefinitions.FindAsync(id.Value);
if (mob != null)
{
Mob = mob;
MobLootTables = await _db.DungeonMobLootTables
.Include(m => m.LootTable)
.ThenInclude(t => t!.Entries)
.Where(m => m.MobDefinitionId == id.Value)
.OrderBy(m => m.Priority)
.ToListAsync();
}
}
else
{
// Defaults
Mob.IsEnabled = true;
Mob.MinTier = 1;
Mob.MaxTier = 99;
Mob.BaseHealth = 50;
Mob.BasePhysicalDamage = 5;
Mob.MoveSpeed = 60f;
Mob.AttackRange = 40f;
Mob.AttackSpeed = 1.0f;
Mob.AggroRange = 150f;
Mob.LeashRange = 400f;
Mob.HealthPerTier = 1.2f;
Mob.DamagePerTier = 1.15f;
Mob.ArmorPerTier = 1.1f;
Mob.BaseXp = 10;
Mob.XpPerTier = 1.25f;
Mob.TintColor = "#ffffff";
Mob.Scale = 1.0f;
Mob.AnimationSpeed = 8f;
}
}
public async Task<IActionResult> OnPostAsync(string? action)
{
AllLootTables = await _db.DungeonLootTables.Where(t => t.IsEnabled).OrderBy(t => t.Name).ToListAsync();
// Handle checkbox binding
Mob.IsEnabled = Request.Form.ContainsKey("Mob.IsEnabled");
if (string.IsNullOrWhiteSpace(Mob.Name))
{
Message = "Name is required.";
IsError = true;
return Page();
}
try
{
if (action == "duplicate")
{
var newMob = new DungeonMobDefinition
{
Name = Mob.Name + " (Copy)",
Description = Mob.Description,
Type = Mob.Type,
Category = Mob.Category,
MinTier = Mob.MinTier,
MaxTier = Mob.MaxTier,
BaseHealth = Mob.BaseHealth,
BaseMana = Mob.BaseMana,
BasePhysicalDamage = Mob.BasePhysicalDamage,
BaseMagicDamage = Mob.BaseMagicDamage,
BaseArmor = Mob.BaseArmor,
BaseMagicResist = Mob.BaseMagicResist,
MoveSpeed = Mob.MoveSpeed,
AttackRange = Mob.AttackRange,
AttackSpeed = Mob.AttackSpeed,
AggroRange = Mob.AggroRange,
LeashRange = Mob.LeashRange,
HealthPerTier = Mob.HealthPerTier,
DamagePerTier = Mob.DamagePerTier,
ArmorPerTier = Mob.ArmorPerTier,
BaseXp = Mob.BaseXp,
XpPerTier = Mob.XpPerTier,
TintColor = Mob.TintColor,
Scale = Mob.Scale,
AnimationSpeed = Mob.AnimationSpeed,
SpriteConfigJson = Mob.SpriteConfigJson,
ResistancesJson = Mob.ResistancesJson,
AbilitiesJson = Mob.AbilitiesJson,
IsEnabled = Mob.IsEnabled
};
_db.DungeonMobDefinitions.Add(newMob);
await _db.SaveChangesAsync();
return RedirectToPage("/Mobs/Edit", new { id = newMob.Id });
}
if (Mob.Id == 0)
{
_db.DungeonMobDefinitions.Add(Mob);
await _db.SaveChangesAsync();
Message = $"Mob '{Mob.Name}' created. Now assign loot tables below.";
return RedirectToPage("/Mobs/Edit", new { id = Mob.Id });
}
else
{
var existing = await _db.DungeonMobDefinitions.FindAsync(Mob.Id);
if (existing == null)
{
Message = "Mob not found.";
IsError = true;
return Page();
}
existing.Name = Mob.Name;
existing.Description = Mob.Description;
existing.Type = Mob.Type;
existing.Category = Mob.Category;
existing.MinTier = Mob.MinTier;
existing.MaxTier = Mob.MaxTier;
existing.BaseHealth = Mob.BaseHealth;
existing.BaseMana = Mob.BaseMana;
existing.BasePhysicalDamage = Mob.BasePhysicalDamage;
existing.BaseMagicDamage = Mob.BaseMagicDamage;
existing.BaseArmor = Mob.BaseArmor;
existing.BaseMagicResist = Mob.BaseMagicResist;
existing.MoveSpeed = Mob.MoveSpeed;
existing.AttackRange = Mob.AttackRange;
existing.AttackSpeed = Mob.AttackSpeed;
existing.AggroRange = Mob.AggroRange;
existing.LeashRange = Mob.LeashRange;
existing.HealthPerTier = Mob.HealthPerTier;
existing.DamagePerTier = Mob.DamagePerTier;
existing.ArmorPerTier = Mob.ArmorPerTier;
existing.BaseXp = Mob.BaseXp;
existing.XpPerTier = Mob.XpPerTier;
existing.TintColor = Mob.TintColor;
existing.Scale = Mob.Scale;
existing.AnimationSpeed = Mob.AnimationSpeed;
existing.SpriteConfigJson = Mob.SpriteConfigJson;
existing.IsEnabled = Mob.IsEnabled;
await _db.SaveChangesAsync();
Mob = existing;
MobLootTables = await _db.DungeonMobLootTables
.Include(m => m.LootTable)
.ThenInclude(t => t!.Entries)
.Where(m => m.MobDefinitionId == Mob.Id)
.OrderBy(m => m.Priority)
.ToListAsync();
Message = "Changes saved successfully.";
}
}
catch (Exception ex)
{
Message = $"Error: {ex.Message}";
IsError = true;
}
return Page();
}
public async Task<IActionResult> OnPostAddLootAsync(int mobId, int lootTableId, int priority, float rollChance)
{
var mapping = new DungeonMobLootTable
{
MobDefinitionId = mobId,
LootTableId = lootTableId,
Priority = priority,
RollChance = rollChance
};
_db.DungeonMobLootTables.Add(mapping);
await _db.SaveChangesAsync();
return RedirectToPage("/Mobs/Edit", new { id = mobId });
}
public async Task<IActionResult> OnPostRemoveLootAsync(int mappingId, int mobId)
{
var mapping = await _db.DungeonMobLootTables.FindAsync(mappingId);
if (mapping != null)
{
_db.DungeonMobLootTables.Remove(mapping);
await _db.SaveChangesAsync();
}
return RedirectToPage("/Mobs/Edit", new { id = mobId });
}
}
+138 -3
View File
@@ -1,14 +1,16 @@
@page "/admin/mobs"
@model Mobs.IndexModel
@using Server.Data.Enums
@{
ViewData["Title"] = "Mobs";
}
<div class="space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Mobs</h1>
<p class="text-gray-400 mt-1">Manage mob definitions (@Model.MobCount total)</p>
<p class="text-gray-400 mt-1">Manage mob definitions</p>
</div>
<a href="/admin/mobs/edit" class="btn btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -18,7 +20,140 @@
</a>
</div>
<div class="card p-8 text-center">
<p class="text-gray-400">Mob editor coming soon...</p>
<!-- Filters -->
<div class="card p-4">
<form method="get" class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<label class="label">Search</label>
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Search by name..." />
</div>
<div class="w-40">
<label class="label">Type</label>
<select name="type" class="input">
<option value="">All Types</option>
@foreach (var t in Enum.GetValues<MobType>())
{
<option value="@t" selected="@(Model.TypeFilter == t)">@t</option>
}
</select>
</div>
<div class="w-40">
<label class="label">Category</label>
<select name="category" class="input">
<option value="">All Categories</option>
@foreach (var c in Enum.GetValues<MobCategory>())
{
<option value="@c" selected="@(Model.CategoryFilter == c)">@c</option>
}
</select>
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/mobs" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Mobs Table -->
<div class="card overflow-hidden">
<table class="w-full">
<thead class="bg-gray-900/50">
<tr>
<th class="table-header w-16">ID</th>
<th class="table-header">Name</th>
<th class="table-header w-24">Type</th>
<th class="table-header w-28">Category</th>
<th class="table-header w-24">Tier</th>
<th class="table-header w-20">HP</th>
<th class="table-header w-20">DMG</th>
<th class="table-header w-20">Enabled</th>
<th class="table-header w-24">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
@foreach (var mob in Model.Mobs)
{
<tr class="hover:bg-gray-700/30">
<td class="table-cell font-mono text-gray-500">@mob.Id</td>
<td class="table-cell">
<span class="font-medium text-white">@mob.Name</span>
@if (!string.IsNullOrEmpty(mob.Description))
{
<p class="text-xs text-gray-500 truncate max-w-xs">@mob.Description</p>
}
</td>
<td class="table-cell">
<span class="badge @(mob.Type == MobType.Boss ? "badge-legendary" : mob.Type == MobType.Elite ? "badge-epic" : "badge-common")">
@mob.Type
</span>
</td>
<td class="table-cell text-gray-400">@mob.Category</td>
<td class="table-cell text-gray-400">@mob.MinTier - @mob.MaxTier</td>
<td class="table-cell text-green-400">@mob.BaseHealth</td>
<td class="table-cell text-red-400">@mob.BasePhysicalDamage</td>
<td class="table-cell">
@if (mob.IsEnabled)
{
<span class="w-3 h-3 bg-green-500 rounded-full inline-block" title="Enabled"></span>
}
else
{
<span class="w-3 h-3 bg-red-500 rounded-full inline-block" title="Disabled"></span>
}
</td>
<td class="table-cell">
<div class="flex items-center gap-1">
<a href="/admin/mobs/edit?id=@mob.Id" class="p-1.5 hover:bg-gray-700 rounded" title="Edit">
<svg class="w-4 h-4 text-indigo-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
</a>
<button type="button" onclick="confirmDelete(@mob.Id, '@mob.Name.Replace("'", "\\'"))" class="p-1.5 hover:bg-gray-700 rounded" title="Delete">
<svg class="w-4 h-4 text-red-400" 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>
</div>
</td>
</tr>
}
@if (!Model.Mobs.Any())
{
<tr>
<td colspan="9" class="table-cell text-center text-gray-500 py-12">
No mobs found. <a href="/admin/mobs/edit" class="text-indigo-400 hover:underline">Create one?</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<!-- Delete Modal -->
<div id="deleteModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-md w-full mx-4 border border-gray-700">
<h3 class="text-lg font-semibold text-white mb-2">Delete Mob</h3>
<p class="text-gray-400 mb-4">Are you sure you want to delete "<span id="deleteItemName" class="text-white"></span>"?</p>
<form method="post" asp-page-handler="Delete" class="flex justify-end gap-3">
@Html.AntiForgeryToken()
<input type="hidden" name="id" id="deleteItemId" />
<button type="button" onclick="closeDeleteModal()" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</div>
</div>
@section Scripts {
<script>
function confirmDelete(id, name) {
document.getElementById('deleteItemId').value = id;
document.getElementById('deleteItemName').textContent = name;
document.getElementById('deleteModal').classList.remove('hidden');
document.getElementById('deleteModal').classList.add('flex');
}
function closeDeleteModal() {
document.getElementById('deleteModal').classList.add('hidden');
document.getElementById('deleteModal').classList.remove('flex');
}
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeDeleteModal(); });
</script>
}
+41 -3
View File
@@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Data.Entities;
using Server.Data.Enums;
namespace VoidScavengers.Services.Admin.Pages.Mobs;
@@ -12,10 +15,45 @@ public class IndexModel : AdminPageModel
_db = db;
}
public int MobCount { get; set; }
public List<DungeonMobDefinition> Mobs { get; set; } = new();
public string? Search { get; set; }
public MobType? TypeFilter { get; set; }
public MobCategory? CategoryFilter { get; set; }
public async Task OnGetAsync()
public async Task OnGetAsync(string? search, MobType? type, MobCategory? category)
{
MobCount = await _db.DungeonMobDefinitions.CountAsync();
Search = search;
TypeFilter = type;
CategoryFilter = category;
var query = _db.DungeonMobDefinitions.AsQueryable();
if (!string.IsNullOrWhiteSpace(search))
query = query.Where(m => m.Name.Contains(search) || m.Description.Contains(search));
if (type.HasValue)
query = query.Where(m => m.Type == type.Value);
if (category.HasValue)
query = query.Where(m => m.Category == category.Value);
Mobs = await query
.OrderBy(m => m.Id)
.ToListAsync();
}
public async Task<IActionResult> OnPostDeleteAsync(int id)
{
var mob = await _db.DungeonMobDefinitions.FindAsync(id);
if (mob != null)
{
// Also delete loot table mappings
var mappings = await _db.DungeonMobLootTables.Where(m => m.MobDefinitionId == id).ToListAsync();
_db.DungeonMobLootTables.RemoveRange(mappings);
_db.DungeonMobDefinitions.Remove(mob);
await _db.SaveChangesAsync();
}
return RedirectToPage();
}
}
@@ -104,6 +104,13 @@
CDN Assets
</a>
<a href="/admin/loottables" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/LootTables") == true ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Loot Tables
</a>
<div class="pt-4">
<p class="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Management</p>
</div>