Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Split task into Eat and CheckForFood #275
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens-tolboom committed Jul 11, 2016
1 parent c5a3af2 commit 865932d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions bot.user.js
Expand Up @@ -900,6 +900,23 @@ var scheduler = window.scheduler = (function() {
// TODO: checkCollision() needs refactoring; it should return but not set direction
}
},
{
id: 'Eat',
active: true,
description: 'Eat what is detected by CheckForFood',

getPriority: function () {
return 300;
},
execute: function () {
if (bot.currentFood) {
window.setAcceleration(bot.foodAccel());
}

window.goalCoordinates = bot.currentFood;
canvasUtil.setMouseCoordinates(canvasUtil.mapToMouse(window.goalCoordinates));
}
},
{
id: 'CheckForFood',
active: true,
Expand All @@ -913,22 +930,19 @@ var scheduler = window.scheduler = (function() {
getPriority: function () {
var currentPriority = this.priority;

if (bot.currentFood) {
window.setAcceleration(bot.foodAccel());
}

if (this.priority < this.triggerPriority) {
// Increment priority to trigger bot.computeFoodGoal
var step = (this.triggerPriority - this.startPriority) / bot.opt.targetFps * bot.opt.foodFrames;
return Math.round(this.priority + step);
}
else {
bot.computeFoodGoal();
}

return this.startPriority;
},
execute: function () {
bot.computeFoodGoal();
if (bot.currentFood) {
window.setAcceleration(bot.foodAccel());
}

window.goalCoordinates = bot.currentFood;
canvasUtil.setMouseCoordinates(canvasUtil.mapToMouse(window.goalCoordinates));
}
Expand Down

0 comments on commit 865932d

Please sign in to comment.