public static float DamageCalculation(PlayerStats attackerStats, PlayerStats receiverStats) { // Damage calculation float physicalDamage = attackerStats.physicalDamage; float magicDamage = attackerStats.magicDamage; // Resistance Calculation float enemyArmor = (receiverStats.armor - attackerStats.armorPenetrationFlat) * (1 - attackerStats.armorPenetrationPercentage); enemyArmor = (enemyArmor > 0) ? enemyArmor : 0; float physicalDamageReduction = Mathf.Exp(-(enemyArmor / 50)); float enemyMagicResistance = (receiverStats.magicResistance - attackerStats.magicPenetrationFlat) * (1 - attackerStats.magicPenetrationPercentage); enemyMagicResistance = (enemyMagicResistance > 0) ? enemyMagicResistance : 0; float magicDamageReduction = Mathf.Exp(-(enemyMagicResistance / 50)); return physicalDamage * physicalDamageReduction + magicDamage * magicDamageReduction; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter