Created
June 12, 2012 04:24
-
-
Save TheBatScripts/2914947 to your computer and use it in GitHub Desktop.
BatIvy 1.23
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.MouseInfo; | |
| import java.awt.Point; | |
| import java.awt.Rectangle; | |
| import java.awt.event.KeyEvent; | |
| import java.awt.event.MouseEvent; | |
| import java.awt.image.BufferedImage; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.util.ArrayList; | |
| import javax.imageio.ImageIO; | |
| import org.tribot.api.General; | |
| import org.tribot.api.Timing; | |
| import org.tribot.api.colour.GameTab; | |
| import org.tribot.api.colour.Screen; | |
| import org.tribot.api.colour.types.Tolerance; | |
| import org.tribot.api.input.Keyboard; | |
| import org.tribot.api.input.Mouse; | |
| import org.tribot.api.togl.Game; | |
| import org.tribot.api.togl.ScreenModels; | |
| import org.tribot.api.togl.Text; | |
| import org.tribot.api.togl.types.ScreenModel; | |
| import org.tribot.api.togl.types.TextChar; | |
| import org.tribot.bot.ClientContext; | |
| import org.tribot.script.Script; | |
| import org.tribot.script.ScriptManifest; | |
| import org.tribot.script.interfaces.EventBlockingOverride; | |
| import org.tribot.script.interfaces.Painting; | |
| @ScriptManifest (authors = { "TheBat" }, category = "WoodCutting", name = "BatIvy", | |
| description="<html>"+ | |
| "<h1 align=\"center\"><img style=\"WIDTH: 393px; HEIGHT: 229px\" "+ | |
| "border=0 hspace=0 src=\"http://i.imgur.com/FPDbJ.png\" width=393 height=229></h1>"+ | |
| "</html>") | |
| public class BatIvy extends Script implements Painting, EventBlockingOverride { | |
| Point[] IVY_DTM_PTS = { new Point( 279, 71), new Point( 278, 65)}; | |
| Color[] IVY_DTM_RGB = { new Color( 93, 124, 64), new Color( 100, 134, 68)}; | |
| DTM dtmIvy = new DTM(IVY_DTM_PTS, IVY_DTM_RGB); | |
| Point[] BIG_IVY_DTM_PTS = { new Point( 250, 128), new Point( 254, 105), new Point( 265, 116), new Point( 264, 129)}; | |
| Color[] BIG_IVY_DTM_RGB = { new Color( 95, 127, 66), new Color( 99, 132, 68), new Color( 94, 125, 65), new Color( 95, 127, 66)}; | |
| DTM dtmBigIvy = new DTM(BIG_IVY_DTM_PTS, BIG_IVY_DTM_RGB); | |
| final Rectangle VIEWPORT = new Rectangle(3, 3, 513, 334); | |
| long TIME = 0; | |
| int centerX = 0; | |
| int centerY = 0; | |
| String status = "Finding ivy"; | |
| ScreenModel player = null; | |
| int tempL = -1; | |
| private boolean showPaint = true; | |
| Rectangle hideR = new Rectangle(450,300,50,20); | |
| private long CUR_ID = 0; | |
| private int cut = 0; | |
| private String version = "1.23"; | |
| private int templvl = 300; | |
| private int levelsGained = -2; | |
| private int startEXP = -1; | |
| private double EXP = 332.5; | |
| int oAm = 0; | |
| ExpChecker xpCheck = new ExpChecker(); | |
| private long lastAnti = 0, upStair = 2030098555L; | |
| private boolean first = true; | |
| private int trys = 0; | |
| private long SSTIME; | |
| private boolean onStart() { | |
| centerX = (int) VIEWPORT.getCenterX(); | |
| centerY = (int) VIEWPORT.getCenterY(); | |
| startEXP = -1; | |
| while(startEXP < 0 && trys <= 5){ | |
| try{ | |
| Mouse.clickBox(590, 176, 607, 198, 1); | |
| startEXP = Skills.getCurrentXP(Skills.SKILLS.WOODCUTTING); | |
| }catch(Exception e){ | |
| startEXP = -1; | |
| trys++; | |
| } | |
| } | |
| if(startEXP < 0){ | |
| startEXP = 0; | |
| } | |
| trys = 0; | |
| Mouse.click(new Point(659,187), 1); | |
| templvl = convertToLevel(startEXP); | |
| if(!dtmBigIvy.findDTMS(21,VIEWPORT))rotateToIvy(); | |
| player = getPlayer(); | |
| lastAnti = System.currentTimeMillis(); | |
| SSTIME = System.currentTimeMillis(); | |
| TIME = System.currentTimeMillis(); | |
| levelsGained = 0; | |
| return true; | |
| } | |
| private int loop() { | |
| if(first){ | |
| xpCheck.start(); | |
| first = false; | |
| } | |
| if((System.currentTimeMillis()-SSTIME) > 3600000){ | |
| SSTIME = System.currentTimeMillis(); | |
| BufferedImage image = ClientContext.get().imagePanel.M; | |
| onPaint(image.getGraphics()); | |
| try { | |
| File file = new File("./Storage/ScreenShots/ScreenShot.png"); | |
| file.getParentFile().mkdirs(); | |
| ImageIO.write(image, "png",file); | |
| } catch (IOException ex) { | |
| } | |
| } | |
| Mouse.setSpeed(General.random(130, 150)); | |
| if(System.currentTimeMillis()-lastAnti>240000){ | |
| Mouse.moveBox(VIEWPORT.x, VIEWPORT.y, VIEWPORT.x+VIEWPORT.width, VIEWPORT.y+VIEWPORT.height); | |
| Keyboard.pressKey((General.random(1,2) > 1) ? (char)KeyEvent.VK_LEFT : (char)KeyEvent.VK_RIGHT); | |
| sleep(General.random(100, 200)); | |
| Keyboard.releaseKey((char)KeyEvent.VK_LEFT); | |
| Keyboard.releaseKey((char)KeyEvent.VK_RIGHT); | |
| lastAnti = System.currentTimeMillis(); | |
| } | |
| if(status.equals("Finding ivy")){ | |
| if(trys >= 6){ | |
| ScreenModel [] test = null; | |
| int k = -1; | |
| while(k < 0){ | |
| try{ | |
| test = ScreenModels.find(upStair); | |
| k = -1; | |
| }catch(Exception e){ | |
| k = 3; | |
| } | |
| } | |
| if(test.length > 0){ | |
| Mouse.click(test[0].base_point, 1); | |
| } | |
| sleep(205,285); | |
| rotateToIvy(); | |
| trys = 0; | |
| } | |
| if(dtmIvy.findDTMS(20, VIEWPORT)){ | |
| Rectangle rec = dtmIvy.getList().get(General.random(0,dtmIvy.getList().size()-1)); | |
| Mouse.move(new Point(General.random(rec.x, rec.x + rec.width),General.random(rec.y, rec.y + rec.height))); | |
| sleep(General.random(100, 200)); | |
| try{ | |
| if(Game.getUptext().contains("Chop")){ | |
| Mouse.click(Mouse.getPos(), 1); | |
| trys = 0; | |
| }else{ | |
| trys++; | |
| return 100; | |
| } | |
| }catch(Exception e){ | |
| return 100; | |
| } | |
| int k = 0; | |
| while(k <= 20 && getPlayer().id == player.id){ | |
| sleep(100); | |
| } | |
| if(k<20)status = "Chopping"; | |
| }else rotateToIvy(); | |
| return 100; | |
| } | |
| if(status.equals("Chopping")){ | |
| try{ | |
| int k = 0; | |
| while(k <= 8 && getPlayer().id == player.id){ | |
| sleep(100); | |
| k++; | |
| } | |
| if(k > 8)status = "Finding ivy"; | |
| else{ | |
| if(General.random(0,180000000) < 100){ | |
| Mouse.moveBox(VIEWPORT.x, VIEWPORT.y, VIEWPORT.x+VIEWPORT.width, VIEWPORT.y+VIEWPORT.height); | |
| Keyboard.pressKey((General.random(1,2) > 1) ? (char)KeyEvent.VK_LEFT : (char)KeyEvent.VK_RIGHT); | |
| sleep(General.random(100, 200)); | |
| Keyboard.releaseKey((char)KeyEvent.VK_LEFT); | |
| Keyboard.releaseKey((char)KeyEvent.VK_RIGHT); | |
| lastAnti = System.currentTimeMillis(); | |
| } | |
| } | |
| }catch(NullPointerException e){} | |
| return 100; | |
| } | |
| return 100; | |
| } | |
| private void rotateToIvy() { | |
| Mouse.clickBox(535, 15,552, 36, 1); | |
| Keyboard.pressKey((char)KeyEvent.VK_UP); | |
| sleep(600); | |
| Keyboard.releaseKey((char)KeyEvent.VK_UP); | |
| Keyboard.pressKey((General.random(1,2) > 1) ? (char)KeyEvent.VK_LEFT : (char)KeyEvent.VK_RIGHT); | |
| while(!dtmBigIvy.findDTMS(21,VIEWPORT)){ | |
| sleep(50); | |
| dtmIvy.getList().clear(); | |
| } | |
| Keyboard.releaseKey((char)KeyEvent.VK_LEFT); | |
| Keyboard.releaseKey((char)KeyEvent.VK_RIGHT); | |
| } | |
| private ScreenModel getPlayer() { | |
| int k = -1; | |
| ScreenModel ply = null; | |
| while(k < 0){ | |
| try{ | |
| ScreenModel [] allMods = ScreenModels.getAll(); | |
| if(allMods.length > 0 && allMods[0] != null)ply = allMods[0]; | |
| else continue; | |
| for(int i = 0; i < allMods.length; i++){ | |
| ScreenModel test = allMods[i]; | |
| if(test != null && test.id != 3397519456L){ | |
| if(Point.distance(test.base_point.x, test.base_point.y, centerX, centerY)< | |
| Point.distance(ply.base_point.x, ply.base_point.y, centerX, centerY)){ | |
| if(VIEWPORT.contains(test.base_point))ply = test; | |
| } | |
| } | |
| } | |
| k = 3; | |
| }catch(NullPointerException e){ | |
| k = -1; | |
| } | |
| } | |
| CUR_ID = ply.id; | |
| return ply; | |
| } | |
| @SuppressWarnings("deprecation") | |
| private void onStop() { | |
| xpCheck.interrupt(); | |
| xpCheck.destroy(); | |
| } | |
| public void onPaint(Graphics g) { | |
| final Color OPAQUE_BLACK = new Color(0, 0, 0, 180); | |
| final Color GREEN = new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue(), 175).darker(); | |
| final Color WHITE = new Color(Color.WHITE.getRed(), Color.WHITE.getGreen(), Color.WHITE.getBlue(), 175).darker(); | |
| final int CUR_XP = (int) (startEXP + (EXP * cut)); | |
| final int CUR_LVL = convertToLevel(CUR_XP); | |
| if(templvl < CUR_LVL) levelsGained++; | |
| templvl = CUR_LVL; | |
| final double percentage = percentToNext(CUR_XP); | |
| if(showPaint){ | |
| g.setColor(new Color(0,0,0,175)); | |
| g.fill3DRect(1, 215, 515, 123, true); | |
| int idx = 213; | |
| g.setColor(Color.WHITE); | |
| g.drawString("Time Running: " + Timing.msToString(System.currentTimeMillis() - TIME), 5, idx+=20); | |
| g.setColor(Color.GREEN); | |
| g.drawString("BatIvy", 270,idx); | |
| g.setColor(Color.WHITE); | |
| g.drawString("Bat", 270,idx); | |
| g.drawString("Total cut: " + cut, 5, idx+=20); | |
| g.drawString("Version " + version, 270,idx); | |
| try{ | |
| g.drawString("Player ID: " + player.id + "/" + CUR_ID, 5, idx+=20); | |
| }catch(Exception e){ | |
| g.drawString("Player ID: Finding", 5, idx+=20); | |
| } | |
| try{ | |
| g.drawString("Exp./Hour: " + (int)(EXP *(3600000*(long)cut)/(System.currentTimeMillis() - TIME)), 5, idx+=20); | |
| }catch(Exception e){} | |
| g.drawString("Status: " + status, 5, idx+=20); | |
| g.setColor(OPAQUE_BLACK); | |
| g.fill3DRect(5, idx+=5, 270, 17, true); | |
| g.setColor(GREEN); | |
| g.fillRect(6, idx+1, (int) (268 * percentage), 15); | |
| g.setColor(Color.WHITE); | |
| try{ | |
| g.drawString("Current Level: " + CUR_LVL + "(+" + levelsGained + ") | " + (int)(100*percentage) +"% to " + (CUR_LVL+1) + " | TTL: " + Timing.msToString((System.currentTimeMillis() - TIME)*(xpRemaing(CUR_XP))/(long)(EXP * cut)),8,idx+=13); | |
| }catch(Exception e){ | |
| g.drawString("Current Level: " + CUR_LVL + "(+" + levelsGained + ") | " + (int)(100*percentage) +"% to " + (CUR_LVL+1) + " | TTL: " + Timing.msToString(0),8,idx+=13); | |
| } | |
| if(new Rectangle(hideR.x+ClientContext.get().imagePanel.getLocationOnScreen().x, hideR.y+ClientContext.get().imagePanel.getLocationOnScreen().y, hideR.width, hideR.height).contains(MouseInfo.getPointerInfo().getLocation())){ | |
| g.setColor(GREEN); | |
| g.fillRect(hideR.x, hideR.y, hideR.width, hideR.height); | |
| g.setColor(Color.WHITE); | |
| } | |
| g.drawRect(hideR.x, hideR.y, hideR.width, hideR.height); | |
| g.drawString("Hide",hideR.x+10,hideR.y+15); | |
| }else{ | |
| if(new Rectangle(hideR.x+ClientContext.get().imagePanel.getLocationOnScreen().x, hideR.y+ClientContext.get().imagePanel.getLocationOnScreen().y, hideR.width, hideR.height).contains(MouseInfo.getPointerInfo().getLocation())){ | |
| g.setColor(WHITE); | |
| g.fillRect(hideR.x, hideR.y, hideR.width, hideR.height); | |
| } | |
| g.setColor(Color.BLACK); | |
| g.drawRect(hideR.x, hideR.y, hideR.width, hideR.height); | |
| g.drawString("Show",hideR.x+10,hideR.y+15); | |
| } | |
| g.setColor(Color.RED); | |
| g.fillOval(centerX-2, centerY-2, 4, 4); | |
| g.drawRect(VIEWPORT.x, VIEWPORT.y, VIEWPORT.width, VIEWPORT.height); | |
| } | |
| public OVERRIDE_RETURN overrideKeyEvent(KeyEvent arg0) { | |
| return OVERRIDE_RETURN.PROCESS; | |
| } | |
| public OVERRIDE_RETURN overrideMouseEvent(MouseEvent e) { | |
| if(hideR.contains(e.getPoint())){ | |
| if(e.getID() == MouseEvent.MOUSE_CLICKED){ | |
| e.consume(); | |
| showPaint = !showPaint; | |
| return OVERRIDE_RETURN.DISMISS; | |
| }else if(e.getID() == MouseEvent.MOUSE_PRESSED)return OVERRIDE_RETURN.DISMISS; | |
| } | |
| return OVERRIDE_RETURN.PROCESS; | |
| } | |
| /** | |
| * Gives the percent to the next level given the current exp amount. (multiply by 100 for common percent value). | |
| * @param int xp - the current amount of xp. | |
| * @return double percent - the percent of the next level complete. | |
| */ | |
| public static double percentToNext(int xp){ | |
| return 1-(double)xpRemaing(xp)/(double)(minXPForLevel(convertToLevel(xp))-minXPForLevel(convertToLevel(xp)-1)); | |
| } | |
| /** | |
| * Gives the total amount of experience needed to attain the next level up. | |
| * @param int xp - the current amount of xp. | |
| * @return int xp - the amount remaining. | |
| */ | |
| public static int xpRemaing(int xp) { | |
| return minXPForLevel(convertToLevel(xp))-xp; | |
| } | |
| /** | |
| * Gives the minimum amount of experience needed to attain the given level. | |
| * @param int level - the level that needs to be reached. | |
| * @return the minimum amount of experience possible at that level. | |
| */ | |
| public static int minXPForLevel(int level) { | |
| if(level > 0)return (int)(.25*(int)(level + 300.0 * Math.pow(2.0, (double)level/7.0)) + (int)minXPForLevel(--level)); | |
| return 0; | |
| } | |
| /** | |
| * Returns the maximum level possible at the given xp amount. | |
| * @param xp - the current amount of xp. | |
| * @return int level - the maximum level possible at the given xp amount. | |
| */ | |
| public static int convertToLevel(int xp) { | |
| for(int i = 1; i < 121; i++){ | |
| if(xp < minXPForLevel(i)){ | |
| return i; | |
| } | |
| } | |
| return 1; | |
| } | |
| public void run() { | |
| if(onStart()){ | |
| while(!Thread.interrupted() && loop()>=0){} | |
| onStop(); | |
| }else println("Script failed to start!"); | |
| } | |
| class DTM { | |
| private final Color[] rgb; | |
| private final Point[] loc; | |
| private Rectangle box; | |
| private final String name; | |
| public ArrayList<Rectangle> dtmLocations = new ArrayList<Rectangle>(); | |
| private ArrayList<Rectangle> dtmLocationsNS = new ArrayList<Rectangle>(); | |
| public DTM(final Point[] loc, final Color[] color, final String name) { | |
| this.loc = loc; | |
| this.rgb = color; | |
| this.name = name; | |
| box = createRectangleFromPoints(loc); | |
| } | |
| public DTM(final Point[] loc, final Color[] color) { | |
| this(loc, color, "DTM"); | |
| } | |
| /** | |
| * Given a set of points create a rectangle that encases all of those points | |
| * @param points : set of points to create a rectangle with | |
| * @return : A rectangle that encloses all points | |
| */ | |
| private Rectangle createRectangleFromPoints(final Point[] points) { | |
| Point minPoint = new Point(800, 600), maxPoint = new Point(0, 0); | |
| for(int i = 0; i < loc.length; i++) { | |
| if(points[i].x < minPoint.x) minPoint.x = points[i].x; | |
| if(points[i].x > maxPoint.x) maxPoint.x = points[i].x; | |
| if(points[i].y < minPoint.y) minPoint.y = points[i].y; | |
| if(points[i].y > maxPoint.y) maxPoint.y = points[i].y; | |
| } | |
| return new Rectangle(minPoint.x, minPoint.y, (maxPoint.x - minPoint.x) + 1, (maxPoint.y - minPoint.y) + 1); | |
| } | |
| /** | |
| * Looks for the DTM in the original spot specified | |
| * @param tol : tolerance between each RGB value when checking if colors are the same | |
| * @return <tt>true</tt> if a DTM was found; otherwise <tt>false</tt> | |
| */ | |
| public boolean findOriginalDTM(final int tol) { | |
| return checkAllPoints(loc[0], tol); | |
| } | |
| /** | |
| * Finds all DTMs on the game screen stores and stores there location to the dtmLocations ArrayList. | |
| * @param tol : tolerance between each RGB value when checking if colors are the same | |
| * @return <tt>true</tt> if a DTM was found; otherwise <tt>false</tt> | |
| */ | |
| public boolean findDTMS(final int tol) { | |
| return findDTMS(tol, new Rectangle(0, 0, Screen.getDimension().width, Screen.getDimension().height)); | |
| } | |
| /** | |
| * Searches for DTMs in in the rectangle passed and stores all DTMs found to the dtmLocations ArrayList. | |
| * @param tol : tolerance between each RGB value when checking if colors are the same | |
| * @param rec : Rectangle to search for the DTM to be in. | |
| * @return <tt>true</tt> if a DTM was found; otherwise <tt>false</tt> | |
| */ | |
| public boolean findDTMS(final int tol, final Rectangle rec) { | |
| boolean foundDTM = false; | |
| dtmLocations.clear(); | |
| dtmLocationsNS.clear(); | |
| for(int y = rec.y; y < rec.y + rec.height; y++) { | |
| for(int x = rec.x; x < rec.x + rec.width; x++) { | |
| if(checkColor(Screen.getColourAt(new Point(x, y)), rgb[0], tol)) { | |
| final Rectangle curbox = new Rectangle(x - (loc[0].x - box.x), y - (loc[0].y - box.y), box.width, box.height); | |
| if(checkAllPoints(new Point(x, y), tol)) { | |
| dtmLocations.add(curbox); | |
| dtmLocationsNS.add(curbox); | |
| foundDTM = true; | |
| } | |
| } | |
| } | |
| } | |
| return foundDTM; | |
| } | |
| /** | |
| * Grabs the DTM specified by index in the dtms found array | |
| * @param i : index in the dtm array to grab | |
| * @return : the center point of the rectangle for the DTM or null if not found | |
| */ | |
| public Point getDTM(final int i) { | |
| return dtmLocationsNS.isEmpty() ? null : new Point(dtmLocationsNS.get(i).x + (dtmLocationsNS.get(i).width / 2), dtmLocationsNS.get(i).y + (dtmLocationsNS.get(i).height / 2)); | |
| } | |
| /** | |
| * | |
| * @param gameS game screen colors array | |
| * @param locM location of point that matches the first color in the array list colorB | |
| * @return true if all colors match | |
| */ | |
| private boolean checkAllPoints(Point locM, final int tol) { | |
| try { | |
| final Point locI = loc[0]; | |
| for(int i = 0; i < loc.length; i++) { | |
| // we can come back and shorten this, but for now this is to make sure we make no mistakes | |
| final Color initialColor = rgb[i]; | |
| final Point initialColorPoint = loc[i]; | |
| final int xshift = initialColorPoint.x - locI.x; | |
| final int yshift = initialColorPoint.y - locI.y; | |
| final Point pointToCheck = new Point(locM.x + xshift, locM.y + yshift); | |
| final Color colorToCheck = Screen.getColourAt(pointToCheck); | |
| if(!checkColor(initialColor, colorToCheck, tol)) return false; | |
| } | |
| return true; | |
| } catch (Exception e) { | |
| return false; | |
| } | |
| } | |
| /** | |
| * Checks to see if the 2 colors passed match | |
| * @param c : Color 1 | |
| * @param c2 : Color 2 | |
| * @param tol : tolerance between each RGB value when checking if colors are the same | |
| * @return <tt>true</tt> if colors match; otherwise <tt>false</tt> | |
| */ | |
| private boolean checkColor(final Color c, final Color c2, final int Tol) { | |
| return (checkColor(c.getRed(), c2.getRed(), Tol) | |
| && checkColor(c.getGreen(), c2.getGreen(), Tol) && checkColor(c.getBlue(), | |
| c2.getBlue(), Tol)); | |
| } | |
| /** | |
| * Checks to see if the 2 RGB values match | |
| * @param RGB1 : RGB value 1 | |
| * @param RGB2 : RGB value 2 | |
| * @param tol : tolerance between the RGB values when checking if they are the same | |
| * @return <tt>true</tt> if RGB values match; otherwise <tt>false</tt> | |
| */ | |
| private boolean checkColor(final int RGB1, final int RGB2, final int Tol) { | |
| return Math.abs(RGB1 - RGB2) < Tol; | |
| } | |
| public void drawDTMs(Graphics g) { | |
| g.setColor(Color.RED); | |
| for(int i = 0; i < dtmLocationsNS.size(); i++) { | |
| drawX(g, dtmLocationsNS.get(i)); | |
| } | |
| } | |
| private void drawX(Graphics g, Rectangle rec) { | |
| g.setColor(Color.RED); | |
| g.drawLine(rec.x, rec.y, rec.x + rec.width, rec.y + rec.height); | |
| g.drawLine(rec.x, rec.y + rec.height, rec.x + rec.width, rec.y); | |
| } | |
| public void drawDTMSquares(Graphics g, final Color c1, boolean addname) throws Exception { | |
| for(int i = 0; i < dtmLocationsNS.size(); i++) { | |
| Rectangle dtm = dtmLocationsNS.get(i); | |
| g.setColor(c1); | |
| g.drawRect(dtm.x, dtm.y, dtm.width, dtm.height); | |
| if(!addname) return; | |
| g.setColor(Color.BLACK); | |
| g.fill3DRect(dtm.x + dtm.width - 33, dtm.y + dtm.height + 4, 41, 11, true); | |
| g.setColor(Color.WHITE); | |
| g.drawString(name + " " + i, dtm.x + dtm.width - 30, dtm.y + dtm.height + 13); | |
| } | |
| } | |
| public void fancydraw(Graphics g, Color recColor, boolean addname, boolean addX) { | |
| try { | |
| if(dtmLocationsNS.isEmpty()) return; | |
| g.setFont(g.getFont().deriveFont((float) 9)); | |
| for(int i = 0; i < dtmLocationsNS.size(); i++) { | |
| drawDTMSquares(g, recColor, addname); | |
| } | |
| if(addX) drawX(g, dtmLocationsNS.get(0)); | |
| } catch (Exception e) { | |
| General.println("Exception occured in paint"); | |
| } | |
| } | |
| public ArrayList<Rectangle> getList() { | |
| return dtmLocationsNS; | |
| } | |
| } | |
| class ExpChecker extends Thread implements Runnable { | |
| private boolean coolDown = false; | |
| long lastDetect; | |
| public ExpChecker() { | |
| this.setPriority(MIN_PRIORITY); | |
| lastDetect = System.currentTimeMillis(); | |
| } | |
| @Override | |
| public void run() { | |
| try{ | |
| while (!Thread.interrupted()) { | |
| if(!coolDown)sleep(10); | |
| if(!coolDown && Screen.coloursMatch(Screen.getColourAt(new Point(253,166)), new Color(245,178,65),new Tolerance(10,10,10))){ | |
| coolDown = true; | |
| lastDetect = System.currentTimeMillis(); | |
| cut++; | |
| } | |
| if(coolDown && (System.currentTimeMillis()-lastDetect) > 800){ | |
| coolDown = false; | |
| } | |
| } | |
| } catch (InterruptedException e) { | |
| } finally{} | |
| } | |
| } | |
| public static class Skills { | |
| /** | |
| * Opens the stats tab. | |
| */ | |
| public static void openTab(){ | |
| GameTab.open(GameTab.TABS.STATS); | |
| } | |
| /** | |
| * Returns whether the stats tab is open. | |
| * @return boolean open - true if open. | |
| * false if not open. | |
| */ | |
| public static boolean isOpen(){ | |
| return GameTab.getOpen().equals(GameTab.TABS.STATS); | |
| } | |
| /** | |
| * Gives the percent to the next level given the current exp amount. (multiply by 100 for common percent value). | |
| * @param int xp - the current amount of xp. | |
| * @return double percent - the percent of the next level complete. | |
| */ | |
| public static double percentToNext(int xp){ | |
| return 1-(double)xpRemaing(xp)/(double)(minXPForLevel(convertToLevel(xp))-minXPForLevel(convertToLevel(xp)-1)); | |
| } | |
| /** | |
| * Gives the total amount of experience needed to attain the next level up. | |
| * @param int xp - the current amount of xp. | |
| * @return int xp - the amount remaining. | |
| */ | |
| public static int xpRemaing(int xp) { | |
| return minXPForLevel(convertToLevel(xp))-xp; | |
| } | |
| /** | |
| * Gives the minimum amount of experience needed to attain the given level. | |
| * @param int level - the level that needs to be reached. | |
| * @return the minimum amount of experience possible at that level. | |
| */ | |
| public static int minXPForLevel(int level) { | |
| if(level > 0)return (int)(.25*(int)(level + 300.0 * Math.pow(2.0, (double)level/7.0)) + (int)minXPForLevel(--level)); | |
| return 0; | |
| } | |
| /** | |
| * Returns the maximum level possible at the given xp amount. | |
| * @param xp - the current amount of xp. | |
| * @return int level - the maximum level possible at the given xp amount. | |
| */ | |
| public static int convertToLevel(int xp) { | |
| for(int i = 1; i < 121; i++){ | |
| if(xp < minXPForLevel(i)){ | |
| return i; | |
| } | |
| } | |
| return 1; | |
| } | |
| /** | |
| * Return the current amount of xp in the given skill. | |
| * @param Skill skill - the skill that you want to read. | |
| * @return int xp - The amount of xp. | |
| */ | |
| public static int getCurrentXP(SKILLS skill){ | |
| moveToSkill(skill); | |
| General.sleep(100, 200); | |
| Rectangle pop = getPopBounds(); | |
| int exp = 0; | |
| TextChar [] chars = Text.findCharsInArea(pop.x+1, pop.y+16, pop.x+pop.width-1, 15, true); | |
| String xpS = Text.lineToString(chars, 0); | |
| int i = xpS.length()-1; | |
| for(; i >= 0; i--){ | |
| if(xpS.charAt(i) == ':')break; | |
| } | |
| xpS = xpS.substring(i+1).replaceAll(",", ""); | |
| exp = Integer.parseInt(xpS); | |
| return exp; | |
| } | |
| private static void moveToSkill(SKILLS skill) { | |
| Mouse.moveBox(skill.getBounds().x, skill.getBounds().y, skill.getBounds().x+skill.getBounds().width, skill.getBounds().y+skill.getBounds().height); | |
| } | |
| private static Rectangle getPopBounds(){ | |
| final Color edge = new Color(235,236,230); | |
| Rectangle rec = SKILLS.BOUNDS; | |
| Point [] points = getPoints(edge, rec, new Tolerance(0,0,0)); | |
| int minX = points[0].x; | |
| for(int i = 0; i < points.length; i++){ | |
| if(points[i].x < minX){ | |
| minX = points[i].x; | |
| } | |
| } | |
| int maxX = points[0].x; | |
| for(int i = 0; i < points.length; i++){ | |
| if(points[i].x > maxX){ | |
| maxX = points[i].x; | |
| } | |
| } | |
| int minY = points[0].y; | |
| for(int i = 0; i < points.length; i++){ | |
| if(points[i].y < minY){ | |
| minY = points[i].y; | |
| } | |
| } | |
| int maxY = points[0].y; | |
| for(int i = 0; i < points.length; i++){ | |
| if(points[i].y > maxY){ | |
| maxY = points[i].y; | |
| } | |
| } | |
| return new Rectangle(minX,minY,maxX-minX, maxY-minY); | |
| } | |
| private static Point [] getPoints(Color c, Rectangle rec, Tolerance tol){ | |
| BufferedImage image = ClientContext.get().imagePanel.M; | |
| ArrayList<Point> builder = new ArrayList<Point>(); | |
| for(int y = rec.y; y < rec.y+rec.height; y++){ | |
| for(int x = rec.x; x < rec.x+rec.width; x++){ | |
| if(image.getRGB(x, y) == c.getRGB()) builder.add(new Point(x,y)); | |
| } | |
| } | |
| return builder.toArray(new Point[builder.size()]); | |
| } | |
| public enum SKILLS{ | |
| ATTACK("Attack", new Rectangle(550, 210, 59, 26)), | |
| STRENGTH("Strength", new Rectangle(550, 238, 59, 26)), | |
| DEFENCE("Defence", new Rectangle(550, 266, 59, 26)), | |
| RANGED("Ranged", new Rectangle(550, 294, 59, 26)), | |
| PRAYER("Prayer", new Rectangle(550, 322, 59, 26)), | |
| MAGIC("Magic", new Rectangle(550, 350, 59, 26)), | |
| RUNECRAFTING("Runecrafting", new Rectangle(550, 378, 59,26)), | |
| CONSTRUCTION("Construction", new Rectangle(550, 406, 59, 26)), | |
| DUNGEONEERING("Dungeoneering", new Rectangle(550, 434, 59, 26)), | |
| CONSTITUTION("Constitution", new Rectangle(612, 210, 59, 26)), | |
| AGILITY("Agility", new Rectangle(612, 238, 59, 26)), | |
| HERBLORE("Herblore", new Rectangle(612, 266, 59, 26)), | |
| THIEVING("Thieving", new Rectangle(612, 294, 59, 26)), | |
| CRAFTING("Crafting", new Rectangle(612, 322, 59, 26)), | |
| FLETCHING("Fletching", new Rectangle(612, 350, 59, 26)), | |
| SLAYER("Slayer", new Rectangle(612, 378, 59, 26)), | |
| HUNTER("Hunter", new Rectangle(612, 406, 59, 26)), | |
| MINING("Mining", new Rectangle(674, 210, 59, 26)), | |
| SMITHING("Smithing", new Rectangle(674, 238, 59, 26)), | |
| FISHING("Fishing", new Rectangle(674, 266, 59, 26)), | |
| COOKING("Cooking", new Rectangle(674, 294, 59, 26)), | |
| FIREMAKING("Firemaking", new Rectangle(674, 322, 59, 26)), | |
| WOODCUTTING("Woodcutting", new Rectangle(674, 350, 59, 26)), | |
| FARMING("Farming", new Rectangle(674, 378, 59, 26)), | |
| SUMMONING("Summoning", new Rectangle(674, 406, 59, 26)); | |
| private final String skill; | |
| private final Rectangle bounds; | |
| public static final Rectangle BOUNDS = new Rectangle(545, 206, 192, 260); | |
| private SKILLS(final String skill, final Rectangle bounds) { | |
| this.skill = skill; | |
| this.bounds = bounds; | |
| } | |
| /** | |
| * Gets the skill's name. | |
| * @return The skill's name. | |
| */ | |
| public String getSkill() { | |
| return skill; | |
| } | |
| /** | |
| * Gets the skill's bounding rectangle. | |
| * @return The skill's bounding rectangle. | |
| */ | |
| public Rectangle getBounds() { | |
| return bounds; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment