Skip to content

Commit

Permalink
Reload bot config when new config is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
sefirosweb committed Apr 6, 2024
1 parent 2cf8a31 commit e1cf208
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions core/src/NestedStateModules/MainStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import movementModule from '@/modules/movementModule'
import botWebsocket from '@/modules/botWebsocket'
import mineflayerPathfinder from 'mineflayer-pathfinder'
import { startPrismarineViewer } from '@/modules/viewer'
import DeathFunction from '@/NestedStateModules/afterDeathFunction'
import { afterDeathFunction } from '@/NestedStateModules/afterDeathFunction'
import { StateTransition, BotStateMachine, StateMachineWebserver, BehaviorIdle, NestedStateMachine } from 'mineflayer-statemachine'
import { getFreePort } from "@/modules/utils"

Expand Down Expand Up @@ -101,7 +101,7 @@ const startStateMachine = (bot: Bot) => {
watiState.x = 125
watiState.y = 313

const death = DeathFunction(bot, targets)
const death = afterDeathFunction(bot, targets)
death.x = 425
death.y = 213

Expand Down
32 changes: 16 additions & 16 deletions core/src/NestedStateModules/afterDeathFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import GoChestsFunctions from '@/NestedStateModules/getReady/goChestsFunctions'
import { Bot } from 'mineflayer'
import { BehaviorGetPlayer, BehaviorLoadConfig } from '@/BehaviorModules'

function deathFunction(bot: Bot, targets: LegionStateMachineTargets) {
export let afterDeathTransitions: Array<StateTransition> = []

export const afterDeathFunction = (bot: Bot, targets: LegionStateMachineTargets): NestedStateMachine => {
const start = new BehaviorIdle()
start.stateName = 'Start'
start.x = 125
start.y = 113

const startWork = StartWork(bot, targets)
startWork.x = 525
startWork.y = 413
startWork.y = 513

const commands = Commands(bot, targets)
commands.x = 325
Expand All @@ -40,7 +42,7 @@ function deathFunction(bot: Bot, targets: LegionStateMachineTargets) {
goSleep.x = 725
goSleep.y = 263

const transitions = [
afterDeathTransitions = [
new StateTransition({ // 0
parent: startWork,
child: loadConfig,
Expand Down Expand Up @@ -140,28 +142,28 @@ function deathFunction(bot: Bot, targets: LegionStateMachineTargets) {

new StateTransition({
parent: goChests,
child: startWork,
child: loadConfig,
shouldTransition: () => goChests.isFinished()
}),


]

function reloadTrigger() {
const reloadTrigger = () => {
targets.entity = undefined
bot.stopDigging()
bot.pathfinder.setGoal(null)

transitions[0].trigger()
transitions[1].trigger()
afterDeathTransitions[0].trigger()
afterDeathTransitions[1].trigger()
}

function commandTrigger() {
const commandTrigger = () => {
botWebsocket.log('sendStay')
transitions[3].trigger()
transitions[4].trigger()
transitions[5].trigger()
transitions[6].trigger()
afterDeathTransitions[3].trigger()
afterDeathTransitions[4].trigger()
afterDeathTransitions[5].trigger()
afterDeathTransitions[6].trigger()
botWebsocket.emitCombat(false)
}

Expand Down Expand Up @@ -196,9 +198,7 @@ function deathFunction(bot: Bot, targets: LegionStateMachineTargets) {
}
})

const nestedState = new NestedStateMachine(transitions, start)
const nestedState = new NestedStateMachine(afterDeathTransitions, start)
nestedState.stateName = 'After death function'
return nestedState
}

export default deathFunction
}
1 change: 1 addition & 0 deletions core/src/NestedStateModules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './afterDeathFunction'
2 changes: 2 additions & 0 deletions core/src/modules/botWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Bot } from 'mineflayer'
import { connectBotToServer } from '@/modules/connectSocket'
import { webSocketQueue } from './queues'
import { saveBotConfig } from './botConfig'
import { afterDeathTransitions } from '@/NestedStateModules'

let socket: Socket
let friends: Array<BotFriends> = []
Expand Down Expand Up @@ -76,6 +77,7 @@ const connect = async () => {
Object.assign(bot.config, botConfig)
saveBotConfig()
response({ success: true });
afterDeathTransitions[0].trigger()
})

socket.on('get_master_position', (data: { master: string }, response) => {
Expand Down

0 comments on commit e1cf208

Please sign in to comment.