Advertisement
Guest User

Untitled

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