diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index c1be891..a52976f 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -1064,21 +1064,6 @@ export async function moveAway(bot, distance) { 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) { /** * Move a given distance away from all nearby enemy mobs. diff --git a/src/agent/modes.js b/src/agent/modes.js index 54558dc..ee10390 100644 --- a/src/agent/modes.js +++ b/src/agent/modes.js @@ -215,13 +215,17 @@ const modes_list = [ interrupts: ['action:followPlayer'], on: true, active: false, - crowded_distance: 0.5, - clear_distance: 1, + distance: 0.5, 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) { 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); + } }); } }