RPG damage equation

Started by
15 comments, last by gpalin 21 years, 8 months ago
Ah , the ever popular turn based RPG!!

I don''t suppose it would be a problem if you do the math on the fly if it is turn based, but better to get in the habit of pre-calculating now, before it becomes a problem later!!

Also the example you gave of a class is a user defined TYPE, which is fine really, but i was refering to an actual class file (.cls) so you build your class file very much like you built your User Defined Type, except your class file can be referenced by a collection, which is far easier to navigate through than an array(IMHO) which is what you will be stuck with if you use the UDT data structure, also you can code events into your class file so you don''t have to do a recursive poll to get your current game data, you can raise an event when your character attacks instead of constantly asking, in each game loop if your character has attacked. (oh hell, i guess in a turn based system optimization''s not such a big deal but events are really tidy, and easy to code!)

So you''re using the VB Controls to display your characters? Hey i wrote a few of those before i tackled my first display driver, you can come up with a pretty cool game really (and pump them out every 3 days or so after, just make sure your code is modular enough to re-use it)

Sorry for the long post. G/L


Dreddnafious Maelstrom

"If i saw farther, it was because I stood on the shoulders of giants."

Sir Isaac Newton
"Let Us Now Try Liberty"-- Frederick Bastiat
Advertisement
quote:
Ah , the ever popular turn based RPG!!

Yeah, I''ve played some before, and enjoyed them, so I wanted to try making one of my own. I didn''t think it would be a bad idea for a first game, so here I am!

quote:
I don''t suppose it would be a problem if you do the math on the fly if it is turn based, but better to get in the habit of pre-calculating now, before it becomes a problem later!!


By pre-calculating, do you mean to do all these calculation beforehand and store the results in an array or such? I don''t know if that would work, since my character generation system randomly generates statistics for the character being created, so the results would undoubtedly be different from the previous result. Or do you mean to do the calculating right after you finish creating thr character?

quote:
Also the example you gave of a class is a user defined TYPE, which is fine really, but i was refering to an actual class file (.cls) so you build your class file very much like you built your User Defined Type, except your class file can be referenced by a collection, which is far easier to navigate through than an array(IMHO) which is what you will be stuck with if you use the UDT data structure, also you can code events into your class file so you don''t have to do a recursive poll to get your current game data, you can raise an event when your character attacks instead of constantly asking, in each game loop if your character has attacked. (oh hell, I guess in a turn based system optimization''s not such a big deal but events are really tidy, and easy to code!)


So do you think I should convert the User Defined Type section to a seperate class file, then? I''ve never had to use class files before...I guess I''ll have to do some research on those.

quote:
So you''re using the VB Controls to display your characters? Hey I wrote a few of those before I tackled my first display driver, you can come up with a pretty cool game really (and pump them out every 3 days or so after, just make sure your code is modular enough to re-use it)


I haven''t even gottoen to the graphics yet...I''m still trying to get the basic game running, like I said before. You wrote a few VB controls before? How do you mean that? And what''s that about display drivers?

Grant Palin
Grant Palin
I have a new, simplified equation now. Take a look.

Old equation:
If Random(50) < x Then ‘Miss  Damage = 0   enemyHP = enemyHPElseIf Random(50) >= x and Random(50) < n Then ’Normal hit  If characterStrength > enemyEndurance Then    Damage = characterStrength + 5 + (characterAgility - enemyAgility) + Random(characterLevel)    enemyHP = enemyHP - Damage  ElseIf characterStrength < enemyEndurance Then    Damage = characterStrength - 5 + (characterAgility - enemyAgility) + Random(characterLevel)    enemyHP = enemyHP - Damage  End IfElseIf Random(50) >=n Then ‘Lucky hit- double damage  If characterStrength > enemyEndurance Then    Damage = 2 * (characterStrength + 5 + (characterAgility - enemyAgility) + Random(characterLevel))    enemyHP = enemyHP - Damage  ElseIf characterStrength < enemyEndurance Then    Damage = 2 * (characterStrength - 5 + (characterAgility - enemyAgility) + Random(characterLevel))    enemyHP = enemyHP - Damage  End IfEnd If  


New equation:
If Random(50) < x Then ‘Miss  Damage = 0  enemyHP = enemyHPElseIf Random(50) >= x and Random(50) < n Then ’Normal hit  Damage = characterStrength + (characterStrength - enemyEndurance) + (characterAgility - enemyAgility)  enemyHP = enemyHP - DamageElseIf Random(50) >=n Then ‘Lucky hit- double damage  Damage = 2 * (characterStrength + (characterStrength - enemyEndurance) + (characterAgility - enemyAgility))  enemyHP = enemyHP - DamageEnd If  


This simplified version removes the Random number using the characterLevel, since it doesn’t seem to have an impact on the damage done. Also, new statements have been added subtracting the enemyEndurance from the characterStrength. If the difference is positive, do more damage; if it is less, do less damage. This allowed the removal of several lines of code, which compared the characterStrength and enemyEndurance, adding or subtracting constant values from the flowing damage equation where appropriate. This equation does the job in less work, and is considerably shorter. This equation is only 10 lines, and the previous equation is 20 lines.

Please let me know what you think of this new equation. Thoughts on efficiency, comprehension etc are welcome.

Grant Palin

[edited by - gpalin on July 29, 2002 1:42:38 AM]
Grant Palin
quote:Original post by gpalin
If Random(50) < x Then ‘Miss  Damage = 0  enemyHP = enemyHPElseIf Random(50) >= x and Random(50) < n Then ’Normal hit  Damage = characterStrength + (characterStrength - enemyEndurance) + (characterAgility - enemyAgility)  enemyHP = enemyHP - DamageElseIf Random(50) >=n Then ‘Lucky hit- double damage  Damage = 2 * (characterStrength + (characterStrength - enemyEndurance) + (characterAgility - enemyAgility))  enemyHP = enemyHP - DamageEnd If   

i think you havea logic problem with your Random() function... assuming that it generates a random number each time it is called, there is a chance that none of your statements will be called; for example, if it is >=x the first time, then =n the third time, then also (and this following part is simply opinion and not debug help), you should use the agility of the character and enemy to determine if there is a hit, or maybe multiple hits, and leave the damage numbers to the strength. it kinda makes sense: it would be agility that determines if you hit or miss something, and also agility that determines if they can dodge it; the amount you hurt them (assuming you hit) would be based on how string you were and how strong they were (you might even want to put in another character trait for this, such as "defense" or something).
just my $0.02...

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
quote:Original post by krez
i think you havea logic problem with your Random() function... assuming that it generates a random number each time it is called, there is a chance that none of your statements will be called; for example, if it is >=x the first time, then =n the third time, then


I don't really understand...could you elaborate bit on that please?

quote:
also (and this following part is simply opinion and not debug help), you should use the agility of the character and enemy to determine if there is a hit, or maybe multiple hits, and leave the damage numbers to the strength. it kinda makes sense: it would be agility that determines if you hit or miss something, and also agility that determines if they can dodge it; the amount you hurt them (assuming you hit) would be based on how string you were and how strong they were (you might even want to put in another character trait for this, such as "defense" or something).


I thought of that too; for instance, the enemy is too fast to hit. I got that idea from other games. The problem is, I'm not sure yet how to implement it. Endurance is my defense-ish trait- it determines how much damage I can handle.

Grant Palin

[edited by - gpalin on July 29, 2002 8:26:02 PM]
Grant Palin
every time "Random(50)" appears in your formulas, it will pick a new random number between 0 and 50... so, the first line will pick a random number and compare it to "x". let''s say it picks a number greater than x, then it goes to the the "elseif" on line #4. now it picks a NEW random number and ocmpares it to x, then picks YET ANOTHER random number and compares it to n... because it is picking a new random number each time, it is quite possible that all of those conditions will be false, and nothing will happen (not even a "miss").
what you should do it get another variable and set it to Random(50), then use that variable in all of those IF statements...
did i make sense that time?

*** "timeout expired" error ***
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
quote:Original post by krez
every time "Random(50)" appears in your formulas, it will pick a new random number between 0 and 50... so, the first line will pick a random number and compare it to "x". let''s say it picks a number greater than x, then it goes to the the "elseif" on line #4. now it picks a NEW random number and ocmpares it to x, then picks YET ANOTHER random number and compares it to n... because it is picking a new random number each time, it is quite possible that all of those conditions will be false, and nothing will happen (not even a "miss").
what you should do it get another variable and set it to Random(50), then use that variable in all of those IF statements...
did i make sense that time?


All right, I understand now. How''s this, then?
z = Random(50)If z < x Then ‘Miss  Damage = 0  enemyHP = enemyHPElseIf z >= x and z < n Then ’Normal hit  Damage = characterStrength + (characterStrength - enemyEndurance) + (characterAgility - enemyAgility)  enemyHP = enemyHP - DamageElseIf z >=n Then ‘Lucky hit- double damage  Damage = 2 * (characterStrength + (characterStrength - enemyEndurance) + (characterAgility - enemyAgility))  enemyHP = enemyHP - DamageEnd If 

The way you explained it helped me understand. Thanks!

Grant Palin
Grant Palin

This topic is closed to new replies.

Advertisement