Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * From http:// pastebin.com/N8yf8QYb
- * Battle INF item handler (v3.5)
- */
- /*global ScriptAPI, API, items*/
- (function (ScriptAPI, API, items) {
- "use strict";
- var rarityToGrind = 1, // This rarity & lower is merged & sold
- raritiesToSave = [2, 3, 4, 5, 6], // These rarities are merged with exactly matching items
- rarityToSell = 1, // This rarity & lower is simply sold if it has no other use
- defaultTimeout = 30, // Timeout for notifications
- allowAging = 1, // 1 ages inventory, 2 ages equipped items, 3 ages both
- showNotifications = [false, true, false, false]; // [ grind, merge, sell, keep ]
- function getInventory() { // Get inventory items
- return ScriptAPI.$user.inventory.items;
- }
- function getEquipment() { // Get equipped items
- return ScriptAPI.$user.character.equipment;
- }
- function notify(message, timeout) { // Create a notification
- API.notifications.create(message, timeout || defaultTimeout);
- }
- function sell(item) { // Sell an item
- if (showNotifications[2]) {
- notify("\u2604 " + item.name + " \u2606" + item.rarity + ".");
- }
- ScriptAPI.$userService.sellItem(item); // Sell item
- return true;
- }
- function keep(item) { // Keep an item
- if (showNotifications[3]) {
- notify("\u2764 " + item.name + " \u2606" + item.rarity + ".");
- }
- return true;
- }
- function craft(primary, secondary, option) { // Craft items
- var tmp;
- if (primary.ts > secondary.ts) { // Ensures primary is older than secondary
- tmp = primary;
- primary = secondary;
- secondary = tmp;
- }
- if (primary.rarity < secondary.rarity) { // Ensures primary is rarer than secondary
- tmp = primary;
- primary = secondary;
- secondary = tmp;
- }
- // Notify
- if (option === 1 && showNotifications[0]) {
- notify("\u267A " + primary.name + " \u2606" + primary.rarity + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + ".");
- }
- if (option === 2 && showNotifications[1]) {
- notify("\u2726 " + primary.name + " \u2606" + primary.rarity + " +" + primary.plus + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + " +" + secondary.plus + ".");
- }
- ScriptAPI.$craftingService.craftItems(primary, secondary); // Craft item
- return primary;
- }
- function grind(item) { // Grind item with another in inventory
- var items = getInventory(),
- i;
- for (i = 0; i < items.length; i++) {
- if ((items[i] !== item) && (items[i].rarity <= rarityToGrind) && !items[i].lock) {
- ScriptAPI.$userService.sellItem(craft(items[i], item, 1)); // Grind items & sell result
- return true;
- }
- }
- }
- function merge(item) { // Merge with a similar item in inventory or equipped
- var items = getInventory().concat(getEquipment()),
- i;
- for (i = 0; i < items.length; i++) {
- 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) {
- craft(items[i], item, 2); // Merge items
- return true;
- }
- }
- }
- function aging(setting) {
- var items,
- i;
- if (setting === 1) { // Age items in inventory
- items = getInventory();
- } else if (setting === 2) { // Age equipped items
- items = getEquipment();
- } else if (setting === 3) { // Age all items
- items = getEquipment().concat(getInventory());
- }
- if (items) {
- for (i = 0; i < items.length; i++) {
- ScriptAPI.$craftingService.ageUpItem(items[i]);
- }
- }
- }
- // Handle new item
- items.forEach(function (item) {
- var isDone = false;
- // Check if item meets requirements for grinding
- if (item.rarity <= rarityToGrind) {
- isDone = grind(item);
- }
- // Checks if item meets requirements for merging
- if (!isDone && raritiesToSave.indexOf(item.rarity) >= 0) {
- isDone = merge(item);
- }
- // Checks if item meets requirements for selling
- if (!isDone && (item.rarity <= rarityToSell)) {
- isDone = sell(item);
- }
- // If no function has been run, item will be kept
- if (!isDone) {
- isDone = keep(item);
- }
- });
- // Triggers item aging function
- if (allowAging > 0) {
- aging(allowAging);
- }
- }(ScriptAPI, API, items));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement