rename task -> action

This commit is contained in:
JurassikLizard 2024-11-03 12:03:12 -05:00
parent 0896907224
commit 25a0f5c069
7 changed files with 67 additions and 68 deletions

View file

@ -1,23 +1,23 @@
export class TaskManager { export class ActionManager {
constructor(agent) { constructor(agent) {
this.agent = agent; this.agent = agent;
this.executing = false; this.executing = false;
this.currentTaskLabel = ''; this.currentActionLabel = '';
this.currentTaskFn = null; this.currentActionFn = null;
this.timedout = false; this.timedout = false;
this.resume_func = null; this.resume_func = null;
this.resume_name = ''; this.resume_name = '';
} }
async resumeTask(taskFn, timeout) { async resumeAction(actionFn, timeout) {
return this._executeResume(taskFn, timeout); return this._executeResume(actionFn, timeout);
} }
async runTask(taskLabel, taskFn, { timeout, resume = false } = {}) { async runAction(actionLabel, actionFn, { timeout, resume = false } = {}) {
if (resume) { if (resume) {
return this._executeResume(taskFn, timeout); return this._executeResume(actionFn, timeout);
} else { } else {
return this._executeTask(taskLabel, taskFn, timeout); return this._executeAction(actionLabel, actionFn, timeout);
} }
} }
@ -40,31 +40,31 @@ export class TaskManager {
this.resume_name = null; this.resume_name = null;
} }
async _executeResume(taskFn = null, timeout = 10) { async _executeResume(actionFn = null, timeout = 10) {
const new_resume = taskFn != null; const new_resume = actionFn != null;
if (new_resume) { // start new resume if (new_resume) { // start new resume
this.resume_func = taskFn; this.resume_func = actionFn;
this.resume_name = this.currentTaskLabel; this.resume_name = this.currentActionLabel;
} }
if (this.resume_func != null && this.agent.isIdle() && (!this.agent.self_prompter.on || new_resume)) { if (this.resume_func != null && this.agent.isIdle() && (!this.agent.self_prompter.on || new_resume)) {
this.currentTaskLabel = this.resume_name; this.currentActionLabel = this.resume_name;
let res = await this._executeTask(this.resume_name, this.resume_func, timeout); let res = await this._executeAction(this.resume_name, this.resume_func, timeout);
this.currentTaskLabel = ''; this.currentActionLabel = '';
return res; return res;
} else { } else {
return { success: false, message: null, interrupted: false, timedout: false }; return { success: false, message: null, interrupted: false, timedout: false };
} }
} }
async _executeTask(taskLabel, taskFn, timeout = 10) { async _executeAction(actionLabel, actionFn, timeout = 10) {
let TIMEOUT; let TIMEOUT;
try { try {
console.log('executing code...\n'); console.log('executing code...\n');
// await current task to finish (executing=false), with 10 seconds timeout // await current action to finish (executing=false), with 10 seconds timeout
// also tell agent.bot to stop various actions // also tell agent.bot to stop various actions
if (this.executing) { if (this.executing) {
console.log(`new task "${taskLabel}" trying to interrupt current task "${this.currentTaskLabel}"`); console.log(`new action "${actionLabel}" trying to interrupt current action "${this.currentActionLabel}"`);
} }
await this.stop(); await this.stop();
@ -72,21 +72,21 @@ export class TaskManager {
this.agent.clearBotLogs(); this.agent.clearBotLogs();
this.executing = true; this.executing = true;
this.currentTaskLabel = taskLabel; this.currentActionLabel = actionLabel;
this.currentTaskFn = taskFn; this.currentActionFn = actionFn;
// timeout in minutes // timeout in minutes
if (timeout > 0) { if (timeout > 0) {
TIMEOUT = this._startTimeout(timeout); TIMEOUT = this._startTimeout(timeout);
} }
// start the task // start the action
await taskFn(); await actionFn();
// mark task as finished + cleanup // mark action as finished + cleanup
this.executing = false; this.executing = false;
this.currentTaskLabel = ''; this.currentActionLabel = '';
this.currentTaskFn = null; this.currentActionFn = null;
clearTimeout(TIMEOUT); clearTimeout(TIMEOUT);
// get bot activity summary // get bot activity summary
@ -100,12 +100,12 @@ export class TaskManager {
this.agent.bot.emit('idle'); this.agent.bot.emit('idle');
} }
// return task status report // return action status report
return { success: true, message: output, interrupted, timedout }; return { success: true, message: output, interrupted, timedout };
} catch (err) { } catch (err) {
this.executing = false; this.executing = false;
this.currentTaskLabel = ''; this.currentActionLabel = '';
this.currentTaskFn = null; this.currentActionFn = null;
clearTimeout(TIMEOUT); clearTimeout(TIMEOUT);
this.cancelResume(); this.cancelResume();
console.error("Code execution triggered catch: " + err); console.error("Code execution triggered catch: " + err);

View file

@ -94,7 +94,7 @@ export class Coder {
async generateCode(agent_history) { async generateCode(agent_history) {
// wrapper to prevent overlapping code generation loops // wrapper to prevent overlapping code generation loops
await this.agent.tasks.stop(); await this.agent.actions.stop();
this.generating = true; this.generating = true;
let res = await this.generateCodeLoop(agent_history); let res = await this.generateCodeLoop(agent_history);
this.generating = false; this.generating = false;
@ -154,7 +154,7 @@ export class Coder {
return {success: false, message: null, interrupted: false, timedout: false}; return {success: false, message: null, interrupted: false, timedout: false};
} }
code_return = await this.agent.tasks.runTask('newAction', async () => { code_return = await this.agent.actions.runAction('newAction', async () => {
return await executionModuleExports.main(this.agent.bot); return await executionModuleExports.main(this.agent.bot);
}, { timeout: settings.code_timeout_mins }); }, { timeout: settings.code_timeout_mins });
if (code_return.interrupted && !code_return.timedout) if (code_return.interrupted && !code_return.timedout)

View file

@ -1,12 +1,12 @@
import * as skills from '../library/skills.js'; import * as skills from '../library/skills.js';
import settings from '../../../settings.js'; import settings from '../../../settings.js';
function runAsTask (taskLabel, taskFn, resume = false, timeout = -1) { function runAsAction (taskLabel, actionFn, resume = false, timeout = -1) {
return async function (agent, ...args) { return async function (agent, ...args) {
const taskFnWithAgent = async () => { const actionFnWithAgent = async () => {
await taskFn(agent, ...args); await actionFn(agent, ...args);
}; };
const code_return = await agent.tasks.runTask(`action:${taskLabel}`, taskFnWithAgent, { timeout, resume }); const code_return = await agent.actions.runAction(`action:${taskLabel}`, actionFnWithAgent, { timeout, resume });
if (code_return.interrupted && !code_return.timedout) if (code_return.interrupted && !code_return.timedout)
return; return;
return code_return.message; return code_return.message;
@ -31,9 +31,9 @@ export const actionsList = [
name: '!stop', name: '!stop',
description: 'Force stop all actions and commands that are currently executing.', description: 'Force stop all actions and commands that are currently executing.',
perform: async function (agent) { perform: async function (agent) {
await agent.tasks.stop(); await agent.actions.stop();
agent.clearBotLogs(); agent.clearBotLogs();
agent.tasks.cancelResume(); agent.actions.cancelResume();
agent.bot.emit('idle'); agent.bot.emit('idle');
let msg = 'Agent stopped.'; let msg = 'Agent stopped.';
if (agent.self_prompter.on) if (agent.self_prompter.on)
@ -73,7 +73,7 @@ export const actionsList = [
'player_name': {type: 'string', description: 'The name of the player to go to.'}, 'player_name': {type: 'string', description: 'The name of the player to go to.'},
'closeness': {type: 'float', description: 'How close to get to the player.', domain: [0, Infinity]} 'closeness': {type: 'float', description: 'How close to get to the player.', domain: [0, Infinity]}
}, },
perform: runAsTask('goToPlayer', async (agent, player_name, closeness) => { perform: runAsAction('goToPlayer', async (agent, player_name, closeness) => {
return await skills.goToPlayer(agent.bot, player_name, closeness); return await skills.goToPlayer(agent.bot, player_name, closeness);
}) })
}, },
@ -84,7 +84,7 @@ export const actionsList = [
'player_name': {type: 'string', description: 'name of the player to follow.'}, 'player_name': {type: 'string', description: 'name of the player to follow.'},
'follow_dist': {type: 'float', description: 'The distance to follow from.', domain: [0, Infinity]} 'follow_dist': {type: 'float', description: 'The distance to follow from.', domain: [0, Infinity]}
}, },
perform: runAsTask('followPlayer', async (agent, player_name, follow_dist) => { perform: runAsAction('followPlayer', async (agent, player_name, follow_dist) => {
await skills.followPlayer(agent.bot, player_name, follow_dist); await skills.followPlayer(agent.bot, player_name, follow_dist);
}, true) }, true)
}, },
@ -96,7 +96,7 @@ export const actionsList = [
'closeness': { type: 'float', description: 'How close to get to the block.', domain: [0, Infinity] }, 'closeness': { type: 'float', description: 'How close to get to the block.', domain: [0, Infinity] },
'search_range': { type: 'float', description: 'The distance to search for the block.', domain: [0, Infinity] } 'search_range': { type: 'float', description: 'The distance to search for the block.', domain: [0, Infinity] }
}, },
perform: runAsTask('goToBlock', async (agent, type, closeness, range) => { perform: runAsAction('goToBlock', async (agent, type, closeness, range) => {
await skills.goToNearestBlock(agent.bot, type, closeness, range); await skills.goToNearestBlock(agent.bot, type, closeness, range);
}) })
}, },
@ -104,7 +104,7 @@ export const actionsList = [
name: '!moveAway', name: '!moveAway',
description: 'Move away from the current location in any direction by a given distance.', description: 'Move away from the current location in any direction by a given distance.',
params: {'distance': { type: 'float', description: 'The distance to move away.', domain: [0, Infinity] }}, params: {'distance': { type: 'float', description: 'The distance to move away.', domain: [0, Infinity] }},
perform: runAsTask('moveAway', async (agent, distance) => { perform: runAsAction('moveAway', async (agent, distance) => {
await skills.moveAway(agent.bot, distance); await skills.moveAway(agent.bot, distance);
}) })
}, },
@ -122,7 +122,7 @@ export const actionsList = [
name: '!goToPlace', name: '!goToPlace',
description: 'Go to a saved location.', description: 'Go to a saved location.',
params: {'name': { type: 'string', description: 'The name of the location to go to.' }}, params: {'name': { type: 'string', description: 'The name of the location to go to.' }},
perform: runAsTask('goToPlace', async (agent, name) => { perform: runAsAction('goToPlace', async (agent, name) => {
const pos = agent.memory_bank.recallPlace(name); const pos = agent.memory_bank.recallPlace(name);
if (!pos) { if (!pos) {
skills.log(agent.bot, `No location named "${name}" saved.`); skills.log(agent.bot, `No location named "${name}" saved.`);
@ -139,7 +139,7 @@ export const actionsList = [
'item_name': { type: 'ItemName', description: 'The name of the item to give.' }, 'item_name': { type: 'ItemName', description: 'The name of the item to give.' },
'num': { type: 'int', description: 'The number of items to give.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of items to give.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('givePlayer', async (agent, player_name, item_name, num) => { perform: runAsAction('givePlayer', async (agent, player_name, item_name, num) => {
await skills.giveToPlayer(agent.bot, item_name, player_name, num); await skills.giveToPlayer(agent.bot, item_name, player_name, num);
}) })
}, },
@ -147,7 +147,7 @@ export const actionsList = [
name: '!consume', name: '!consume',
description: 'Eat/drink the given item.', description: 'Eat/drink the given item.',
params: {'item_name': { type: 'ItemName', description: 'The name of the item to consume.' }}, params: {'item_name': { type: 'ItemName', description: 'The name of the item to consume.' }},
perform: runAsTask('consume', async (agent, item_name) => { perform: runAsAction('consume', async (agent, item_name) => {
await agent.bot.consume(item_name); await agent.bot.consume(item_name);
skills.log(agent.bot, `Consumed ${item_name}.`); skills.log(agent.bot, `Consumed ${item_name}.`);
}) })
@ -156,7 +156,7 @@ export const actionsList = [
name: '!equip', name: '!equip',
description: 'Equip the given item.', description: 'Equip the given item.',
params: {'item_name': { type: 'ItemName', description: 'The name of the item to equip.' }}, params: {'item_name': { type: 'ItemName', description: 'The name of the item to equip.' }},
perform: runAsTask('equip', async (agent, item_name) => { perform: runAsAction('equip', async (agent, item_name) => {
await skills.equip(agent.bot, item_name); await skills.equip(agent.bot, item_name);
}) })
}, },
@ -167,7 +167,7 @@ export const actionsList = [
'item_name': { type: 'ItemName', description: 'The name of the item to put in the chest.' }, 'item_name': { type: 'ItemName', description: 'The name of the item to put in the chest.' },
'num': { type: 'int', description: 'The number of items to put in the chest.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of items to put in the chest.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('putInChest', async (agent, item_name, num) => { perform: runAsAction('putInChest', async (agent, item_name, num) => {
await skills.putInChest(agent.bot, item_name, num); await skills.putInChest(agent.bot, item_name, num);
}) })
}, },
@ -178,7 +178,7 @@ export const actionsList = [
'item_name': { type: 'ItemName', description: 'The name of the item to take.' }, 'item_name': { type: 'ItemName', description: 'The name of the item to take.' },
'num': { type: 'int', description: 'The number of items to take.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of items to take.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('takeFromChest', async (agent, item_name, num) => { perform: runAsAction('takeFromChest', async (agent, item_name, num) => {
await skills.takeFromChest(agent.bot, item_name, num); await skills.takeFromChest(agent.bot, item_name, num);
}) })
}, },
@ -186,7 +186,7 @@ export const actionsList = [
name: '!viewChest', name: '!viewChest',
description: 'View the items/counts of the nearest chest.', description: 'View the items/counts of the nearest chest.',
params: { }, params: { },
perform: runAsTask('viewChest', async (agent) => { perform: runAsAction('viewChest', async (agent) => {
await skills.viewChest(agent.bot); await skills.viewChest(agent.bot);
}) })
}, },
@ -197,7 +197,7 @@ export const actionsList = [
'item_name': { type: 'ItemName', description: 'The name of the item to discard.' }, 'item_name': { type: 'ItemName', description: 'The name of the item to discard.' },
'num': { type: 'int', description: 'The number of items to discard.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of items to discard.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('discard', async (agent, item_name, num) => { perform: runAsAction('discard', async (agent, item_name, num) => {
const start_loc = agent.bot.entity.position; const start_loc = agent.bot.entity.position;
await skills.moveAway(agent.bot, 5); await skills.moveAway(agent.bot, 5);
await skills.discard(agent.bot, item_name, num); await skills.discard(agent.bot, item_name, num);
@ -211,7 +211,7 @@ export const actionsList = [
'type': { type: 'BlockName', description: 'The block type to collect.' }, 'type': { type: 'BlockName', description: 'The block type to collect.' },
'num': { type: 'int', description: 'The number of blocks to collect.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of blocks to collect.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('collectBlocks', async (agent, type, num) => { perform: runAsAction('collectBlocks', async (agent, type, num) => {
await skills.collectBlock(agent.bot, type, num); await skills.collectBlock(agent.bot, type, num);
}, false, 10) // 10 minute timeout }, false, 10) // 10 minute timeout
}, },
@ -221,7 +221,7 @@ export const actionsList = [
params: { params: {
'type': { type: 'BlockName', description: 'The block type to collect.' } 'type': { type: 'BlockName', description: 'The block type to collect.' }
}, },
perform: runAsTask('collectAllBlocks', async (agent, type) => { perform: runAsAction('collectAllBlocks', async (agent, type) => {
let success = await skills.collectBlock(agent.bot, type, 1); let success = await skills.collectBlock(agent.bot, type, 1);
if (!success) if (!success)
agent.tasks.cancelResume(); agent.tasks.cancelResume();
@ -234,7 +234,7 @@ export const actionsList = [
'recipe_name': { type: 'ItemName', description: 'The name of the output item to craft.' }, 'recipe_name': { type: 'ItemName', description: 'The name of the output item to craft.' },
'num': { type: 'int', description: 'The number of times to craft the recipe. This is NOT the number of output items, as it may craft many more items depending on the recipe.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of times to craft the recipe. This is NOT the number of output items, as it may craft many more items depending on the recipe.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('craftRecipe', async (agent, recipe_name, num) => { perform: runAsAction('craftRecipe', async (agent, recipe_name, num) => {
await skills.craftRecipe(agent.bot, recipe_name, num); await skills.craftRecipe(agent.bot, recipe_name, num);
}) })
}, },
@ -245,7 +245,7 @@ export const actionsList = [
'item_name': { type: 'ItemName', description: 'The name of the input item to smelt.' }, 'item_name': { type: 'ItemName', description: 'The name of the input item to smelt.' },
'num': { type: 'int', description: 'The number of times to smelt the item.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of times to smelt the item.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsTask('smeltItem', async (agent, item_name, num) => { perform: runAsAction('smeltItem', async (agent, item_name, num) => {
let response = await skills.smeltItem(agent.bot, item_name, num); let response = await skills.smeltItem(agent.bot, item_name, num);
if (response.indexOf('Successfully') !== -1) { if (response.indexOf('Successfully') !== -1) {
// there is a bug where the bot's inventory is not updated after smelting // there is a bug where the bot's inventory is not updated after smelting
@ -258,9 +258,8 @@ export const actionsList = [
{ {
name: '!clearFurnace', name: '!clearFurnace',
description: 'Take all items out of the nearest furnace.', description: 'Take all items out of the nearest furnace.',
description: 'Take all items out of the nearest furnace.',
params: { }, params: { },
perform: runAsTask('clearFurnace', async (agent) => { perform: runAsAction('clearFurnace', async (agent) => {
await skills.clearNearestFurnace(agent.bot); await skills.clearNearestFurnace(agent.bot);
}) })
}, },
@ -268,7 +267,7 @@ export const actionsList = [
name: '!placeHere', name: '!placeHere',
description: 'Place a given block in the current location. Do NOT use to build structures, only use for single blocks/torches.', description: 'Place a given block in the current location. Do NOT use to build structures, only use for single blocks/torches.',
params: {'type': { type: 'BlockName', description: 'The block type to place.' }}, params: {'type': { type: 'BlockName', description: 'The block type to place.' }},
perform: runAsTask('placeHere', async (agent, type) => { perform: runAsAction('placeHere', async (agent, type) => {
let pos = agent.bot.entity.position; let pos = agent.bot.entity.position;
await skills.placeBlock(agent.bot, type, pos.x, pos.y, pos.z); await skills.placeBlock(agent.bot, type, pos.x, pos.y, pos.z);
}) })
@ -277,14 +276,14 @@ export const actionsList = [
name: '!attack', name: '!attack',
description: 'Attack and kill the nearest entity of a given type.', description: 'Attack and kill the nearest entity of a given type.',
params: {'type': { type: 'string', description: 'The type of entity to attack.'}}, params: {'type': { type: 'string', description: 'The type of entity to attack.'}},
perform: runAsTask('attack', async (agent, type) => { perform: runAsAction('attack', async (agent, type) => {
await skills.attackNearest(agent.bot, type, true); await skills.attackNearest(agent.bot, type, true);
}) })
}, },
{ {
name: '!goToBed', name: '!goToBed',
description: 'Go to the nearest bed and sleep.', description: 'Go to the nearest bed and sleep.',
perform: runAsTask('goToBed', async (agent) => { perform: runAsAction('goToBed', async (agent) => {
await skills.goToBed(agent.bot); await skills.goToBed(agent.bot);
}) })
}, },
@ -292,7 +291,7 @@ export const actionsList = [
name: '!activate', name: '!activate',
description: 'Activate the nearest object of a given type.', description: 'Activate the nearest object of a given type.',
params: {'type': { type: 'BlockName', description: 'The type of object to activate.' }}, params: {'type': { type: 'BlockName', description: 'The type of object to activate.' }},
perform: runAsTask('activate', async (agent, type) => { perform: runAsAction('activate', async (agent, type) => {
await skills.activateNearestBlock(agent.bot, type); await skills.activateNearestBlock(agent.bot, type);
}) })
}, },
@ -300,7 +299,7 @@ export const actionsList = [
name: '!stay', name: '!stay',
description: 'Stay in the current location no matter what. Pauses all modes.', description: 'Stay in the current location no matter what. Pauses all modes.',
params: {'type': { type: 'int', description: 'The number of seconds to stay. -1 for forever.', domain: [-1, Number.MAX_SAFE_INTEGER] }}, params: {'type': { type: 'int', description: 'The number of seconds to stay. -1 for forever.', domain: [-1, Number.MAX_SAFE_INTEGER] }},
perform: runAsTask('stay', async (agent, seconds) => { perform: runAsAction('stay', async (agent, seconds) => {
await skills.stay(agent.bot, seconds); await skills.stay(agent.bot, seconds);
}) })
}, },

View file

@ -260,7 +260,7 @@ async function execute(mode, agent, func, timeout=-1) {
if (agent.self_prompter.on) if (agent.self_prompter.on)
agent.self_prompter.stopLoop(); agent.self_prompter.stopLoop();
mode.active = true; mode.active = true;
let code_return = await agent.tasks.runTask(`mode:${mode.name}`, async () => { let code_return = await agent.actions.runAction(`mode:${mode.name}`, async () => {
await func(); await func();
}, { timeout }); }, { timeout });
mode.active = false; mode.active = false;
@ -328,7 +328,7 @@ class ModeController {
this.unPauseAll(); this.unPauseAll();
} }
for (let mode of this.modes_list) { for (let mode of this.modes_list) {
let interruptible = mode.interrupts.some(i => i === 'all') || mode.interrupts.some(i => `action:${i}` === this.agent.tasks.currentTaskLabel); let interruptible = mode.interrupts.some(i => i === 'all') || mode.interrupts.some(i => `action:${i}` === this.agent.actions.currentActionLabel);
if (mode.on && !mode.paused && !mode.active && (this.agent.isIdle() || interruptible)) { if (mode.on && !mode.paused && !mode.active && (this.agent.isIdle() || interruptible)) {
await mode.update(this.agent); await mode.update(this.agent);
} }

View file

@ -13,7 +13,7 @@ export class BuildGoal {
async wrapSkill(func) { async wrapSkill(func) {
if (!this.agent.isIdle()) if (!this.agent.isIdle())
return false; return false;
let res = await this.agent.tasks.runTask('BuildGoal', func); let res = await this.agent.actions.runAction('BuildGoal', func);
return !res.interrupted; return !res.interrupted;
} }

View file

@ -72,7 +72,7 @@ export class NPCContoller {
if (!this.agent.isIdle()) return; if (!this.agent.isIdle()) return;
// Persue goal // Persue goal
if (!this.agent.tasks.resume_func) { if (!this.agent.actions.resume_func) {
this.executeNext(); this.executeNext();
this.agent.history.save(); this.agent.history.save();
} }
@ -104,7 +104,7 @@ export class NPCContoller {
async executeNext() { async executeNext() {
if (!this.agent.isIdle()) return; if (!this.agent.isIdle()) return;
await this.agent.tasks.runTask('npc:moveAway', async () => { await this.agent.actions.runAction('npc:moveAway', async () => {
await skills.moveAway(this.agent.bot, 2); await skills.moveAway(this.agent.bot, 2);
}); });
@ -114,7 +114,7 @@ export class NPCContoller {
if (building == this.data.home) { if (building == this.data.home) {
let door_pos = this.getBuildingDoor(building); let door_pos = this.getBuildingDoor(building);
if (door_pos) { if (door_pos) {
await this.agent.tasks.runTask('npc:exitBuilding', async () => { await this.agent.actions.runAction('npc:exitBuilding', async () => {
await skills.useDoor(this.agent.bot, door_pos); await skills.useDoor(this.agent.bot, door_pos);
await skills.moveAway(this.agent.bot, 2); // If the bot is too close to the building it will try to enter again await skills.moveAway(this.agent.bot, 2); // If the bot is too close to the building it will try to enter again
}); });
@ -132,13 +132,13 @@ export class NPCContoller {
let building = this.currentBuilding(); let building = this.currentBuilding();
if (this.data.home !== null && (building === null || building != this.data.home)) { if (this.data.home !== null && (building === null || building != this.data.home)) {
let door_pos = this.getBuildingDoor(this.data.home); let door_pos = this.getBuildingDoor(this.data.home);
await this.agent.tasks.runTask('npc:returnHome', async () => { await this.agent.actions.runAction('npc:returnHome', async () => {
await skills.useDoor(this.agent.bot, door_pos); await skills.useDoor(this.agent.bot, door_pos);
}); });
} }
// Go to bed // Go to bed
await this.agent.tasks.runTask('npc:bed', async () => { await this.agent.actions.runAction('npc:bed', async () => {
await skills.goToBed(this.agent.bot); await skills.goToBed(this.agent.bot);
}); });
} }

View file

@ -87,7 +87,7 @@ export class SelfPrompter {
async stop(stop_action=true) { async stop(stop_action=true) {
this.interrupt = true; this.interrupt = true;
if (stop_action) if (stop_action)
await this.agent.tasks.stop(); await this.agent.actions.stop();
await this.stopLoop(); await this.stopLoop();
this.on = false; this.on = false;
} }