Jump to content

Setting a break condition for WalkEvent


Recommended Posts

So I'm trying to use path walking instead of webwalking wherever I can. The problem I'm facing is what if a bot enters a location accidentally from which it can't go out without handling obstacles?

WalkingEvent walkEvent = new WalkingEvent();
//			walkEvent.setBreakCondition(new Condition() {
//				@Override
//				public boolean evaluate() {
//					return (?????????);
//				}
//			});
			if (walkEvent.hasFailed())
				s.log("Walk event failed");

Seems like hasFailed() never really fires. Event just clicks on the minimap on the next position.

Planning to use webwalking if path walking fails.

So the question is:

 Is it possible to evaluate if a bot can reach the next desired position in WalkingEvents' position list? Would like not to do calculations of which position the bot is currently closest to in the provided list myself, the idea here is to save cpu power. Maybe set the break condition to check if the bot is not moving for more than, say, 5 seconds and then break the event?

So basically, what would be the cleanest, most efficient way in doing this?

Link to comment
Share on other sites

	public static WalkingEvent wEvent;
	public static boolean walkPath(Script script, LinkedList<Position> path) {
		Paint.action = "Walk path";
		wEvent = new WalkingEvent();
		wEvent.setBreakCondition(new Condition() {
			public boolean evaluate() {
				List<Position> eventPath = wEvent.getPath().stream()
						.sorted((a, b) -> Integer.compare(script.getMap().distance(a), script.getMap().distance(b)))
				Position p = eventPath.get(0);
				return !script.getMap().canReach(p);
		return false;

before you start walkPath() you should do a check to see if the next point on the path can be reached. use the sorter i provided to do that and then handle the obstacle if you cannot reach the next position.

edit: this snippet is designed to handle paths without obstacles on it but should function the way you need it to. you'll have to create the obstacle handling part yourself. with that said, there is a way to combine them both together but that is a whole new can of worms and something that i don't want to share :p

Edited by superuser
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...