[Fix] Storing items now costs money

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

[Fix] Storing items now costs money

Postby FransK on Mon May 20, 2013 11:01 am

Hi,

Here's some code to fix the issue where storing items does not cost any zuly.

This code is written for Osirose, but i guess it will work in any version.
This code is included in osiRose [REV 87]

Component: World Server
File: worldpackets.cpp
Line: Around 2777

Action : Replace function pakChangeStorage with code below:

  1. bool CWorldServer::pakChangeStorage( CPlayer* thisclient, CPacket* P)
  2. {
  3.     // Change Storage (Deposit/Withdraw items)
  4.     // Modified by FransK ; storing items now cost money.
  5.     // Thanks to [?] for already providing the function GetStorageFee and [?] for the basic function in the first place.
  6.     // May 2013.
  7.  
  8.     /* Packet for this function
  9.        ===========================
  10.        [BYTE] Action
  11.        [BYTE] Item Slot
  12.        [WORD] Item Head
  13.        [DWORD] Item Body
  14.        [BYTE] Unk (0x00)
  15.     */
  16.  
  17.     UINT bprice=0;             // Item Price      (from STB)
  18.     UINT bpricerate=0;         // Item Price Rate (from STB)
  19.     UINT bfee=0;               // Storage Fee     (Calculated)
  20.     BYTE action = GETBYTE((*P),0);
  21.  
  22.     switch (action)
  23.     {
  24.     case 0x00: //Deposit
  25.     {
  26.         int itemslot = (int)GETBYTE((*P),1);
  27.         CItem clientitem = GetItemByHeadAndData( GETWORD((*P), 2), GETDWORD((*P), 4) );
  28.  
  29.         if (!CheckInventorySlot( thisclient, itemslot ))
  30.             return false;
  31.  
  32.         CItem newitem = thisclient->items[itemslot];
  33.         // Set the newitem's count to the count from the client for slot search
  34.         newitem.count = clientitem.count;
  35.  
  36.         // find an empty or matching slot depending on new item type
  37.         int newslot = thisclient->GetNewStorageItemSlot ( newitem );
  38.         if (newslot==0xffff)
  39.             return true;
  40.  
  41.         int count = clientitem.count;
  42.         // Stops players from storing more items than they actually have.
  43.         if (count > thisclient->items[itemslot].count)
  44.             count = thisclient->items[itemslot].count;
  45.  
  46.         // Set the desired amount
  47.         newitem.count = count;
  48.  
  49.         Log(MSG_INFO, "Request storage by %s, type=%i id=%i, amount=%i",thisclient->CharInfo->charname, newitem.itemtype, newitem.itemnum, newitem.count);
  50.  
  51.         // Retreive Price information for the item from the STB. Different item types are stored in different tables.
  52.         if(newitem.itemtype<10)
  53.             {
  54.             bprice = EquipList[newitem.itemtype].Index[newitem.itemnum]->price;
  55.             bpricerate = EquipList[newitem.itemtype].Index[newitem.itemnum]->pricerate;
  56.             }
  57.         else
  58.             {
  59.             switch(newitem.itemtype){
  60.                 case CONSUMIBLE:
  61.                     bprice = GServer->UseList.Index[newitem.itemnum]->price;
  62.                     bpricerate = GServer->UseList.Index[newitem.itemnum]->pricerate;
  63.                     break;
  64.                 case JEM:
  65.                     bprice = JemList.Index[newitem.itemnum]->price;
  66.                     bpricerate = JemList.Index[newitem.itemnum]->pricerate;
  67.                     break;
  68.                 case NATURAL:
  69.                     bprice = NaturalList.Index[newitem.itemnum]->price;
  70.                     bpricerate = NaturalList.Index[newitem.itemnum]->pricerate;
  71.                     break;
  72.                 case PAT:
  73.                     bprice = PatList.Index[newitem.itemnum]->price;
  74.                     bpricerate = PatList.Index[newitem.itemnum]->pricerate;
  75.                     break;
  76.                 }
  77.             }
  78.  
  79.         // Ok, we got all STB item info, now calculate the storage fee.
  80.         bfee = GetStorageFee(bprice,bpricerate, clientitem.count);
  81.  
  82.         // Check if client has enough zulies to complete the transaction.
  83.         if (thisclient->CharInfo->Zulies >=bfee){
  84.  
  85.             if (newitem.itemtype >= 10 && newitem.itemtype <= 12) {
  86.                 //is it a stackable type, so must do some math with item counts etc.
  87.                 UINT bfee = GetStorageFee(bprice,bpricerate, clientitem.count);
  88.  
  89.                 //add the new items to the storage slot
  90.                 if (thisclient->storageitems[newslot].count > 0)
  91.                     thisclient->storageitems[newslot].count += newitem.count;
  92.                 else
  93.                     thisclient->storageitems[newslot] = newitem;
  94.  
  95.                 //delete the items from inventory slot
  96.                 thisclient->items[itemslot].count -= count;
  97.  
  98.                 //Remove item + amount from client inventory slot
  99.                 if (thisclient->items[itemslot].count <= 0)
  100.                     ClearItem(thisclient->items[itemslot]);
  101.             } else {
  102.                 // This item is not stackable, so remove it from client inventory slot and add to storage slot.
  103.                 ClearItem(thisclient->items[itemslot]);
  104.                 thisclient->storageitems[newslot] = newitem;
  105.             }
  106.  
  107.             // Take the money.
  108.             thisclient->CharInfo->Zulies -=bfee;
  109.  
  110.         } else {
  111.             // Not Enough Zulie; too bad. Client already pops up a messagbox so we don't have to.
  112.         }
  113.  
  114.         BEGINPACKET( pak, 0x7ae );
  115.         ADDWORD    ( pak, itemslot );
  116.         ADDWORD    ( pak, newslot );
  117.         ADDWORD    ( pak, BuildItemHead( thisclient->items[itemslot] ) );
  118.         ADDDWORD   ( pak, BuildItemData( thisclient->items[itemslot] ) );
  119.         ADDWORD    ( pak, BuildItemHead( thisclient->storageitems[newslot] ) );
  120.         ADDDWORD   ( pak, BuildItemData( thisclient->storageitems[newslot] ) );
  121.         ADDQWORD   ( pak, thisclient->CharInfo->Zulies );
  122.         ADDBYTE    ( pak, 0x00 );
  123.         thisclient->client->SendPacket( &pak );
  124.     }
  125.     break;//thanks to anon for post that this break was missing
  126.  
  127.     case 0x01: //Withdraw
  128.     {
  129.         BYTE storageslot = GETBYTE((*P),1);
  130.         CItem clientitem = GetItemByHeadAndData( GETWORD((*P), 2), GETDWORD((*P), 4) );
  131.  
  132.         if (storageslot>=160)
  133.         {
  134.             Log( MSG_HACK, "Invalid storage slot %i from %s", storageslot, thisclient->Session->username );
  135.             return false;
  136.         }
  137.         CItem newitem = thisclient->storageitems[storageslot];
  138.         newitem.count = clientitem.count;
  139.  
  140.         int newslot= thisclient->GetNewItemSlot ( newitem );
  141.         if (newslot == 0xffff)
  142.             return true;
  143.  
  144.  
  145.         if (newitem.itemtype>9 && newitem.itemtype<14)
  146.         {
  147.             // This is a useitem.
  148.             WORD count = clientitem.count;
  149.             if ( count > thisclient->storageitems[storageslot].count )
  150.                 count = thisclient->storageitems[storageslot].count;
  151.             newitem.count = count;
  152.  
  153.             if (thisclient->items[newslot].count > 0)
  154.                 thisclient->items[newslot].count += newitem.count;
  155.             else
  156.                 thisclient->items[newslot] = newitem;
  157.  
  158.             thisclient->storageitems[storageslot].count -= count;
  159.             if (thisclient->storageitems[storageslot].count<=0)
  160.                 ClearItem(thisclient->storageitems[storageslot]);
  161.         }
  162.         else
  163.         //type 1 to 8; Clothing and other stuff that is not stackable etc.
  164.         {
  165.             ClearItem(thisclient->storageitems[storageslot]);
  166.             thisclient->items[newslot] = newitem;
  167.         }
  168.  
  169.         BEGINPACKET( pak, 0x7ae );
  170.         ADDWORD    ( pak, newslot );
  171.         ADDWORD    ( pak, storageslot );
  172.         ADDWORD   ( pak, BuildItemHead( thisclient->items[newslot] ) );
  173.         ADDDWORD   ( pak, BuildItemData( thisclient->items[newslot] ) );
  174.         ADDWORD   ( pak, BuildItemHead( thisclient->storageitems[storageslot] ) );
  175.         ADDDWORD   ( pak, BuildItemData( thisclient->storageitems[storageslot] ) );
  176.         ADDQWORD   ( pak, thisclient->CharInfo->Zulies );
  177.         ADDBYTE    ( pak, 0x00 );
  178.         thisclient->client->SendPacket( &pak );
  179.     }
  180.     break;
  181.     default:
  182.         Log( MSG_INFO, "Storage unknown action: %i ", action);
  183.     }
  184.     return true;
  185. }
life's too short to complain.
User avatar
FransK
osiRose dev
osiRose dev
 
Posts: 24
Joined: Tue Apr 30, 2013 8:45 pm
Location: The Netherlands

Return to Submit Code

Who is online

Users browsing this forum: No registered users and 0 guests

cron