Advertisement
Koviko

Battle INF script

Nov 9th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * From http:// pastebin.com/N8yf8QYb
  3.  * Battle INF item handler (v3.5)
  4.  */
  5.  
  6. /*global ScriptAPI, API, items*/
  7. (function (ScriptAPI, API, items) {
  8.   "use strict";
  9.  
  10.   var rarityToGrind = 1, // This rarity & lower is merged & sold
  11.     raritiesToSave = [2, 3, 4, 5, 6], // These rarities are merged with exactly matching items
  12.     rarityToSell = 1, // This rarity & lower is simply sold if it has no other use
  13.     defaultTimeout = 30, // Timeout for notifications
  14.     allowAging = 1, // 1 ages inventory, 2 ages equipped items, 3 ages both
  15.     showNotifications = [false, true, false, false]; // [ grind, merge, sell, keep ]
  16.  
  17.   function getInventory() { // Get inventory items
  18.     return ScriptAPI.$user.inventory.items;
  19.   }
  20.  
  21.   function getEquipment() { // Get equipped items
  22.     return ScriptAPI.$user.character.equipment;
  23.   }
  24.  
  25.   function notify(message, timeout) { // Create a notification
  26.     API.notifications.create(message, timeout || defaultTimeout);
  27.   }
  28.  
  29.   function sell(item) { // Sell an item
  30.     if (showNotifications[2]) {
  31.       notify("\u2604 " + item.name + " \u2606" + item.rarity + ".");
  32.     }
  33.  
  34.     ScriptAPI.$userService.sellItem(item); // Sell item
  35.  
  36.     return true;
  37.   }
  38.  
  39.   function keep(item) { // Keep an item
  40.     if (showNotifications[3]) {
  41.       notify("\u2764 " + item.name + " \u2606" + item.rarity + ".");
  42.     }
  43.  
  44.     return true;
  45.   }
  46.  
  47.   function craft(primary, secondary, option) { // Craft items
  48.     var tmp;
  49.  
  50.     if (primary.ts > secondary.ts) { // Ensures primary is older than secondary
  51.       tmp = primary;
  52.       primary = secondary;
  53.       secondary = tmp;
  54.     }
  55.  
  56.     if (primary.rarity < secondary.rarity) { // Ensures primary is rarer than secondary
  57.       tmp = primary;
  58.       primary = secondary;
  59.       secondary = tmp;
  60.     }
  61.  
  62.     // Notify
  63.     if (option === 1 && showNotifications[0]) {
  64.       notify("\u267A " + primary.name + " \u2606" + primary.rarity + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + ".");
  65.     }
  66.  
  67.     if (option === 2 && showNotifications[1]) {
  68.       notify("\u2726 " + primary.name + " \u2606" + primary.rarity + " +" + primary.plus + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + " +" + secondary.plus + ".");
  69.     }
  70.  
  71.     ScriptAPI.$craftingService.craftItems(primary, secondary); // Craft item
  72.     return primary;
  73.   }
  74.  
  75.   function grind(item) { // Grind item with another in inventory
  76.     var items = getInventory(),
  77.       i;
  78.  
  79.     for (i = 0; i < items.length; i++) {
  80.       if ((items[i] !== item) && (items[i].rarity <= rarityToGrind) && !items[i].lock) {
  81.         ScriptAPI.$userService.sellItem(craft(items[i], item, 1)); // Grind items & sell result
  82.         return true;
  83.       }
  84.     }
  85.   }
  86.  
  87.   function merge(item) { // Merge with a similar item in inventory or equipped
  88.     var items = getInventory().concat(getEquipment()),
  89.       i;
  90.  
  91.     for (i = 0; i < items.length; i++) {
  92.       if ((items[i] !== item) && (items[i].rarity === item.rarity) && (items[i].name === item.name) && (items[i].mod === item.mod) && (items[i].plus + item.plus < (5 * item.rarity + 5)) && !items[i].lock) {
  93.         craft(items[i], item, 2); // Merge items
  94.         return true;
  95.       }
  96.     }
  97.   }
  98.  
  99.   function aging(setting) {
  100.     var items,
  101.       i;
  102.  
  103.     if (setting === 1) { // Age items in inventory
  104.       items = getInventory();
  105.     } else if (setting === 2) { // Age equipped items
  106.       items = getEquipment();
  107.     } else if (setting === 3) { // Age all items
  108.       items = getEquipment().concat(getInventory());
  109.     }
  110.  
  111.     if (items) {
  112.       for (i = 0; i < items.length; i++) {
  113.         ScriptAPI.$craftingService.ageUpItem(items[i]);
  114.       }
  115.     }
  116.   }
  117.  
  118.   // Handle new item
  119.   items.forEach(function (item) {
  120.     var isDone = false;
  121.  
  122.     // Check if item meets requirements for grinding
  123.     if (item.rarity <= rarityToGrind) {
  124.       isDone = grind(item);
  125.     }
  126.  
  127.     // Checks if item meets requirements for merging
  128.     if (!isDone && raritiesToSave.indexOf(item.rarity) >= 0) {
  129.       isDone = merge(item);
  130.     }
  131.  
  132.     // Checks if item meets requirements for selling
  133.     if (!isDone && (item.rarity <= rarityToSell)) {
  134.       isDone = sell(item);
  135.     }
  136.  
  137.     // If no function has been run, item will be kept
  138.     if (!isDone) {
  139.       isDone = keep(item);
  140.     }
  141.   });
  142.  
  143.   // Triggers item aging function
  144.   if (allowAging > 0) {
  145.     aging(allowAging);
  146.   }
  147. }(ScriptAPI, API, items));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement