World changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using DataServer.Data.Entities;
|
||||
using GameServer.Shared;
|
||||
|
||||
namespace GameServer.Dungeon;
|
||||
|
||||
@@ -11,7 +12,7 @@ public static class CombatCalculator
|
||||
/// Calculate damage dealt from player to mob
|
||||
/// </summary>
|
||||
public static DamageResult CalculatePlayerToMobDamage(
|
||||
PlayerInstance player,
|
||||
IPlayerTarget player,
|
||||
MobInstance mob,
|
||||
string damageTypeKey,
|
||||
int baseDamage)
|
||||
@@ -70,7 +71,7 @@ public static class CombatCalculator
|
||||
/// </summary>
|
||||
public static DamageResult CalculateMobToPlayerDamage(
|
||||
MobInstance mob,
|
||||
PlayerInstance player,
|
||||
IPlayerTarget player,
|
||||
string damageTypeKey,
|
||||
int baseDamage,
|
||||
Dictionary<string, float> playerTotalResistances)
|
||||
@@ -148,7 +149,7 @@ public static class CombatCalculator
|
||||
/// Calculate player weapon damage range
|
||||
/// </summary>
|
||||
public static (int min, int max, string damageTypeKey) GetPlayerWeaponDamage(
|
||||
PlayerInstance player,
|
||||
IPlayerTarget player,
|
||||
DungeonItemDefinition? weapon)
|
||||
{
|
||||
if (weapon == null)
|
||||
@@ -191,6 +192,51 @@ public static class CombatCalculator
|
||||
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate damage dealt from player to player (PvP)
|
||||
/// </summary>
|
||||
public static DamageResult CalculatePlayerToPlayerDamage(
|
||||
IPlayerTarget attacker,
|
||||
IPlayerTarget defender,
|
||||
string damageTypeKey,
|
||||
int baseDamage)
|
||||
{
|
||||
// 1. Base damage modified by attacker stats
|
||||
float damage = baseDamage;
|
||||
if (damageTypeKey == "physical")
|
||||
damage *= 1 + (attacker.Strength * 0.05f);
|
||||
else
|
||||
damage *= 1 + (attacker.Intelligence * 0.05f);
|
||||
|
||||
// 2. Apply defender armor
|
||||
float armorMitigation = defender.Armor / (float)(defender.Armor + 100);
|
||||
damage *= (1 - armorMitigation);
|
||||
|
||||
// 3. Apply defender resistances (capped at 75%)
|
||||
float defenderResist = 0f;
|
||||
if (defender.Resistances.TryGetValue(damageTypeKey, out float resist))
|
||||
defenderResist = Math.Min(resist, 0.75f);
|
||||
if (defenderResist != 0)
|
||||
damage *= (1 - defenderResist);
|
||||
|
||||
// 4. Endurance reduction (capped at 50%)
|
||||
float enduranceReduction = Math.Min(defender.Endurance / (float)(defender.Endurance + 100), 0.50f);
|
||||
damage *= (1.0f - enduranceReduction);
|
||||
|
||||
// 5. PvP damage reduction (30% global reduction to make fights last longer)
|
||||
damage *= 0.7f;
|
||||
|
||||
int finalDamage = Math.Max(1, (int)damage);
|
||||
|
||||
return new DamageResult
|
||||
{
|
||||
FinalDamage = finalDamage,
|
||||
WasResisted = defenderResist > 0,
|
||||
WasWeakness = defenderResist < 0,
|
||||
DamageTypeKey = damageTypeKey
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class DamageResult
|
||||
|
||||
@@ -2,13 +2,14 @@ using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
using GameServer.Shared;
|
||||
|
||||
namespace GameServer.Dungeon;
|
||||
|
||||
/// <summary>
|
||||
/// Runtime simulation for an active dungeon instance
|
||||
/// </summary>
|
||||
public partial class DungeonSimulation
|
||||
public partial class DungeonSimulation : ICombatEnvironment
|
||||
{
|
||||
public DungeonLayout Layout { get; }
|
||||
public int Tier { get; }
|
||||
@@ -1887,6 +1888,14 @@ public partial class DungeonSimulation
|
||||
_pendingSummons.Add((mobDefinitionId, x, y, tier));
|
||||
}
|
||||
|
||||
// ---- ICombatEnvironment implementation ----
|
||||
|
||||
IEnumerable<IPlayerTarget> ICombatEnvironment.GetAlivePlayers()
|
||||
=> Players.Values.Where(p => p.IsAlive);
|
||||
|
||||
IPlayerTarget? ICombatEnvironment.GetPlayer(ulong characterId)
|
||||
=> Players.TryGetValue(characterId, out var p) ? p : null;
|
||||
|
||||
public int AllocateRuntimeMobId()
|
||||
{
|
||||
lock (_mobIdLock)
|
||||
|
||||
+93
-94
@@ -1,5 +1,6 @@
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
using GameServer.Shared;
|
||||
|
||||
namespace GameServer.Dungeon;
|
||||
|
||||
@@ -13,7 +14,7 @@ public static class MobAI
|
||||
/// <summary>
|
||||
/// Main AI update - called each tick for each mob
|
||||
/// </summary>
|
||||
public static void UpdateMob(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
public static void UpdateMob(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
if (!mob.IsAlive || mob.IsStunned) return;
|
||||
|
||||
@@ -21,7 +22,7 @@ public static class MobAI
|
||||
UpdateCooldowns(mob, deltaTime);
|
||||
|
||||
// Update status effects
|
||||
UpdateStatusEffects(mob, sim, deltaTime);
|
||||
UpdateStatusEffects(mob, env, deltaTime);
|
||||
|
||||
// Check for phase transitions (for bosses)
|
||||
CheckPhaseTransition(mob);
|
||||
@@ -35,7 +36,7 @@ public static class MobAI
|
||||
mob.CastTimeRemaining -= deltaTime;
|
||||
if (mob.CastTimeRemaining <= 0)
|
||||
{
|
||||
ExecuteAbility(mob, mob.CastingAbility, sim);
|
||||
ExecuteAbility(mob, mob.CastingAbility, env);
|
||||
mob.CastingAbility = null;
|
||||
mob.State = MobState.Idle;
|
||||
mob.StateTime = 0;
|
||||
@@ -47,37 +48,37 @@ public static class MobAI
|
||||
switch (mob.Behavior)
|
||||
{
|
||||
case MobBehavior.Aggressive:
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
UpdateAggressive(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Defensive:
|
||||
UpdateDefensive(mob, sim, deltaTime);
|
||||
UpdateDefensive(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Ranged:
|
||||
UpdateRanged(mob, sim, deltaTime);
|
||||
UpdateRanged(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Skirmisher:
|
||||
UpdateSkirmisher(mob, sim, deltaTime);
|
||||
UpdateSkirmisher(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Tank:
|
||||
UpdateTank(mob, sim, deltaTime);
|
||||
UpdateTank(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Assassin:
|
||||
UpdateAssassin(mob, sim, deltaTime);
|
||||
UpdateAssassin(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Healer:
|
||||
UpdateHealer(mob, sim, deltaTime);
|
||||
UpdateHealer(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Patrol:
|
||||
UpdatePatrol(mob, sim, deltaTime);
|
||||
UpdatePatrol(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Pack:
|
||||
UpdatePack(mob, sim, deltaTime);
|
||||
UpdatePack(mob, env, deltaTime);
|
||||
break;
|
||||
case MobBehavior.Summoner:
|
||||
UpdateSummoner(mob, sim, deltaTime);
|
||||
UpdateSummoner(mob, env, deltaTime);
|
||||
break;
|
||||
default:
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
UpdateAggressive(mob, env, deltaTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -87,14 +88,14 @@ public static class MobAI
|
||||
/// <summary>
|
||||
/// Aggressive: Charges player on sight, melee attacks. Wanders when idle.
|
||||
/// </summary>
|
||||
private static void UpdateAggressive(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateAggressive(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
// No target - wander or return to spawn area
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ public static class MobAI
|
||||
// Check leash range
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,16 +126,16 @@ public static class MobAI
|
||||
// Chase
|
||||
mob.State = MobState.Chasing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defensive: Only attacks if player comes close to spawn. Wanders near spawn.
|
||||
/// </summary>
|
||||
private static void UpdateDefensive(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateDefensive(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
float distFromSpawn = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
if (target != null)
|
||||
@@ -148,7 +149,7 @@ public static class MobAI
|
||||
// Don't stray too far from spawn
|
||||
if (distFromSpawn > mob.Stats.LeashRange * 0.5f)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ public static class MobAI
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Chasing;
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 0.7f * deltaTime, sim);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 0.7f * deltaTime, env);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -172,19 +173,19 @@ public static class MobAI
|
||||
|
||||
// No threat - wander near spawn
|
||||
mob.TargetId = null;
|
||||
UpdateIdleWander(mob, sim, deltaTime, wanderRadius: 80f);
|
||||
UpdateIdleWander(mob, env, deltaTime, wanderRadius: 80f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ranged: Keeps distance, fires projectiles
|
||||
/// </summary>
|
||||
private static void UpdateRanged(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateRanged(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -193,7 +194,7 @@ public static class MobAI
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -209,14 +210,14 @@ public static class MobAI
|
||||
// Too close, back up
|
||||
mob.State = MobState.Kiting;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
}
|
||||
else if (distance > preferredRange * 1.3f && distance <= mob.Stats.LeashRange)
|
||||
{
|
||||
// Too far, move closer
|
||||
mob.State = MobState.Chasing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -229,13 +230,13 @@ public static class MobAI
|
||||
/// <summary>
|
||||
/// Skirmisher: Hit-and-run tactics
|
||||
/// </summary>
|
||||
private static void UpdateSkirmisher(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateSkirmisher(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,13 +248,13 @@ public static class MobAI
|
||||
{
|
||||
mob.State = MobState.Fleeing;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.3f * deltaTime, sim);
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.3f * deltaTime, env);
|
||||
return;
|
||||
}
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -274,7 +275,7 @@ public static class MobAI
|
||||
else
|
||||
{
|
||||
mob.State = MobState.Chasing;
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.2f * deltaTime, sim);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.2f * deltaTime, env);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -282,20 +283,20 @@ public static class MobAI
|
||||
// Retreat phase
|
||||
mob.State = MobState.Kiting;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tank: Slow but tough, always moves toward target
|
||||
/// </summary>
|
||||
private static void UpdateTank(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateTank(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime, wanderRadius: 50f);
|
||||
UpdateIdleWander(mob, env, deltaTime, wanderRadius: 50f);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -304,7 +305,7 @@ public static class MobAI
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -322,25 +323,24 @@ public static class MobAI
|
||||
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);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 0.6f * deltaTime, env);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assassin: Targets lowest HP player, moves fast
|
||||
/// </summary>
|
||||
private static void UpdateAssassin(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateAssassin(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
// Target lowest HP player
|
||||
var target = sim.Players.Values
|
||||
.Where(p => p.IsAlive)
|
||||
var target = env.GetAlivePlayers()
|
||||
.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);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ public static class MobAI
|
||||
|
||||
if (distFromSpawn > mob.Stats.LeashRange)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -366,17 +366,17 @@ public static class MobAI
|
||||
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);
|
||||
MoveToward(mob, target.X, target.Y, mob.Stats.MoveSpeed * 1.3f * deltaTime, env);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Healer: Heals nearby mobs, stays back from combat
|
||||
/// </summary>
|
||||
private static void UpdateHealer(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateHealer(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
// Check for injured allies first
|
||||
var injuredAlly = sim.Mobs.Values
|
||||
var injuredAlly = env.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)
|
||||
@@ -402,7 +402,7 @@ public static class MobAI
|
||||
}
|
||||
|
||||
// Otherwise, stay back from combat
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
if (target != null)
|
||||
{
|
||||
float distance = GetDistance(mob.X, mob.Y, target.X, target.Y);
|
||||
@@ -411,7 +411,7 @@ public static class MobAI
|
||||
if (distance < preferredRange)
|
||||
{
|
||||
mob.State = MobState.Kiting;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
}
|
||||
else if (distance <= mob.Stats.AttackRange)
|
||||
{
|
||||
@@ -420,69 +420,69 @@ public static class MobAI
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Patrol: Walks a path, alerts others when seeing players
|
||||
/// </summary>
|
||||
private static void UpdatePatrol(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdatePatrol(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
// Alert nearby mobs
|
||||
if (!mob.HasCalledForHelp)
|
||||
{
|
||||
CallForHelp(mob, sim);
|
||||
CallForHelp(mob, env);
|
||||
}
|
||||
|
||||
// Then fight like aggressive
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
UpdateAggressive(mob, env, deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.HasCalledForHelp = false;
|
||||
|
||||
// Patrol - wander in a larger area
|
||||
UpdateIdleWander(mob, sim, deltaTime, wanderRadius: 150f);
|
||||
UpdateIdleWander(mob, env, deltaTime, wanderRadius: 150f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pack: Calls nearby mobs when engaged
|
||||
/// </summary>
|
||||
private static void UpdatePack(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdatePack(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
if (!mob.HasCalledForHelp)
|
||||
{
|
||||
CallForHelp(mob, sim);
|
||||
CallForHelp(mob, env);
|
||||
}
|
||||
UpdateAggressive(mob, sim, deltaTime);
|
||||
UpdateAggressive(mob, env, deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
mob.HasCalledForHelp = false;
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Summoner: Stays back and summons minions
|
||||
/// </summary>
|
||||
private static void UpdateSummoner(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateSummoner(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var target = FindNearestPlayer(mob, sim);
|
||||
var target = FindNearestPlayer(mob, env);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UpdateIdleWander(mob, sim, deltaTime);
|
||||
UpdateIdleWander(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ public static class MobAI
|
||||
if (distance < preferredRange * 0.5f)
|
||||
{
|
||||
mob.State = MobState.Kiting;
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, sim);
|
||||
MoveAwayFrom(mob, target.X, target.Y, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -528,7 +528,7 @@ public static class MobAI
|
||||
/// <summary>
|
||||
/// Wander around spawn area when no targets
|
||||
/// </summary>
|
||||
private static void UpdateIdleWander(MobInstance mob, DungeonSimulation sim, float deltaTime, float wanderRadius = 0f)
|
||||
private static void UpdateIdleWander(MobInstance mob, ICombatEnvironment env, float deltaTime, float wanderRadius = 0f)
|
||||
{
|
||||
// Use leash range if no wander radius specified
|
||||
if (wanderRadius <= 0)
|
||||
@@ -539,7 +539,7 @@ public static class MobAI
|
||||
// Too far from spawn? Return first
|
||||
if (distFromSpawn > wanderRadius)
|
||||
{
|
||||
ReturnToSpawn(mob, sim, deltaTime);
|
||||
ReturnToSpawn(mob, env, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ public static class MobAI
|
||||
float targetY = mob.SpawnY + MathF.Sin(angle) * dist;
|
||||
|
||||
// Check if target is walkable
|
||||
if (sim.CanActorMoveTo(targetX, targetY))
|
||||
if (env.CanActorMoveTo(targetX, targetY))
|
||||
{
|
||||
mob.WanderTargetX = targetX;
|
||||
mob.WanderTargetY = targetY;
|
||||
@@ -610,12 +610,12 @@ public static class MobAI
|
||||
// Keep moving toward target (30% speed for casual wandering)
|
||||
mob.UpdateFacingDirection(mob.WanderTargetX, mob.WanderTargetY);
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("walk");
|
||||
MoveToward(mob, mob.WanderTargetX, mob.WanderTargetY, mob.Stats.MoveSpeed * 0.3f * deltaTime, sim);
|
||||
MoveToward(mob, mob.WanderTargetX, mob.WanderTargetY, mob.Stats.MoveSpeed * 0.3f * deltaTime, env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReturnToSpawn(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void ReturnToSpawn(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
float dist = GetDistance(mob.X, mob.Y, mob.SpawnX, mob.SpawnY);
|
||||
|
||||
@@ -636,7 +636,7 @@ public static class MobAI
|
||||
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);
|
||||
MoveToward(mob, mob.SpawnX, mob.SpawnY, mob.Stats.MoveSpeed * deltaTime, env);
|
||||
|
||||
// Heal while returning
|
||||
if (mob.Health < mob.MaxHealth)
|
||||
@@ -650,12 +650,12 @@ public static class MobAI
|
||||
}
|
||||
}
|
||||
|
||||
private static void CallForHelp(MobInstance mob, DungeonSimulation sim)
|
||||
private static void CallForHelp(MobInstance mob, ICombatEnvironment env)
|
||||
{
|
||||
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))
|
||||
foreach (var ally in env.Mobs.Values.Where(m => m.IsAlive && m.Id != mob.Id))
|
||||
{
|
||||
if (GetDistance(mob.X, mob.Y, ally.X, ally.Y) <= helpRadius)
|
||||
{
|
||||
@@ -673,7 +673,7 @@ public static class MobAI
|
||||
|
||||
#region Movement with Collision
|
||||
|
||||
private static void MoveToward(MobInstance mob, float targetX, float targetY, float speed, DungeonSimulation sim)
|
||||
private static void MoveToward(MobInstance mob, float targetX, float targetY, float speed, ICombatEnvironment env)
|
||||
{
|
||||
if (mob.IsRooted) return;
|
||||
|
||||
@@ -693,7 +693,7 @@ public static class MobAI
|
||||
float newY = mob.Y + moveY;
|
||||
|
||||
// Check collision for each axis separately
|
||||
if (sim.CanActorMoveTo(newX, mob.Y))
|
||||
if (env.CanActorMoveTo(newX, mob.Y))
|
||||
{
|
||||
mob.X = newX;
|
||||
}
|
||||
@@ -703,7 +703,7 @@ public static class MobAI
|
||||
mob.StuckTime += 0.05f;
|
||||
}
|
||||
|
||||
if (sim.CanActorMoveTo(mob.X, newY))
|
||||
if (env.CanActorMoveTo(mob.X, newY))
|
||||
{
|
||||
mob.Y = newY;
|
||||
}
|
||||
@@ -715,12 +715,12 @@ public static class MobAI
|
||||
// If stuck for too long, try to unstick
|
||||
if (mob.StuckTime > 1f)
|
||||
{
|
||||
TryUnstick(mob, sim);
|
||||
TryUnstick(mob, env);
|
||||
mob.StuckTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveAwayFrom(MobInstance mob, float targetX, float targetY, float speed, DungeonSimulation sim)
|
||||
private static void MoveAwayFrom(MobInstance mob, float targetX, float targetY, float speed, ICombatEnvironment env)
|
||||
{
|
||||
if (mob.IsRooted) return;
|
||||
|
||||
@@ -736,25 +736,25 @@ public static class MobAI
|
||||
float newX = mob.X + moveX;
|
||||
float newY = mob.Y + moveY;
|
||||
|
||||
if (sim.CanActorMoveTo(newX, mob.Y))
|
||||
if (env.CanActorMoveTo(newX, mob.Y))
|
||||
{
|
||||
mob.X = newX;
|
||||
}
|
||||
|
||||
if (sim.CanActorMoveTo(mob.X, newY))
|
||||
if (env.CanActorMoveTo(mob.X, newY))
|
||||
{
|
||||
mob.Y = newY;
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryUnstick(MobInstance mob, DungeonSimulation sim)
|
||||
private static void TryUnstick(MobInstance mob, ICombatEnvironment env)
|
||||
{
|
||||
// Try moving in cardinal directions to get unstuck
|
||||
float[] offsets = { 16, -16 };
|
||||
|
||||
foreach (float ox in offsets)
|
||||
{
|
||||
if (sim.CanActorMoveTo(mob.X + ox, mob.Y))
|
||||
if (env.CanActorMoveTo(mob.X + ox, mob.Y))
|
||||
{
|
||||
mob.X += ox * 0.5f;
|
||||
return;
|
||||
@@ -763,7 +763,7 @@ public static class MobAI
|
||||
|
||||
foreach (float oy in offsets)
|
||||
{
|
||||
if (sim.CanActorMoveTo(mob.X, mob.Y + oy))
|
||||
if (env.CanActorMoveTo(mob.X, mob.Y + oy))
|
||||
{
|
||||
mob.Y += oy * 0.5f;
|
||||
return;
|
||||
@@ -775,7 +775,7 @@ public static class MobAI
|
||||
|
||||
#region Ability System
|
||||
|
||||
private static void ExecuteAbility(MobInstance mob, MobAbilityState ability, DungeonSimulation sim)
|
||||
private static void ExecuteAbility(MobInstance mob, MobAbilityState ability, ICombatEnvironment env)
|
||||
{
|
||||
ability.CooldownRemaining = ability.Definition.Cooldown;
|
||||
mob.Mana -= ability.Definition.ManaCost;
|
||||
@@ -786,7 +786,7 @@ public static class MobAI
|
||||
{
|
||||
case MobAbilityType.SummonSingle:
|
||||
case MobAbilityType.SummonBulk:
|
||||
ExecuteSummon(mob, ability, sim);
|
||||
ExecuteSummon(mob, ability, env);
|
||||
break;
|
||||
|
||||
// TODO: Implement other ability types
|
||||
@@ -796,7 +796,7 @@ public static class MobAI
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExecuteSummon(MobInstance mob, MobAbilityState ability, DungeonSimulation sim)
|
||||
private static void ExecuteSummon(MobInstance mob, MobAbilityState ability, ICombatEnvironment env)
|
||||
{
|
||||
if (!ability.Definition.SummonMobId.HasValue)
|
||||
{
|
||||
@@ -819,7 +819,7 @@ public static class MobAI
|
||||
float spawnY = mob.Y + (float)Math.Sin(angle) * summonDistance;
|
||||
|
||||
// Make sure spawn position is walkable
|
||||
if (!sim.CanActorMoveTo(spawnX, spawnY))
|
||||
if (!env.CanActorMoveTo(spawnX, spawnY))
|
||||
{
|
||||
// Try closer
|
||||
spawnX = mob.X + (float)Math.Cos(angle) * (summonDistance * 0.5f);
|
||||
@@ -827,7 +827,7 @@ public static class MobAI
|
||||
}
|
||||
|
||||
// Request mob spawn (this will be handled by DungeonSimulation)
|
||||
sim.RequestMobSummon(summonMobId, spawnX, spawnY, sim.Tier);
|
||||
env.RequestMobSummon(summonMobId, spawnX, spawnY, env.Tier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -844,7 +844,7 @@ public static class MobAI
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateStatusEffects(MobInstance mob, DungeonSimulation sim, float deltaTime)
|
||||
private static void UpdateStatusEffects(MobInstance mob, ICombatEnvironment env, float deltaTime)
|
||||
{
|
||||
var expired = new List<MobStatusEffect>();
|
||||
|
||||
@@ -898,10 +898,9 @@ public static class MobAI
|
||||
}
|
||||
}
|
||||
|
||||
private static PlayerInstance? FindNearestPlayer(MobInstance mob, DungeonSimulation sim)
|
||||
private static IPlayerTarget? FindNearestPlayer(MobInstance mob, ICombatEnvironment env)
|
||||
{
|
||||
return sim.Players.Values
|
||||
.Where(p => p.IsAlive)
|
||||
return env.GetAlivePlayers()
|
||||
.Where(p => GetDistance(mob.X, mob.Y, p.X, p.Y) <= mob.Stats.AggroRange)
|
||||
.OrderBy(p => GetDistance(mob.X, mob.Y, p.X, p.Y))
|
||||
.FirstOrDefault();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using GameServer.Shared;
|
||||
|
||||
namespace GameServer.Dungeon;
|
||||
|
||||
/// <summary>
|
||||
/// Runtime instance of a player in a dungeon
|
||||
/// </summary>
|
||||
public class PlayerInstance
|
||||
public class PlayerInstance : IPlayerTarget
|
||||
{
|
||||
public ulong CharacterId { get; set; }
|
||||
public string CharacterName { get; set; } = "";
|
||||
|
||||
Reference in New Issue
Block a user