Created
February 14, 2021 23:20
-
-
Save iam4x/40a7ac4d26c0379b758f087ca234e8c5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'bot', | |
initial: 'loggedOut', | |
context: { | |
operators: [], | |
options: { | |
eat: true, | |
sleep: true, | |
}, | |
}, | |
states: { | |
loggedOut: { | |
id: 'loggedOut', | |
initial: 'loggingIn', | |
states: { | |
loggingIn: { | |
invoke: { | |
id: 'login', | |
src: 'initialize', | |
onDone: '#inGame', | |
onError: 'retryConnection', | |
}, | |
}, | |
retryConnection: { | |
after: { 5000: 'loggingIn' }, | |
}, | |
}, | |
}, | |
inGame: { | |
id: 'inGame', | |
initial: 'restoringActivity', | |
invoke: { | |
id: 'listenDisconnect', | |
src: 'listenDisconnect', | |
onDone: { target: '.disconnected' }, | |
}, | |
states: { | |
disconnected: { | |
after: { 5000: '#loggedOut' }, | |
}, | |
restoringActivity: { | |
id: 'restoringActivity', | |
always: [ | |
{ target: 'farming', cond: ({ farming }) => farming === true }, | |
{ target: 'fishing', cond: ({ fishing }) => fishing === true }, | |
{ target: 'waitingForCommand' }, | |
], | |
}, | |
waitingForCommand: { | |
id: 'waitingForCommand', | |
activities: ['lookAround'], | |
invoke: { | |
id: 'listen_chat_commands', | |
src: 'listenChatCommands', | |
}, | |
on: { | |
FARM: 'farming', | |
FISH: 'fishing', | |
MOVE_TO_PLAYER: 'movingToPlayer', | |
FOLLOW_PLAYER: 'followingPlayer', | |
}, | |
}, | |
movingToPlayer: { | |
invoke: { | |
id: 'moveToPlayer', | |
src: 'moveToPlayer', | |
onDone: { | |
target: 'waitingForCommand', | |
actions: 'disposeContextVariables', | |
}, | |
}, | |
}, | |
followingPlayer: { | |
invoke: { | |
id: 'followPlayer', | |
src: 'followPlayer', | |
onDone: { | |
target: 'waitingForCommand', | |
actions: 'disposeContextVariables', | |
}, | |
}, | |
}, | |
farming: { | |
initial: 'harvesting', | |
entry: (context) => (context.farming = true), | |
invoke: { | |
id: 'waitForStop', | |
src: 'waitForStop', | |
}, | |
on: { | |
STOP: '#waitingForCommand', | |
}, | |
states: { | |
harvesting: { | |
invoke: { | |
id: 'harvest', | |
src: 'harvest', | |
onDone: 'harvesting', | |
onError: { | |
target: 'collecting', | |
actions: 'setCollectFarmItems', | |
}, | |
}, | |
}, | |
collecting: { | |
invoke: { | |
id: 'collect', | |
src: 'collectGroundItems', | |
onDone: { | |
target: 'planting', | |
actions: 'disposeContextVariables', | |
}, | |
}, | |
}, | |
planting: { | |
invoke: { | |
id: 'plant', | |
src: 'plant', | |
onDone: 'planting', | |
onError: 'eating', | |
}, | |
}, | |
eating: { | |
invoke: { | |
id: 'eat', | |
src: 'eat', | |
onDone: { | |
target: 'emptyingInventory', | |
actions: 'setDepositFarmItems', | |
}, | |
}, | |
}, | |
emptyingInventory: { | |
invoke: { | |
id: 'deposit', | |
src: 'deposit', | |
onDone: { | |
target: 'sleeping', | |
actions: 'disposeContextVariables', | |
}, | |
}, | |
}, | |
sleeping: { | |
invoke: { | |
id: 'sleep', | |
src: 'sleep', | |
onDone: 'waiting', | |
}, | |
}, | |
waiting: { | |
entry: 'logWaiting', | |
activities: ['lookAround'], | |
after: { 2000: 'harvesting' }, | |
}, | |
}, | |
}, | |
fishing: { | |
initial: 'movingNearWater', | |
entry: (context) => (context.fishing = true), | |
invoke: { | |
id: 'waitForStop', | |
src: 'waitForStop', | |
}, | |
on: { | |
STOP: '#waitingForCommand', | |
}, | |
states: { | |
movingNearWater: { | |
invoke: { | |
id: 'moveNearWater', | |
src: 'moveNearWater', | |
onDone: 'waitingForFish', | |
onError: { | |
actions: send('ERROR', { to: 'waitForStop' }), | |
}, | |
}, | |
}, | |
waitingForFish: { | |
invoke: { | |
id: 'waitForFish', | |
src: 'waitForFish', | |
onDone: { | |
target: 'emptyingInventory', | |
actions: 'setDepositFishingItems', | |
}, | |
onError: { | |
actions: send('ERROR', { to: 'waitForStop' }), | |
}, | |
}, | |
}, | |
emptyingInventory: { | |
invoke: { | |
id: 'deposit', | |
src: 'deposit', | |
onDone: { | |
target: 'eating', | |
actions: 'disposeContextVariables', | |
}, | |
}, | |
}, | |
eating: { | |
invoke: { | |
id: 'eat', | |
src: 'eat', | |
onDone: 'sleeping', | |
}, | |
}, | |
sleeping: { | |
invoke: { | |
id: 'sleep', | |
src: 'sleep', | |
onDone: 'movingNearWater', | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment