Mob AIv2 and player speed cap

This commit is contained in:
dingo
2025-12-27 11:09:09 -05:00
parent 4d26c37671
commit 9c67dd3935
14 changed files with 3479 additions and 34 deletions
+147 -3
View File
@@ -20,6 +20,45 @@ public class CarriedLootItem
public int Quantity { get; set; }
}
/// <summary>
/// Runtime state for a mob ability
/// </summary>
public class MobAbilityState
{
public int AbilityId { get; set; }
public MobAbilityDefinition Definition { get; set; } = null!;
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; }
/// <summary>
/// Check if this ability is available (off cooldown and HP in range)
/// </summary>
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;
}
}
/// <summary>
/// Active status effect on a mob
/// </summary>
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; }
}
/// <summary>
/// Runtime instance of a mob in a dungeon
/// </summary>
@@ -37,15 +76,73 @@ public class MobInstance
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;
/// <summary>Current phase for multi-phase mobs (0 = first phase)</summary>
public int CurrentPhase { get; set; } = 0;
/// <summary>Phase configurations loaded from definition</summary>
public List<MobPhaseConfig>? Phases { get; set; }
public ulong? TargetId { get; set; }
public long LastAttackTick { get; set; }
/// <summary>Time spent in current state (for behavior decisions)</summary>
public float StateTime { get; set; }
/// <summary>Last position for stuck detection</summary>
public float LastX { get; set; }
public float LastY { get; set; }
public float StuckTime { get; set; }
// === Abilities ===
/// <summary>Abilities this mob can use</summary>
public List<MobAbilityState> Abilities { get; set; } = new();
/// <summary>Currently casting ability (null if not casting)</summary>
public MobAbilityState? CastingAbility { get; set; }
/// <summary>Remaining cast time</summary>
public float CastTimeRemaining { get; set; }
/// <summary>Active status effects on this mob</summary>
public List<MobStatusEffect> StatusEffects { get; set; } = new();
/// <summary>Current animation being played</summary>
public string CurrentAnimation { get; set; } = "idle";
/// <summary>Direction mob is facing (down, up, left, right)</summary>
public string FacingDirection { get; set; } = "down";
// === Behavior-specific ===
/// <summary>Preferred combat distance (for ranged/skirmisher)</summary>
public float PreferredRange { get; set; } = 40f;
/// <summary>Flee threshold HP percentage</summary>
public float FleeThreshold { get; set; } = 0f;
/// <summary>Has already called for help this combat</summary>
public bool HasCalledForHelp { get; set; }
/// <summary>Patrol waypoints (for Patrol behavior)</summary>
public List<(float X, float Y)>? PatrolPath { get; set; }
/// <summary>Current patrol waypoint index</summary>
public int PatrolIndex { get; set; }
/// <summary>Enrage stacks (for Enrage behavior)</summary>
public int EnrageStacks { get; set; }
/// <summary>Time since combat started (for time-based mechanics)</summary>
public float CombatTime { get; set; }
// Visual - sprite configuration JSON
public string? SpriteConfigJson { get; set; }
public string TintColor { get; set; } = "#ffffff";
@@ -54,10 +151,53 @@ public class MobInstance
// Carried loot from player kills
public List<CarriedLoot> CarriedPlayerLoot { get; set; } = new();
/// <summary>
/// Check if this mob is carrying loot from player kills
/// </summary>
/// <summary>Check if this mob is carrying loot from player kills</summary>
public bool HasCarriedLoot => CarriedPlayerLoot.Count > 0;
/// <summary>Current HP as percentage (0-1)</summary>
public float HpPercent => MaxHealth > 0 ? (float)Health / MaxHealth : 0f;
/// <summary>Check if mob is stunned</summary>
public bool IsStunned => StatusEffects.Any(e => e.EffectType == "stun" && e.Duration > 0);
/// <summary>Check if mob is rooted</summary>
public bool IsRooted => StatusEffects.Any(e => e.EffectType == "root" && e.Duration > 0);
/// <summary>Check if mob is silenced</summary>
public bool IsSilenced => StatusEffects.Any(e => e.EffectType == "silence" && e.Duration > 0);
/// <summary>Get current speed modifier from status effects</summary>
public float GetSpeedModifier()
{
float modifier = 1.0f;
foreach (var effect in StatusEffects.Where(e => e.EffectType == "slow"))
{
modifier *= effect.Modifier;
}
return modifier;
}
/// <summary>Update facing direction based on movement</summary>
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";
}
}
/// <summary>Get the animation key with direction</summary>
public string GetDirectionalAnimation(string baseAnim)
{
return $"{baseAnim}_{FacingDirection}";
}
}
public enum MobState
@@ -65,7 +205,11 @@ 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
}