Advertisement
thommas

Battle INF Item Handler 3.6

Nov 19th, 2015
284
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.6
  5. /*************************************************************************************************************************************************************************************************************************************************************************/
  6. //  User settings
  7. 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
  8. 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
  9. var sellDezeNuts            = 0;                    //Items of this rarity and lower will be sold if no other action is assigned to them                                                        0 to disable
  10. var timeOut                 = 5;                    //Script-scale notification timeout                                                                                                         5 is default
  11. var notifyMe                = false;                //Script-scale notification switch.    False to prevent ALL notifications, true to allow notifications
  12. var callMe                  = [
  13.     /*Grind         */        false,    //Disables/enables notifications    False to disable, true to enable
  14.     /*Merge         */        false,    //Disables/enables notifications    False to disable, true to enable
  15.     /*Sell          */        false,    //Disables/enables notifications    False to disable, true to enable
  16.     /*Keep          */        false,    //Disables/enables notifications    False to disable, true to enable
  17.     /*exp/min       */        false,    //Disables/enables notifications    False to disable, true to enable
  18.     /*exp%          */        false,    //Disables/enables notifications    False to disable, true to enable
  19.     /*timeUntilLvlUp*/        false     //Disables/enables notifications    False to disable, true to enable
  20.                               ];
  21. var getOld                  = [
  22.     /*Equipment     */        false,    //Disables/enables aging of equipment             False to disable, true to enable
  23.     /*Inventory     */        false     //Disables/enables aging of items in inventory    False to disable, true to enable
  24.                               ];
  25. var useOverride             = false;    //Disables/enables use of override                False to disable, true to enable
  26. var overrideItems           = [
  27.     /*Helmet        */        0,        //Helmets   of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  28.     /*Armor         */        0,        //Armor     of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  29.     /*Gloves        */        0,        //Gloves    of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  30.     /*Leggings      */        0,        //Leggings  of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  31.     /*Boots         */        0,        //Boots     of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  32.     /*Sword         */        0,        //Swords    of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  33.     /*2-handed Sword*/        0,        //2-handed Swords of defined rarity will be kept and locked regardless of non-override settings     0 to disable
  34.     /*Bow           */        0,        //Bows      of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  35.     /*Crossbow      */        0,        //Crossbows of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  36.     /*Wand          */        0,        //Wands     of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  37.     /*Staff         */        0,        //Staffs    of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  38.     /*Shield        */        0         //Shields   of defined rarity will be kept and locked regardless of non-override settings           0 to disable
  39.                               ];
  40. var expCalc                 = false;    //Disables/enables calculation of exp stuff         False to disable, true to enable
  41. var expReset                = false;    //Resets old exp and time                           False to disable, true to enable
  42. //  Settings be done
  43. /*************************************************************************************************************************************************************************************************************************************************************************/
  44.  
  45. //Functions start here
  46. //Grind item with item in inventory. Both must be of equal or lower rarity than defined by variable die
  47. function findGrindComponent(item, grindRarity) {
  48.     for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) { //Cycles through items in inventory
  49.         if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity <= grindRarity) && !ScriptAPI.$user.inventory.items[i].lock) { //Criteria
  50.             ScriptAPI.$userService.sellItem(craft(ScriptAPI.$user.inventory.items[i], item, 1)); //Crafting component 1 & 2, and notification setting
  51.             return true;
  52.         }
  53.     }
  54. }
  55.  
  56. //Merge item with item in inventory. Both must be of the same rarity and have the same name. E.g. Sword, or Armor
  57. function findMergeCompenent(item) {
  58.     for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) { //Cycles through items in inventory
  59.         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
  60.             craft(ScriptAPI.$user.inventory.items[i], item, 2); //Crafting component 1 & 2, and notification setting
  61.             return true;
  62.         }
  63.     }
  64. }
  65.  
  66. //Notifications, yeah
  67. function notify(message) {
  68.     if (notifyMe) {
  69.         API.notifications.create(message, timeOut); } }
  70.  
  71. //Sells item
  72. function sell(item) {
  73.     if (callMe[2]) { //Criteria
  74.         notify("\u2604 " + item.name + " \u2606" + item.rarity + "."); }
  75.     API.$userService.sellItem(item);
  76.     return true;
  77. }
  78.  
  79. //Notifies that item will be kept
  80. function keep(item) {
  81.     if (callMe[3]) { //Criteria
  82.         notify("\u2764 " + item.name + " \u2606" + item.rarity + "."); }
  83.     return true;
  84. }
  85.  
  86. //Crafting itself and notifications for either merging or grinding
  87. function craft(primary, secondary, notificationSetting) {
  88.     if (primary.ts > secondary.ts) { //Ensures primary item is older than secondary
  89.         var tmp = primary;
  90.         primary = secondary;
  91.         secondary = tmp;
  92.     }
  93.     if (primary.rarity < secondary.rarity) { //Ensures rarity of primary item is higher or equal to secondary item. Rarity has priority over age
  94.         var tmp = primary;
  95.         primary = secondary;
  96.         secondary = tmp;
  97.     }
  98.     //Notifications
  99.     if (callMe[0] && (notificationSetting == 1)) { //Criteria
  100.             notify("\u267A " + primary.name + " \u2606" + primary.rarity + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + "."); }
  101.     if (callMe[1] && (notificationSetting == 2)) { //Criteria
  102.             notify("\u2726 " + primary.name + " \u2606" + primary.rarity + " +" + primary.plus + " \u2190 " + secondary.name + " \u2606" + secondary.rarity + " +" + secondary.plus + "."); }
  103.     ScriptAPI.$craftingService.craftItems(primary, secondary); //Crafting itself
  104.     return primary; //Returns primary item
  105. }
  106.  
  107. //Function which ages items
  108. function ageing(setting) {
  109.     if (setting[0]) { //Criteria
  110.         for (var i = 0; i < ScriptAPI.$user.character.equipment.length; i++) { //Cycle through items currently equipped
  111.             ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.character.equipment[i]); } } //Ageing up item
  112.     if (setting[1]) { //Criteria
  113.         for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) { //Cycles through items in inventory
  114.             ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.inventory.items[i]); } } //Ageing up item
  115. }
  116.  
  117. //EXP. Stuff
  118. function expPerMinCalc(reset) {
  119.     if (reset || (sessionStorage.oldEXP == null)) { //Criteria
  120.         sessionStorage.oldEXP = ScriptAPI.$user.character.levelEXP; //Remember/getting current/old exp
  121.         var d = new Date; //Getting old time
  122.         sessionStorage.oldTime = d.getTime(); //Remember old time
  123.     }
  124.     var d = new Date(); //Getting new time
  125.     var timeDifference = (((d.getTime() - sessionStorage.oldTime) / 1000) / 60); //Meth (dividing to reach minutes)
  126.     var expDifference = (ScriptAPI.$user.character.levelEXP - sessionStorage.oldEXP); //Meth
  127.     var expPN = (expDifference / timeDifference); //Meth
  128.     return expPN;
  129. }
  130.  
  131. //Override stuff
  132. function overrideOhYes(item, overrideRarity) {
  133.     var itemTypesAndSubTypes = ["head", "body", "hands", "legs", "feet", "SWORD", "TWO_HANDED_SWORD", "BOW", "CROSSBOW", "WAND", "STAFF", "SHIELD"];
  134.     for (var i = 0; i < itemTypesAndSubTypes.length; i++) {
  135.         if ((itemTypesAndSubTypes[i] == item.type || itemTypesAndSubTypes[i] == item.subType) && overrideRarity[i] == item.rarity) { //Criteria
  136.             ScriptAPI._modules.inventory.lock(item); //Locks item
  137.             return keep(item); //Notification, keep returns true
  138.         }
  139.     }
  140. }
  141.  
  142. //The one who renders judgement
  143. function judge(item, mergeRarity, grindRarity, sellRarity) {
  144.     for (var i = 0; i < mergeRarity.length; i++) { //Cycle through rarites defined be beCareful
  145.         if (item.rarity == mergeRarity[i]) { //Criteria
  146.             return findMergeCompenent(item); } } //Calls merge function
  147.     if (item.rarity <= grindRarity) { //Criteria
  148.         return findGrindComponent(item, grindRarity); } //Calls grind function
  149.     if (item.rarity <= sellRarity) { //Criteria
  150.         return sell(item); } //Calls sell function
  151.     return keep(item); //If nothing of the above was applied
  152. }
  153.  
  154. //EXP.All about the cents
  155. function expPerCent() {
  156.     var x = 2000 * Math.pow(2.7225, ScriptAPI.$user.character.level / 10); //Exp needed for lvl up: (2.7225^(CharLevel/10))*2000
  157.     var y = ScriptAPI.$user.character.levelEXP; //Current exp
  158.     var z = (y * 100) / x; //(CurrentExp*100)/expNeeded=exp percentage towards completion
  159.     return z;
  160.     //API.notifications.create("Level: " + z.toFixed(4).toString() + "%"); //z.toFixed(i) i defines amount of decimals
  161. }
  162.  
  163. //EXP. Time until level up
  164. function timeUntilLvlUp(expPerMin) {
  165.     var i = ((2000 * (Math.pow(2.7225, (ScriptAPI.$user.character.level / 10)))) - ScriptAPI.$user.character.levelEXP) / expPerMin; //(totalExpNeeded- currentExp) / expPerMin = totalMinutesUntilLvlUp
  166.     var j = Math.floor(i / 1440); //totalMinutesUntilLvlUp / 1440 = daysUntilLvlUp
  167.     var k = Math.floor((i % 1440) / 60); //(totalMinutesUntilLvlUp modulus 1440) / 60 = hoursUntilLvlUp - daysUntilLvlUp
  168.     var l = Math.floor((i % 1440) % 60); //(totalMinutesUntilLvlUp modulus 1440) modulus 60 = minutesUntilLvlUp - (daysUntilLvlUp + hoursUntilLvlUp)
  169.     var s = j + " days " + k + " hours " + l + " minutes until level up.";
  170.     return s;
  171. }
  172. //No more functions
  173.  
  174. //Function triggers start here
  175. //New item trigger. Loops equal to amount of items received, as such, script can handle any amount of new items
  176. for (var i = 0; i < items.length; i++) {
  177.     var newItemDone = false; //newItemDone equals true when new item has been processed. No other new item related function will be run then
  178.     if (useOverride) { //Criteria
  179.         newItemDone = overrideOhYes(items[i], overrideItems); } //Triggers override
  180.     if (!newItemDone) { //Criteria
  181.         newItemDone = judge(items[i], beCareful, die, sellDezeNuts); } //Triggers judge to decide/deal with the item
  182. }
  183.  
  184. //Triggers item ageing function
  185. if (getOld[0] || getOld[1]) { //Criteria
  186.     ageing(getOld); }
  187.  
  188. //Triggers exp calculation
  189. if (expCalc) { //Criteria
  190.     var ePN = expPerMinCalc(expReset); //Calculates exp/min
  191.     if (callMe[4]) {
  192.         notify("Exp/min:" + Math.round(ePN)); } //Notifies exp/min
  193.     if (callMe[5]) {
  194.         notify(expPerCent().toFixed(4) + "%exp"); } //Notifies exp%
  195.     if (callMe[6]) {
  196.         notify(timeUntilLvlUp(ePN)); } //Notifies time until level up
  197. }
  198. //No more function triggers
  199.  
  200.  
  201. /*
  202. **************************************************************************************************Changelog**************************************************************************************************
  203.  
  204. Version 3.6
  205. Added notify function
  206. Added item override. Items of defined rarity can now be kept regardless of other new item related settings
  207. Added 'percentage of current exp to level up' notification (thanks LongneckKiller)
  208. Added exp per minute calculation (thanks NuclearZombie)
  209. Added time until lvl up notification
  210. Added lots of 'Criteria'
  211. Added notifyMe variable. Script-wide notifications switch. False disables ALL notifications script-wide, true allows notifications. If true, customized notification settings apply
  212. Added callMe variable, if notifyMe is true then callMe determines notifications. If notifyMe is false, then no notifications will be displayed
  213. Hired 'the one who renders judgement'
  214. Changed beCareful to scaleable array. Script can now merge every rarity... Because we need it
  215. Changed icons in notifications to unicode. (Still the same icons)
  216. Changed ageing a little bit
  217. Adjusted comments
  218. Revamped user settings
  219. Thanks Koviko
  220.  
  221. Version 3.5
  222. Fixed craft function selling items that should not be sold
  223. Fixed craft function crafting older items into newer
  224.  
  225. Version 3.4
  226. Added craft function. Crafting is now done by one single function. Grind and merge now merely tell craft which items to merge/grind
  227. Added usage of timestamp. Is still not needed if handling new items
  228. Cleaned up code a teeny bit
  229. Modified notifications
  230.  
  231. Version 3.3
  232. Fixed attempt to merge/grind locked items
  233.  
  234. Version 3.2
  235. Added automagic item ageing
  236. Adjusted comments
  237. Note: Automagic ageing appears to be quite resource intensive. I myself experience a small stutter whenever it cycles through 80+ items.
  238.  
  239. Version 3.1:
  240. Added changelog
  241. Added notification timeout variable
  242.  
  243. **************************************************************************************************Changelog**************************************************************************************************
  244. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement