GauHelldragon

ClickRunner

Oct 13th, 2017 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Clickpocalypse Runner
  3. // @namespace    http://tampermonkey.net/
  4. // @version      3.25
  5. // @description  plays clickpocalypse 2 for you :3
  6. // @author       GauHelldragon
  7. // @match        http://minmaxia.com/c2/
  8. // @grant        none
  9. // @run-at       document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14. })();
  15.  
  16. var MAX_SCROLL = 30;
  17. window.setTimeout(function() { if ( document.getElementById("pointUpgradesContainer_0_0_0").classList[0] == "ownedUpgradeButton" ) { MAX_SCROLL = 40; } },1000);
  18.  
  19. setInterval(checkStuff, 1000);
  20.  
  21. debugLog("hello");
  22.  
  23. function debugLog(string) {
  24.    // console.log(string);
  25. }
  26.  
  27. var paused = false;
  28.  
  29. function checkStuff() {
  30.     if ( shouldPause() ) {
  31.         if ( !paused ) { paused = true; debugLog("Now paused"); }
  32.         return;
  33.     }
  34.     if ( paused ) { paused = false; debugLog("unpaused"); }
  35.  
  36.     // Click first upgrade
  37.     document.getElementById("upgradeButtonContainer_0").onmouseup();
  38.  
  39.     // Click loot button
  40.     var loots = document.getElementsByClassName("lootButton");
  41.     if ( loots.length > 0 ) {
  42.         loots[0].onmouseup();
  43.     }
  44.  
  45.     // Click all potions
  46.     var auto = clickPotions();
  47.  
  48.     // Maybe click some scrolls
  49.     clickScrolls(auto);
  50.  
  51.     levelUp();
  52.  
  53.  
  54. }
  55.  
  56. function clickPotions() {
  57.     if ( isMaxPotions() ) {
  58.         RemoveDuplicatePotion();
  59.     }
  60.  
  61.     var potionTypes = getPotionTypes();
  62.     if ( potionTypes.length == 1 && potionTypes[0] == "Potions Last Longer" ) { return; }
  63.  
  64.     var potions = document.getElementsByClassName("potionContentContainer");
  65.     var auto = 0;
  66.  
  67.     var inCombat = isInCombat();
  68.  
  69.     for ( var i=0;i<potions.length;i++) {
  70.         var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
  71.         if ( potionName == "Scrolls Auto Fire" ) { auto = 1; }
  72.         if ( shouldFirePotion(potionName,inCombat,potionTypes)) {
  73.             potions[i].onmouseup();
  74.         }
  75.     }
  76.     return auto;
  77. }
  78.  
  79. function isInCombat() {
  80.     return document.getElementById("encounterNotificationPanel").style.display == "block";
  81.  
  82. }
  83. function shouldFirePotion(potionName,inCombat,potionTypes) {
  84.     if ( potionName == "Scrolls Auto Fire" && isInList(potionTypes,"Infinite Scrolls") ) { return false; }
  85.     if ( inCombat ) { return true; }
  86.     var combatPotions = [
  87.         "Double Gold",
  88.         "Double Kills",
  89.         "Double Experience",
  90.         "Infinite Scrolls",
  91.         "100% Item Drops",
  92.         "Spells Cost Nothing",
  93.         "Item Gold Values",
  94.         "Scrolls Auto Fire",
  95.         "Double Gold Drops",
  96.         "Double Item Drops"];
  97.     if ( isInList(combatPotions,potionName) ) { return false; }
  98.     return true;
  99. }
  100.  
  101. function getPotionTypes() {
  102.     var pList = [];
  103.     var potions = document.getElementsByClassName("potionContentContainer");
  104.     for ( var i=0;i<potions.length;i++) {
  105.         var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
  106.         if ( !isInList( pList, potionName )) {
  107.  
  108.             pList.push(potionName);
  109.         }
  110.     }
  111.     return pList;
  112. }
  113.  
  114. function RemoveDuplicatePotion() {
  115.     //debugLog("searching for duplicates");
  116.     var potion = getDuplicatePotion();
  117.     if ( !potion ) {
  118.         //debugLog("no duplicates");
  119.         potion = getBadPotion();
  120.  
  121.     }
  122.     if ( potion ) {
  123.         //debugLog("dropping potion");
  124.         dropPotion(potion);
  125.     }
  126.  
  127. }
  128.  
  129. function getDuplicatePotion() {
  130.     var potionList = [];
  131.     var duplicateNameList = [];
  132.  
  133.     var potions = document.getElementsByClassName("potionContentContainer");
  134.     for ( var i=0;i<potions.length;i++) {
  135.         var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
  136.         if ( !isInList( potionList, potionName )) { potionList.push(potionName); }
  137.         else if ( isInList( potionList, potionName ) && !isInList( duplicateNameList, potionName ) ) {
  138.             //   debugLog("adding to dupe list");
  139.             duplicateNameList.push(potionName);
  140.         }
  141.     }
  142.     if ( duplicateNameList.length === 0 ) { return; }
  143.     //debugLog("returning oldest");
  144.     for ( i=0; i<potions.length;i++ ) {
  145.         potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
  146.         if ( isInList(duplicateNameList,potionName) ) { return potions[i]; }
  147.     }
  148. }
  149.  
  150. function getBadPotion() {
  151.     var potions = document.getElementsByClassName("potionContentContainer");
  152.     var autoPot = false;
  153.     var infiPot = false;
  154.     for ( var i=0;i<potions.length;i++) {
  155.         var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
  156.         if ( potionName == "Double Kills" ) { return potions[i]; }
  157.         if ( potionName == "Docile Monsters" ) { return potions[i]; }
  158.         if ( !autoPot && potionName == "Scrolls Auto Fire" ) { autoPot = potions[i]; }
  159.         if ( potionName == "Infinite Scrolls" ) { infiPot = true; }
  160.     }
  161.     if ( infiPot && autoPot ) {
  162.         return autoPot;
  163.  
  164.     }
  165. }
  166.  
  167. function dropPotion(potion) {
  168.     debugLog( "dropping potion: " + potion.children[0].rows[0].cells[1].innerHTML ) ;
  169.     potion.children[2].onmouseup();
  170. }
  171.  
  172. function isInList(list,thing) {
  173.     return ( list.indexOf(thing) != -1 );
  174. }
  175.  
  176. function isMaxPotions() {
  177.     var max = getMaxPotions();
  178.     var x = max % 2;
  179.     var y = Math.floor(max / 2);
  180.     var pID = "potionButton_Row" + y + "_Col" + x;
  181.     if ( document.getElementById(pID).children[0].children[2].style.display == "block" ) {
  182.         return true;
  183.     }
  184.     return false;
  185. }
  186.  
  187. function getMaxPotions() {
  188.     var max = 5;
  189.     if ( document.getElementById("pointUpgradesContainer_1_0_1").classList[0] == "ownedUpgradeButton" ) { max++; }
  190.     if ( document.getElementById("pointUpgradesContainer_1_1_1").classList[0] == "ownedUpgradeButton" ) { max++; }
  191.     return max;
  192. }
  193.  
  194. function clickScrolls(auto) {
  195.     var scrolls = document.getElementsByClassName("scrollButton");
  196.     if ( scrolls.length === 0 ) { return; }
  197.     var i = Math.floor(Math.random() * scrolls.length);
  198.     var mynumString = scrolls[i].children[0].rows[1].cells[0].innerHTML;
  199.     if ( mynumString == "Infinite" )
  200.     {
  201.         for ( i = 0; i < scrolls.length; i++ ) {
  202.             scrolls[i].onmouseup();
  203.         }
  204.         window.setTimeout(fireAllScrolls,500);
  205.  
  206.     }
  207.     else
  208.     {
  209.         if ( fireMaxedScroll() ) {
  210.             window.setTimeout(fireMaxedScroll,500);
  211.             return;
  212.         }
  213.  
  214.  
  215.         var numLeft = parseInt(mynumString.substring(1) );
  216.         var boss = document.getElementsByClassName("bossEncounterNotificationDiv").length > 0;
  217.         if ( Math.random() > 0.5 || numLeft > (MAX_SCROLL-5) || boss )
  218.         {
  219.             var stock = MAX_SCROLL-20;
  220.             if ( boss ) {
  221.                 stock = 0;
  222.             }
  223.             if ( auto == 1 ) { stock = MAX_SCROLL-5; }
  224.             //debugLog("wanted stock: " + stock);
  225.             if ( numLeft > stock ) {
  226.                 scrolls[i].onmouseup();
  227.             }
  228.         }
  229.     }
  230. }
  231. var scrolls;
  232.  
  233. function fireMaxedScroll() {
  234.     var maxedScroll = getMaxedScroll(scrolls);
  235.     if ( maxedScroll )
  236.     {
  237.         maxedScroll.onmouseup();
  238.         return true;
  239.     }
  240.     return false;
  241. }
  242.  
  243. function getMaxedScroll(scrolls) {
  244.     var highest = MAX_SCROLL-4;
  245.     //debugLog("HIGHEST = " + highest);
  246.     var maxScroll = 0;
  247.     for ( var i =0; i < scrolls.length;i++ ) {
  248.         var numString = scrolls[i].children[0].rows[1].cells[0].innerHTML;
  249.         var numLeft = parseInt(numString.substring(1) );
  250.         if ( numLeft > highest || ( numLeft == highest && ( !maxScroll || Math.random() > 0.5 ) ) ) {
  251.             maxScroll = scrolls[i];
  252.             highest = numLeft;
  253.         }
  254.     }
  255.     // debugLog("maxed scroll num: " + highest + " return = " + maxScroll);
  256.     return maxScroll;
  257. }
  258.  
  259. function shouldPause() {
  260.     var gameTab = getGameTab();
  261.     if ( gameTab.classList[0] != "selectedTab" ) { return true; }
  262.     return false;
  263. }
  264.  
  265. function getGameTab() {
  266.     var tabList = document.getElementById("gameTabMenu").children[0].getElementsByTagName("li");
  267.     for (var i=0;i<tabList.length;i++)
  268.     {
  269.         if ( tabList[i].children[0].innerHTML == "Game" )
  270.         {
  271.             return tabList[i];
  272.         }
  273.     }
  274. }
  275.  
  276. function fireAllScrolls() {
  277.     scrolls = document.getElementsByClassName("scrollButton");
  278.     if ( scrolls.length > 0 ) {
  279.         var numString = scrolls[0].children[0].rows[1].cells[0].innerHTML;
  280.         if ( numString == "Infinite" )
  281.         {
  282.             for ( var i = 0; i < scrolls.length; i++ ) {
  283.                 scrolls[i].onmouseup();
  284.             }
  285.         }
  286.     }
  287. }
  288.  
  289. function levelUp() {
  290.     var levelUpTabIndex = getLevelTab();
  291.     if ( levelUpTabIndex == -1 ) {
  292.         debugLog("No Levelup tab found");
  293.         return; }
  294.     var levelUpTab = document.getElementById("gameTabMenu").children[0].getElementsByTagName("li")[levelUpTabIndex];
  295.  
  296.     levelUpTab.children[0].click();
  297.     window.setTimeout(function() {chooseSkill(levelUpTabIndex);},100);
  298. }
  299.  
  300. function getLevelTab() {
  301.     var gameTabs = document.getElementById("gameTabMenu").children[0].getElementsByTagName("li");
  302.     for ( var i = 3; i<=7; i++) {
  303.         if ( gameTabs[i].className == "tabHighlighted" ) { return i; }
  304.     }
  305.     return -1;
  306. }
  307.  
  308. function chooseSkill(index) {
  309.     debugLog("chooseSkill called with index: " + index);
  310.     index = index - 3;
  311.     var buttons = document.getElementsByClassName("upgradeButton");
  312.     var bestButton = 0;
  313.     var lowest = -1;
  314.     for ( var i=1;i<buttons.length;i++) {
  315.         var id = buttons[i].id;
  316.         if ( id.substring(0,25) == "characterSkillsContainer" + index ) {
  317.             var height = id.substring(26,27);
  318.             if ( height > lowest || ( height == lowest && Math.random > 0.5 )) {
  319.                 lowest = height;
  320.                 bestButton = buttons[i];
  321.             }
  322.  
  323.         }
  324.     }
  325.     if ( bestButton ) {
  326.         debugLog("clicking skill");
  327.         bestButton.onmouseup();
  328.     }
  329.  
  330.     window.setTimeout(clickGameTab,100);
  331.  
  332.  
  333. }
  334.  
  335. function clickGameTab() {
  336.     debugLog("returning to gametab");
  337.     var gameTab = getGameTab();
  338.     gameTab.children[0].click();
  339. }
Add Comment
Please, Sign In to add comment