Advertisement
Guest User

ore1

a guest
Feb 29th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.25 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={"james1@james.com", "james2@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. 359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302,
  214. 346, 376, 342, 367, 304, 354, 358, 377, 365, 343,
  215. };
  216. Mouse.setSpeed(50);
  217. timeBegan = System.currentTimeMillis();
  218. startTile = Players.getLocal().getLocation();
  219. xpStart = Skills.getTotalExperience();
  220. return true;
  221. }
  222. int money=(int) (moneyGained * 3600000D / (System.currentTimeMillis() - timeBegan));
  223.  
  224. @Override
  225.  
  226. public void onRepaint(Graphics g) {
  227. DecimalFormat df = new DecimalFormat("#");
  228. g.setColor(Color.WHITE);
  229. mX = Mouse.getX();
  230. mY = Mouse.getY();
  231. g.drawLine(mX-1, mY+5, mX-1, mY-5);
  232. g.drawLine(mX, mY+6, mX, mY-6);
  233. g.drawLine(mX+1, mY+5, mX+1, mY-5);
  234. g.drawLine(mX+5, mY-1, mX-5, mY-1);
  235. g.drawLine(mX+6, mY, mX-6, mY);
  236. g.drawLine(mX+5, mY+1, mX-5, mY+1);
  237. timeRan = System.currentTimeMillis() - this.timeBegan;
  238. g.drawString("Money spent: " + (moneyBefore-Inventory.getCount(995)), 20, 325);
  239. g.drawString("Time: " + ft(timeRan), 20, 310);
  240. g.drawString("Money p/hr: " + ((moneyGained * 3600000D )/( (System.currentTimeMillis() - timeBegan))),20, 295);
  241. g.drawString("World: " + currentWorld, 20, 280);
  242. g.drawString("State: " + currentState, 20, 265);
  243. g.drawString("Iron earned: " + (totalIron), 20, 250);
  244. g.drawString("Coal earned: " + (totalCoal), 20, 235);
  245. g.drawString("Gold earned: " + (totalGold), 20, 220);
  246. g.drawString("Money earned: " + (Game.getGameState()), 20, 205);
  247. g.drawString("acc : " + (username[accCount]), 20, 195);
  248. //g.drawRect(15, 250, 125, 80);
  249. //
  250. currentWorld = Game.getCurrentWorld();
  251. }
  252. //Other methods
  253. private void loot()
  254. {
  255. myItem=null;
  256. WidgetChild j=null;
  257. int ironOre = Inventory.getCount(440);
  258. int coal = Inventory.getCount(453);
  259. int gold = Inventory.getCount(444);
  260. orden = Npcs.getNearest(1560);
  261. if (!Shop.isOpen()){
  262. if(orden.interact("Trade"))
  263. {
  264. Time.sleepUntil(SHOP_OPEN, 1000);
  265. }
  266. }
  267. Time.sleep(200, 300);
  268. if (Shop.isOpen())
  269. {
  270. if(Shop.getItem(444)!=null && Shop.getItem(444).getStackSize()>90)
  271. {
  272. //gold
  273. j = Widgets.getWidget(300).getChild(2).getChild(5);
  274. myItem = Shop.getItem(444);
  275. }
  276. if(Shop.getItem(453)!=null && Shop.getItem(453).getStackSize()>80)
  277. {
  278. //coal
  279. j = Widgets.getWidget(300).getChild(2).getChild(6);
  280. myItem = Shop.getItem(453);
  281. }
  282. if(Shop.getItem(440) != null && Shop.getItem(440).getStackSize()>0)
  283. {
  284. //iron
  285. j = Widgets.getWidget(300).getChild(2).getChild(2);
  286. myItem = Shop.getItem(440);
  287. }
  288. if (j!=null && myItem!=null)
  289. {
  290. myItem.interact("Buy 10");
  291. if (Inventory.isFull())
  292. walkbank();
  293. }
  294. }
  295. totalGold+=Inventory.getCount(444)-gold;
  296. totalIron+=Inventory.getCount(440)-ironOre;
  297. totalCoal+=Inventory.getCount(453)-coal;
  298. moneyGained=((totalCoal*200)+(totalGold*400)+(totalIron*170));
  299. }
  300. private void welcome(){
  301. WidgetChild welcomeScreen = Widgets.getWidget(378,17);
  302. if(welcomeScreen.isValid()){
  303. welcomeScreen.interact("Play Runescape");
  304. }
  305. }
  306. public void login() {
  307. final WidgetChild wc = Widgets.getWidget(378, 17);
  308. final int state = Game.getGameState();
  309. if (state == 30) {
  310. if (wc != null && wc.isValid() && wc.isVisible()) {
  311. if (wc != null)
  312. if (wc.click())
  313. Time.sleepUntil(new Condition() {
  314. @Override
  315. public boolean check() {
  316. return !wc.isValid() && !wc.isVisible();
  317. }
  318. }, 1500);
  319. }
  320. } else if (state == 10) {
  321. final String loginText = getLoginText();
  322. if (Game.getLoginMenuIndex() == 2) {
  323. final String currentUsername = Game.getCurrentUsername();
  324. final String wantedName = currentAcc;
  325. final String currentPassword = TBot.getBot().getClient().getCurrentPassword();
  326. final String wantedPassword = TBot.getBot().getCurrentAccount().getPassword();
  327.  
  328. if (currentUsername.equalsIgnoreCase(wantedName) && currentPassword.equalsIgnoreCase(wantedPassword)) {
  329. if (Game.getGameState() == 10)
  330. if (Mouse.click((int) (235 + (Math.random() * (370 - 235))), (int) (305 + (Math.random() * (335 - 305))), true))
  331. Time.sleep(Random.nextInt(2000, 3000));
  332. } else {
  333. if (!currentUsername.equalsIgnoreCase(wantedName)) {
  334. if (!currentUsername.isEmpty()) {
  335. Mouse.click(Random.nextInt(400, 512), Random.nextInt(307, 330), true);
  336. } else {
  337. Mouse.click((int) (340 + (Math.random() * (450 - 340))), (int) (246 + (Math.random() * (260 - 246))), true);
  338. Keyboard.sendText(wantedName);
  339. }
  340. }
  341.  
  342. if (!currentPassword.equalsIgnoreCase(wantedPassword)) {
  343. if (!currentPassword.isEmpty()) {
  344. Mouse.click(Random.nextInt(400, 512), Random.nextInt(307, 330), true);
  345. } else {
  346. Mouse.click((int) (340 + (Math.random() * (450 - 340))), (int) (261 + (Math.random() * (275 - 261))), true);
  347. Keyboard.sendText(wantedPassword);
  348.  
  349. }
  350. }
  351. }
  352. if (loginText.contains("Too many")) {
  353. Time.sleep(3000, 5000);
  354. }
  355.  
  356. if (loginText.contains("exceeded")) {
  357. Game.instaHopNextP2P();
  358. Time.sleep(1000, 2000);
  359. }
  360. if (loginText.contains("disable")) {
  361. TBot.getBot().getScriptHandler().stopScript();
  362.  
  363. } else if (loginText.contains("update")) {
  364. System.exit(0);
  365.  
  366. TBot.getBot().getScriptHandler().stopScript();
  367. }
  368. } else if (loginText.contains("Locked")) {
  369. TBot.getBot().getScriptHandler().stopScript();
  370.  
  371. } else if (Game.getLoginMenuIndex() == 0) {
  372. Mouse.click((int) (395 + (Math.random() * (530 - 395))), (int) (275 + (Math.random() * (305 - 275))), true);
  373. Time.sleep(Random.nextInt(500, 750));
  374. } else if (Game.getLoginMenuIndex() == 3) {
  375. Mouse.click((int) (315 + (Math.random() * (450 - 315))), (int) (335 + (Math.random() * (335 - 305))), true);
  376. Time.sleep(Random.nextInt(500, 750));
  377. }
  378.  
  379. }
  380.  
  381. }
  382. private static String getLoginText() {
  383. return Game.getLoginMessage1() + Game.getLoginMessage2();
  384. }
  385.  
  386. private void hop(){
  387. if (i==worldArray.length)
  388. {
  389. i=0;
  390. }
  391. if(Game.instaHop(worldArray[i]))
  392. Time.sleepUntil(WELCOME,5000);
  393. currentWorld = Game.getCurrentWorld();
  394. i++;
  395. }
  396. private void walkbank()
  397. {
  398. Tile[] areaArr = BANK_AREA.getTileArray();
  399. int areaRan = Random.nextInt(BANK_AREA.getTileArray().length-1);
  400. Keyboard.pressKey(control);
  401. Walking.findLocalPath(areaArr[areaRan]).traverse();
  402. Keyboard.releaseKey(control); }
  403. private void bank()
  404. {
  405. Inventory.deselectItem();
  406. GameObject booth = GameObjects.getNearest(26707);
  407. if (booth!=null)
  408. booth = GameObjects.getNearest(26707);
  409. if (booth != null) {
  410. if (booth.isOnScreen()) {
  411. booth.interact("Use Bank chest");
  412. Time.sleepUntil(bankIsOpen, 1000);
  413. Bank.depositAllExcept(995);
  414. }
  415. else {
  416. Camera.turnTo(booth);
  417. }
  418. }
  419. }
  420. private void walkBack()
  421. {
  422. Tile[] areaArr = BUY_AREA.getTileArray();
  423. int areaRan = Random.nextInt(BUY_AREA.getTileArray().length-1);
  424. Keyboard.pressKey(control);
  425. Walking.findLocalPath(areaArr[areaRan]).traverse();
  426. Keyboard.releaseKey(control);
  427. }
  428. private String ft(long duration)
  429. {
  430. String res = "";
  431. long hours = TimeUnit.MILLISECONDS.toHours(duration)
  432. - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  433. long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
  434. - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
  435. .toHours(duration));
  436. long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
  437. - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
  438. .toMinutes(duration));
  439. res = (hours + ":" + minutes + ":" + seconds);
  440. return res;
  441. }
  442.  
  443. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement