diff --git a/Services/Admin/Pages/Items/Edit.cshtml b/Services/Admin/Pages/Items/Edit.cshtml new file mode 100644 index 0000000..11a38bc --- /dev/null +++ b/Services/Admin/Pages/Items/Edit.cshtml @@ -0,0 +1,310 @@ +@page "/admin/items/edit" +@model Items.EditModel +@using Server.Data.Enums +@{ + ViewData["Title"] = Model.IsNew ? "Create Item" : $"Edit: {Model.Item.Name}"; +} + +
+ +
+ + + + + +
+

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

+

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

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

Basic Information

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

Stacking

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

Visual

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

Requirements

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

Stat Bonuses (When Equipped)

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

Combat Stats

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

Consumable Effects

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ + +
+ + Cancel + @if (!Model.IsNew) + { +
+ + } +
+
+
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Items/Edit.cshtml.cs b/Services/Admin/Pages/Items/Edit.cshtml.cs new file mode 100644 index 0000000..0d46367 --- /dev/null +++ b/Services/Admin/Pages/Items/Edit.cshtml.cs @@ -0,0 +1,169 @@ +using Microsoft.AspNetCore.Mvc; +using Server.Data; +using Server.Data.Entities; + +namespace VoidScavengers.Services.Admin.Pages.Items; + +public class EditModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public EditModel(GameDbContext db) + { + _db = db; + } + + [BindProperty] + public DungeonItemDefinition Item { get; set; } = new(); + + public bool IsNew => Item.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; + + if (id.HasValue) + { + var item = await _db.DungeonItemDefinitions.FindAsync(id.Value); + if (item != null) Item = item; + } + else + { + // Defaults for new item + Item.IsEnabled = true; + Item.RequiredLevel = 1; + Item.MaxStack = 1; + } + } + + public async Task OnPostAsync(string? action) + { + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl; + + // Handle checkbox binding (unchecked = not sent) + Item.IsEnabled = Request.Form.ContainsKey("Item.IsEnabled"); + Item.Stackable = Request.Form.ContainsKey("Item.Stackable"); + Item.IsTeleportScroll = Request.Form.ContainsKey("Item.IsTeleportScroll"); + + if (string.IsNullOrWhiteSpace(Item.Name)) + { + Message = "Name is required."; + IsError = true; + return Page(); + } + + try + { + if (action == "duplicate") + { + var newItem = new DungeonItemDefinition + { + Name = Item.Name + " (Copy)", + Description = Item.Description, + Type = Item.Type, + Rarity = Item.Rarity, + EquipSlot = Item.EquipSlot, + RequiredStrength = Item.RequiredStrength, + RequiredIntelligence = Item.RequiredIntelligence, + RequiredWisdom = Item.RequiredWisdom, + RequiredDexterity = Item.RequiredDexterity, + RequiredLevel = Item.RequiredLevel, + BonusStrength = Item.BonusStrength, + BonusIntelligence = Item.BonusIntelligence, + BonusWisdom = Item.BonusWisdom, + BonusEndurance = Item.BonusEndurance, + BonusDexterity = Item.BonusDexterity, + BonusHealth = Item.BonusHealth, + BonusMana = Item.BonusMana, + MinDamage = Item.MinDamage, + MaxDamage = Item.MaxDamage, + AttackRange = Item.AttackRange, + DamageType = Item.DamageType, + Armor = Item.Armor, + MagicResist = Item.MagicResist, + HealAmount = Item.HealAmount, + ManaRestore = Item.ManaRestore, + StaminaRestore = Item.StaminaRestore, + IsTeleportScroll = Item.IsTeleportScroll, + Stackable = Item.Stackable, + MaxStack = Item.MaxStack, + SpritePath = Item.SpritePath, + TintColor = Item.TintColor, + IsEnabled = Item.IsEnabled + }; + _db.DungeonItemDefinitions.Add(newItem); + await _db.SaveChangesAsync(); + return RedirectToPage("/Items/Edit", new { id = newItem.Id }); + } + + if (Item.Id == 0) + { + // Create new + _db.DungeonItemDefinitions.Add(Item); + await _db.SaveChangesAsync(); + Message = $"Item '{Item.Name}' created with ID {Item.Id}"; + return RedirectToPage("/Items/Edit", new { id = Item.Id }); + } + else + { + // Update existing + var existing = await _db.DungeonItemDefinitions.FindAsync(Item.Id); + if (existing == null) + { + Message = "Item not found."; + IsError = true; + return Page(); + } + + existing.Name = Item.Name; + existing.Description = Item.Description; + existing.Type = Item.Type; + existing.Rarity = Item.Rarity; + existing.EquipSlot = Item.EquipSlot; + existing.RequiredStrength = Item.RequiredStrength; + existing.RequiredIntelligence = Item.RequiredIntelligence; + existing.RequiredWisdom = Item.RequiredWisdom; + existing.RequiredDexterity = Item.RequiredDexterity; + existing.RequiredLevel = Item.RequiredLevel; + existing.BonusStrength = Item.BonusStrength; + existing.BonusIntelligence = Item.BonusIntelligence; + existing.BonusWisdom = Item.BonusWisdom; + existing.BonusEndurance = Item.BonusEndurance; + existing.BonusDexterity = Item.BonusDexterity; + existing.BonusHealth = Item.BonusHealth; + existing.BonusMana = Item.BonusMana; + existing.MinDamage = Item.MinDamage; + existing.MaxDamage = Item.MaxDamage; + existing.AttackRange = Item.AttackRange; + existing.DamageType = Item.DamageType; + existing.Armor = Item.Armor; + existing.MagicResist = Item.MagicResist; + existing.HealAmount = Item.HealAmount; + existing.ManaRestore = Item.ManaRestore; + existing.StaminaRestore = Item.StaminaRestore; + existing.IsTeleportScroll = Item.IsTeleportScroll; + existing.Stackable = Item.Stackable; + existing.MaxStack = Item.MaxStack; + existing.SpritePath = Item.SpritePath; + existing.TintColor = Item.TintColor; + existing.IsEnabled = Item.IsEnabled; + + await _db.SaveChangesAsync(); + Item = existing; + Message = "Changes saved successfully."; + } + } + catch (Exception ex) + { + Message = $"Error: {ex.Message}"; + IsError = true; + } + + return Page(); + } +} diff --git a/Services/Admin/Pages/Items/Index.cshtml b/Services/Admin/Pages/Items/Index.cshtml index 9b8f700..d7aa70c 100644 --- a/Services/Admin/Pages/Items/Index.cshtml +++ b/Services/Admin/Pages/Items/Index.cshtml @@ -1,14 +1,16 @@ @page "/admin/items" @model Items.IndexModel +@using Server.Data.Enums @{ ViewData["Title"] = "Items"; }
+

Items

-

Manage item definitions (@Model.ItemCount total)

+

Manage item definitions

@@ -18,7 +20,182 @@
-
-

Full item editor coming in next update...

+ +
+
+
+ + +
+
+ + +
+
+ + +
+ + Clear +
+
+ + +
+ + + + + + + + + + + + + + + @foreach (var item in Model.Items) + { + + + + + + + + + + + } + @if (!Model.Items.Any()) + { + + + + } + +
IDIconNameTypeRarityStackEnabledActions
@item.Id + @if (!string.IsNullOrEmpty(item.SpritePath)) + { + @item.Name + } + else + { +
+ + + +
+ } +
+ @item.Name + @if (!string.IsNullOrEmpty(item.Description)) + { +

@item.Description

+ } +
@item.Type + @item.Rarity + + @if (item.Stackable) + { + @item.MaxStack + } + else + { + - + } + + @if (item.IsEnabled) + { + + } + else + { + + } + +
+ + + + + + +
+
+ No items found. Create one? +
+
+ + + @if (Model.TotalPages > 1) + { +
+

+ Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount +

+
+ @if (Model.CurrentPage > 1) + { + ← Prev + } + @Model.CurrentPage / @Model.TotalPages + @if (Model.CurrentPage < Model.TotalPages) + { + Next → + } +
+
+ } +
+ + + + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Items/Index.cshtml.cs b/Services/Admin/Pages/Items/Index.cshtml.cs index b7327ef..70d0b6d 100644 --- a/Services/Admin/Pages/Items/Index.cshtml.cs +++ b/Services/Admin/Pages/Items/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.Items; @@ -12,10 +15,54 @@ public class IndexModel : AdminPageModel _db = db; } - public int ItemCount { get; set; } + public List Items { get; set; } = new(); + public string? Search { get; set; } + public ItemType? TypeFilter { get; set; } + public ItemRarity? RarityFilter { get; set; } + public int CurrentPage { get; set; } = 1; + public int PageSize { get; set; } = 20; + public int TotalCount { get; set; } + public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize); + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; - public async Task OnGetAsync() + public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1) { - ItemCount = await _db.DungeonItemDefinitions.CountAsync(); + Search = search; + TypeFilter = type; + RarityFilter = rarity; + CurrentPage = Math.Max(1, page); + + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl; + + var query = _db.DungeonItemDefinitions.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(search)) + query = query.Where(i => i.Name.Contains(search) || i.Description.Contains(search)); + + if (type.HasValue) + query = query.Where(i => i.Type == type.Value); + + if (rarity.HasValue) + query = query.Where(i => i.Rarity == rarity.Value); + + TotalCount = await query.CountAsync(); + + Items = await query + .OrderBy(i => i.Id) + .Skip((CurrentPage - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); + } + + public async Task OnPostDeleteAsync(int id) + { + var item = await _db.DungeonItemDefinitions.FindAsync(id); + if (item != null) + { + _db.DungeonItemDefinitions.Remove(item); + await _db.SaveChangesAsync(); + } + return RedirectToPage(); } }