I was having troubles for a little bit trying to get the closest bank, then stumbled upon Chris's post on how getting the closest bank works. So all credits go to him for this one. All I did was modified the coding a little bit to make it compatible with task usage.
Code:
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.script.MethodProvider;
public enum WebBank {
GRAND_EXCHANGE(new Area(new Position(3161, 3493, 0), new Position(3168, 3486, 0))),
VARROCK_EAST(new Area(new Position(3250, 3423, 0), new Position(3257, 3416, 0))),
VARROCK_WEST(new Area(new Position(3180, 3447, 0), new Position(3185, 3433, 0))),
EDGEVILLE(new Area(new Position(3091, 3499, 0), new Position(3098, 3487, 0)));
private final Area area;
WebBank(Area area) {
this.area = area;
}
public static Area closestTo(MethodProvider e) {
HashMap<WebBank, Integer> distMap = new HashMap<WebBank, Integer>();
for (WebBank b : WebBank.values()) {
distMap.put(b, e.myPosition().distance(b.area.getRandomPosition()));
}
HashMap<Integer, WebBank> distMapSorted = sortByDistance(distMap);
Area cBank = distMapSorted.values().toArray(new WebBank[WebBank.values().length])[0].area;
return cBank;
}
private static <K, V extends Comparable<? super V>> HashMap<V, K> sortByDistance(Map<K, V> map) {
HashMap<V, K> result = new LinkedHashMap<>();
Stream<Map.Entry<K, V>> st = map.entrySet().stream();
st.sorted(Map.Entry.comparingByValue()).forEachOrdered(e -> result.put(e.getValue(), e.getKey()));
return result;
}
}
Usage:
import org.osbot.rs07.event.WebWalkEvent;
import org.osbot.rs07.event.webwalk.PathPreferenceProfile;
import org.osbot.rs07.script.MethodProvider;
public class DropTask extends Task {
public DropTask(MethodProvider api) {
super(api);
}
@Override
public void startBankWalk() {
WebWalkEvent webEvent = new WebWalkEvent(WebBank.closestTo(api));
webEvent.useSimplePath();
PathPreferenceProfile ppp = new PathPreferenceProfile();
ppp.setAllowObstacles(true);
webEvent.setPathPreferenceProfile(ppp);
api.execute(webEvent);
return;
}
}