From 82555b970150ad494c1b8fa2c0f5b03e0cd9078e Mon Sep 17 00:00:00 2001 From: Sefirosweb Date: Sat, 6 Apr 2024 12:45:27 +0200 Subject: [PATCH] Added a bit delay to swap combat --- core/src/BehaviorModules/combat/BehaviorAttack.ts | 4 +++- core/src/NestedStateModules/MainStateMachine.ts | 2 ++ core/src/NestedStateModules/combat/combatStrategy.ts | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/BehaviorModules/combat/BehaviorAttack.ts b/core/src/BehaviorModules/combat/BehaviorAttack.ts index 451b8cd..8b9b9c2 100644 --- a/core/src/BehaviorModules/combat/BehaviorAttack.ts +++ b/core/src/BehaviorModules/combat/BehaviorAttack.ts @@ -3,6 +3,8 @@ import { LegionStateMachineTargets } from "base-types" import inventoryModule from '@/modules/inventoryModule' import { StateBehavior } from "mineflayer-statemachine" import { Bot } from "mineflayer"; + +const attackEvery = 600 export class BehaviorAttack implements StateBehavior { active: boolean; readonly bot: Bot @@ -34,7 +36,7 @@ export class BehaviorAttack implements StateBehavior { nextAttack() { const currentDate = Date.now() - if (currentDate - this.lastAttack > 500) { + if (currentDate - this.lastAttack > attackEvery) { this.lastAttack = currentDate return true } diff --git a/core/src/NestedStateModules/MainStateMachine.ts b/core/src/NestedStateModules/MainStateMachine.ts index 44139d4..f0f80a3 100644 --- a/core/src/NestedStateModules/MainStateMachine.ts +++ b/core/src/NestedStateModules/MainStateMachine.ts @@ -224,6 +224,7 @@ const startStateMachine = (bot: Bot) => { webserver = new StateMachineWebserver(bot, stateMachine, 4550) bot.stateMachinePort = webserver.port if (!webserver.isServerRunning()) { + console.log(`Started state machine web server at http://localhost:4550`) webserver.startServer() } @@ -261,6 +262,7 @@ const startStateMachine = (bot: Bot) => { } if (typeof webserver.isServerRunning === 'function') { if (!webserver.isServerRunning()) { + console.log(`Started state machine web server at http://localhost:${port}`) webserver.startServer() } botWebsocket.log(`Started state machine web server at http://localhost:${port}`) diff --git a/core/src/NestedStateModules/combat/combatStrategy.ts b/core/src/NestedStateModules/combat/combatStrategy.ts index c4498cd..284c748 100644 --- a/core/src/NestedStateModules/combat/combatStrategy.ts +++ b/core/src/NestedStateModules/combat/combatStrategy.ts @@ -26,6 +26,7 @@ function combatStrategy(bot: Bot, targets: LegionStateMachineTargets) { const rangeFollowToShortAttack = 5 const timeBowCountdown = 1550 + const changeTargetEvery = 1000 const timeMobCountdown = 7500 let newTimeMobCountdown: number @@ -71,7 +72,7 @@ function combatStrategy(bot: Bot, targets: LegionStateMachineTargets) { const getGrades = function () { // Of other enemies aproax, change target (Ex clipper) - if (Date.now() - newTargetColdDown > 1000) { + if (Date.now() - newTargetColdDown > changeTargetEvery) { const entity = bot.nearestEntity(filter) if (entity) { botWebsocket.log('Change Target => ' + entity.displayName + ' ' + JSON.stringify(entity.position))