Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Clickpocalypse Runner
- // @namespace http://tampermonkey.net/
- // @version 3.25
- // @description plays clickpocalypse 2 for you :3
- // @author GauHelldragon
- // @match http://minmaxia.com/c2/
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- (function() {
- 'use strict';
- })();
- var MAX_SCROLL = 30;
- window.setTimeout(function() { if ( document.getElementById("pointUpgradesContainer_0_0_0").classList[0] == "ownedUpgradeButton" ) { MAX_SCROLL = 40; } },1000);
- setInterval(checkStuff, 1000);
- debugLog("hello");
- function debugLog(string) {
- // console.log(string);
- }
- var paused = false;
- function checkStuff() {
- if ( shouldPause() ) {
- if ( !paused ) { paused = true; debugLog("Now paused"); }
- return;
- }
- if ( paused ) { paused = false; debugLog("unpaused"); }
- // Click first upgrade
- document.getElementById("upgradeButtonContainer_0").onmouseup();
- // Click loot button
- var loots = document.getElementsByClassName("lootButton");
- if ( loots.length > 0 ) {
- loots[0].onmouseup();
- }
- // Click all potions
- var auto = clickPotions();
- // Maybe click some scrolls
- clickScrolls(auto);
- levelUp();
- }
- function clickPotions() {
- if ( isMaxPotions() ) {
- RemoveDuplicatePotion();
- }
- var potionTypes = getPotionTypes();
- if ( potionTypes.length == 1 && potionTypes[0] == "Potions Last Longer" ) { return; }
- var potions = document.getElementsByClassName("potionContentContainer");
- var auto = 0;
- var inCombat = isInCombat();
- for ( var i=0;i<potions.length;i++) {
- var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
- if ( potionName == "Scrolls Auto Fire" ) { auto = 1; }
- if ( shouldFirePotion(potionName,inCombat,potionTypes)) {
- potions[i].onmouseup();
- }
- }
- return auto;
- }
- function isInCombat() {
- return document.getElementById("encounterNotificationPanel").style.display == "block";
- }
- function shouldFirePotion(potionName,inCombat,potionTypes) {
- if ( potionName == "Scrolls Auto Fire" && isInList(potionTypes,"Infinite Scrolls") ) { return false; }
- if ( inCombat ) { return true; }
- var combatPotions = [
- "Double Gold",
- "Double Kills",
- "Double Experience",
- "Infinite Scrolls",
- "100% Item Drops",
- "Spells Cost Nothing",
- "Item Gold Values",
- "Scrolls Auto Fire",
- "Double Gold Drops",
- "Double Item Drops"];
- if ( isInList(combatPotions,potionName) ) { return false; }
- return true;
- }
- function getPotionTypes() {
- var pList = [];
- var potions = document.getElementsByClassName("potionContentContainer");
- for ( var i=0;i<potions.length;i++) {
- var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
- if ( !isInList( pList, potionName )) {
- pList.push(potionName);
- }
- }
- return pList;
- }
- function RemoveDuplicatePotion() {
- //debugLog("searching for duplicates");
- var potion = getDuplicatePotion();
- if ( !potion ) {
- //debugLog("no duplicates");
- potion = getBadPotion();
- }
- if ( potion ) {
- //debugLog("dropping potion");
- dropPotion(potion);
- }
- }
- function getDuplicatePotion() {
- var potionList = [];
- var duplicateNameList = [];
- var potions = document.getElementsByClassName("potionContentContainer");
- for ( var i=0;i<potions.length;i++) {
- var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
- if ( !isInList( potionList, potionName )) { potionList.push(potionName); }
- else if ( isInList( potionList, potionName ) && !isInList( duplicateNameList, potionName ) ) {
- // debugLog("adding to dupe list");
- duplicateNameList.push(potionName);
- }
- }
- if ( duplicateNameList.length === 0 ) { return; }
- //debugLog("returning oldest");
- for ( i=0; i<potions.length;i++ ) {
- potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
- if ( isInList(duplicateNameList,potionName) ) { return potions[i]; }
- }
- }
- function getBadPotion() {
- var potions = document.getElementsByClassName("potionContentContainer");
- var autoPot = false;
- var infiPot = false;
- for ( var i=0;i<potions.length;i++) {
- var potionName = potions[i].children[0].rows[0].cells[1].innerHTML;
- if ( potionName == "Double Kills" ) { return potions[i]; }
- if ( potionName == "Docile Monsters" ) { return potions[i]; }
- if ( !autoPot && potionName == "Scrolls Auto Fire" ) { autoPot = potions[i]; }
- if ( potionName == "Infinite Scrolls" ) { infiPot = true; }
- }
- if ( infiPot && autoPot ) {
- return autoPot;
- }
- }
- function dropPotion(potion) {
- debugLog( "dropping potion: " + potion.children[0].rows[0].cells[1].innerHTML ) ;
- potion.children[2].onmouseup();
- }
- function isInList(list,thing) {
- return ( list.indexOf(thing) != -1 );
- }
- function isMaxPotions() {
- var max = getMaxPotions();
- var x = max % 2;
- var y = Math.floor(max / 2);
- var pID = "potionButton_Row" + y + "_Col" + x;
- if ( document.getElementById(pID).children[0].children[2].style.display == "block" ) {
- return true;
- }
- return false;
- }
- function getMaxPotions() {
- var max = 5;
- if ( document.getElementById("pointUpgradesContainer_1_0_1").classList[0] == "ownedUpgradeButton" ) { max++; }
- if ( document.getElementById("pointUpgradesContainer_1_1_1").classList[0] == "ownedUpgradeButton" ) { max++; }
- return max;
- }
- function clickScrolls(auto) {
- var scrolls = document.getElementsByClassName("scrollButton");
- if ( scrolls.length === 0 ) { return; }
- var i = Math.floor(Math.random() * scrolls.length);
- var mynumString = scrolls[i].children[0].rows[1].cells[0].innerHTML;
- if ( mynumString == "Infinite" )
- {
- for ( i = 0; i < scrolls.length; i++ ) {
- scrolls[i].onmouseup();
- }
- window.setTimeout(fireAllScrolls,500);
- }
- else
- {
- if ( fireMaxedScroll() ) {
- window.setTimeout(fireMaxedScroll,500);
- return;
- }
- var numLeft = parseInt(mynumString.substring(1) );
- var boss = document.getElementsByClassName("bossEncounterNotificationDiv").length > 0;
- if ( Math.random() > 0.5 || numLeft > (MAX_SCROLL-5) || boss )
- {
- var stock = MAX_SCROLL-20;
- if ( boss ) {
- stock = 0;
- }
- if ( auto == 1 ) { stock = MAX_SCROLL-5; }
- //debugLog("wanted stock: " + stock);
- if ( numLeft > stock ) {
- scrolls[i].onmouseup();
- }
- }
- }
- }
- var scrolls;
- function fireMaxedScroll() {
- var maxedScroll = getMaxedScroll(scrolls);
- if ( maxedScroll )
- {
- maxedScroll.onmouseup();
- return true;
- }
- return false;
- }
- function getMaxedScroll(scrolls) {
- var highest = MAX_SCROLL-4;
- //debugLog("HIGHEST = " + highest);
- var maxScroll = 0;
- for ( var i =0; i < scrolls.length;i++ ) {
- var numString = scrolls[i].children[0].rows[1].cells[0].innerHTML;
- var numLeft = parseInt(numString.substring(1) );
- if ( numLeft > highest || ( numLeft == highest && ( !maxScroll || Math.random() > 0.5 ) ) ) {
- maxScroll = scrolls[i];
- highest = numLeft;
- }
- }
- // debugLog("maxed scroll num: " + highest + " return = " + maxScroll);
- return maxScroll;
- }
- function shouldPause() {
- var gameTab = getGameTab();
- if ( gameTab.classList[0] != "selectedTab" ) { return true; }
- return false;
- }
- function getGameTab() {
- var tabList = document.getElementById("gameTabMenu").children[0].getElementsByTagName("li");
- for (var i=0;i<tabList.length;i++)
- {
- if ( tabList[i].children[0].innerHTML == "Game" )
- {
- return tabList[i];
- }
- }
- }
- function fireAllScrolls() {
- scrolls = document.getElementsByClassName("scrollButton");
- if ( scrolls.length > 0 ) {
- var numString = scrolls[0].children[0].rows[1].cells[0].innerHTML;
- if ( numString == "Infinite" )
- {
- for ( var i = 0; i < scrolls.length; i++ ) {
- scrolls[i].onmouseup();
- }
- }
- }
- }
- function levelUp() {
- var levelUpTabIndex = getLevelTab();
- if ( levelUpTabIndex == -1 ) {
- debugLog("No Levelup tab found");
- return; }
- var levelUpTab = document.getElementById("gameTabMenu").children[0].getElementsByTagName("li")[levelUpTabIndex];
- levelUpTab.children[0].click();
- window.setTimeout(function() {chooseSkill(levelUpTabIndex);},100);
- }
- function getLevelTab() {
- var gameTabs = document.getElementById("gameTabMenu").children[0].getElementsByTagName("li");
- for ( var i = 3; i<=7; i++) {
- if ( gameTabs[i].className == "tabHighlighted" ) { return i; }
- }
- return -1;
- }
- function chooseSkill(index) {
- debugLog("chooseSkill called with index: " + index);
- index = index - 3;
- var buttons = document.getElementsByClassName("upgradeButton");
- var bestButton = 0;
- var lowest = -1;
- for ( var i=1;i<buttons.length;i++) {
- var id = buttons[i].id;
- if ( id.substring(0,25) == "characterSkillsContainer" + index ) {
- var height = id.substring(26,27);
- if ( height > lowest || ( height == lowest && Math.random > 0.5 )) {
- lowest = height;
- bestButton = buttons[i];
- }
- }
- }
- if ( bestButton ) {
- debugLog("clicking skill");
- bestButton.onmouseup();
- }
- window.setTimeout(clickGameTab,100);
- }
- function clickGameTab() {
- debugLog("returning to gametab");
- var gameTab = getGameTab();
- gameTab.children[0].click();
- }
Add Comment
Please, Sign In to add comment