Skip to content

Instantly share code, notes, and snippets.

@wtfaremyinitials
Last active August 29, 2015 14:18
Show Gist options
  • Save wtfaremyinitials/9029c4f716093dabe920 to your computer and use it in GitHub Desktop.
Save wtfaremyinitials/9029c4f716093dabe920 to your computer and use it in GitHub Desktop.
Example of my "Duties" API
var Duties = require('./index.js');
var main = new Duties();
var bot = new Bot(); // stub for other bot related code
var MiningTask = function* MiningTask(d, config) {
while(true) {
var block = bot.findBlockToBreak();
d.add(NavigateTask, block.location);
d.add(BreakBlockTask, block);
yield {};
}
};
var NavigateTask = function* NavigateTask(d, location) {
bot.navigate(location, d.resume);
yield d.suspend();
};
var BreakBlockTask = function* BreakBlockTask(d, block) {
bot.breakBlock(block, d.resume);
yield d.suspend();
};
var ExecuteTask = function* ExecuteTask(d, target) {
while(!target.dead) {
bot.attack(target, d.resume)
yield d.suspend();
}
};
main.add(MiningTask, {});
bot.on('threatDetected', function(threat) {
main.add(ExecuteTask, threat);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment