Resistances + Dmg Types
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Items;
|
||||
|
||||
@@ -17,6 +19,10 @@ public class EditModel : AdminPageModel
|
||||
[BindProperty]
|
||||
public DungeonItemDefinition Item { get; set; } = new();
|
||||
|
||||
public List<DamageResistanceType> ResistanceTypes { get; set; } = new();
|
||||
public Dictionary<string, float> ItemResistances => Item.Resistances;
|
||||
public Dictionary<string, float> BuffResistances => Item.BuffResistances;
|
||||
|
||||
public bool IsNew => Item.Id == 0;
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
@@ -27,6 +33,11 @@ public class EditModel : AdminPageModel
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
ResistanceTypes = await _db.DamageResistanceTypes
|
||||
.Where(r => r.IsEnabled)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.ToListAsync();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var item = await _db.DungeonItemDefinitions.FindAsync(id.Value);
|
||||
@@ -46,6 +57,11 @@ public class EditModel : AdminPageModel
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
ResistanceTypes = await _db.DamageResistanceTypes
|
||||
.Where(r => r.IsEnabled)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.ToListAsync();
|
||||
|
||||
// Handle checkbox binding (unchecked = not sent)
|
||||
Item.IsEnabled = Request.Form.ContainsKey("Item.IsEnabled");
|
||||
Item.Stackable = Request.Form.ContainsKey("Item.Stackable");
|
||||
@@ -55,6 +71,34 @@ public class EditModel : AdminPageModel
|
||||
Item.Description ??= "";
|
||||
Item.SpritePath ??= "";
|
||||
Item.TintColor ??= "#ffffff";
|
||||
|
||||
// Parse equipment resistances
|
||||
var resistances = new Dictionary<string, float>();
|
||||
var resistNames = Request.Form["resist_name[]"].ToArray();
|
||||
var resistValues = Request.Form["resist_value[]"].ToArray();
|
||||
for (int i = 0; i < resistNames.Length && i < resistValues.Length; i++)
|
||||
{
|
||||
var name = resistNames[i]?.Trim().ToLower();
|
||||
if (!string.IsNullOrEmpty(name) && float.TryParse(resistValues[i], out var value))
|
||||
{
|
||||
resistances[name] = value;
|
||||
}
|
||||
}
|
||||
Item.ResistancesJson = JsonSerializer.Serialize(resistances);
|
||||
|
||||
// Parse buff resistances
|
||||
var buffResistances = new Dictionary<string, float>();
|
||||
var buffResistNames = Request.Form["buff_resist_name[]"].ToArray();
|
||||
var buffResistValues = Request.Form["buff_resist_value[]"].ToArray();
|
||||
for (int i = 0; i < buffResistNames.Length && i < buffResistValues.Length; i++)
|
||||
{
|
||||
var name = buffResistNames[i]?.Trim().ToLower();
|
||||
if (!string.IsNullOrEmpty(name) && float.TryParse(buffResistValues[i], out var value))
|
||||
{
|
||||
buffResistances[name] = value;
|
||||
}
|
||||
}
|
||||
Item.BuffResistancesJson = JsonSerializer.Serialize(buffResistances);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Item.Name))
|
||||
{
|
||||
@@ -95,11 +139,14 @@ public class EditModel : AdminPageModel
|
||||
HealAmount = Item.HealAmount,
|
||||
ManaRestore = Item.ManaRestore,
|
||||
StaminaRestore = Item.StaminaRestore,
|
||||
BuffDuration = Item.BuffDuration,
|
||||
IsTeleportScroll = Item.IsTeleportScroll,
|
||||
Stackable = Item.Stackable,
|
||||
MaxStack = Item.MaxStack,
|
||||
SpritePath = Item.SpritePath,
|
||||
TintColor = Item.TintColor,
|
||||
ResistancesJson = Item.ResistancesJson,
|
||||
BuffResistancesJson = Item.BuffResistancesJson,
|
||||
IsEnabled = Item.IsEnabled
|
||||
};
|
||||
_db.DungeonItemDefinitions.Add(newItem);
|
||||
@@ -152,11 +199,14 @@ public class EditModel : AdminPageModel
|
||||
existing.HealAmount = Item.HealAmount;
|
||||
existing.ManaRestore = Item.ManaRestore;
|
||||
existing.StaminaRestore = Item.StaminaRestore;
|
||||
existing.BuffDuration = Item.BuffDuration;
|
||||
existing.IsTeleportScroll = Item.IsTeleportScroll;
|
||||
existing.Stackable = Item.Stackable;
|
||||
existing.MaxStack = Item.MaxStack;
|
||||
existing.SpritePath = Item.SpritePath;
|
||||
existing.TintColor = Item.TintColor;
|
||||
existing.ResistancesJson = Item.ResistancesJson;
|
||||
existing.BuffResistancesJson = Item.BuffResistancesJson;
|
||||
existing.IsEnabled = Item.IsEnabled;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Reference in New Issue
Block a user