Advertisement
thommas

Battle INF Item Handler 3.4

Oct 21st, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**************************************************************************************************************************************************************************************************************/
  2. //      Battle INF item handler
  3. //      Author: Thommas
  4. //      version 3.4
  5. /**************************************************************************************************************************************************************************************************************/
  6. //User settings
  7. var die                 = 0;        //Items of this rarity and lower will be crafted together mindlessly and then sold                  0 to disable
  8. var beCareful           = 0;        //Items of this rarity will be crafted together with items of the same rarity and name/subclass     0 to disable
  9. var itsDangerousAlone   = 0;        //Items of this rarity will be crafted together with items of the same rarity and name/subclass     0 to disable
  10. var sellDezeNuts        = 0;        //Items of this rarity and lower will be sold if no other action is assigned to them                0 to disable
  11. var timeOut             = 5;        //Notification timeout. 5 is default
  12. var getOld              = 0;        //If 3, will attempt to age ALL items, inventory AND equipment. If 2, will attempt to age items equipped. If 1 will attempt to age ALL items in inventory. 0 to disable
  13. //Settings be done
  14. /**************************************************************************************************************************************************************************************************************/
  15.  
  16. //Functions start here
  17. //Grind item with item in inventory. Both must be of equal or lower rarity than defined by variable die
  18. var grind = function (item) {
  19.     //Cycles through items in inventory
  20.     for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) {
  21.         //If current item matches requirements
  22.         if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity <= die) && !ScriptAPI.$user.inventory.items[i].lock) {
  23.             var option = 1; //Option for which notification to display
  24.             //Then items will be grinded and notification
  25.             craft(ScriptAPI.$user.inventory.items[i], item, option);
  26.             //Item has been processed
  27.             return true;
  28.         }
  29.     }
  30. }
  31.  
  32. //Merge item with item in inventory. Both must be of the same rarity and have the same name. E.g. Sword, or Armor
  33. var merge = function (item) {
  34.     //Cycles through items in inventory
  35.     for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) //Cycles through items in inventory
  36.     {
  37.         //If current item matches requirements
  38.         if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity == item.rarity) && (ScriptAPI.$user.inventory.items[i].name == item.name) && (ScriptAPI.$user.inventory.items[i].plus + item.plus < (5 * item.rarity + 5)) && !ScriptAPI.$user.inventory.items[i].lock) {
  39.             var option = 2; //Option for which notification to display
  40.             craft(ScriptAPI.$user.inventory.items[i], item, option); //
  41.             //Item has been processed
  42.             return true;
  43.         }
  44.     }
  45. }
  46.  
  47. //Sells item
  48. var sell = function (item) {
  49.     //Sells item and notification
  50.     API.notifications.create("☄ " + item.name + " ☆" + item.rarity + ".", timeOut);
  51.     ScriptAPI.$userService.sellItem(item);
  52.     //Item has ben processed
  53.     return true;
  54. }
  55.  
  56. //Notifies that item will be kept
  57. var keep = function (item) {
  58.     //Notification
  59.     API.notifications.create("❤ " + item.name + " ☆" + item.rarity + ".", timeOut);
  60.     //Item has been processed
  61.     return true;
  62. }
  63.  
  64. //Crafting itself and notifications for either merging or grinding
  65. var craft = function (primary, secondary, option) {
  66.     //Ensures primary item is older than secondary
  67.     if (primary.ts < secondary.ts) {
  68.         var tmp = primary;
  69.         primary = secondary;
  70.         secondary = tmp;
  71.     }
  72.     //Ensures rarity of primary item is higher or equal to secondary item
  73.     if (primary.rarity < secondary.rarity) {
  74.         var tmp = primary;
  75.         primary = secondary;
  76.         secondary = tmp;
  77.     }
  78.     //Notifications based on var option
  79.     if (option == 1) {
  80.         API.notifications.create("♺ " + primary.name + " ☆" + primary.rarity + " ← " + secondary.name + " ☆" + secondary.rarity + ".", timeOut);
  81.     }
  82.     if (option == 2) {
  83.         API.notifications.create("✦ " + primary.name + " ☆" + primary.rarity + " +" + primary.plus + " ← " + secondary.name + " ☆" + secondary.rarity + " +" + secondary.plus + ".", timeOut);
  84.     }
  85.     //Crafting itself
  86.     ScriptAPI.$craftingService.craftItems(primary, secondary);
  87.     ScriptAPI.$userService.sellItem(primary);
  88. }
  89.  
  90. //Function which ages items
  91. var ageing = function (setting) {
  92.     //Determining what to do
  93.     //If setting 1 or 3, age ALL items in inventory
  94.     if (setting == 1 || setting == 3) {
  95.         //Cycle through items in inventory
  96.         for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) {
  97.             //Ageing up item
  98.             ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.inventory.items[i]);
  99.         }
  100.     }
  101.     //If setting 2 or 3, age items currently equipped
  102.     if (setting == 2 || setting == 3) {
  103.         //Cycle through items currently equipped
  104.         for (var i = 0; i < ScriptAPI.$user.character.equipment.length; i++) {
  105.             //Ageing up item
  106.             ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.character.equipment[i]);
  107.         }
  108.     }
  109. }
  110. //No more functions
  111.  
  112. //Function triggers start here
  113. //New item trigger. Loops equal amount of items received, as such script can handle any amount of new items
  114. for (var i = 0; i < items.length; i++) {
  115.     //var newItemDone equals true when new item has been processed. No other new item related function will be run then
  116.     var newItemDone = false;
  117.     //Check if item meets requirements for grinding
  118.     if (items[i].rarity <= die) {
  119.         newItemDone = grind(items[i]);
  120.     }
  121.     //Checks if item meets requirements for merging
  122.     if (!newItemDone && ((items[i].rarity == beCareful) || (items[i].rarity == itsDangerousAlone))) {
  123.         newItemDone = merge(items[i]);
  124.     }
  125.     //Checks if item meets requirements for selling
  126.     if (!newItemDone && (items[i].rarity <= sellDezeNuts)) {
  127.         newItemDone = sell(items[i]);
  128.     }
  129.     //If no function has been run, item will be kept
  130.     if (!newItemDone) {
  131.         newItemDone = keep(items[i]);
  132.     }
  133. }
  134. //Triggers item ageing function
  135. if (getOld > 0) {
  136.     ageing(getOld);
  137. }
  138. //No more function triggers
  139.  
  140.  
  141.  
  142. /*
  143. *****************************************************************Changelog*****************************************************************
  144.  
  145. Version 3.4
  146. Added craft function. Crafting is now done by one single function. grind and merge now merely tell craft which items to merge/grind
  147. Added usage of timestamp. Is still not needed if handling new items
  148. Cleaned up code a teeny bit
  149. Modified notifications
  150.  
  151. Version 3.3
  152. Fixed attempt to merge/grind locked items
  153.  
  154. Version 3.2
  155. Added automagic item ageing
  156. Adjusted comments
  157. Note: Automagic ageing appears to be quite resource intensive. I myself experience a small stutter whenever it cycles through 80+ items.
  158.  
  159. Version 3.1:
  160. Added changelog
  161. Added notification timeout variable
  162.  
  163. *****************************************************************Changelog*****************************************************************
  164. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement