Skip to content

Commit

Permalink
Added a bit delay to swap combat
Browse files Browse the repository at this point in the history
  • Loading branch information
sefirosweb committed Apr 6, 2024
1 parent e1cf208 commit 82555b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/BehaviorModules/combat/BehaviorAttack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/NestedStateModules/MainStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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}`)
Expand Down
3 changes: 2 additions & 1 deletion core/src/NestedStateModules/combat/combatStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 82555b9

Please sign in to comment.