Fix your refines. (not quite as messy)

Submit code for osProse project.

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

Fix your refines. (not quite as messy)

Postby PurpleYouko on Tue May 13, 2008 5:38 pm

These instructions will allow you to make refines work in osProse.

Included are changes to

server code

startup.cpp
worldpackets.cpp
datatypes.h
sockets.h

sql
A small mod to our new list_config database table (there will be a lot of these to come as I add more and more configurable items)
This time I'm adding a value to set it so that it becomes easier (or not) to refine rare items. If you don't want it to be easier, leave it at zero.
I'm also adding a configurable option that allows you to set whether you want items to be destroyed (1) or downgraded (0) on a failed refine attempt.
Failed attempts above level 5 will always fail (unless you mod the code)
just run this small query into your database.
  1.  
  2. ALTER TABLE `list_config` ADD `rare_refine` INT NOT NULL DEFAULT '0' AFTER `refine_chance` ;
  3. ALTER TABLE `list_config` ADD `kill_on_fail` BOOL NOT NULL DEFAULT '0' AFTER `exp_rate` ;
  4.  

It is a prerequisite that you already have the list_config database table from my drops code. Otherwise it will not run.


Datatypes.h
We need to add an item to the CEquip structure to track the "raretype" of an item. This will be needed in various places throughout the server.

find

After, add


Sockets.h
find

after, add
  1.  
  2. int Rare_Refine;
  3. int KillOnFail;
  4.  


Worldpackets.cpp
We need to seriously modify the refine system from the irose version
find
  1.  
  2.         case 0x04://NPC Refine
  3.         case 0x05://Player Refine
  4.  

replace all code down to the next break; with this
  1.  
  2.         case 0x04://NPC Refine
  3.         case 0x05://Player Refine
  4.         {
  5.             BYTE item = GETBYTE((*P),3);
  6.             BYTE material1 = GETBYTE((*P),4);
  7.             if(!CheckInventorySlot( thisclient, item))
  8.                 return false;
  9.             if(!CheckInventorySlot( thisclient, material1))
  10.                 return false;
  11.             if(thisclient->items[item].count<1 || thisclient->items[material1].count<1)
  12.             {
  13.                 BEGINPACKET( pak, 0x7bc );
  14.                 ADDBYTE    ( pak, 0x12 );
  15.                 ADDBYTE    ( pak, 0x00 );
  16.                 thisclient->client->SendPacket( &pak );
  17.                 return true;
  18.             }
  19.             unsigned int nextlevel = ( thisclient->items[item].refine / 16 ) + 1;
  20.             if( nextlevel > 9 )
  21.                 return true;//if a client were able to try and upgrade an lvl 9 grade item this would probebly lockup this client
  22.  
  23.             thisclient->items[material1].count -=1;
  24.             if ((thisclient->items[material1].count)<1)
  25.             ClearItem( thisclient->items[material1] );
  26.  
  27.            
  28.             bool success = true;
  29.             srand( time(NULL));
  30.             unsigned int prefine = rand()%100;
  31.             int refinechance = upgrade[nextlevel];
  32.             int itemtype = thisclient->items[item].itemtype;
  33.             int itemnum = thisclient->items[item].itemnum;
  34.             if( GServer->EquipList[itemtype].Index[itemnum]->raretype != 0 )
  35.                 refinechance += GServer->Config.Rare_Refine;
  36.             if( prefine > refinechance)
  37.                 success = false;
  38.            
  39.             BEGINPACKET( pak, 0x7bc )
  40.             if( success )
  41.             {
  42.                 thisclient->items[item].refine = nextlevel*16;
  43.                 ADDBYTE    ( pak, 0x10 );//successful
  44.             }
  45.             else
  46.             {
  47.                 if(GServer->Config.KillOnFail || nextlevel > 5)
  48.                 {
  49.                     ClearItem( thisclient->items[item] );
  50.                 }
  51.                 else
  52.                 {
  53.                     thisclient->items[item].refine = (nextlevel-2)*16;
  54.                 }
  55.                 ADDBYTE    ( pak, 0x11 );//Fail
  56.             }
  57.             {ADDBYTE    ( pak, 0x04 );}
  58.             ADDBYTE    ( pak, material1 );
  59.             ADDWORD   ( pak, BuildItemHead( thisclient->items[material1] ) );
  60.             ADDDWORD   ( pak, BuildItemData( thisclient->items[material1] ) );
  61.             ADDBYTE    ( pak, item );
  62.             ADDWORD   ( pak, BuildItemHead( thisclient->items[item] ) );
  63.             ADDDWORD   ( pak, BuildItemData( thisclient->items[item] ) );
  64.             ADDBYTE    ( pak, 0x00 );
  65.             ADDDWORD   ( pak, 0x002f0000 );
  66.             ADDDWORD   ( pak, 0x00000017 );
  67.             thisclient->client->SendPacket( &pak );
  68.  
  69.         }
  70.         break;
  71.  

Yes it is much shorter.
in pre-evo, player refine is not actually possible but it should not hurt to leave the switch in place for it since I don' think it is used elsewhere.


Startup.cpp
There are actually a few problems in startup.cpp due to some of the references in the STB reading code, looking at the wrong places or just plain wrong.
An example of this is 'itemgrade' which is simply being set to zero for every item. Can't imagine why.
We are going to need itemgrade to make sure that the correct binds and talis are being used to refine our stuff so I will modify it.
It will probably be easier to just put up the entire function for LoadEquip()
so here it is.

find
  1.  
  2. bool CWorldServer::LoadEquip( )
  3.  

replace entire function with
  1.  
  2. bool CWorldServer::LoadEquip( )
  3. {
  4.     Log( MSG_LOAD, "Equip Data         " );
  5.     for(int j=0;j<9;j++)      
  6.     {
  7.         for(unsigned int i=0;i<STB_ITEM[j].rowcount;i++)
  8.         {
  9.             CEquip* newequip = new (nothrow) CEquip;
  10.             if(newequip==NULL)
  11.             {
  12.                 Log(MSG_WARNING, "\nError allocing memory: equip" );
  13.                 return false;
  14.             }
  15.             newequip->id = i;
  16.             newequip->equiptype = (j+1);
  17.             newequip->type = STB_ITEM[j].rows[i][4];
  18.             newequip->price = STB_ITEM[j].rows[i][5];
  19.             newequip->pricerate = STB_ITEM[j].rows[i][6];
  20.             newequip->weight = STB_ITEM[j].rows[i][7];
  21.             newequip->quality = STB_ITEM[j].rows[i][8];
  22.             newequip->level = STB_ITEM[j].rows[i][13];
  23.             newequip->material = STB_ITEM[j].rows[i][14];
  24.             newequip->defense = STB_ITEM[j].rows[i][31];
  25.             newequip->magicresistence = STB_ITEM[j].rows[i][32];
  26.             newequip->attackdistance = STB_ITEM[j].rows[i][33];//Speed of travel/Range
  27.             if(newequip->equiptype==SHOE)
  28.             {
  29.                 newequip->movespeed = newequip->attackdistance;
  30.             }
  31.             else
  32.             {
  33.                 newequip->movespeed = 0;
  34.             }
  35.    
  36.             if (STB_ITEM[j].fieldcount>35){
  37.                 newequip->attackpower = STB_ITEM[j].rows[i][35];
  38.                 newequip->attackspeed = STB_ITEM[j].rows[i][36];
  39.             }
  40.             else{  
  41.                 newequip->attackpower = 0;
  42.                 newequip->attackspeed = 0;
  43.             }
  44.            
  45.    
  46.             for(int k=0;k<3;k++)
  47.                 newequip->occupation[k] = STB_ITEM[j].rows[i][(16+k)];
  48.             for(int k=0;k<2;k++)
  49.                 newequip->condition1[k] = STB_ITEM[j].rows[i][(19+k)];
  50.             for(int k=0;k<2;k++)
  51.                 newequip->condition2[k] = STB_ITEM[j].rows[i][(21+k)];
  52.             for(int k=0;k<2;k++)
  53.                 newequip->stat1[k] = STB_ITEM[j].rows[i][(24+k)];
  54.             for(int k=0;k<2;k++)
  55.                 newequip->stat2[k] = STB_ITEM[j].rows[i][(27+k)];
  56.             newequip->itemgrade = STB_ITEM[j].rows[i][46];
  57.             newequip->raretype = STB_ITEM[j].rows[i][47];
  58.             EquipList[newequip->equiptype].Data.push_back( newequip );
  59.             EquipList[newequip->equiptype].Index[newequip->id] = newequip; // Index to read more quickly the data
  60.             //delete newequip;
  61.         }
  62.     }
  63.     return true;
  64. }
  65.  


we also need to put in a new version of LoadConfig() to allow for the new config stuff.
find
  1.  
  2. bool CWorldServer::LoadConfig( )
  3.  

replace the entire function with
  1.  
  2. bool CWorldServer::LoadConfig( )
  3. {
  4.     Log( MSG_INFO, "Loading database config files" );
  5.     MYSQL_ROW row;    
  6.     MYSQL_RES *result = DB->QStore("SELECT exp_rate, drop_rate, zuly_rate, blue_chance, stat_chance, slot_chance, \
  7.         refine_chance, rare_refine, kill_on_fail FROM list_config");
  8.     if(result==NULL)
  9.     {
  10.         DB->QFree( );
  11.         return false;
  12.     }
  13.     while( row = mysql_fetch_row(result) )
  14.     {
  15.        GServer->Config.EXP_RATE = atoi(row[0]);
  16.        GServer->Config.DROP_RATE = atoi(row[1]);
  17.        GServer->Config.ZULY_RATE = atoi(row[2]);
  18.        GServer->Config.BlueChance = atoi(row[3]);
  19.        GServer->Config.StatChance = atoi(row[4]);
  20.        GServer->Config.SlotChance = atoi(row[5]);
  21.        GServer->Config.RefineChance = atoi(row[6]);
  22.        GServer->Config.Rare_Refine = atoi(row[7]);
  23.        GServer->Config.KillOnFail = atoi(row[8]);
  24.     }
  25.     DB->QFree( );
  26.     Log( MSG_INFO, "Config Data Loaded" );  
  27.     return true;
  28. }
  29.  


CSV
It should also be noted that the CSV file "refine_data" in your data folder, is just ever so slightly WRONG.
it presently looks like
  1.  
  2. grade   probability
  3. 1   95
  4. 2   85
  5. 3   70
  6. 4   60
  7. 5   50
  8. 6   25
  9. 7   25
  10. 8   15
  11. 9   10
  12.  

the STB in the osProse client says it should look like this
  1.  
  2. grade   probability
  3. 1   100
  4. 2   100
  5. 3   100
  6. 4   70
  7. 5   50
  8. 6   30
  9. 7   30
  10. 8   20
  11. 9   20
  12.  

You should probably change that otherwise you will keep failing your refines before you get to level 3.

Database Configurations
In your newly modified list_config table you can now set two new features related to refining.
1 Set 'rare_refine' to any value you like (0-100) This value will be added to the refine chance of any item that has a non-zero 'raretype' value. i.e. it is a blue or some other special item.
2 Set 'kill_on_fail' to 1 or 0. If set to 0 then any failed refine attempt up to level 5 will result in a refine level reduction rather than destruction of the item.
If you try for 6 and fail though, your item is gone forever.
if set to 1, any failed attempt will destroy the item. Use this if you are a purist.

Unfortunately there is no way to make the client tell you it has been reduced. You will always get the fail message saying that your item will be destroyed. ;)
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: 4598
Joined: Fri Aug 10, 2007 2:05 pm

Re: Fix your refines. (not quite as messy)

Postby Cellcote on Tue May 13, 2008 5:46 pm

great job. Is there any chance this(along with your other mod) could be uploaded to the svn?
Image
Cellcote
Rackie
Rackie
 
Posts: 188
Joined: Thu Aug 09, 2007 11:07 am

Re: Fix your refines. (not quite as messy)

Postby PurpleYouko on Tue May 13, 2008 6:18 pm

It could but i have absolutely no idea how to use the SVN. I've never even played with uploading stuff to an SVN so i don't know where to start
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: 4598
Joined: Fri Aug 10, 2007 2:05 pm

Re: Fix your refines. (not quite as messy)

Postby Cellcote on Tue May 13, 2008 6:26 pm

I assume you already have svn username and password? If so, just checkout trough the https link, then make some changes and then commit :) (atleast that's the way it is going with codegoogle svn with turtoise)
Image
Cellcote
Rackie
Rackie
 
Posts: 188
Joined: Thu Aug 09, 2007 11:07 am

Re: Fix your refines. (not quite as messy)

Postby PurpleYouko on Tue May 13, 2008 7:09 pm

You assume wrong. i don't have any such thing yet.
I had probably better remedy that.
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: 4598
Joined: Fri Aug 10, 2007 2:05 pm

Re: Fix your refines. (not quite as messy)

Postby Rifke on Tue May 13, 2008 8:01 pm

If you add an event ID to the config_list, the config_list could be related to events, so that you have different things when there are different events. Like 'Refine event', that you have more chance that something refening drops?
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Re: Fix your refines. (not quite as messy)

Postby Cellcote on Tue May 13, 2008 8:13 pm

PurpleYouko wrote:You assume wrong. i don't have any such thing yet.
I had probably better remedy that.

I thought you were part of the team, and pepu said it sended all data to team members. :P
Image
Cellcote
Rackie
Rackie
 
Posts: 188
Joined: Thu Aug 09, 2007 11:07 am

Re: Fix your refines. (not quite as messy)

Postby PurpleYouko on Tue May 13, 2008 8:28 pm

maybe it is buried in my PMs list somewhere. I will have a look. It probably is.
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: 4598
Joined: Fri Aug 10, 2007 2:05 pm


Return to Submit Code

Who is online

Users browsing this forum: No registered users and 1 guest