wandering for goal, and tool goal fix

This commit is contained in:
Kolby Nottingham 2024-02-27 14:45:47 -08:00
parent 16c8192872
commit 214999df2f
2 changed files with 26 additions and 7 deletions

View file

@ -175,8 +175,15 @@ export class Agent {
}
});
this.bot.on('idle', () => {
this.bot.on('idle', async () => {
// Resume all paused modes
this.bot.modes.unPauseAll();
// Wait a while for inputs before acting independently
await new Promise((resolve) => setTimeout(resolve, 2000));
if (!this.isIdle()) return;
// Resume behavior or persue goal
if (this.coder.resume_func != null)
this.coder.executeResume();
else

View file

@ -309,6 +309,7 @@ export class ItemGoal {
this.timeout = timeout;
this.goals = [];
this.nodes = {};
this.failed = [];
}
setGoals(goals) {
@ -321,11 +322,10 @@ export class ItemGoal {
async executeNext() {
// Get goal by priority
let goal = null;
let inventory = world.getInventoryCounts(this.agent.bot);
for (let g of this.goals) {
if (inventory[g.name] === undefined || inventory[g.name] < g.quantity) {
if (this.nodes[g.name] === undefined)
this.nodes[g.name] = new ItemWrapper(this, null, g.name);
if (!this.nodes[g.name].isDone(g.quantity)) {
goal = this.nodes[g.name];
break;
}
@ -342,8 +342,20 @@ export class ItemGoal {
if (next.type === 'block' && !world.getNearbyBlockTypes(this.agent.bot).includes(next.source) ||
next.type === 'hunt' && !world.getNearbyEntityTypes(this.agent.bot).includes(next.source)) {
next.fails += 1;
// If the bot has failed to obtain the block before, explore
if (this.failed.includes(next.name)) {
this.failed = this.failed.filter((item) => item !== next.name);
this.agent.coder.interruptible = true;
await this.agent.coder.execute(async () => {
await skills.moveAway(this.agent.bot, 8);
}, this.timeout);
this.agent.coder.interruptible = false;
} else {
this.failed.push(next.name);
await new Promise((resolve) => setTimeout(resolve, 500));
this.agent.bot.emit('idle');
}
return;
}