Advertisement
Conderoga

Untitled

Mar 14th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 KB | None | 0 0
  1. import java.awt.event.*;
  2. import java.awt.*;
  3. import java.util.*;
  4. import java.io.*;
  5. import java.net.*;
  6. import java.lang.reflect.Method;
  7. import javax.swing.*;
  8. import org.rsbot.script.*;
  9. import org.rsbot.script.methods.Game;
  10. import org.rsbot.script.methods.Skills;
  11. import org.rsbot.script.wrappers.*;
  12. import org.rsbot.event.events.MessageEvent;
  13. import org.rsbot.event.listeners.*;
  14. import javax.imageio.ImageIO;
  15.  
  16. @ScriptManifest(authors = { "Rawr & Conderoga" }, keywords = "Money Making", name = "White Berry Grabber Pro", version = 1.00,description = "Collects White Berries.")
  17. /*UpdateLog:
  18. v1.00 - initial release
  19. */
  20.  
  21. public class WhiteBerries extends Script implements PaintListener, MessageListener{
  22.  
  23. //Paint Stuff
  24. private String status = "";
  25. private boolean full = false;
  26. private long startTime;
  27. private double startTimeDbl;
  28. private int startExp;
  29. private int expGained;
  30. private int startLevel;
  31. private int levelsGained;
  32. //Money Stuff
  33. private int doOnce =0;
  34. private int whiteBerriesVal;
  35. private int lawRuneVal;
  36. private int profit = 0;
  37. private int numBerries = 0;
  38.  
  39. //IDS
  40. private int berryID = 239;
  41. private int lawID = 563;
  42.  
  43.  
  44. //Walking stuff
  45. boolean inWild = false;
  46. RSTile [] bankToCanoe = {new RSTile(3097,3496),new RSTile(3104,3503),new RSTile(3113,3508),
  47. new RSTile(3121,3515),new RSTile(3133,3513),new RSTile(3132,3508)};
  48. RSTile [] pondToTele = {new RSTile(3141,3796),new RSTile(3151,3795),new RSTile(3166,3793),
  49. new RSTile(3181,3793),new RSTile(3195,3795),new RSTile(3206,3796),
  50. new RSTile(3215,3802),new RSTile(3219,3806)};
  51. RSTile [] teleToEscape = {new RSTile(3219,3806),new RSTile(3221,3792),new RSTile(3221,3777),
  52. new RSTile(3221,3766),new RSTile(3224,3754)};
  53. RSTile [] escapeToBank = {new RSTile(3087,3496),new RSTile(3097,3495)};
  54.  
  55.  
  56.  
  57. public boolean onStart() {
  58. startTime = System.currentTimeMillis();
  59. startTimeDbl = System.currentTimeMillis();
  60. return true;
  61. }
  62.  
  63. public boolean makeCanoe(){
  64. RSObject station;
  65. RSObject [] check = objects.getAllAt(new RSTile(3131,3510));
  66. for(RSOBject o : check)
  67. if(o.getID()==12166)
  68. station=o;
  69.  
  70. if(station!=null){
  71. Point p = o.getModel().getPoint();
  72. mouse.move(p);
  73. menu.doAction("Chop-down Canoe station");
  74. sleep(random(2000,3000));
  75. mouse.move(p);
  76. menu.doAction("Shape-canoe Canoe station");
  77. sleep(random(2000,3000)); //==================================================ALL OF THESE TIMES NEED ADJUSTMENT
  78. if(interfaces.get(52)!=null)
  79. if(handleInterface(52,33,"Select")){
  80. sleep(random(2000,3000));
  81. Point p2 = o.getModel().getPoint();
  82. mouse.move(p2);
  83. menu.doAction("Float Canoe Canoe station");
  84. sleep(random(2000,3000));
  85. mouse.move(p2);
  86. menu.doAction("Paddle Canoe Canoe station");
  87. sleep(random(2000,3000));
  88. if(interfaces.get(53)!=null)
  89. if(handleInterface(53,45,"Select")){
  90. sleep(random(2000,3000));
  91. if(interfaces.get(382)!=null)
  92. return handleInterface(382,19,"Proceed");
  93. }
  94. }
  95. }
  96. return false;
  97. }
  98. public boolean handleInterface(int i, int c, String a){
  99. return interfaces.getComponent(i,c).doAction(a);
  100. }
  101. public void walkTo(RSTile [] path, int time){
  102. long startTime = System.currentTimeMillis();
  103. mouse.setSpeed(random(5,8));
  104. if(random(1,3)==2)
  105. camera.setPitch(true);
  106. int lastTileToWalkTo = -1;
  107. int tempTileToWalkTo = 0;
  108.  
  109.  
  110. path = fixPath(path);
  111.  
  112. if(path.length!=0)
  113. while(!playerIsNear(path[path.length-1],4)&&System.currentTimeMillis()-startTime<time)
  114. {
  115. if(!walking.isRunEnabled()&&walking.getEnergy()>20){
  116. walking.setRun(true);
  117. sleep(random(600,800));
  118. }
  119.  
  120. if(!getMyPlayer().isMoving()){
  121. sleep(random(600,800));
  122. if(!getMyPlayer().isMoving())
  123. lastTileToWalkTo=-1;
  124. }
  125. boolean clicked = false;
  126. tempTileToWalkTo = walkPath(path);
  127. if(tempTileToWalkTo>lastTileToWalkTo){
  128. if(walking.walkTileMM(path[tempTileToWalkTo],1,1))
  129. clicked = true;
  130. sleep(random(400,500));
  131. if(getMyPlayer().isMoving())
  132. clicked = true;
  133. }
  134. if(clicked){
  135. lastTileToWalkTo = tempTileToWalkTo;
  136. }
  137. sleep(random(200, 300));
  138. }
  139. }
  140. public boolean compareTiles(RSTile t1, RSTile t2){
  141. if(t1==null||t2==null)
  142. return false;
  143. return t1.getX()==t2.getX()&&t1.getY()==t2.getY();
  144. }
  145. public int walkPath(RSTile [] path){
  146. int temp = 0;
  147. boolean nearSomething = false;
  148. for(int i = 0; i<path.length;i++)
  149. {
  150. if(playerIsNear(path[i],5))
  151. {
  152. nearSomething = true;
  153. temp = i+1;
  154. antiBan(random(1,200));
  155. for(int j = i; j<path.length; j++)
  156. {
  157. if(calc.tileToMinimap(path[j]).x<0)
  158. {
  159. temp=j-1;
  160. break;
  161. }
  162. if(j==path.length-1&&calc.tileToMinimap(path[j]).x>0)
  163. {
  164. temp=j;
  165. break;
  166. }
  167. }
  168. return temp;
  169. }
  170. }
  171. if(!nearSomething){
  172. RSTile tempTileToCompare = walking.newTilePath(path).getNext();
  173. for(int i = 0; i<path.length;i++)
  174. {
  175. if(compareTiles(path[i],tempTileToCompare))
  176. return i;
  177. }
  178.  
  179. }
  180. return 0;
  181. }
  182. public void messageReceived(final MessageEvent e) {
  183. final String serverString = e.getMessage();
  184. if (serverString.toLowerCase().contains("wilderness"))
  185. inWild = true;
  186.  
  187. }
  188. public boolean playerIsNear(RSTile tile, int d)
  189. {
  190. return (Math.abs(getMyPlayer().getLocation().getX()-tile.getX())<d&&Math.abs(getMyPlayer().getLocation().getY()-tile.getY())<d);
  191. }
  192. public int distanceTo(RSTile test){
  193. RSTile myLoc = players.getMyPlayer().getLocation();
  194. return (int)Math.pow(Math.pow(test.getY()-myLoc.getY(),2)+Math.pow(test.getX()-myLoc.getX(),2),.5);
  195. }
  196. public int distanceBetween(RSTile t1, RSTile t2){
  197. return (int)Math.pow(Math.pow(t1.getY()-t2.getY(),2)+Math.pow(t1.getX()-t2.getX(),2),.5);
  198. }
  199. public RSTile[] fixPath(RSTile [] path){
  200. ArrayList<RSTile> newPath = new ArrayList<RSTile>();
  201. for(RSTile t : path)
  202. newPath.add(t);
  203. newPath = fixPath(newPath);
  204. path = new RSTile[newPath.size()];
  205. for(int i=0; i<path.length;i++){
  206. path[i]=newPath.get(i);
  207. }
  208. return path;
  209. }
  210. public ArrayList<RSTile> fixPath(ArrayList<RSTile> path){
  211. boolean madeSwap = false;
  212. do{
  213. madeSwap = false;
  214. for(int i = 0; i<path.size()-1;i++)
  215. if(distanceBetween(path.get(i),path.get(i+1))>7){
  216. path.add(i+1,getMidTile(path.get(i),path.get(i+1)));
  217. madeSwap = true;
  218. }
  219. }while(madeSwap);
  220. return path;
  221. }
  222. public RSTile getMidTile(RSTile tile1, RSTile tile2)
  223. {
  224. int x1 = tile1.getX();
  225. int y1 = tile1.getY();
  226. int x2 = tile2.getX();
  227. int y2 = tile2.getY();
  228.  
  229. return new RSTile((int)(x1+x2)/2,(int)(y1+y2)/2);
  230. }
  231. public int getGEValue(String name, int id){
  232. try{
  233. String [] temp = name.split(" ");
  234. String newName = "";
  235. for(int i = 0; i<temp.length; i++)
  236. if(i==temp.length-1)
  237. newName+=temp[i];
  238. else
  239. newName+="_"+temp[i];
  240. URL url = new URL("http://services.runescape.com/m=itemdb_rs/"+newName+"/viewitem.ws?obj="+id);
  241. InputStream is = url.openStream();
  242. InputStreamReader isr = new InputStreamReader(is);
  243. BufferedReader br = new BufferedReader(isr);
  244. String line;
  245. String num = "";
  246. while((line=br.readLine())!=null){
  247. if(line.contains("Current guide price:"))
  248. num = line;
  249. }
  250. System.out.println(num);
  251. if(num.length()<29)
  252. return -1;
  253. else{
  254. num = num.substring(28);
  255. num = num.replaceAll(",", "");
  256. return Integer.parseInt(num);
  257. }
  258.  
  259. }catch(Exception e){
  260. return -1;
  261. }
  262. }
  263.  
  264.  
  265. //LOOP====================================================================================================================
  266. public int loop() {
  267. try{
  268. if(doOnce==0){
  269. doOnce=1;
  270. whiteBerriesVal = getGEValue("White berries",berryID);
  271. lawRuneVal = getGEValue("Law rune",lawID);
  272. profit = whiteBerriesVal-lawRuneVal;
  273. }
  274.  
  275. //Walk To canoe
  276. walkTo(bankToCanoe,20000);
  277.  
  278. //Make canoe/Go To wilderness
  279. makeCanoe();
  280.  
  281. //Walk to telegrab area
  282. walkTo(pondToTele,25000);
  283.  
  284. //Walk away from telegrab
  285. walkTo(teleToEscape,20000);
  286.  
  287. //Walk to bank
  288. walkTo(escapeToBank,8000);
  289.  
  290.  
  291. }catch (Exception e){};
  292. return random(300,500);
  293. }
  294. //LOOP====================================================================================================================
  295. public void antiBan(int rand){
  296. status += "(AB)";
  297. mouse.setSpeed(random(7,8));
  298. if(rand==1)
  299. if(random(1, 8) == 2)
  300. mouse.moveRandomly(900,1200);
  301. if(rand==2)
  302. if(random(1, 8) == 2)
  303. mouse.moveRandomly(400,800);
  304. if(rand==3)
  305. if(random(1, 8) == 2)
  306. mouse.moveRandomly(200,700);
  307. if(rand==5) //THIS CLICKS THE XP BUTTON UNDER THE COMPASS (Update thanks to Rawr =D)
  308. if(random(1, 24) == 2)
  309. {
  310. if (interfaces.get(548).getComponent(38).isValid()) {
  311. return;
  312. } else {
  313. if (interfaces.get(548).getComponent(0).doClick()) {
  314. sleep(1500);
  315. }
  316. }
  317. }
  318. if(rand==7) //RANDOM SPIN
  319. if(random(1, 3) == 2)
  320. {int r = random(1,2);
  321. camera.setAngle(random(1,359));
  322. if(r!=1)
  323. camera.setPitch(random(1,99));}
  324.  
  325. if(rand==8) //THIS CHECKS A RANDOM TAB
  326. if(random(1, 4) == 2)
  327. {
  328. int[] tabs = {0,1,2,3,5,6,7,9,10,11,12,13,14,15};
  329. game.openTab(tabs[random(0,tabs.length-1)]);
  330. mouse.moveRandomly(175,200);
  331. sleep(random(1600,1800));
  332. sleep(random(900,1000));
  333.  
  334. }
  335. if(rand==9)
  336. if(random(1,10)==2)
  337. mouse.moveOffScreen();
  338. status=status.substring(0,status.indexOf('('));
  339.  
  340. }
  341. public void onRepaint(Graphics g)
  342. {
  343. if(game.isLoggedIn())
  344. {
  345. if(startExp==0)
  346. {
  347. startExp = skills.getCurrentExp(skills.getIndex("magic"));
  348. startLevel = skills.getCurrentLevel(skills.getIndex("magic"));
  349. }
  350. lvlsGained = skills.getCurrentLevel(skills.getIndex("magic")) - startLevel;
  351. expGained = skills.getCurrentExp(skills.getIndex("magic")) - startExp;
  352.  
  353.  
  354. //setting up the time
  355. long ms = System.currentTimeMillis() - startTime;
  356. double ms2 = System.currentTimeMillis() - startTimeDbl;
  357. long hours = ms/3600000;
  358. ms = ms-(hours*3600000);
  359. long minutes = ms/60000;
  360. ms = ms-(minutes*60000);
  361. long seconds = ms/1000;
  362.  
  363. g.setColor(Color.RED);
  364.  
  365. numBerries = expGained/43;
  366.  
  367. g.drawString("Status: "+status,15,25);
  368. g.drawString("Time Running: "+hours+" : "+minutes+" : "+seconds,15,50);
  369. g.drawString("Profit: "+(numBerries*profit)+" ("+numBerries+" berries)",15,75);
  370. g.drawString("Profit/Hr: "+(numBerries*profit)/(ms2/3600000),15,100);
  371.  
  372. }
  373.  
  374. }
  375. public void onFinish() {
  376. log("Money gained: "+numBerries*profit);
  377. log("Levels gained: "+lvlsGained);
  378. log("Thanks for using our White Berry Grabber!");
  379. }
  380. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement