using DataServer.Data.Entities; using DataServer.Data.Enums; namespace GameServer.Dungeon; /// /// Loot carried by a mob from killing a player /// public class CarriedLoot { public ulong VictimCharacterId { get; set; } public string VictimName { get; set; } = ""; public List Items { get; set; } = new(); public long Gold { get; set; } } public class CarriedLootItem { public int ItemDefinitionId { get; set; } public int Quantity { get; set; } } /// /// Runtime state for a mob ability /// public class MobAbilityState { public int AbilityId { get; set; } public MobAbilityDefinition Definition { get; set; } = null!; public string ResolvedAnimationKey { get; set; } = "attack"; public float CooldownRemaining { get; set; } public int Priority { get; set; } public int Phase { get; set; } public float? MinHpPercent { get; set; } public float? MaxHpPercent { get; set; } /// /// Check if this ability is available (off cooldown and HP in range) /// public bool IsAvailable(float currentHpPercent) { if (CooldownRemaining > 0) return false; if (MinHpPercent.HasValue && currentHpPercent < MinHpPercent.Value) return false; if (MaxHpPercent.HasValue && currentHpPercent > MaxHpPercent.Value) return false; return true; } } /// /// Active status effect on a mob /// public class MobStatusEffect { public string EffectType { get; set; } = ""; // poison, bleed, burn, slow, stun, etc. public float Duration { get; set; } public float TickInterval { get; set; } public float NextTickIn { get; set; } public int DamagePerTick { get; set; } public float Modifier { get; set; } = 1.0f; // For slow, etc. public ulong SourcePlayerId { get; set; } } /// /// Runtime instance of a mob in a dungeon /// public class MobInstance { public int Id { get; set; } public int DefinitionId { get; set; } public string Name { get; set; } = ""; public float X { get; set; } public float Y { get; set; } public float Rotation { get; set; } public float SpawnX { get; set; } public float SpawnY { get; set; } public int Health { get; set; } public int MaxHealth { get; set; } public int Mana { get; set; } public int MaxMana { get; set; } public bool IsAlive { get; set; } = true; public DungeonMobCombatStats Stats { get; set; } = new(); public MobState State { get; set; } = MobState.Idle; public MobType Type { get; set; } public MobBehavior Behavior { get; set; } = MobBehavior.Aggressive; /// Current phase for multi-phase mobs (0 = first phase) public int CurrentPhase { get; set; } = 0; /// Phase configurations loaded from definition public List? Phases { get; set; } public ulong? TargetId { get; set; } public long LastAttackTick { get; set; } /// Time spent in current state (for behavior decisions) public float StateTime { get; set; } /// Last position for stuck detection public float LastX { get; set; } public float LastY { get; set; } public float StuckTime { get; set; } // === Abilities === /// Abilities this mob can use public List Abilities { get; set; } = new(); /// Last ability key used by this mob (for anti-repeat selection). public string? LastUsedAbilityKey { get; set; } /// How many times in a row the same ability has been used. public int ConsecutiveAbilityUses { get; set; } /// Currently casting ability (null if not casting) public MobAbilityState? CastingAbility { get; set; } /// Remaining cast time public float CastTimeRemaining { get; set; } /// Active status effects on this mob public List StatusEffects { get; set; } = new(); /// Current animation being played public string CurrentAnimation { get; set; } = "idle"; /// Direction mob is facing (down, up, left, right) public string FacingDirection { get; set; } = "down"; // === Behavior-specific === /// Preferred combat distance (for ranged/skirmisher) public float PreferredRange { get; set; } = 40f; /// Flee threshold HP percentage public float FleeThreshold { get; set; } = 0f; /// Has already called for help this combat public bool HasCalledForHelp { get; set; } /// Wander target X when idle public float WanderTargetX { get; set; } /// Wander target Y when idle public float WanderTargetY { get; set; } /// Patrol waypoints (for Patrol behavior) public List<(float X, float Y)>? PatrolPath { get; set; } /// Current patrol waypoint index public int PatrolIndex { get; set; } /// Enrage stacks (for Enrage behavior) public int EnrageStacks { get; set; } /// Time since combat started (for time-based mechanics) public float CombatTime { get; set; } // Visual - sprite configuration JSON public string? SpriteConfigJson { get; set; } public string TintColor { get; set; } = "#ffffff"; public float Scale { get; set; } = 1.0f; // Carried loot from player kills public List CarriedPlayerLoot { get; set; } = new(); /// Check if this mob is carrying loot from player kills public bool HasCarriedLoot => CarriedPlayerLoot.Count > 0; // Death loot - generated when mob dies, lootable by players public List? DeathLoot { get; set; } public long DeathLootGold { get; set; } // Corpse cleanup tracking public long? LootEmptiedAtTick { get; set; } // Tick when loot became empty (for corpse removal timer) /// Check if this mob has loot available public bool HasDeathLoot => DeathLoot != null && (DeathLoot.Count > 0 || DeathLootGold > 0); /// Current HP as percentage (0-1) public float HpPercent => MaxHealth > 0 ? (float)Health / MaxHealth : 0f; /// Check if mob is stunned public bool IsStunned => StatusEffects.Any(e => e.EffectType == "stun" && e.Duration > 0); /// Check if mob is rooted public bool IsRooted => StatusEffects.Any(e => e.EffectType == "root" && e.Duration > 0); /// Check if mob is silenced public bool IsSilenced => StatusEffects.Any(e => e.EffectType == "silence" && e.Duration > 0); /// Get current speed modifier from status effects public float GetSpeedModifier() { float modifier = 1.0f; foreach (var effect in StatusEffects.Where(e => e.EffectType == "slow")) { modifier *= effect.Modifier; } return modifier; } /// Update facing direction based on movement public void UpdateFacingDirection(float targetX, float targetY) { float dx = targetX - X; float dy = targetY - Y; if (Math.Abs(dx) > Math.Abs(dy)) { FacingDirection = dx > 0 ? "right" : "left"; } else { FacingDirection = dy > 0 ? "down" : "up"; } } /// Get the animation key with direction public string GetDirectionalAnimation(string baseAnim) { return $"{baseAnim}_{FacingDirection}"; } } public enum MobState { Idle, Chasing, Attacking, Casting, Returning, Fleeing, Kiting, // Moving away while attacking (skirmisher) Summoning, // In summoning animation Healing, // Healing self or ally Dead, Walking, Damaged }