Dungeon Admin management

This commit is contained in:
dingo
2026-01-31 11:19:38 -05:00
parent 4108d20555
commit 0b89cd06aa
5 changed files with 256 additions and 20 deletions
+1 -1
View File
@@ -496,7 +496,7 @@ public partial class DungeonHandler
return false; return false;
if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player)) if (!dungeon.Simulation.Players.TryGetValue(characterId, out var player))
return false; return false;
player.Armor = invulnerable ? 999999 : 0; player.IsInvulnerable = invulnerable;
return true; return true;
} }
+8 -2
View File
@@ -951,6 +951,7 @@ public partial class DungeonSimulation
private void ApplyDamageToPlayer(MobInstance? mob, PlayerInstance player, int damage, string damageTypeKey, bool wasResisted, bool wasWeakness) private void ApplyDamageToPlayer(MobInstance? mob, PlayerInstance player, int damage, string damageTypeKey, bool wasResisted, bool wasWeakness)
{ {
if (player.IsInvulnerable) return;
player.Health -= damage; player.Health -= damage;
player.IsInCombat = true; player.IsInCombat = true;
player.LastCombatTick = CurrentTick; player.LastCombatTick = CurrentTick;
@@ -1068,12 +1069,17 @@ public partial class DungeonSimulation
{ {
effect.NextTickIn -= TickDelta; effect.NextTickIn -= TickDelta;
if (effect.NextTickIn <= 0) if (effect.NextTickIn <= 0)
{
if (!player.IsInvulnerable)
{ {
player.Health -= effect.DamagePerTick; player.Health -= effect.DamagePerTick;
player.IsInCombat = true; player.IsInCombat = true;
player.LastCombatTick = CurrentTick; player.LastCombatTick = CurrentTick;
}
effect.NextTickIn = effect.TickInterval; effect.NextTickIn = effect.TickInterval;
if (!player.IsInvulnerable)
{
_pendingDamageEvents.Add(new DamageEvent _pendingDamageEvents.Add(new DamageEvent
{ {
SourceType = EntityType.Mob, SourceType = EntityType.Mob,
@@ -1083,8 +1089,9 @@ public partial class DungeonSimulation
Damage = effect.DamagePerTick, Damage = effect.DamagePerTick,
DamageTypeKey = effect.EffectType DamageTypeKey = effect.EffectType
}); });
}
if (player.Health <= 0) if (!player.IsInvulnerable && player.Health <= 0)
{ {
player.Health = 0; player.Health = 0;
player.IsAlive = false; player.IsAlive = false;
@@ -1362,4 +1369,3 @@ public partial class DungeonSimulation
} }
+5
View File
@@ -29,6 +29,11 @@ public class PlayerInstance
// Defensive stats (from gear) // Defensive stats (from gear)
public int Armor { get; set; } public int Armor { get; set; }
/// <summary>
/// Admin override to prevent all incoming damage
/// </summary>
public bool IsInvulnerable { get; set; }
/// <summary> /// <summary>
/// Weapon damage type key (from equipped weapon, defaults to physical for unarmed) /// Weapon damage type key (from equipped weapon, defaults to physical for unarmed)
/// </summary> /// </summary>
+123 -4
View File
@@ -21,6 +21,10 @@
.stat-card { background: rgba(30, 30, 50, 0.8); border: 1px solid #374151; border-radius: 8px; padding: 12px; } .stat-card { background: rgba(30, 30, 50, 0.8); border: 1px solid #374151; border-radius: 8px; padding: 12px; }
.inspector { background: rgba(20, 20, 40, 0.95); border: 1px solid #4f46e5; border-radius: 8px; padding: 16px; } .inspector { background: rgba(20, 20, 40, 0.95); border: 1px solid #4f46e5; border-radius: 8px; padding: 16px; }
.inspector-stat { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.1); } .inspector-stat { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.1); }
.inspector, .inspector * { color: #e5e7eb; }
.inspector .text-gray-400 { color: #9ca3af !important; }
.inspector select, .inspector input, .inspector textarea { background: #111827; border-color: #374151; color: #e5e7eb; }
.inspector option { color: #e5e7eb; background: #111827; }
.tool-btn { padding: 6px 10px; border-radius: 6px; font-size: 12px; transition: all 0.15s; background: #374151; color: #ccc; border: none; cursor: pointer; } .tool-btn { padding: 6px 10px; border-radius: 6px; font-size: 12px; transition: all 0.15s; background: #374151; color: #ccc; border: none; cursor: pointer; }
.tool-btn:hover { background: #4b5563; } .tool-btn:hover { background: #4b5563; }
.tool-btn.active { background: #4f46e5; color: white; } .tool-btn.active { background: #4f46e5; color: white; }
@@ -145,9 +149,57 @@ else
<button onclick="closeMobInspector()" class="text-gray-400 hover:text-white">✕</button> <button onclick="closeMobInspector()" class="text-gray-400 hover:text-white">✕</button>
</div> </div>
<div id="mobInspectorContent" class="space-y-1 text-sm"></div> <div id="mobInspectorContent" class="space-y-1 text-sm"></div>
<div class="flex gap-2 mt-4"> <div class="grid grid-cols-2 gap-2 mt-4">
<button onclick="killSelectedMob()" class="btn btn-danger btn-sm flex-1">🗡️ Kill</button> <button onclick="healSelectedMob()" class="btn btn-success btn-sm">❤️ Heal</button>
<button onclick="copyMobPosition()" class="btn btn-secondary btn-sm flex-1">📍 Copy</button> <button onclick="copyMobPosition()" class="btn btn-secondary btn-sm">📍 Copy</button>
<button onclick="killSelectedMob()" class="btn btn-danger btn-sm">🗡️ Kill</button>
</div>
<div class="mt-4 space-y-3">
<div>
<div class="text-xs text-gray-400 mb-1">Add Ability</div>
<div class="flex gap-2">
<select id="mobAbilitySelect" class="input text-xs w-full">
<option value="">Select ability...</option>
@foreach (var ability in Model.AbilityDefinitions)
{
<option value="@ability.Id">@ability.Name (@ability.Key)</option>
}
</select>
<button onclick="addMobAbility()" class="btn btn-secondary btn-sm">Add</button>
</div>
</div>
<div>
<div class="text-xs text-gray-400 mb-1">Resistances</div>
<div class="grid grid-cols-3 gap-2">
<select id="mobResistSelect" class="input text-xs col-span-2">
<option value="">Select type...</option>
@foreach (var res in Model.ResistanceTypes)
{
<option value="@res.Key">@res.DisplayName (@res.Key)</option>
}
</select>
<input type="number" id="mobResistValue" class="input text-xs" placeholder="0.25" step="0.05" />
</div>
<div class="flex gap-2 mt-2">
<button onclick="setMobResistance(false)" class="btn btn-secondary btn-sm">Add/Update</button>
<button onclick="setMobResistance(true)" class="btn btn-danger btn-sm">Remove</button>
</div>
</div>
<div>
<div class="text-xs text-gray-400 mb-1">Loot</div>
<div class="grid grid-cols-3 gap-2">
<input type="number" id="mobLootGold" class="input text-xs col-span-2" placeholder="Gold" />
<button onclick="setMobLootGold()" class="btn btn-secondary btn-sm">Set</button>
</div>
<div class="grid grid-cols-3 gap-2 mt-2">
<input type="number" id="mobLootItemId" class="input text-xs" placeholder="Item Id" />
<input type="number" id="mobLootItemQty" class="input text-xs" placeholder="Qty" value="1" />
<button onclick="addMobLootItem()" class="btn btn-secondary btn-sm">Add</button>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -182,6 +234,7 @@ else
<div class="stat-card"> <div class="stat-card">
<h3 class="text-lg font-semibold text-white mb-3">Spawn Mob</h3> <h3 class="text-lg font-semibold text-white mb-3">Spawn Mob</h3>
<div class="space-y-2"> <div class="space-y-2">
<input type="text" id="spawnMobFilter" class="input text-sm w-full" placeholder="Type to filter mobs..." />
<select id="spawnMobSelect" class="input text-sm w-full"> <select id="spawnMobSelect" class="input text-sm w-full">
<option value="">Select mob...</option> <option value="">Select mob...</option>
@foreach (var mob in Model.MobDefinitions) @foreach (var mob in Model.MobDefinitions)
@@ -270,6 +323,11 @@ else
buildSheetList(); buildSheetList();
updateEntities(@Html.Raw(Model.PlayersJson), @Html.Raw(Model.MobsJson)); updateEntities(@Html.Raw(Model.PlayersJson), @Html.Raw(Model.MobsJson));
refreshInterval = setInterval(fetchUpdate, 500); refreshInterval = setInterval(fetchUpdate, 500);
const filterInput = document.getElementById('spawnMobFilter');
if (filterInput) {
filterInput.addEventListener('input', () => filterMobSelect(filterInput.value));
}
} }
async function loadSheetTextures() { async function loadSheetTextures() {
@@ -579,10 +637,19 @@ else
selectedMobId = m.id; selectedPlayerId = null; closePlayerInspector(); selectedMobId = m.id; selectedPlayerId = null; closePlayerInspector();
document.getElementById('mobInspector').classList.remove('hidden'); document.getElementById('mobInspector').classList.remove('hidden');
document.getElementById('mobInspectorName').textContent = m.name; document.getElementById('mobInspectorName').textContent = m.name;
const abilities = (m.abilities || []).map(a => `${a.name} (${a.key})`).join(', ') || 'None';
const resEntries = m.resistances ? Object.entries(m.resistances) : [];
const resText = resEntries.length ? resEntries.map(([k, v]) => `${k}: ${v}`).join(', ') : 'None';
const lootItems = (m.lootItems || []).map(i => `${i.name} x${i.qty}`).join(', ') || 'None';
document.getElementById('mobInspectorContent').innerHTML = ` document.getElementById('mobInspectorContent').innerHTML = `
<div class="inspector-stat"><span class="text-gray-400">Health</span><span>${m.health}/${m.maxHealth}</span></div> <div class="inspector-stat"><span class="text-gray-400">Health</span><span>${m.health}/${m.maxHealth}</span></div>
<div class="inspector-stat"><span class="text-gray-400">Position</span><span>${Math.round(m.x)}, ${Math.round(m.y)}</span></div> <div class="inspector-stat"><span class="text-gray-400">Position</span><span>${Math.round(m.x)}, ${Math.round(m.y)}</span></div>
<div class="inspector-stat"><span class="text-gray-400">State</span><span>${m.state}</span></div>`; <div class="inspector-stat"><span class="text-gray-400">State</span><span>${m.state}</span></div>
<div class="inspector-stat"><span class="text-gray-400">Abilities</span><span>${abilities}</span></div>
<div class="inspector-stat"><span class="text-gray-400">Resistances</span><span>${resText}</span></div>
<div class="inspector-stat"><span class="text-gray-400">Loot</span><span>${lootItems} (Gold: ${m.lootGold ?? 0})</span></div>`;
const lootGoldInput = document.getElementById('mobLootGold');
if (lootGoldInput) lootGoldInput.value = m.lootGold ?? 0;
updateEntities(currentPlayers, currentMobs); updateEntities(currentPlayers, currentMobs);
} }
function closeMobInspector() { selectedMobId = null; document.getElementById('mobInspector').classList.add('hidden'); updateEntities(currentPlayers, currentMobs); } function closeMobInspector() { selectedMobId = null; document.getElementById('mobInspector').classList.add('hidden'); updateEntities(currentPlayers, currentMobs); }
@@ -627,6 +694,47 @@ else
closeMobInspector(); closeMobInspector();
} }
async function healSelectedMob() {
if (!selectedMobId) return;
await fetch(`/admin/dungeons/view?handler=HealMob&id=${dungeonId}&mobId=${selectedMobId}`, {
method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
});
}
async function addMobAbility() {
const abilityId = document.getElementById('mobAbilitySelect').value;
if (!selectedMobId || !abilityId) return;
await fetch(`/admin/dungeons/view?handler=AddMobAbility&id=${dungeonId}&mobId=${selectedMobId}&abilityId=${abilityId}`, {
method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
});
}
async function setMobResistance(remove) {
const key = document.getElementById('mobResistSelect').value;
if (!selectedMobId || !key) return;
const value = parseFloat(document.getElementById('mobResistValue').value || '0');
await fetch(`/admin/dungeons/view?handler=SetMobResistance&id=${dungeonId}&mobId=${selectedMobId}&key=${encodeURIComponent(key)}&value=${value}&remove=${remove}`, {
method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
});
}
async function setMobLootGold() {
const gold = parseInt(document.getElementById('mobLootGold').value || '0', 10);
if (!selectedMobId) return;
await fetch(`/admin/dungeons/view?handler=SetMobLootGold&id=${dungeonId}&mobId=${selectedMobId}&gold=${gold}`, {
method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
});
}
async function addMobLootItem() {
const itemId = parseInt(document.getElementById('mobLootItemId').value || '0', 10);
const qty = parseInt(document.getElementById('mobLootItemQty').value || '0', 10);
if (!selectedMobId || itemId <= 0 || qty <= 0) return;
await fetch(`/admin/dungeons/view?handler=AddMobLootItem&id=${dungeonId}&mobId=${selectedMobId}&itemId=${itemId}&quantity=${qty}`, {
method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
});
}
function copyMobPosition() { function copyMobPosition() {
const m = currentMobs.find(m => m.id == selectedMobId); const m = currentMobs.find(m => m.id == selectedMobId);
if (m) navigator.clipboard.writeText(`${Math.round(m.x)}, ${Math.round(m.y)}`); if (m) navigator.clipboard.writeText(`${Math.round(m.x)}, ${Math.round(m.y)}`);
@@ -641,6 +749,16 @@ else
}); });
} }
function filterMobSelect(query) {
const select = document.getElementById('spawnMobSelect');
if (!select) return;
const q = (query || '').toLowerCase();
Array.from(select.options).forEach(opt => {
if (!opt.value) return;
opt.hidden = q.length > 0 && !opt.text.toLowerCase().includes(q);
});
}
async function broadcastTiles() { async function broadcastTiles() {
await fetch(`/admin/dungeons/view?handler=BroadcastTiles&id=${dungeonId}`, { await fetch(`/admin/dungeons/view?handler=BroadcastTiles&id=${dungeonId}`, {
method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value } method: 'POST', headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
@@ -671,3 +789,4 @@ else
document.addEventListener('DOMContentLoaded', init); document.addEventListener('DOMContentLoaded', init);
</script> </script>
} }
+108 -2
View File
@@ -29,6 +29,8 @@ public class ViewModel : AdminPageModel
public string TileSheetsJson { get; set; } = "[]"; public string TileSheetsJson { get; set; } = "[]";
public int VisualTileCount { get; set; } public int VisualTileCount { get; set; }
public List<DungeonMobDefinition> MobDefinitions { get; set; } = new(); public List<DungeonMobDefinition> MobDefinitions { get; set; } = new();
public List<MobAbilityDefinition> AbilityDefinitions { get; set; } = new();
public List<DamageResistanceType> ResistanceTypes { get; set; } = new();
public async Task OnGetAsync(Guid id) public async Task OnGetAsync(Guid id)
{ {
@@ -37,6 +39,15 @@ public class ViewModel : AdminPageModel
MobDefinitions = await _db.DungeonMobDefinitions MobDefinitions = await _db.DungeonMobDefinitions
.Where(m => m.IsEnabled).OrderBy(m => m.Name).ToListAsync(); .Where(m => m.IsEnabled).OrderBy(m => m.Name).ToListAsync();
AbilityDefinitions = await _db.MobAbilityDefinitions
.Where(a => a.IsEnabled).OrderBy(a => a.Name).ToListAsync();
ResistanceTypes = await _db.DamageResistanceTypes
.Where(r => r.IsEnabled)
.OrderBy(r => r.SortOrder)
.ThenBy(r => r.DisplayName)
.ToListAsync();
// Load ALL available tile sheets from database (not just those in dungeon) // Load ALL available tile sheets from database (not just those in dungeon)
var allSheets = await _db.Set<TileMapSheet>() var allSheets = await _db.Set<TileMapSheet>()
.Where(s => s.IsEnabled) .Where(s => s.IsEnabled)
@@ -85,7 +96,13 @@ public class ViewModel : AdminPageModel
MobsJson = JsonSerializer.Serialize(Dungeon.Simulation.Mobs.Values.Select(m => new { MobsJson = JsonSerializer.Serialize(Dungeon.Simulation.Mobs.Values.Select(m => new {
id = m.Id, name = m.Name, x = m.X, y = m.Y, health = m.Health, maxHealth = m.MaxHealth, id = m.Id, name = m.Name, x = m.X, y = m.Y, health = m.Health, maxHealth = m.MaxHealth,
alive = m.IsAlive, isBoss = m.Type == DataServer.Data.Enums.MobType.Boss, state = m.State.ToString() alive = m.IsAlive, isBoss = m.Type == DataServer.Data.Enums.MobType.Boss, state = m.State.ToString(),
abilities = m.Abilities.Select(a => new { id = a.AbilityId, name = a.Definition?.Name ?? $"Ability {a.AbilityId}", key = a.Definition?.Key ?? "" }),
resistances = m.Stats.Resistances,
lootGold = m.DeathLootGold,
lootItems = m.DeathLoot == null
? Array.Empty<object>()
: m.DeathLoot.Select(l => new { id = l.ItemDefinitionId, name = l.Item?.Name ?? $"Item {l.ItemDefinitionId}", qty = l.Quantity })
})); }));
} }
@@ -104,7 +121,13 @@ public class ViewModel : AdminPageModel
}), }),
mobs = dungeon.Simulation.Mobs.Values.Select(m => new { mobs = dungeon.Simulation.Mobs.Values.Select(m => new {
id = m.Id, name = m.Name, x = m.X, y = m.Y, health = m.Health, maxHealth = m.MaxHealth, id = m.Id, name = m.Name, x = m.X, y = m.Y, health = m.Health, maxHealth = m.MaxHealth,
alive = m.IsAlive, isBoss = m.Type == DataServer.Data.Enums.MobType.Boss, state = m.State.ToString() alive = m.IsAlive, isBoss = m.Type == DataServer.Data.Enums.MobType.Boss, state = m.State.ToString(),
abilities = m.Abilities.Select(a => new { id = a.AbilityId, name = a.Definition?.Name ?? $"Ability {a.AbilityId}", key = a.Definition?.Key ?? "" }),
resistances = m.Stats.Resistances,
lootGold = m.DeathLootGold,
lootItems = m.DeathLoot == null
? Array.Empty<object>()
: m.DeathLoot.Select(l => new { id = l.ItemDefinitionId, name = l.Item?.Name ?? $"Item {l.ItemDefinitionId}", qty = l.Quantity })
}) })
}); });
} }
@@ -148,6 +171,89 @@ public class ViewModel : AdminPageModel
return new JsonResult(new { error = "Not found" }) { StatusCode = 404 }; return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
} }
public IActionResult OnPostHealMob(Guid id, int mobId)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon?.Simulation.Mobs.TryGetValue(mobId, out var mob) == true)
{
mob.Health = mob.MaxHealth;
mob.IsAlive = true;
return new JsonResult(new { success = true });
}
return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
}
public async Task<IActionResult> OnPostAddMobAbilityAsync(Guid id, int mobId, int abilityId)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon?.Simulation.Mobs.TryGetValue(mobId, out var mob) != true)
return new JsonResult(new { error = "Mob not found" }) { StatusCode = 404 };
var ability = await _db.MobAbilityDefinitions.FirstOrDefaultAsync(a => a.Id == abilityId && a.IsEnabled);
if (ability == null)
return new JsonResult(new { error = "Ability not found" }) { StatusCode = 404 };
if (mob.Abilities.Any(a => a.AbilityId == abilityId))
return new JsonResult(new { success = true, message = "Ability already present" });
mob.Abilities.Add(new MobAbilityState
{
AbilityId = ability.Id,
Definition = ability,
CooldownRemaining = 0,
Priority = ability.Priority
});
return new JsonResult(new { success = true });
}
public IActionResult OnPostSetMobResistance(Guid id, int mobId, string key, float value, bool remove = false)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon?.Simulation.Mobs.TryGetValue(mobId, out var mob) != true)
return new JsonResult(new { error = "Mob not found" }) { StatusCode = 404 };
if (remove)
mob.Stats.Resistances.Remove(key);
else
mob.Stats.Resistances[key] = value;
return new JsonResult(new { success = true });
}
public IActionResult OnPostSetMobLootGold(Guid id, int mobId, long gold)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon?.Simulation.Mobs.TryGetValue(mobId, out var mob) != true)
return new JsonResult(new { error = "Mob not found" }) { StatusCode = 404 };
mob.DeathLootGold = Math.Max(0, gold);
return new JsonResult(new { success = true });
}
public async Task<IActionResult> OnPostAddMobLootItemAsync(Guid id, int mobId, int itemId, int quantity)
{
if (quantity <= 0)
return new JsonResult(new { error = "Quantity must be > 0" }) { StatusCode = 400 };
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon?.Simulation.Mobs.TryGetValue(mobId, out var mob) != true)
return new JsonResult(new { error = "Mob not found" }) { StatusCode = 404 };
var item = await _db.Set<DungeonItemDefinition>().FirstOrDefaultAsync(i => i.Id == itemId);
if (item == null)
return new JsonResult(new { error = "Item not found" }) { StatusCode = 404 };
mob.DeathLoot ??= new List<LootDrop>();
var existing = mob.DeathLoot.FirstOrDefault(l => l.ItemDefinitionId == itemId);
if (existing != null)
existing.Quantity += quantity;
else
mob.DeathLoot.Add(new LootDrop { ItemDefinitionId = itemId, Item = item, Quantity = quantity });
return new JsonResult(new { success = true });
}
public IActionResult OnPostSpawnMob(Guid id, int mobDefId, float x, float y) public IActionResult OnPostSpawnMob(Guid id, int mobDefId, float x, float y)
{ {
var mob = _dungeonHandler.SpawnMobInDungeon(id, mobDefId, x, y); var mob = _dungeonHandler.SpawnMobInDungeon(id, mobDefId, x, y);