mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-10 12:02:59 +02:00
commit
821b44c389
3 changed files with 9 additions and 7 deletions
|
@ -229,8 +229,8 @@ export const actionsList = [
|
|||
'quantity': '(number) The quantity of the goal to set. Default is 1.'
|
||||
},
|
||||
perform: async function (agent, name=null, quantity=1) {
|
||||
if (!agent.npc.data) return 'NPC module is not loaded.';
|
||||
await agent.npc.setGoal(name, quantity);
|
||||
agent.bot.emit('idle'); // to trigger the goal
|
||||
return 'Set goal: ' + agent.npc.data.curr_goal.name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,6 @@ export class NPCContoller {
|
|||
}
|
||||
|
||||
init() {
|
||||
if (this.data === null) return;
|
||||
|
||||
for (let file of readdirSync('src/agent/npc/construction')) {
|
||||
if (file.endsWith('.json')) {
|
||||
try {
|
||||
|
@ -68,6 +66,7 @@ export class NPCContoller {
|
|||
}
|
||||
|
||||
this.agent.bot.on('idle', async () => {
|
||||
if (this.data.goals.length === 0 && !this.data.curr_goal) return;
|
||||
// Wait a while for inputs before acting independently
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
if (!this.agent.isIdle()) return;
|
||||
|
@ -81,12 +80,15 @@ export class NPCContoller {
|
|||
}
|
||||
|
||||
async setGoal(name=null, quantity=1) {
|
||||
this.data.curr_goal = null;
|
||||
this.last_goals = {};
|
||||
if (name) {
|
||||
this.data.curr_goal = {name: name, quantity: quantity};
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!this.data.do_set_goal) return;
|
||||
|
||||
let past_goals = {...this.last_goals};
|
||||
for (let goal in this.data.goals) {
|
||||
if (past_goals[goal.name] === undefined) past_goals[goal.name] = true;
|
||||
|
|
|
@ -4,8 +4,8 @@ export class NPCData {
|
|||
this.curr_goal = null;
|
||||
this.built = {};
|
||||
this.home = null;
|
||||
this.do_routine = true;
|
||||
this.do_set_goal = true;
|
||||
this.do_routine = false;
|
||||
this.do_set_goal = false;
|
||||
}
|
||||
|
||||
toObject() {
|
||||
|
@ -24,8 +24,8 @@ export class NPCData {
|
|||
}
|
||||
|
||||
static fromObject(obj) {
|
||||
if (!obj) return null;
|
||||
let npc = new NPCData();
|
||||
if (!obj) return npc;
|
||||
if (obj.goals) {
|
||||
npc.goals = [];
|
||||
for (let goal of obj.goals) {
|
||||
|
|
Loading…
Add table
Reference in a new issue