2015-04-13 21:59:56 -04:00
|
|
|
var botUsers = ['atomaka','greggnic'];
|
2015-04-08 21:06:27 -04:00
|
|
|
var botLoop;
|
2015-04-13 18:42:38 -04:00
|
|
|
var botGlobalBossTimer;
|
2015-04-08 21:06:27 -04:00
|
|
|
var botPaused = true;
|
|
|
|
var botPurchasing = false;
|
2015-04-09 13:14:00 -04:00
|
|
|
var botRaiding = false;
|
2015-04-08 21:06:27 -04:00
|
|
|
var botFightingRandomBoss = false;
|
|
|
|
var botFightingGlobalBoss = false;
|
|
|
|
var botBuySlimes = false;
|
2015-04-11 00:14:34 -04:00
|
|
|
var botFightGlobal = true;
|
2015-04-14 10:24:09 -04:00
|
|
|
var botFightRandom = true;
|
2015-04-09 13:14:00 -04:00
|
|
|
var botRaidTarget = null;
|
2015-04-14 10:09:27 -04:00
|
|
|
var botLastRandom = 0;
|
2015-04-14 10:28:12 -04:00
|
|
|
var botSleeping = false;
|
2015-04-08 21:06:27 -04:00
|
|
|
|
|
|
|
function mainLoop() {
|
|
|
|
if($('#popup').is(':visible')) {
|
|
|
|
var botPopupTitle = $('#popup p[name="title"]').text();
|
|
|
|
switch(botPopupTitle) {
|
|
|
|
case 'Raid report':
|
2015-04-09 11:06:34 -04:00
|
|
|
var botMessage = botBuildRaidReport($('#popup div[name="content"]').text());
|
2015-04-08 21:06:27 -04:00
|
|
|
console.log(botMessage);
|
|
|
|
clickButton('CONTINUE');
|
|
|
|
break;
|
|
|
|
case 'SUMMON BOSS':
|
|
|
|
clickButton('Summon Boss');
|
2015-04-13 19:15:31 -04:00
|
|
|
botLastRandom = botTimestamp();
|
2015-04-08 21:06:27 -04:00
|
|
|
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;
|
2015-04-09 13:14:00 -04:00
|
|
|
case 'Raid':
|
2015-04-09 14:06:34 -04:00
|
|
|
if(haveRaidTarget() === true) {
|
|
|
|
if(botRaiding) {
|
|
|
|
clickButton('Raid!');
|
|
|
|
botRaiding = false;
|
|
|
|
} else {
|
|
|
|
clickButton('Nevermind');
|
|
|
|
}
|
2015-04-09 13:14:00 -04:00
|
|
|
}
|
|
|
|
break;
|
2015-04-08 21:06:27 -04:00
|
|
|
case 'WHOOPS!':
|
|
|
|
case 'BATTLE REPORT':
|
|
|
|
case 'Battle Report':
|
|
|
|
case 'ACTIVITY PASSED!':
|
|
|
|
case 'SCENARIO #1':
|
2015-04-09 13:14:00 -04:00
|
|
|
case 'Lobby closed':
|
|
|
|
case 'Wait':
|
2015-04-13 20:09:38 -04:00
|
|
|
case 'ACTIVITY FAILED!':
|
2015-04-14 10:09:27 -04:00
|
|
|
case 'Game in progress':
|
2015-04-08 21:06:27 -04:00
|
|
|
clickButton('CONTINUE');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log('Unknown popup: ' + botPopupTitle);
|
|
|
|
break;
|
|
|
|
}
|
2015-04-13 18:42:38 -04:00
|
|
|
} else {
|
|
|
|
//RANDOM BOSS
|
2015-04-13 21:42:34 -04:00
|
|
|
if(randomBossRefreshing() === true && botFightingRandomBoss === true && botFightingGlobalBoss === false && haveSoldiers()) {
|
2015-04-13 18:42:38 -04:00
|
|
|
botFightingRandomBoss = false;
|
|
|
|
} else if(randomBossRefreshing() === false && botFightingRandomBoss === false) {
|
|
|
|
clickSelector('#randomBossPortal a');
|
|
|
|
botFightingRandomBoss = true;
|
2015-04-13 19:15:31 -04:00
|
|
|
} else if(botTimestamp() > botLastRandom + 180) {
|
|
|
|
clickSelector('#randomBossPortal a');
|
|
|
|
botFightingRandomBoss = true;
|
2015-04-13 18:42:38 -04:00
|
|
|
}
|
2015-04-08 21:06:27 -04:00
|
|
|
|
2015-04-13 18:42:38 -04:00
|
|
|
//GLOBAL BOSS
|
|
|
|
if(globalBossRefreshing() === true && botFightingGlobalBoss === true) {
|
|
|
|
clearInterval(botGlobalBossTimer);
|
|
|
|
botFightingGlobalBoss = false;
|
|
|
|
} else if(globalBossRefreshing() === false && botFightingGlobalBoss === false && botFightGlobal === true) {
|
|
|
|
clickSelector('span[name="timeRemaining"]:contains("JOIN") a');
|
|
|
|
botGlobalBossTimer = setInterval(fightGlobalBoss, 250);
|
|
|
|
botFightingGlobalBoss = true;
|
|
|
|
}
|
2015-04-08 21:06:27 -04:00
|
|
|
|
2015-04-13 18:42:38 -04:00
|
|
|
//ACTIVATE BUFFS
|
|
|
|
if(inactiveBuffs()) {
|
|
|
|
clickSelector('button:contains("Activate")');
|
|
|
|
}
|
2015-04-08 21:06:27 -04:00
|
|
|
|
2015-04-13 18:42:38 -04:00
|
|
|
//BUY SCIENTISTS
|
|
|
|
if(haveBossCoins() && haveCheapLabor()) {
|
|
|
|
botPurchasing = true;
|
|
|
|
clickSelector('button[name="hiremax_scientists"]');
|
|
|
|
}
|
2015-04-08 21:06:27 -04:00
|
|
|
|
2015-04-13 18:42:38 -04:00
|
|
|
//RAID
|
2015-04-14 10:24:09 -04:00
|
|
|
if(raidRefreshing() === false && haveRaidTarget() === true && botFightRandom === true) {
|
2015-04-13 18:42:38 -04:00
|
|
|
clickSelector('button[name="raid_button"]');
|
|
|
|
botFillIn('input[name="raid_user"]', botRaidTarget);
|
|
|
|
botRaiding = true;
|
|
|
|
}
|
2015-04-09 13:14:00 -04:00
|
|
|
|
2015-04-13 18:42:38 -04:00
|
|
|
//BUY SLIMES
|
|
|
|
if(botBuySlimes === true && haveTrillions(10) && botPurchasing === false) {
|
|
|
|
botPurchasing = true;
|
|
|
|
clickSelector('button[name="buymax-knight"]');
|
|
|
|
}
|
2015-04-08 21:06:27 -04:00
|
|
|
}
|
2015-04-06 17:01:14 -04:00
|
|
|
}
|
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
botToggle();
|
2015-04-06 17:30:55 -04:00
|
|
|
|
2015-04-13 21:42:34 -04:00
|
|
|
function haveSoldiers() {
|
|
|
|
if(convertToNumber($('tr[name="knight"] > .owned').text()) == 0) {
|
|
|
|
return false;
|
|
|
|
} else if(convertToNumber($('tr[name="advknight"] > .owned').text()) == 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 20:47:17 -04:00
|
|
|
function chatMonitor() {
|
|
|
|
$('#chatbox, #groupchatbox').bind('DOMSubtreeModified', function() {
|
|
|
|
var lastMessage = $(this).find('.chat-message').last();
|
|
|
|
if(chatIsPM(lastMessage) || chatHasName(lastMessage)) {
|
|
|
|
var user = lastMessage.find('.username').text().trim();
|
|
|
|
var content = lastMessage.find('.message').text().trim();
|
|
|
|
console.log('CHAT (' + user + '): ' + content);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function chatIsPM(message) {
|
|
|
|
return message.find('.chat-pm').length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function chatHasName(message) {
|
2015-04-13 21:59:56 -04:00
|
|
|
var string = message.find('.message').text();
|
|
|
|
return (new RegExp( '\\b' + botUsers.join('\\b|\\b') + '\\b')).test(string) === true;
|
2015-04-13 19:15:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function botTimestamp() {
|
|
|
|
return Math.floor(Date.now() / 1000);
|
|
|
|
}
|
|
|
|
|
2015-04-09 13:14:00 -04:00
|
|
|
function botFillIn(selector, text) {
|
|
|
|
$(selector).val(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
function raidRefreshing() {
|
2015-04-10 18:18:55 -04:00
|
|
|
if($('span[name="raidtime"]').css('display') == 'none') {
|
2015-04-09 13:14:00 -04:00
|
|
|
return false;
|
2015-04-10 18:20:38 -04:00
|
|
|
} else {
|
|
|
|
return true;
|
2015-04-09 13:14:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function haveRaidTarget() {
|
|
|
|
if(botRaidTarget == null) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
function botBuildRaidReport(message) {
|
2015-04-09 11:06:34 -04:00
|
|
|
var botRaidUser;
|
|
|
|
if(/You.? were raided by (.*?).? /.exec(message)) {
|
|
|
|
botRaidUser = /You.? were raided by (.*?).? /.exec(message)[1];
|
|
|
|
} else {
|
|
|
|
botRaidUser = /You .*? the raid against (.*?)! /.exec(message)[1];
|
|
|
|
}
|
|
|
|
var botRaidSoldiers = /! .*? lost (.*?) soldiers/.exec(message)[1];
|
2015-04-08 21:06:27 -04:00
|
|
|
var botRaidResult = (/won/.exec(message) !== null) ? 'won' : 'lost';
|
|
|
|
var botRaidStolen = (/steal (.*?) from/.exec(message) !== null) ? /steal (.*?) from/.exec(message)[1] : '$0';
|
|
|
|
|
2015-04-13 21:42:34 -04:00
|
|
|
return "RAIDED (" + botRaidUser + "): " + botRaidResult + "; soldiers: -" + botRaidSoldiers + "; " + botRaidResult + " money: " + botRaidStolen;
|
2015-04-08 21:06:27 -04:00
|
|
|
}
|
|
|
|
|
2015-04-13 19:53:48 -04:00
|
|
|
function haveTrillions(number) {
|
|
|
|
if(convertToNumber($('#money_display').text()) > trillions(number)) {
|
2015-04-08 21:06:27 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 19:53:48 -04:00
|
|
|
function convertToNumber(string) {
|
|
|
|
return Number(string.replace(/[^0-9\.]+/g, ''));
|
|
|
|
}
|
|
|
|
|
|
|
|
function trillions(number) {
|
|
|
|
return number * 1000000000000;
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 16:55:11 -04:00
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
function randomBossRefreshing() {
|
|
|
|
if($('span[name="timer"]').is(':visible')) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-07 13:42:08 -04:00
|
|
|
}
|
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
function globalBossRefreshing() {
|
|
|
|
if($('span[name="timeRemaining"]:contains("min"), span[name="timeRemaining"]:contains("sec")').length > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2015-04-06 17:30:55 -04:00
|
|
|
}
|
2015-04-07 13:42:08 -04:00
|
|
|
}
|
2015-04-07 15:19:27 -04:00
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
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();
|
2015-04-07 15:19:27 -04:00
|
|
|
}
|
2015-04-07 15:44:58 -04:00
|
|
|
|
2015-04-14 10:28:12 -04:00
|
|
|
function botSetTarget(username) {
|
|
|
|
botRaidTarget = username;
|
|
|
|
}
|
|
|
|
|
|
|
|
function botClearTarget() {
|
|
|
|
botRaidTarget = null;
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:06:27 -04:00
|
|
|
function botToggle() {
|
|
|
|
if(botPaused) {
|
|
|
|
console.log('Playing bot');
|
|
|
|
botLoop = setInterval(mainLoop, 1000);
|
2015-04-13 20:47:17 -04:00
|
|
|
chatMonitor();
|
2015-04-08 21:06:27 -04:00
|
|
|
botPaused = false;
|
|
|
|
} else {
|
|
|
|
console.log('Pausing bot');
|
|
|
|
clearInterval(botLoop);
|
2015-04-13 20:47:17 -04:00
|
|
|
$('#chatbox, #groupchatbox').unbind('DOMSubtreeModified');
|
2015-04-08 21:06:27 -04:00
|
|
|
botPaused = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function botToggleSlimes() {
|
|
|
|
if(botBuySlimes) {
|
|
|
|
console.log('Stopping slime purchases');
|
|
|
|
botBuySlimes = false;
|
|
|
|
} else {
|
|
|
|
console.log('Starting slime purchases');
|
|
|
|
botBuySlimes = true;
|
|
|
|
}
|
2015-04-07 15:44:58 -04:00
|
|
|
}
|
2015-04-09 13:14:00 -04:00
|
|
|
|
2015-04-11 00:14:34 -04:00
|
|
|
function botToggleGlobal() {
|
|
|
|
if(botFightGlobal) {
|
|
|
|
console.log('Stopping global fighting');
|
|
|
|
botFightGlobal = false;
|
|
|
|
} else {
|
|
|
|
console.log('Starting global fighting');
|
|
|
|
botFightGlobal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 10:24:09 -04:00
|
|
|
function botToggleRandom() {
|
|
|
|
if(botFightGlobal) {
|
|
|
|
console.log('Stopping random fighting');
|
|
|
|
botFightRandom = false;
|
|
|
|
} else {
|
|
|
|
console.log('Starting random fighting');
|
|
|
|
botFightRandom = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 20:47:17 -04:00
|
|
|
function botToggleUI() {
|
|
|
|
clickSelector('a[name="portal"]');
|
|
|
|
clickSelector('button[name="vault_hide"]');
|
|
|
|
$('a[name="bossPortal"] > img').toggle();
|
|
|
|
}
|
|
|
|
|
2015-04-14 10:28:12 -04:00
|
|
|
function botToggleSleep() {
|
|
|
|
if(botSleeping) {
|
|
|
|
botFightRandom = true;
|
|
|
|
botFightGlobal = true;
|
|
|
|
botSleeping = false;
|
|
|
|
} else {
|
|
|
|
botFightRandom = false;
|
|
|
|
botFightGlobal = false;
|
|
|
|
botBuySlimes = false;
|
|
|
|
botSleeping = true;
|
|
|
|
}
|
2015-04-09 13:14:00 -04:00
|
|
|
}
|
|
|
|
|
2015-04-14 10:32:51 -04:00
|
|
|
function botHelp() {
|
|
|
|
console.log('bt(): Toggle for the entire bot.');
|
|
|
|
console.log('bs(): Toggle "sleep mode." Disables all actions, but logs raids and chat.');
|
|
|
|
console.log('bts(): Toggle auto-slime purchasing.');
|
|
|
|
console.log('btu(): Toggle the UI (probably only works once).');
|
|
|
|
console.log('btg(): Toggle the global boss.');
|
|
|
|
console.log('btr(): Toggle the random boss.');
|
|
|
|
console.log('bst("username"): Set a target to raid every 5 minutes.');
|
|
|
|
console.log('bct(): Clear the raid target.');
|
|
|
|
}
|
|
|
|
|
2015-04-14 10:28:12 -04:00
|
|
|
function bt() { botToggle(); }
|
|
|
|
function bs() { botToggleSleep(); }
|
|
|
|
function bts() { botToggleSlimes(); }
|
|
|
|
function btu() { botToggleUI(); }
|
|
|
|
function btg() { botToggleGlobal(); }
|
|
|
|
function btr() { botToggleRandom(); }
|
|
|
|
function bst(username) { botSetTarget(username); }
|
|
|
|
function bct() { botClearTarget(); }
|