slyte33 Posted November 12, 2009 Share Posted November 12, 2009 I have an online game, and I'm currently making real-time PvP battles, but I cannot seem to figure out a decent formula to calculate how much damage the the players deal based on the defence of the opponent. Example: Player A - 1,000 strength, 500 defence Player B - 1,500 strength, 1,000 defence Player A's max damage would be 1,000 VS 1 defence, and the minimum damage.. well I already have a good formula to calculate that. What I want Player A's max damage to equal is around 750, due to the opponent having 1,000 defence. Formulas that would not work is subtracting the opponents defence from the attackers strength, else that would mean you'd always hit 1 IF their defence was greater than the strength. I have been trying for 4 hours to calculate this correctly, and will keep going until I get it right, but I was wondering if any geniuses on here could give me a hand with this All feedback is much much appreciated Thanks. Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted November 13, 2009 Share Posted November 13, 2009 <?php function calibrateDamage($attack, $defence) { $atkDifference = $attack-$defence; if($atkDifference>0) $atkDifference = ($atkDifference/7)*2; elseif($atkDifference==0) $atkDifference = ($attack*-.25); elseif($atkDifference<0) $atkDifference = ($atkDifference/3)*2; echo $atkDifference.' - '; return $attack+$atkDifference; } echo calibrateDamage(1000, 1000); echo("<br/>"); echo calibrateDamage(1500, 1000); ?> That's as close as I can get it for you. You can adjust the figures as needed, its pretty simple. Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted November 13, 2009 Share Posted November 13, 2009 With just a simple addition of a query string we can adjust them as we want to test. I also fixed the <0 issue. <?php function calibrateDamage($attack, $defence) { $atkDifference = $attack-$defence; if($atkDifference>0) $atkDifference = ($atkDifference/7)*2; elseif($atkDifference==0) $atkDifference = ($attack*-.25); elseif($atkDifference<0) $atkDifference = ($atkDifference/3)*2; echo $atkDifference.' - '; return (($attack+$atkDifference)<0)?0:$attack+$atkDifference; } echo calibrateDamage($_GET['atk'], $_GET['def']); ?> Quote Link to comment Share on other sites More sharing options...
slyte33 Posted November 13, 2009 Author Share Posted November 13, 2009 Thank you I will test it a bit later and what you know the results Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.