Guest User

Untitled

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