Rewrite current functionality to be cleaner
This commit is contained in:
parent
b81994746a
commit
0ba3b9e926
1 changed files with 170 additions and 59 deletions
229
bot.js
229
bot.js
|
@ -1,71 +1,182 @@
|
|||
var activeTimers = [];
|
||||
var botLoop;
|
||||
var botPaused = true;
|
||||
var botPurchasing = false;
|
||||
var botFightingRandomBoss = false;
|
||||
var botFightingGlobalBoss = false;
|
||||
var botBuySlimes = false;
|
||||
var botGlobalBossTimer;
|
||||
|
||||
function delayClick(selector, seconds) {
|
||||
var timer = setInterval(
|
||||
function() {
|
||||
if($(selector).length > 0) {
|
||||
$(selector).get(0).click();
|
||||
}
|
||||
},
|
||||
seconds * 1000
|
||||
);
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
function play() {
|
||||
activeTimers.push(delayClick('#popup span button:contains("Summon Boss")', 3));
|
||||
activeTimers.push(delayClick('#popup span button:contains("CONTINUE")', 3));
|
||||
activeTimers.push(delayClick('#randomBossPortal a', 20));
|
||||
activeTimers.push(delayClick('span[name="timeRemaining"]:contains("JOIN") a', 80));
|
||||
|
||||
var globalBossTimer = setInterval(function() {
|
||||
if($('img[name="globalBossImg"]').is(':visible')) {
|
||||
$('img[name="globalBossImg"]').get(0).click();
|
||||
function mainLoop() {
|
||||
//first, deal with pop-ups
|
||||
if($('#popup').is(':visible')) {
|
||||
// we check the title and respond accordingly
|
||||
var botPopupTitle = $('#popup p[name="title"]').text();
|
||||
switch(botPopupTitle) {
|
||||
case 'Raid report':
|
||||
var botMessage = botBuildRaidReport($('#popup div[name="content"]'));
|
||||
console.log(botMessage);
|
||||
clickButton('CONTINUE');
|
||||
break;
|
||||
case 'SUMMON BOSS':
|
||||
clickButton('Summon Boss');
|
||||
break;
|
||||
case 'Are you sure?':
|
||||
clickButton('Activate Item');
|
||||
break;
|
||||
case 'ARE YOU SURE?':
|
||||
case 'CONFIRM PURCHASE':
|
||||
if(botPurchasing) {
|
||||
clickButton('Yes');
|
||||
botPurchasing = false;
|
||||
} else {
|
||||
clickButton('No');
|
||||
}
|
||||
break;
|
||||
case 'WHOOPS!':
|
||||
case 'BATTLE REPORT':
|
||||
case 'Battle Report':
|
||||
case 'ACTIVITY PASSED!':
|
||||
case 'SCENARIO #1':
|
||||
clickButton('CONTINUE');
|
||||
break;
|
||||
default:
|
||||
console.log('Unknown popup: ' + botPopupTitle);
|
||||
break;
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
|
||||
var activateTimer = setInterval(function() {
|
||||
if($('button:contains("Activate")')) {
|
||||
$('button:contains("Activate")').get(0).click();
|
||||
setTimeout(function() {
|
||||
$('button:contains("Activate Item")').get(0).click();
|
||||
}, 250);
|
||||
}
|
||||
}, 10000);
|
||||
//then, check to see if we need to do anything
|
||||
|
||||
var scientistTimer = setInterval(function() {
|
||||
if($('span[name="scientists_price"]').text() == "1 BC") {
|
||||
$('button[name="hiremax_scientists"]').get(0).click();
|
||||
setTimeout(function() {
|
||||
$('button:contains("Yes")').get(0).click();
|
||||
}, 250);
|
||||
}
|
||||
}, 20000);
|
||||
//RANDOM BOSS
|
||||
if(randomBossRefreshing() === true && botFightingRandomBoss === true) {
|
||||
botFightingRandomBoss = false;
|
||||
} else if(randomBossRefreshing() === false && botFightingRandomBoss === false) {
|
||||
clickSelector('#randomBossPortal a');
|
||||
botFightingRandomBoss = true;
|
||||
}
|
||||
|
||||
activeTimers.push(globalBossTimer);
|
||||
activeTimers.push(activateTimer);
|
||||
activeTimers.push(scientistTimer);
|
||||
}
|
||||
//GLOBAL BOSS
|
||||
if(globalBossRefreshing() === true && botFightingGlobalBoss === true) {
|
||||
clearInterval(botGlobalBossTimer);
|
||||
botFightingGlobalBoss = false;
|
||||
} else if(globalBossRefreshing() === false && botFightingGlobalBoss === false) {
|
||||
clickSelector('span[name="timeRemaining"]:contains("JOIN") a');
|
||||
botGlobalBossTimer = setInterval(fightGlobalBoss, 250);
|
||||
botFightingGlobalBoss = true;
|
||||
}
|
||||
|
||||
function pause() {
|
||||
for(var i = 0; i < activeTimers.length; i++) {
|
||||
clearInterval(activeTimers[i]);
|
||||
//ACTIVATE BUFFS
|
||||
if(inactiveBuffs()) {
|
||||
clickSelector('button:contains("Activate")');
|
||||
}
|
||||
|
||||
//BUY SCIENTISTS
|
||||
if(haveBossCoins() && haveCheapLabor() && botPurchasing === false) {
|
||||
botPurchasing = true;
|
||||
clickSelector('button[name="hiremax_scientists"]');
|
||||
}
|
||||
|
||||
//BUY SLIMES
|
||||
if(botBuySlimes === true && botPurchasing === false && haveTrillions(10)) {
|
||||
botPurchasing = true;
|
||||
clickSelector('button[name="buymax-knight"]');
|
||||
}
|
||||
}
|
||||
|
||||
function botRaid(username) {
|
||||
$('button:contains("Raid")').get(0).click();
|
||||
$('input[name="raid_user"]').val(username);
|
||||
$('button:contains("Raid!")').get(0).click();
|
||||
botToggle();
|
||||
|
||||
function botBuildRaidReport(message) {
|
||||
var botRaidUser = /You.? were raided by (.*?).? /.exec(message)[1];
|
||||
var botRaidSoldiers = /lost (.*?) soldiers/.exec(message)[1];
|
||||
var botRaidResult = (/won/.exec(message) !== null) ? 'won' : 'lost';
|
||||
var botRaidStolen = (/steal (.*?) from/.exec(message) !== null) ? /steal (.*?) from/.exec(message)[1] : '$0';
|
||||
|
||||
return "RAIDED (" + botRaidUser + "): " + botRaidResult + "; lost: " + botRaidSoldiers + " and " + botRaidStolen;
|
||||
}
|
||||
|
||||
function buySlimes() {
|
||||
var slimeTimer = setInterval(function() {
|
||||
$('button[name="buymax-knight"]').get(0).click();
|
||||
setTimeout(function() {
|
||||
$('button:contains("Yes")').get(0).click();
|
||||
}, 250);
|
||||
}, 60000);
|
||||
activeTimers.push(slimeTimer);
|
||||
function haveTrillions(trillions) {
|
||||
var botCurrency = $('#money_display').text();
|
||||
var botLowerLimit = trillions * 1000000000000;
|
||||
var botCurrencyInt = Number(botCurrency.replace(/[^0-9\.]+/g,""));
|
||||
if(botCurrencyInt > botLowerLimit) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function haveBossCoins() {
|
||||
if($('#bc_display').text() != 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function haveCheapLabor() {
|
||||
if($('span[name="scientists_price"]').text() == "1 BC") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function inactiveBuffs() {
|
||||
if($('button:contains("Activate")').length > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function randomBossRefreshing() {
|
||||
if($('span[name="timer"]').is(':visible')) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function globalBossRefreshing() {
|
||||
if($('span[name="timeRemaining"]:contains("min"), span[name="timeRemaining"]:contains("sec")').length > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function fightGlobalBoss() {
|
||||
if($('img[name="globalBossImg"]').is(':visible')) {
|
||||
$('img[name="globalBossImg"]').get(0).click();
|
||||
}
|
||||
}
|
||||
|
||||
function clickButton(text) {
|
||||
$('#popup span button:contains("' + text + '")').get(0).click();
|
||||
}
|
||||
|
||||
function clickSelector(selector) {
|
||||
$(selector).get(0).click();
|
||||
}
|
||||
|
||||
function botToggle() {
|
||||
if(botPaused) {
|
||||
console.log('Playing bot');
|
||||
botLoop = setInterval(mainLoop, 1000);
|
||||
botPaused = false;
|
||||
} else {
|
||||
console.log('Pausing bot');
|
||||
clearInterval(botLoop);
|
||||
botPaused = true;
|
||||
}
|
||||
}
|
||||
|
||||
function botToggleSlimes() {
|
||||
if(botBuySlimes) {
|
||||
console.log('Stopping slime purchases');
|
||||
botBuySlimes = false;
|
||||
} else {
|
||||
console.log('Starting slime purchases');
|
||||
botBuySlimes = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue