-
-
Save iancaffey/8470052a773cc7c195b1f1bd23bf2737 to your computer and use it in GitHub Desktop.
This file contains 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
package com.iancaffey.runemate.script; | |
import com.runemate.game.api.hybrid.local.hud.interfaces.Bank; | |
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory; | |
import com.runemate.game.api.script.framework.FiniteStateBot; | |
import com.runemate.game.api.script.framework.TransitionState; | |
import com.runemate.game.api.script.framework.TransitionTable; | |
import com.runemate.game.api.script.framework.TransitionTableBuilder; | |
/** | |
* FlaxPickerStateBotExample | |
* | |
* @author Ian Caffey | |
* @since 1.0 | |
*/ | |
public class FlaxPickerStateBotExample extends FiniteStateBot<FlaxPickerStateBotExample.FlaxState, FlaxPickerStateBotExample.FlaxCondition> { | |
@Override | |
public TransitionTable<FlaxState, FlaxCondition> createTransitionTable() { | |
final TransitionTableBuilder<FlaxState, FlaxCondition> builder = TransitionTable.newBuilder(FlaxState.class, FlaxCondition.class); | |
//About to walk to the flax field, close the bank if necessary, before continuing onwards. | |
builder.register(FlaxState.PICKING, FlaxCondition.READY_TO_WALK_TO_FIELD, state -> { | |
if (Bank.isOpen()) | |
Bank.close(); | |
return new TransitionState<>(FlaxState.PICKING, FlaxCondition.WALKING_TO_FIELD); | |
}); | |
//Walking towards the field. If we're there, transition to picking flax. | |
builder.register(FlaxState.PICKING, FlaxCondition.WALKING_TO_FIELD, state -> { | |
//TODO: If close enough to flax field, return (PICKING, READY_TO_PICK_FLAX) | |
//Walk towards flax field | |
return state; | |
}); | |
//About to walk back to bank, ensure we're ready by checking inventory, to decide whether to continue picking flax or start the walk to bank. | |
builder.register(FlaxState.PICKING, FlaxCondition.READY_TO_WALK_TO_BANK, state -> Inventory.isFull() ? | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.WALKING_TO_BANK) : | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.PICKING_FLAX) | |
); | |
//Walking towards the bank. We shouldn't be picking when walking to bank, so let's transition to banking. | |
builder.register(FlaxState.PICKING, FlaxCondition.WALKING_TO_BANK, state -> | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.WALKING_TO_BANK)); | |
//Ready to pick flax. Check that we're within range of flax before continuing to pick flax. Otherwise, try to walk again. | |
builder.register(FlaxState.PICKING, FlaxCondition.READY_TO_PICK_FLAX, state -> { | |
//TODO: Check if we're not close to flax. If not, return (PICKING, WALKING_TO_FIELD) | |
return new TransitionState<>(FlaxState.PICKING, FlaxCondition.PICKING_FLAX); | |
}); | |
//Picking flax. If we've reached a full inventory, let's prepare to walk to the bank. | |
builder.register(FlaxState.PICKING, FlaxCondition.PICKING_FLAX, state -> Inventory.isFull() ? | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.READY_TO_WALK_TO_BANK) : state); | |
//Ready to bank. We shouldn't be picking when being ready to bank, so let's transition to banking. | |
builder.register(FlaxState.PICKING, FlaxCondition.READY_TO_BANK, state -> | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.READY_TO_BANK)); | |
//Banking flax. We shouldn't be picking when banking, so let's transition to banking. | |
builder.register(FlaxState.PICKING, FlaxCondition.BANKING_FLAX, state -> | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.BANKING_FLAX)); | |
//Ready to walk to flax field. If we have an empty inventory, let's start the trek. Otherwise, try banking again. | |
builder.register(FlaxState.BANKING, FlaxCondition.READY_TO_WALK_TO_FIELD, state -> Inventory.isEmpty() ? | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.WALKING_TO_FIELD) : | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.BANKING_FLAX) | |
); | |
//Walking to flax field. We shouldn't be banking when walking to the field, so let's transition to picking. | |
builder.register(FlaxState.BANKING, FlaxCondition.WALKING_TO_FIELD, state -> | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.WALKING_TO_FIELD)); | |
//About to walk back to bank, ensure we're ready by checking inventory, to decide whether to continue picking flax or start the walk to bank. | |
builder.register(FlaxState.BANKING, FlaxCondition.READY_TO_WALK_TO_BANK, state -> Inventory.isFull() ? | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.WALKING_TO_BANK) : | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.PICKING_FLAX) | |
); | |
//Walking towards the bank. If we're there, transition to banking flax. | |
builder.register(FlaxState.BANKING, FlaxCondition.WALKING_TO_BANK, state -> { | |
//TODO: If close enough to bank, return (PICKING, BANKING_FLAX) | |
//Walk towards bank | |
return state; | |
}); | |
//Ready to pick flax. We shouldn't be banking when ready to pick flax, so let's transition to picking. | |
builder.register(FlaxState.BANKING, FlaxCondition.READY_TO_PICK_FLAX, state -> | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.READY_TO_PICK_FLAX)); | |
//Picking flax. We shouldn't be banking when picking flax, so let's transition to picking. | |
builder.register(FlaxState.BANKING, FlaxCondition.PICKING_FLAX, state -> | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.PICKING_FLAX)); | |
//Ready to bank. If we have any items, let's bank them. Otherwise, prepare to walk to flax field. | |
builder.register(FlaxState.BANKING, FlaxCondition.READY_TO_BANK, state -> Inventory.isEmpty() ? | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.READY_TO_WALK_TO_FIELD) : | |
new TransitionState<>(FlaxState.BANKING, FlaxCondition.BANKING_FLAX)); | |
//Banking flax. Deposit entire inventory. If we succeed, prepare to walk to flax field. Otherwise, try again. | |
builder.register(FlaxState.BANKING, FlaxCondition.BANKING_FLAX, state -> Bank.depositInventory() ? | |
new TransitionState<>(FlaxState.PICKING, FlaxCondition.READY_TO_WALK_TO_FIELD) : | |
state); | |
//We're done declaring how we're going to handle every single possible scenario while picking flax. Let's go. | |
return builder.build(); | |
} | |
public static enum FlaxState { | |
PICKING, BANKING | |
} | |
public static enum FlaxCondition { | |
READY_TO_WALK_TO_FIELD, | |
WALKING_TO_FIELD, | |
READY_TO_WALK_TO_BANK, | |
WALKING_TO_BANK, | |
READY_TO_PICK_FLAX, | |
PICKING_FLAX, | |
READY_TO_BANK, | |
BANKING_FLAX | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment