# ALGORITHMS FOR FUN AND PROFIT

### Some food for thought if you're hurting for algorithms.

- Trihan
- 06/09/2007 12:00 AM
- 2197 views

Hello there gentle readers.

I see a lot of people who ask about algorithms, be it to work out battle damage, levelling up formulas, or the odds of winning in a game of chance.

The point of this article is to offer, if nothing else, some inspiration and a point in the right direction. I'm going to do this by looking at how calculations are done in a "professional" game. And while some of you might not like the game itself, I personally think that it has the balance down pretty well as far as calculations go. I'm talking, of course, about Ragnarok Online.

A lot of the concepts I'm going to discuss are specific to Ragnarok Online, but they may give you ideas for similar mechanics to implement in your own game, or point out something you had overlooked.

(Note: If a calculation is inside square brackets, you should round the value inside down. max(x, y) indicates that you should take the greater of the two values)

------

RO has six statistics. STR (strength), AGI (agility), VIT (vitality), INT (intelligence), DEX (dexterity) and LUK (luck).

STR offers the following:

:- +1 base damage per point for melee weapons

:- A bonus of [STR/10]^2 for melee weapons

:- +1 base damage per 5 points for ranged weapons

:- +30 carrying capacity per point of base STR (not counting bonuses)

AGI offers the following:

:- +1 flee per point

:- Increased attack speed per point (The full calculation is omitted as it's only really useful for real-time games)

VIT offers the following:

:- +1% to max HP per point

:- +0.8 weapon damage reduction per point

:- Effect of healing items increased by +2% per point

:- Every 5 points of VIT increases HP recovery rate by 1

:- Monsters receive a damage reduction bonus of rnd(0, [VIT/20]^2-1)

:- Players receive a damage reduction bonus of [VIT*0.5] + rnd([VIT*0.3], max([VIT*0.3], [VIT^2/150]-1))

:- +1 magic defence per 2 points

:- Decreased chance of being afflicted with poison, silence and stun.

INT offers the following:

:- +1 base magic attack per point

:- +1% to max SP per point

:- Effect of SP recovery items increased by +2% per point

:- Every 6 points of INT increases SP recovery rate by 1 and past 120 INT, every 2 points increases SP recovery rate by a further 1.

:- A bonus to minimum magic attack of [Int/7]^2

:- A bonus to maximum magic attack of [Int/5]^2

:- +1 spell damage reduction

:- Decreased chance of being afflicted with blind, sleep and stone curse.

DEX offers the following:

:- +1 hit per point

:- Increased attack speed per point

:- +1 base damage per point for ranged weapons

:- Bonus of [Dex/10]^2 for ranged weapons

:- +1 base damage per 5 points for melee weapons

:- +1 minimum damage per point for melee weapons. If DEX exceeds the attack of the weapon, then the weapon's attack is considered the minimum.

:- Reduces spell casting time by [Dex/1.5]%

:- +0.1% forging success chance per point

LUK offers the following:

:- +1 base damage per 5 points for ranged and melee weapons

:- +1 crit chance per 3 points

:- +1 lucky dodge chance per 10 points

:- +0.1% forging success chance per point

:- Decreased chance of being afflicted with any negative status (not as much as the effect of VIT/INT)

------

A lot of this won't apply to a traditional RPG - in a turn based battle system, what's the use in having attack speed? However, in a tactics or real-time system, these could be useful for you if you're trying to balance things out.

Of course, there are a myriad of substats referenced here that depend on the six base stats. They are as follows:

------

ATK:

:- ATK stands for, well, attack.

:- When unarmed, ATK is equal to STR + [STR/10]^2 + [DEX/5] + [LUK/5]

:- For ranged weapons, ATK is equal to DEX + [DEX/10]^2 + [STR/5] + [LUK/5]

:- When using a weapon, the weapon's attack stat is added to this value, as well as any attack power bonuses from cards.

MATK:

:- MATK stands for magic attack.

:- Minimum MATK is equal to INT + [INT/7]^2

:- Maximum MATK is equal to INT + [INT/5]^2

:- Any time a magic attack is used, a random number between the minimum and maximum is chosen and used as the damage value for every hit in the spell.

HIT:

:- Hit is your ability to hit a target.

:- Each point of hit increases hit success chance by 1%.

:- Hit is equal to BaseLevel + DEX + hit bonuses from cards

CRIT:

:- Crit, or critical, is your chance of striking a critical blow when you attack.

:- Each point of critical increases crit chance by 1%.

:- Crit is equal to 1 + LUK*0.3 + crit bonuses from cards

:- Criticals are checked before seeing if your hit overcomes your target's flee.

:- Crit is reduced by the LUK of your target / 5

:- A critical always hits for maximum damage and ignores DEF.

DEF:

:- Def stands for defence.

:- Def is split into two parts. Def derived from armour, and Def derived from VIT.

:- Armour Def is equal to BaseArmour + Refinements*2/3. Armour def reduces damage taken by a percentage.

:- VIT-based Def is different for players and monsters. For players it's [VIT*0.5] + rnd([VIT*0.3], max([VIT*0.3], [VIT^2/150]-1))

:- For monsters it's VIT + rnd(0, [VIT/20]^2-1)

:- VIT-based def reduces damage by [def] points after the percentage from armour def is applied.

:- Def can never reduce damage below 1 point.

MDEF:

:- MDEF stands for magic defence.

:- MDEF is split into two parts. MDEF derived from armour, and MDEF derived from INT.

:- Armour MDEF is equal to any MDEF bonuses on the armour.

:- INT-based MDEF reduces magic damage by [def] points after the percentage from armour MDEF is applied.

:- MDEF can never reduce spell damage below 1 point.

Flee:

:- Flee is a measurement of your ability to dodge attacks.

:- Flee is split into two parts. The first part is equal to BaseLevel + AGI + flee bonuses from cards, and each 1 point increases your chance of dodging an attack by 1%, with a minimum chance of 0% and a maximum of 95%.

:- The second part is equal to 1 + [LUK/10]. Each 1 point increases your chance of a "lucky" dodge, which is calculated before a normal dodge and separately from it.

HP:

:- Hit points. This one's pretty complex, so bear with me.

:- HP is equal to [([(35 + base level * HP multiplier from job + sigma of base level * HP factor from job)*(1 + VIT/100)]+HP additions from items)*HP multipliers from items]

:- Sigma of base level means adding up each integer from 2 to the character's base level.

:- HP additions from items are equal to whatever bonus, if any, that item gives to VIT.

(As this one's so complex, let's take an example. Let's say your character is a Mage, at level 12, and has 1 VIT.

HP multiplier for Mage is 5, HP factor is 0.3. So we have:

(35 + 12*5 + (2+3+4+5+6+7+8+9+10+11+12)*0.3) * (1+1/100)

Which simplifies to:

(35 + 60 + 77*0.3)*1.01

And further simplifies to:

(35 + 60 + 23.1)*1.01

And finally:

118.1*1.01 = 119 HP

Simple, huh?)

SP:

:- Skill Points. Not quite as complex as HP.

:- SP is equal to [([10 + base level * SP factor from job)*(1 + INT/100)]+SP additions from items)*SP multipliers from items]

:- SP additions from items are equal to whatever bonus, if any, that item gives to INT.

(Simpler, but could still benefit from an example. Let's take the level 12 Mage again, with 9 int. SP factor for Mage is 6.

(10 + 12*6)*(1+9/100)

Which simplifies to:

(10 + 72) * 1.09

And so:

82 * 1.09 = 89 SP

------

So we have all these stats, but they're all pretty useless if we're not going to use them. In my next article, I'll cover the battle calculations that actually make use of the stats. Until next time!

I see a lot of people who ask about algorithms, be it to work out battle damage, levelling up formulas, or the odds of winning in a game of chance.

The point of this article is to offer, if nothing else, some inspiration and a point in the right direction. I'm going to do this by looking at how calculations are done in a "professional" game. And while some of you might not like the game itself, I personally think that it has the balance down pretty well as far as calculations go. I'm talking, of course, about Ragnarok Online.

A lot of the concepts I'm going to discuss are specific to Ragnarok Online, but they may give you ideas for similar mechanics to implement in your own game, or point out something you had overlooked.

(Note: If a calculation is inside square brackets, you should round the value inside down. max(x, y) indicates that you should take the greater of the two values)

------

RO has six statistics. STR (strength), AGI (agility), VIT (vitality), INT (intelligence), DEX (dexterity) and LUK (luck).

STR offers the following:

:- +1 base damage per point for melee weapons

:- A bonus of [STR/10]^2 for melee weapons

:- +1 base damage per 5 points for ranged weapons

:- +30 carrying capacity per point of base STR (not counting bonuses)

AGI offers the following:

:- +1 flee per point

:- Increased attack speed per point (The full calculation is omitted as it's only really useful for real-time games)

VIT offers the following:

:- +1% to max HP per point

:- +0.8 weapon damage reduction per point

:- Effect of healing items increased by +2% per point

:- Every 5 points of VIT increases HP recovery rate by 1

:- Monsters receive a damage reduction bonus of rnd(0, [VIT/20]^2-1)

:- Players receive a damage reduction bonus of [VIT*0.5] + rnd([VIT*0.3], max([VIT*0.3], [VIT^2/150]-1))

:- +1 magic defence per 2 points

:- Decreased chance of being afflicted with poison, silence and stun.

INT offers the following:

:- +1 base magic attack per point

:- +1% to max SP per point

:- Effect of SP recovery items increased by +2% per point

:- Every 6 points of INT increases SP recovery rate by 1 and past 120 INT, every 2 points increases SP recovery rate by a further 1.

:- A bonus to minimum magic attack of [Int/7]^2

:- A bonus to maximum magic attack of [Int/5]^2

:- +1 spell damage reduction

:- Decreased chance of being afflicted with blind, sleep and stone curse.

DEX offers the following:

:- +1 hit per point

:- Increased attack speed per point

:- +1 base damage per point for ranged weapons

:- Bonus of [Dex/10]^2 for ranged weapons

:- +1 base damage per 5 points for melee weapons

:- +1 minimum damage per point for melee weapons. If DEX exceeds the attack of the weapon, then the weapon's attack is considered the minimum.

:- Reduces spell casting time by [Dex/1.5]%

:- +0.1% forging success chance per point

LUK offers the following:

:- +1 base damage per 5 points for ranged and melee weapons

:- +1 crit chance per 3 points

:- +1 lucky dodge chance per 10 points

:- +0.1% forging success chance per point

:- Decreased chance of being afflicted with any negative status (not as much as the effect of VIT/INT)

------

A lot of this won't apply to a traditional RPG - in a turn based battle system, what's the use in having attack speed? However, in a tactics or real-time system, these could be useful for you if you're trying to balance things out.

Of course, there are a myriad of substats referenced here that depend on the six base stats. They are as follows:

------

ATK:

:- ATK stands for, well, attack.

:- When unarmed, ATK is equal to STR + [STR/10]^2 + [DEX/5] + [LUK/5]

:- For ranged weapons, ATK is equal to DEX + [DEX/10]^2 + [STR/5] + [LUK/5]

:- When using a weapon, the weapon's attack stat is added to this value, as well as any attack power bonuses from cards.

MATK:

:- MATK stands for magic attack.

:- Minimum MATK is equal to INT + [INT/7]^2

:- Maximum MATK is equal to INT + [INT/5]^2

:- Any time a magic attack is used, a random number between the minimum and maximum is chosen and used as the damage value for every hit in the spell.

HIT:

:- Hit is your ability to hit a target.

:- Each point of hit increases hit success chance by 1%.

:- Hit is equal to BaseLevel + DEX + hit bonuses from cards

CRIT:

:- Crit, or critical, is your chance of striking a critical blow when you attack.

:- Each point of critical increases crit chance by 1%.

:- Crit is equal to 1 + LUK*0.3 + crit bonuses from cards

:- Criticals are checked before seeing if your hit overcomes your target's flee.

:- Crit is reduced by the LUK of your target / 5

:- A critical always hits for maximum damage and ignores DEF.

DEF:

:- Def stands for defence.

:- Def is split into two parts. Def derived from armour, and Def derived from VIT.

:- Armour Def is equal to BaseArmour + Refinements*2/3. Armour def reduces damage taken by a percentage.

:- VIT-based Def is different for players and monsters. For players it's [VIT*0.5] + rnd([VIT*0.3], max([VIT*0.3], [VIT^2/150]-1))

:- For monsters it's VIT + rnd(0, [VIT/20]^2-1)

:- VIT-based def reduces damage by [def] points after the percentage from armour def is applied.

:- Def can never reduce damage below 1 point.

MDEF:

:- MDEF stands for magic defence.

:- MDEF is split into two parts. MDEF derived from armour, and MDEF derived from INT.

:- Armour MDEF is equal to any MDEF bonuses on the armour.

:- INT-based MDEF reduces magic damage by [def] points after the percentage from armour MDEF is applied.

:- MDEF can never reduce spell damage below 1 point.

Flee:

:- Flee is a measurement of your ability to dodge attacks.

:- Flee is split into two parts. The first part is equal to BaseLevel + AGI + flee bonuses from cards, and each 1 point increases your chance of dodging an attack by 1%, with a minimum chance of 0% and a maximum of 95%.

:- The second part is equal to 1 + [LUK/10]. Each 1 point increases your chance of a "lucky" dodge, which is calculated before a normal dodge and separately from it.

HP:

:- Hit points. This one's pretty complex, so bear with me.

:- HP is equal to [([(35 + base level * HP multiplier from job + sigma of base level * HP factor from job)*(1 + VIT/100)]+HP additions from items)*HP multipliers from items]

:- Sigma of base level means adding up each integer from 2 to the character's base level.

:- HP additions from items are equal to whatever bonus, if any, that item gives to VIT.

(As this one's so complex, let's take an example. Let's say your character is a Mage, at level 12, and has 1 VIT.

HP multiplier for Mage is 5, HP factor is 0.3. So we have:

(35 + 12*5 + (2+3+4+5+6+7+8+9+10+11+12)*0.3) * (1+1/100)

Which simplifies to:

(35 + 60 + 77*0.3)*1.01

And further simplifies to:

(35 + 60 + 23.1)*1.01

And finally:

118.1*1.01 = 119 HP

Simple, huh?)

SP:

:- Skill Points. Not quite as complex as HP.

:- SP is equal to [([10 + base level * SP factor from job)*(1 + INT/100)]+SP additions from items)*SP multipliers from items]

:- SP additions from items are equal to whatever bonus, if any, that item gives to INT.

(Simpler, but could still benefit from an example. Let's take the level 12 Mage again, with 9 int. SP factor for Mage is 6.

(10 + 12*6)*(1+9/100)

Which simplifies to:

(10 + 72) * 1.09

And so:

82 * 1.09 = 89 SP

------

So we have all these stats, but they're all pretty useless if we're not going to use them. In my next article, I'll cover the battle calculations that actually make use of the stats. Until next time!

## Posts

Pages:
1

Pages:
1