Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.40 KB | None | 0 0
  1. import com.rsbuddy.event.events.MessageEvent;
  2. import com.rsbuddy.event.listeners.MessageListener;
  3. import com.rsbuddy.event.listeners.PaintListener;
  4. import com.rsbuddy.script.ActiveScript;
  5. import com.rsbuddy.script.Manifest;
  6. import com.rsbuddy.script.methods.*;
  7. import com.rsbuddy.script.util.Filter;
  8. import com.rsbuddy.script.util.Random;
  9. import com.rsbuddy.script.util.Timer;
  10. import com.rsbuddy.script.wrappers.*;
  11.  
  12. import java.awt.*;
  13. import java.util.Comparator;
  14.  
  15. @Manifest(name = "VarrockMiningChampion", version = 0.01, authors = "iCyrus")
  16. public class VarrockMiningChampion extends ActiveScript implements PaintListener, MessageListener {
  17.  
  18. boolean developerMode = true;
  19. int failed = 0;
  20. boolean pickaxeEqupped = true;
  21. boolean multipleRocks = false;
  22. int oresMined = 0;
  23. int gemsMined = 0;
  24.  
  25. private static final int[] miningAnimations = {
  26. -1, -1, 627, 629, 628, -1, -1};
  27.  
  28. private static final int[] pickAxes = {
  29. -1, -1, 1269, 1273, 1271, 1275, -1};
  30.  
  31. private static final int[] banker = {5912, 5913};
  32.  
  33. private static final int[] copperRock = {11960, 11961, 11962};
  34. private static final int[] tinRock = {11957, 11958, 11959};
  35. //Mined copper rocks IDs: 11555, 11556, 11557
  36.  
  37. private int[] rocksToMine;
  38.  
  39. private Tile bankingTile = new Tile(3253, 3420);
  40.  
  41. Tile[] eastBankToMine = {new Tile(3254, 3421), new Tile(3254, 3422),
  42. new Tile(3254, 3423), new Tile(3254, 3424), new Tile(3254, 3425),
  43. new Tile(3254, 3426), new Tile(3255, 3426), new Tile(3256, 3427),
  44. new Tile(3257, 3428), new Tile(3258, 3428), new Tile(3259, 3428),
  45. new Tile(3260, 3428), new Tile(3261, 3428), new Tile(3262, 3428),
  46. new Tile(3263, 3428), new Tile(3264, 3428), new Tile(3265, 3428),
  47. new Tile(3266, 3428), new Tile(3267, 3428), new Tile(3268, 3428),
  48. new Tile(3269, 3428), new Tile(3270, 3428), new Tile(3271, 3428),
  49. new Tile(3272, 3428), new Tile(3273, 3428), new Tile(3274, 3428),
  50. new Tile(3275, 3428), new Tile(3276, 3428), new Tile(3277, 3428),
  51. new Tile(3278, 3428), new Tile(3278, 3427), new Tile(3278, 3426),
  52. new Tile(3279, 3425), new Tile(3280, 3424), new Tile(3280, 3423),
  53. new Tile(3281, 3423), new Tile(3282, 3423), new Tile(3283, 3423),
  54. new Tile(3284, 3423), new Tile(3285, 3422), new Tile(3285, 3421),
  55. new Tile(3285, 3420), new Tile(3285, 3419), new Tile(3285, 3418),
  56. new Tile(3285, 3417), new Tile(3285, 3416), new Tile(3286, 3415),
  57. new Tile(3287, 3414), new Tile(3288, 3413), new Tile(3289, 3412),
  58. new Tile(3289, 3411), new Tile(3289, 3410), new Tile(3289, 3409),
  59. new Tile(3289, 3408), new Tile(3289, 3407), new Tile(3289, 3406),
  60. new Tile(3289, 3405), new Tile(3289, 3404), new Tile(3290, 3403),
  61. new Tile(3290, 3402), new Tile(3290, 3401), new Tile(3290, 3400),
  62. new Tile(3290, 3399), new Tile(3290, 3398), new Tile(3290, 3397),
  63. new Tile(3290, 3396), new Tile(3290, 3395), new Tile(3290, 3394),
  64. new Tile(3290, 3393), new Tile(3290, 3392), new Tile(3290, 3391),
  65. new Tile(3290, 3390), new Tile(3290, 3389), new Tile(3290, 3388),
  66. new Tile(3291, 3387), new Tile(3292, 3386), new Tile(3292, 3385),
  67. new Tile(3292, 3384), new Tile(3292, 3383), new Tile(3292, 3382),
  68. new Tile(3293, 3381), new Tile(3293, 3380), new Tile(3293, 3379),
  69. new Tile(3293, 3378), new Tile(3293, 3377), new Tile(3292, 3376),
  70. new Tile(3291, 3375), new Tile(3290, 3374), new Tile(3289, 3373),
  71. new Tile(3288, 3372), new Tile(3287, 3371), new Tile(3287, 3370),
  72. new Tile(3287, 3369), new Tile(3287, 3368), new Tile(3286, 3367),
  73. new Tile(3285, 3366)};
  74.  
  75. private Tile[] pathFromBankToMine;
  76.  
  77. private Area eastMiningArea = new Area(3277, 3358, 3292, 3372);
  78. private Area eastBankingArea = new Area(3250, 3419, 3257, 3423);
  79.  
  80. private Area bankingArea;
  81. private Area miningArea;
  82.  
  83.  
  84. private int random(int min, int max) {
  85. return Random.nextInt(min, max);
  86. }
  87.  
  88. private void dLog(String log) {
  89. if (developerMode) {
  90. log(log);
  91. }
  92. }
  93.  
  94. private void setRocksToMine(int[] ids) {
  95. int i = 0;
  96. for (; i <= ids.length; i++) {
  97. rocksToMine[i] = ids[i];
  98. }
  99. }
  100.  
  101. private void setRocksToMine(int[] ids, int[] secondIDs) {
  102. int i = 0;
  103. for (; i <= ids.length; i++) {
  104. rocksToMine[i] = ids[i];
  105. }
  106. for (; i < secondIDs.length + ids.length; i++) {
  107. rocksToMine[i] = secondIDs[i];
  108. }
  109. }
  110.  
  111. private GameObject getRockToMine(int... ids) {
  112. return Objects.getNearest(ids);
  113. }
  114.  
  115. //private Filter
  116.  
  117. private boolean isMining() {
  118. if (currentRockToMine != null) {
  119. TileObject rock = new TileObject(currentRockToMine);
  120. if (rock != null) {
  121. if (rock.isValid() && playerIsSwinging(rock)) {
  122. sleep(30);
  123. }
  124. }
  125. }
  126. return false;
  127. }
  128.  
  129. private boolean playerIsSwinging(TileObject rock) {
  130. Timer t = new Timer(random(600, 800));
  131. while (t.isRunning()) {
  132. if ((Players.getLocal().getAnimation() == 627 ||
  133. Players.getLocal().getAnimation() == 629 ||
  134. Players.getLocal().getAnimation() == 628) &&
  135. rock.isValid()) {
  136. return true;
  137. }
  138. }
  139.  
  140. return false;
  141.  
  142. }
  143.  
  144. @Override
  145. public boolean onStart() {
  146. rocksToMine = tinRock;
  147. pathFromBankToMine = eastBankToMine.clone();
  148. bankingArea = eastBankingArea;
  149. miningArea = eastMiningArea;
  150. return super.onStart();
  151. }
  152.  
  153. public boolean inventoryContainsExtra() {
  154. dLog("Inventory contains extra: " + String.valueOf(Inventory.getCountExcept(pickAxes)));
  155. return (Inventory.getCountExcept(pickAxes) > 1);
  156. }
  157.  
  158. private boolean isValid(int value, int array[]) {
  159. for (int i = 0; i < array.length; i++) {
  160. if (array[i] == value)
  161. return true;
  162. }
  163. return false;
  164. }
  165.  
  166. private GameObject getSecondNearest(int[] id) {
  167. final GameObject nearest = Objects.getNearest(rocksToMine);
  168. GameObject secondNearest = Objects.getNearest(new Filter<GameObject>() {
  169. public boolean accept(GameObject Object) {
  170. return isValid(Object.getId(), rocksToMine) && !nearest.equals(Object);
  171. }
  172. });
  173. return secondNearest;
  174. }
  175.  
  176. private boolean hover(final Model model, boolean continueToHover) {
  177. if (currentRockToMine == null)
  178. loop();
  179. for (Polygon p : model.getTriangles()) {
  180. if (currentRockToMine == null) {
  181. dLog("currentRockToMine is null");
  182. loop();
  183. }
  184. if (p.contains(Mouse.getLocation()) && new TileObject(currentRockToMine).isValid()) {
  185. dLog("In first if statement");
  186. if (currentRockToMine == null) {
  187. return false;
  188. } else if (continueToHover && new TileObject(currentRockToMine).isValid()) {
  189. dLog("In if statement");
  190. Mouse.move(model.getNextPoint());
  191. }
  192. return true;
  193. }
  194. }
  195. if (new TileObject(currentRockToMine).isValid()) {
  196. Mouse.move(model.getNextPoint());
  197. }
  198. return false;
  199. }
  200.  
  201. private GameObject currentRockToMine;
  202.  
  203. private enum ScriptState {
  204. STARTUP, OPENING_BANK, DEPOSITING, WALKING_TO_MINE,
  205. WALKING_TO_BANK, CLICKING_ROCK, HOVERING_NEXT, UNKNOWN
  206. }
  207.  
  208. private ScriptState getScriptState() {
  209. if (Bank.isOpen() && inventoryContainsExtra()) {
  210. return ScriptState.DEPOSITING;
  211. }
  212. if (Inventory.isFull()) {
  213. dLog("Inventory is full");
  214. if (!bankingArea.contains(Players.getLocal().getLocation())) {
  215. return ScriptState.WALKING_TO_BANK;
  216. }
  217. if (bankingArea.contains(Players.getLocal().getLocation()) &&
  218. Bank.isOpen()) {
  219. return ScriptState.DEPOSITING;
  220. }
  221. if (bankingArea.contains(Players.getLocal().getLocation()) &&
  222. !Bank.isOpen()) {
  223. return ScriptState.OPENING_BANK;
  224. }
  225. } else if (!Inventory.isFull()) {
  226. dLog("Inventory is not full");
  227. TileObject rock = new TileObject(currentRockToMine);
  228. if (rock.isValid()) {
  229. boolean isMining = playerIsSwinging(rock);
  230.  
  231. if (!miningArea.contains(Players.getLocal().getLocation())) {
  232. return ScriptState.WALKING_TO_MINE;
  233. } else if (isMining && Objects.getNearest(rocksToMine) != null &&
  234. new TileObject(currentRockToMine).isValid()) {
  235. return ScriptState.HOVERING_NEXT;
  236. } else if (miningArea.contains(Players.getLocal().getLocation())) {
  237. if (isMining && new TileObject(currentRockToMine).isValid()) {
  238. return ScriptState.HOVERING_NEXT;
  239. } else {
  240. return ScriptState.CLICKING_ROCK;
  241. }
  242. }
  243. }
  244. }
  245. return ScriptState.UNKNOWN;
  246. }
  247.  
  248. public int loop() {
  249. dLog("loop() started");
  250. switch (getScriptState()) {
  251. case OPENING_BANK:
  252. dLog("In OPENING_BANK");
  253. if (random(1, 2) == 1) {
  254. GameObject bankbooth = Objects.getNearest(11402);
  255. if (bankbooth != null && bankbooth.isOnScreen()) {
  256. bankbooth.interact("Use-quickly");
  257. }
  258. } else {
  259. Npc bankerToUse = Npcs.getNearest(banker);
  260. if (bankerToUse != null && bankerToUse.isOnScreen()) {
  261. bankerToUse.interact("Bank");
  262. }
  263. }
  264. sleep(random(800, 1000));
  265. while (Players.getLocal().isMoving()) {
  266. sleep(30);
  267. }
  268. return 0;
  269. case DEPOSITING:
  270. dLog("In DEPOSITING");
  271. Bank.depositAllExcept(pickAxes);
  272. sleep(random(500, 750));
  273. return 0;
  274. case CLICKING_ROCK:
  275. dLog("In CLICKING_ROCK");
  276. if (!isMining()) {
  277. GameObject rock = Objects.getNearest(rocksToMine);
  278. if (rock != null && rock.isOnScreen()) {
  279. currentRockToMine = rock;
  280. rock.interact("Mine");
  281. sleep(random(550, 750));
  282. } else if (rock != null && !rock.isOnScreen()) {
  283. Walking.findPath(rock.getLocation()).traverse();
  284. }
  285. while (Players.getLocal().isMoving()) {
  286. sleep(30);
  287. }
  288. } else
  289. return 0;
  290. case HOVERING_NEXT:
  291. dLog("In HOVERING_NEXT");
  292. GameObject newRock = getSecondNearest(rocksToMine);
  293. if (newRock != null) {
  294. dLog("newRock is not null");
  295. dLog(String.valueOf(newRock.getLocation()));
  296. dLog("Going into hover");
  297. hover(newRock.getModel(), false);
  298. dLog("Out of hover");
  299. }
  300. return 0;
  301. case WALKING_TO_BANK:
  302. dLog("In WALKING_TO_BANK");
  303. Walking.newTilePath(pathFromBankToMine).reverse().traverse();
  304. sleep(random(1000, 1500));
  305. return 0;
  306. case WALKING_TO_MINE:
  307. dLog("In WALKING_TO_MINE");
  308. Walking.newTilePath(pathFromBankToMine).traverse();
  309. return 0;
  310. default:
  311. dLog("In DEFAULT(" + String.valueOf(failed) + ") times");
  312. failed++;
  313. if (failed >= 5) {
  314. log("Failed 5 times, stopping script");
  315. stop();
  316. }
  317. }
  318. return 0;
  319. }
  320.  
  321. private static class TileObject {
  322.  
  323. final GameObject obj;
  324. final Tile tile;
  325.  
  326. public TileObject(GameObject obj) {
  327. this.obj = obj;
  328. tile = obj.getLocation();
  329. }
  330.  
  331. boolean isValid() {
  332. for (GameObject obj : Objects.getAllAt(tile)) {
  333. if (obj.equals(this.obj))
  334. return true;
  335. }
  336. return false;
  337. }
  338.  
  339. }
  340.  
  341. public void messageReceived(MessageEvent messageEvent) {
  342. String s = messageEvent.getMessage();
  343.  
  344. if (s.contains("You just found a")) {
  345. gemsMined++;
  346. }
  347. if (s.contains("You manage to mine")) {
  348. oresMined++;
  349. }
  350.  
  351. }
  352.  
  353. public void onRepaint(Graphics graphics) {
  354.  
  355. }
  356.  
  357. @Override
  358. public void onFinish() {
  359. super.onFinish();
  360. }
  361.  
  362. }
Add Comment
Please, Sign In to add comment