Resistance System

This commit is contained in:
dingo
2025-12-26 10:40:09 -05:00
parent 2d847c91dd
commit fd056692df
16 changed files with 2862 additions and 8 deletions
+41 -7
View File
@@ -273,8 +273,18 @@ public class DungeonSimulation
private void MobAttackPlayer(MobInstance mob, PlayerInstance player)
{
int damage = mob.Stats.PhysicalDamage + mob.Stats.MagicDamage;
player.Health -= damage;
// Determine damage type (physical if mob has no magic damage)
var damageType = mob.Stats.MagicDamage > mob.Stats.PhysicalDamage
? DataServer.Data.Enums.DamageType.Fire // Use fire for magic mobs (could be configured per mob)
: DataServer.Data.Enums.DamageType.Physical;
int baseDamage = mob.Stats.PhysicalDamage + mob.Stats.MagicDamage;
// Calculate damage with resistances
var result = CombatCalculator.CalculateMobToPlayerDamage(
mob, player, damageType, baseDamage, player.Resistances);
player.Health -= result.FinalDamage;
player.IsInCombat = true;
player.LastCombatTick = CurrentTick;
@@ -284,7 +294,9 @@ public class DungeonSimulation
SourceId = mob.Id,
TargetType = EntityType.Player,
TargetId = (int)player.CharacterId,
Damage = damage
Damage = result.FinalDamage,
WasResisted = result.WasResisted,
WasWeakness = result.WasWeakness
});
if (player.Health <= 0)
@@ -347,10 +359,30 @@ public class DungeonSimulation
float dist = Distance(player.X, player.Y, mob.X, mob.Y);
if (dist > 60) return; // Out of range
// Calculate damage
int damage = (int)(10 * (1 + player.Strength * 0.05f));
// Base damage from stats (would be enhanced by equipped weapon in full implementation)
int baseDamage = 10 + (int)(player.Strength * 0.5f);
var damageType = DataServer.Data.Enums.DamageType.Physical;
mob.Health -= damage;
// Calculate damage with mob resistances
var result = CombatCalculator.CalculatePlayerToMobDamage(
player, mob, damageType, baseDamage);
if (result.WasImmune)
{
// Mob is immune, still add event for client feedback
_pendingDamageEvents.Add(new DamageEvent
{
SourceType = EntityType.Player,
SourceId = (int)player.CharacterId,
TargetType = EntityType.Mob,
TargetId = mob.Id,
Damage = 0,
WasImmune = true
});
return;
}
mob.Health -= result.FinalDamage;
player.IsInCombat = true;
player.LastCombatTick = CurrentTick;
@@ -360,7 +392,9 @@ public class DungeonSimulation
SourceId = (int)player.CharacterId,
TargetType = EntityType.Mob,
TargetId = mob.Id,
Damage = damage
Damage = result.FinalDamage,
WasResisted = result.WasResisted,
WasWeakness = result.WasWeakness
});
if (mob.Health <= 0)