243 lines
8.8 KiB
C#
243 lines
8.8 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Text.Json;
|
|
using DataServer.Data.Enums;
|
|
|
|
namespace DataServer.Data.Entities;
|
|
|
|
/// <summary>
|
|
/// Monster/NPC template definition stored in database
|
|
/// </summary>
|
|
[Table("dungeon_mob_definitions")]
|
|
public class DungeonMobDefinition
|
|
{
|
|
[Key]
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(64)]
|
|
public string Name { get; set; } = "";
|
|
|
|
[MaxLength(256)]
|
|
public string Description { get; set; } = "";
|
|
|
|
public MobType Type { get; set; } = MobType.Normal;
|
|
public MobCategory Category { get; set; } = MobCategory.Undead;
|
|
|
|
/// <summary>
|
|
/// AI behavior pattern for this mob
|
|
/// </summary>
|
|
public MobBehavior Behavior { get; set; } = MobBehavior.Aggressive;
|
|
|
|
public int MinTier { get; set; } = 1; // Minimum dungeon tier to spawn
|
|
public int MaxTier { get; set; } = 99; // Maximum tier (for progression gating)
|
|
|
|
// Base Combat Stats
|
|
public int BaseHealth { get; set; } = 50;
|
|
public int BaseMana { get; set; } = 0;
|
|
public int BasePhysicalDamage { get; set; } = 5;
|
|
public int BaseMagicDamage { get; set; } = 0;
|
|
public int BaseArmor { get; set; } = 0;
|
|
public int BaseMagicResist { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Primary damage type key (references DamageResistanceType.Key)
|
|
/// e.g., "physical", "fire", "poison"
|
|
/// </summary>
|
|
[MaxLength(32)]
|
|
public string DamageTypeKey { get; set; } = "physical";
|
|
|
|
// Movement & Combat
|
|
public float MoveSpeed { get; set; } = 60f;
|
|
public float AttackRange { get; set; } = 40f; // Melee range ~40, ranged 150+
|
|
public float AttackSpeed { get; set; } = 1.0f; // Attacks per second
|
|
public float AggroRange { get; set; } = 150f; // Detection radius
|
|
public float LeashRange { get; set; } = 400f; // Max chase distance before reset
|
|
|
|
/// <summary>
|
|
/// Preferred combat distance (for ranged/skirmisher behaviors)
|
|
/// </summary>
|
|
public float PreferredRange { get; set; } = 40f;
|
|
|
|
/// <summary>
|
|
/// Flee threshold - if HP drops below this %, mob may flee (for skirmisher/defensive)
|
|
/// </summary>
|
|
public float FleeThreshold { get; set; } = 0f;
|
|
|
|
/// <summary>
|
|
/// Call for help radius - alerts nearby mobs when engaged
|
|
/// </summary>
|
|
public float CallForHelpRadius { get; set; } = 0f;
|
|
|
|
// Scaling per dungeon tier (multipliers)
|
|
public float HealthPerTier { get; set; } = 1.2f;
|
|
public float DamagePerTier { get; set; } = 1.15f;
|
|
public float ArmorPerTier { get; set; } = 1.1f;
|
|
|
|
// Experience & Loot
|
|
public int BaseXp { get; set; } = 10;
|
|
public float XpPerTier { get; set; } = 1.25f;
|
|
public int LootTableId { get; set; } = 0; // Reference to loot_tables
|
|
public float DropChanceMultiplier { get; set; } = 1.0f;
|
|
|
|
/// <summary>
|
|
/// JSON block for resistances/weaknesses
|
|
/// Example: {"fire": -0.25, "ice": 0.5, "poison": 1.0}
|
|
/// Negative = weakness (takes more damage), Positive = resistance (takes less), 1.0 = immune
|
|
/// </summary>
|
|
[MaxLength(1024)]
|
|
public string ResistancesJson { get; set; } = "{}";
|
|
|
|
/// <summary>
|
|
/// JSON block for boss phases (for multi-phase bosses)
|
|
/// Example: [{"hpThreshold": 0.75, "behavior": "Enrage"}, {"hpThreshold": 0.25, "behavior": "Summoner"}]
|
|
/// </summary>
|
|
[MaxLength(2048)]
|
|
public string? PhasesJson { get; set; }
|
|
|
|
// Visuals
|
|
/// <summary>
|
|
/// JSON configuration for mob sprites and animations
|
|
/// Structure: {
|
|
/// "spriteSheet": "textures/mobs/skeleton.png",
|
|
/// "frameWidth": 64,
|
|
/// "frameHeight": 64,
|
|
/// "animations": {
|
|
/// "idle_down": {"row": 0, "frames": 4, "fps": 4, "loop": true},
|
|
/// "idle_up": {"row": 1, "frames": 4, "fps": 4, "loop": true},
|
|
/// "idle_left": {"row": 2, "frames": 4, "fps": 4, "loop": true},
|
|
/// "idle_right": {"row": 3, "frames": 4, "fps": 4, "loop": true},
|
|
/// "walk_down": {"row": 4, "frames": 8, "fps": 8, "loop": true},
|
|
/// "walk_up": {"row": 5, "frames": 8, "fps": 8, "loop": true},
|
|
/// "walk_left": {"row": 6, "frames": 8, "fps": 8, "loop": true},
|
|
/// "walk_right": {"row": 7, "frames": 8, "fps": 8, "loop": true},
|
|
/// "attack_down": {"row": 8, "frames": 6, "fps": 12, "loop": false},
|
|
/// "attack_up": {"row": 9, "frames": 6, "fps": 12, "loop": false},
|
|
/// "attack_left": {"row": 10, "frames": 6, "fps": 12, "loop": false},
|
|
/// "attack_right": {"row": 11, "frames": 6, "fps": 12, "loop": false},
|
|
/// "cast_down": {"row": 12, "frames": 8, "fps": 10, "loop": false},
|
|
/// "death": {"row": 16, "frames": 6, "fps": 8, "loop": false}
|
|
/// }
|
|
/// }
|
|
/// </summary>
|
|
[MaxLength(8192)]
|
|
public string? SpriteConfigJson { get; set; }
|
|
|
|
/// <summary>
|
|
/// Color tint applied to the mob (hex, e.g., "#ff0000" for red variant)
|
|
/// </summary>
|
|
[MaxLength(16)]
|
|
public string TintColor { get; set; } = "#ffffff";
|
|
|
|
/// <summary>
|
|
/// Scale multiplier for the mob (1.0 = normal size)
|
|
/// </summary>
|
|
public float Scale { get; set; } = 1.0f;
|
|
|
|
public float AnimationSpeed { get; set; } = 8f; // Frames per second
|
|
|
|
public bool IsEnabled { get; set; } = true;
|
|
|
|
// === Navigation Properties ===
|
|
/// <summary>
|
|
/// Abilities assigned to this mob
|
|
/// </summary>
|
|
public ICollection<MobAbilityAssignment> AbilityAssignments { get; set; } = new List<MobAbilityAssignment>();
|
|
|
|
// Helper to get parsed sprite config
|
|
[NotMapped]
|
|
public Dictionary<string, object>? SpriteConfig
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(SpriteConfigJson)) return null;
|
|
try { return System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>>(SpriteConfigJson); }
|
|
catch { return null; }
|
|
}
|
|
}
|
|
|
|
// Helper methods for JSON parsing
|
|
[NotMapped]
|
|
public Dictionary<string, float> Resistances
|
|
{
|
|
get
|
|
{
|
|
try { return JsonSerializer.Deserialize<Dictionary<string, float>>(ResistancesJson) ?? new(); }
|
|
catch { return new(); }
|
|
}
|
|
set { ResistancesJson = JsonSerializer.Serialize(value); }
|
|
}
|
|
|
|
[NotMapped]
|
|
public List<MobPhaseConfig>? Phases
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(PhasesJson)) return null;
|
|
try { return JsonSerializer.Deserialize<List<MobPhaseConfig>>(PhasesJson); }
|
|
catch { return null; }
|
|
}
|
|
set { PhasesJson = value != null ? JsonSerializer.Serialize(value) : null; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calculate scaled stats for a specific level bracket
|
|
/// Level bracket scaling: each bracket adds 15% to base stats
|
|
/// </summary>
|
|
public DungeonMobCombatStats GetStatsForBracket(int bracketMin)
|
|
{
|
|
// Calculate bracket number (1-10 = bracket 1, 11-20 = bracket 2, etc.)
|
|
int bracketNumber = Math.Max(1, (bracketMin - 1) / 10 + 1);
|
|
|
|
// Bracket scaling: each bracket adds 15% to base stats (compound)
|
|
double bracketMultiplier = Math.Pow(1.15, bracketNumber - 1);
|
|
|
|
// Calculate scaled damage values
|
|
int physDmg = (int)(BasePhysicalDamage * DamagePerTier * bracketMultiplier);
|
|
int magicDmg = (int)(BaseMagicDamage * DamagePerTier * bracketMultiplier);
|
|
|
|
// Safety: if both physical and magic damage are 0, set physical to 5 as fallback
|
|
if (physDmg == 0 && magicDmg == 0)
|
|
{
|
|
physDmg = 5;
|
|
}
|
|
|
|
return new DungeonMobCombatStats
|
|
{
|
|
MaxHealth = (int)(BaseHealth * HealthPerTier * bracketMultiplier),
|
|
PhysicalDamage = physDmg,
|
|
MagicDamage = magicDmg,
|
|
Armor = (int)(BaseArmor * ArmorPerTier * bracketMultiplier),
|
|
MoveSpeed = MoveSpeed,
|
|
AttackRange = AttackRange,
|
|
AttackSpeed = AttackSpeed,
|
|
AggroRange = AggroRange,
|
|
LeashRange = LeashRange,
|
|
XpReward = (int)(BaseXp * XpPerTier * bracketMultiplier),
|
|
Resistances = Resistances,
|
|
DamageTypeKey = DamageTypeKey
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configuration for a boss phase
|
|
/// </summary>
|
|
public class MobPhaseConfig
|
|
{
|
|
/// <summary>HP threshold to trigger this phase (0-1)</summary>
|
|
public float HpThreshold { get; set; }
|
|
|
|
/// <summary>New behavior for this phase</summary>
|
|
public MobBehavior Behavior { get; set; }
|
|
|
|
/// <summary>Speed multiplier for this phase</summary>
|
|
public float SpeedMultiplier { get; set; } = 1.0f;
|
|
|
|
/// <summary>Damage multiplier for this phase</summary>
|
|
public float DamageMultiplier { get; set; } = 1.0f;
|
|
|
|
/// <summary>Optional message to display when entering phase</summary>
|
|
public string? PhaseMessage { get; set; }
|
|
}
|