TShelby

Kadou

Oct 28th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1. ACMD (do_sort_special_storage)
  2. {
  3.     char arg1[256];
  4.     one_argument(argument, arg1, sizeof(arg1));
  5.  
  6.     BYTE inventoryNumber = 0;
  7.     str_to_number(inventoryNumber, arg1);
  8.    
  9.     if(inventoryNumber < 0 || inventoryNumber > 3)
  10.         return;
  11.    
  12.     if (ch->IsDead() || ch->GetExchange() || ch->GetViewingShopOwner() || ch->IsShop() || ch->IsOpenSafebox() || ch->IsCubeOpen())
  13.     {
  14.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can't sort your inventory with those windows open."));
  15.         return;
  16.     }
  17.    
  18.     int lastSortSpecialStoragePulse = ch->GetSortSpecialStoragePulse(inventoryNumber);
  19.     int currentPulse = thecore_pulse();
  20.    
  21.     if (lastSortSpecialStoragePulse > currentPulse) {
  22.         int deltaInSeconds = ((lastSortSpecialStoragePulse / PASSES_PER_SEC(1)) - (currentPulse / PASSES_PER_SEC(1)));
  23.         int minutes = deltaInSeconds / 60;
  24.         int seconds = (deltaInSeconds - (minutes * 60));
  25.  
  26.         if(minutes > 0)
  27.             ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can sort your inventory again in %02d minutes and %02d seconds."), minutes, seconds);
  28.         else
  29.             ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can sort your inventory again in %02d seconds."), seconds);
  30.        
  31.         return;
  32.     }
  33.    
  34.     for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i)
  35.     {
  36.         LPITEM item;
  37.        
  38.         switch(inventoryNumber)
  39.         {
  40.             case 0:
  41.                 item = ch->GetUpgradeInventoryItem(i);
  42.                 break;
  43.             case 1:
  44.                 item = ch->GetBookInventoryItem(i);
  45.                 break;
  46.             case 2:
  47.                 item = ch->GetStoneInventoryItem(i);
  48.                 break;
  49.             case 3:
  50.                 item = ch->GetChestInventoryItem(i);
  51.                 break;
  52.             default:
  53.                 item = ch->GetUpgradeInventoryItem(i);
  54.                 break;
  55.         }
  56.        
  57.         if(!item)
  58.             continue;
  59.        
  60.         if(item->isLocked())
  61.             continue;
  62.        
  63.         if(item->GetCount() == g_bItemCountLimit)
  64.             continue;
  65.        
  66.         if ((item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK)))
  67.         {
  68.             for (int j = i + 1; j < SPECIAL_INVENTORY_MAX_NUM; ++j)
  69.             {
  70.                 LPITEM item2;
  71.                
  72.                 switch(inventoryNumber)
  73.                 {
  74.                     case 0:
  75.                         item2 = ch->GetUpgradeInventoryItem(j);
  76.                         break;
  77.                     case 1:
  78.                         item2 = ch->GetBookInventoryItem(j);
  79.                         break;
  80.                     case 2:
  81.                         item2 = ch->GetStoneInventoryItem(j);
  82.                         break;
  83.                     case 3:
  84.                         item2 = ch->GetChestInventoryItem(j);
  85.                         break;
  86.                     default:
  87.                         item2 = ch->GetUpgradeInventoryItem(j);
  88.                         break;
  89.                 }
  90.        
  91.                 if(!item2)
  92.                     continue;
  93.                
  94.                 if(item2->isLocked())
  95.                     continue;
  96.                
  97.                 if(item->GetID() == item2->GetID()) // sanity check
  98.                     continue;
  99.    
  100.                 if (item2->GetVnum() == item->GetVnum())
  101.                 {
  102.                     {
  103.                         bool bStopSockets = false;
  104.                        
  105.                         for (int k = 0; k < ITEM_SOCKET_MAX_NUM; ++k)
  106.                         {
  107.                             if (item2->GetSocket(k) != item->GetSocket(k))
  108.                             {
  109.                                 bStopSockets = true;
  110.                                 break;
  111.                             }
  112.                         }
  113.                        
  114.                         if(bStopSockets)
  115.                             continue;
  116.        
  117.                         BYTE bAddCount = MIN(g_bItemCountLimit - item->GetCount(), item2->GetCount());
  118.        
  119.                         item->SetCount(item->GetCount() + bAddCount);
  120.                         item2->SetCount(item2->GetCount() - bAddCount);
  121.                     }
  122.                    
  123.                     continue;
  124.                 }
  125.             }
  126.         }
  127.     }
  128.  
  129.     ch->SetNextSortSpecialStoragePulse(inventoryNumber, thecore_pulse() + PASSES_PER_SEC(69));
  130. }
Advertisement
Add Comment
Please, Sign In to add comment