Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.43 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.event.KeyEvent;
  4. import java.io.Console;
  5. import java.text.DecimalFormat;
  6. import java.util.concurrent.TimeUnit;
  7.  
  8. import org.tbot.util.Condition;
  9. import org.tbot.wrappers.Area;
  10. import org.tbot.wrappers.GameObject;
  11. import org.tbot.wrappers.Item;
  12. import org.tbot.wrappers.NPC;
  13. import org.tbot.wrappers.Tile;
  14. import org.tbot.wrappers.WidgetChild;
  15. import org.tbot.bot.TBot;
  16. import org.tbot.internal.AbstractScript;
  17. import org.tbot.internal.Manifest;
  18. import org.tbot.internal.event.listeners.PaintListener;
  19. import org.tbot.methods.Bank;
  20. import org.tbot.methods.Camera;
  21. import org.tbot.methods.Game;
  22. import org.tbot.methods.GameObjects;
  23. import org.tbot.methods.Menu;
  24. import org.tbot.methods.Mouse;
  25. import org.tbot.methods.Npcs;
  26. import org.tbot.methods.Players;
  27. import org.tbot.methods.Random;
  28. import org.tbot.methods.Shop;
  29. import org.tbot.methods.ShopItem;
  30. import org.tbot.methods.Skills;
  31. import org.tbot.methods.Time;
  32. import org.tbot.methods.Widgets;
  33. import org.tbot.methods.input.keyboard.Keyboard;
  34. import org.tbot.methods.tabs.Inventory;
  35. import org.tbot.methods.walking.Walking;
  36.  
  37. @Manifest(name = "oreBuy", authors = "James", version = 0.1, description = "Buys/Hops")
  38. public class oreBuy extends AbstractScript implements PaintListener{
  39. GameObject rocks;
  40.  
  41. public enum State {
  42. WAIT, BUY, BANK, HOP, EMPTY, WALKBANK, LOGIN, RETURN;
  43. }
  44.  
  45. private Tile startTile;
  46. private int xpStart;
  47. private int mY, mX;
  48. int barsGained=0;
  49. private int moneyBefore= Inventory.getCount(995);
  50. private long timeBegan;
  51. private long timeRan;
  52. char control = KeyEvent.VK_CONTROL;
  53. int invb4;
  54. int i=0;
  55. int totalGold=0;
  56. int totalCoal=0;
  57. int totalIron=0;
  58. int moneyGained=0;
  59. ShopItem myItem;
  60. NPC banker;
  61. NPC orden;
  62. private final Area BUY_AREA = new Area(1937, 4967, 1935, 4965);
  63. private final Area BANK_AREA = new Area(1947, 4959, 1949, 4957);
  64. int[] worldArray;
  65. //359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302
  66. //346, 376, 342, 367, 304, 321, 354, 358, 377, 365, 343
  67. //386, 351, 305, 306, 341, 309, 349, 362, 320, 378, 312
  68. //333, 322, 369, 314, 336, 344, 375, 310, 350, 327, 368
  69. private final Tile bankTile=new Tile(1948, 4957);
  70. private int currentWorld;
  71. private String currentState = "";
  72. WidgetChild welcomeScreen = Widgets.getWidget(378, 17);
  73. private final Condition LOGGED_IN = new Condition(){
  74. public boolean check(){
  75. return (Game.isLoggedIn());
  76. }
  77. };
  78. private final Condition WELCOME = new Condition(){
  79. public boolean check(){
  80. return (welcomeScreen.isVisible());
  81. }
  82. };
  83. private final Condition SHOP_OPEN = new Condition(){
  84. public boolean check(){
  85. return (Shop.isOpen());
  86. }
  87. };
  88. private final Condition empty = new Condition(){
  89. public boolean check(){
  90. return (Inventory.getCount(7810) > 10);
  91. }
  92. };
  93. private final Condition itemGone = new Condition(){
  94. public boolean check(){
  95. return (myItem.getStackSize()<1);
  96. }
  97. };
  98. private final Condition bankIsOpen = new Condition(){
  99. public boolean check(){
  100. return (Bank.isOpen());
  101. }
  102. };
  103. private State getState(){
  104. if(!welcomeScreen.isValid() && !Game.isLoggedIn())
  105. return State.LOGIN;
  106. if(welcomeScreen.isValid())
  107. welcome();
  108. if(Players.getLocal().inCombat()==true)
  109. {
  110. Walking.setRun(true);
  111. currentState = "Running from combat";
  112. walkbank();
  113. Time.sleep(20000);
  114. }
  115. if (!welcomeScreen.isValid() && Inventory.getCount()==1 && ((Npcs.getNearest(1560)!=null && !Npcs.getNearest(1560).isOnScreen()) || Npcs.getNearest(1560)==null))
  116. return State.RETURN;
  117. if (!welcomeScreen.isValid() && Inventory.isFull() && GameObjects.getNearest(26707)!=null && !GameObjects.getNearest(26707).isOnScreen())
  118. return State.WALKBANK;
  119. //26707
  120. if (!welcomeScreen.isValid() && GameObjects.getNearest(26707)!=null && Inventory.getCount()>1 && Npcs.getNearest(1560)!=null && Npcs.getNearest(1560).distance()>1)
  121. return State.BANK;
  122. //hop
  123. if (!welcomeScreen.isValid() && Shop.isOpen())
  124. Time.sleepUntil(SHOP_OPEN,500);
  125. if ((Shop.isOpen() && Shop.getItem(440)!=null && Shop.getItem(440).getStackSize()<1) && (Shop.isOpen() && Shop.getItem(453)!=null && Shop.getItem(453).getStackSize()<81) && Shop.getItem(444) != null && Shop.getItem(444).getStackSize()<91)
  126. return State.HOP;
  127.  
  128. //buy
  129. if(!welcomeScreen.isValid() && Npcs.getNearest(1560)!=null && Npcs.getNearest(1560).distance()<10)
  130. return State.BUY;
  131. //bank
  132. if(!welcomeScreen.isValid() && !Game.isLoggedIn())
  133. return State.LOGIN;
  134. return State.WAIT;
  135.  
  136. //coal prof= 16600
  137. //iron prof= 60000
  138. //gold prof= 77200
  139. }
  140. @Override
  141. public int loop() {
  142. try{
  143. switch (getState()) {
  144. case BUY:
  145. currentState = "Buying";
  146. loot();
  147. break;
  148. case HOP:
  149. currentState = "Hopping";
  150. hop();
  151. break;
  152. case WAIT:
  153. currentState = "Waiting";
  154. Time.sleep(400);
  155. break;
  156. case WALKBANK:
  157. currentState = "Walking to bank";
  158. walkbank();
  159. Time.sleep(500);
  160. break;
  161. case BANK:
  162. currentState="Banking";
  163. bank();
  164. break;
  165. case RETURN:
  166. currentState = "Returning to store";
  167. walkBack();
  168. Time.sleep(500);
  169. break;
  170. case LOGIN:
  171. currentState = "Logging in";
  172. login();
  173. break;
  174. default:
  175. log("Error, Stopping the script.");
  176. return -1;
  177. }
  178. }catch(Exception e)
  179. {
  180.  
  181. }
  182. return 0;
  183. }
  184.  
  185. @Override
  186. public boolean onStart(){
  187. String user = TBot.getBot().getCurrentAccount().getUsername();
  188. //359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302
  189. //346, 376, 342, 367, 304, 321, 354, 358, 377, 365, 343
  190. //386, 351, 305, 306, 341, 309, 349, 362, 320, 378, 312
  191. //333, 322, 369, 314, 336, 344, 375, 310, 350, 327, 368
  192. if(user.contains("yung1@"))
  193. {
  194. worldArray=new int[]{359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302};
  195. }
  196. if(user.contains("yung11@"))
  197. {
  198. worldArray=new int[]{346, 376, 342, 367, 304, 354, 358, 377, 365, 343};
  199. }
  200. if(user.contains("yung12@"))
  201. {
  202. worldArray=new int[]{386, 351, 305, 306, 341, 309, 362, 320, 378, 312};
  203. }
  204. if(user.contains("yung13@"))
  205. {
  206. worldArray=new int[]{333, 322, 369, 314, 336, 344, 375, 310, 350, 327, 368};
  207. }
  208. Mouse.setSpeed(50);
  209. timeBegan = System.currentTimeMillis();
  210. startTile = Players.getLocal().getLocation();
  211. xpStart = Skills.getTotalExperience();
  212. return true;
  213. }
  214. int money=(int) (moneyGained * 3600000D / (System.currentTimeMillis() - timeBegan));
  215.  
  216. @Override
  217.  
  218. public void onRepaint(Graphics g) {
  219. DecimalFormat df = new DecimalFormat("#");
  220. g.setColor(Color.WHITE);
  221. mX = Mouse.getX();
  222. mY = Mouse.getY();
  223. g.drawLine(mX-1, mY+5, mX-1, mY-5);
  224. g.drawLine(mX, mY+6, mX, mY-6);
  225. g.drawLine(mX+1, mY+5, mX+1, mY-5);
  226. g.drawLine(mX+5, mY-1, mX-5, mY-1);
  227. g.drawLine(mX+6, mY, mX-6, mY);
  228. g.drawLine(mX+5, mY+1, mX-5, mY+1);
  229. timeRan = System.currentTimeMillis() - this.timeBegan;
  230. g.drawString("Money spent: " + (moneyBefore-Inventory.getCount(995)), 20, 325);
  231. g.drawString("Time: " + ft(timeRan), 20, 310);
  232. g.drawString("Money p/hr: " + ((moneyGained * 3600000D )/( (System.currentTimeMillis() - timeBegan))),20, 295);
  233. g.drawString("World: " + currentWorld, 20, 280);
  234. g.drawString("State: " + currentState, 20, 265);
  235. g.drawString("Iron earned: " + (totalIron), 20, 250);
  236. g.drawString("Coal earned: " + (totalCoal), 20, 235);
  237. g.drawString("Gold earned: " + (totalGold), 20, 220);
  238. g.drawString("Money earned: " + (Game.getGameState()), 20, 205);
  239. //g.drawRect(15, 250, 125, 80);
  240. //
  241. currentWorld = Game.getCurrentWorld();
  242. }
  243. //Other methods
  244. private void loot()
  245. {
  246. myItem=null;
  247. WidgetChild j=null;
  248. int ironOre = Inventory.getCount(440);
  249. int coal = Inventory.getCount(453);
  250. int gold = Inventory.getCount(444);
  251. orden = Npcs.getNearest(1560);
  252. if (!Shop.isOpen()){
  253. if(orden.interact("Trade"))
  254. {
  255. Time.sleepUntil(SHOP_OPEN, 1000);
  256. }
  257. }
  258. Time.sleep(200, 300);
  259. if (Shop.isOpen())
  260. {
  261. if(Shop.getItem(444)!=null && Shop.getItem(444).getStackSize()>90)
  262. {
  263. //gold
  264. j = Widgets.getWidget(300).getChild(2).getChild(5);
  265. myItem = Shop.getItem(444);
  266. }
  267. if(Shop.getItem(453)!=null && Shop.getItem(453).getStackSize()>80)
  268. {
  269. //coal
  270. j = Widgets.getWidget(300).getChild(2).getChild(6);
  271. myItem = Shop.getItem(453);
  272. }
  273. if(Shop.getItem(440) != null && Shop.getItem(440).getStackSize()>0)
  274. {
  275. //iron
  276. j = Widgets.getWidget(300).getChild(2).getChild(2);
  277. myItem = Shop.getItem(440);
  278. }
  279. if (j!=null && myItem!=null)
  280. {
  281. myItem.interact("Buy 10");
  282. if (Inventory.isFull())
  283. walkbank();
  284. }
  285. }
  286. totalGold+=Inventory.getCount(444)-gold;
  287. totalIron+=Inventory.getCount(440)-ironOre;
  288. totalCoal+=Inventory.getCount(453)-coal;
  289. moneyGained=((totalCoal*200)+(totalGold*400)+(totalIron*170));
  290. }
  291. private void welcome(){
  292. WidgetChild welcomeScreen = Widgets.getWidget(378,17);
  293. if(welcomeScreen.isValid()){
  294. welcomeScreen.interact("Play Runescape");
  295. }
  296. }
  297. public void login() {
  298. final WidgetChild wc = Widgets.getWidget(378, 17);
  299. final int state = Game.getGameState();
  300. if (state == 30) {
  301. if (wc != null && wc.isValid() && wc.isVisible()) {
  302. if (wc != null)
  303. if (wc.click())
  304. Time.sleepUntil(new Condition() {
  305. @Override
  306. public boolean check() {
  307. return !wc.isValid() && !wc.isVisible();
  308. }
  309. }, 1500);
  310. }
  311. } else if (state == 10) {
  312. final String loginText = getLoginText();
  313. if (Game.getLoginMenuIndex() == 2) {
  314. final String currentUsername = Game.getCurrentUsername();
  315. final String wantedName = TBot.getBot().getCurrentAccount().getUsername();
  316. final String currentPassword = TBot.getBot().getClient().getCurrentPassword();
  317. final String wantedPassword = TBot.getBot().getCurrentAccount().getPassword();
  318.  
  319. if (currentUsername.equalsIgnoreCase(wantedName) && currentPassword.equalsIgnoreCase(wantedPassword)) {
  320. if (Game.getGameState() == 10)
  321. if (Mouse.click((int) (235 + (Math.random() * (370 - 235))), (int) (305 + (Math.random() * (335 - 305))), true)){
  322. Time.sleep(Random.nextInt(2000, 3000));
  323. }
  324.  
  325. } else {
  326. if (!currentUsername.equalsIgnoreCase(wantedName)) {
  327. if (!currentUsername.isEmpty()) {
  328. Mouse.click(Random.nextInt(400, 512), Random.nextInt(307, 330), true);
  329. } else {
  330. Mouse.click((int) (340 + (Math.random() * (450 - 340))), (int) (246 + (Math.random() * (260 - 246))), true);
  331. Keyboard.sendText(wantedName);
  332. }
  333. }
  334.  
  335. if (!currentPassword.equalsIgnoreCase(wantedPassword)) {
  336. if (!currentPassword.isEmpty()) {
  337. Mouse.click(Random.nextInt(400, 512), Random.nextInt(307, 330), true);
  338. } else {
  339. Mouse.click((int) (340 + (Math.random() * (450 - 340))), (int) (261 + (Math.random() * (275 - 261))), true);
  340. Keyboard.sendText(wantedPassword);
  341.  
  342. }
  343. }
  344. }
  345. if (loginText.contains("Too many")) {
  346. Time.sleep(3000, 5000);
  347. }
  348.  
  349. if (loginText.contains("exceeded")) {
  350. Game.instaHopNextP2P();
  351. Time.sleep(1000, 2000);
  352. }
  353.  
  354. if (loginText.contains("disable")) {
  355. TBot.getBot().getScriptHandler().stopScript();
  356.  
  357. } else if (loginText.contains("update")) {
  358. System.exit(0);
  359.  
  360. TBot.getBot().getScriptHandler().stopScript();
  361. }
  362. } else if (loginText.contains("Locked")) {
  363. TBot.getBot().getScriptHandler().stopScript();
  364.  
  365. } else if (Game.getLoginMenuIndex() == 0) {
  366. Mouse.click((int) (395 + (Math.random() * (530 - 395))), (int) (275 + (Math.random() * (305 - 275))), true);
  367. Time.sleep(Random.nextInt(500, 750));
  368. } else if (Game.getLoginMenuIndex() == 3) {
  369. Mouse.click((int) (315 + (Math.random() * (450 - 315))), (int) (335 + (Math.random() * (335 - 305))), true);
  370. Time.sleep(Random.nextInt(500, 750));
  371. }
  372.  
  373. }
  374.  
  375. }
  376. private static String getLoginText() {
  377. return Game.getLoginMessage1() + Game.getLoginMessage2();
  378. }
  379.  
  380. private void hop(){
  381. if (i==worldArray.length)
  382. {
  383. i=0;
  384. }
  385. if(Game.instaHop(worldArray[i]))
  386. Time.sleepUntil(WELCOME,5000);
  387. currentWorld = Game.getCurrentWorld();
  388. i++;
  389. }
  390. private void walkbank()
  391. {
  392. Tile[] areaArr = BANK_AREA.getTileArray();
  393. int areaRan = Random.nextInt(BANK_AREA.getTileArray().length-1);
  394. Keyboard.pressKey(control);
  395. Walking.findLocalPath(areaArr[areaRan]).traverse();
  396. Keyboard.releaseKey(control); }
  397. private void bank()
  398. {
  399. Inventory.deselectItem();
  400. GameObject booth = GameObjects.getNearest(26707);
  401. if (booth!=null)
  402. booth = GameObjects.getNearest(26707);
  403. if (booth != null) {
  404. if (booth.isOnScreen()) {
  405. booth.interact("Use Bank chest");
  406. Time.sleepUntil(bankIsOpen, 1000);
  407. Bank.depositAllExcept(995);
  408. }
  409. else {
  410. Camera.turnTo(booth);
  411. }
  412. }
  413. }
  414. private void walkBack()
  415. {
  416. Tile[] areaArr = BUY_AREA.getTileArray();
  417. int areaRan = Random.nextInt(BUY_AREA.getTileArray().length-1);
  418. Keyboard.pressKey(control);
  419. Walking.findLocalPath(areaArr[areaRan]).traverse();
  420. Keyboard.releaseKey(control);
  421. }
  422. private String ft(long duration)
  423. {
  424. String res = "";
  425. long hours = TimeUnit.MILLISECONDS.toHours(duration)
  426. - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  427. long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
  428. - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
  429. .toHours(duration));
  430. long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
  431. - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
  432. .toMinutes(duration));
  433. res = (hours + ":" + minutes + ":" + seconds);
  434. return res;
  435. }
  436.  
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement