Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.45 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5. import java.awt.Point;
  6. import java.awt.Rectangle;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.MouseListener;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.util.List;
  12.  
  13. import javax.imageio.ImageIO;
  14.  
  15. import com.rarebot.script.Script;
  16. import com.rarebot.script.ScriptManifest;
  17. import com.rarebot.script.methods.Bank;
  18. import com.rarebot.script.methods.Camera;
  19. import com.rarebot.script.methods.Game;
  20. import com.rarebot.script.methods.ImageUtil;
  21. import com.rarebot.script.methods.Mouse;
  22. import com.rarebot.script.methods.OCR;
  23. import com.rarebot.script.util.Random;
  24. import com.rarebot.script.util.Timer;
  25. @ScriptManifest(
  26. authors = { "TheBat"},
  27. name = "BatCooker",
  28. version = 1.0,
  29. description = "Cooks fish at the rogues den.",
  30. keywords = {},
  31. language = { true, true, true, true })
  32.  
  33. public class BatCooker extends Script implements MouseListener{
  34.  
  35. final private static Color fire = new Color(203,125,35);
  36. final private static Color bankerF = new Color(108,124,55);
  37. final private static Color bankerB = new Color(30,41,23);
  38. final private static Rectangle viewPort = new Rectangle(4,4,513,335);
  39. private static String status = "";
  40. private static Image pic = null;
  41. private static long TIME = 0;
  42. private boolean showPaint = true;
  43. private int cooked = 0;
  44. private int row = 0;
  45. private int col = 0;
  46. private boolean first;
  47. Color temp = null;
  48. Color raw = null;
  49. private boolean getColor = true;
  50.  
  51. public boolean onStart(){
  52. TIME = System.currentTimeMillis();
  53. try {
  54. pic = ImageIO.read(new URL("http://i1024.photobucket.com/albums/y308/dudebrosick/fire.png"));
  55. } catch (IOException e) {
  56. }
  57. status = "Finding banker";
  58. return true;
  59. }
  60.  
  61. public int loop() {
  62. Mouse.setSpeed(Random.random(6,12));
  63. if(status.equals("Finding banker")){
  64. Mouse.setSpeed(2);
  65. Point bankerPt = findBanker();
  66. if(bankerPt.x == -1){
  67. Mouse.move(Random.random(0,517),Random.random(0,339));
  68. if(Bank.isOpen()){
  69. status = "Banking";
  70. return 100;
  71. }
  72. Camera.rotateLeft(300);
  73. Camera.pitchDown(300);
  74. return 100;
  75. }
  76. Mouse.click(bankerPt, false);
  77. Script.sleep(100);
  78. String lol = OCR.findString(new Rectangle(bankerPt.x-200,bankerPt.y+30, 200,25), null);
  79. if(lol.contains("Bank"))Mouse.click(bankerPt.x,bankerPt.y+46);
  80. else return 100;
  81. int i = 0;
  82. while(!Bank.isOpen() && i <= 40){
  83. Script.sleep(100);
  84. i++;
  85. }
  86. if(Bank.isOpen()){
  87. status = "Banking";
  88. }
  89. return 100;
  90. }
  91. if(status.equals("Banking")){
  92. if(Bank.isOpen()){
  93. if(getColor ){
  94. raw = Game.getColorAt(51,111);
  95. getColor = false;
  96. }
  97. int x = Random.random(50, 60);
  98. int y = Random.random(100, 110);
  99. Bank.depositAll();
  100. sleep(500,700);
  101. Mouse.click(x,y,false);
  102. sleep(500,700);
  103. Mouse.click(x, (y + Random.random(103,126)));
  104. sleep(500,700);
  105. Mouse.move(489,30);
  106. if(Mouse.getLocation()!= new Point(489,30)) Mouse.move(489,30);
  107. sleep(200,300);
  108. Mouse.click();
  109. sleep(100,200);
  110. Mouse.move(Random.random(0,765), Random.random(0,502));
  111. sleep(400,500);
  112. }
  113. status = "Finding fire";
  114. return 100;
  115. }
  116. if(status.equals("Finding fire")){
  117. if(Game.getColorAt(343,427).equals(new Color(89,81,68))){
  118. status = "Cooking";
  119. return 100;
  120. }
  121. Camera.pitchUp(300);
  122. sleep(100);
  123. Camera.rotateLeft(300);
  124. Mouse.click(Random.random(567,587),Random.random(219,240));
  125. Mouse.setSpeed(2);
  126. Point firePt = findFire();
  127. sleep(300);
  128. if(firePt.x == -1)return 100;
  129. Mouse.click(firePt,false);
  130. sleep(200);
  131. boolean found = false;
  132. int k = 0;
  133. if(checkColor(Color.WHITE,new Point(firePt.x,firePt.y+72),4)){
  134. k = 1;
  135. found = true;
  136. }else{
  137. for(; k <= 12; k++){
  138. if(Game.getColorAt(343,427).equals(new Color(89,81,68))){
  139. status = "Cooking";
  140. return 100;
  141. }
  142. String lol = OCR.findString(new Rectangle(firePt.x-60,firePt.y+(17*k),350,21), null);
  143. Mouse.move(firePt.x,firePt.y+(17*k)+11);
  144. if(lol.contains("Fire")){
  145. found = true;
  146. break;
  147. }
  148. if(checkColor(Color.WHITE,new Point(firePt.x,firePt.y+((k + 1)*17)),4)){
  149. found = true;
  150. break;
  151. }
  152.  
  153. }
  154. }
  155. if(found)Mouse.click(firePt.x,firePt.y+(17*k)+11);
  156. sleep(1000);
  157. if(Game.getColorAt(343,427).equals(new Color(89,81,68)))status = "Cooking";
  158. row = 0;
  159. col = 0;
  160. first = true;
  161. if(!checkColor(raw,new Point(576,232),10)){
  162. status = "Finding banker";
  163. return 100;
  164. }
  165. return 100;
  166. }
  167.  
  168. if(status.equals("Cooking")){
  169. if(first){
  170. temp = Game.getColorAt(576+84 ,232);
  171. Mouse.click(Random.random(240,282),Random.random(405,455));
  172. first = false;
  173. }
  174.  
  175. if(!temp.equals(Game.getColorAt(576 + (col*42),232 + (row*36)))){
  176. col++;
  177. cooked++;
  178. if(col == 4){
  179. col = 0;
  180. row++;
  181. if(row == 7){
  182. status = "Finding banker";
  183. return 100;
  184. }
  185. }
  186. return 100;
  187. }
  188. return 100;
  189. }
  190.  
  191. return 100;
  192. }
  193. public void onRepaint(Graphics g){
  194. if(showPaint){
  195. g.setColor(new Color(203,186,153));
  196. g.fillRect(7,345,505,128);
  197. g.setColor(Color.BLACK);
  198. g.setFont(new Font("Salaryman", 1, 18));
  199. g.drawString("Time Running : " + Timer.getTime(System.currentTimeMillis() - TIME), 11, 365);
  200. g.drawString("Total Cooked: " + cooked ,11,390);
  201. g.drawString("Cooks/Hour: " + (int)((long)(cooked*3600000)/(System.currentTimeMillis() - TIME)),11,415);
  202. g.drawString("Status: " + status ,11,440);
  203. g.drawImage(pic, 240, 300, null, null);
  204.  
  205. g.setFont(new Font("Salaryman", 1, 25));
  206. g.drawString("BatCooker",270,390);
  207. g.drawString("Version 1.0",265,420);
  208. g.setColor(Color.ORANGE);
  209. g.drawString("Ve",265,420);
  210. g.setColor(Color.RED);
  211. g.drawString("x",500,360);
  212. }else{
  213. g.setColor(Color.GREEN);
  214. g.setFont(new Font("Salaryman", 1, 25));
  215. g.drawString("o",500,360);
  216. }
  217.  
  218. g.setColor(Color.CYAN);
  219. g.drawLine(Mouse.getLocation().x,0,Mouse.getLocation().x,2100);
  220. g.drawLine(0,Mouse.getLocation().y,2100,Mouse.getLocation().y);
  221. }
  222.  
  223. private static Point findBanker(){
  224. Point thePoint = new Point();
  225. List<Point> test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, bankerF,.05);
  226. try{
  227. if(test.size() < 1)throw new IllegalArgumentException();
  228. thePoint = test.get(Random.random(0,test.size()-1));
  229. }catch(IllegalArgumentException e){
  230. try{
  231. test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, bankerB,.02);
  232. if(test.size() < 1)throw new IllegalArgumentException();
  233. thePoint = test.get(Random.random(0,test.size()-1));
  234. }catch(IllegalArgumentException e2){
  235. thePoint = new Point(-1,-1);
  236. }
  237. }
  238. return thePoint;
  239. }
  240. private static Point findFire(){
  241. Point thePoint = new Point();
  242. List<Point> test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, fire,.05);
  243. try{
  244. if(test.size() < 1)throw new IllegalArgumentException();
  245. thePoint = test.get(Random.random(0,test.size()-1));
  246. }catch(IllegalArgumentException e){
  247. // try{
  248. // test = ImageUtil.getPointsWithColor(Game.getImage(), viewPort, bankerB,.02);
  249. // if(test.size() < 1)throw new IllegalArgumentException();
  250. // thePoint = test.get(Random.random(0,test.size()-1));
  251. // }catch(IllegalArgumentException e2){
  252. thePoint = new Point(-1,-1);
  253. // }
  254. }
  255. return thePoint;
  256. }
  257. /**
  258. * Returns whether the given point is a certain color.
  259. * Accounts for the variable colors that runescape produces whenever you log in.
  260. * @param col
  261. * - Color to check for.
  262. * @param p
  263. * - Point to check at.
  264. * @return
  265. */
  266. private boolean checkColor(Color col, Point p, int tol){
  267. if(Math.abs(col.getRed() - Game.getColorAt(p).getRed()) < tol)
  268. if(Math.abs(col.getGreen() - Game.getColorAt(p).getGreen()) < tol)
  269. if(Math.abs(col.getBlue() - Game.getColorAt(p).getBlue()) < tol)
  270. return true;
  271. return false;
  272. }
  273. /**
  274. * Mouse listener
  275. */
  276. public void mouseClicked(MouseEvent e) {
  277. Point pt = e.getPoint();
  278. if (pt.x >= 499 && pt.x <= 512 && pt.y >= 345 && pt.y <= 360) {
  279. showPaint = !showPaint;
  280. }
  281. }
  282. public void mouseEntered(MouseEvent arg0) {}
  283. public void mouseExited(MouseEvent arg0) {}
  284. public void mousePressed(MouseEvent arg0) {}
  285. public void mouseReleased(MouseEvent arg0) {}
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement