Resistance System

This commit is contained in:
dingo
2025-12-26 10:40:09 -05:00
parent 2d847c91dd
commit fd056692df
16 changed files with 2862 additions and 8 deletions
+60
View File
@@ -0,0 +1,60 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataServer.Data.Entities;
/// <summary>
/// Defines a damage resistance type that can be applied to mobs, players, and items.
/// This allows for dynamic resistance types beyond the base DamageType enum.
/// </summary>
[Table("damage_resistance_types")]
public class DamageResistanceType
{
[Key]
public int Id { get; set; }
/// <summary>
/// Internal key name (lowercase, no spaces) - e.g., "fire", "ice", "bleed"
/// Used in JSON resistance blocks
/// </summary>
[Required]
[MaxLength(32)]
public string Key { get; set; } = "";
/// <summary>
/// Display name for UI - e.g., "Fire", "Ice", "Bleeding"
/// </summary>
[Required]
[MaxLength(64)]
public string DisplayName { get; set; } = "";
/// <summary>
/// Description of what this resistance does
/// </summary>
[MaxLength(256)]
public string Description { get; set; } = "";
/// <summary>
/// Hex color for UI display (e.g., "#ff4400" for fire)
/// </summary>
[MaxLength(16)]
public string Color { get; set; } = "#888888";
/// <summary>
/// Icon path on CDN (optional)
/// </summary>
[MaxLength(256)]
public string? IconPath { get; set; }
/// <summary>
/// Sort order for display in dropdowns
/// </summary>
public int SortOrder { get; set; } = 0;
/// <summary>
/// Whether this resistance type is available for use
/// </summary>
public bool IsEnabled { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}
+23
View File
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
namespace DataServer.Data.Entities;
@@ -70,6 +71,28 @@ public class DungeonCharacter
// Soft delete
public bool IsDeleted { get; set; } = false;
/// <summary>
/// JSON block for innate resistances/weaknesses (from skills, buffs, etc.)
/// Example: {"fire": 0.1, "poison": -0.2}
/// Stacks with gear resistances
/// </summary>
[MaxLength(1024)]
public string ResistancesJson { get; set; } = "{}";
/// <summary>
/// Helper to get/set resistances dictionary
/// </summary>
[NotMapped]
public Dictionary<string, float> Resistances
{
get
{
try { return JsonSerializer.Deserialize<Dictionary<string, float>>(ResistancesJson) ?? new(); }
catch { return new(); }
}
set { ResistancesJson = JsonSerializer.Serialize(value); }
}
// Navigation
public virtual Account? Account { get; set; }
public virtual ICollection<DungeonCharacterItem> Inventory { get; set; } = new List<DungeonCharacterItem>();
+23
View File
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using DataServer.Data.Enums;
namespace DataServer.Data.Entities;
@@ -80,5 +81,27 @@ public class DungeonItemDefinition
// Legacy field - kept for backwards compatibility
public int SpriteId { get; set; } = 0;
/// <summary>
/// JSON block for resistance bonuses when equipped
/// Example: {"fire": 0.15, "ice": 0.10}
/// Values are percentage (0.15 = 15% resistance)
/// </summary>
[MaxLength(1024)]
public string ResistancesJson { get; set; } = "{}";
/// <summary>
/// Helper to get/set resistances dictionary
/// </summary>
[NotMapped]
public Dictionary<string, float> Resistances
{
get
{
try { return JsonSerializer.Deserialize<Dictionary<string, float>>(ResistancesJson) ?? new(); }
catch { return new(); }
}
set { ResistancesJson = JsonSerializer.Serialize(value); }
}
public bool IsEnabled { get; set; } = true;
}