Original Post
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!