Created
June 4, 2012 02:56
-
-
Save TheBatScripts/2866076 to your computer and use it in GitHub Desktop.
PinBall
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.Point; | |
| import java.awt.Rectangle; | |
| import java.awt.event.KeyEvent; | |
| import org.tribot.api.General; | |
| import org.tribot.api.colour.DTMs; | |
| import org.tribot.api.colour.types.ColourPoint; | |
| import org.tribot.api.colour.types.DTM; | |
| import org.tribot.api.colour.types.DTMPoint; | |
| import org.tribot.api.colour.types.DTMSubPoint; | |
| 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.types.ScreenModel; | |
| import org.tribot.script.Script; | |
| import org.tribot.script.ScriptManifest; | |
| @ScriptManifest (authors = { "TheBat" }, category = "Randoms", name = "PinBall") | |
| public class PinBall extends Script{ | |
| final Rectangle VIEWPORT = new Rectangle(3, 3, 513, 334); | |
| final long [] posts = {1135902842L,985085052L,2222730729L,3038238976L,1051239276L}; | |
| final long cave = 2885945863L, film = 1370947984L; | |
| DTMPoint RING_DTM_PT = new DTMPoint(new Color(111, 223, 143), new Tolerance(20, 20, 20)); | |
| DTMSubPoint [] RING_DTM_PTS = { new DTMSubPoint(new ColourPoint(new Point(14, -1), new Color( 112, 219, 144)), new Tolerance(20, 20, 20),1), new DTMSubPoint(new ColourPoint(new Point(16, 14), new Color( 117, 211, 146)), new Tolerance(20, 20, 20),1), new DTMSubPoint(new ColourPoint(new Point(2, 19), new Color( 109, 219, 140)), new Tolerance(20, 20, 20),1)}; | |
| DTM dtmRing = new DTM(RING_DTM_PT, RING_DTM_PTS); | |
| DTMPoint TEN_DTM_PT = new DTMPoint(new Color(226, 227, 37), new Tolerance(10, 10, 10)); | |
| DTMSubPoint [] TEN_DTM_PTS = { new DTMSubPoint(new ColourPoint(new Point(0, 13), new Color( 228, 224, 40)), new Tolerance(10, 10, 10),1), new DTMSubPoint(new ColourPoint(new Point(18, 8), new Color( 228, 224, 40)), new Tolerance(10, 10, 10),1), new DTMSubPoint(new ColourPoint(new Point(13, 14), new Color( 203, 202, 9)), new Tolerance(10, 10, 10),1), new DTMSubPoint(new ColourPoint(new Point(9, 9), new Color( 228, 224, 40)), new Tolerance(10, 10, 10),1), new DTMSubPoint(new ColourPoint(new Point(14, -1), new Color( 229, 224, 40)), new Tolerance(10, 10, 10),1), new DTMSubPoint(new ColourPoint(new Point(14, -1), new Color( 229, 224, 40)), new Tolerance(10, 10, 10),1)}; | |
| DTM dtmTen = new DTM(TEN_DTM_PT, TEN_DTM_PTS); | |
| public void run() { | |
| while(DTMs.find(dtmTen, VIEWPORT.x, VIEWPORT.y, VIEWPORT.x+VIEWPORT.width, VIEWPORT.y+VIEWPORT.height).length < 1){ | |
| DTM [] points; | |
| while((points = DTMs.find(dtmRing, VIEWPORT.x, VIEWPORT.y, VIEWPORT.x+VIEWPORT.width, VIEWPORT.y+VIEWPORT.height)).length < 1); | |
| ScreenModel post = findClosest(averagePoint(points),posts); | |
| Mouse.click(post.base_point,1); | |
| sleep(4575,5595); | |
| } | |
| while(ScreenModels.find(film).length > 0){ | |
| Mouse.clickBox(535, 15,552, 36, 1); | |
| int k = -1; | |
| ScreenModel [] out = null; | |
| while(k < 0){ | |
| try{ | |
| Keyboard.pressKey((char)KeyEvent.VK_DOWN); | |
| Keyboard.pressKey((char)KeyEvent.VK_RIGHT); | |
| while((out = ScreenModels.find(cave)).length < 1 || !VIEWPORT.contains(out[0].base_point) || ScreenModels.find(film).length < 1){ | |
| sleep(75,125); | |
| } | |
| Keyboard.releaseKey((char)KeyEvent.VK_RIGHT); | |
| Keyboard.releaseKey((char)KeyEvent.VK_DOWN); | |
| k = 3; | |
| }catch(Exception e){ | |
| k = -1; | |
| } | |
| } | |
| if(ScreenModels.find(film).length > 0){ | |
| Mouse.click(new Point(out[0].base_point.x+General.random(43, 58),out[0].base_point.y), 3); | |
| sleep(125,175); | |
| k = -1; | |
| while(k < 0){ | |
| try{ | |
| Game.chooseOption("Exit"); | |
| k = 3; | |
| }catch(Exception e){ | |
| k = -1; | |
| } | |
| } | |
| sleep(2500,3000); | |
| } | |
| } | |
| } | |
| private ScreenModel findClosest(Point pt, long[] ids) { | |
| int k = -1; | |
| ScreenModel out = null; | |
| while(k < 0){ | |
| try{ | |
| ScreenModel [] allMods = ScreenModels.find(ids); | |
| if(allMods.length > 0 && allMods[0] != null)out = allMods[0]; | |
| else continue; | |
| for(int i = 0; i < allMods.length; i++){ | |
| ScreenModel test = allMods[i]; | |
| if(test != null){ | |
| if(Point.distance(test.base_point.x, test.base_point.y, pt.x, pt.y)< | |
| Point.distance(out.base_point.x, out.base_point.y, pt.x, pt.y)){ | |
| if(VIEWPORT.contains(test.base_point))out = test; | |
| } | |
| } | |
| } | |
| if(out != null)k = 3; | |
| }catch(NullPointerException e){ | |
| k = -1; | |
| } | |
| } | |
| return out; | |
| } | |
| private Point averagePoint(DTM[] pts) { | |
| int totX = 0; | |
| int totY = 0; | |
| for(int i = 0; i < pts.length; i++){ | |
| totX += buildRec(pts [i]).getCenterX(); | |
| totY += buildRec(pts [i]).getCenterY(); | |
| } | |
| return new Point (totX/pts.length,totY/pts.length); | |
| } | |
| private Rectangle buildRec(DTM dtm) { | |
| Point minPoint = new Point(800, 600), maxPoint = new Point(0, 0); | |
| for(int i = 0; i < dtm.sub_points.length; i++) { | |
| if(dtm.sub_points[i].colourPoint.point.x < minPoint.x) minPoint.x = dtm.sub_points[i].colourPoint.point.x; | |
| if(dtm.sub_points[i].colourPoint.point.x > maxPoint.x) maxPoint.x = dtm.sub_points[i].colourPoint.point.x; | |
| if(dtm.sub_points[i].colourPoint.point.y < minPoint.y) minPoint.y = dtm.sub_points[i].colourPoint.point.y; | |
| if(dtm.sub_points[i].colourPoint.point.y > maxPoint.y) maxPoint.y = dtm.sub_points[i].colourPoint.point.y; | |
| } | |
| if(dtm.main_point.point.x < minPoint.x) minPoint.x = dtm.main_point.point.x; | |
| if(dtm.main_point.point.x > maxPoint.x) maxPoint.x = dtm.main_point.point.x; | |
| if(dtm.main_point.point.y < minPoint.y) minPoint.y = dtm.main_point.point.y; | |
| if(dtm.main_point.point.y > maxPoint.y) maxPoint.y = dtm.main_point.point.y; | |
| return new Rectangle(minPoint.x, minPoint.y, (maxPoint.x - minPoint.x) + 1, (maxPoint.y - minPoint.y) + 1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment