Guest User

Untitled

a guest
Dec 4th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.01 KB | None | 0 0
  1. package sorcGardenMinigame;
  2. import org.osbot.rs07.api.model.NPC;
  3. import org.osbot.rs07.api.map.Position;
  4. import org.osbot.rs07.api.model.RS2Object;
  5. import org.osbot.rs07.script.Script;
  6. import org.osbot.rs07.script.ScriptManifest;
  7. import org.osbot.rs07.api.map.Area;
  8. import org.osbot.rs07.input.mouse.MiniMapTileDestination;
  9.  
  10. import java.awt.*;
  11. import java.util.Arrays;
  12.  
  13.  
  14. import javax.swing.JButton;
  15. import javax.swing.JComboBox;
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JPanel;
  19.  
  20.  
  21. @ScriptManifest(name = "SorcGardenSolver", author = "Zappa2010", version = 1.1, info = "Solves the sorc garden minigame for fruitz", logo = "")
  22. public class main extends Script {
  23. private JFrame jFrame;
  24.  
  25. private long timeBegan;
  26. private long timeRan;
  27.  
  28. private String selectedGarden = "Winter";
  29. private boolean started = false;
  30.  
  31. private void createJFrame() {
  32.  
  33. final int frameWidth = 500, frameHeight = 200;
  34. final int halfFWidth = (frameWidth / 2), halfFHeight = (frameHeight / 2);
  35.  
  36. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  37. final int jFrameX = (int) (screenSize.getWidth() / 2) - halfFWidth;
  38. final int jFrameY = (int) (screenSize.getHeight() / 2) - halfFHeight;
  39.  
  40. jFrame = new JFrame("SorcGarden");
  41. jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  42. jFrame.setBounds(jFrameX, jFrameY, halfFWidth, halfFHeight);
  43.  
  44. JPanel jPanel = new JPanel();
  45. jFrame.add(jPanel);
  46.  
  47. JLabel label = new JLabel("Select garden:");
  48. label.setForeground(Color.white);
  49. jPanel.add(label);
  50. label.setBounds(10,10, label.getWidth(), label.getHeight());
  51.  
  52. JComboBox<String> gardenSelector = new JComboBox<>(new String[] { "winter", "spring" });
  53. gardenSelector.addActionListener( e-> selectedGarden = (String) gardenSelector.getSelectedItem());
  54. jPanel.add(gardenSelector);
  55.  
  56. JButton startButton = new JButton("Start");
  57. startButton.addActionListener(e -> {
  58.  
  59. started = true;
  60. jFrame.setVisible(false);
  61.  
  62. });
  63. jPanel.add(startButton);
  64.  
  65. jFrame.setVisible(true);
  66. }
  67.  
  68. //end building gui
  69. //Many thanks to Explv and Lambos Bruh for helping with the gui
  70.  
  71.  
  72. private void setGarden(){
  73. switch (selectedGarden){
  74. case "winter":
  75. garden = 0;
  76. break;
  77. case "spring":
  78. garden = 1;
  79. break;
  80. }
  81.  
  82. }
  83.  
  84. private static final Area GARDEN_AREA = new Area(2903, 5480, 2920, 5463);
  85. private static final Area BANK_AREA = new Area(3309, 3119, 3301, 3126);
  86. private static final Area ENTER_AREA = new Area(3316,3143,3324,3137);
  87.  
  88. public boolean doorIsClosed(RS2Object door) {
  89. return Arrays.asList(door.getDefinition().getActions()).contains("Open");
  90. }
  91.  
  92.  
  93. public enum State{
  94. WALK_TO_BANK, BANK, WALK_TO_GARDEN, SOLVE, EXIT, ENTER, BREATHE
  95. };
  96.  
  97.  
  98. private State getState() {
  99. if (inventory.isFull() && GARDEN_AREA.contains(myPlayer()))
  100. return State.EXIT;
  101. if (inventory.isFull() && BANK_AREA.contains(myPlayer()))
  102. return State.BANK;
  103. if (!inventory.isFull() && BANK_AREA.contains(myPlayer()))
  104. return State.WALK_TO_GARDEN;
  105. if (inventory.isFull())
  106. return State.WALK_TO_BANK;
  107. if(!inventory.isFull() &&ENTER_AREA.contains(myPlayer()))
  108. return State.ENTER;
  109. return State.SOLVE;
  110. }
  111. //Code to find + pick the fruit from the tree
  112. private boolean pickFruit() throws InterruptedException{
  113. RS2Object tree = objects.closest("Sq'irk tree");
  114. if(tree != null){
  115. tree.interact("Pick-Fruit");
  116. sleep(random(4000,5000));
  117. fruitPicked++;
  118. return true;
  119. }
  120. return false;
  121. }
  122. //All garden areas
  123. //0 - winter
  124. private Area[] treeZones={
  125. new Area (2888,5479,2895,5472),
  126. new Area(2933,5467,2930,5465)
  127. };
  128.  
  129. //If the user is in the garden's tree zone, pick the fruit
  130. private boolean inTreeZone(int i)throws InterruptedException{
  131. return (treeZones[i].contains(myPlayer()))? pickFruit(): false;
  132. }
  133.  
  134. //Area check for garden solver loop
  135. private boolean inArea(int i){
  136. log("here");
  137. return (playerArea[garden][i].contains(myPlayer())) ? true : false ;
  138.  
  139. }
  140.  
  141. @Override
  142. public void onStart() {
  143.  
  144. timeBegan = System.currentTimeMillis();
  145. createJFrame();
  146.  
  147. }
  148.  
  149. @Override
  150. public void onExit() {
  151. if (jFrame != null) {
  152.  
  153. jFrame.setVisible(false);
  154. jFrame.dispose();
  155. }
  156. log("Thanks for using my script! Please leave feedback");
  157. }
  158.  
  159. private Position[][] walkPath = {
  160.  
  161. { //winter path
  162. new Position(2903,5470,0),
  163. new Position(2900,5476,0),
  164. new Position(2898,5481,0),
  165. new Position(2893,5481,0),
  166. new Position(2892,5484,0),
  167. new Position(2891,5478,0)
  168. },
  169. {
  170. new Position(2920,5473,0),
  171. new Position(2923,5471,0),
  172. new Position(2923,5466,0),
  173. new Position(2923,5465,0),
  174. new Position(2923,5459,0),
  175. new Position(2924,5468,0),
  176. new Position(2928,5470,0),
  177. new Position(2931,5466,0)
  178.  
  179. }
  180. };
  181. private Area[][] NpcArea ={
  182.  
  183. {//winter NpcArea
  184. new Area(2899,5476,2897,5475),
  185. new Area(2897, 5478, 2897, 5472),
  186. new Area(2899,5480,2896,5483),
  187. new Area(2893,5481,2892,5483),
  188. new Area(2896,5482,2900,5483),
  189. new Area(2893, 5485, 2897, 5485),
  190. new Area(2896,5482,2891,5481)
  191. },
  192. {
  193. new Area(2922,5469,2922,5462),
  194. new Area(2922,5465,2922,5471),
  195. new Area(2925,5461,2926,5459),
  196. new Area(2925,5463,2928,5462),
  197. new Area(2925,5466,2925,5472),
  198. new Area(2925,5469,2925,5473),
  199. new Area(2931,5470,2931,5477),
  200. new Area(2931,5469,2933,5469)
  201. }
  202.  
  203. };
  204.  
  205. private Area[][] playerArea ={
  206.  
  207. { //Winter garden = 0
  208. GARDEN_AREA,
  209. new Area(2902,5470,2901,5470),
  210. new Area(2901,5475,2899,5477),
  211. new Area(2898,5481,2897,5481),
  212. new Area(2892,5485,2891,5483)
  213. },
  214. {//spring garden = 1
  215. GARDEN_AREA,
  216. new Area(2923,5473,2923,5471),
  217. new Area(2923,5466,2923,5465),
  218. new Area(2923,5459,2923,5458),
  219. new Area(2924,5468,2926,5468),
  220. new Area(2926,5470,2928,5470)
  221. }
  222. };
  223.  
  224. private void startRun() throws InterruptedException{
  225. do {
  226. sleep(random(1000,4000));
  227. }while(settings.getRunEnergy() < 5);
  228. settings.setRunning(true);
  229.  
  230. }
  231.  
  232. //Custom walk script to walk exact tile.. Hope this works :/
  233. public boolean pWalk(Position p) throws InterruptedException {
  234. startRun();
  235.  
  236. do{
  237. mouse.click(new MiniMapTileDestination(bot, p), false);
  238. int fail = 0;
  239. while (myPosition().distance(p) > 2 && fail < 10) {
  240. if (!myPlayer().isMoving())
  241. fail++;
  242. }
  243. if (map.distance(p) <= 5)
  244. p.interact(bot,"Walk here");
  245. return fail != 10;
  246.  
  247. }while(!myPlayer().isMoving());
  248.  
  249. }
  250.  
  251. private void gardenSolver(int i, NPC[] npc)throws InterruptedException{
  252. switch (garden){
  253. case 0:
  254. winterGarden(i,npc);
  255. break;
  256.  
  257. case 1:
  258. springGarden(i,npc);
  259. break;
  260. }
  261.  
  262. }
  263.  
  264. private int springGarden(int step, NPC[] sNpc) throws InterruptedException{
  265. switch (step){
  266. case 0:
  267. log("Walking to spring garden door");
  268. pWalk(walkPath[garden][0]);
  269. sleep(random(700,1000));
  270. log("Opening the gate");
  271. objects.closest(12719).interact("Open");
  272. log("here2");
  273. sleep(random(800,900));
  274. pWalk(walkPath[garden][1]);
  275. code = 1;
  276. break;
  277.  
  278. case 1:
  279. if (NpcArea[garden][0].contains(sNpc[0])&& sNpc[0].getRotation() == south){
  280. log("Walking to step 2");
  281. pWalk(walkPath[garden][2]);
  282. sleep(random(200,700));
  283. pWalk(walkPath[garden][3]);
  284. }
  285. break;
  286.  
  287. case 2:
  288. if (NpcArea[garden][1].contains(sNpc[0])){
  289. log("walking to step 3");
  290. pWalk(walkPath[garden][4]);
  291. sleep(random(700,1000));
  292. }
  293.  
  294. break;
  295. case 3:
  296. Area bugFix = new Area(2925,5467,2925,5465);
  297. if (bugFix.contains(myPlayer())){
  298. pWalk(walkPath[garden][4]);
  299. }
  300. if (NpcArea[garden][2].contains(sNpc[1]) && NpcArea[garden][3].contains(sNpc[2]) && NpcArea[garden][4].contains(sNpc[3]) && sNpc[3].getRotation() == north){
  301. log("Walking to step 4");
  302. pWalk(walkPath[garden][5]);
  303. sleep(random(700,1000));
  304. }
  305. break;
  306.  
  307. case 4:
  308. if (NpcArea[garden][5].contains(sNpc[3]) && sNpc[3].getRotation()== north){
  309. log("walking to step 5");
  310. pWalk(walkPath[garden][6]);
  311. sleep(random(700,1000));
  312. }
  313.  
  314. break;
  315.  
  316. case 5:
  317. if (NpcArea[garden][6].contains(sNpc[4]) && sNpc[4].getRotation() == north && NpcArea[garden][7].contains(sNpc[5]) && sNpc[5].getRotation()==east){
  318. log("Walking to tree");
  319. pWalk(walkPath[garden][7]);
  320. }
  321. break;
  322.  
  323.  
  324.  
  325. }
  326.  
  327. return code;
  328.  
  329. }
  330.  
  331.  
  332. //Following solves the winter garden
  333. private int winterGarden(int step, NPC[] wNpc) throws InterruptedException{
  334. switch (step){
  335.  
  336. case 0:
  337. log("Walking to winter garden door");
  338. pWalk(walkPath[garden][0]);
  339. sleep(random(700,1000));
  340. log("Opening the gate");
  341. objects.closest(12617).interact("Open");
  342. log("here2");
  343. sleep(random(800,900));
  344. code = 1;
  345. break;
  346.  
  347. case 1: //navigate around the first NPC
  348. if (NpcArea[garden][0].contains(wNpc[0])){
  349. log("Navigate first obsticle");
  350. pWalk(walkPath[garden][1]);
  351. log("here3");
  352. sleep(random(150, 450));
  353. code = 1;
  354. }else code = 0;
  355. break;
  356.  
  357. case 2: //Navigate around the second NPC
  358. if (NpcArea[garden][1].contains(wNpc[0]) && NpcArea[garden][2].contains(wNpc[1])){
  359. log("Navigate second obsticle");
  360. pWalk(walkPath[garden][2]);
  361. sleep(random(150, 450));
  362. code = 1;
  363. }else code =0;
  364. break;
  365.  
  366.  
  367. //for some reason it won't do this
  368. //work it out tomorrow morning
  369. case 3: //navigate around the 3rd NPC
  370. if (NpcArea[garden][3].contains(wNpc[2]) && NpcArea[garden][4].contains(wNpc[1])){
  371. log("Navigate 3rd obsticle path 1");
  372. localWalker.walk(walkPath[garden][3]); //we are running a walk right after this, and don't want to wait the preset wait
  373. sleep(random(300,500));
  374. pWalk(walkPath[garden][4]);
  375. code = 1;
  376. /* }else if (NpcArea[garden][6].contains(wNpc[1]) && NpcArea[garden][4].contains(wNpc[1])){
  377. log("Navigate 3rd obsitcle path 2");
  378. pWalk(walkPath[garden][4]);*/
  379. }else code =0;
  380. break;
  381.  
  382. case 4: //final stretch
  383. if (myPlayer().getPosition().equals(new Position(2891,5483,0))){
  384. walkPath[garden][4].interact(bot,"Walk here");
  385. sleep(random(400,700));
  386. }
  387. if (NpcArea[garden][5].contains(wNpc[3]) && wNpc[3].getRotation() == east){
  388. log("Navigate 4th obsticle");
  389. pWalk(walkPath[garden][5]);
  390. code = 1;
  391. }else code = 0;
  392. break;
  393. }
  394. return code;
  395. }
  396.  
  397. private Position[] stuckLocation={
  398. new Position(2905,5478,0),
  399. new Position(2905,5477,0),
  400. new Position(2905,5476,0)
  401. };
  402. private Position[] walkBank = {
  403. new Position(3307,3144,0),
  404. new Position(3308,3120,0)
  405. };
  406.  
  407. private Position[] walkGarden = {
  408. new Position(3304,3136,0),
  409. new Position(3321,3142,0)
  410. };
  411.  
  412. private boolean stuck() {
  413. for (int i =0; i<stuckLocation.length; i++){
  414. if (myPlayer().getPosition().equals(stuckLocation[i])){
  415. log("The bot was detected in a stuck location");
  416. log("Now attempting to restart");
  417. return true;
  418. }
  419. }
  420. return false;
  421. }
  422. //keeping these cause it's nice to have them, they will be used in the next gardens
  423. private int north = 1024;
  424. private int east = 1536;
  425. private int south = 0;
  426. private int west = 512;
  427.  
  428.  
  429. //Get our global vars for the loop
  430. private int code = 0; //not used atm
  431. private int fruitPicked = 0;
  432. private int garden;
  433.  
  434.  
  435. @Override
  436. public int onLoop() throws InterruptedException{
  437. if (started) {
  438. setGarden();
  439. switch (getState()){
  440.  
  441. case BREATHE:
  442. log("wait a min, I need to catch my breathe! (no run speed)");
  443. sleep(random(1000,7000));
  444. break;
  445.  
  446. case WALK_TO_GARDEN:
  447. log("walk to garden");
  448. localWalker.walk(walkGarden[1]);
  449. localWalker.walk(3321,3139);
  450. RS2Object doorE = objects.closest("door");
  451. if(doorE != null){
  452. if (doorIsClosed(doorE)){
  453. doorE.interact("Open");
  454. sleep(random(100,250));
  455. }
  456. }
  457. break;
  458.  
  459. case ENTER:
  460. log("entering the garden");
  461. NPC apprentice = npcs.closest("Apprentice");
  462. apprentice.interact("Teleport");
  463. sleep(random(4000,5000));
  464. break;
  465.  
  466. case BANK:
  467. log("Attempting to deposit at the bank");
  468. RS2Object bankBooth = objects.closest("Bank chest");
  469. if (bankBooth != null) {
  470. if (bankBooth.interact("Use")) {
  471.  
  472. while (!bank.isOpen()){
  473. sleep(random(250,500));
  474. bank.depositAll();
  475. }
  476. }
  477. }
  478. break;
  479.  
  480. case WALK_TO_BANK:
  481. log("Walking to the bank");
  482. RS2Object exitDoor = objects.closest("door");
  483. if (doorIsClosed(exitDoor)){
  484. exitDoor.interact("open");
  485. sleep(random(450,650));
  486. }
  487. //localWalker.walk(walkBank[0]);
  488. sleep(random(150,250));
  489. localWalker.walk(walkBank[1]);
  490. sleep(random(150,250));
  491. break;
  492.  
  493. case EXIT:
  494. log("Leaving the garden");
  495. RS2Object fountain = objects.closest("Fountain");
  496. if (fountain != null)
  497. fountain.interact("Drink-from");
  498. sleep(random(2000,3000));
  499. break;
  500.  
  501. case SOLVE:
  502.  
  503. NPC[][] gardenNpc= {
  504. {//winter Npc's
  505. npcs.closest(5798),
  506. npcs.closest(5799),
  507. npcs.closest(5800),
  508. npcs.closest(5801)
  509. },
  510.  
  511. {//autumn Npc's
  512. npcs.closest(2956),
  513. npcs.closest(2958),
  514. npcs.closest(2957),
  515. npcs.closest(2962),
  516. npcs.closest(2963),
  517. npcs.closest(2961)
  518.  
  519. }
  520. };
  521. if (!inTreeZone(garden)){
  522. for (int i = 0; i < playerArea[garden].length; i++){
  523. //log("here : "+i);
  524. if (inArea(i)){
  525. log("area : " + i);
  526. i = (stuck()) ? 0 : i;
  527. gardenSolver(i,gardenNpc[garden]);
  528. }
  529. }
  530. }
  531.  
  532. break;
  533.  
  534. }
  535. }
  536. return random(150,350); //The amount of time in milliseconds before the loop starts over
  537. }
  538.  
  539.  
  540. //stole the graphics off Lambos Bruh so, thanks bro. :)
  541. @Override
  542. public void onPaint(Graphics2D g) {
  543. if(started){
  544. /*if(tempFish < (skills.getExperience(Skill.FISHING) - startExp) && timeRan % 1000 == 0){
  545. log("Got One!");
  546. fishCounter++;
  547. }*/
  548. //tempFish = skills.getExperience(Skill.FISHING) - startExp;
  549.  
  550.  
  551. timeRan = System.currentTimeMillis() - this.timeBegan;
  552.  
  553. g.drawString("Fruits picked: "+fruitPicked,4, 315);
  554. g.drawString("Time Ran: " + ft(timeRan), 4, 330);
  555.  
  556. }
  557. }
  558.  
  559. private String ft(long duration) {
  560.  
  561. long s = duration / 1000, m = s / 60, h = m / 60;
  562. s %= 60; m %= 60; h %= 24;
  563. return String.format("%02d:%02d:%02d", h, m, s);
  564.  
  565. }
  566.  
  567. }
Advertisement
Add Comment
Please, Sign In to add comment