Guest User

Untitled

a guest
Jul 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.84 KB | None | 0 0
  1. /**
  2. * Created by IntelliJ IDEA.
  3. * User: Jesse
  4. * Date: Nov 30, 2009
  5. * Time: 10:29:53 PM
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. package com.kosaki;
  9. /*
  10. * Copyright © 2009 Jan Ove Saltvedt.
  11. * All rights reserved.
  12. */
  13.  
  14. import com.kbotpro.scriptsystem.events.PaintEventListener;
  15. import com.kbotpro.scriptsystem.interfaces.Looped;
  16. import com.kbotpro.scriptsystem.runnable.Script;
  17. import com.kbotpro.scriptsystem.runnable.Worker;
  18. import com.kbotpro.scriptsystem.wrappers.PhysicalObject;
  19. import com.kbotpro.scriptsystem.wrappers.Tile;
  20. import com.kbotpro.scriptsystem.wrappers.Interface;
  21. import com.kbotpro.scriptsystem.wrappers.IComponent;
  22. import com.kbotpro.scriptsystem.fetch.Bank;
  23. import com.kbotpro.scriptsystem.fetch.Skills;
  24.  
  25. import java.awt.*;
  26. import java.text.DecimalFormat;
  27. import java.text.DecimalFormatSymbols;
  28.  
  29. public class DeviantWoodcutter extends Script implements PaintEventListener {
  30. public String getName() {
  31. return "Deviant Woodcutter";
  32. }
  33.  
  34. public boolean canStart() {
  35. return true;
  36. }
  37.  
  38. public void onStart() {
  39. startTime = System.currentTimeMillis();
  40. startExp = skills.getExperience(Skills.SKILL_WOODCUTTING);
  41. lastExp = skills.getExperience(Skills.SKILL_WOODCUTTING);
  42. startLevel = skills.getLevel(Skills.SKILL_WOODCUTTING);
  43. if (inventory.contains(hatchet)) {
  44. wieldable = false;
  45. }
  46. }
  47.  
  48. public void pause() {
  49. }
  50.  
  51. public void stop() {
  52. }
  53.  
  54. private final Tile[] bankToTrees = new Tile[]{new Tile(3093, 3244),
  55. new Tile(3086, 3234)};
  56. private final int[] treeIDs = new int[]{5553, 5551, 5552}, hatchet = new int[]{1351, 1349, 1353, 1361, 1355, 1357, 1359, 6739, 13470};
  57. ;
  58. private int treeID = 5553, bankID = 2213, logID = 1519, startExp, startLevel, lastExp, chopped;
  59. public Color BG = new Color(59, 52, 39, 100);
  60. private boolean chopping = false, wieldable;
  61. private long startTime;
  62.  
  63. public enum Action {
  64. CHOP, BANK, WALKTOTREE, WALKTOTREES, WALKTOBANK, NOTHING, ANTIBAN
  65. }
  66.  
  67. public void registerWorkers() {
  68. createWorker(new Looped() {
  69. public int loop() {
  70. try {
  71. /*if(game.getCurrentTab() > -1)
  72. closeTab(game.getCurrentTab());
  73. */
  74. Action action = getAction();
  75. if (action != null) {
  76. switch (action) {
  77. case CHOP:
  78. if (!objectOnScreen(Object(treeIDs))) {
  79. camera.setAngle(camera.getAngleTo(Object(treeIDs).getLocation()));
  80. }
  81. Object(treeIDs).doAction("chop");
  82. sleep(1200, 1300);
  83. break;
  84. case BANK:
  85. if (inventory.isFull() & isInZone(3095, 3087, 3240, 3247)) {
  86. if (!bank.isOpen()) {
  87. if (!objectOnScreen(Object(bankID))) {
  88. camera.setAngle(camera.getAngleTo(Object(bankID).getLocation()));
  89. }
  90. Object(bankID).doAction("use-quickly");
  91. if (!bank.isOpen()) {
  92. sleep(2000, 2200);
  93. }
  94. }
  95. if (bank.isOpen()) {
  96. if (inventory.isFull()) {
  97. if (wieldable)
  98. bank.depositAll();
  99. else
  100. bank.depositAllExcept(hatchet);
  101. }
  102. close();
  103. }
  104. }
  105. break;
  106. case WALKTOBANK:
  107. if (inventory.isFull() & !isInZone(3095, 3087, 3240, 3247) & !getMyPlayer().isMoving()) {
  108. walkPathMM(reversePath(bankToTrees), 16);
  109. }
  110. break;
  111. case WALKTOTREE:
  112. walking.walkToMM(Object(treeIDs).getLocation());
  113. break;
  114. case WALKTOTREES:
  115. walkPathMM(bankToTrees, 16);
  116. break;
  117. case ANTIBAN:
  118. int random = random(1, 20);
  119. switch (random) {
  120. case 1:
  121. mouse.moveMouseRandomly(300);
  122. break;
  123. case 2:
  124. mouse.moveMouseRandomly(100);
  125. break;
  126. case 3:
  127. break;
  128. }
  129. break;
  130. }
  131. }
  132. } catch (NullPointerException e) {
  133. }
  134. return random(200, 300);
  135. }
  136. });
  137. }
  138.  
  139. Worker cameraAnti = startWorker(new Looped() {
  140. public int loop() {
  141. int random = random(1, 50);
  142. if (camera != null)
  143. switch (random) {
  144. case 1:
  145. camera.setAngle((int) camera.getAngle() + random(-20, 20));
  146. break;
  147. case 2:
  148. camera.setAngle((int) camera.getAngle() + random(-50, 150));
  149. break;
  150. }
  151. return random(300, 400);
  152. }
  153.  
  154. });
  155.  
  156. public Action getAction() {
  157. chopping = getMyPlayer().getAnimation() != -1;
  158. if (!inventory.isFull() & !getMyPlayer().isMoving() & farFromTree(Object(treeIDs))) {
  159. return Action.WALKTOTREE;
  160. }
  161. if (!inventory.isFull() & !getMyPlayer().isMoving() & !getMyPlayer().isMoving() & farFromTrees(Object(treeIDs))) {
  162. return Action.WALKTOTREES;
  163. }
  164. if (inventory.isFull() & !isInZone(3095, 3087, 3240, 3247)) {
  165. return Action.WALKTOBANK;
  166. }
  167. if (inventory.isFull() & isInZone(3095, 3087, 3240, 3247)) {
  168. return Action.BANK;
  169. }
  170. if (!inventory.isFull() & !chopping & closeToTree(Object(treeIDs))) {
  171. return Action.CHOP;
  172. }
  173. if (!inventory.isFull() & (chopping || Object(treeID) == null)) {
  174. return Action.ANTIBAN;
  175. } else return Action.NOTHING;
  176. }
  177.  
  178. public void onRepaint(Graphics g) {
  179. long millis = System.currentTimeMillis() - startTime;
  180. final long hours = millis / (1000 * 60 * 60);
  181. millis -= hours * 1000 * 60 * 60;
  182. final long minutes = millis / (1000 * 60);
  183. millis -= minutes * 1000 * 60;
  184. final long seconds = millis / 1000;
  185. DecimalFormat df = new DecimalFormat();
  186. DecimalFormatSymbols dfs = new DecimalFormatSymbols();
  187. df.setDecimalFormatSymbols(dfs);
  188. DecimalFormat digit = new DecimalFormat("00");
  189. if (skills.getExperience(skills.SKILL_WOODCUTTING) > lastExp) {
  190. lastExp = skills.getExperience(skills.SKILL_WOODCUTTING);
  191. chopped++;
  192. }
  193. g.setColor(BG);
  194. int w = 150, x = upperLeftX() - w, y = upperLeftY();
  195. g.fill3DRect(x, y, 150, 52, true);
  196. g.setColor(new Color(0, 0, 0, 200));
  197. g.setFont(new Font("Default", Font.BOLD, 12));
  198. g.drawString("" + getName(), x + 5, y += 10);
  199. g.setFont(new Font("Default", Font.PLAIN, 12));
  200. g.drawString("Runtime: " + digit.format(hours) + ":" + digit.format(minutes) + ":" + digit.format(seconds), x + 5, y += 10);
  201. g.drawString("Willows Chopped: " + chopped, x + 5, y += 10);
  202. g.drawString("Levels Gained: " + (skills.getLevel(skills.SKILL_WOODCUTTING) - startLevel), x + 5, y += 10);
  203. g.drawString("Exp Gained: " + df.format(skills.getExperience(skills.SKILL_WOODCUTTING) - startExp), x + 5, y += 10);
  204. g.setColor(new Color(59, 52, 39, 125));
  205. g.fillRect(x + (w - 16), y += (height() - 167), 16, 100);
  206. g.setColor(new Color(0, 0, 0));
  207. g.drawRect(x + (w - 16), y, 16, 100);
  208. g.setColor(new Color(59, 52, 39, 50));
  209. g.drawRect(x + (w - 14), y, 14, 98);
  210. g.setColor(new Color(255, 18, 0, 125));
  211. g.fillRoundRect(x + (w - 12), y + 96 - (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 12, (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 4, 4);
  212. g.setColor(new Color(0, 0, 0));
  213. g.drawRoundRect(x + (w - 12), y + 96 - (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 12, (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 4, 4);
  214. g.setColor(new Color(59, 52, 39, 125));
  215. g.fillRect(x + (w - 30), y += 100, 30, 16);
  216. g.setColor(new Color(0, 0, 0));
  217. g.drawRect(x + (w - 30), y, 30, 16);
  218. g.setColor(new Color(59, 52, 39, 50));
  219. g.drawRect(x + (w - 30), y, 28, 14);
  220. g.setColor(Color.WHITE);
  221. g.drawString(getPercent(skills.SKILL_WOODCUTTING) + "%", x + (w - 24), y += 12);
  222. }
  223.  
  224. private static int[] xpTable = {0, 0, 83, 174, 276, 388, 512, 650, 801,
  225. 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973,
  226. 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031,
  227. 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408,
  228. 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127,
  229. 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
  230. 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599,
  231. 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445,
  232. 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200,
  233. 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594,
  234. 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253,
  235. 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431};
  236.  
  237. public int getPercent(final int index) {
  238. final int lvl = skills.getLevel(index);
  239. if (lvl == 99) {
  240. return 0;
  241. }
  242. final int xpTotal = xpTable[lvl + 1] - xpTable[lvl];
  243. if (xpTotal == 0) {
  244. return 0;
  245. }
  246. final int xpDone = skills.getExperience(index) - xpTable[lvl];
  247. return 100 * xpDone / xpTotal;
  248. }
  249.  
  250. public boolean objectOnScreen(PhysicalObject object) {
  251. if (object != null) {
  252. if (calculations.onScreen(calculations.tileToScreen(object.getLocation()))) {
  253. return true;
  254. }
  255. }
  256. return false;
  257. }
  258.  
  259. public PhysicalObject Object(int... ids) {
  260. PhysicalObject object = objects.getClosestObject(20, ids);
  261.  
  262. if (object != null) {
  263. return object;
  264. } else
  265. return null;
  266. }
  267.  
  268. public boolean isInZone(int x1, int x2, int y1, int y2) {
  269. int currentX = getMyPlayer().getLocation().getX();
  270. int currentY = getMyPlayer().getLocation().getY();
  271. if ((currentY >= y1) && (currentY <= y2) && (currentX <= x1) && (currentX >= x2)) {
  272. return true;
  273. }
  274. return false;
  275. }
  276.  
  277. public Tile[] reversePath(final Tile[] other) {
  278. final Tile[] t = new Tile[other.length];
  279. for (int i = 0; i < t.length; i++) {
  280. t[i] = other[other.length - i - 1];
  281. }
  282. return t;
  283. }
  284.  
  285. public Tile nextTile(final Tile path[], final int maxDist,
  286. final boolean enableMaxDist) {
  287. final int randomdis = random(3, 5);
  288. int closest = -1, sDist = -1;
  289. if (players.distanceTo(path[path.length - 1]) <= randomdis) {
  290. return null;
  291. }
  292. for (int i = path.length - 1; i >= 0; i--) {
  293. final int dist = players.distanceTo(path[i]);
  294. if (sDist == -1 || dist < sDist) {
  295. sDist = dist;
  296. closest = i;
  297. }
  298. if (enableMaxDist && dist <= maxDist) {
  299. return path[i];
  300. }
  301. }
  302. return path[closest];
  303. }
  304.  
  305. public boolean walkPathMM(final Tile[] path, final int maxDist) {
  306. try {
  307. final Tile next = nextTile(path, maxDist, true);
  308. return next != null && walkTileMM(next);
  309. } catch (final Exception e) {
  310. return false;
  311. }
  312. }
  313.  
  314. /* Close tab by ampzz*/
  315. public boolean closeTab(int id) {
  316. if (id < 0 || id > 15) return false;
  317. IComponent currTab = interfaces.getComponent(746, (124 + id));
  318. return (currTab != null && currTab.doClick());
  319. }
  320.  
  321. public boolean walkTileMM(final Tile t) {
  322. final Point p = calculations.tileToMinimap(t);
  323. if (p.x == -1 || p.y == -1) {
  324. return false;
  325. }
  326. mouse.moveMouse(p, true);
  327. return true;
  328. }
  329.  
  330. /* Closes the bank interface
  331. * @return whether the bank is open (or successfully clicks "Close")
  332. * @author Ampzz
  333. */
  334. public boolean close() {
  335. if (!bank.isOpen()) return true;
  336.  
  337. Interface bankIFace = interfaces.getInterface(Bank.BANK_INTERFACE_ID);
  338.  
  339. if (bankIFace != null && bankIFace.isValid()) {
  340. IComponent closeButton = interfaces.getComponent(Bank.BANK_INTERFACE_ID, Bank.BANK_BUTTON_CLOSE);
  341. try {
  342. mouse.moveMouse(new Point((int) closeButton.getUpperLeftScreenPos().getX() + random(0, (int) closeButton.getBounds().getWidth()), (int) closeButton.getUpperLeftScreenPos().getY() + random(0, (int) closeButton.getBounds().getHeight())));
  343. sleep(10, 20);
  344. if (menu.atMenu("Close"))
  345. return true;
  346. } catch (Exception e) {
  347. }
  348. }
  349.  
  350. return false;
  351. }
  352.  
  353. public int width() {
  354. IComponent inventoryComponent = interfaces.getComponent(746, 25);
  355. return (int) inventoryComponent.getBounds().getWidth();
  356. }
  357.  
  358. public int height() {
  359. IComponent inventoryComponent = interfaces.getComponent(746, 25);
  360. return (int) inventoryComponent.getBounds().getHeight();
  361. }
  362.  
  363. public int upperLeftX() {
  364. IComponent inventoryComponent = interfaces.getComponent(746, 25);
  365. return ((int) inventoryComponent.getUpperLeftScreenPos().getX() / 2);
  366. }
  367.  
  368. public int upperLeftY() {
  369. IComponent inventoryComponent = interfaces.getComponent(746, 25);
  370. return ((int) inventoryComponent.getUpperLeftScreenPos().getY() / 2);
  371. }
  372.  
  373. public boolean closeToTree(PhysicalObject object) {
  374. if (object != null) {
  375. if (players.distanceTo(object) <= 8) {
  376. return true;
  377. }
  378. }
  379.  
  380. return false;
  381. }
  382.  
  383. public boolean farFromTree(PhysicalObject object) {
  384. if (object != null) {
  385. if (players.distanceTo(object) > 8 & players.distanceTo(object) < 15) {
  386. return true;
  387. }
  388. }
  389. return false;
  390. }
  391.  
  392. public boolean farFromTrees(PhysicalObject object) {
  393. if (object != null) {
  394. if (players.distanceTo(object) >= 15) {
  395. return true;
  396. }
  397. }
  398. return false;
  399. }
  400. }
Add Comment
Please, Sign In to add comment