Resistance System
This commit is contained in:
@@ -174,7 +174,8 @@
|
||||
(DungeonEquipmentSlot.Legs, "Legs"),
|
||||
(DungeonEquipmentSlot.Boots, "Boots"),
|
||||
(DungeonEquipmentSlot.Gloves, "Gloves"),
|
||||
(DungeonEquipmentSlot.Accessory1, "Accessory")
|
||||
(DungeonEquipmentSlot.Accessory1, "Accessory 1"),
|
||||
(DungeonEquipmentSlot.Accessory2, "Accessory 2")
|
||||
})
|
||||
{
|
||||
var item = Model.EquippedItems.FirstOrDefault(i => i.EquipSlot == slot.Item1);
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
@page "/admin/resistances"
|
||||
@model Resistances.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Damage Resistance Types";
|
||||
}
|
||||
|
||||
<div class="space-y-6 max-w-4xl">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Damage Resistance Types</h1>
|
||||
<p class="text-gray-400 mt-1">Define resistance types for mobs, players, and items</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-300" : "bg-green-900/50 border border-green-700 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Add New Type -->
|
||||
<form method="post" asp-page-handler="Create" class="card p-6">
|
||||
@Html.AntiForgeryToken()
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Add New Resistance Type</h2>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-6 gap-4 mb-4">
|
||||
<div class="md:col-span-2">
|
||||
<label class="label">Key (lowercase, no spaces)</label>
|
||||
<input type="text" name="key" class="input" required pattern="[a-z0-9_]+" maxlength="32" placeholder="e.g., bleed"
|
||||
oninput="this.value = this.value.toLowerCase().replace(/[^a-z0-9_]/g, '')" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="label">Display Name</label>
|
||||
<input type="text" name="displayName" class="input" required maxlength="64" placeholder="e.g., Bleeding" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Color</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="color" id="newColor" value="#888888" class="w-10 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer"
|
||||
oninput="document.getElementById('newColorText').value=this.value" />
|
||||
<input type="text" id="newColorText" name="color" value="#888888" class="input flex-1" maxlength="16" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Order</label>
|
||||
<input type="number" name="sortOrder" value="@(Model.Types.Count * 10)" class="input" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="label">Description (optional)</label>
|
||||
<input type="text" name="description" class="input" maxlength="256" placeholder="What this damage type represents..." />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Add Resistance Type</button>
|
||||
</form>
|
||||
|
||||
<!-- Existing Types -->
|
||||
<div class="card overflow-hidden">
|
||||
<table class="w-full">
|
||||
<thead class="bg-gray-800">
|
||||
<tr>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Color</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Key</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Display Name</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Description</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Order</th>
|
||||
<th class="px-4 py-3 text-right text-xs font-medium text-gray-400 uppercase">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700">
|
||||
@foreach (var type in Model.Types)
|
||||
{
|
||||
<tr class="hover:bg-gray-800/50">
|
||||
<td class="px-4 py-3">
|
||||
<div class="w-6 h-6 rounded" style="background-color: @type.Color"></div>
|
||||
</td>
|
||||
<td class="px-4 py-3">
|
||||
<code class="text-indigo-400 bg-gray-800 px-2 py-0.5 rounded text-sm">@type.Key</code>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-white">@type.DisplayName</td>
|
||||
<td class="px-4 py-3 text-gray-400 text-sm">@(string.IsNullOrEmpty(type.Description) ? "-" : type.Description)</td>
|
||||
<td class="px-4 py-3 text-gray-400">@type.SortOrder</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<button type="button" onclick="editType(@type.Id, '@type.Key', '@type.DisplayName', '@type.Description', '@type.Color', @type.SortOrder)"
|
||||
class="btn btn-secondary text-xs px-2 py-1">Edit</button>
|
||||
<form method="post" asp-page-handler="Delete" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@type.Id" />
|
||||
<button type="submit" class="btn bg-red-700 hover:bg-red-600 text-white text-xs px-2 py-1"
|
||||
onclick="return confirm('Delete @type.DisplayName? This may break existing resistances using this type.')">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@if (!Model.Types.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="6" class="px-4 py-8 text-center text-gray-400">
|
||||
No resistance types defined. Add the base types above.
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Seed Base Types -->
|
||||
@if (!Model.Types.Any())
|
||||
{
|
||||
<form method="post" asp-page-handler="SeedDefaults" class="card p-6 text-center">
|
||||
@Html.AntiForgeryToken()
|
||||
<p class="text-gray-400 mb-4">Want to start with the default damage types?</p>
|
||||
<button type="submit" class="btn btn-primary">Seed Default Resistance Types</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Edit Modal -->
|
||||
<div id="editModal" class="fixed inset-0 bg-black/70 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-4">Edit Resistance Type</h3>
|
||||
<form method="post" asp-page-handler="Update">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" id="editId" />
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="label">Key (read-only)</label>
|
||||
<input type="text" id="editKey" class="input bg-gray-900" readonly />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Display Name</label>
|
||||
<input type="text" name="displayName" id="editDisplayName" class="input" required maxlength="64" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Description</label>
|
||||
<input type="text" name="description" id="editDescription" class="input" maxlength="256" />
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="label">Color</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="color" id="editColorPicker" class="w-10 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer"
|
||||
oninput="document.getElementById('editColor').value=this.value" />
|
||||
<input type="text" name="color" id="editColor" class="input flex-1" maxlength="16" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Sort Order</label>
|
||||
<input type="number" name="sortOrder" id="editSortOrder" class="input" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4 mt-4 border-t border-gray-700">
|
||||
<button type="button" onclick="closeEditModal()" class="btn btn-secondary">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function editType(id, key, displayName, description, color, sortOrder) {
|
||||
document.getElementById('editId').value = id;
|
||||
document.getElementById('editKey').value = key;
|
||||
document.getElementById('editDisplayName').value = displayName;
|
||||
document.getElementById('editDescription').value = description || '';
|
||||
document.getElementById('editColor').value = color;
|
||||
document.getElementById('editColorPicker').value = color;
|
||||
document.getElementById('editSortOrder').value = sortOrder;
|
||||
|
||||
document.getElementById('editModal').classList.remove('hidden');
|
||||
document.getElementById('editModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeEditModal() {
|
||||
document.getElementById('editModal').classList.add('hidden');
|
||||
document.getElementById('editModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeEditModal(); });
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Resistances;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public IndexModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<DamageResistanceType> Types { get; set; } = new();
|
||||
|
||||
[TempData]
|
||||
public string? Message { get; set; }
|
||||
[TempData]
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Types = await _db.DamageResistanceTypes
|
||||
.Where(t => t.IsEnabled)
|
||||
.OrderBy(t => t.SortOrder)
|
||||
.ThenBy(t => t.DisplayName)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostCreateAsync(string key, string displayName, string? description, string color, int sortOrder)
|
||||
{
|
||||
key = key?.Trim().ToLower().Replace(" ", "_") ?? "";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(displayName))
|
||||
{
|
||||
Message = "Key and Display Name are required.";
|
||||
IsError = true;
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
// Check for duplicate key (case insensitive)
|
||||
var existing = await _db.DamageResistanceTypes
|
||||
.FirstOrDefaultAsync(t => t.Key.ToLower() == key.ToLower());
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
Message = $"A resistance type with key '{key}' already exists.";
|
||||
IsError = true;
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
var type = new DamageResistanceType
|
||||
{
|
||||
Key = key,
|
||||
DisplayName = displayName,
|
||||
Description = description ?? "",
|
||||
Color = color ?? "#888888",
|
||||
SortOrder = sortOrder,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_db.DamageResistanceTypes.Add(type);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Message = $"Resistance type '{displayName}' created.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostUpdateAsync(int id, string displayName, string? description, string color, int sortOrder)
|
||||
{
|
||||
var type = await _db.DamageResistanceTypes.FindAsync(id);
|
||||
if (type == null)
|
||||
{
|
||||
Message = "Resistance type not found.";
|
||||
IsError = true;
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
type.DisplayName = displayName;
|
||||
type.Description = description ?? "";
|
||||
type.Color = color ?? "#888888";
|
||||
type.SortOrder = sortOrder;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Resistance type '{displayName}' updated.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var type = await _db.DamageResistanceTypes.FindAsync(id);
|
||||
if (type != null)
|
||||
{
|
||||
// Soft delete by disabling
|
||||
type.IsEnabled = false;
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Resistance type '{type.DisplayName}' deleted.";
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostSeedDefaultsAsync()
|
||||
{
|
||||
var defaults = new[]
|
||||
{
|
||||
new DamageResistanceType { Key = "physical", DisplayName = "Physical", Color = "#a0a0a0", SortOrder = 0 },
|
||||
new DamageResistanceType { Key = "fire", DisplayName = "Fire", Color = "#ff4400", SortOrder = 10 },
|
||||
new DamageResistanceType { Key = "ice", DisplayName = "Ice", Color = "#00aaff", SortOrder = 20 },
|
||||
new DamageResistanceType { Key = "lightning", DisplayName = "Lightning", Color = "#ffff00", SortOrder = 30 },
|
||||
new DamageResistanceType { Key = "poison", DisplayName = "Poison", Color = "#00ff44", SortOrder = 40 },
|
||||
new DamageResistanceType { Key = "holy", DisplayName = "Holy", Color = "#ffffaa", SortOrder = 50 },
|
||||
new DamageResistanceType { Key = "dark", DisplayName = "Dark", Color = "#8800aa", SortOrder = 60 },
|
||||
new DamageResistanceType { Key = "wind", DisplayName = "Wind", Color = "#88ffaa", SortOrder = 70 },
|
||||
};
|
||||
|
||||
foreach (var def in defaults)
|
||||
{
|
||||
var existing = await _db.DamageResistanceTypes
|
||||
.FirstOrDefaultAsync(t => t.Key == def.Key);
|
||||
if (existing == null)
|
||||
{
|
||||
_db.DamageResistanceTypes.Add(def);
|
||||
}
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
Message = "Default resistance types seeded.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,13 @@
|
||||
Loot Tables
|
||||
</a>
|
||||
|
||||
<a href="/admin/resistances" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Resistances") == 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="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
|
||||
</svg>
|
||||
Resistances
|
||||
</a>
|
||||
|
||||
<div class="pt-4">
|
||||
<p class="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Management</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user