1. cmd_general.cpp :
  2. Add :
  3. ACMD (do_sort_items)
  4. {
  5. if (ch->IsDead() || ch->GetExchange() || ch->IsShop() || ch->IsOpenSafebox() || ch->IsCubeOpen())
  6. {
  7. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can't sort your inventory with those windows open."));
  8. return;
  9. }
  10. int lastSortInventoryPulse = ch->GetSortInventoryPulse();
  11. int currentPulse = thecore_pulse();
  12. if (lastSortInventoryPulse > currentPulse) {
  13. int deltaInSeconds = ((lastSortInventoryPulse / PASSES_PER_SEC(1)) - (currentPulse / PASSES_PER_SEC(1)));
  14. int minutes = deltaInSeconds / 60;
  15. int seconds = (deltaInSeconds - (minutes * 60));
  16. return;
  17. }
  18. for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
  19. {
  20. LPITEM item = ch->GetInventoryItem(i);
  21. if(!item)
  22. continue;
  23. if(item->isLocked())
  24. continue;
  25. if(item->GetCount() == 200)
  26. continue;
  27. if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
  28. {
  29. for (int j = i; j < INVENTORY_MAX_NUM; ++j)
  30. {
  31. LPITEM item2 = ch->GetInventoryItem(j);
  32. if(!item2)
  33. continue;
  34. if(item2->isLocked())
  35. continue;
  36. if (item2->GetVnum() == item->GetVnum())
  37. {
  38. bool bStopSockets = false;
  39. for (int k = 0; k < ITEM_SOCKET_MAX_NUM; ++k)
  40. {
  41. if (item2->GetSocket(k) != item->GetSocket(k))
  42. {
  43. bStopSockets = true;
  44. break;
  45. }
  46. }
  47. if(bStopSockets)
  48. continue;
  49. BYTE bAddCount = MIN(200 - item->GetCount(), item2->GetCount());
  50. item->SetCount(item->GetCount() + bAddCount);
  51. item2->SetCount(item2->GetCount() - bAddCount);
  52. continue;
  53. }
  54. }
  55. }
  56. }
  57. }
  58. _________________________________________
  59. ACMD (do_sort_special_storage)
  60. {
  61. if (ch->IsDead() || ch->GetExchange() || ch->IsShop() || ch->IsOpenSafebox() || ch->IsCubeOpen())
  62. {
  63. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can't sort your inventory with those windows open."));
  64. return;
  65. }
  66. int lastSortSpecialStoragePulse = ch->GetSortSpecialStoragePulse();
  67. int currentPulse = thecore_pulse();
  68. if (lastSortSpecialStoragePulse > currentPulse) {
  69. int deltaInSeconds = ((lastSortSpecialStoragePulse / PASSES_PER_SEC(1)) - (currentPulse / PASSES_PER_SEC(1)));
  70. int minutes = deltaInSeconds / 60;
  71. int seconds = (deltaInSeconds - (minutes * 60));
  72. // ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can sort your inventory again in %02d seconds.", seconds));
  73. return;
  74. }
  75. for (int m = 0; m < 3; m++)
  76. {
  77. for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i)
  78. {
  79. LPITEM item;
  80. switch(m)
  81. {
  82. case 0:
  83. item = ch->GetUpgradeInventoryItem(i);
  84. break;
  85. case 1:
  86. item = ch->GetBookInventoryItem(i);
  87. break;
  88. case 2:
  89. item = ch->GetStoneInventoryItem(i);
  90. break;
  91. default:
  92. item = ch->GetUpgradeInventoryItem(i);
  93. break;
  94. }
  95. if(!item)
  96. continue;
  97. if(item->isLocked())
  98. continue;
  99. if(item->GetCount() == g_bItemCountLimit)
  100. continue;
  101. if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
  102. {
  103. for (int j = i; j < SPECIAL_INVENTORY_MAX_NUM; ++j)
  104. {
  105. LPITEM item2;
  106. switch(m)
  107. {
  108. case 0:
  109. item2 = ch->GetUpgradeInventoryItem(j);
  110. break;
  111. case 1:
  112. item2 = ch->GetBookInventoryItem(j);
  113. break;
  114. case 2:
  115. item2 = ch->GetStoneInventoryItem(j);
  116. break;
  117. default:
  118. item2 = ch->GetUpgradeInventoryItem(j);
  119. break;
  120. }
  121. if(!item2)
  122. continue;
  123. if(item2->isLocked())
  124. continue;
  125. if (item2->GetVnum() == item->GetVnum())
  126. {
  127. bool bStopSockets = false;
  128. for (int k = 0; k < ITEM_SOCKET_MAX_NUM; ++k)
  129. {
  130. if (item2->GetSocket(k) != item->GetSocket(k))
  131. {
  132. bStopSockets = true;
  133. break;
  134. }
  135. }
  136. if(bStopSockets)
  137. continue;
  138. BYTE bAddCount = MIN(g_bItemCountLimit - item->GetCount(), item2->GetCount());
  139. item->SetCount(item->GetCount() + bAddCount);
  140. item2->SetCount(item2->GetCount() - bAddCount);
  141. continue;
  142. }
  143. }
  144. }
  145. }
  146. }
  147. ch->SetNextSortSpecialStoragePulse(thecore_pulse() + PASSES_PER_SEC(60));
  148. }
  149. cmd.cpp :
  150. Add :
  151. ACMD(do_sort_items);
  152. ACMD(do_sort_special_storage);
  153. And :
  154. { "click_sort_items", do_sort_items, 0, POS_DEAD, GM_PLAYER },
  155. { "click_sort_special_storage", do_sort_special_storage, 0, POS_DEAD, GM_PLAYER },