# Balancing Attack to Defense in a text based RPG [duplicate]

I understand that there is no correct or incorrect way of doing this, and its all down to a matter of trial and error in terms of perfecting the system.

What I am after is some advice or even get thoughts on how others have tackled a situation like this.

Right now I have a very basic attack formula

$attackPower =$baseAttack * 4;
$percent =$attackPower / 100;
$percent1 =$percent * 10; // Gets 10% of the users attack power


Using the above code I then use rand to work out a users attack power, so it varies rather than a single number

$power = rand($attackPower - $percent1,$attackPower + $percent1)  So that's the users attack power calculated. However if I used the same formula to calculate the opponents defense, and then calculated the Attack minus Defense equals the damage $totalDamage = $power -$defense;


This may sometimes result in a negative value (especially if the opponent has a considerably higher defense stat to the users attack)

Above I have used

$attackPower =$baseAttack * 4;


For calculating the defense would this be efficient?

$defensePower =$baseDefense * 2; // Could have this set to rand? 1 - 3??


Is there anything that could be changed to balance the stats out a bit more? Could there be a much simpler formula?

• Not an anwser, but quick coding advice: you're using a lot of bogus variables here. The top four lines could also be written: $power =$baseAttack * rand(3.6, 4.4). – Marcks Thomas Sep 1 '14 at 19:27
• This question/answer also here on GameDev.SE might be interesting to read. – Philip Allgaier Sep 1 '14 at 20:00
• I have come across that already Philip, however right now I'm looking to keep it as simple as possible. Once users have started to build up their character, I may take a copy of their stats and play around with them locally to fine the system and/or try to find an alternative system through trial and error – Kyle Sep 2 '14 at 12:14
• Questions asking for "advice" or "thoughts" are generally too broad or discussion-based to be considered on-topic here. For now I closed this as a duplicate, but if you can sufficiently clarify the question it may be possible to reopen it. You can also consider asking in the Game Development Chat. – user1430 Jan 19 '15 at 16:39

## Handling negative values

There are ways to handle negative values aside from healing the high-defense enemy with your sword strike (which is weird).

You could introduce a block mechanic, where if target defense > attack power, the damage is nullified.

But this is imbalanced. This might mean you might encounter an opponent who you will never hit. Of course you don't want that.

## Rethinking defense

1. Your attack power fluctuates, which is understandable. Sometimes you get a good strike in (up to 10% more damage), sometimes you don't (up to 10% less). You could apply the the same mechanic to defense.
2. Instead of defense being additive, which might lead to an enemy never ever being damaged, you can make defense multiplicative. Instead of blocking of N flat damage, you can shave off X% of the damage as a whole. The increased complexity to this is that you either have to set a min and max defense reachable, up to a possible 99% damage reduction, or let defense scale from 1 to infinity but as defense approaches infinity, the damage reduction increase should lessen.

Think of it like this graph :

Where X = Defense and Y = Damage Reduction

• I have considered a block mechanic, however it seems useless with the evasion system I have. Theoretically they are the same. – Kyle Sep 2 '14 at 12:18
• Yeah, block or evade or parry, technically the same thing in terms of results. – Zaenille Sep 2 '14 at 12:19

Why not use an IF statement:

IF ($power >$defence) {
$totalDamage =$power - $defence; } else {$totalDamage = 0;
}