Articron 738 Share Posted August 6, 2017 Wrote this in a sad state, prob could be improved Note: this is written in my own scripting environment, you'll need to edit a few things if you want to use this. TraversalNode: package io.articron.cronfighter.api.walking; import io.articron.cronfighter.fw.ScriptEnvironment; import org.dreambot.api.methods.map.Tile; /** * Author: Articron * Date: 4/08/2017. */ public interface TraversalNode { boolean traverse(ScriptEnvironment env); Tile getTile(); boolean equals(Object object); boolean passed(ScriptEnvironment env); } TileNode: package io.articron.cronfighter.api.walking.impl; import io.articron.cronfighter.api.walking.TraversalNode; import io.articron.cronfighter.fw.ScriptEnvironment; import org.dreambot.api.methods.map.Tile; /** * Author: Articron * Date: 4/08/2017. */ public class TileNode implements TraversalNode { private Tile tile; public TileNode(int x, int y) { this(x,y,0); } public TileNode(int x, int y, int z) { this(new Tile(x,y,z)); } public TileNode(Tile tile) { this.tile = tile; } @Override public boolean traverse(ScriptEnvironment env) { return env.getDreambot().getWalking().walk(tile); } @Override public boolean equals(Object obj) { if (!(obj instanceof TraversalNode)) { return false; } TraversalNode node = (TraversalNode) obj; return node.getTile().equals(getTile()); } @Override public boolean passed(ScriptEnvironment env) { return getTile().distance() <= 3; } @Override public Tile getTile() { return tile; } } ObstacleNode: package io.articron.cronfighter.api.walking.impl; import io.articron.cronfighter.api.walking.TraversalNode; import io.articron.cronfighter.fw.ScriptEnvironment; import org.dreambot.api.methods.MethodProvider; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.wrappers.interactive.GameObject; import java.util.Arrays; import java.util.Optional; /** * Author: Articron * Date: 4/08/2017. */ public class ObstacleNode implements TraversalNode { private String objName; private String objAction; private Tile loc; private boolean passed; private Tile end; public ObstacleNode(String objName, String objAction, Tile loc, Tile end) { this.objAction = objAction; this.objName = objName; this.loc = loc; this.end = end; } @Override public boolean traverse(ScriptEnvironment env) { if (loc.distance() > 10) { if (env.getDreambot().getWalking().walk(loc)) return false; } Optional<GameObject> opt = Arrays.stream(env.getDreambot().getGameObjects().getObjectsOnTile(loc)) .filter(g -> g != null && g.getName().equals(objName) && g.hasAction(objAction)) .findFirst(); if (!opt.isPresent()) { passed = true; return true; } GameObject obj = opt.get(); if (env.getDreambot().getCamera().rotateToEntity(obj) && obj.interactForceRight(objAction)) { MethodProvider.sleepUntil(() -> env.getDreambot().getLocalPlayer().getTile().equals(end),2000); } else { if (env.getDreambot().getCamera().rotateToPitch(383)) { return false; } } passed = (env.getDreambot().getLocalPlayer().getTile().equals(end)); return passed; } @Override public boolean equals(Object obj) { if (!(obj instanceof TraversalNode)) { return false; } TraversalNode node = (TraversalNode) obj; return node.getTile().equals(getTile()); } @Override public boolean passed(ScriptEnvironment env) { return passed; } @Override public Tile getTile() { return end; } } CustomPath: package io.articron.cronfighter.api.walking; import io.articron.cronfighter.fw.ScriptEnvironment; import java.util.*; /** * Author: Articron * Date: 4/08/2017. */ public class CustomPath { private ArrayDeque<TraversalNode> pathQueue = new ArrayDeque<>(); private List<TraversalNode> blueprint = new LinkedList<>(); private ScriptEnvironment env; public CustomPath(ScriptEnvironment env) { this.env = env; } public void addNodes(TraversalNode... nodes) { Collections.addAll(pathQueue,nodes); Collections.addAll(blueprint,nodes); } public boolean walk() { TraversalNode next = pathQueue.peek(); if (next != null && next.traverse(env) && next.passed(env)) { pathQueue.pop(); return true; } return false; } public boolean isCompleted() { return pathQueue.isEmpty(); } public void resetPath() { pathQueue.clear(); pathQueue.addAll(blueprint); } private TraversalNode findNextNode() { TraversalNode node = pathQueue.peek(); if (node == null) { return null; } while(node.getTile().distance() < 3) { pathQueue.pop(); node = pathQueue.peek(); } return node; } } Example of use: ^ The above runs a lap through the edgeville sewers Link to comment Share on other sites More sharing options...
Hashtag 8693 Share Posted August 6, 2017 Oh damn thanks for sharing it ! Link to comment Share on other sites More sharing options...
Articron 738 Author Share Posted August 6, 2017 Oh damn thanks for sharing it ! np bb disclaimer: the code is pretty crap this is a draft, keeping the gud shit 4 myself for now Edit: a small bug that I didn't mention, make sure you return true on "walk" if your node's traverse is true, just only pop it if TraversalNode#passed is true Link to comment Share on other sites More sharing options...
Dinh 496 Share Posted August 6, 2017 arti back at it again with them crappy but useful snippets xd thanks for sharing bae Link to comment Share on other sites More sharing options...
Articron 738 Author Share Posted August 6, 2017 arti back at it again with them crappy but useful snippets xd thanks for sharing bae Call my snippet crap again and I'll neck you rich kid Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.