Combat Formula

Started by
1 comment, last by erissian 15 years, 11 months ago
Sorry for posting in two sections, I wasn't sure where it belongs, please delete the incorrect one. Thanks I am working on a browser based role-playing game. I just started work on it tonight, so right now, the combat system is a matter of chance with VERY slight use of your level. It's win or lose based on chance. Later tonight, however, I will be adding an inventory and equipment system. I plan to add HP, STR and Def bonuses. STR and DEF would both be levels you could train, plus wearing the right equipment would boost them. I need a combat formula that can somehow factor in all my skills and my level, vs the npc's, and decide how much hp I hit and how much they hit. Can anybody help me with this, or at least get me started? I'm no good at logistical math. Here's the game, if you need a little reference. Keep in mind I just started it a few hours ago, so it's not that great yet. www.kolwebs.org/darkrealm Well I just thought something up, can anybody see any problems with this? Would this work on a normal basis? my_hit=(((mystr+hishp)*hislvl)/mylvl)/2 his_hit=((hislvl*(hishp-mylvl))/mydef)/2 if(his_hit <= 0){ hit = my_hit; // I would hit him my initial hit }else if(my_hit <= 0){ hit = his_hit; // He would hit me his initial hit }else if(my_hit > his_hit){ hit = (my_hit-his_hit)*2; // Meaning I would hit him the difference between our hits. }else if(my_hit < his_hit){ hit = (his_hit-my_hit)*2; // Meaning he would hit me the difference between our hits. } Let me use that in a few examples.... My level: 30 My str: 15 My Def: 13 My HP: 50 His Level: 25 His HP: 43 my_hit=(((15+43)*25)/50)/2 // Calculates to 14.5 rounded to 15 his_hit=((25*(43-30))/13)/2 // Calculates to 12.5 rounded to 13 15-13=2*2=4 // I would hit him for 4. Let's try another set. My Lvl: 50 My str: 45 My Def: 34 My HP: 44 His Lvl: 25 His HP: 43 my_hit=(((45+43)*25)/50)/2 //Calculates to be 22his_hit=((25*(43-50))/34)/2 //Calculates to be -2 Since His hit is negative it would be ignored, I would hit him for 22. My Lvl: 66, my str: 53, my def: 54, my HP: 59 His Lvl: 84, his HP: 81 my_hit=(((53+81)*84)/66)/2 //Calculates to 85 his_hit=((84*(81-66))/54)/2 // Calculates to 11. Dang, this means if he were stronger, I would still be hitting him way more than he hits me. I hit stronger depending on his level. Hmm If I change the formula to.... my_hit=((mystr*mylvl)/hislvl)/2 his_hit=((hislvl*hishp)/mydef)/2 my_hit=((53*66)/84)/2 // I would hit him for 20 his_hit = ((84*81)/54)/2 // He would hit me for 63 63-20=43 So he would finally hit me for 43 hit points. This seems around right to me. Let's try another with this formula. My Lvl: 50 My str: 45 My Def: 34 My HP: 44 His Lvl: 25 His HP: 43 my_hit=((45*50)/25)/2 // I hit him for 45 his_hit=((25*43)/34)/2 // He hits me for 15 45-15=30 I hit him for 30. Lets try roughly equal stats. My Lvl: 50 My str: 50 My Def: 50 My HP: 44 His Lvl: 50 His HP: 44 my_hit=((44*50)/50)/2 //I hit him for 22 his_hit=((50*44)/34)/2 // He hits me for 32 Hmm Something isn't right here? Can anybody help this cause? The problem is clearly the way I am differing the formulas, but I'm too tired to think better right now. Hopefully somebody can shed some light on this project! [EDIT] Should I stick with something simple, like my_hit= rand(0, ((mylvl+mystr)/2); his_hit = rand(0, ((hislvl+hishp+mydef)/3); And if it lands on a certain number/range, it hits? [Edited by - mrdek11 on May 10, 2008 1:34:25 AM]
Advertisement
Hi
I would preferably use something like this:
make into account level difference, every 1 level lower take from full damage 20%, every level beyond add +20% damage (+-5 LVL MAX), meaning if you are 20 lvl he is 18 lvl you will hit him with 120%, but if you are 20 and he is 24 you will hit him with only 20% (24-20 = 4*20% = 80%, 100-80 = 20%).
If you are 20 lvl and he is 15, you can hit enemies with 200%, but that is maximum don't give him experience points.
So level difference is -5 lvl no experience +5 lvl can't hit

For hitting you must take into account your strength, his defense and weapon.
Meaning your strength is added to weapon damage, minus defense: example, your strength is 50 his defense is 40 and your weapon make damage from 18-30 meaning
hit_min = (50-40)+18; //28
hit_max = (50-40)+30; //40
hit = (rnd()%(hit_max-hit_min)) + hit_min; // damage between 28-40

always take into account that player can miss, defend itself, dodge or anything similar.
Traditionally, there are several stats that determine the outcome of an attack.

Generally, I would recommend either (1) using stats such as strength, or weapon proficiency, ability to dodge and so forth which increase with level, but where the level is not directly involved in the formulas, or (2) use the level exclusively in the calculations and ignore individual stats, but allowing for weapon bonuses in damage and accuracy.

I wouldn't try to mix the two, as it's redundant.

So far, it looks like the variables you have in place are:

Level
Hit Points
Strength
Defense

Using this you calculate "hit," which isn't clear to me what its function is. Does this determine the damage done, or whether the blow lands?

In general, I've found that directly comparing differences in stats to be the hard way to go. I would go with something like this:

Strength (for damage determination)
Weapon Proficiency (for higher chance of hitting)
Defense (for reducing damage)
Dodge (for reducing chance of hitting)
Hit Points (threshold of damage)

These can all increase with level, or be simple functions of level, such as:
Let's say the level goes from 1-100.

Strength is an independent stat, let's say it's in the range of 0-100 and gives a damage bonus of 0-10
Weapon Proficiency determines what the chances of hitting the opponent are, and is in the range of 0.0-1.0. The base chance to hit an opponent is 50%, so for evenly matched opponents it could go either way.
Defense is the opposite of strength, and allows the player to absorb some damage, let's say the player can negate 1 point of damage for every 10th level.
Dodge allows the player to get out of the way of an attack, opposing weapon proficiency. It's in the range of 0.0-1.0, let's say it is the level divided by 100.
Hit Point are determined however you like, but you should try to decided how many successful attacks it should take to kill an equal opponent, versus how long it should take to kill an insignificant opponent.
All of these are subject to major tuning.

So an example combat would be:
my_dodge = my_level/100.0his_dodge = his_level/100.0my_chance_to_hit = 0.5 + my_weapon_proficiency - his_dodgehis_chance_to_hit = 0.5 + his_weapon_proficiency - my_dodgeif (random_number < my_chance_to_hit) {  my_damage = weapon_damage + my_strength/10 - his_defense/10  his_HP -= my_damage}


...And so on.

Of course, you don't have to implement something like this, but you may want to mull it over.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)

This topic is closed to new replies.

Advertisement