Advertisement
Guest User

Untitled

a guest
Mar 15th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.     "use strict";
  3.     // Golden Miner Prospector version 1.2.0
  4.  
  5.     //For todays date;
  6.     Date.prototype.today = function(){
  7.         return this.getFullYear() + "/" + (((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1)  +"/"+ ((this.getDate() < 10)?"0":"") + this.getDate();
  8.     };
  9.    
  10.     //For the time now
  11.     Date.prototype.timeNow = function(){
  12.         return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
  13.     };
  14.  
  15.     function ItemCompare(options){
  16.         this.Enabled = options[0] || false;
  17.         this.CheckGold = options[1] || false;
  18.         this.CheckDiamonds = options[2] || false;
  19.         this.CheckMagicFind = options[3] || false;
  20.         this.CheckXp = options[4] || false;
  21.         this.MinSockets = options[5] || 0;
  22.     }
  23.  
  24.     function ItemType(elementClass, name, action, compareStats, quantityThreshold) {
  25.         this.ElementClass = elementClass || null;
  26.         this.Name = name || null;
  27.         this.Action = action || null; // sell, drink, craft, stash        
  28.         this.CompareStats = new ItemCompare(compareStats); // checks to see if stats have been imporved, if not then executes action. Can also check for minimum sockets        
  29.         this.QuantityThreshold = quantityThreshold || null; // Action will not be executed unless the count of items of a type exceed this number, minimum number required to execute action
  30.     }
  31.  
  32.     function Item(itemElement) {
  33.         this.Id = null;
  34.         this.StatChange = null;
  35.         this.Stats = null;
  36.         this.ActionElement = null;
  37.         this.ExecuteAction = true;
  38.         this.ActionExecuteTime = null;
  39.         this.Place = null;
  40.  
  41.         this.Init(itemElement);
  42.     }
  43.  
  44.     Item.prototype.Init = function(itemElement){
  45.         this.Place = 'stash';
  46.         this.Id = itemElement.getAttribute('stashid');
  47.         if(!this.Id){
  48.             this.Place = 'finds';
  49.             this.Id = itemElement.getAttribute('findid');
  50.         }
  51.     };
  52.    
  53.     function addSuffixPadding(value, length) {
  54.         value = value.toString();
  55.         var diff = length - value.length;
  56.  
  57.         if(diff > 0) {
  58.             return (value + new Array(diff).join(' '));
  59.         }
  60.  
  61.         return value;
  62.     }
  63.  
  64.     var itemTypes = [
  65.         // Gems
  66.         new ItemType('itemtype100','Tiny Ruby','sell', [], 0),
  67.         new ItemType('itemtype101','Small Ruby','sell', [], 0),
  68.         new ItemType('itemtype102','Big Ruby','sell', [], 0),
  69.         new ItemType('itemtype103','Giant Ruby','sell', [], 0),
  70.  
  71.         new ItemType('itemtype110','Tiny Diamond','sell', [], 0),
  72.         new ItemType('itemtype111','Small Diamond','sell', [], 0),
  73.         new ItemType('itemtype112','Big Diamond','sell', [], 0),
  74.         new ItemType('itemtype113','Giant Diamond','sell', [], 0),
  75.  
  76.         new ItemType('itemtype120','Tiny Amethyst','sell', [], 15),
  77.         new ItemType('itemtype121','Small Amethyst','sell', [], 15),
  78.         new ItemType('itemtype122','Big Amethyst','sell', [], 15),
  79.         new ItemType('itemtype123','Giant Amethyst','sell', [], 15),
  80.  
  81.         new ItemType('itemtype130','Tiny Sapphire','sell', [], 0),
  82.         new ItemType('itemtype131','Small Sapphire','sell', [], 0),
  83.         new ItemType('itemtype132','Big Sapphire','sell', [], 0),
  84.         new ItemType('itemtype133','Giant Sapphire','sell', [], 0),
  85.  
  86.         new ItemType('itemtype140','Tiny Starstone','sell', [], 0),
  87.         new ItemType('itemtype141','Small Starstone','sell', [], 0),
  88.         new ItemType('itemtype142','Big Starstone','sell', [], 0),
  89.         new ItemType('itemtype143','Giant Starstone','sell', [], 0),
  90.  
  91.         // Potions
  92.         new ItemType('itemtype8','Instant Gold Potion','drink', [], 50),
  93.         new ItemType('itemtype9','Instant Diamond Potion','drink', [], 50),
  94.         new ItemType('itemtype10','Gold Potion','drink', [], 0),
  95.         new ItemType('itemtype11','Diamond Potion','drink', [], 0),
  96.         new ItemType('itemtype12','Magic Find Potion','drink', [], 0),
  97.  
  98.         // Scrolls
  99.         new ItemType('itemtype5','Blue scroll','craft', [], 0),
  100.         new ItemType('itemtype6','Yellow scroll','craft', [], 0),
  101.         new ItemType('itemtype7','Legendary scroll','craft', [], 0), // these chew up too much of my diamond supply
  102.         new ItemType('itemtype13','Amnesia Scroll','sell', [], 5), // don't craft this one unless you want your stats reset automatically
  103.        
  104.  
  105.         // Items
  106.         new ItemType('itemtype0','pickaxe','sell', [true, true, false, true, false, 1], 0),
  107.         new ItemType('itemtype1','armor','sell', [true, true, false, true, false, 1], 0),
  108.         new ItemType('itemtype2','helm','sell', [true, true, false, true, false, 1], 0),
  109.         new ItemType('itemtype3','ring','sell', [true, true, false, true, false, 1], 0),
  110.         new ItemType('itemtype4','amulet','sell', [true, true, false, true, false, 1], 0)
  111.     ];
  112.  
  113.     function appendNodeListToArray(targetArray, nodeList ){
  114.         for (var i = 0; i < nodeList.length; ++i) {
  115.                 targetArray.push(nodeList[i]);
  116.             }
  117.         return targetArray;
  118.     }
  119.    
  120.     function generateOutput(itemType, item, message) {
  121.         var output = [
  122.             addSuffixPadding(itemType.Action, 7),
  123.             addSuffixPadding(itemType.Name, 25),
  124.             'from ' + addSuffixPadding(item.Place, 7),
  125.             'on ' + addSuffixPadding(item.ActionExecuteTime.today() + " @ " + item.ActionExecuteTime.timeNow(), 26)
  126.         ];
  127.  
  128.         if(itemType.CompareStats.Enabled){
  129.             output.push(' stats Change: ');
  130.             output.push(' GPS:' + addSuffixPadding(parseInt(item.StatChange.goldPerSec, 10), 11));
  131.             output.push(' DPS:' + addSuffixPadding(parseInt(item.StatChange.diamondsPerSec, 10), 7));
  132.             output.push(' MF:' + addSuffixPadding(parseFloat(item.StatChange.magicFind).toFixed(2), 7));
  133.             output.push(' XP:' + addSuffixPadding(parseInt(item.StatChange.maxXpPerSec, 10), 6));
  134.             output.push(' Sockets:' + addSuffixPadding(parseInt(item.Stats.sockets, 10), 2));
  135.         }
  136.  
  137.         output.push(message);
  138.  
  139.         return output.join('');
  140.     }
  141.  
  142.     function automate(){
  143.         itemTypes.every(function(itemType) {
  144.             var itemTypeList = [],
  145.                 stashAreaList = document.getElementById('stash'),
  146.                 findsAreaList = document.getElementById('finds'),
  147.                 itemProcessed = false,
  148.                 item,
  149.                 output,
  150.                 message = '',
  151.                 countItemsOfType = 0,
  152.                 diamondBalance = 0;
  153.  
  154.             itemTypeList = appendNodeListToArray(itemTypeList, stashAreaList.getElementsByClassName(itemType.ElementClass));
  155.             itemTypeList = appendNodeListToArray(itemTypeList, findsAreaList.getElementsByClassName(itemType.ElementClass));
  156.            
  157.  
  158.             itemTypeList.every(function(itemElement){
  159.                 item = new Item(itemElement);
  160.  
  161.                 countItemsOfType++;
  162.  
  163.                 if(itemType.CompareStats.Enabled){
  164.  
  165.                     item.StatChange = game.getStatsIfEquipped(item.Place, item.Id);
  166.                     item.Stats = game.data[item.Place][item.Id];
  167.  
  168.                     var socketedMf = item.Stats.sockets * 0.4;
  169.  
  170.                     if(
  171.                            (itemType.CompareStats.CheckGold && item.StatChange.goldPerSec > 0)
  172.                         || (itemType.CompareStats.CheckMagicFind && (item.StatChange.magicFind + socketedMf) >= 0)
  173.                         || (itemType.CompareStats.CheckDiamonds && item.StatChange.diamondsPerSec > 0)
  174.                         || (itemType.CompareStats.CheckXp && item.StatChange.maxXpPerSec > 0)
  175.                     ){
  176.                         if(item.ExecuteAction && item.Stats.sockets >= itemType.CompareStats.MinSockets ){
  177.                         // at least one of the stats is better then the currnetly equipped itemType, don't sell                                                
  178.                             item.ExecuteAction  = false;
  179.                         } else {
  180.                             message += " Not enough sockets. Has " + item.Stats.sockets + " needed " + itemType.CompareStats.MinSockets;
  181.                         }
  182.                     }
  183.                 }
  184.                
  185.                 // don't execute action unless the item count exceeds threshold            
  186.                 if(itemType.QuantityThreshold >= countItemsOfType){
  187.                     item.ExecuteAction  = false;
  188.                 } else if(itemType.QuantityThreshold > 0) {
  189.                     // only do so for threshold > 0 so that the message is not printed for every item action
  190.                     message += ' QuantityThreshold of ' + itemType.QuantityThreshold  + ' exceeded';
  191.                 }
  192.  
  193.                 // make sure we have enough diamonds to craft a scroll
  194.                 if(itemType.Action === 'craft'){
  195.                     item.Stats = game.data[item.Place][item.Id];
  196.                     diamondBalance =  parseInt(document.getElementById('diamond').innerHTML.replace(/ /g,''),10);
  197.  
  198.                     // not enough diamonds, skip to next item in itemTypeList
  199.                     if(item.Stats.diamondsCost > diamondBalance){
  200.                         item.ExecuteAction  = false;
  201.                     }
  202.                 }
  203.                
  204.                 // skips to next item in itemTypeList
  205.                 if(!item.ExecuteAction){
  206.                     return true;
  207.                 }
  208.  
  209.                 item.ActionElement = itemElement.getElementsByClassName(itemType.Action)[0];
  210.  
  211.                 // make sure element exists or is found
  212.                 if(item.ActionElement) {
  213.                     item.ActionElement.click();
  214.                     item.ActionExecuteTime = new Date();
  215.                     itemProcessed = true;
  216.                    
  217.                     output = generateOutput(itemType, item, message);
  218.                     console.log(output);
  219.  
  220.                     // exists the itemTypeList loop
  221.                     return false;
  222.                 }
  223.             });
  224.  
  225.             // this ensures that only one item is sold per automation interval
  226.             if(itemProcessed){
  227.                 return false;
  228.             }
  229.  
  230.             return true;
  231.         });
  232.     }
  233.        
  234.     var automateInterval = setInterval(automate, 500);
  235. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement