Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*************************************************************************************************************************************************************************************************************************************************************************/
- // Battle INF item handler
- // Author: Thommas
- // Version: 3.6
- /*************************************************************************************************************************************************************************************************************************************************************************/
- // User settings
- var beCareful = [0, 0, 0, 0, 0, 0]; //Items of these rarities will be crafted together with items of their own rarity and name/subclass (merging has priority over grinding) 0 to disable
- var die = 0; //Items of this rarity and lower will be crafted together mindlessly and then sold (merging has priority over grinding) 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 = 5; //Script-scale notification timeout 5 is default
- var notifyMe = false; //Script-scale notification switch. False to prevent ALL notifications, true to allow notifications
- var callMe = [
- /*Grind */ false, //Disables/enables notifications False to disable, true to enable
- /*Merge */ false, //Disables/enables notifications False to disable, true to enable
- /*Sell */ false, //Disables/enables notifications False to disable, true to enable
- /*Keep */ false, //Disables/enables notifications False to disable, true to enable
- /*exp/min */ false, //Disables/enables notifications False to disable, true to enable
- /*exp% */ false, //Disables/enables notifications False to disable, true to enable
- /*timeUntilLvlUp*/ false //Disables/enables notifications False to disable, true to enable
- ];
- var getOld = [
- /*Equipment */ false, //Disables/enables aging of equipment False to disable, true to enable
- /*Inventory */ false //Disables/enables aging of items in inventory False to disable, true to enable
- ];
- var useOverride = false; //Disables/enables use of override False to disable, true to enable
- var overrideItems = [
- /*Helmet */ 0, //Helmets of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Armor */ 0, //Armor of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Gloves */ 0, //Gloves of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Leggings */ 0, //Leggings of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Boots */ 0, //Boots of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Sword */ 0, //Swords of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*2-handed Sword*/ 0, //2-handed Swords of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Bow */ 0, //Bows of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Crossbow */ 0, //Crossbows of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Wand */ 0, //Wands of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Staff */ 0, //Staffs of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- /*Shield */ 0 //Shields of defined rarity will be kept and locked regardless of non-override settings 0 to disable
- ];
- var expCalc = false; //Disables/enables calculation of exp stuff False to disable, true to enable
- var expReset = false; //Resets old exp and time False to disable, true to enable
- // 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
- function findGrindComponent(item, grindRarity) {
- for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) { //Cycles through items in inventory
- if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity <= grindRarity) && !ScriptAPI.$user.inventory.items[i].lock) { //Criteria
- ScriptAPI.$userService.sellItem(craft(ScriptAPI.$user.inventory.items[i], item, 1)); //Crafting component 1 & 2, and notification setting
- 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
- function findMergeCompenent(item) {
- for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) { //Cycles through items in inventory
- 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) { //Criteria
- craft(ScriptAPI.$user.inventory.items[i], item, 2); //Crafting component 1 & 2, and notification setting
- return true;
- }
- }
- }
- //Notifications, yeah
- function notify(message) {
- if (notifyMe) {
- API.notifications.create(message, timeOut); } }
- //Sells item
- function sell(item) {
- if (callMe[2]) { //Criteria
- notify("\u2604 " + item.name + " \u2606" + item.rarity + "."); }
- API.$userService.sellItem(item);
- return true;
- }
- //Notifies that item will be kept
- function keep(item) {
- if (callMe[3]) { //Criteria
- notify("\u2764 " + item.name + " \u2606" + item.rarity + "."); }
- return true;
- }
- //Crafting itself and notifications for either merging or grinding
- function craft(primary, secondary, notificationSetting) {
- if (primary.ts > secondary.ts) { //Ensures primary item is older than secondary
- var tmp = primary;
- primary = secondary;
- secondary = tmp;
- }
- if (primary.rarity < secondary.rarity) { //Ensures rarity of primary item is higher or equal to secondary item. Rarity has priority over age
- var tmp = primary;
- primary = secondary;
- secondary = tmp;
- }
- //Notifications
- if (callMe[0] && (notificationSetting == 1)) { //Criteria
- notify("\u267A " + primary.name + " \u2606" + primary.rarity + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + "."); }
- if (callMe[1] && (notificationSetting == 2)) { //Criteria
- notify("\u2726 " + primary.name + " \u2606" + primary.rarity + " +" + primary.plus + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + " +" + secondary.plus + "."); }
- ScriptAPI.$craftingService.craftItems(primary, secondary); //Crafting itself
- return primary; //Returns primary item
- }
- //Function which ages items
- function ageing(setting) {
- if (setting[0]) { //Criteria
- for (var i = 0; i < ScriptAPI.$user.character.equipment.length; i++) { //Cycle through items currently equipped
- ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.character.equipment[i]); } } //Ageing up item
- if (setting[1]) { //Criteria
- for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) { //Cycles through items in inventory
- ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.inventory.items[i]); } } //Ageing up item
- }
- //EXP. Stuff
- function expPerMinCalc(reset) {
- if (reset || (sessionStorage.oldEXP == null)) { //Criteria
- sessionStorage.oldEXP = ScriptAPI.$user.character.levelEXP; //Remember/getting current/old exp
- var d = new Date; //Getting old time
- sessionStorage.oldTime = d.getTime(); //Remember old time
- }
- var d = new Date(); //Getting new time
- var timeDifference = (((d.getTime() - sessionStorage.oldTime) / 1000) / 60); //Meth (dividing to reach minutes)
- var expDifference = (ScriptAPI.$user.character.levelEXP - sessionStorage.oldEXP); //Meth
- var expPN = (expDifference / timeDifference); //Meth
- return expPN;
- }
- //Override stuff
- function overrideOhYes(item, overrideRarity) {
- var itemTypesAndSubTypes = ["head", "body", "hands", "legs", "feet", "SWORD", "TWO_HANDED_SWORD", "BOW", "CROSSBOW", "WAND", "STAFF", "SHIELD"];
- for (var i = 0; i < itemTypesAndSubTypes.length; i++) {
- if ((itemTypesAndSubTypes[i] == item.type || itemTypesAndSubTypes[i] == item.subType) && overrideRarity[i] == item.rarity) { //Criteria
- ScriptAPI._modules.inventory.lock(item); //Locks item
- return keep(item); //Notification, keep returns true
- }
- }
- }
- //The one who renders judgement
- function judge(item, mergeRarity, grindRarity, sellRarity) {
- for (var i = 0; i < mergeRarity.length; i++) { //Cycle through rarites defined be beCareful
- if (item.rarity == mergeRarity[i]) { //Criteria
- return findMergeCompenent(item); } } //Calls merge function
- if (item.rarity <= grindRarity) { //Criteria
- return findGrindComponent(item, grindRarity); } //Calls grind function
- if (item.rarity <= sellRarity) { //Criteria
- return sell(item); } //Calls sell function
- return keep(item); //If nothing of the above was applied
- }
- //EXP.All about the cents
- function expPerCent() {
- var x = 2000 * Math.pow(2.7225, ScriptAPI.$user.character.level / 10); //Exp needed for lvl up: (2.7225^(CharLevel/10))*2000
- var y = ScriptAPI.$user.character.levelEXP; //Current exp
- var z = (y * 100) / x; //(CurrentExp*100)/expNeeded=exp percentage towards completion
- return z;
- //API.notifications.create("Level: " + z.toFixed(4).toString() + "%"); //z.toFixed(i) i defines amount of decimals
- }
- //EXP. Time until level up
- function timeUntilLvlUp(expPerMin) {
- var i = ((2000 * (Math.pow(2.7225, (ScriptAPI.$user.character.level / 10)))) - ScriptAPI.$user.character.levelEXP) / expPerMin; //(totalExpNeeded- currentExp) / expPerMin = totalMinutesUntilLvlUp
- var j = Math.floor(i / 1440); //totalMinutesUntilLvlUp / 1440 = daysUntilLvlUp
- var k = Math.floor((i % 1440) / 60); //(totalMinutesUntilLvlUp modulus 1440) / 60 = hoursUntilLvlUp - daysUntilLvlUp
- var l = Math.floor((i % 1440) % 60); //(totalMinutesUntilLvlUp modulus 1440) modulus 60 = minutesUntilLvlUp - (daysUntilLvlUp + hoursUntilLvlUp)
- var s = j + " days " + k + " hours " + l + " minutes until level up.";
- return s;
- }
- //No more functions
- //Function triggers start here
- //New item trigger. Loops equal to amount of items received, as such, script can handle any amount of new items
- for (var i = 0; i < items.length; i++) {
- var newItemDone = false; //newItemDone equals true when new item has been processed. No other new item related function will be run then
- if (useOverride) { //Criteria
- newItemDone = overrideOhYes(items[i], overrideItems); } //Triggers override
- if (!newItemDone) { //Criteria
- newItemDone = judge(items[i], beCareful, die, sellDezeNuts); } //Triggers judge to decide/deal with the item
- }
- //Triggers item ageing function
- if (getOld[0] || getOld[1]) { //Criteria
- ageing(getOld); }
- //Triggers exp calculation
- if (expCalc) { //Criteria
- var ePN = expPerMinCalc(expReset); //Calculates exp/min
- if (callMe[4]) {
- notify("Exp/min:" + Math.round(ePN)); } //Notifies exp/min
- if (callMe[5]) {
- notify(expPerCent().toFixed(4) + "%exp"); } //Notifies exp%
- if (callMe[6]) {
- notify(timeUntilLvlUp(ePN)); } //Notifies time until level up
- }
- //No more function triggers
- /*
- **************************************************************************************************Changelog**************************************************************************************************
- Version 3.6
- Added notify function
- Added item override. Items of defined rarity can now be kept regardless of other new item related settings
- Added 'percentage of current exp to level up' notification (thanks LongneckKiller)
- Added exp per minute calculation (thanks NuclearZombie)
- Added time until lvl up notification
- Added lots of 'Criteria'
- Added notifyMe variable. Script-wide notifications switch. False disables ALL notifications script-wide, true allows notifications. If true, customized notification settings apply
- Added callMe variable, if notifyMe is true then callMe determines notifications. If notifyMe is false, then no notifications will be displayed
- Hired 'the one who renders judgement'
- Changed beCareful to scaleable array. Script can now merge every rarity... Because we need it
- Changed icons in notifications to unicode. (Still the same icons)
- Changed ageing a little bit
- Adjusted comments
- Revamped user settings
- Thanks Koviko
- 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