From 30b7d89a70d7c32f220fe6e7da232974e5407edf Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 25 Dec 2025 13:11:34 -0500 Subject: [PATCH] Admin Panel v6 --- Services/Admin/Pages/Items/Edit.cshtml | 24 +- Services/Admin/Pages/LootTables/Edit.cshtml | 257 ++++++++++++++ .../Admin/Pages/LootTables/Edit.cshtml.cs | 165 +++++++++ Services/Admin/Pages/LootTables/Index.cshtml | 140 ++++++++ .../Admin/Pages/LootTables/Index.cshtml.cs | 51 +++ Services/Admin/Pages/Mobs/Edit.cshtml | 334 ++++++++++++++++++ Services/Admin/Pages/Mobs/Edit.cshtml.cs | 221 ++++++++++++ Services/Admin/Pages/Mobs/Index.cshtml | 141 +++++++- Services/Admin/Pages/Mobs/Index.cshtml.cs | 44 ++- Services/Admin/Pages/Shared/_Layout.cshtml | 7 + 10 files changed, 1372 insertions(+), 12 deletions(-) create mode 100644 Services/Admin/Pages/LootTables/Edit.cshtml create mode 100644 Services/Admin/Pages/LootTables/Edit.cshtml.cs create mode 100644 Services/Admin/Pages/LootTables/Index.cshtml create mode 100644 Services/Admin/Pages/LootTables/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Mobs/Edit.cshtml create mode 100644 Services/Admin/Pages/Mobs/Edit.cshtml.cs diff --git a/Services/Admin/Pages/Items/Edit.cshtml b/Services/Admin/Pages/Items/Edit.cshtml index 11a38bc..89b43ee 100644 --- a/Services/Admin/Pages/Items/Edit.cshtml +++ b/Services/Admin/Pages/Items/Edit.cshtml @@ -281,15 +281,25 @@ @section Scripts { } diff --git a/Services/Admin/Pages/LootTables/Edit.cshtml b/Services/Admin/Pages/LootTables/Edit.cshtml new file mode 100644 index 0000000..062db5f --- /dev/null +++ b/Services/Admin/Pages/LootTables/Edit.cshtml @@ -0,0 +1,257 @@ +@page "/admin/loottables/edit" +@model LootTables.EditModel +@{ + ViewData["Title"] = Model.IsNew ? "Create Loot Table" : $"Edit: {Model.LootTable.Name}"; +} + +
+ +
+ + + + + +
+

@(Model.IsNew ? "Create Loot Table" : "Edit Loot Table")

+

@(Model.IsNew ? "Add a new loot table" : $"ID: {Model.LootTable.Id}")

+
+
+ + @if (!string.IsNullOrEmpty(Model.Message)) + { +
+ @Model.Message +
+ } + +
+ @Html.AntiForgeryToken() + + + +
+
+

Basic Information

+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + +
+
+

Drop Settings

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ + Cancel +
+
+ + + @if (!Model.IsNew) + { +
+
+

Loot Entries (@Model.Entries.Count)

+ +
+
+ + + + + + + + + + + + + + @foreach (var entry in Model.Entries) + { + + + + + + + + + + } + @if (!Model.Entries.Any()) + { + + + + } + +
IconItemChanceQtyWeightGuar.Actions
+ @if (entry.ItemDefinition != null && !string.IsNullOrEmpty(entry.ItemDefinition.SpritePath)) + { + @entry.ItemDefinition.Name + } + else + { +
+ + + +
+ } +
+ @entry.ItemDefinition?.Name + (ID: @entry.ItemDefinitionId) + + = 0.1 ? "text-yellow-400" : "text-red-400")"> + @((entry.DropChance * 100).ToString("0.##"))% + + @entry.MinQuantity - @entry.MaxQuantity@entry.Weight + @if (entry.Guaranteed) + { + ✓ + } + else + { + - + } + +
+ @Html.AntiForgeryToken() + + + +
+
+ No entries yet. Add items to this loot table. +
+
+
+ + + + } +
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/LootTables/Edit.cshtml.cs b/Services/Admin/Pages/LootTables/Edit.cshtml.cs new file mode 100644 index 0000000..5bfd6c5 --- /dev/null +++ b/Services/Admin/Pages/LootTables/Edit.cshtml.cs @@ -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 Entries { get; set; } = new(); + public List 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 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 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 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 }); + } +} diff --git a/Services/Admin/Pages/LootTables/Index.cshtml b/Services/Admin/Pages/LootTables/Index.cshtml new file mode 100644 index 0000000..94842fa --- /dev/null +++ b/Services/Admin/Pages/LootTables/Index.cshtml @@ -0,0 +1,140 @@ +@page "/admin/loottables" +@model LootTables.IndexModel +@{ + ViewData["Title"] = "Loot Tables"; +} + +
+ +
+
+

Loot Tables

+

Manage loot table definitions

+
+ + + + + Create Loot Table + +
+ + +
+
+
+ + +
+ + Clear +
+
+ + +
+ + + + + + + + + + + + + + @foreach (var table in Model.LootTables) + { + + + + + + + + + + } + @if (!Model.LootTables.Any()) + { + + + + } + +
IDNameTierDropsEntriesEnabledActions
@table.Id + @table.Name + @if (!string.IsNullOrEmpty(table.Description)) + { +

@table.Description

+ } +
+ @table.MinTier - @table.MaxTier + + @table.MinDrops - @table.MaxDrops + @if (table.GuaranteedDrop) + { + ✓ + } + + @table.Entries.Count + + @if (table.IsEnabled) + { + + } + else + { + + } + +
+ + + + + + +
+
+ No loot tables found. Create one? +
+
+
+ + + + +@section Scripts { + +} diff --git a/Services/Admin/Pages/LootTables/Index.cshtml.cs b/Services/Admin/Pages/LootTables/Index.cshtml.cs new file mode 100644 index 0000000..569ca93 --- /dev/null +++ b/Services/Admin/Pages/LootTables/Index.cshtml.cs @@ -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 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 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(); + } +} diff --git a/Services/Admin/Pages/Mobs/Edit.cshtml b/Services/Admin/Pages/Mobs/Edit.cshtml new file mode 100644 index 0000000..d39e1eb --- /dev/null +++ b/Services/Admin/Pages/Mobs/Edit.cshtml @@ -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}"; +} + +
+ +
+ + + + + +
+

@(Model.IsNew ? "Create Mob" : "Edit Mob")

+

@(Model.IsNew ? "Add a new mob definition" : $"ID: {Model.Mob.Id}")

+
+
+ + @if (!string.IsNullOrEmpty(Model.Message)) + { +
+ @Model.Message +
+ } + +
+ @Html.AntiForgeryToken() + + + +
+
+

Basic Information

+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+
+ +
+
+
+ + +
+
+

Base Combat Stats

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+

Movement & Behavior

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+

Tier Scaling (Multipliers)

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+

Visual

+
+
+
+ +
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ + Cancel + @if (!Model.IsNew) + { +
+ + } +
+
+ + + @if (!Model.IsNew) + { +
+
+

Loot Tables (@Model.MobLootTables.Count)

+ +
+
+ + + + + + + + + + + + @foreach (var mlt in Model.MobLootTables) + { + + + + + + + + } + @if (!Model.MobLootTables.Any()) + { + + + + } + +
Loot TablePriorityRoll %EntriesActions
+ + @mlt.LootTable?.Name + + (ID: @mlt.LootTableId) + @mlt.Priority + + @((mlt.RollChance * 100).ToString("0"))% + + + @(mlt.LootTable?.Entries?.Count ?? 0) + +
+ @Html.AntiForgeryToken() + + + +
+
+ No loot tables assigned. This mob won't drop items. +
+
+
+ + + + } +
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Mobs/Edit.cshtml.cs b/Services/Admin/Pages/Mobs/Edit.cshtml.cs new file mode 100644 index 0000000..2913419 --- /dev/null +++ b/Services/Admin/Pages/Mobs/Edit.cshtml.cs @@ -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 MobLootTables { get; set; } = new(); + public List 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 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 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 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 }); + } +} diff --git a/Services/Admin/Pages/Mobs/Index.cshtml b/Services/Admin/Pages/Mobs/Index.cshtml index ff76925..03d0199 100644 --- a/Services/Admin/Pages/Mobs/Index.cshtml +++ b/Services/Admin/Pages/Mobs/Index.cshtml @@ -1,14 +1,16 @@ @page "/admin/mobs" @model Mobs.IndexModel +@using Server.Data.Enums @{ ViewData["Title"] = "Mobs"; }
+

Mobs

-

Manage mob definitions (@Model.MobCount total)

+

Manage mob definitions

@@ -18,7 +20,140 @@
-
-

Mob editor coming soon...

+ +
+
+
+ + +
+
+ + +
+
+ + +
+ + Clear +
+
+ + +
+ + + + + + + + + + + + + + + + @foreach (var mob in Model.Mobs) + { + + + + + + + + + + + + } + @if (!Model.Mobs.Any()) + { + + + + } + +
IDNameTypeCategoryTierHPDMGEnabledActions
@mob.Id + @mob.Name + @if (!string.IsNullOrEmpty(mob.Description)) + { +

@mob.Description

+ } +
+ + @mob.Type + + @mob.Category@mob.MinTier - @mob.MaxTier@mob.BaseHealth@mob.BasePhysicalDamage + @if (mob.IsEnabled) + { + + } + else + { + + } + +
+ + + + + + +
+
+ No mobs found. Create one? +
+ + + + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Mobs/Index.cshtml.cs b/Services/Admin/Pages/Mobs/Index.cshtml.cs index 61bea18..2b2010e 100644 --- a/Services/Admin/Pages/Mobs/Index.cshtml.cs +++ b/Services/Admin/Pages/Mobs/Index.cshtml.cs @@ -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 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 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(); } } diff --git a/Services/Admin/Pages/Shared/_Layout.cshtml b/Services/Admin/Pages/Shared/_Layout.cshtml index 55ac6c6..4306481 100644 --- a/Services/Admin/Pages/Shared/_Layout.cshtml +++ b/Services/Admin/Pages/Shared/_Layout.cshtml @@ -104,6 +104,13 @@ CDN Assets + + + + + Loot Tables + +

Management