Created
January 17, 2013 19:04
-
-
Save TheBatScripts/4558607 to your computer and use it in GitHub Desktop.
BatAgility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package scripts; | |
| import java.awt.Color; | |
| import java.awt.Graphics; | |
| import java.awt.Point; | |
| import java.awt.Polygon; | |
| import java.awt.geom.Point2D; | |
| import java.awt.image.BufferedImage; | |
| import java.io.File; | |
| import java.io.FileNotFoundException; | |
| import java.io.IOException; | |
| import java.net.URL; | |
| import javax.imageio.ImageIO; | |
| import org.tribot.api.EGW; | |
| import org.tribot.api.Game; | |
| import org.tribot.api.GameTab; | |
| import org.tribot.api.GameTab.TABS; | |
| import org.tribot.api.General; | |
| import org.tribot.api.Player; | |
| import org.tribot.api.Screen; | |
| import org.tribot.api.ScreenModels; | |
| import org.tribot.api.Timing; | |
| import org.tribot.api.input.Mouse; | |
| import org.tribot.api.types.ScreenModel; | |
| import org.tribot.api.types.colour.Tolerance; | |
| import org.tribot.script.Script; | |
| import org.tribot.script.ScriptManifest; | |
| import org.tribot.script.interfaces.Painting; | |
| @ScriptManifest(authors = { "TheBat" }, category = "Agility", name = "BatAgility") | |
| public class BatAgility extends Script implements Painting{ | |
| //IDs for screen models | |
| private final long m_rock = 3108025121L; | |
| private final long m_tree = 2450281625L; | |
| private final long m_bars = 408717104L; | |
| private final long m_skulls = 3549117173L; | |
| private final long m_rope = 2452536905L; | |
| private final long m_treeVine = 2231904923L; | |
| //Constants | |
| private final Point CENTER = new Point((int)Screen.getViewport().getCenterX(),(int)Screen.getViewport().getCenterY()); | |
| //Paint variables | |
| private int zone = -1; | |
| private BufferedImage backy = null; | |
| private long startTime = System.currentTimeMillis(); | |
| private int laps; | |
| private int totalEXP; | |
| private int tempZone = -1; | |
| private boolean fullCourse = true; | |
| //egw zones | |
| private final Polygon black = new Polygon(new int[]{2753, 2760, 2762, 2759, 2753, 2744, 2745}, new int[]{2751, 2748, 2742, 2738, 2732, 2738, 2748}, 7);//not really a zone, but its uszed in zoning | |
| private final Polygon egw_zone_0 = new Polygon(new int[]{2759, 2760, 2762, 2763, 2775, 2778, 2748, 2748, 2753, 2755, 2756}, new int[]{2741, 2742, 2742, 2736, 2736, 2764, 2764, 2749, 2746, 2742, 2741}, 11);//before rock after vine | |
| private final Polygon egw_zone_1 = new Polygon(new int[]{2751, 2756, 2754, 2751}, new int[]{2744, 2743, 2740, 2740}, 4);//before tree climb after rock | |
| private final Polygon egw_zone_2 = new Polygon(new int[]{2751, 2756, 2754, 2751}, new int[]{2744, 2743, 2740, 2740}, 4);//before money bars after tree climb | |
| private final Polygon egw_zone_3 = new Polygon(new int[]{2750, 2748, 2747, 2748}, new int[]{2741, 2743, 2741, 2740}, 4);//before skulls after money bars | |
| private final Polygon egw_zone_4 = new Polygon(new int[]{2738, 2746, 2746, 2750, 2754, 2754, 2754, 2753, 2754, 2752, 2745, 2737}, new int[]{2744, 2744, 2741, 2738, 2736, 2733, 2730, 2727, 2725, 2723, 2728, 2733}, 12);//before rope swing after skulls | |
| private final Polygon egw_zone_5 = new Polygon(new int[]{2756, 2762, 2765, 2767, 2760, 2755, 2755}, new int[]{2740, 2739, 2729, 2724, 2723, 2727, 2735}, 7);//before vine after rope swing | |
| public boolean onStart(){ | |
| try { | |
| backy = ImageIO.read(new File("./Storage/BatScripts/backPick.png")); | |
| }catch (FileNotFoundException e) { | |
| }catch (IOException e) { | |
| try { | |
| println("Images not found, retrieving from internet."); | |
| backy = ImageIO.read(new URL("http://i.imgur.com/I2vLB.png")); | |
| File file = new File("./Storage/BatScripts/backPick.png"); | |
| file.getParentFile().mkdirs(); | |
| ImageIO.write(backy, "png",file); | |
| } catch (IOException ex) {} | |
| } | |
| return true; | |
| } | |
| public int loop(){ | |
| Mouse.setSpeed(General.random(100,150)); | |
| if(!GameTab.getOpen().equals(TABS.INVENTORY))GameTab.open(TABS.INVENTORY); | |
| zone = getZone(); | |
| if(Player.isMoving()){ | |
| sleep(300, 600); | |
| return 100; | |
| } | |
| switch(zone){ | |
| case 0: | |
| nextObst(m_rock, new Point(2756,2742), "jump"); | |
| break; | |
| case 1: | |
| nextObst(m_tree, new Point(2754,2742), "climb"); | |
| break; | |
| case 2: | |
| nextObst(m_bars, new Point(2754,2741), "swing"); | |
| break; | |
| case 3: | |
| nextObst(m_skulls, new Point(2748,2741), "climb"); | |
| break; | |
| case 4: | |
| nextObst(m_rope, new Point(2752,2732), "swing"); | |
| break; | |
| case 5: | |
| nextObst(m_treeVine, new Point(2758,2735), "climb"); | |
| break; | |
| default: | |
| UnknownZone(); | |
| break; | |
| } | |
| return 100; | |
| } | |
| private void nextObst(long model, Point location, String action) { | |
| ScreenModel[] positions = ScreenModels.find(model); | |
| if(positions.length < 1){ | |
| EGW.walkTo(General.random(location.x-2, location.x+2), General.random(location.y-2, location.y+2)); | |
| sleep(150,250); | |
| return; | |
| } | |
| try{//Sometimes it will try to click after it has already moved past an obstacle. | |
| int k = 0; | |
| while(Game.getUptext() == null || !Game.getUptext().toLowerCase().contains(action)){ | |
| Mouse.move(closest(positions).getVisiblePoints()[General.random(0, positions[0].getVisiblePoints().length-1)]); | |
| Mouse.setSpeed(250); | |
| if(k++ >= 6)return; | |
| sleep(250,300); | |
| } | |
| Mouse.click(1); | |
| sleep(500,750); | |
| }catch(ArrayIndexOutOfBoundsException e){} | |
| } | |
| private ScreenModel closest(ScreenModel[] positions) { | |
| return ScreenModels.sortByDistance(CENTER, positions)[0]; | |
| } | |
| private void UnknownZone() { | |
| } | |
| public void onStop(){ | |
| } | |
| @Override | |
| public void onPaint(Graphics g) { | |
| zoneChangeCheck(); | |
| if(backy != null)g.drawImage(backy, 0, 0, null); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawString("Runtime: " + Timing.msToString(System.currentTimeMillis() - startTime), 75, 21); | |
| g.drawString("Current Zone: " + zone, 75, 34); | |
| g.drawString("Experience: " + totalEXP, 233, 21); | |
| g.drawString("Exp/Hour: " + ((long)totalEXP*3600000)/(System.currentTimeMillis() - startTime), 233, 34); | |
| g.drawString("Laps: " + laps, 389, 21); | |
| g.drawString("Laps/Hour: " + ((long)laps*3600000)/(System.currentTimeMillis() - startTime), 389, 34); | |
| switch(zone){ | |
| case 0: | |
| g.setColor(new Color(0,0,0,100)); | |
| g.fillPolygon(posToMMPoly(egw_zone_0)); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawPolygon(posToMMPoly(egw_zone_0)); | |
| break; | |
| case 1: | |
| g.setColor(new Color(0,0,0,100)); | |
| g.fillPolygon(posToMMPoly(egw_zone_1)); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawPolygon(posToMMPoly(egw_zone_1)); | |
| break; | |
| case 2: | |
| g.setColor(new Color(0,0,0,100)); | |
| g.fillPolygon(posToMMPoly(egw_zone_2)); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawPolygon(posToMMPoly(egw_zone_2)); | |
| break; | |
| case 3: | |
| g.setColor(new Color(0,0,0,100)); | |
| g.fillPolygon(posToMMPoly(egw_zone_3)); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawPolygon(posToMMPoly(egw_zone_3)); | |
| break; | |
| case 4: | |
| g.setColor(new Color(0,0,0,100)); | |
| g.fillPolygon(posToMMPoly(egw_zone_4)); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawPolygon(posToMMPoly(egw_zone_4)); | |
| break; | |
| case 5: | |
| g.setColor(new Color(0,0,0,100)); | |
| g.fillPolygon(posToMMPoly(egw_zone_5)); | |
| g.setColor(new Color(233,192,42)); | |
| g.drawPolygon(posToMMPoly(egw_zone_5)); | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| private Polygon posToMMPoly(Polygon zone) { | |
| Polygon poly = new Polygon(); | |
| for(int i = 0; i < zone.npoints; i++){ | |
| Point pt = EGW.posToMM(zone.xpoints[i], zone.ypoints[i]); | |
| poly.addPoint(pt.x,pt.y); | |
| } | |
| return poly; | |
| } | |
| private void zoneChangeCheck() { | |
| if(zone != -1 && tempZone != zone){ | |
| if(tempZone == 0 && zone == 1){ | |
| totalEXP+=40; | |
| }else if(tempZone == 1 && zone == 2){ | |
| totalEXP+=40; | |
| }else if(tempZone == 2 && zone == 3){ | |
| totalEXP+=40; | |
| }else if(tempZone == 3 && zone == 4){ | |
| totalEXP+=60; | |
| }else if(tempZone == 4 && zone == 5){ | |
| totalEXP+=100; | |
| }else if(tempZone == 5 && zone == 0){ | |
| totalEXP+=100; | |
| if(fullCourse)totalEXP+=200; | |
| fullCourse = true; | |
| laps++; | |
| }else{ | |
| fullCourse = false; | |
| } | |
| tempZone = zone; | |
| } | |
| } | |
| //Gives the script a loop structure | |
| @Override | |
| public void run() { | |
| if(onStart()){ | |
| while(!Thread.interrupted() && loop()>=0){} | |
| onStop(); | |
| }else println("Script failed to start!"); | |
| } | |
| private int getZone(){ | |
| Point2D loc = EGW.getPosition(); | |
| if(egw_zone_0.contains(loc)){ | |
| return 0; | |
| }else if(egw_zone_2.contains(loc)){ | |
| if(isBlack()){ | |
| return 2; | |
| } | |
| return 1; | |
| }else if(egw_zone_1.contains(loc)){ | |
| return 1; | |
| }else if(egw_zone_3.contains(loc)){ | |
| return 3; | |
| }else if(egw_zone_4.contains(loc)){ | |
| return 4; | |
| }else if(egw_zone_5.contains(loc)){ | |
| return 5; | |
| } | |
| return -1; | |
| } | |
| private boolean isBlack() { | |
| int count = 0; | |
| for(int i = 0; i < black.npoints; i++){ | |
| Point pt = EGW.posToMM(black.xpoints[i], black.ypoints[i]); | |
| if(!Screen.coloursMatch(Screen.getColourAt(pt), (Color.BLACK), new Tolerance(15,15,15)))count++; | |
| if(count >= 2)return false; | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment