diff --git a/core/src/NestedStateModules/MainStateMachine.ts b/core/src/NestedStateModules/MainStateMachine.ts index 7544dfc..44139d4 100644 --- a/core/src/NestedStateModules/MainStateMachine.ts +++ b/core/src/NestedStateModules/MainStateMachine.ts @@ -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" @@ -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 diff --git a/core/src/NestedStateModules/afterDeathFunction.ts b/core/src/NestedStateModules/afterDeathFunction.ts index 5d2f908..5e26843 100644 --- a/core/src/NestedStateModules/afterDeathFunction.ts +++ b/core/src/NestedStateModules/afterDeathFunction.ts @@ -8,7 +8,9 @@ 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 = [] + +export const afterDeathFunction = (bot: Bot, targets: LegionStateMachineTargets): NestedStateMachine => { const start = new BehaviorIdle() start.stateName = 'Start' start.x = 125 @@ -16,7 +18,7 @@ function deathFunction(bot: Bot, targets: LegionStateMachineTargets) { const startWork = StartWork(bot, targets) startWork.x = 525 - startWork.y = 413 + startWork.y = 513 const commands = Commands(bot, targets) commands.x = 325 @@ -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, @@ -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) } @@ -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 +} \ No newline at end of file diff --git a/core/src/NestedStateModules/index.ts b/core/src/NestedStateModules/index.ts new file mode 100644 index 0000000..c835ab9 --- /dev/null +++ b/core/src/NestedStateModules/index.ts @@ -0,0 +1 @@ +export * from './afterDeathFunction' \ No newline at end of file diff --git a/core/src/modules/botWebsocket.ts b/core/src/modules/botWebsocket.ts index 596284f..608bd48 100644 --- a/core/src/modules/botWebsocket.ts +++ b/core/src/modules/botWebsocket.ts @@ -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 = [] @@ -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) => {