Last active
August 29, 2015 14:18
-
-
Save wtfaremyinitials/9029c4f716093dabe920 to your computer and use it in GitHub Desktop.
Example of my "Duties" API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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