Mysteryy Posted January 15, 2015 Share Posted January 15, 2015 (edited) Since Novak is a lazy bum I made a banking enum. I needed this for my web walker anyway. Banking enum (with areas): import org.osbot.rs07.api.map.Position; import org.osbot.rs07.utility.Area; /** * Created by zach on 1/10/15. */ public enum BankAreas{ DRAYNOR (new Area(3092, 3246, 3095, 3240), 0), LUMBRIDGE_LOWER (new Area(3215, 9623, 3219, 9620), 0), LUMBRIDGE_UPPER (new Area(3207, 3220, 3210, 3216), 2), ALKHARID(new Area(3269, 3170, 3272, 3162), 0), SHANTYPASS(new Area(3307, 3122, 3308, 3119), 0), DUEL_ARENA(new Area(3381, 3271, 3384, 3267), 0), EDGEVILLE(new Area(3090, 3498, 3098, 3489), 0), SEERS(new Area(2721, 3490, 2729, 3493), 0), CATHERBY(new Area(2806, 3438, 2812, 3441), 0), ARDOUGNE_NORTH(new Area(2621, 3334, 2612, 3332), 0), ARDOUGNE_SOUTH(new Area(2649, 3280, 2655, 3287), 0), VARROCK_EAST(new Area(3250, 3423, 3257, 3420), 0), VARROCK_WEST(new Area(3181, 3445, 3185, 3435), 0), FALADOR_WEST(new Area(2943, 3372, 2949, 3368), 0), FALADOR_EAST(new Area(3009, 3358, 3017, 3355), 0), YANILLE(new Area(2609, 3088, 2613, 3097), 0) ; private Area bankArea; private int zPlane; private BankAreas(Area bankArea, int zPlane){ this.bankArea = bankArea; this.zPlane = zPlane; } /** * Gets the bank area for the specified location. * * @return the bank area of the specified location. */ public Area getBankArea(){ return this.bankArea; } /** * Gets the z plane value for the specified bank location. * * @return the z plane that contains the specified bank location. */ public int getzPlane(){ return this.zPlane; } /** * Gets the central tile for the specified bank location. * * @return the central tile in the bank location. */ public Position getCentralPosition(){ return getCentralPosition(this.bankArea);//call the private method } /** * Checks if the specified bank area contains the specified position. * * @param position the position to check the bank area for. * @return true if the bank area contains position, false otherwise. */ public boolean areaContainsPosition(Position position){ if(position != null){ return (this.bankArea.contains(position) && position.getZ() == this.getzPlane()); } return false; } private Position getCentralPosition(Area area){ int centralX = area.getMinX() + ((area.getMaxX() - area.getMinX())/2); int centralY = area.getMinY() + ((area.getMaxY() - area.getMinY())/2); return new Position(centralX, centralY, this.zPlane); } } Useful methods inside of a banking class that use the enum: import org.osbot.rs07.api.map.Position; import org.osbot.rs07.utility.Area; /** * Created by zach on 1/14/15. */ public class Banking { /** * Gets the nearest bank to the specified position. * * @param position the position to measure the distance to. * @return the bank nearest to the specified position. */ public Area getNearestBankArea(Position position){ Area closestArea = null; int closestDistance = 99999; for(BankAreas bankAreas : BankAreas.values()){ if(bankAreas.getzPlane() == position.getZ()){//make sure that the z planes are the same Position tempPosition = bankAreas.getCentralPosition(); int tempDistance = (int) getEstimatedDistanceToFinish(tempPosition.getX(), tempPosition.getY(), position.getX(), position.getY()); if(tempDistance < closestDistance){ closestArea = bankAreas.getBankArea(); closestDistance = tempDistance; } } } return closestArea; } /** * Gets the central tile of the nearest bank to the specified position. * * @param position the position to measure the distance to. * @return the central position of the nearest bank to the specified position. */ public Position getNearestBankCentralPosition(Position position){ Area closestArea = getNearestBankArea(position); if(closestArea != null) return getCentralPosition(closestArea, position.getZ()); return null; } /** * Estimates the distance from x1, y1 to x2, y2. * * Note: The method used to calculate the estimation is an average of the * estimated manhattan distance + the estimated euclidean distance. * In tile based games where both diagonal and non diagonal movement is * possible, this method will give a more accurate estimation of the * real distance between points 1 and 2. * * @param initialX the starting x value. * @param initialY the starting y value. * @param finalX the ending x value. * @param finalY the ending y value. * * @return the estimated distance from x1, y1 to x2, y2. */ public float getEstimatedDistanceToFinish(int initialX, int initialY, int finalX, int finalY){ return ((calculateEuclideanDistance(initialX, initialY, finalX, finalY) + calculateManhattanDistance(initialX, initialY, finalX, finalY)) /2 ); } private float calculateManhattanDistance(int initialX, int initialY, int finalX, int finalY){ float dx = Math.abs(finalX - initialX); float dy = Math.abs(finalY - initialY); return dx+dy; } private float calculateEuclideanDistance(int initialX, int initialY, int finalX, int finalY){ return (float) Math.sqrt(Math.pow(initialX - finalX, 2) + Math.pow(initialY - finalY, 2)); } private Position getCentralPosition(Area area, int zPlane){ int centralX = area.getMinX() + ((area.getMaxX() - area.getMinX())/2); int centralY = area.getMinY() + ((area.getMaxY() - area.getMinY())/2); return new Position(centralX, centralY, zPlane); } } You can use the methods in something like this: /** * Created by zach on 1/5/15. */ @ScriptManifest(name = "Test", author = "Mysteryy", info = "Testing", version = 1.0, logo = "none") public class Test extends Script { Banking banking = new Banking(); @Override public void onStart(){ Player player = myPlayer(); if(player != null){ this.log(banking.getNearestBankArea(player.getPosition()).getMinX() + ", " + banking.getNearestBankArea(player.getPosition()).getMaxY()); this.log(banking.getNearestBankCentralPosition(player.getPosition()).getX() + ", " + banking.getNearestBankCentralPosition(player.getPosition()).getY()); this.log(BankAreas.DRAYNOR.getCentralPosition().getX() + ", " + BankAreas.DRAYNOR.getCentralPosition().getY()); this.log(BankAreas.DRAYNOR.areaContainsPosition(player.getPosition())); } } @Override public int onLoop() throws InterruptedException { return 50; } } which would output [iNFO][bot #1][01/14 10:35:12 PM]: 3092, 3246 [iNFO][bot #1][01/14 10:35:12 PM]: 3093, 3243 [iNFO][bot #1][01/14 10:35:12 PM]: 3093, 3243 [iNFO][bot #1][01/14 10:35:12 PM]: true Let me know if you have any questions or suggestions. Edited January 20, 2015 by Mysteryy 2 Link to comment Share on other sites More sharing options...
Novak Posted January 15, 2015 Share Posted January 15, 2015 im not that lazy, i got half those areas :P Link to comment Share on other sites More sharing options...
Mysteryy Posted January 15, 2015 Author Share Posted January 15, 2015 im not that lazy, i got half those areas Hey i had to make the files. Thats alot of work. xD Link to comment Share on other sites More sharing options...
flaxspinner Posted January 15, 2015 Share Posted January 15, 2015 don't want to bother you or anything but can you reply on skype :P? mystery Link to comment Share on other sites More sharing options...
Botre Posted January 15, 2015 Share Posted January 15, 2015 kewl Link to comment Share on other sites More sharing options...
Joseph Posted January 15, 2015 Share Posted January 15, 2015 You know there's a banks class with polya right. Why didn't you use that? Example; Banks.VARROCK_WEST.contains(myPlayer); Link to comment Share on other sites More sharing options...
Mysteryy Posted January 15, 2015 Author Share Posted January 15, 2015 You know there's a banks class with polya right. Why didn't you use that? Example; Banks.VARROCK_WEST.contains(myPlayer); The less that you can rely on the API the better. Making your own banking enum will abstract this from the api and make it more reusable. Link to comment Share on other sites More sharing options...
Joseph Posted January 15, 2015 Share Posted January 15, 2015 i mean alek is expanding the api to help us the scripters. So i dont see why not use what they give us. Link to comment Share on other sites More sharing options...
Mysteryy Posted January 15, 2015 Author Share Posted January 15, 2015 i mean alek is expanding the api to help us the scripters. So i dont see why not use what they give us. Its just the way I like to do things. I dont like to depend on things if I dont have to. Just my personal preference, not saying its bad to use the API. :P 1 Link to comment Share on other sites More sharing options...