Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************************************************************************************************************************************************/
- // Battle INF item handler
- // Author: Thommas
- // version 3.4
- /**************************************************************************************************************************************************************************************************************/
- //User settings
- var die = 5; //Items of this rarity and lower will be crafted together mindlessly and then sold 0 to disable
- var beCareful = 6; //Items of this rarity will be crafted together with items of the same rarity and name/subclass 0 to disable
- var itsDangerousAlone = 0; //Items of this rarity will be crafted together with items of the same rarity and name/subclass 0 to disable
- var sellDezeNuts = 0; //Items of this rarity and lower will be sold if no other action is assigned to them 0 to disable
- var timeOut = 20; //Notification timeout. 5 is default
- 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
- //Settings be done
- /**************************************************************************************************************************************************************************************************************/
- //Functions start here
- //Grind item with item in inventory. Both must be of equal or lower rarity than defined by variable die
- var grind = function (item) {
- //Cycles through items in inventory
- for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) {
- //If current item matches requirements
- if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity <= die) && !ScriptAPI.$user.inventory.items[i].lock) {
- var option = 1; //Option for which notification to display
- //Then items will be grinded and notification
- ScriptAPI.$userService.sellItem(craft(ScriptAPI.$user.inventory.items[i], item, option));
- //Item has been processed
- return true;
- }
- }
- }
- //Merge item with item in inventory. Both must be of the same rarity and have the same name. E.g. Sword, or Armor
- var merge = function (item) {
- //Cycles through items in inventory
- for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) //Cycles through items in inventory
- {
- //If current item matches requirements
- 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) {
- var option = 2; //Option for which notification to display
- craft(ScriptAPI.$user.inventory.items[i], item, option); //
- //Item has been processed
- return true;
- }
- }
- }
- //Sells item
- var sell = function (item) {
- //Sells item and notification
- API.notifications.create("☄ " + item.name + " ☆" + item.rarity + ".", timeOut);
- ScriptAPI.$userService.sellItem(item);
- //Item has ben processed
- return true;
- }
- //Notifies that item will be kept
- var keep = function (item) {
- //Notification
- API.notifications.create("❤ " + item.name + " ☆" + item.rarity + ".", timeOut);
- //Item has been processed
- return true;
- }
- //Crafting itself and notifications for either merging or grinding
- var craft = function (primary, secondary, option) {
- //Ensures primary item is older than secondary
- if (primary.ts > secondary.ts) {
- var tmp = primary;
- primary = secondary;
- secondary = tmp;
- }
- //Ensures rarity of primary item is higher or equal to secondary item
- if (primary.rarity < secondary.rarity) {
- var tmp = primary;
- primary = secondary;
- secondary = tmp;
- }
- //Notifications based on var option
- if (option == 1) {
- API.notifications.create("♺ " + primary.name + " ☆" + primary.rarity + " ← " + secondary.name + " ☆" + secondary.rarity + ".", timeOut);
- }
- if (option == 2) {
- API.notifications.create("✦ " + primary.name + " ☆" + primary.rarity + " +" + primary.plus + " ← " + secondary.name + " ☆" + secondary.rarity + " +" + secondary.plus + ".", timeOut);
- }
- //Crafting itself
- ScriptAPI.$craftingService.craftItems(primary, secondary);
- return primary;
- }
- //Function which ages items
- var ageing = function (setting) {
- //Determining what to do
- //If setting 1 or 3, age ALL items in inventory
- if (setting == 1 || setting == 3) {
- //Cycle through items in inventory
- for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) {
- //Ageing up item
- ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.inventory.items[i]);
- }
- }
- //If setting 2 or 3, age items currently equipped
- if (setting == 2 || setting == 3) {
- //Cycle through items currently equipped
- for (var i = 0; i < ScriptAPI.$user.character.equipment.length; i++) {
- //Ageing up item
- ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.character.equipment[i]);
- }
- }
- }
- //No more functions
- //Function triggers start here
- //New item trigger. Loops equal amount of items received, as such script can handle any amount of new items
- for (var i = 0; i < items.length; i++) {
- //var newItemDone equals true when new item has been processed. No other new item related function will be run then
- var newItemDone = false;
- //Check if item meets requirements for grinding
- if (items[i].rarity <= die) {
- newItemDone = grind(items[i]);
- }
- //Checks if item meets requirements for merging
- if (!newItemDone && ((items[i].rarity == beCareful) || (items[i].rarity == itsDangerousAlone))) {
- newItemDone = merge(items[i]);
- }
- //Checks if item meets requirements for selling
- if (!newItemDone && (items[i].rarity <= sellDezeNuts)) {
- newItemDone = sell(items[i]);
- }
- //If no function has been run, item will be kept
- if (!newItemDone) {
- newItemDone = keep(items[i]);
- }
- }
- //Triggers item ageing function
- if (getOld > 0) {
- ageing(getOld);
- }
- //No more function triggers
- /*
- *****************************************************************Changelog*****************************************************************
- Version 3.5
- Fixed craft function selling items that should not be sold
- Fixed craft function crafting older items into newer
- Version 3.4
- Added craft function. Crafting is now done by one single function. grind and merge now merely tell craft which items to merge/grind
- Added usage of timestamp. Is still not needed if handling new items
- Cleaned up code a teeny bit
- Modified notifications
- Version 3.3
- Fixed attempt to merge/grind locked items
- Version 3.2
- Added automagic item ageing
- Adjusted comments
- Note: Automagic ageing appears to be quite resource intensive. I myself experience a small stutter whenever it cycles through 80+ items.
- Version 3.1:
- Added changelog
- Added notification timeout variable
- *****************************************************************Changelog*****************************************************************
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement