<
>
 Thread (3 posts)
mrdek11  5/10/08 12:27:16 AM

Rank: 1/100 Rank: 1/100 Rank: 1/100 Rank: 1/100 Rank: 1/100

Novice Member

Joined: 5/16/07
Posts: 4

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

- Derek -
The Dark Realm

mrdek11  5/10/08 12:41:42 AM

Rank: 1/100 Rank: 1/100 Rank: 1/100 Rank: 1/100 Rank: 1/100

Novice Member

Joined: 5/16/07
Posts: 4

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!

- Derek -
The Dark Realm

Barrikor  5/15/08 10:18:06 PM

Rank: 44/100 Rank: 44/100 Rank: 44/100 Rank: 44/100 Rank: 44/100

Advanced Member

Joined: 12/06/07
Posts: 63

You're using PHP?

Maybe something like this might work...


//----------------------------------------------------------
function AttackPower( $Stats )
{
$Level = $Stats[0];
$Str = $Stats[1];
$Def = $Stats[2];
$HP = $Stats[3];


// to keep the power from raising too fast every new level..
$ModifyDown = 0.25 ;

$Power = ($Level * $Str) * $ModifyDown;
/*
Close to your origional formula, I'd use
>>>>>>> $Power = ($Level + $Str);
instead of multiplying it though... I think multiplying would make the attack power go up too much at the higher levels.... if you do multiply then the $ModifyDown would help, multiplying the result by $ModifyDown is basically the same as dividing the number but the "/" eats up server time... multiplying by a decimal takes a lot less system resources. It only really matters if the formula is called a lot, but this one will be.

Also does "Level" matter for your game? Could you just use $Str alone in the formula?
*/
}


//----------------------------------------------------------


function DefensePower( $Stats )
{
$Level = $Stats[0];
$Str = $Stats[1];
$Def = $Stats[2];
$HP = $Stats[3];


$ModifyDown = 0.30; //a little higher then at AttackPower

$Power = ($Level * $Def) * $ModifyDown;
//or maybe $Power = ($Level + $Def); instead ???
}


//----------------------------------------------------------

// This code would work best in a function or loop:
//
//
//

$My_Stats = array( $My_Level , $My_Str , $My_Def , $My_HP);
$His_Stats = array( $His_Level , $His_Str , $His_Def , $His_HP);

//My Attack at him
$His_HP = $His_HP -( AttackPower($My_Stats) - DefensePower($His_Stats));

//His Attack at me
$My_HP = $My_HP - ( AttackPower($His_Stats) - DefensePower($My_Stats));


//------------------------------------------------------------


It would be good to add a little bit of randomness to it though... If the player always hits the same number against the mob then a long fight would be boring...

Also maybe you should have different attack modes; ex: slash, stab, over-defensive, over-aggressive etc. maybe each mob would have a given attack mode that it's weaker against... The weapons could have a mode that they hit more with...

$His_HP = $His_HP - ( (AttackPower($My_Stats) + getWeaponBonus($My_Stats)) - (DefensePower($His_Stats) - getModeWeakness($My_Stats,$His_Stats)));

The way I have arrays being passed into the functions might not be a good idea though, some of the values passed won't be used by the function and passing them is unnecessary work for the server... Passing them individually would be better. (But it would clutter up my example if I did it here :)

...

Anyway, everything I wrote up above is just guesswork, only you know what's best for your game.

- Barrikor