I'm working with C# and I need advice on the following code I'm trying to make it so that I can calculate magic and physical damage according to the List below the Code. When I try to do the second example the Damage is 167.16782 instead of 199.3007 (I'm using Leauge of legends damage calculation system).
class Player
{
float HP;
float Armor;
float PhysicalAttack;
float MagicAttack;
public void TakePhysicalDamage(float HP, float Armor, float PhysicalDamage)
{
float Multiplier;
if (Armor >= 0)
{
Multiplier = 100 / (100 + Armor);
}
else
{
Multiplier = 2 - 100 / (100 - Armor);
}
PhysicalDamage = PhysicalDamage * Multiplier;
float HP_Value = HP - PhysicalDamage;
Console.WriteLine("Spelaren tog " + PhysicalDamage + " Fysisk skada");
Console.WriteLine("Spelarens liv är " + HP_Value);
}
public void TakeMagicDamage(float HP, float MR, float MagicDamage)
{
float Multiplier;
if (MR >= 0)
{
Multiplier = 100 / (100 + MR);
}
else
{
Multiplier = 2 - 100 / (100 - MR);
}
MagicDamage = MagicDamage * Multiplier;
float HP_Value = HP - MagicDamage;
Console.WriteLine("Spelaren tog " + MagicDamage + " Magisk Skada");
Console.WriteLine("Spelarens liv är " + HP_Value);
}
public void TakeMagicAndPhysicalDamage(float HP, float MR, float MagicDamage, float Armor, float PhysicalDamage)
{
float PhysicalMultiplier;
if (MR >= 0)
{
PhysicalMultiplier = 100 / (100 + MR);
}
else
{
PhysicalMultiplier = 2 - 100 / (100 - MR);
}
float MagicMultiplier;
if (Armor >= 0)
{
MagicMultiplier = 100 / (100 + Armor);
}
else
{
MagicMultiplier = 2 - 100 / (100 - Armor);
}
PhysicalDamage = PhysicalDamage * PhysicalMultiplier;
MagicDamage = MagicDamage * MagicMultiplier;
float Damage = MagicDamage + PhysicalDamage;
float HP_Value = HP - Damage;
Console.WriteLine("Spelaren tog " + Damage + " Skada");
Console.WriteLine("Spelarens liv är " + HP_Value);
}
public static void Main()
{
Player player = new Player();
Console.WriteLine("Skriv spelarens Liv");
float HP = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Skriv Spelarens Fysiska försvar");
float Armor = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Skriv Spelarens Magiska försvar");
float MR = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Skriv motståndarens Fysiska skada");
float PhysicalDamage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Skriv motståndarens Magiska skada");
float MagicDamage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Skriv in Fysisk skada, Magisk skada eller Båda");
string input = Console.ReadLine();
if (input == "Fysisk skada")
{
player.TakePhysicalDamage(HP, Armor, PhysicalDamage);
}
else if (input == "Magisk skada")
{
player.TakeMagicDamage(HP, MR, MagicDamage);
}
else if (input == "Båda")
{
player.TakeMagicAndPhysicalDamage(HP, MagicDamage, MR, Armor, PhysicalDamage);
}
}
}
Magicdmg physicaldmg MagicResist Armor Total Damage
100 100 100 100 = 100
200 100 30 120 = 199.3007
679 60 30 120 = 549.5804
100 350 -10 100 = 284.0909