Advertisement
Guest User

ok_StarterWoodcutter

a guest
Dec 7th, 2013
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.90 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6.  
  7. import org.tribot.api.Timing;
  8. import org.tribot.api.General;
  9. import org.tribot.api2007.Screen;
  10. import org.tribot.api2007.types.RSTile;
  11.  
  12. import org.tribot.api.DynamicClicking;
  13. import org.tribot.api.input.Mouse;
  14. import org.tribot.api.types.generic.Condition;
  15. import org.tribot.api2007.Banking;
  16. import org.tribot.api2007.Camera;
  17. import org.tribot.api2007.Equipment;
  18. import org.tribot.api2007.GameTab;
  19. import org.tribot.api2007.Inventory;
  20. import org.tribot.api2007.Login;
  21. import org.tribot.api2007.Objects;
  22. import org.tribot.api2007.Player;
  23. import org.tribot.api2007.Skills;
  24. import org.tribot.api2007.Walking;
  25. import org.tribot.api2007.GameTab.TABS;
  26. import org.tribot.api2007.types.RSItem;
  27. import org.tribot.api2007.types.RSObject;
  28. import org.tribot.script.Script;
  29. import org.tribot.script.ScriptManifest;
  30. import org.tribot.script.interfaces.Painting;
  31. import org.tribot.script.interfaces.RandomEvents;
  32.  
  33. @ScriptManifest(authors = { "Okokokok" }, category = "ok_StarterPack", name = "ok_StarterWoodcutter")
  34. public class ok_StarterWoodcutter extends Script implements Painting, RandomEvents {
  35.  
  36. private boolean paused = false;
  37.  
  38. private double version = 1.00;
  39.  
  40. private String[] nothing;
  41.  
  42. private RSArea bankArea = new RSArea(new RSTile(3207, 3215, 2), new RSTile(3210, 3221, 2)),
  43. stairArea = new RSArea(new RSTile(3205, 3206), new RSTile(3207, 3211)),
  44. treeArea = new RSArea(new RSTile(3178, 3207, 0), new RSTile(3200, 3235, 0)),
  45. walkingArea = new RSArea(new RSTile(3160, 3198), new RSTile(3245, 3251));
  46.  
  47. private RSTile[] bankPath = new RSTile[] {new RSTile(3205, 3210, 2), new RSTile(3208, 3219, 2), new RSTile(3206, 3215, 2), new RSTile(3208, 3220, 2)},
  48. treePath = new RSTile[] {new RSTile(3205, 3209, 0), new RSTile(3213, 3210, 0),
  49. new RSTile(3215, 3216, 0), new RSTile(3223, 3219, 0),
  50. new RSTile(3229, 3220, 0), new RSTile(3231, 3226, 0),
  51. new RSTile(3227, 3234, 0), new RSTile(3221, 3239, 0),
  52. new RSTile(3215, 3239, 0), new RSTile(3208, 3240, 0),
  53. new RSTile(3202, 3240, 0), new RSTile(3196, 3238, 0),
  54. new RSTile(3190, 3234, 0), new RSTile(3190, 3226, 0),
  55. new RSTile(3192, 3219, 0), new RSTile(3186, 3214, 0),
  56. new RSTile(3189, 3207, 0), new RSTile(3193, 3212, 0)};
  57.  
  58. // MISC METHODS
  59.  
  60. public boolean waitFor(Condition c, long timeout) {
  61. Timer t = new Timer(timeout);
  62. while (t.isRunning()) {
  63. if (c.active()) {
  64. return true;
  65. }
  66. sleep(60, 80);
  67. }
  68. return false;
  69. }
  70.  
  71. public boolean loggedOut() {
  72. return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
  73. && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
  74. }
  75.  
  76. public boolean logout() {
  77. if (Login.getLoginState() == Login.STATE.INGAME)
  78. {
  79. Login.logout();
  80. for(int x = 0; x < 6; x++)
  81. {
  82. if(loggedOut())
  83. {
  84. return true;
  85. }
  86. sleep(490,510);
  87. }
  88. }
  89. return false;
  90. }
  91.  
  92.  
  93. // ANTI-BAN BY SOKCRA
  94. public void antiBan(int rotation) {
  95. int number = General.random(1, 500);
  96. sleep(200);
  97. switch (number) {
  98. case 1:
  99. case 2:
  100. case 3:
  101. case 4:
  102. case 5:
  103. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  104. break;
  105. case 20:
  106. case 21:
  107. case 22:
  108. case 23:
  109. case 24:
  110. case 25:
  111. case 26:
  112. case 27:
  113. case 28:
  114. case 29:
  115. case 30:
  116. case 31:
  117. Mouse.move(General.random(100, 200), General.random(200, 400));
  118. sleep(200);
  119. break;
  120. case 50:
  121. GameTab.open(TABS.INVENTORY);
  122. sleep(200);
  123. break;
  124. case 75:
  125. GameTab.open(TABS.STATS);
  126. sleep(300);
  127. Mouse.moveBox(678, 386, 725, 366);
  128. sleep(1000, 1500);
  129. GameTab.open(TABS.INVENTORY);
  130. break;
  131. case 76:
  132. GameTab.open(TABS.FRIENDS);
  133. sleep(2000, 3000);
  134. GameTab.open(TABS.INVENTORY);
  135. break;
  136. case 89:
  137. case 90:
  138. case 91:
  139. case 92:
  140. case 93:
  141. case 94:
  142. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  143. sleep(200, 400);
  144. break;
  145. case 95:
  146. case 96:
  147. case 97:
  148. case 98:
  149. case 99:
  150. case 100:
  151. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  152. sleep(200, 400);
  153. break;
  154. }
  155. }
  156.  
  157. // HATCHET METHODS
  158.  
  159. private boolean haveHatchetInv(){
  160. RSItem[] hatchet = Inventory.find("Bronze axe");
  161. return hatchet != null && hatchet.length > 0;
  162. }
  163.  
  164. private boolean haveHatchetEquipped(){
  165. RSItem[] hatchet = Equipment.find("Bronze axe");
  166. return hatchet != null && hatchet.length > 0;
  167. }
  168.  
  169. private void equipHatchet(){
  170. RSItem[] hatchet = Inventory.find("Bronze axe");
  171. if (hatchet != null && hatchet.length > 0){
  172. if(hatchet[0].click("Wield")){
  173. waitFor(new Condition(){
  174. @Override
  175. public boolean active(){
  176. return haveHatchetEquipped();
  177. }
  178. }, 4000);
  179. }
  180. }
  181. }
  182.  
  183. // BANKING METHODS
  184.  
  185. private void openBank(){
  186. if(Banking.isBankScreenOpen()){
  187. sleep(100);
  188. }
  189. if(!Banking.isBankScreenOpen()){
  190. Banking.openBankBooth();
  191. }
  192. }
  193.  
  194. private void withdrawHatchet(){
  195. RSItem[] hatchet = Banking.find("Bronze axe");
  196. if(hatchet != null && hatchet.length > 0){
  197. if(Banking.withdraw(1, "Bronze axe")){
  198. waitFor(new Condition(){
  199. @Override
  200. public boolean active(){
  201. return haveHatchetInv();
  202. }
  203. }, 4000);
  204. }
  205. }
  206. }
  207.  
  208. // WALKING METHODS
  209.  
  210. private void bankWalk(){
  211. final RSTile myPos = Player.getPosition();
  212. if(!bankArea.contains(myPos)){
  213. if(Walking.walkPath(bankPath)){
  214. waitFor(new Condition(){
  215. @Override
  216. public boolean active(){
  217. return !Player.isMoving() && bankArea.contains(myPos);
  218. }
  219. }, 6000);
  220. }
  221. }
  222. }
  223.  
  224. private void stairWalkP2(){
  225. final RSTile myPos = Player.getPosition();
  226. if(!stairArea.contains(myPos)){
  227. if(Walking.walkPath(Walking.invertPath(bankPath))){
  228. waitFor(new Condition(){
  229. @Override
  230. public boolean active(){
  231. return !Player.isMoving() && stairArea.contains(myPos);
  232. }
  233. }, 4000);
  234. }
  235. }
  236. }
  237.  
  238. private void stairWalkP0(){
  239. final RSTile myPos = Player.getPosition();
  240. if(!stairArea.contains(myPos)){
  241. if(Walking.walkPath(Walking.invertPath(treePath))){
  242. waitFor(new Condition(){
  243. @Override
  244. public boolean active(){
  245. return stairArea.contains(myPos);
  246. }
  247. }, 4000);
  248. }
  249. }
  250. }
  251.  
  252. private void treeWalk(){
  253. final RSTile myPos = Player.getPosition();
  254. if(!treeArea.contains(myPos)){
  255. if(Walking.walkPath(treePath)){
  256. waitFor(new Condition(){
  257. @Override
  258. public boolean active(){
  259. return treeArea.contains(myPos) && !Player.isMoving();
  260. }
  261. }, 6000);
  262. }
  263. }
  264. }
  265.  
  266. // LADDER METHODS
  267.  
  268. private void climbLadder(){
  269. RSObject[] stairs = Objects.findNearest(5, "Staircase");
  270. final int plane = Player.getPosition().getPlane();
  271. if(stairs != null && stairs.length > 0){
  272. if(haveHatchetEquipped() && plane == 2){
  273. if(DynamicClicking.clickRSObject(stairs[0], "Climb-down")){
  274. waitFor(new Condition(){
  275. @Override
  276. public boolean active(){
  277. return plane == 1;
  278. }
  279. }, 4000);
  280. }
  281. }
  282. if(haveHatchetEquipped() && plane == 1){
  283. if(DynamicClicking.clickRSObject(stairs[0], "Climb-down")){
  284. waitFor(new Condition(){
  285. @Override
  286. public boolean active(){
  287. return plane == 0;
  288. }
  289. }, 4000);
  290. }
  291. }
  292. if(!haveHatchetEquipped() && plane == 0){
  293. if(DynamicClicking.clickRSObject(stairs[0], "Climb-up")){
  294. waitFor(new Condition(){
  295. @Override
  296. public boolean active(){
  297. return plane == 1;
  298. }
  299. }, 4000);
  300. }
  301. }
  302. if(!haveHatchetEquipped() && plane == 1){
  303. if(DynamicClicking.clickRSObject(stairs[0], "Climb-up")){
  304. waitFor(new Condition(){
  305. @Override
  306. public boolean active(){
  307. return plane == 2;
  308. }
  309. }, 4000);
  310. }
  311. }
  312. }
  313. }
  314.  
  315. private void walkTree(){
  316. if(Walking.walkTo(getTree())){
  317. waitFor(new Condition(){
  318. @Override
  319. public boolean active(){
  320. return !Player.isMoving();
  321. }
  322. }, 8000);
  323. }
  324. }
  325.  
  326. // TREE METHODS
  327.  
  328. private boolean treeLength(){
  329. RSObject[] tree = Objects.findNearest(30, "Tree");
  330. return tree != null && tree.length > 0 && tree[0].getModel().getPoints().length == 366;
  331. }
  332.  
  333. private RSTile getTree(){
  334. RSObject[] tree = Objects.findNearest(30, "Tree");
  335. return tree[0].getPosition();
  336. }
  337.  
  338. public boolean treeInArea(){
  339. RSObject[] tree = Objects.findNearest(30, "Tree");
  340. if(tree != null && tree.length > 0){
  341. if(treeArea.contains(getTree())){
  342. return true;
  343. }
  344. }
  345. return false;
  346. }
  347.  
  348. private boolean isTreeChopped(){
  349. final RSTile myPos = Player.getPosition();
  350. return myPos.distanceTo(getTree()) > 1;
  351. }
  352.  
  353. private boolean isTreeOnscreen(){
  354. RSObject[] tree = Objects.findNearest(30, "Tree");
  355. return tree != null && tree.length > 0 && tree[0].isOnScreen();
  356. }
  357.  
  358. private boolean isTreeOffscreen(){
  359. RSObject[] tree = Objects.findNearest(30, "Tree");
  360. return tree != null && tree.length > 0 && !tree[0].isOnScreen();
  361. }
  362.  
  363. // WOODCUTTING METHODS
  364.  
  365. private void chopTree(){
  366. RSObject[] tree = Objects.findNearest(30, "Tree");
  367. if(tree != null && tree.length > 0){
  368. if(DynamicClicking.clickRSObject(tree[0], "Chop down")){
  369. sleep(1500, 1700);
  370. waitFor(new Condition(){
  371. @Override
  372. public boolean active(){
  373. return Player.getAnimation() == -1 && isTreeChopped() || !treeLength();
  374. }
  375. }, 10000);
  376. }
  377. }
  378. }
  379.  
  380. // DROPPING METHODS
  381.  
  382. private void dropInventory(){
  383. if(Inventory.isFull()){
  384. Inventory.dropAllExcept(nothing);
  385. }
  386. }
  387.  
  388. // STATES
  389.  
  390. private enum State{
  391. OPENING_BANK, WITHDRAWING_HATCHET,
  392. WALKING_BANK, WALKING_STAIRS_UP,
  393. WALKING_STAIRS_DOWN, WALKING_TO_TREES,
  394. WALK_TREE, CLIMBING_LADDER,
  395. CHOPPING, DROPPING, CLOSING_BANK,
  396. EQUIPPING_HATCHET, SOLVING_RANDOM,
  397. LOGING_OUT;
  398. }
  399.  
  400. private State getState(){
  401. final RSTile myPos = Player.getPosition();
  402. final int plane = Player.getPosition().getPlane();
  403. if(paused){
  404. return State.SOLVING_RANDOM;
  405. }
  406. if(bankArea.contains(myPos)){
  407. if(!haveHatchetInv() && !haveHatchetEquipped() && !Banking.isBankScreenOpen() && plane == 2){
  408. return State.OPENING_BANK;
  409. }
  410. if(!haveHatchetInv() && !haveHatchetEquipped() && Banking.isBankScreenOpen()){
  411. return State.WITHDRAWING_HATCHET;
  412. }
  413. if(haveHatchetInv() && !haveHatchetEquipped() && Banking.isBankScreenOpen()){
  414. return State.CLOSING_BANK;
  415. }
  416. if(haveHatchetInv() && !haveHatchetEquipped() && !Banking.isBankScreenOpen()){
  417. return State.EQUIPPING_HATCHET;
  418. }
  419. if(!haveHatchetInv() && haveHatchetEquipped() && !Banking.isBankScreenOpen()){
  420. return State.WALKING_STAIRS_UP;
  421. }
  422. }
  423. if(stairArea.contains(myPos)){
  424. if(!haveHatchetEquipped() && !bankArea.contains(myPos) && plane == 2){
  425. return State.WALKING_BANK;
  426. }
  427. if(haveHatchetEquipped() && plane == 2){
  428. return State.CLIMBING_LADDER;
  429. }
  430. if(haveHatchetEquipped() && plane == 1){
  431. return State.CLIMBING_LADDER;
  432. }
  433. if(haveHatchetEquipped() && plane == 0){
  434. return State.WALKING_TO_TREES;
  435. }
  436. if(!haveHatchetEquipped() && plane == 0){
  437. return State.CLIMBING_LADDER;
  438. }
  439. if(!haveHatchetEquipped() && plane == 1){
  440. return State.CLIMBING_LADDER;
  441. }
  442. }
  443. if(treeArea.contains(myPos)){
  444. if(haveHatchetEquipped()){
  445. if(!Inventory.isFull()){
  446. if(isTreeOnscreen() && treeArea.contains(getTree())){
  447. return State.CHOPPING;
  448. }
  449. if(isTreeOffscreen() && treeArea.contains(getTree())){
  450. return State.WALK_TREE;
  451. }
  452. }
  453. if(Inventory.isFull()){
  454. return State.DROPPING;
  455. }
  456. }
  457. if(!haveHatchetEquipped()){
  458. return State.WALKING_STAIRS_DOWN;
  459. }
  460. }
  461. if(walkingArea.contains(myPos) && !bankArea.contains(myPos) && !stairArea.contains(myPos) && treeArea.contains(myPos)){
  462. return State.WALK_TREE;
  463. }
  464. if(walkingArea.contains(myPos) && !bankArea.contains(myPos) && !stairArea.contains(myPos) && !treeArea.contains(myPos)){
  465. if(haveHatchetEquipped()){
  466. if(plane == 0){
  467. return State.WALKING_TO_TREES;
  468. }
  469. if(plane == 1){
  470. return State.CLIMBING_LADDER;
  471. }
  472. if(plane == 2){
  473. return State.WALKING_STAIRS_UP;
  474. }
  475. }
  476. if(!haveHatchetEquipped()){
  477. if(plane == 0){
  478. return State.WALKING_STAIRS_DOWN;
  479. }
  480. if(plane == 1){
  481. return State.CLIMBING_LADDER;
  482. }
  483. if(plane == 2){
  484. return State.WALKING_BANK;
  485. }
  486. }
  487. }
  488. if(paused){
  489. return State.SOLVING_RANDOM;
  490. }
  491. return State.LOGING_OUT;
  492. }
  493.  
  494.  
  495.  
  496.  
  497. private static final long startTime = System.currentTimeMillis();
  498. Font font = new Font("Calibri", Font.BOLD, 16);
  499. private State SCRIPT_STATE = getState();
  500.  
  501.  
  502. @SuppressWarnings("deprecation")
  503. private final int startXP = Skills.getXP("woodcutting");
  504. private int START_XP;
  505.  
  506. @SuppressWarnings("deprecation")
  507. @Override
  508. public void onPaint(Graphics g) {
  509.  
  510. long timeRan = System.currentTimeMillis() - startTime;
  511. double multiplier = timeRan / 3600000D;
  512. int xpGained = Skills.getXP("woodcutting") - START_XP;
  513.  
  514. g.setFont(font);
  515. g.setColor(new Color(255, 255, 255));
  516. g.drawString("ok_StarterWoodcutter V" + version, 558, 220);
  517. g.drawString("Action: " + SCRIPT_STATE, 558, 235);
  518. g.drawString("Time running: " + Timing.msToString(timeRan), 558, 250);
  519.  
  520. g.drawString("XP Gained p/h: " + (int) (xpGained / multiplier), 558, 265);
  521. g.drawString("XP Gained: " + (int) xpGained, 558, 280);
  522.  
  523. g.drawString("Logs p/h: " + (int)((xpGained / 25) / multiplier), 558, 295);
  524. g.drawString("Logs chopped: " + (int) (xpGained / 25), 558, 310);
  525. }
  526.  
  527. @SuppressWarnings("deprecation")
  528. @Override
  529. public void run() {
  530. // TODO Auto-generated method stub
  531. println("Started ok_StarterWoodcutter");
  532. START_XP = startXP;
  533. super.setRandomSolverState(true);
  534. Walking.setControlClick(true);
  535.  
  536.  
  537. while(true){
  538. if (loggedOut()) {
  539. super.setLoginBotState(active);
  540. } else {
  541. while (!loggedOut()) {
  542. SCRIPT_STATE = getState();
  543. int mSpeed = General.random(180, 200);
  544. Mouse.setSpeed(mSpeed);
  545. Walking.setControlClick(true);
  546.  
  547. switch (SCRIPT_STATE) {
  548.  
  549. case CHOPPING:
  550. chopTree();
  551. sleep(200, 300);
  552.  
  553. int rotation5 = General.random(90, 200);
  554. antiBan(rotation5);
  555. break;
  556.  
  557. case CLIMBING_LADDER:
  558. climbLadder();
  559. sleep(200, 300);
  560. break;
  561.  
  562. case DROPPING:
  563. dropInventory();
  564. sleep(200, 300);
  565. break;
  566.  
  567. case LOGING_OUT:
  568. logout();
  569. stopScript();
  570. sleep(200, 300);
  571. break;
  572.  
  573. case OPENING_BANK:
  574. openBank();
  575. sleep(200, 300);
  576. break;
  577.  
  578. case WALKING_BANK:
  579. bankWalk();
  580. sleep(200, 300);
  581. break;
  582.  
  583. case WALKING_STAIRS_DOWN:
  584. stairWalkP0();
  585. sleep(200, 300);
  586. break;
  587.  
  588. case WALKING_STAIRS_UP:
  589. stairWalkP2();
  590. sleep(200, 300);
  591. break;
  592.  
  593. case WALKING_TO_TREES:
  594. treeWalk();
  595. sleep(200, 300);
  596. break;
  597.  
  598. case WALK_TREE:
  599. walkTree();
  600. sleep(200, 300);
  601. break;
  602.  
  603. case WITHDRAWING_HATCHET:
  604. withdrawHatchet();
  605. sleep(200, 300);
  606. break;
  607.  
  608. case CLOSING_BANK:
  609. Banking.close();
  610. sleep(200, 300);
  611. break;
  612.  
  613. case EQUIPPING_HATCHET:
  614. equipHatchet();
  615. sleep(200, 300);
  616. break;
  617.  
  618. case SOLVING_RANDOM:
  619. while(paused){
  620. sleep(100, 150);
  621. println("Solving Random");
  622. }
  623.  
  624. break;
  625.  
  626. }
  627. }
  628. }
  629. }
  630. }
  631.  
  632. @Override
  633. public void onRandom(RANDOM_SOLVERS arg0) {
  634. paused = true;
  635. }
  636.  
  637. @Override
  638. public boolean randomFailed(RANDOM_SOLVERS arg0) {
  639. paused = false;
  640. return false;
  641. }
  642.  
  643. @Override
  644. public void randomSolved(RANDOM_SOLVERS arg0) {
  645. paused = false;
  646.  
  647. }
  648. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement