thepecher Posted September 11, 2014 Share Posted September 11, 2014 (edited) First off, thanks for explaining the logic of such a path handling method and his obstacle class //list is made with positions you want to reach and obstacles you want to handle public void TraversePath(Script sI, ArrayList list) throws InterruptedException { sI=this.sI; int entry=findEntry(sI,list); for (int i = entry; i < (list.size());) { sI.log("Tackling path/obstacle number: " +i); if(list.get(i) instanceof Position ){ sI.log("Instance position"); if(sI.map.canReach((Position)list.get(i)) && sI.myPlayer().getPosition() != list.get(i)){ sI.log("CanReach is true, first if()"); sI.localWalker.walk((Position) list.get(i)); clickMiniMapPosition((Position) list.get(i)); i++; } else{ sI.log("CanReach is false, second if()"); i--; } } else if(list.get(i) instanceof Obstacle){ sI.log("Instance Obstacle"); String obstacleName=((Obstacle)list.get(i)).getName(); RS2Object obstacleObject=sI.objects.closest(obstacleName); if(sI.map.canReach(((Obstacle)list.get(i)).getPosition()) && sI.myPlayer().getPosition() != ((Obstacle)list.get(i)).getPosition()){ sI.log("CanReach is true, first if()"); sI.localWalker.walk(((Obstacle)list.get(i)).getPosition()); clickMiniMapPosition(((Obstacle)list.get(i)).getPosition()); i++; } else if(obstacleObject !=null && obstacleObject.exists() && (obstacleObject.hasAction(((Obstacle)list.get(i)).getAction()) || obstacleName=="Trapdoor")){ sI.log("CanReach is false, second if()"); if(obstacleObject.getOrientation()==0 || obstacleObject.getOrientation()==2){ sI.camera.moveYaw(MethodProvider.random(246,300)); } else{sI.camera.moveYaw(MethodProvider.random(150,200));} //^for broken interaction, thanks OsBot obstacleObject.interact(((Obstacle) list.get(i)).getAction()); i++; } else{ i--; } } sI.sleep(MethodProvider.random(1000,1500)); if(i==list.size()+1){ i=0; } if(i==-1){ i=list.size(); } } } public static int findEntry(Script script, ArrayList path) { int index = -1; for (int i = 0; i < path.size(); i++) { Object o = path.get(i); if (o instanceof Position && script.getMap().canReach(((Position) o))) { index = i; } } return index; } public boolean clickMiniMapPosition(Position position) throws InterruptedException { return sI.mouse.click(new MiniMapTileDestination(sI.bot, position), false); } public class Obstacle { private final String name; private final String action; private final Position position; public Obstacle(final String name, final String action, final Position position) { this.name = name; this.action = action; this.position = position; } public Position getPosition() { return this.position; } public String getAction() { return this.action; } public String getName() { return this.name; } } Edited September 11, 2014 by thepecher 1 Link to comment Share on other sites More sharing options...
Th3 Posted September 11, 2014 Share Posted September 11, 2014 You would give much better results if you simply checked for flags for obstacle handling. Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 11, 2014 Share Posted September 11, 2014 RS2Object obstacleObject=sI.objects.closest(obstacleName); Entity obstacleEntity=sI.objects.closest(obstacleName); Why are you grabbing the obstacle twice? Link to comment Share on other sites More sharing options...
Dog_ Posted September 11, 2014 Share Posted September 11, 2014 java 6 Link to comment Share on other sites More sharing options...
thepecher Posted September 11, 2014 Author Share Posted September 11, 2014 Why are you grabbing the obstacle twice? Maybe a typo Maybe i needed a object somewhere and then a entity elsewhere. I removed some script specific code so that maybe why. Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 11, 2014 Share Posted September 11, 2014 Maybe a typo Maybe i needed a object somewhere and then a entity elsewhere. I removed some script specific code so that maybe why. Even so you could just cast it. Link to comment Share on other sites More sharing options...
thepecher Posted September 11, 2014 Author Share Posted September 11, 2014 Even so you could just cast it. I told you, it's a mistake Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 11, 2014 Share Posted September 11, 2014 I told you, it's a mistake I'm only saying that if you needed a subclass you could have just casted it.... Link to comment Share on other sites More sharing options...
Pandemic Posted September 11, 2014 Share Posted September 11, 2014 I'm only saying that if you needed a subclass you could have just casted it.... IIRC Objects are entities anyways, so you wouldn't even need to cast it, but it looks like he just accidentally left it in there. 1 Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 11, 2014 Share Posted September 11, 2014 IIRC Objects are entities anyways, so you wouldn't even need to cast it, but it looks like he just accidentally left it in there. I was referring to the Entity. Link to comment Share on other sites More sharing options...
Joseph Posted September 12, 2014 Share Posted September 12, 2014 It's great practice if you use the interface list rather than the class arraylist. Also if you cast your list<E>. You don't have to add in the instanceof checks it actually casting a variable off the list. Link to comment Share on other sites More sharing options...
Isolate Posted September 22, 2014 Share Posted September 22, 2014 It's great practice if you use the interface list rather than the class arraylist. Also if you cast your list<E>. You don't have to add in the instanceof checks it actually casting a variable off the list. I'm assuming he did it because the list contains more than one type of data. it contains positions AND obstacles, so of course it will need to check which one it's currently dealing with. Link to comment Share on other sites More sharing options...
Joseph Posted September 22, 2014 Share Posted September 22, 2014 I'm assuming he did it because the list contains more than one type of data. it contains positions AND obstacles, so of course it will need to check which one it's currently dealing with. then create new class that support position entity and obstacle and cast it using the new class he created Link to comment Share on other sites More sharing options...