Guest User

ore2

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