[devRev4] Where is the Mob Accuracy calculation coded?

Welcome in the osRose emulator Project.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

[devRev4] Where is the Mob Accuracy calculation coded?

Postby kismetbecomes on Mon Apr 15, 2013 2:32 pm

Hi again, I was busy changing all monster attributes to balance things up and keep the players interested of grinding throughout all maps and I've noticed an odd thing.

list_config.sql = monster_acc (global/universal monster accuracy setting) doesn't seem to work. I'am level 250, maxed all stat to 500, equipped a high dodge raider armor but level 30 mobs can still hit me.. No MISS at all. Although, sikuku underground prison mobs misses sometimes. I have set the monster_acc = 1, still no change. :lol:

I have not changed the stb value of the mobs accuracy, because if that will be the only option then I'am foreseeing a lot of work as I was planning to change mob accu's universally. (don't ask why, there's something I have in mind.) :)

I don't want to mess up all the coded, if you would be so kind, please point me where it is coded and hopefully I/you/we can fix it. Thanks a lot and cheers!
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby PurpleYouko on Tue Apr 16, 2013 2:16 pm

accuracy is determined in Battle.cpp function NormalAttack()

  1. // dodge
  2.     unsigned int hitvalue = (unsigned int)floor(Stats->Accuracy * 50 / Enemy->Stats->Dodge);
  3.     if(hitvalue>100) hitvalue = 100;
  4.     if(GServer->RandNumber( 0, 100 )>hitvalue)
  5.         hitpower = 0; // dodged

At the moment it isn't even using the config value at all.
The easiest way to make it use the config value is to replace the 50 in the calculation. It's a constant so it will be pretty easy.
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby kismetbecomes on Tue Apr 16, 2013 4:37 pm

PurpleYouko wrote:accuracy is determined in Battle.cpp function NormalAttack()

  1. // dodge
  2.     unsigned int hitvalue = (unsigned int)floor(Stats->Accuracy * 50 / Enemy->Stats->Dodge);
  3.     if(hitvalue>100) hitvalue = 100;
  4.     if(GServer->RandNumber( 0, 100 )>hitvalue)
  5.         hitpower = 0; // dodged


At the moment it isn't even using the config value at all.
The easiest way to make it use the config value is to replace the 50 in the calculation. It's a constant so it will be pretty easy.



I'm sorry. Please explain 50. Replacing it with a higher number would mean higher DODGE rate for players or otherwise?
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby kismetbecomes on Tue Apr 16, 2013 5:47 pm

I don't know but I can't seem to find that code you gave me PY under battle.cpp. :(

Altho, I found this and don't get it. :D

  1. //Dodge - If we successfully dodge damage = 0 and should skip rest of calculations to free up CPU time
  2.     float hitchance;
  3.     if(!IsMonster( )) hitchance = Stats->Accuracy / statmodifier; else hitchance = (Stats->Accuracy/10) / statmodifier; //can have a hitchance of 75% at level 220 when same level
  4.     float dodgechance = Enemy->Stats->Dodge / statmodifier; //enemys dodge chance up to 75% at level 220 when same level
  5.     if(hitchance > 75) hitchance = 75;
  6.  
  7.     int serverrandom = GServer->RandNumber( 0, 100 );
  8.  
  9.     if(IsMonster( ) && !IsSummon()) //monsters have a static 19% dodge level when at the same level
  10.     {
  11.         if(serverrandom < (19-hitchance)) //19 was chosen as at level 1 with default accuracy its 5% chance to dodge
  12.             dodge=true; // dodged
  13.     }
  14.     else
  15.     {
  16.         if(dodgechance > 75) dodgechance = 75;
  17.  
  18.         if(serverrandom < (dodgechance - hitchance)) //enemys dodge chance - your hit chance
  19.             dodge=true; // dodged
  20.     }



Please explain me those lines. I think it calculates mob accuracy and players' dodge?
And what is a statmodifier? What is its value? Is it coded somewhere else?

I'm sorry I'm sorry... I just so confused right now.
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby PurpleYouko on Wed Apr 17, 2013 2:55 pm

I have no idea where the code that you posted code came from.
it looks like an independent mod that was added after initial release.

What I have is the roseZA source from just before it was released as dev rev 4.
If anything got updated after that then i don't have it. I have not been keeping up with mods to the source.

Looks to me like statmodifier is a local variable. it should be defined nearer to the top of the NormalAttack function

The code as will calculate the hitchance of both monster and player.
for monster it is hitchance = (Stats->Accuracy/10) / statmodifier;
for player it is hitchance = Stats->Accuracy / statmodifier;
Note the conditional uses a NOT operand if(!IsMonster( )) so the logic is reversed from what it might look like initially
It seems this was done to reduce monster accuracy by a factor of 10 across the board. You could change the 10 to whatever you like to penalize the monsters

Dodgechance appears to be the same for monsters and players
float dodgechance = Enemy->Stats->Dodge / statmodifier; //enemys dodge chance up to 75% at level 220 when same level
Note that Enemy can be either player or monster. It is whatever the currently selected character (player or monster) is fighting.
Then it is capped at a maximum of 75

Next it generates a random number between 0 and 100 and stores it in local variable serverrandom.

then it gets a bit strange.
First it calculates if the hit was dodged by non-summon monsters
  1. if(IsMonster( ) && !IsSummon()) //monsters have a static 19% dodge level when at the same level
  2.     {
  3.         if(serverrandom < (19-hitchance)) //19 was chosen as at level 1 with default accuracy its 5% chance to dodge
  4.             dodge=true; // dodged
  5.     }

The reason I say it gets strange is that we need serverrandom to be less than the condition (19 - hitchance) for a successful dodge.
It appears that as the attacker's hitchance goes up (i.e. he has greater accuracy) the condition is going to go down (get more negative). So it should but I'm not so sure about the logic here.
with hitchance = 5 then serverrandom needs to be lower than (19 - 5 = 14) for a successful dodge. 14%
with hitchance = 75 (maximum) then serverrandom needs to be less than (19 - 75 = -56) It's clearly impossible for a value in the range of 0 - 100 to be less than -56 so something is seriously wrong with this formula :?
What it means is that for any monster attack against a player of summon if its accuracy is greater than 19 then it cannot ever be dodged
It scales wrong.
No negative values should ever come from a formula like this. The concept is fine but I think it needs to be overhauled and re-balanced. Usually the use of any Addition or subtraction should be avoided in this type of formula. Better to use division and multiplication. That way it can be kept in the right range.

now the other cases
  1.  
  2. else
  3.     {
  4.         if(dodgechance > 75) dodgechance = 75;
  5.  
  6.         if(serverrandom < (dodgechance - hitchance)) //enemys dodge chance - your hit chance
  7.             dodge=true; // dodged
  8.     }

at least now we use the dodgechance value for something. it wasn't used at all in the monster attack formula.
So anyway the ELSE clause means this applies to anything that is not a monster
Basically for any case where the Enemy's dodgechance is greater than the attacker's hitchance there is ZERO chance of scoring a hit.
There should always be a small chance of a successful hit even if the dodgechance is greater than the hitchance
Good luck fighting above your level with a formula like that. You are never going to hit anything.
try dividing dodgechance by hitchance and multiplying by 50
when the two are equal the division will result in 1. Multiply by 50 to get a 50% chance which seems fair
If dodgechance is 75 (max) and hitchance is only 50 then D/H*50 = 33%
My example may be scaled a little wrong but you get the idea right? Keep your actual chance of scoring a hit positive
You could use (dodgechance / (hitchance * 2) * 50) or whatever that would give 25% when the two are the same and 16% for the two examples above.
It will NEVER go negative though
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby PurpleYouko on Wed Apr 17, 2013 3:14 pm

Here is how I did it in KTRose

  1. unsigned int totalchance = Stats->Accury + Enemy->Stats->Dodge;
  2.     double acdm = Stats->Accury * 100 / totalchance;
  3.     unsigned int hitchance = (unsigned int)floor(acdm);
  4.     if(GServer->RandNumber( 0, 100 ) > hitchance)
  5.     {
  6.         hitpower = 0; // dodged
  7.         //Log(MSG_DEBUG,"accuracy %i dodge %i",Stats->Accury,Enemy->Stats->Dodge);
  8.         //Log(MSG_DEBUG,"Dodged total %i mod %f hit chance %i",totalchance,acdm,hitchance);
  9.     }
  10.     else
  11.     {
  12.    


Note earlier code bases used accury instead of accuracy. no idea why.
Anyway this method is ridiculously simple.
You add accuracy and dodge together to make totalchance
Now you multiply your accuracy by 100 and divide it by totalchance and convert it back to an integer called hitchance
Now we make a random number from 0 to 100
If it's greater than hitchance then the attack was dodged so we set hitpower to zero.
DONE!

now for some math examples. remember that these values can be many many hundred. 1000 or more is not uncommon in the STB
accuracy = 50
dodge = 50
totalchance = 50 + 50 = 100
hitchance = (50 * 100) / 100 = 50%

accuracy = 654
dodge = 317
totalchance = 971
hitchance = (654 * 100) / 971 = 67%

It works for any combination and always gives a percentage as the answer. There will never be a 100% or a 0% no matter how ridiculously unmatched the values are

accuracy = 1000
dodge = 5
(level 200 vs a jelly bean maybe?)
totalchance = 1005
hitchance = (1000 * 100) / 1005 = 99.5% (rounded down to 99%)

accuracy = 25
dodge = 10000
(Jelly bean attacking a ridiculously decked out high level player with maxed out DEX and all dodge gear equipped maybe?)
totalchance = 10025 (unrealistically huge really but just making a point)
hitchance = (25 * 100) / 10025 = 0.25%. OK so this does round down to zero but so what? You didn't really expect the jelly bean to have a snowball's chance in hell in this fight did you?

The point is that the formula ALWAYS returns a value between 0 and 99 and that's what we want when it comes to combat chances
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby kismetbecomes on Thu Apr 18, 2013 6:22 pm

Hello PY. My jaw dropped after reading all that, and it is very clear I should say. :D Since these are all calculations, and no packets are involved, is it safe that I revise the Rev4 accuracy/dodge calculation based from how you did it in KTRose?

EDIT:
Assuming I can code it correctly? :lol: Anyway, I will try. :)
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby PurpleYouko on Fri Apr 19, 2013 3:20 pm

just grab the KT source and port it over.

One note though. If you find anything unbalanced in this system it's far easier to adjust the STB values for attack, def, accuracy and dodge than it is to mess with the formula.
I began a project to balance the entire STB in KTRose but while I was working on that kind of stuff my staff members who were so frickin keen to launch an incomplete client onto the public, decided to go AWOL and stopped doing their jobs. That was why i finally said fuck it and stopped developing the thing.
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: [devRev4] Where is the Mob Accuracy calculation coded?

Postby kismetbecomes on Sun Apr 21, 2013 3:44 pm

PurpleYouko wrote:just grab the KT source and port it over.

One note though. If you find anything unbalanced in this system its far easier to adjust the STB values for attack, def, accuracy and dodge than it is to mess with the formula.
I began a project to balance the entire STB in KTRose but while I was working on that kind of stuff my staff members who were so frickin keen to launch an incomplete client onto the public, decided to go AWOL and stopped doing their jobs. That was why i finally said fuck it and stopped developing the thing.


Although it might be a lot of work, but, I'd rather take your advise to adjust the stbs instead. Thanks for that. I don't know how to reformulate the whole thing like how you did it it Ktrose anyway. I thought and was thinking I could just copy, replace, and replace some ints etc2. :?

I' am really tempted to try ktRose for some time now. And see how amazing it works. :lol:
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am


Return to Support - OsRose Emulator

Who is online

Users browsing this forum: No registered users and 7 guests

cron