DamageTypeChanges
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using DataServer.Data.Entities;
|
||||
using DataServer.Data.Enums;
|
||||
|
||||
namespace Server.Game.Dungeon;
|
||||
|
||||
@@ -14,54 +13,41 @@ public static class CombatCalculator
|
||||
public static DamageResult CalculatePlayerToMobDamage(
|
||||
PlayerInstance player,
|
||||
MobInstance mob,
|
||||
DamageType damageType,
|
||||
int baseDamage,
|
||||
Dictionary<string, float>? playerGearResistances = null)
|
||||
string damageTypeKey,
|
||||
int baseDamage)
|
||||
{
|
||||
// 1. Base damage modified by player stats
|
||||
float damage = baseDamage;
|
||||
|
||||
// Physical damage scales with STR
|
||||
if (damageType == DamageType.Physical)
|
||||
// Physical damage scales with STR, all other types scale with INT
|
||||
if (damageTypeKey == "physical")
|
||||
{
|
||||
damage *= 1 + (player.Strength * 0.05f); // 5% per STR
|
||||
}
|
||||
// Magical damage scales with INT
|
||||
else
|
||||
{
|
||||
damage *= 1 + (player.Intelligence * 0.05f); // 5% per INT
|
||||
}
|
||||
|
||||
// 2. Apply mob's armor/magic resist reduction
|
||||
float mitigation = 0f;
|
||||
if (damageType == DamageType.Physical)
|
||||
{
|
||||
// Armor formula: damage reduction = armor / (armor + 100)
|
||||
mitigation = mob.Stats.Armor / (float)(mob.Stats.Armor + 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Magic resist formula
|
||||
mitigation = mob.Stats.MagicResist / (float)(mob.Stats.MagicResist + 100);
|
||||
}
|
||||
|
||||
damage *= (1 - mitigation);
|
||||
// 2. Apply mob's armor reduction (flat mitigation for all damage types)
|
||||
float armorMitigation = mob.Stats.Armor / (float)(mob.Stats.Armor + 100);
|
||||
damage *= (1 - armorMitigation);
|
||||
|
||||
// 3. Apply mob's elemental resistances
|
||||
string resistKey = damageType.ToString().ToLower();
|
||||
if (mob.Stats.Resistances.TryGetValue(resistKey, out float mobResist))
|
||||
float mobResist = 0f;
|
||||
if (mob.Stats.Resistances.TryGetValue(damageTypeKey, out float resist))
|
||||
{
|
||||
mobResist = resist;
|
||||
// Positive = resistance (reduces damage), Negative = weakness (increases damage)
|
||||
// 0.5 = 50% resistance, -0.25 = 25% weakness, 1.0 = immune
|
||||
if (mobResist >= 1.0f)
|
||||
{
|
||||
// Immune
|
||||
return new DamageResult
|
||||
{
|
||||
FinalDamage = 0,
|
||||
WasResisted = true,
|
||||
WasImmune = true,
|
||||
DamageType = damageType
|
||||
DamageTypeKey = damageTypeKey
|
||||
};
|
||||
}
|
||||
damage *= (1 - mobResist);
|
||||
@@ -75,7 +61,7 @@ public static class CombatCalculator
|
||||
FinalDamage = finalDamage,
|
||||
WasResisted = mobResist > 0,
|
||||
WasWeakness = mobResist < 0,
|
||||
DamageType = damageType
|
||||
DamageTypeKey = damageTypeKey
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,32 +71,19 @@ public static class CombatCalculator
|
||||
public static DamageResult CalculateMobToPlayerDamage(
|
||||
MobInstance mob,
|
||||
PlayerInstance player,
|
||||
DamageType damageType,
|
||||
string damageTypeKey,
|
||||
int baseDamage,
|
||||
Dictionary<string, float> playerTotalResistances)
|
||||
{
|
||||
float damage = baseDamage;
|
||||
|
||||
// 1. Apply player's armor/magic resist reduction
|
||||
float mitigation = 0f;
|
||||
if (damageType == DamageType.Physical)
|
||||
{
|
||||
// Player armor from gear + endurance bonus
|
||||
int playerArmor = player.Armor;
|
||||
mitigation = playerArmor / (float)(playerArmor + 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
int playerMagicResist = player.MagicResist;
|
||||
mitigation = playerMagicResist / (float)(playerMagicResist + 100);
|
||||
}
|
||||
|
||||
damage *= (1 - mitigation);
|
||||
// 1. Apply player's armor reduction (flat mitigation for all damage types)
|
||||
float armorMitigation = player.Armor / (float)(player.Armor + 100);
|
||||
damage *= (1 - armorMitigation);
|
||||
|
||||
// 2. Apply player's elemental resistances (from gear + innate)
|
||||
string resistKey = damageType.ToString().ToLower();
|
||||
float playerResist = 0f;
|
||||
if (playerTotalResistances.TryGetValue(resistKey, out float resist))
|
||||
if (playerTotalResistances.TryGetValue(damageTypeKey, out float resist))
|
||||
{
|
||||
playerResist = resist;
|
||||
}
|
||||
@@ -134,7 +107,7 @@ public static class CombatCalculator
|
||||
FinalDamage = finalDamage,
|
||||
WasResisted = playerResist > 0,
|
||||
WasWeakness = playerResist < 0,
|
||||
DamageType = damageType
|
||||
DamageTypeKey = damageTypeKey
|
||||
};
|
||||
}
|
||||
|
||||
@@ -161,10 +134,18 @@ public static class CombatCalculator
|
||||
return total;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate total armor for a player from gear
|
||||
/// </summary>
|
||||
public static int CalculatePlayerTotalArmor(List<DungeonItemDefinition> equippedItems)
|
||||
{
|
||||
return equippedItems.Sum(item => item.Armor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate player weapon damage range
|
||||
/// </summary>
|
||||
public static (int min, int max, DamageType type) GetPlayerWeaponDamage(
|
||||
public static (int min, int max, string damageTypeKey) GetPlayerWeaponDamage(
|
||||
PlayerInstance player,
|
||||
DungeonItemDefinition? weapon)
|
||||
{
|
||||
@@ -173,10 +154,31 @@ public static class CombatCalculator
|
||||
// Unarmed: base damage + STR
|
||||
int unarmedMin = 1 + (int)(player.Strength * 0.5f);
|
||||
int unarmedMax = 3 + (int)(player.Strength * 0.5f);
|
||||
return (unarmedMin, unarmedMax, DamageType.Physical);
|
||||
return (unarmedMin, unarmedMax, "physical");
|
||||
}
|
||||
|
||||
return (weapon.MinDamage, weapon.MaxDamage, weapon.DamageType);
|
||||
return (weapon.MinDamage, weapon.MaxDamage, weapon.DamageTypeKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if player meets equipment requirements
|
||||
/// </summary>
|
||||
public static (bool canEquip, string? reason) CanEquipItem(
|
||||
DungeonCharacter character,
|
||||
DungeonItemDefinition item)
|
||||
{
|
||||
if (character.Level < item.RequiredLevel)
|
||||
return (false, $"Requires level {item.RequiredLevel}");
|
||||
if (character.Strength < item.RequiredStrength)
|
||||
return (false, $"Requires {item.RequiredStrength} STR");
|
||||
if (character.Intelligence < item.RequiredIntelligence)
|
||||
return (false, $"Requires {item.RequiredIntelligence} INT");
|
||||
if (character.Wisdom < item.RequiredWisdom)
|
||||
return (false, $"Requires {item.RequiredWisdom} WIS");
|
||||
if (character.Dexterity < item.RequiredDexterity)
|
||||
return (false, $"Requires {item.RequiredDexterity} DEX");
|
||||
|
||||
return (true, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,5 +189,5 @@ public class DamageResult
|
||||
public bool WasWeakness { get; set; }
|
||||
public bool WasImmune { get; set; }
|
||||
public bool WasCritical { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public string DamageTypeKey { get; set; } = "physical";
|
||||
}
|
||||
|
||||
@@ -273,16 +273,13 @@ public class DungeonSimulation
|
||||
|
||||
private void MobAttackPlayer(MobInstance mob, PlayerInstance player)
|
||||
{
|
||||
// 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;
|
||||
|
||||
// Use mob's configured damage type key
|
||||
string damageTypeKey = mob.Stats.DamageTypeKey ?? "physical";
|
||||
int baseDamage = mob.Stats.PhysicalDamage + mob.Stats.MagicDamage;
|
||||
|
||||
// Calculate damage with resistances
|
||||
var result = CombatCalculator.CalculateMobToPlayerDamage(
|
||||
mob, player, damageType, baseDamage, player.Resistances);
|
||||
mob, player, damageTypeKey, baseDamage, player.Resistances);
|
||||
|
||||
player.Health -= result.FinalDamage;
|
||||
player.IsInCombat = true;
|
||||
@@ -295,6 +292,7 @@ public class DungeonSimulation
|
||||
TargetType = EntityType.Player,
|
||||
TargetId = (int)player.CharacterId,
|
||||
Damage = result.FinalDamage,
|
||||
DamageTypeKey = damageTypeKey,
|
||||
WasResisted = result.WasResisted,
|
||||
WasWeakness = result.WasWeakness
|
||||
});
|
||||
@@ -359,13 +357,13 @@ public class DungeonSimulation
|
||||
float dist = Distance(player.X, player.Y, mob.X, mob.Y);
|
||||
if (dist > 60) return; // Out of range
|
||||
|
||||
// Base damage from stats (would be enhanced by equipped weapon in full implementation)
|
||||
// Use player's weapon damage type (set when loading equipped weapon)
|
||||
string damageTypeKey = player.WeaponDamageTypeKey ?? "physical";
|
||||
int baseDamage = 10 + (int)(player.Strength * 0.5f);
|
||||
var damageType = DataServer.Data.Enums.DamageType.Physical;
|
||||
|
||||
// Calculate damage with mob resistances
|
||||
var result = CombatCalculator.CalculatePlayerToMobDamage(
|
||||
player, mob, damageType, baseDamage);
|
||||
player, mob, damageTypeKey, baseDamage);
|
||||
|
||||
if (result.WasImmune)
|
||||
{
|
||||
@@ -377,6 +375,7 @@ public class DungeonSimulation
|
||||
TargetType = EntityType.Mob,
|
||||
TargetId = mob.Id,
|
||||
Damage = 0,
|
||||
DamageTypeKey = damageTypeKey,
|
||||
WasImmune = true
|
||||
});
|
||||
return;
|
||||
@@ -393,6 +392,7 @@ public class DungeonSimulation
|
||||
TargetType = EntityType.Mob,
|
||||
TargetId = mob.Id,
|
||||
Damage = result.FinalDamage,
|
||||
DamageTypeKey = damageTypeKey,
|
||||
WasResisted = result.WasResisted,
|
||||
WasWeakness = result.WasWeakness
|
||||
});
|
||||
|
||||
@@ -28,7 +28,11 @@ public class PlayerInstance
|
||||
|
||||
// Defensive stats (from gear)
|
||||
public int Armor { get; set; }
|
||||
public int MagicResist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Weapon damage type key (from equipped weapon, defaults to physical for unarmed)
|
||||
/// </summary>
|
||||
public string WeaponDamageTypeKey { get; set; } = "physical";
|
||||
|
||||
/// <summary>
|
||||
/// Combined resistances from innate + gear
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using DataServer.Data.Enums;
|
||||
|
||||
namespace Server.Game.Dungeon;
|
||||
|
||||
public class TickResult
|
||||
@@ -16,7 +14,11 @@ public class DamageEvent
|
||||
public EntityType TargetType { get; set; }
|
||||
public int TargetId { get; set; }
|
||||
public int Damage { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Damage type key (e.g., "physical", "fire", "poison")
|
||||
/// </summary>
|
||||
public string DamageTypeKey { get; set; } = "physical";
|
||||
|
||||
/// <summary>
|
||||
/// True if damage was reduced by resistance
|
||||
|
||||
Reference in New Issue
Block a user