From e0bbd661dd7bf100c5f01fb9d916020ecdd4fae2 Mon Sep 17 00:00:00 2001 From: Ayush Maniar Date: Thu, 20 Mar 2025 12:56:29 -0700 Subject: [PATCH] Fixed validator not getting executed after agent exiting the world due to smelting, by clearing inventories in the end --- src/agent/tasks.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/agent/tasks.js b/src/agent/tasks.js index 141d1a4..0e2f8bb 100644 --- a/src/agent/tasks.js +++ b/src/agent/tasks.js @@ -126,25 +126,16 @@ class CookingCraftingTaskValidator { this.data = data; this.agent = agent; } - validate(has_initiated) { - if (has_initiated) { - - const result = checkItemPresence(this.data, this.agent); - let score = 0; - if (result.success) { - score = 1; - } - return { - "valid": result.success, - "score": score, - }; - } - else { - return { - "valid": false, - "score": 0 - }; + validate() { + const result = checkItemPresence(this.data, this.agent); + let score = 0; + if (result.success) { + score = 1; } + return { + "valid": result.success, + "score": score, + }; } } @@ -202,7 +193,6 @@ export class Task { this.name = this.agent.name; this.available_agents = settings.profiles.map((p) => JSON.parse(readFileSync(p, 'utf8')).name); - this.agent_initialized = false; } getAgentGoal() { @@ -213,7 +203,7 @@ export class Task { let add_string = ''; if (this.task_type === 'cooking') { - add_string = '\nIn the end, all the food items should be given to one single player.'; + add_string = '\nIn the end, all the food items should be given to one single bot.'; } // If goal is a string, all agents share the same goal @@ -254,8 +244,12 @@ export class Task { isDone() { let res = null; if (this.validator) - res = this.validator.validate(this.agent_initialized); + res = this.validator.validate(); if (res && res.valid) { + // Find all the agents and clear their inventories + for (let agent of this.available_agents) { + this.agent.bot.chat(`/clear ${agent}`); + } return {"message": 'Task successful', "score": res.score}; } let other_names = this.available_agents.filter(n => n !== this.name); @@ -326,8 +320,6 @@ export class Task { await new Promise((resolve) => setTimeout(resolve, 500)); } - this.agent_initialized = true; - if (this.initiator) { await this.initiator.init(); }