Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An auto-attack bot for BrowserQuest
/*!
* A bot for BrowserQuest(http://browserquest.mozilla.org/) that hooks the client to send auto-attack commands. Can be seen in
* action at https://gfycat.com/ifr/EcstaticHomelyEastrussiancoursinghounds
*
* Execute in the developer console after you load into the server with your player. Tested with Chrome.
*/
/*!
* Development was done on a modified version (https://github.com/nenuadrian/BrowserQuest) of BrowserQuest that fixed some
* dependency issues in the original version.
*
* It works by hooking the game's tick function and extracting out the Game class to the global level. To understand how this works,
* check out https://attilathedud.me/accessing-requirejs-modules-for-debugging/
*
* From the Game class we can call makePlayerAttack(enemy_entity) which triggers the client to create an attack link and start
* sending attack packets up to the server. It also sends the necessary movement packets. We use an event driven model to make the bot
* continue to acquire targets.
*/
var bot_info = {
'is_attacking': false,
'attacked_mob': undefined
}
require.s.contexts._.defined.game.prototype.tick = function () {
if (!window.game) {
window.game = this;
if (window.game) {
document.dispatchEvent(new Event('game_hooked'));
}
}
// Check to see if our previous target is dead and we need to acquire a new one
if (bot_info.is_attacking) {
if (bot_info.attacked_mob === undefined || bot_info.attacked_mob.isDead) {
bot_info.is_attacking = false;
bot_info.attacked_mob = undefined;
document.dispatchEvent(new Event('kill_mob'));
}
}
// The original function
this.currentTime = (new Date).getTime(), this.started && (this.updateCursorLogic(), this.updater.update(), this.renderer.renderFrame()), this.isStopped || requestAnimFrame(this.tick.bind(this))
}
document.addEventListener('game_hooked', function (e) {
// Quickly toggle invincibility to bring the invincible member to the global level so we can set it
window.game.player.startInvincibility();
window.game.player.stopInvincibility();
window.game.player.invincible = true;
document.addEventListener('kill_mob', function (e) {
window.game.forEachMob(function (entity) {
if (!bot_info.is_attacking) {
bot_info.is_attacking = true;
bot_info.attacked_mob = entity;
window.game.makePlayerAttack(bot_info.attacked_mob);
}
});
}, false);
document.dispatchEvent(new Event('kill_mob'));
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.