mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-06-08 18:25:54 +02:00
improved elbow_room
This commit is contained in:
parent
210843a0ad
commit
53c02c55ee
2 changed files with 8 additions and 19 deletions
|
@ -1064,21 +1064,6 @@ export async function moveAway(bot, distance) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function moveAwayFrom(bot, entity, distance=1) {
|
|
||||||
const follow = new pf.goals.GoalFollow(entity, distance+1);
|
|
||||||
const inverted_goal = new pf.goals.GoalInvert(follow);
|
|
||||||
bot.pathfinder.setMovements(new pf.Movements(bot));
|
|
||||||
bot.pathfinder.setGoal(inverted_goal, true);
|
|
||||||
for (let i = 0; i < 10*distance; i++) {
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
|
||||||
if (bot.interrupt_code)
|
|
||||||
return false;
|
|
||||||
if (bot.entity.position.distanceTo(entity.position) > distance)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function avoidEnemies(bot, distance=16) {
|
export async function avoidEnemies(bot, distance=16) {
|
||||||
/**
|
/**
|
||||||
* Move a given distance away from all nearby enemy mobs.
|
* Move a given distance away from all nearby enemy mobs.
|
||||||
|
|
|
@ -215,13 +215,17 @@ const modes_list = [
|
||||||
interrupts: ['action:followPlayer'],
|
interrupts: ['action:followPlayer'],
|
||||||
on: true,
|
on: true,
|
||||||
active: false,
|
active: false,
|
||||||
crowded_distance: 0.5,
|
distance: 0.5,
|
||||||
clear_distance: 1,
|
|
||||||
update: async function (agent) {
|
update: async function (agent) {
|
||||||
const player = world.getNearestEntityWhere(agent.bot, entity => entity.type === 'player', this.crowded_distance);
|
const player = world.getNearestEntityWhere(agent.bot, entity => entity.type === 'player', this.distance);
|
||||||
if (player) {
|
if (player) {
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
await skills.moveAwayFrom(agent.bot, player, this.clear_distance);
|
// wait a random amount of time to avoid identical movements with other bots
|
||||||
|
const wait_time = Math.random() * 1000;
|
||||||
|
await new Promise(resolve => setTimeout(resolve, wait_time));
|
||||||
|
if (player.position.distanceTo(agent.bot.entity.position) < this.distance) {
|
||||||
|
await skills.moveAway(agent.bot, this.distance);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue