mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-04 06:15:32 +02:00
goal quantity
This commit is contained in:
parent
24965b2e06
commit
6571b3c87b
4 changed files with 47 additions and 31 deletions
|
@ -32,7 +32,7 @@ export class BuildGoal {
|
||||||
}
|
}
|
||||||
|
|
||||||
let inventory = world.getInventoryCounts(this.agent.bot);
|
let inventory = world.getInventoryCounts(this.agent.bot);
|
||||||
let missing = [];
|
let missing = {};
|
||||||
let acted = false;
|
let acted = false;
|
||||||
for (let y = goal.offset; y < sizey+goal.offset; y++) {
|
for (let y = goal.offset; y < sizey+goal.offset; y++) {
|
||||||
for (let z = 0; z < sizez; z++) {
|
for (let z = 0; z < sizez; z++) {
|
||||||
|
@ -70,7 +70,9 @@ export class BuildGoal {
|
||||||
return {missing: missing, acted: acted, position: position, orientation: orientation};
|
return {missing: missing, acted: acted, position: position, orientation: orientation};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
missing.push(block_typed);
|
if (missing[block_typed] === undefined)
|
||||||
|
missing[block_typed] = 0;
|
||||||
|
missing[block_typed]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,38 +40,43 @@ export class NPCContoller {
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeNext() {
|
async executeNext() {
|
||||||
let goals = this.data.goals;
|
// If we need more blocks to complete a building, get those first
|
||||||
if (this.temp_goals !== null && this.temp_goals.length > 0) {
|
let goals = this.temp_goals.concat(this.data.goals);
|
||||||
goals = this.temp_goals.concat(goals);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let goal of goals) {
|
for (let goal of goals) {
|
||||||
if (this.constructions[goal] === undefined) {
|
|
||||||
let quantity = 0;
|
// Obtain goal item or block
|
||||||
for (let item of goals) {
|
if (this.constructions[goal.name] === undefined) {
|
||||||
if (item === goal) quantity++;
|
if (!itemSatisfied(this.agent.bot, goal.name, goal.quantity)) {
|
||||||
}
|
await this.item_goal.executeNext(goal.name, goal.quantity);
|
||||||
if (!itemSatisfied(this.agent.bot, goal, quantity)) {
|
|
||||||
await this.item_goal.executeNext(goal);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// Build construction goal
|
||||||
|
else {
|
||||||
let res = null;
|
let res = null;
|
||||||
if (this.data.built.hasOwnProperty(goal)) {
|
if (this.data.built.hasOwnProperty(goal.name)) {
|
||||||
res = await this.build_goal.executeNext(
|
res = await this.build_goal.executeNext(
|
||||||
this.constructions[goal],
|
this.constructions[goal.name],
|
||||||
this.data.built[goal].position,
|
this.data.built[goal.name].position,
|
||||||
this.data.built[goal].orientation
|
this.data.built[goal.name].orientation
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
res = await this.build_goal.executeNext(this.constructions[goal]);
|
res = await this.build_goal.executeNext(this.constructions[goal.name]);
|
||||||
this.data.built[goal] = {
|
this.data.built[goal.name] = {
|
||||||
name: goal,
|
name: goal.name,
|
||||||
position: res.position,
|
position: res.position,
|
||||||
orientation: res.orientation
|
orientation: res.orientation
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
this.temp_goals = res.missing;
|
this.temp_goals = [];
|
||||||
|
for (let block_name in res.missing) {
|
||||||
|
this.temp_goals.push({
|
||||||
|
name: block_name,
|
||||||
|
quantity: res.missing[block_name]
|
||||||
|
})
|
||||||
|
}
|
||||||
if (res.acted) break;
|
if (res.acted) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,26 @@ export class NPCData {
|
||||||
}
|
}
|
||||||
|
|
||||||
toObject() {
|
toObject() {
|
||||||
return {
|
let obj = {};
|
||||||
goals: this.goals,
|
if (this.goals.length > 0)
|
||||||
built: this.built
|
obj.goals = this.goals;
|
||||||
}
|
if (Object.keys(this.built).length > 0)
|
||||||
|
obj.built = this.built;
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromObject(obj) {
|
static fromObject(obj) {
|
||||||
if (!obj) return null;
|
if (!obj) return null;
|
||||||
let npc = new NPCData();
|
let npc = new NPCData();
|
||||||
if (obj.goals)
|
if (obj.goals) {
|
||||||
npc.goals = obj.goals;
|
npc.goals = [];
|
||||||
|
for (let goal of obj.goals) {
|
||||||
|
if (typeof goal === 'string')
|
||||||
|
npc.goals.push({name: goal, quantity: 1});
|
||||||
|
else
|
||||||
|
npc.goals.push({name: goal.name, quantity: goal.quantity});
|
||||||
|
}
|
||||||
|
}
|
||||||
if (obj.built)
|
if (obj.built)
|
||||||
npc.built = obj.built;
|
npc.built = obj.built;
|
||||||
return npc;
|
return npc;
|
||||||
|
|
|
@ -160,7 +160,7 @@ class ItemNode {
|
||||||
} else if (this.type === 'hunt') {
|
} else if (this.type === 'hunt') {
|
||||||
for (let i=0; i<quantity; i++) {
|
for (let i=0; i<quantity; i++) {
|
||||||
res = await skills.attackNearest(this.manager.agent.bot, this.source);
|
res = await skills.attackNearest(this.manager.agent.bot, this.source);
|
||||||
if (!res)
|
if (!res || this.manager.agent.bot.interrupt_code)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (this.type === 'craft') {
|
} else if (this.type === 'craft') {
|
||||||
|
@ -285,13 +285,13 @@ export class ItemGoal {
|
||||||
this.failed = [];
|
this.failed = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeNext(item_name) {
|
async executeNext(item_name, item_quantity=1) {
|
||||||
if (this.nodes[item_name] === undefined)
|
if (this.nodes[item_name] === undefined)
|
||||||
this.nodes[item_name] = new ItemWrapper(this, null, item_name);
|
this.nodes[item_name] = new ItemWrapper(this, null, item_name);
|
||||||
this.goal = this.nodes[item_name];
|
this.goal = this.nodes[item_name];
|
||||||
|
|
||||||
// Get next goal to execute
|
// Get next goal to execute
|
||||||
let next_info = this.goal.getNext();
|
let next_info = this.goal.getNext(item_quantity);
|
||||||
if (!next_info) {
|
if (!next_info) {
|
||||||
console.log(`Invalid item goal ${this.goal.name}`);
|
console.log(`Invalid item goal ${this.goal.name}`);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue