Skip to content

Commit

Permalink
added proper filters and organised the code a lil more
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidsquid1 authored Mar 1, 2024
1 parent 12c6072 commit 4037a7a
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,30 @@ function createNewBot(user) {
});
}

function locateNearestPlayer(bot) {
let mobFilter = (e) => e.type === 'player';
let player = bot.nearestEntity(mobFilter);
return player;
}

function killauraTick(bot, range) {
let entity = bot.nearestEntity();
if (entity !== null) {
if (entity.type === "player") {
if (bot.entity.position.distanceTo(entity.position) <= range) {
let pos = entity.position.offset(0, entity.height, 0);

if (rotations) {
bot.lookAt(pos, true);
}
bot.attack(entity);
}
}
}
entity = locateNearestPlayer(bot);
if (!entity) { return; }
let pos = entity.position.offset(0, entity.height, 0);

if (bot.entity.position.distanceTo(entity.position) > range) { return; }
if (rotations) { bot.lookAt(pos, true); }
bot.attack(entity);
return entity;
}

function fightBotTick(bot, range) {
killauraTick(bot, range);
let entity = bot.nearestEntity();
if (entity !== null && entity.type === "player") {
bot.pathfinder.setGoal(new GoalFollow(entity, range));
}

entity = locateNearestPlayer(bot);
if (!entity) { return; }

bot.pathfinder.setGoal(new GoalFollow(entity, range));
}

function readyCommands(bot) {
Expand Down Expand Up @@ -146,7 +148,7 @@ function readyCommands(bot) {
bowBot = !bowBot;
console.log("bowbot: " + bowBot);
if (bowBot) {
bot.hawkEye.autoAttack(bot.hawkEye.getPlayer(), 'bow');
bot.hawkEye.autoAttack(locateNearestPlayer(), 'bow');
} else {
bot.hawkEye.stop();
}
Expand Down

0 comments on commit 4037a7a

Please sign in to comment.