Regen code rewriting need tester and feedback

If you want to help us or give some corrections / codes, put it here ;)

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

Regen code rewriting need tester and feedback

Postby Planetary_Myth on Thu Oct 28, 2010 4:25 am

Edit: Updated code condensed it and removed logs not needed. (Tested)

This should be closer to official and should fix the bugs I noticed.

Below you will notice a difference at higher lvls when healing.
Note: This is optional you can leave the old values.

In: playerstats.cpp
  1. // Get MP Regeneration Amount                   //A_MP_REC_RATE(28) / MP_REC_RATE(57)
  2. unsigned int CPlayer::GetMPRegenAmount( )
  3. {
  4.     UINT amount = (UINT)ceil ( Stats->MaxMP * 0.03 );


  1. // Get HP Regeneration Amount                   //A_HP_REC_RATE(27) / HP_REC_AMONT5(56)
  2. unsigned int CPlayer::GetHPRegenAmount( )
  3. {
  4.     UINT amount = (UINT)ceil ( Stats->MaxHP * 0.022 );


This fixes the extra calculations that should of not been called.
This fixes insta heal when hit with full Hp.
This also fixes parts of the code that was not getting right values.
e.g. lastRegenTime_hp and mp were being set to 0.

In: playerfunctions.cpp
  1. // HP/MP Regeneration Function
  2. bool CPlayer::Regeneration()
  3. {
  4.     if (Stats->MaxHP==Stats->HP)
  5.        lastRegenTime_hp = clock();
  6.  
  7.     if (Stats->MaxMP==Stats->MP)
  8.       lastRegenTime_mp = clock();
  9.      
  10.     if ((Stats->MaxHP==Stats->HP)&&(Stats->MaxMP==Stats->MP))
  11.        return true;
  12.  
  13.      UINT bonus_sitted=1;
  14.      UINT bonus_fairy=1;
  15.      int bonus_hp=0;
  16.      int bonus_mp=0;      
  17.      int nb_sec_stance=8;   //Original setting was 5
  18.  
  19.      if(Fairy)
  20.      {
  21.      nb_sec_stance= 8;      //Original setting was 3
  22.      bonus_mp++;
  23.      bonus_hp++;
  24.      bonus_fairy=3;
  25.      }
  26.      if (Status->Stance==1)
  27.      {
  28.      nb_sec_stance= 5;      //Original setting was 3
  29.      bonus_mp++;
  30.      bonus_hp++;
  31.      bonus_sitted=3;
  32.      }
  33.      
  34.      int TimeDiff=nb_sec_stance*CLOCKS_PER_SEC;
  35.    
  36.     //LMA: HP
  37.     if (Stats->HP<Stats->MaxHP)
  38.     {
  39.         clock_t etimeHP = clock() - lastRegenTime_hp;
  40.  
  41.         if( etimeHP >= TimeDiff && Stats->HP > 0 )
  42.         {
  43.             unsigned int hpamount = GetHPRegenAmount( );
  44.  
  45.             if (bonus_hp!=0)
  46.             {
  47.                Stats->HP += (long int) (hpamount*bonus_sitted)*bonus_fairy;
  48.                //Log(MSG_INFO,"REGEN HP %i(%i*%i)*%i",(long int) (hpamount*bonus_sitted)*bonus_fairy,hpamount,bonus_sitted,bonus_fairy);
  49.             }
  50.             else
  51.             {
  52.                 Stats->HP += hpamount;
  53.             }
  54.             if( Stats->HP > Stats->MaxHP)
  55.                 Stats->HP = Stats->MaxHP;
  56.  
  57.             if (Stats->HP < Stats->MaxHP)
  58.                 lastRegenTime_hp = clock();
  59.         }
  60.     }
  61.  
  62.     //LMA: MP
  63.     if(Stats->MP<Stats->MaxMP)
  64.     {
  65.         clock_t etimeMP = clock() - lastRegenTime_mp;
  66.  
  67.         if( etimeMP >= TimeDiff && Stats->HP > 0 )
  68.         {
  69.             unsigned int mpamount = GetMPRegenAmount( );
  70.  
  71.             if (bonus_mp!=0)
  72.             {
  73.                Stats->MP += (long int) (mpamount * bonus_sitted)* bonus_fairy;
  74.                //Log(MSG_INFO,"RegenMP %i(%i*%i)*%i",(long int) (mpamount*bonus_sitted)*bonus_fairy,mpamount,bonus_sitted,bonus_fairy);
  75.             }
  76.             else
  77.             {
  78.                 Stats->MP += mpamount;
  79.             }
  80.             if( Stats->MP > Stats->MaxMP )
  81.                 Stats->MP = Stats->MaxMP;
  82.                
  83.             if (Stats->HP < Stats->MaxHP)
  84.                 lastRegenTime_mp = clock();
  85.         }
  86.     }
  87.     return true;
  88. }
Last edited by Planetary_Myth on Sun Nov 07, 2010 4:44 am, edited 6 times in total.
Planetary_Myth
Smoulie
Smoulie
 
Posts: 49
Joined: Sun Apr 18, 2010 2:50 pm

Re: Regen code rewriting need tester and feedback

Postby lmame on Thu Oct 28, 2010 11:38 pm

Hummm bonfire and salamender should "heal" using skills so it should be automatic through AIPs. That's why they aren't in this part of code anymore.
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: Regen code rewriting need tester and feedback

Postby Raavi on Fri Oct 29, 2010 11:40 am

I've tested it from level 1 to 180 and it works kinda the same as NaRose congratz !
Raavi
Rackie
Rackie
 
Posts: 243
Joined: Sun May 30, 2010 4:15 pm

Re: Regen code rewriting need tester and feedback

Postby will1023631 on Fri Oct 29, 2010 5:32 pm

The code looks great but Thriel attempted to implement it on our server but it caused severe lag on our server. Once we placed that original code that came with Rev II and the lag was gone. Just to let you know
User avatar
will1023631
Jelly Bean
Jelly Bean
 
Posts: 30
Joined: Thu Jul 01, 2010 7:17 pm

Re: Regen code rewriting need tester and feedback

Postby Planetary_Myth on Fri Oct 29, 2010 5:57 pm

Thanks for testing and as for lagging yes it does.
I read more about using "while" and found it uses alot of the processor and until it returns true it holds up the server from doing other code.
I found this is also true with "for statements"
"Sleep()" on the other hand uses next to no process time but also lags the server.
So for now I am going to try a different approach.
Planetary_Myth
Smoulie
Smoulie
 
Posts: 49
Joined: Sun Apr 18, 2010 2:50 pm

Re: Regen code rewriting need tester and feedback

Postby lmame on Sat Oct 30, 2010 8:09 pm

Oh my I didn't see the while... Yeah indeed it's not a good idea.
It stops other processes as well...
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: Regen code rewriting need tester and feedback

Postby Planetary_Myth on Sun Oct 31, 2010 7:24 pm

Reworked the code and now should work without lagging the server.
All sal/bon code was removed.
Planetary_Myth
Smoulie
Smoulie
 
Posts: 49
Joined: Sun Apr 18, 2010 2:50 pm

Re: Regen code rewriting need tester and feedback

Postby Xsidol on Mon Nov 01, 2010 4:35 pm

with this code the food and potions are instant heal, which is not normal. but other than that its quite nicely done.
We Have it all ... Image
Image
User avatar
Xsidol
Smoulie
Smoulie
 
Posts: 60
Joined: Tue Dec 29, 2009 3:34 pm

Re: Regen code rewriting need tester and feedback

Postby Planetary_Myth on Tue Nov 02, 2010 8:04 pm

Xsidol wrote:with this code the food and potions are instant heal, which is not normal. but other than that its quite nicely done.


Ok put a new code set in first post try that one.
Changed it to that one because it was less code.
I quickly tested, all worked ok, used a banana and worked like it was supposed to.
I will run more tests when I get home from work.

Thank you for testing.
Planetary_Myth
Smoulie
Smoulie
 
Posts: 49
Joined: Sun Apr 18, 2010 2:50 pm

Re: Regen code rewriting need tester and feedback

Postby Xsidol on Tue Nov 02, 2010 9:18 pm

ill give it a try and post any feedback.
We Have it all ... Image
Image
User avatar
Xsidol
Smoulie
Smoulie
 
Posts: 60
Joined: Tue Dec 29, 2009 3:34 pm

Next

Return to Submit Code

Who is online

Users browsing this forum: No registered users and 6 guests

cron