Advertisement
JackPS9

Cheapest Purchase ++

Oct 30th, 2014
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @id          JSModExampleApp
  3. // @name        Purchaser
  4. // @namespace   .
  5. // @version     1.2
  6. // @author      JackPS9
  7. // @include     http://www.clickerheroes.com/
  8. // @grant       none
  9. // @require     http://code.jquery.com/jquery-2.1.1.min.js
  10. // @updateURL   https://dl.dropboxusercontent.com/u/64858538/ClickerHeroes/Purchaser.js
  11. // ==/UserScript==
  12.  
  13. (function () {
  14.     "use strict";
  15.    
  16.     var main = function () {
  17.         "use strict";
  18.         //////////////////////
  19.         //Editable variables//
  20.         //////////////////////
  21.         //Integer is in miliseconds
  22.         var pur = 50;  //Purchase Interval
  23.         var asd = 30000;  //Ascend Interval
  24.         var bs = 135; //Zone Number of the last boss you want to fight
  25.         //List of the IDs of your gilded heroes Cid = 1, Frostleaf = 26  (this link shows the IDs if you show contents http://clickerheroes.wikia.com/wiki/Upgrades)
  26.         var guildedList = [];
  27.         //The level of you dogcog
  28.         var dogcoglvl = 12;
  29.         //Solo Levels - Putting hero IDs in here will cause only these heroes to be leveled
  30.         var tst = [];
  31.        
  32.        
  33.         ///////////////////////////////
  34.         //Edit nothing below this!!!!//
  35.         ///////////////////////////////
  36.         var JSMod = null;
  37.         var loadAttempts = 0;
  38.         var maxAttempts = 100;
  39.         var loadTimeout = 10000;
  40.         var baseCosts = [10, 50, 250, 1000, 4000, 20000, 100000, 400000, 2500000, 15000000, 100000000, 800000000, 6500000000, 50000000000, 450000000000, 4000000000000, 36000000000000, 320000000000000, 2700000000000000, 24000000000000000, 300000000000000000, 9000000000000000000, 350000000000000000000, 1.4e+22, 4.19999999999999e+24, 2.1e+27];
  41.         var dogcog = 1 - (dogcoglvl * 0.02);
  42.         var onlyLevels = false;
  43.         //***** implement app here *****
  44.         var App = {
  45.             name: "JSMod Example App",
  46.             onReady: function () {
  47.                 //Useless crap for this App
  48.                 //stage 1: JSMod has completely loaded. Do stuff like initializing your app here.
  49.                 init_app();
  50.             },
  51.             onPlaying: function () {
  52.                 //stage 2: User has pressed "play"-button in-game. You can now make calls to the game and receive data.
  53.                 //Where all the code really goes
  54.                 advance();
  55.                     setInterval(purchase, pur);//50 miliseconds
  56.                 setInterval(ascend, asd);//30 seconds
  57.                 if(tst.length < 0)
  58.                 {
  59.                     gildedList = tst;
  60.                     onlyLevels = true;
  61.                 }
  62.             }
  63.         };
  64.        
  65.         function calculateHeroCost(id, level){
  66.             if (id === 0 && level <= 15) {
  67.                 return Math.floor((5 + level) * Math.pow(1.07, level) * dogcog);
  68.             } else if (id === 0) {
  69.                 return Math.floor(20 * Math.pow(1.07, level) * dogcog);
  70.             } else {
  71.                 return Math.floor(baseCosts[id] * Math.pow(1.07, level) * dogcog);
  72.             }
  73.         }
  74.         function isGuilded(guildedList, heroID){
  75.             var i = guildedList.length;
  76.             while (i--) {
  77.                 if (guildedList[i] == heroID) {
  78.                     return true;
  79.                 }
  80.             }
  81.             return false;
  82.         }
  83.         function levelcheck(){
  84.             var lvl = 10;
  85.             if(onlyLevels == true)
  86.             {
  87.                 lvl = 0;
  88.             }
  89.             else
  90.             {
  91.                 var save = JSON.parse(JSMod.getUserData());
  92.                 if(save.heroCollection.heroes[4].level >= 10){lvl = 25;}//The Wandering Fisherman
  93.                 if(save.heroCollection.heroes[9].level >= 25){lvl = 50;}//Alexa, Assassin
  94.                 if(save.heroCollection.heroes[14].level >= 50){lvl = 75;}//Sir George II, King's Guard
  95.                 if(save.heroCollection.heroes[20].level >= 75){lvl = 100;}//Amenhotep
  96.                 if(save.heroCollection.heroes[20].level >= 100){lvl = 150;}
  97.                 if(save.heroCollection.heroes[26].level >= 25){lvl = 200;}//Frost Leaf
  98.                 if(save.heroCollection.heroes[26].level >= 35){lvl = 300;}
  99.                 if(save.heroCollection.heroes[26].level >= 50){lvl = 400;}
  100.                 if(save.heroCollection.heroes[26].level >= 65){lvl = 500;}
  101.                 if(save.heroCollection.heroes[26].level >= 80){lvl = 60;}
  102.                 if(save.heroCollection.heroes[26].level >= 100){lvl = 700;}
  103.                 if(save.heroCollection.heroes[26].level >= 120){lvl = 8000;}
  104.                 if(save.heroCollection.heroes[26].level >= 150){lvl = 10000;}
  105.                 if(save.currentZoneHeight > bs){lvl = 1000;}
  106.             }
  107.             return lvl;
  108.         }
  109.         function Upgrades(){
  110.             try{
  111.                 JSMod.buyAllAvailableUpgrades();
  112.             }
  113.             catch(e){};
  114.         }
  115.         function purchase(){
  116.             var save = JSON.parse(JSMod.getUserData());
  117.             var heroCosts = [];
  118.             var currentGold = save.gold;
  119.             var MLevel = levelcheck();
  120.             for (i = 0; i < 26; i++) {
  121.                 if(save.heroCollection.heroes[i+1].level < MLevel || isGuilded(guildedList, i))
  122.                 {
  123.                     try{
  124.                         heroCosts[i] = calculateHeroCost(i, save.heroCollection.heroes[i+1].level);
  125.                     }catch(e){};
  126.                 }
  127.                 else
  128.                 {
  129.                     heroCosts[i] = Number.MAX_VALUE;
  130.                 }
  131.             }
  132.             if (currentGold > Math.min.apply(Math,heroCosts))
  133.             {
  134.                 try{
  135.                     JSMod.levelHero(heroCosts.indexOf(Math.min.apply(Math,heroCosts)) + 1);
  136.                 }catch(e){};
  137.             }
  138.             Upgrades();
  139.         }
  140.         function advance(){
  141.             JSMod.setProgressMode(true);
  142.         }
  143.         function ascend(){
  144.             var save = JSON.parse(JSMod.getUserData());
  145.             if(save.currentZoneHeight >= (bs+14))
  146.             {
  147.                 JSMod.ascend();
  148.             }
  149.             advance();
  150.         }
  151.        
  152.         function init_app() {
  153.             //...
  154.         }
  155.         //******************************
  156.        
  157.         function init() {
  158.             if (window.JSMod === undefined) {
  159.                 if (loadAttempts++ < maxAttempts) {
  160.                     window.setTimeout(init, loadTimeout/maxAttempts);
  161.                 } else {
  162.                     alert("Failed to load " + App.name + "! Cannot find JSMod object on global scope");
  163.                 }
  164.             } else {
  165.                 JSMod = window.JSMod;
  166.                 JSMod.loadApp(App);
  167.             }
  168.         }
  169.        
  170.         init();
  171.     }
  172.    
  173.     function inject(func) {
  174.         var script = document.createElement("script");
  175.         script.setAttribute("type", "text/javascript");
  176.         script.appendChild(document.createTextNode("(" + func + ")();"));
  177.         $("head").append(script)[0].removeChild(script);
  178.     }
  179.    
  180.     $(inject(main));
  181. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement