Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.49 KB | None | 0 0
  1. package Main;
  2.  
  3. import org.osbot.rs07.api.GrandExchange;
  4. import org.osbot.rs07.api.map.Area;
  5. import org.osbot.rs07.api.map.constants.Banks;
  6. import org.osbot.rs07.api.model.NPC;
  7. import org.osbot.rs07.api.model.Player;
  8. import org.osbot.rs07.api.ui.Message;
  9. import org.osbot.rs07.api.ui.Tab;
  10. import org.osbot.rs07.script.Script;
  11. import org.osbot.rs07.script.ScriptManifest;
  12. import org.osbot.rs07.utility.ConditionalSleep;
  13.  
  14. import java.awt.*;
  15. import java.io.File;
  16. import java.io.FileWriter;
  17. import java.io.IOException;
  18. import java.io.PrintWriter;
  19. import java.text.DateFormat;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Date;
  22.  
  23. @ScriptManifest(name = "Shopper", author = "Kadiem", version = 1.0, info = "", logo = "")
  24.  
  25. public class Main extends Script {
  26.  
  27. long Timer;
  28. Area shopArea = new Area(2953, 3205, 2960, 3202);
  29. Area grandexchangeArea = Banks.GRAND_EXCHANGE;
  30. Area tradingArea = Banks.VARROCK_WEST;
  31. static String Status = "Normal";
  32. boolean GotTradeOffer;
  33. Timer logTimer;
  34. Timer updateTimer;
  35. int numberofWSB;
  36. int numberofWLB;
  37. int numberofMSB;
  38. int numberofMLB;
  39. int numberofSA;
  40. int coinsinbank;
  41.  
  42.  
  43.  
  44.  
  45. @Override
  46.  
  47. public void onStart() throws InterruptedException {
  48.  
  49. logTimer = new Timer(0);
  50. updateTimer = new Timer(0);
  51.  
  52. Timer = System.currentTimeMillis();
  53.  
  54. try {
  55. File file = new File(getDirectoryData()+"info.txt");
  56.  
  57. if(!file.exists()) {
  58. file.createNewFile();
  59. }
  60. } catch (IOException e) {
  61. // TODO Auto-generated catch block
  62. e.printStackTrace();
  63. }
  64.  
  65. }
  66.  
  67. @Override
  68.  
  69. public int onLoop() throws InterruptedException {
  70.  
  71. if(logTimer.Passed(1)){
  72. log("Current money stock " + (int) inventory.getAmount("Coins"));
  73. log("Current money stock in bank " + coinsinbank);
  74. logTimer.reset();
  75. }
  76. if(updateTimer.Passed(30)){
  77. Update();
  78. updateTimer.reset();
  79. sleep(random(2000,3000));
  80. }
  81.  
  82. if(Status == "Normal") {
  83. if (!GotTradeOffer) {
  84. if (tabs.open(Tab.INVENTORY) && !trade.isFirstInterfaceOpen()) {
  85. if (inventory.contains("Willow longbow") && inventory.contains("Willow shortbow") && inventory.contains("Maple shortbow") && inventory.contains("Maple longbow")) {
  86. GoToShop();
  87. }
  88. if (!inventory.contains("Willow longbow") || !inventory.contains("Willow shortbow") || !inventory.contains("Maple shortbow") || !inventory.contains("Maple longbow")) {
  89. GoToGe();
  90. }
  91. }
  92. } else if (GotTradeOffer) {
  93. Trade();
  94. }
  95. }else if (Status == "Muling"){
  96. WalktoTrade();
  97. }
  98.  
  99. return 100;
  100. }
  101.  
  102. private void WalktoTrade() {
  103. if(!tradingArea.contains(myPlayer())){
  104. walking.webWalk(tradingArea);
  105. }
  106. }
  107.  
  108. public void Update(){
  109. try {
  110. File file = new File(getDirectoryData()+"info.txt");
  111.  
  112. if(!file.exists()) {
  113. file.createNewFile();
  114. }
  115.  
  116. PrintWriter pw = new PrintWriter(new FileWriter(file, true));
  117. long timeRan = System.currentTimeMillis() - this.Timer;
  118. pw.println(myPlayer().getName());
  119. DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  120. Date date = new Date();
  121. pw.println(dateFormat.format(date));
  122. pw.println("Time running ["+formatTime(timeRan)+"]");
  123. pw.println("Current money stock " +"["+(int) inventory.getAmount("Coins")/1000+"K"+"]");
  124. pw.println("Number of steel arrows bought " +"["+ numberofSA+"]");
  125. pw.println("Number of willow shortbows bought " +"["+ numberofWSB+"]");
  126. pw.println("Number of willow longbows bought " +"["+ numberofWLB+"]");
  127. pw.println("Number of maple shortbows bought " +"["+ numberofMSB+"]");
  128. pw.println("Number of maple longbows bought " +"["+ numberofMLB+"]");
  129. pw.println("-------------------------------------------------------------------------");
  130. pw.close();
  131. log("Update!");
  132. } catch (IOException e) {
  133. // TODO Auto-generated catch block
  134. e.printStackTrace();
  135. }
  136. }
  137.  
  138. public final String formatTime(long ms) {
  139. long s = ms / 1000;
  140. long m = s / 60;
  141. long h = m / 60;
  142. return String.format("%02d:%02d:%02d", h %= 24, m %= 60, s %= 60);
  143. }
  144.  
  145.  
  146.  
  147. private void Trade() throws InterruptedException {
  148. Player muleTrade = (Player)this.players.closest(new String[]{"Yourname"});
  149.  
  150.  
  151. if(grandExchange.isOpen()){
  152. grandExchange.close();
  153. }
  154. if(store.isOpen()){
  155. store.close();
  156. }
  157.  
  158. if(!trade.isFirstInterfaceOpen()) {
  159. if(muleTrade != null) {
  160. muleTrade.interact(new String[]{"Trade with"});
  161. new ConditionalSleep(5000) {
  162.  
  163. public boolean condition() throws InterruptedException {
  164. return getTrade().isCurrentlyTrading();
  165. }
  166. }.sleep();
  167. }else{
  168. return;
  169. }
  170. }
  171. if(trade.isFirstInterfaceOpen()){
  172. trade.offer("Coins",GetQuantity());
  173. getTrade().acceptTrade();
  174. new ConditionalSleep(5000){
  175.  
  176. public boolean condition() throws InterruptedException {
  177. return getTrade().isSecondInterfaceOpen();
  178. }
  179. }.sleep();
  180. }
  181. if(trade.isSecondInterfaceOpen()){
  182. getTrade().acceptTrade();
  183. new ConditionalSleep(5000){
  184.  
  185. public boolean condition() throws InterruptedException {
  186. return !getTrade().isSecondInterfaceOpen();
  187. }
  188. }.sleep();
  189. GotTradeOffer = false;
  190. if (inventory.contains("Willow longbow") && inventory.contains("Willow shortbow") && inventory.contains("Maple shortbow") && inventory.contains("Maple longbow")) {
  191. GoToShop();
  192. }
  193. if (!inventory.contains("Willow longbow") || !inventory.contains("Willow shortbow") || !inventory.contains("Maple shortbow") || !inventory.contains("Maple longbow")) {
  194. GoToGe();
  195. }
  196. }
  197. }
  198.  
  199. private int GetQuantity() {
  200. int x = (int) (inventory.getAmount("Coins") - 100000);
  201. return x;
  202. }
  203.  
  204. public boolean invcheck(String name){
  205. if(inventory.contains(name) && inventory.getAmount(name) == 100){
  206. return true;
  207. }
  208.  
  209. return false;
  210. }
  211.  
  212.  
  213. private void GoToGe() throws InterruptedException {
  214. NPC grandexchangeclerk = npcs.closest("Grand Exchange Clerk");
  215.  
  216.  
  217.  
  218.  
  219. if (!grandexchangeArea.contains(myPlayer())) {
  220. walking.webWalk(grandexchangeArea);
  221. }
  222. if (grandexchangeArea.contains(myPlayer())) {
  223. if (inventory.contains(849) || inventory.contains(847) || inventory.contains(851) || inventory.contains(853)) {
  224. changetonoted();
  225. } else {
  226. if (!grandExchange.isOpen()) {
  227. if (grandexchangeclerk != null) {
  228. grandexchangeclerk.interact("Exchange");
  229. new ConditionalSleep(Script.random(5000, 8000)) {
  230. public boolean condition()
  231. throws InterruptedException {
  232. return grandExchange.isOpen();
  233. }
  234. }.sleep();
  235. }
  236. }
  237. if (grandExchange.isOpen()) {
  238. BUY(847, "willow longbow", 150, 100, "Steel arrow", 32);
  239. BUY(849, "willow shortbow", 100, 100, "Steel arrow", 32);
  240. BUY(851, "Maple longbow", 336, 100, "Steel arrow", 32);
  241. BUY(853, "Maple shortbow", 208, 100, "Steel arrow", 32);
  242. }
  243. }
  244.  
  245.  
  246. if(inventory.getAmount("Coins") >= 100000){
  247. despositcoins();
  248. }
  249. }
  250. }
  251.  
  252. private void despositcoins() throws InterruptedException {
  253. if(!bank.isOpen()){
  254. bank.open();
  255. }
  256. if (bank.isOpen()) {
  257. coinsinbank = (int) bank.getAmount("Coins");
  258. bank.deposit("Coins",GetQuantity());
  259. bank.close();
  260. }
  261. }
  262.  
  263. public GrandExchange.Box getbox(){
  264. if(grandExchange.getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.EMPTY){
  265. return GrandExchange.Box.BOX_1;
  266. }
  267. if(grandExchange.getStatus(GrandExchange.Box.BOX_2) == GrandExchange.Status.EMPTY){
  268. return GrandExchange.Box.BOX_2;
  269. }
  270. if(grandExchange.getStatus(GrandExchange.Box.BOX_3) == GrandExchange.Status.EMPTY){
  271. return GrandExchange.Box.BOX_3;
  272. }
  273.  
  274.  
  275. return null;
  276. }
  277.  
  278.  
  279.  
  280. public void BuyMethod(String name,int price,int Quantity) throws InterruptedException {
  281. grandExchange.buyItems(getbox());
  282. sleep(random(1000,1500));
  283. keyboard.typeString(name);
  284. keyboard.typeString("",true);
  285.  
  286. }
  287.  
  288. private void changetonoted() throws InterruptedException {
  289. if(!bank.isOpen()){
  290. bank.open();
  291. }
  292. if (bank.isOpen()) {
  293. bank.depositAllExcept("Coins");
  294. sleep(random(1000, 1500));
  295. getWidgets().getWidgetContainingText("Note").interact("Note");
  296. sleep(random(1000, 1500));
  297. if (bank.contains("Maple shortbow")) {
  298. bank.withdrawAll("Maple shortbow");
  299. }
  300. if (bank.contains("Maple longbow")) {
  301. bank.withdrawAll("Maple longbow");
  302. }
  303. if (bank.contains("Willow shortbow")) {
  304. bank.withdrawAll("Willow shortbow");
  305. }
  306. if (bank.contains("Willow longbow")) {
  307. bank.withdrawAll("Willow longbow");
  308. }
  309. }
  310. }
  311.  
  312. public void BUY(int id,String name,int Price,int Quantity,String Sellingname,int Sellingprice) throws InterruptedException {
  313. if(inventory.contains(Sellingname)){
  314. grandExchange.sellItem(886,Sellingprice, (int) inventory.getAmount(886));
  315. new ConditionalSleep(Script.random(5000, 8000)) {
  316. public boolean condition()
  317. throws InterruptedException {
  318. return grandExchange.isOpen();
  319. }
  320. }.sleep();
  321. sleep(random(1000, 1100));
  322. }
  323.  
  324. if (grandExchange.getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.FINISHED_SALE || grandExchange.getStatus(GrandExchange.Box.BOX_2) == GrandExchange.Status.FINISHED_SALE || grandExchange.getStatus(GrandExchange.Box.BOX_3) == GrandExchange.Status.FINISHED_SALE) {
  325. grandExchange.collect();
  326. }
  327.  
  328. if (grandExchange.getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.FINISHED_BUY || grandExchange.getStatus(GrandExchange.Box.BOX_2) == GrandExchange.Status.FINISHED_BUY || grandExchange.getStatus(GrandExchange.Box.BOX_3) == GrandExchange.Status.FINISHED_BUY) {
  329. grandExchange.collect();
  330. } else if (!inventory.contains(name) && grandExchange.getItemId(GrandExchange.Box.BOX_1) != id && grandExchange.getItemId(GrandExchange.Box.BOX_2) != id && grandExchange.getItemId(GrandExchange.Box.BOX_3) != id || inventory.contains(name) && inventory.getAmount(name) < Quantity && grandExchange.getItemId(GrandExchange.Box.BOX_1) != id && grandExchange.getItemId(GrandExchange.Box.BOX_2) != id && grandExchange.getItemId(GrandExchange.Box.BOX_3) != id) {
  331. grandExchange.buyItem(id, name, Price, GetQuantity(name,Quantity));
  332.  
  333.  
  334. new ConditionalSleep(Script.random(5000, 8000)) {
  335. public boolean condition()
  336. throws InterruptedException {
  337. return grandExchange.isOpen();
  338. }
  339. }.sleep();
  340. sleep(random(1000, 1100));
  341. }
  342. }
  343.  
  344. private int GetQuantity(String name,int InitialQuantity) {
  345. if(!inventory.contains(name)){
  346. return InitialQuantity;
  347. }
  348. if(inventory.contains(name) && inventory.getAmount(name) < 100){
  349. int x = (int) (100 - inventory.getAmount(name));
  350. return x;
  351. }
  352. return 0;
  353. }
  354.  
  355. private void GoToShop() throws InterruptedException {
  356. NPC Brian = npcs.closest("Brian");
  357.  
  358. if(!shopArea.contains(myPlayer())){
  359. walking.webWalk(shopArea);
  360. }
  361. if(shopArea.contains(myPlayer())){
  362. if(!store.isOpen()){
  363. if(Brian !=null) {
  364. Brian.interact("Trade");
  365. new ConditionalSleep(Script.random(5000, 8000))
  366. {
  367. public boolean condition()
  368. throws InterruptedException
  369. {
  370. return grandExchange.isOpen();
  371. }
  372. }.sleep();
  373. }
  374. }
  375. if(store.isOpen()){
  376. shop();
  377. HopWorlds();
  378. }
  379. }
  380. }
  381.  
  382.  
  383.  
  384.  
  385.  
  386. private void shop() throws InterruptedException {
  387. while(store.getAmount("Steel arrow") >= 1460) {
  388. store.buy("Steel arrow", 10);
  389. numberofSA = numberofSA + 10;
  390. sleep(random(800,1100));
  391. }
  392. if (store.getAmount("Oak longbow") <= 5) {
  393. store.sell("Oak longbow", 5);
  394. sleep(random(800,1100));
  395. }
  396. if (store.getAmount("Willow shortbow") <= 4) {
  397. store.sell("Willow shortbow", 5);
  398. numberofWSB = numberofWSB + 5;
  399. sleep(random(800,1100));
  400. }
  401. if (store.getAmount("Willow longbow") <= 4) {
  402. store.sell("Willow longbow", 5);
  403. numberofWLB = numberofWLB + 5;
  404. sleep(random(800,1100));
  405. }
  406. if (store.getAmount("Maple shortbow") <= 3) {
  407. store.sell("Maple shortbow", 5);
  408. numberofMSB = numberofMSB + 5;
  409. sleep(random(800,1100));
  410. }
  411. if (store.getAmount("Maple longbow") <= 3) {
  412. store.sell("Maple longbow", 5);
  413. numberofMLB = numberofMLB + 5;
  414. sleep(random(800,1100));
  415. }
  416. }
  417.  
  418.  
  419.  
  420.  
  421.  
  422. private void HopWorlds() throws InterruptedException {
  423. store.close();
  424. new ConditionalSleep(Script.random(5000, 8000))
  425. {
  426. public boolean condition()
  427. throws InterruptedException
  428. {
  429. return !store.isOpen();
  430. }
  431. }.sleep();
  432. worlds.hop(WorldNumber());
  433. tabs.open(Tab.INVENTORY);
  434. sleep(random(2000,3000));
  435. tabs.open(Tab.INVENTORY);
  436. new ConditionalSleep(Script.random(5000, 8000))
  437. {
  438. public boolean condition()
  439. throws InterruptedException
  440. {
  441. return tabs.open(Tab.INVENTORY);
  442. }
  443. }.sleep();
  444. sleep(random(3000,4000));
  445. }
  446. private int WorldNumber(){
  447. if(worlds.getCurrentWorld() == 301){
  448. return 8;
  449. }
  450. if(worlds.getCurrentWorld() == 308){
  451. return 16;
  452. }
  453. if(worlds.getCurrentWorld() == 316){
  454. return 26;
  455. }
  456. if(worlds.getCurrentWorld() == 326){
  457. return 35;
  458. }
  459. if(worlds.getCurrentWorld() == 335){
  460. return 82;
  461. }
  462. if(worlds.getCurrentWorld() == 382){
  463. return 83;
  464. }
  465. if(worlds.getCurrentWorld() == 383){
  466. return 84;
  467. }
  468. if(worlds.getCurrentWorld() == 384){
  469. return 93;
  470. }
  471. if(worlds.getCurrentWorld() == 393){
  472. return 94;
  473. }
  474. return 1;
  475. }
  476.  
  477. public void SendReply(String message) throws InterruptedException {
  478. if(grandExchange.isOpen()){
  479. grandExchange.close();
  480. }
  481. tabs.open(Tab.FRIENDS);
  482. new ConditionalSleep(Script.random(5000, 8000))
  483. {
  484. public boolean condition()
  485. throws InterruptedException
  486. {
  487. return Tab.FRIENDS.isOpen(bot);
  488. }
  489. }.sleep();
  490. sleep(random(1500,2000));
  491. getWidgets().getWidgetContainingText("Yourname").interact("Message");
  492. new ConditionalSleep(Script.random(5000, 8000))
  493. {
  494. public boolean condition()
  495. throws InterruptedException
  496. {
  497. return dialogues.inDialogue();
  498. }
  499. }.sleep();
  500. sleep(random(1500,2000));
  501. keyboard.typeString(message,true);
  502. }
  503.  
  504. public String getlocation(){
  505. if(shopArea.contains(myPlayer())){
  506. return "At the shop";
  507. }
  508. if(grandexchangeArea.contains(myPlayer())){
  509. return "At ge";
  510. }
  511. return null;
  512. }
  513.  
  514.  
  515.  
  516. public void onMessage(Message c) throws InterruptedException {
  517. if (c.getMessage().contains("Yourname wishes to trade with you.")){
  518. this.log("Yourname wishes to trade with you.");
  519. GotTradeOffer = true;
  520. }
  521. if (c.getMessage().contains("Where are u?.")){
  522. this.log("Message recived.");
  523. SendReply(getlocation());
  524. }
  525. if (c.getMessage().contains("Ok im here.")){
  526. this.log("Message recived.");
  527. Trade();
  528. }
  529. if (c.getMessage().contains("Ok come here.")){
  530. SendReply("Comming...");
  531. this.log("Message recived.");
  532. Status = "Muling";
  533. }
  534. if (c.getMessage().contains("Ok done.")){
  535. SendReply("Ok back to normal");
  536. this.log("Message recived.");
  537. Status = "Normal";
  538. }
  539. }
  540.  
  541. @Override
  542.  
  543. public void onPaint(Graphics2D g) {
  544.  
  545. //This is where you will put your code for paint(s)
  546.  
  547. }
  548.  
  549. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement