Skip to content

Instantly share code, notes, and snippets.

@maritz
Created March 14, 2012 22:47
Show Gist options
  • Save maritz/2040172 to your computer and use it in GitHub Desktop.
Save maritz/2040172 to your computer and use it in GitHub Desktop.
var good_char_min_stat_threshold = 0;
var good_char_max_stat_threshold = 25;
var enemy_easy_peasy_multiplier = 1.75; // if you get a 25 stat char and set this to 1.8 your char will be too much of a pussy to fight anything and just endlessly explore the sewer. if that's up your alley, go ahead.
var max_fps = 10;
var visit_amounts_to_assume_encountered_all = 15;
var pause = false;
(function () {
var encountered_enemies = [];
var banned_enemies = [];
var area_visits = 0;
var body_counter = 0;
var start_stats = 0;
var mainLoop = function () {
var loop_start = +new Date();
var $area = $('body > div').filter(':visible').get(1);
if ($area.id === "Area1") {
inventRidiculousName();
roll();
if (checkCharIsGood($area)) {
confirmChar();
}
} else {
explore();
area_visits++;
if (enemyIsEasyPeasy($area) && ! enemyIsBanned()) {
fightTillDeath();
banIfNoExperience();
if ( ! stillAlive()) {
restart();
}
}
if (doYouWannaGoToTheNextArea('?')) {
if ( ! wellThenGoAlready($area) ) {
wowYouBeatTheGame();
}
}
}
if ( ! pause) {
var loop_time = +new Date()-loop_start;
var time_until_nex_loop = 1000/max_fps - loop_time;
setTimeout(mainLoop, time_until_nex_loop);
}
};
var inventRidiculousName = function () {
$('#nameInput').val('Horrd Brork '+body_counter);
};
var roll = function () {
$('#rollButs button:eq(0)').click();
};
var getCombinedStats = function ($elements) {
var combined_stats = 0;
$elements.each(function() {
combined_stats += parseInt($(this).find('td:eq(1)').text(), 10);
});
return combined_stats;
};
var getPlayerStats = function ($context) {
return getCombinedStats($('#divShowPlayer tr', $context).slice(3,7));
};
var getPlayerHealth = function ($context) {
return getCombinedStats($('#divShowPlayer tr', $context).slice(2,3));
};
var getEnemyName = function () {
return $('#divShowEnemy tr').slice(1,2).find('td:eq(1)').text().replace(/^(.*)[\s]\([\d]+\)$/, "$1");
};
var getEnemyStats = function () {
return getCombinedStats($('#divShowEnemy tr').slice(3,5));
};
var getEnemyHealth = function () {
return getCombinedStats($('#divShowEnemy tr').slice(2,3));
};
var checkCharIsGood = function ($context) {
var stats = getPlayerStats($context);
return stats >= good_char_min_stat_threshold && stats <= good_char_max_stat_threshold;
};
var confirmChar = function () {
start_stats = getPlayerStats();
$('#rollButs button:eq(1)').click();
};
var explore = function () {
$('#divEncButs button').click();
var enemy_name = getEnemyName();
if (enemy_name && encountered_enemies.indexOf(enemy_name) === -1) {
encountered_enemies.push(enemy_name);
}
};
var enemyIsEasyPeasy = function ($context) {
return getPlayerStats($context)+getPlayerHealth($context) > (getEnemyStats()+(getEnemyHealth()/3))*enemy_easy_peasy_multiplier;
};
var enemyIsBanned = function () {
return banned_enemies.indexOf(getEnemyName()) !== -1;
};
var fightTillDeath = function () {
var $attack_button;
$attack_button = $('#divAttButs button').get(0);
while ($attack_button) {
$attack_button.click();
$attack_button = $('#divAttButs button').get(0);
}
};
var banIfNoExperience = function () {
if ($('#divShowBattle div.cgray').text() === "You're too classy to gain from this enemy...") {
var enemy_name = $('#divShowBattle div.cblue').last().text().replace(/You defeated the (.*)\!$/, "$1");
banned_enemies.push(enemy_name);
}
};
var stillAlive = function () {
return getPlayerHealth() > 0;
};
var restart = function () {
body_counter++;
banned_enemies = [];
encountered_enemies = [];
start_stats = 0;
$('#divEncButs button').click();
};
var doYouWannaGoToTheNextArea = function () {
if (area_visits >= visit_amounts_to_assume_encountered_all) {
if (banned_enemies.length >= encountered_enemies.length) {
return true;
}
}
return false;
};
var wellThenGoAlready = function ($current_area) {
area_visits = 0;
var $next = $('.navSelected', $current_area).next();
if ($next.length) {
$next.children('a').click();
return true;
} else {
return false;
}
};
var wowYouBeatTheGame = function () {
pause = true;
alert('You won! And you only died '+body_counter+' times. Grats! You had combined start stats of '+start_stats+'.');
};
mainLoop();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment