MobAIv2P3
This commit is contained in:
+534
-190
@@ -8,6 +8,8 @@ namespace Server.Game.Dungeon;
|
||||
/// </summary>
|
||||
public static class MobAI
|
||||
{
|
||||
private static readonly Random _rng = new();
|
||||
|
||||
/// <summary>
|
||||
/// Main AI update - called each tick for each mob
|
||||
/// </summary>
|
||||
@@ -36,6 +38,7 @@ public static class MobAI
|
||||
ExecuteAbility(mob, mob.CastingAbility, sim);
|
||||
mob.CastingAbility = null;
|
||||
mob.State = MobState.Idle;
|
||||
mob.StateTime = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -55,14 +58,25 @@ public static class MobAI
|
||||
case MobBehavior.Skirmisher:
|
||||
UpdateSkirmisher(mob, sim, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Summoner:
|
||||
case MobBehavior.Tank:
|
||||
UpdateTank(mob, sim, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Assassin:
|
||||
UpdateAssassin(mob, sim, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Healer:
|
||||
UpdateHealer(mob, sim, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Patrol:
|
||||
UpdatePatrol(mob, sim, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Pack:
|
||||
// For now, fall back to aggressive behavior
|
||||
// TODO: Implement specialized behaviors
|
||||
UpdatePack(mob, sim, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Summoner:
|
||||
UpdateSummoner(mob, sim, deltaTime);
|
||||
break;
|
||||
default:
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
break;
|
||||
}
|
||||
@@ -70,185 +84,631 @@ public static class MobAI
|
||||
|
||||
#region Core Behaviors
|
||||
|
||||
/// <summary>
|
||||
/// Aggressive: Charges player on sight, melee attacks. Wanders when idle.
|
||||
/// </summary>
|
||||
private static void UpdateAggressive(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
// No target - wander or return to spawn area
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
// Check leash range
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
mob.CombatTime += deltaTime;
|
||||
|
||||
// Try to use abilities
|
||||
var ability = SelectAbility(mob, distance);
|
||||
if (ability != null && TryUseAbility(mob, ability, target, sim))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Chase and melee
|
||||
// In attack range?
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
}
|
||||
else if (distance <= mob.Stats.LeashRange)
|
||||
{
|
||||
mob.State = MobState.Chasing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * mob.GetSpeedModifier() * deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
// Chase
|
||||
mob.State = MobState.Chasing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defensive: Only attacks if player comes close to spawn. Wanders near spawn.
|
||||
/// </summary>
|
||||
private static void UpdateDefensive(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
float targetDistFromSpawn = GetDistance(target.X, target.Y, mob.SpawnX, mob.SpawnY);
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
|
||||
if (targetDistFromSpawn <= mob.Stats.AggroRange)
|
||||
// Only fight if target is close to our spawn area
|
||||
if (targetDistFromSpawn <= mob.Stats.AggroRange * 0.75f)
|
||||
{
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
// Don't stray too far from spawn
|
||||
if (distFromSpawn > mob.Stats.LeashRange * 0.5f)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
var ability = SelectAbility(mob, distance);
|
||||
if (ability != null && TryUseAbility(mob, ability, target, sim))
|
||||
{
|
||||
return;
|
||||
}
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Chasing;
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 0.7f * deltaTime);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 0.7f * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.TargetId = null;
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
}
|
||||
|
||||
// No threat - wander near spawn
|
||||
mob.TargetId = null;
|
||||
UpdateIdleWander(mob, sim, deltaTime, wanderRadius: 80f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ranged: Keeps distance, fires projectiles
|
||||
/// </summary>
|
||||
private static void UpdateRanged(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
mob.CombatTime += deltaTime;
|
||||
|
||||
var ability = SelectAbility(mob, distance, preferRanged: true);
|
||||
if (ability != null && TryUseAbility(mob, ability, target, sim))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Maintain preferred range
|
||||
if (distance < mob.PreferredRange * 0.6f)
|
||||
float preferredRange = mob.PreferredRange > 0 ? mob.PreferredRange : 120f;
|
||||
|
||||
if (distance < preferredRange * 0.5f)
|
||||
{
|
||||
// Too close, back up
|
||||
mob.State = MobState.Kiting;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
}
|
||||
else if (distance > mob.PreferredRange * 1.2f && distance <= mob.Stats.LeashRange)
|
||||
else if (distance > preferredRange * 1.3f && distance <= mob.Stats.LeashRange)
|
||||
{
|
||||
// Too far, move closer
|
||||
mob.State = MobState.Chasing;
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime);
|
||||
}
|
||||
else if (distance > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Good range, attack
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skirmisher: Hit-and-run tactics
|
||||
/// </summary>
|
||||
private static void UpdateSkirmisher(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (mob.HpPercent <= mob.FleeThreshold && mob.FleeThreshold > 0)
|
||||
// Check flee threshold
|
||||
if (mob.FleeThreshold > 0 && mob.HpPercent <= mob.FleeThreshold)
|
||||
{
|
||||
mob.State = MobState.Fleeing;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.2f * deltaTime);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.3f * deltaTime, sim);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attack then retreat pattern
|
||||
if (mob.State == MobState.Attacking && mob.StateTime < 2.0f)
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
var ability = SelectAbility(mob, distance);
|
||||
if (ability != null && TryUseAbility(mob, ability, target, sim))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
// Cycle between attack (2s) and retreat (2s)
|
||||
float cycleTime = mob.StateTime % 4f;
|
||||
|
||||
if (cycleTime < 2f)
|
||||
{
|
||||
// Attack phase
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime);
|
||||
mob.State = MobState.Chasing;
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.2f * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
else if (mob.StateTime < 4.0f)
|
||||
{
|
||||
mob.State = MobState.Kiting;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.StateTime = 0;
|
||||
// Retreat phase
|
||||
mob.State = MobState.Kiting;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tank: Slow but tough, always moves toward target
|
||||
/// </summary>
|
||||
private static void UpdateTank(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime, wanderRadius: 50f);
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Chasing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
// Tanks move at 60% speed
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 0.6f * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assassin: Targets lowest HP player, moves fast
|
||||
/// </summary>
|
||||
private static void UpdateAssassin(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
// Target lowest HP player
|
||||
var target = sim.Players.Values
|
||||
.Where(p => p.IsAlive)
|
||||
.Where(p => GetDistance(mob.X, mob.Y, p.X, p.Y) <= mob.Stats.AggroRange)
|
||||
.OrderBy(p => p.Health / p.MaxHealth)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Chasing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
// Assassins move at 130% speed
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.3f * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Healer: Heals nearby mobs, stays back from combat
|
||||
/// </summary>
|
||||
private static void UpdateHealer(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
// Check for injured allies first
|
||||
var injuredAlly = sim.Mobs.Values
|
||||
.Where(m => m.IsAlive && m.Id != mob.Id)
|
||||
.Where(m => GetDistance(mob.X, mob.Y, m.X, m.Y) <= 150f)
|
||||
.Where(m => m.HpPercent < 0.7f)
|
||||
.OrderBy(m => m.HpPercent)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (injuredAlly != null)
|
||||
{
|
||||
// Try to heal
|
||||
var healAbility = mob.Abilities
|
||||
.Where(a => a.Definition.AbilityType == MobAbilityType.HealAlly ||
|
||||
a.Definition.AbilityType == MobAbilityType.HealAoe)
|
||||
.Where(a => a.IsAvailable(mob.HpPercent))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (healAbility != null)
|
||||
{
|
||||
mob.State = MobState.Healing;
|
||||
mob.UpdateFacingDirection(injuredAlly.X, injuredAlly.Y);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("cast");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, stay back from combat
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
if (target != null)
|
||||
{
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
float preferredRange = mob.PreferredRange > 0 ? mob.PreferredRange : 150f;
|
||||
|
||||
if (distance < preferredRange)
|
||||
{
|
||||
mob.State = MobState.Kiting;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
}
|
||||
else if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Patrol: Walks a path, alerts others when seeing players
|
||||
/// </summary>
|
||||
private static void UpdatePatrol(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
// Alert nearby mobs
|
||||
if (!mob.HasCalledForHelp)
|
||||
{
|
||||
CallForHelp(mob, sim);
|
||||
}
|
||||
|
||||
// Then fight like aggressive
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.HasCalledForHelp = false;
|
||||
|
||||
// Patrol - wander in a larger area
|
||||
UpdateIdleWander(mob, sim, deltaTime, wanderRadius: 150f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pack: Calls nearby mobs when engaged
|
||||
/// </summary>
|
||||
private static void UpdatePack(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
if (!mob.HasCalledForHelp)
|
||||
{
|
||||
CallForHelp(mob, sim);
|
||||
}
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.HasCalledForHelp = false;
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Summoner: Stays back and summons minions
|
||||
/// </summary>
|
||||
private static void UpdateSummoner(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
float preferredRange = mob.PreferredRange > 0 ? mob.PreferredRange : 200f;
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
// Stay back
|
||||
if (distance < preferredRange * 0.5f)
|
||||
{
|
||||
mob.State = MobState.Kiting;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Summoning;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("cast");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Idle & Wander
|
||||
|
||||
/// <summary>
|
||||
/// Wander around spawn area when no targets
|
||||
/// </summary>
|
||||
private static void UpdateIdleWander(MobInstance mob, DungeonSimulation sim, float deltaTime, float wanderRadius = 100f)
|
||||
{
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
// Too far from spawn? Return first
|
||||
if (distFromSpawn > wanderRadius)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
// Heal when idle
|
||||
if (mob.Health < mob.MaxHealth)
|
||||
{
|
||||
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.02f * deltaTime));
|
||||
}
|
||||
|
||||
// Check if we need a new wander target
|
||||
if (mob.State != MobState.Idle || mob.StateTime > 3f ||
|
||||
(mob.WanderTargetX == 0 && mob.WanderTargetY == 0))
|
||||
{
|
||||
// Pick a new random wander point near spawn
|
||||
float angle = (float)(_rng.NextDouble() * Math.PI * 2);
|
||||
float dist = (float)(_rng.NextDouble() * wanderRadius * 0.7f);
|
||||
|
||||
mob.WanderTargetX = mob.SpawnX + MathF.Cos(angle) * dist;
|
||||
mob.WanderTargetY = mob.SpawnY + MathF.Sin(angle) * dist;
|
||||
mob.StateTime = 0;
|
||||
|
||||
// Sometimes just idle for a bit
|
||||
if (_rng.NextDouble() < 0.3f)
|
||||
{
|
||||
mob.State = MobState.Idle;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("idle");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Move toward wander target
|
||||
float distToTarget = GetDistance(mob.X, mob.Y, mob.WanderTargetX, mob.WanderTargetY);
|
||||
|
||||
if (distToTarget < 10f)
|
||||
{
|
||||
// Reached target, idle for a bit
|
||||
mob.State = MobState.Idle;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("idle");
|
||||
mob.StateTime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Idle; // Still "idle" but moving
|
||||
mob.UpdateFacingDirection(mob.WanderTargetX, mob.WanderTargetY);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
// Wander slowly
|
||||
MoveToward(mob, mob.WanderTargetX, mob.WanderTargetY, mob.Stats.MoveSpeed * 0.3f * deltaTime, sim);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReturnToSpawn(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
float dist = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (dist < 20f)
|
||||
{
|
||||
mob.State = MobState.Idle;
|
||||
mob.TargetId = null;
|
||||
mob.CombatTime = 0;
|
||||
mob.StateTime = 0;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("idle");
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Returning;
|
||||
mob.TargetId = null;
|
||||
mob.UpdateFacingDirection(mob.SpawnX, mob.SpawnY);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, mob.SpawnX, mob.SpawnY, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
|
||||
// Heal while returning
|
||||
if (mob.Health < mob.MaxHealth)
|
||||
{
|
||||
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.05f * deltaTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CallForHelp(MobInstance mob, DungeonSimulation sim)
|
||||
{
|
||||
mob.HasCalledForHelp = true;
|
||||
float helpRadius = mob.Stats.AggroRange * 1.5f;
|
||||
|
||||
foreach (var ally in sim.Mobs.Values.Where(m => m.IsAlive && m.Id != mob.Id))
|
||||
{
|
||||
if (GetDistance(mob.X, mob.Y, ally.X, ally.Y) <= helpRadius)
|
||||
{
|
||||
// Alert ally to our target
|
||||
if (mob.TargetId.HasValue && ally.TargetId == null)
|
||||
{
|
||||
ally.TargetId = mob.TargetId;
|
||||
ally.State = MobState.Chasing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Movement with Collision
|
||||
|
||||
private static void MoveToward(MobInstance mob, float targetX, float targetY, float speed, DungeonSimulation sim)
|
||||
{
|
||||
if (mob.IsRooted) return;
|
||||
|
||||
float dx = targetX - mob.X;
|
||||
float dy = targetY - mob.Y;
|
||||
float dist = MathF.Sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < 1f) return;
|
||||
|
||||
float moveX = (dx / dist) * speed;
|
||||
float moveY = (dy / dist) * speed;
|
||||
|
||||
float newX = mob.X + moveX;
|
||||
float newY = mob.Y + moveY;
|
||||
|
||||
// Check collision for each axis separately
|
||||
if (sim.CanMoveTo(newX, mob.Y))
|
||||
{
|
||||
mob.X = newX;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try sliding along wall
|
||||
mob.StuckTime += 0.05f;
|
||||
}
|
||||
|
||||
if (sim.CanMoveTo(mob.X, newY))
|
||||
{
|
||||
mob.Y = newY;
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.StuckTime += 0.05f;
|
||||
}
|
||||
|
||||
// If stuck for too long, try to unstick
|
||||
if (mob.StuckTime > 1f)
|
||||
{
|
||||
TryUnstick(mob, sim);
|
||||
mob.StuckTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveAwayFrom(MobInstance mob, float targetX, float targetY, float speed, DungeonSimulation sim)
|
||||
{
|
||||
if (mob.IsRooted) return;
|
||||
|
||||
float dx = mob.X - targetX;
|
||||
float dy = mob.Y - targetY;
|
||||
float dist = MathF.Sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < 1f) return;
|
||||
|
||||
float moveX = (dx / dist) * speed;
|
||||
float moveY = (dy / dist) * speed;
|
||||
|
||||
float newX = mob.X + moveX;
|
||||
float newY = mob.Y + moveY;
|
||||
|
||||
if (sim.CanMoveTo(newX, mob.Y))
|
||||
{
|
||||
mob.X = newX;
|
||||
}
|
||||
|
||||
if (sim.CanMoveTo(mob.X, newY))
|
||||
{
|
||||
mob.Y = newY;
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryUnstick(MobInstance mob, DungeonSimulation sim)
|
||||
{
|
||||
// Try moving in cardinal directions to get unstuck
|
||||
float[] offsets = { 16, -16 };
|
||||
|
||||
foreach (float ox in offsets)
|
||||
{
|
||||
if (sim.CanMoveTo(mob.X + ox, mob.Y))
|
||||
{
|
||||
mob.X += ox * 0.5f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (float oy in offsets)
|
||||
{
|
||||
if (sim.CanMoveTo(mob.X, mob.Y + oy))
|
||||
{
|
||||
mob.Y += oy * 0.5f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,71 +716,11 @@ public static class MobAI
|
||||
|
||||
#region Ability System
|
||||
|
||||
private static MobAbilityState? SelectAbility(MobInstance mob, float distance, bool preferRanged = false)
|
||||
{
|
||||
var available = mob.Abilities
|
||||
.Where(a => a.IsAvailable(mob.HpPercent))
|
||||
.Where(a => a.Phase == 0 || a.Phase == mob.CurrentPhase)
|
||||
.Where(a => a.Definition.Range >= distance || a.Definition.Range == 0)
|
||||
.ToList();
|
||||
|
||||
if (preferRanged)
|
||||
{
|
||||
available = available
|
||||
.Where(a => a.Definition.AbilityType == MobAbilityType.ProjectileSingle ||
|
||||
a.Definition.AbilityType == MobAbilityType.ProjectileAoe)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (available.Count == 0) return null;
|
||||
|
||||
// Weight by priority
|
||||
var weighted = available.OrderByDescending(a => a.Priority).ToList();
|
||||
|
||||
// Add some randomness
|
||||
if (weighted.Count > 1 && Random.Shared.NextDouble() < 0.3)
|
||||
{
|
||||
return weighted[Random.Shared.Next(weighted.Count)];
|
||||
}
|
||||
|
||||
return weighted.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static bool TryUseAbility(MobInstance mob, MobAbilityState ability, PlayerInstance target, DungeonSimulation sim)
|
||||
{
|
||||
if (!ability.IsAvailable(mob.HpPercent)) return false;
|
||||
if (mob.IsSilenced && ability.Definition.CastTime > 0) return false;
|
||||
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
if (ability.Definition.Range > 0 && distance > ability.Definition.Range) return false;
|
||||
|
||||
// Check mana cost
|
||||
if (ability.Definition.ManaCost > mob.Mana) return false;
|
||||
|
||||
// Start casting
|
||||
if (ability.Definition.CastTime > 0)
|
||||
{
|
||||
mob.CastingAbility = ability;
|
||||
mob.CastTimeRemaining = ability.Definition.CastTime;
|
||||
mob.State = MobState.Casting;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation(ability.Definition.AnimationKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Instant ability
|
||||
ExecuteAbility(mob, ability, sim);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void ExecuteAbility(MobInstance mob, MobAbilityState ability, DungeonSimulation sim)
|
||||
{
|
||||
ability.CooldownRemaining = ability.Definition.Cooldown;
|
||||
mob.Mana -= ability.Definition.ManaCost;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation(ability.Definition.AnimationKey);
|
||||
|
||||
// TODO: Queue the ability effect for the simulation to process
|
||||
// For now, abilities are tracked but effects need to be wired up in DungeonSimulation
|
||||
// The simulation will need to check mob.CastingAbility and process effects there
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -344,7 +744,6 @@ public static class MobAI
|
||||
{
|
||||
effect.Duration -= deltaTime;
|
||||
|
||||
// Handle DOT
|
||||
if (effect.DamagePerTick > 0)
|
||||
{
|
||||
effect.NextTickIn -= deltaTime;
|
||||
@@ -396,61 +795,6 @@ public static class MobAI
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static void ReturnToSpawn(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
{
|
||||
float dist = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
if (dist < 10f)
|
||||
{
|
||||
mob.State = MobState.Idle;
|
||||
mob.TargetId = null;
|
||||
mob.CombatTime = 0;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("idle");
|
||||
|
||||
// Heal when returning
|
||||
if (mob.Health < mob.MaxHealth)
|
||||
{
|
||||
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.1f * deltaTime));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Returning;
|
||||
mob.UpdateFacingDirection(mob.SpawnX, mob.SpawnY);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, mob.SpawnX, mob.SpawnY, mob.Stats.MoveSpeed * deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveToward(MobInstance mob, float targetX, float targetY, float speed)
|
||||
{
|
||||
if (mob.IsRooted) return;
|
||||
|
||||
float dx = targetX - mob.X;
|
||||
float dy = targetY - mob.Y;
|
||||
float dist = MathF.Sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist > 0)
|
||||
{
|
||||
mob.X += (dx / dist) * speed;
|
||||
mob.Y += (dy / dist) * speed;
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveAwayFrom(MobInstance mob, float targetX, float targetY, float speed)
|
||||
{
|
||||
if (mob.IsRooted) return;
|
||||
|
||||
float dx = mob.X - targetX;
|
||||
float dy = mob.Y - targetY;
|
||||
float dist = MathF.Sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist > 0)
|
||||
{
|
||||
mob.X += (dx / dist) * speed;
|
||||
mob.Y += (dy / dist) * speed;
|
||||
}
|
||||
}
|
||||
|
||||
private static float GetDistance(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
float dx = x2 - x1;
|
||||
|
||||
@@ -131,6 +131,12 @@ public class MobInstance
|
||||
/// <summary>Has already called for help this combat</summary>
|
||||
public bool HasCalledForHelp { get; set; }
|
||||
|
||||
/// <summary>Wander target X when idle</summary>
|
||||
public float WanderTargetX { get; set; }
|
||||
|
||||
/// <summary>Wander target Y when idle</summary>
|
||||
public float WanderTargetY { get; set; }
|
||||
|
||||
/// <summary>Patrol waypoints (for Patrol behavior)</summary>
|
||||
public List<(float X, float Y)>? PatrolPath { get; set; }
|
||||
|
||||
|
||||
+1941
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SystemRevivalServer.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class MobAiv2P3 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
@page "/admin/abilities/edit"
|
||||
@model Abilities.EditModel
|
||||
@using DataServer.Data.Enums
|
||||
@{
|
||||
ViewData["Title"] = Model.Ability.Id > 0 ? $"Edit: {Model.Ability.Name}" : "New Ability";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<a href="/admin/abilities" class="text-gray-400 hover:text-white text-sm">← Back to Abilities</a>
|
||||
<h1 class="text-3xl font-bold text-white mt-2">@ViewData["Title"]</h1>
|
||||
@if (Model.AssignmentCount > 0)
|
||||
{
|
||||
<p class="text-gray-400 mt-1">Assigned to @Model.AssignmentCount mob(s)</p>
|
||||
}
|
||||
</div>
|
||||
@if (Model.Ability.Id > 0)
|
||||
{
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Ability.Id" />
|
||||
<button type="submit" name="action" value="duplicate" class="btn btn-secondary">Duplicate</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-300" : "bg-green-900/50 border border-green-700 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post" class="space-y-6">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Ability.Id" />
|
||||
<input type="hidden" asp-for="Ability.CreatedAt" />
|
||||
|
||||
<!-- Basic Info -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Basic Info</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">Name</label>
|
||||
<input type="text" asp-for="Ability.Name" class="input" required />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Key (unique)</label>
|
||||
<input type="text" asp-for="Ability.Key" class="input font-mono" required />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Type</label>
|
||||
<select asp-for="Ability.AbilityType" class="input">
|
||||
@foreach (var type in Enum.GetValues<MobAbilityType>())
|
||||
{
|
||||
<option value="@type">@type</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Targeting</label>
|
||||
<select asp-for="Ability.Targeting" class="input">
|
||||
@foreach (var target in Enum.GetValues<MobAbilityTargeting>())
|
||||
{
|
||||
<option value="@target">@target</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="label">Description</label>
|
||||
<input type="text" asp-for="Ability.Description" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Priority</label>
|
||||
<input type="number" asp-for="Ability.Priority" class="input" />
|
||||
</div>
|
||||
<div class="flex items-center gap-2 pt-6">
|
||||
<input type="checkbox" asp-for="Ability.IsEnabled" class="w-4 h-4" />
|
||||
<label asp-for="Ability.IsEnabled" class="text-gray-300">Enabled</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Damage -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Damage / Healing</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">Base Damage</label>
|
||||
<input type="number" asp-for="Ability.BaseDamage" class="input" />
|
||||
<p class="text-xs text-gray-500 mt-1">Negative = healing</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Damage Per Tier</label>
|
||||
<input type="number" asp-for="Ability.DamagePerTier" class="input" step="0.01" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Damage Type</label>
|
||||
<select asp-for="Ability.DamageTypeKey" class="input">
|
||||
<option value="physical">Physical</option>
|
||||
@foreach (var dt in Model.DamageTypes)
|
||||
{
|
||||
<option value="@dt.Key">@dt.DisplayName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Mana Cost</label>
|
||||
<input type="number" asp-for="Ability.ManaCost" class="input" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Range & Area -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Range & Area</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">Range</label>
|
||||
<input type="number" asp-for="Ability.Range" class="input" step="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">0 = self only</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">AOE Radius</label>
|
||||
<input type="number" asp-for="Ability.AoeRadius" class="input" step="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">0 = single target</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Cone Angle</label>
|
||||
<input type="number" asp-for="Ability.ConeAngle" class="input" step="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">Degrees, 0 = not cone</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Displacement Distance</label>
|
||||
<input type="number" asp-for="Ability.DisplacementDistance" class="input" step="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">Knockback/pull</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Timing -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Timing</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">Cooldown (sec)</label>
|
||||
<input type="number" asp-for="Ability.Cooldown" class="input" step="0.1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Cast Time (sec)</label>
|
||||
<input type="number" asp-for="Ability.CastTime" class="input" step="0.1" />
|
||||
<p class="text-xs text-gray-500 mt-1">0 = instant</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Animation Duration</label>
|
||||
<input type="number" asp-for="Ability.AnimationDuration" class="input" step="0.1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Projectile -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Projectile (if applicable)</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="label">Projectile Speed</label>
|
||||
<input type="number" asp-for="Ability.ProjectileSpeed" class="input" step="1" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="label">Projectile Sprite Path</label>
|
||||
<input type="text" asp-for="Ability.ProjectileSprite" class="input" placeholder="textures/projectiles/fireball.png" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Status Effects -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Status Effects (DOT, CC)</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">Effect Duration (sec)</label>
|
||||
<input type="number" asp-for="Ability.EffectDuration" class="input" step="0.1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">DOT Damage Per Tick</label>
|
||||
<input type="number" asp-for="Ability.DotDamagePerTick" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">DOT Tick Interval</label>
|
||||
<input type="number" asp-for="Ability.DotTickInterval" class="input" step="0.1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Speed Modifier</label>
|
||||
<input type="number" asp-for="Ability.SpeedModifier" class="input" step="0.1" />
|
||||
<p class="text-xs text-gray-500 mt-1">0.5 = 50% slow</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Summoning -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Summoning</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="label">Summon Mob</label>
|
||||
<select asp-for="Ability.SummonMobId" class="input">
|
||||
<option value="">None</option>
|
||||
@foreach (var mob in Model.SummonableMobs)
|
||||
{
|
||||
<option value="@mob.Id">@mob.Name</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Summon Count</label>
|
||||
<input type="number" asp-for="Ability.SummonCount" class="input" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Conditions -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Conditions</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">HP Below % (0-1)</label>
|
||||
<input type="number" asp-for="Ability.HpThresholdBelow" class="input" step="0.01" min="0" max="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">Only use when HP below</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">HP Above % (0-1)</label>
|
||||
<input type="number" asp-for="Ability.HpThresholdAbove" class="input" step="0.01" min="0" max="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">Only use when HP above</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Min Targets In Range</label>
|
||||
<input type="number" asp-for="Ability.MinTargetsInRange" class="input" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Animation & Effects -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Animation & Effects</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="label">Animation Key</label>
|
||||
<input type="text" asp-for="Ability.AnimationKey" class="input" />
|
||||
<p class="text-xs text-gray-500 mt-1">attack, cast, special, etc.</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Sound Effect Key</label>
|
||||
<input type="text" asp-for="Ability.SoundEffectKey" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Visual Effect Key</label>
|
||||
<input type="text" asp-for="Ability.VisualEffectKey" class="input" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Buff/Debuff -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Buff / Debuff</h2>
|
||||
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="label">Stat Modifier</label>
|
||||
<input type="number" asp-for="Ability.StatModifier" class="input" step="0.01" />
|
||||
<p class="text-xs text-gray-500 mt-1">1.5 = +50%, 0.5 = -50%</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Affected Stat</label>
|
||||
<input type="text" asp-for="Ability.AffectedStat" class="input" placeholder="damage, defense, speed" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit -->
|
||||
<div class="flex gap-4">
|
||||
<button type="submit" class="btn btn-primary">Save Ability</button>
|
||||
<a href="/admin/abilities" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,172 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Abilities;
|
||||
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public EditModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public MobAbilityDefinition Ability { get; set; } = new();
|
||||
|
||||
public List<DamageResistanceType> DamageTypes { get; set; } = new();
|
||||
public List<DungeonMobDefinition> SummonableMobs { get; set; } = new();
|
||||
public int AssignmentCount { get; set; }
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
await LoadLookups();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var ability = await _db.MobAbilityDefinitions.FindAsync(id.Value);
|
||||
if (ability != null)
|
||||
{
|
||||
Ability = ability;
|
||||
AssignmentCount = await _db.MobAbilityAssignments.CountAsync(a => a.AbilityDefinitionId == id.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Ability = new MobAbilityDefinition
|
||||
{
|
||||
Key = "new_ability_" + DateTime.UtcNow.Ticks % 10000,
|
||||
IsEnabled = true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string? action)
|
||||
{
|
||||
await LoadLookups();
|
||||
|
||||
try
|
||||
{
|
||||
if (action == "duplicate" && Ability.Id > 0)
|
||||
{
|
||||
var newAbility = new MobAbilityDefinition
|
||||
{
|
||||
Name = Ability.Name + " (Copy)",
|
||||
Key = Ability.Key + "_copy",
|
||||
Description = Ability.Description,
|
||||
AbilityType = Ability.AbilityType,
|
||||
Targeting = Ability.Targeting,
|
||||
BaseDamage = Ability.BaseDamage,
|
||||
DamagePerTier = Ability.DamagePerTier,
|
||||
DamageTypeKey = Ability.DamageTypeKey,
|
||||
Range = Ability.Range,
|
||||
AoeRadius = Ability.AoeRadius,
|
||||
ConeAngle = Ability.ConeAngle,
|
||||
Cooldown = Ability.Cooldown,
|
||||
CastTime = Ability.CastTime,
|
||||
AnimationDuration = Ability.AnimationDuration,
|
||||
ProjectileSpeed = Ability.ProjectileSpeed,
|
||||
ProjectileSprite = Ability.ProjectileSprite,
|
||||
EffectDuration = Ability.EffectDuration,
|
||||
DotDamagePerTick = Ability.DotDamagePerTick,
|
||||
DotTickInterval = Ability.DotTickInterval,
|
||||
SpeedModifier = Ability.SpeedModifier,
|
||||
DisplacementDistance = Ability.DisplacementDistance,
|
||||
SummonMobId = Ability.SummonMobId,
|
||||
SummonCount = Ability.SummonCount,
|
||||
StatModifier = Ability.StatModifier,
|
||||
AffectedStat = Ability.AffectedStat,
|
||||
Priority = Ability.Priority,
|
||||
ManaCost = Ability.ManaCost,
|
||||
AnimationKey = Ability.AnimationKey,
|
||||
SoundEffectKey = Ability.SoundEffectKey,
|
||||
VisualEffectKey = Ability.VisualEffectKey,
|
||||
IsEnabled = true
|
||||
};
|
||||
_db.MobAbilityDefinitions.Add(newAbility);
|
||||
await _db.SaveChangesAsync();
|
||||
return RedirectToPage(new { id = newAbility.Id });
|
||||
}
|
||||
|
||||
if (Ability.Id == 0)
|
||||
{
|
||||
Ability.CreatedAt = DateTime.UtcNow;
|
||||
Ability.UpdatedAt = DateTime.UtcNow;
|
||||
_db.MobAbilityDefinitions.Add(Ability);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Ability '{Ability.Name}' created.";
|
||||
return RedirectToPage(new { id = Ability.Id });
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = await _db.MobAbilityDefinitions.FindAsync(Ability.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
Message = "Ability not found.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
existing.Name = Ability.Name;
|
||||
existing.Key = Ability.Key;
|
||||
existing.Description = Ability.Description;
|
||||
existing.AbilityType = Ability.AbilityType;
|
||||
existing.Targeting = Ability.Targeting;
|
||||
existing.BaseDamage = Ability.BaseDamage;
|
||||
existing.DamagePerTier = Ability.DamagePerTier;
|
||||
existing.DamageTypeKey = Ability.DamageTypeKey;
|
||||
existing.Range = Ability.Range;
|
||||
existing.AoeRadius = Ability.AoeRadius;
|
||||
existing.ConeAngle = Ability.ConeAngle;
|
||||
existing.Cooldown = Ability.Cooldown;
|
||||
existing.CastTime = Ability.CastTime;
|
||||
existing.AnimationDuration = Ability.AnimationDuration;
|
||||
existing.ProjectileSpeed = Ability.ProjectileSpeed;
|
||||
existing.ProjectileSprite = Ability.ProjectileSprite;
|
||||
existing.EffectDuration = Ability.EffectDuration;
|
||||
existing.DotDamagePerTick = Ability.DotDamagePerTick;
|
||||
existing.DotTickInterval = Ability.DotTickInterval;
|
||||
existing.SpeedModifier = Ability.SpeedModifier;
|
||||
existing.DisplacementDistance = Ability.DisplacementDistance;
|
||||
existing.SummonMobId = Ability.SummonMobId;
|
||||
existing.SummonCount = Ability.SummonCount;
|
||||
existing.StatModifier = Ability.StatModifier;
|
||||
existing.AffectedStat = Ability.AffectedStat;
|
||||
existing.HpThresholdBelow = Ability.HpThresholdBelow;
|
||||
existing.HpThresholdAbove = Ability.HpThresholdAbove;
|
||||
existing.MinTargetsInRange = Ability.MinTargetsInRange;
|
||||
existing.Priority = Ability.Priority;
|
||||
existing.ManaCost = Ability.ManaCost;
|
||||
existing.AnimationKey = Ability.AnimationKey;
|
||||
existing.SoundEffectKey = Ability.SoundEffectKey;
|
||||
existing.VisualEffectKey = Ability.VisualEffectKey;
|
||||
existing.IsEnabled = Ability.IsEnabled;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
Message = "Ability updated.";
|
||||
AssignmentCount = await _db.MobAbilityAssignments.CountAsync(a => a.AbilityDefinitionId == Ability.Id);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"Error: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
private async Task LoadLookups()
|
||||
{
|
||||
DamageTypes = await _db.DamageResistanceTypes.OrderBy(d => d.DisplayName).ToListAsync();
|
||||
SummonableMobs = await _db.DungeonMobDefinitions.Where(m => m.IsEnabled).OrderBy(m => m.Name).ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
@page "/admin/abilities"
|
||||
@model Abilities.IndexModel
|
||||
@using DataServer.Data.Enums
|
||||
@{
|
||||
ViewData["Title"] = "Mob Abilities";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Mob Abilities</h1>
|
||||
<p class="text-gray-400 mt-1">Manage abilities that can be assigned to mobs</p>
|
||||
</div>
|
||||
<a href="/admin/abilities/edit" class="btn btn-primary">+ New Ability</a>
|
||||
</div>
|
||||
|
||||
@if (TempData["Message"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-green-900/50 border border-green-700 text-green-300">
|
||||
@TempData["Message"]
|
||||
</div>
|
||||
}
|
||||
@if (TempData["Error"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-red-900/50 border border-red-700 text-red-300">
|
||||
@TempData["Error"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4">
|
||||
<form method="get" class="flex flex-wrap gap-4 items-end">
|
||||
<div class="flex-1 min-w-[200px]">
|
||||
<label class="label">Search</label>
|
||||
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Name or key..." />
|
||||
</div>
|
||||
<div class="w-48">
|
||||
<label class="label">Type</label>
|
||||
<select name="typeFilter" class="input">
|
||||
<option value="">All Types</option>
|
||||
@foreach (var type in Enum.GetValues<MobAbilityType>())
|
||||
{
|
||||
<option value="@type" selected="@(Model.TypeFilter == type)">@type</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
<a href="/admin/abilities" class="btn btn-secondary">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Abilities Table -->
|
||||
<div class="card">
|
||||
<table class="w-full">
|
||||
<thead class="border-b border-gray-700">
|
||||
<tr>
|
||||
<th class="table-header">Name</th>
|
||||
<th class="table-header">Key</th>
|
||||
<th class="table-header">Type</th>
|
||||
<th class="table-header">Damage</th>
|
||||
<th class="table-header">Range</th>
|
||||
<th class="table-header">Cooldown</th>
|
||||
<th class="table-header">Status</th>
|
||||
<th class="table-header">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700">
|
||||
@foreach (var ability in Model.Abilities)
|
||||
{
|
||||
<tr class="hover:bg-gray-800/50">
|
||||
<td class="table-cell font-medium text-white">@ability.Name</td>
|
||||
<td class="table-cell font-mono text-xs text-gray-400">@ability.Key</td>
|
||||
<td class="table-cell">
|
||||
<span class="badge @GetTypeBadge(ability.AbilityType)">@ability.AbilityType</span>
|
||||
</td>
|
||||
<td class="table-cell">@ability.BaseDamage</td>
|
||||
<td class="table-cell">@ability.Range</td>
|
||||
<td class="table-cell">@ability.Cooldown.ToString("0.#")s</td>
|
||||
<td class="table-cell">
|
||||
@if (ability.IsEnabled)
|
||||
{
|
||||
<span class="text-green-400">Enabled</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-500">Disabled</span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/abilities/edit?id=@ability.Id" class="btn btn-sm btn-secondary">Edit</a>
|
||||
<form method="post" asp-page-handler="Delete" class="inline" onsubmit="return confirm('Delete this ability?')">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@ability.Id" />
|
||||
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if (Model.Abilities.Count == 0)
|
||||
{
|
||||
<div class="p-8 text-center text-gray-400">
|
||||
No abilities found. <a href="/admin/abilities/edit" class="text-indigo-400 hover:underline">Create one</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@functions {
|
||||
string GetTypeBadge(MobAbilityType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
MobAbilityType.MeleeAttack or MobAbilityType.Cleave => "bg-red-600",
|
||||
MobAbilityType.ProjectileSingle or MobAbilityType.ProjectileAoe => "bg-orange-600",
|
||||
MobAbilityType.HealSelf or MobAbilityType.HealAlly or MobAbilityType.HealAoe => "bg-green-600",
|
||||
MobAbilityType.Poison or MobAbilityType.Bleed or MobAbilityType.Burn => "bg-purple-600",
|
||||
MobAbilityType.Stun or MobAbilityType.Knockback or MobAbilityType.Fear or MobAbilityType.Pull => "bg-yellow-600",
|
||||
MobAbilityType.SummonSingle or MobAbilityType.SummonBulk => "bg-blue-600",
|
||||
_ => "bg-gray-600"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Abilities;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public IndexModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<MobAbilityDefinition> Abilities { get; set; } = new();
|
||||
|
||||
[FromQuery]
|
||||
public string? Search { get; set; }
|
||||
|
||||
[FromQuery]
|
||||
public MobAbilityType? TypeFilter { get; set; }
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
var query = _db.MobAbilityDefinitions.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
{
|
||||
query = query.Where(a => a.Name.Contains(Search) || a.Key.Contains(Search));
|
||||
}
|
||||
|
||||
if (TypeFilter.HasValue)
|
||||
{
|
||||
query = query.Where(a => a.AbilityType == TypeFilter.Value);
|
||||
}
|
||||
|
||||
Abilities = await query.OrderBy(a => a.Name).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var ability = await _db.MobAbilityDefinitions.FindAsync(id);
|
||||
if (ability != null)
|
||||
{
|
||||
// Check if ability is assigned to any mobs
|
||||
var assignments = await _db.MobAbilityAssignments.Where(a => a.AbilityDefinitionId == id).CountAsync();
|
||||
if (assignments > 0)
|
||||
{
|
||||
TempData["Error"] = $"Cannot delete: ability is assigned to {assignments} mob(s).";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
_db.MobAbilityDefinitions.Remove(ability);
|
||||
await _db.SaveChangesAsync();
|
||||
TempData["Message"] = $"Ability '{ability.Name}' deleted.";
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,15 @@
|
||||
<h2 class="text-lg font-semibold text-white">Movement & Behavior</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
|
||||
<div>
|
||||
<label class="label">AI Behavior</label>
|
||||
<select name="Mob.Behavior" class="input">
|
||||
@foreach (var b in Enum.GetValues<MobBehavior>())
|
||||
{
|
||||
<option value="@b" selected="@(Model.Mob.Behavior == b)">@b</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Move Speed</label>
|
||||
<input type="number" name="Mob.MoveSpeed" value="@Model.Mob.MoveSpeed" class="input" min="0" step="1" />
|
||||
@@ -143,6 +152,16 @@
|
||||
<label class="label">Attack Speed</label>
|
||||
<input type="number" name="Mob.AttackSpeed" value="@Model.Mob.AttackSpeed" class="input" min="0.1" step="0.1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Preferred Range</label>
|
||||
<input type="number" name="Mob.PreferredRange" value="@Model.Mob.PreferredRange" class="input" min="0" step="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">For ranged/kiting</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Flee Threshold</label>
|
||||
<input type="number" name="Mob.FleeThreshold" value="@Model.Mob.FleeThreshold" class="input" min="0" max="1" step="0.05" />
|
||||
<p class="text-xs text-gray-500 mt-1">HP% to flee (0-1)</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Aggro Range</label>
|
||||
<input type="number" name="Mob.AggroRange" value="@Model.Mob.AggroRange" class="input" min="0" step="1" />
|
||||
@@ -349,6 +368,128 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Abilities Section -->
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-white">Abilities (@Model.MobAbilities.Count)</h2>
|
||||
<button type="button" onclick="showAddAbilityModal()" class="btn btn-sm btn-primary">+ Add Ability</button>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
@if (Model.MobAbilities.Count > 0)
|
||||
{
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-gray-700">
|
||||
<th class="py-2 text-left text-gray-400">Ability</th>
|
||||
<th class="py-2 text-left text-gray-400">Type</th>
|
||||
<th class="py-2 text-left text-gray-400">Damage</th>
|
||||
<th class="py-2 text-left text-gray-400">Range</th>
|
||||
<th class="py-2 text-left text-gray-400">Cooldown</th>
|
||||
<th class="py-2 text-left text-gray-400">Phase</th>
|
||||
<th class="py-2 text-left text-gray-400">Status</th>
|
||||
<th class="py-2 text-right text-gray-400">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700/50">
|
||||
@foreach (var assignment in Model.MobAbilities)
|
||||
{
|
||||
var ability = assignment.AbilityDefinition;
|
||||
<tr class="hover:bg-gray-800/50">
|
||||
<td class="py-3 text-white font-medium">@ability?.Name</td>
|
||||
<td class="py-3 text-gray-300">@ability?.AbilityType</td>
|
||||
<td class="py-3 text-gray-300">@ability?.BaseDamage</td>
|
||||
<td class="py-3 text-gray-300">@ability?.Range</td>
|
||||
<td class="py-3 text-gray-300">@ability?.Cooldown.ToString("0.#")s</td>
|
||||
<td class="py-3 text-gray-300">@(assignment.Phase == 0 ? "All" : $"Phase {assignment.Phase}")</td>
|
||||
<td class="py-3">
|
||||
@if (assignment.IsEnabled)
|
||||
{
|
||||
<span class="text-green-400 text-xs">Active</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-500 text-xs">Disabled</span>
|
||||
}
|
||||
</td>
|
||||
<td class="py-3 text-right">
|
||||
<div class="flex justify-end gap-1">
|
||||
<form method="post" asp-page-handler="ToggleAbility" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="assignmentId" value="@assignment.Id" />
|
||||
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
|
||||
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-gray-400" title="Toggle">
|
||||
@if (assignment.IsEnabled)
|
||||
{
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728L5.636 5.636"/></svg>
|
||||
}
|
||||
else
|
||||
{
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
|
||||
}
|
||||
</button>
|
||||
</form>
|
||||
<form method="post" asp-page-handler="RemoveAbility" class="inline" onsubmit="return confirm('Remove this ability?')">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="assignmentId" value="@assignment.Id" />
|
||||
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
|
||||
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-red-400" title="Remove">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-gray-400 text-center py-4">No abilities assigned. This mob will use a basic attack.</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Ability Modal -->
|
||||
<div id="addAbilityModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center">
|
||||
<div class="bg-gray-900 rounded-xl shadow-xl p-6 w-full max-w-md mx-4 border border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Add Ability</h3>
|
||||
<form method="post" asp-page-handler="AddAbility">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="label">Ability</label>
|
||||
<select name="abilityId" class="input" required>
|
||||
<option value="">Select an ability...</option>
|
||||
@foreach (var ability in Model.AllAbilities)
|
||||
{
|
||||
<option value="@ability.Id">@ability.Name (@ability.AbilityType)</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Priority Override (0 = use default)</label>
|
||||
<input type="number" name="priority" value="0" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Phase (0 = all phases)</label>
|
||||
<input type="number" name="phase" value="0" class="input" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4">
|
||||
<button type="button" onclick="closeAddAbilityModal()" class="btn btn-secondary">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Assign</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Loot Tables Section -->
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
@@ -464,7 +605,20 @@
|
||||
document.getElementById('addLootModal').classList.add('hidden');
|
||||
document.getElementById('addLootModal').classList.remove('flex');
|
||||
}
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeAddLootModal(); });
|
||||
function showAddAbilityModal() {
|
||||
document.getElementById('addAbilityModal').classList.remove('hidden');
|
||||
document.getElementById('addAbilityModal').classList.add('flex');
|
||||
}
|
||||
function closeAddAbilityModal() {
|
||||
document.getElementById('addAbilityModal').classList.add('hidden');
|
||||
document.getElementById('addAbilityModal').classList.remove('flex');
|
||||
}
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') {
|
||||
closeAddLootModal();
|
||||
closeAddAbilityModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Resistance type options for dynamic rows
|
||||
const resistanceOptions = `@Html.Raw(string.Join("", Model.ResistanceTypes.Select(rt => $"<option value=\"{rt.Key}\">{rt.DisplayName}</option>")))`;
|
||||
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Mobs;
|
||||
@@ -41,6 +42,10 @@ public class EditModel : AdminPageModel
|
||||
public List<DungeonLootTable> AllLootTables { get; set; } = new();
|
||||
public List<DamageResistanceType> ResistanceTypes { get; set; } = new();
|
||||
|
||||
// Ability management
|
||||
public List<MobAbilityAssignment> MobAbilities { get; set; } = new();
|
||||
public List<MobAbilityDefinition> AllAbilities { get; set; } = new();
|
||||
|
||||
public bool IsNew => Mob.Id == 0;
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
@@ -92,6 +97,11 @@ public class EditModel : AdminPageModel
|
||||
.Where(r => r.IsEnabled)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.ToListAsync();
|
||||
|
||||
AllAbilities = await _db.MobAbilityDefinitions
|
||||
.Where(a => a.IsEnabled)
|
||||
.OrderBy(a => a.Name)
|
||||
.ToListAsync();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
@@ -105,6 +115,12 @@ public class EditModel : AdminPageModel
|
||||
.Where(m => m.MobDefinitionId == id.Value)
|
||||
.OrderBy(m => m.Priority)
|
||||
.ToListAsync();
|
||||
|
||||
MobAbilities = await _db.MobAbilityAssignments
|
||||
.Include(a => a.AbilityDefinition)
|
||||
.Where(a => a.MobDefinitionId == id.Value)
|
||||
.OrderBy(a => a.AbilityDefinition!.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -336,4 +352,55 @@ public class EditModel : AdminPageModel
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAddAbilityAsync(int mobId, int abilityId, int priority, int phase)
|
||||
{
|
||||
// Check if already assigned
|
||||
var existing = await _db.MobAbilityAssignments
|
||||
.FirstOrDefaultAsync(a => a.MobDefinitionId == mobId && a.AbilityDefinitionId == abilityId);
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
TempData["Error"] = "This ability is already assigned to this mob.";
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
var assignment = new MobAbilityAssignment
|
||||
{
|
||||
MobDefinitionId = mobId,
|
||||
AbilityDefinitionId = abilityId,
|
||||
PriorityOverride = priority > 0 ? priority : null,
|
||||
Phase = phase,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_db.MobAbilityAssignments.Add(assignment);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRemoveAbilityAsync(int assignmentId, int mobId)
|
||||
{
|
||||
var assignment = await _db.MobAbilityAssignments.FindAsync(assignmentId);
|
||||
if (assignment != null)
|
||||
{
|
||||
_db.MobAbilityAssignments.Remove(assignment);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostToggleAbilityAsync(int assignmentId, int mobId)
|
||||
{
|
||||
var assignment = await _db.MobAbilityAssignments.FindAsync(assignmentId);
|
||||
if (assignment != null)
|
||||
{
|
||||
assignment.IsEnabled = !assignment.IsEnabled;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
<svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
|
||||
</svg>
|
||||
Void Scavengers
|
||||
Dungeon Divers
|
||||
</h1>
|
||||
<p class="text-xs text-gray-500 mt-1">Admin Panel</p>
|
||||
</div>
|
||||
@@ -138,6 +138,13 @@
|
||||
Mobs
|
||||
</a>
|
||||
|
||||
<a href="/admin/abilities" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Abilities") == true ? "active" : "")" onclick="closeMobileMenu()">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
|
||||
</svg>
|
||||
Abilities
|
||||
</a>
|
||||
|
||||
<a href="/admin/assets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Assets") == true ? "active" : "")" onclick="closeMobileMenu()">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
|
||||
Reference in New Issue
Block a user