Files
systemrevivalserver/data/entities/DungeonItemDefinition.cs
T
2025-12-26 16:24:12 -05:00

141 lines
4.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using DataServer.Data.Enums;
namespace DataServer.Data.Entities;
/// <summary>
/// Item template/definition - what an item IS
/// </summary>
[Table("dungeon_item_definitions")]
public class DungeonItemDefinition
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(64)]
public string Name { get; set; } = "";
[MaxLength(256)]
public string Description { get; set; } = "";
public ItemType Type { get; set; }
public ItemRarity Rarity { get; set; } = ItemRarity.Common;
public DungeonEquipmentSlot? EquipSlot { get; set; } // Null if not equippable
// Stat requirements to equip/use
public int RequiredStrength { get; set; } = 0;
public int RequiredIntelligence { get; set; } = 0;
public int RequiredWisdom { get; set; } = 0;
public int RequiredDexterity { get; set; } = 0;
public int RequiredLevel { get; set; } = 1;
// Stat bonuses when equipped
public int BonusStrength { get; set; } = 0;
public int BonusIntelligence { get; set; } = 0;
public int BonusWisdom { get; set; } = 0;
public int BonusEndurance { get; set; } = 0;
public int BonusDexterity { get; set; } = 0;
public int BonusHealth { get; set; } = 0;
public int BonusMana { get; set; } = 0;
// Weapon stats
public int MinDamage { get; set; } = 0;
public int MaxDamage { get; set; } = 0;
public float AttackRange { get; set; } = 0; // 0 = melee
/// <summary>
/// Damage type key (references DamageResistanceType.Key)
/// e.g., "physical", "fire", "poison"
/// </summary>
[MaxLength(32)]
public string DamageTypeKey { get; set; } = "physical";
// Armor stats (flat damage reduction for all damage types)
public int Armor { get; set; } = 0;
// Consumable effects
public int HealAmount { get; set; } = 0;
public int ManaRestore { get; set; } = 0;
public int StaminaRestore { get; set; } = 0;
/// <summary>
/// Duration in seconds for consumable buff effects (resistances, stat boosts)
/// 0 = instant effect only, no buff
/// </summary>
public int BuffDuration { get; set; } = 0;
/// <summary>
/// JSON block for temporary resistance buffs when consumed
/// Example: {"fire": 0.25, "poison": 0.5}
/// Only applies if BuffDuration > 0
/// </summary>
[MaxLength(1024)]
public string BuffResistancesJson { get; set; } = "{}";
/// <summary>
/// Helper to get/set buff resistances dictionary
/// </summary>
[NotMapped]
public Dictionary<string, float> BuffResistances
{
get
{
try { return JsonSerializer.Deserialize<Dictionary<string, float>>(BuffResistancesJson) ?? new(); }
catch { return new(); }
}
set { BuffResistancesJson = JsonSerializer.Serialize(value); }
}
// Special
public bool IsTeleportScroll { get; set; } = false;
public int? TeachesSpellId { get; set; } // For spell tomes
// Stacking
public bool Stackable { get; set; } = false;
public int MaxStack { get; set; } = 1;
// Visuals
/// <summary>
/// Path to the item's sprite image on CDN (e.g., "textures/items/sword_iron.png")
/// If null/empty, client uses fallback placeholder based on item type
/// </summary>
[MaxLength(256)]
public string? SpritePath { get; set; }
/// <summary>
/// Optional color tint as hex (e.g., "#ff0000" for red tint)
/// </summary>
[MaxLength(16)]
public string? TintColor { get; set; }
// 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;
}