Skip to content

Instantly share code, notes, and snippets.

@ryepup
Created December 21, 2015 03:20
Show Gist options
  • Save ryepup/cd02d2aea38711377b53 to your computer and use it in GitHub Desktop.
Save ryepup/cd02d2aea38711377b53 to your computer and use it in GitHub Desktop.
function c2Bot(){
var self = this,
spells = {},
potions = [],
mouseUpEvent = new MouseEvent("mouseup", {
bubbles: true,
cancelable: true,
view: window
})
;
self.spells = spells;
self.potions = potions;
self.canCast = canCast;
self.cast = cast;
self.autoCast = autoCast;
self.drink = drink;
self.autoDrink = autoDrink;
self.close = close;
"shock web arrow firerain lightning fireball"
.split(' ')
.map(function(name, index){
spells[name] = document
.getElementById('scrollButtonCell' + index)
.firstChild;
});
for(var row = 0; row <= 3; row++){
for(var col = 0; col <= 1; col++){
var id = 'potionButton_Row' + row + '_Col' + col;
potions.push(document.getElementById(id).firstChild);
}
}
function canCast(spell) { return spell.className === 'scrollButton'; }
function cast(spell) {
if(canCast(spell)) {
spell.dispatchEvent(mouseUpEvent);
return true;
}
return false;
}
function autoCast() {
var delay = cast(spells.arrow) ? 300
: cast(spells.lightning) ? 250
: cast(spells.fireball) ? 500
: cast(spells.shock) ? 250
: cast(spells.firerain) ? 500
: cast(spells.web) ? 400
: 2000;
self.autoCastToken = setTimeout(autoCast, delay);
}
function drink(potion) { potion.dispatchEvent(mouseUpEvent); }
function autoDrink() {
potions.map(drink);
self.autoDrinkToken = setTimeout(autoDrink, 5000);
}
function close() {
clearTimeout(self.autoDrinkToken);
clearTimeout(self.autoCastToken);
}
}
// var bot = new c2Bot(); bot.autoDrink(); bot.autoCast();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment