Guest User

Untitled

a guest
Jun 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.66 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.util.Map;
  4.  
  5. import com.speljohan.rsbot.bot.Bot;
  6. import com.speljohan.rsbot.event.events.ServerMessageEvent;
  7. import com.speljohan.rsbot.event.listeners.PaintListener;
  8. import com.speljohan.rsbot.event.listeners.ServerMessageListener;
  9. import com.speljohan.rsbot.script.Script;
  10. import com.speljohan.rsbot.script.wrappers.RSInterface;
  11. import com.speljohan.rsbot.script.wrappers.RSObject;
  12. import com.speljohan.rsbot.script.wrappers.RSTile;
  13.  
  14. public class YanilleironMiner extends Script implements ServerMessageListener,
  15. PaintListener {
  16.  
  17. private long startTime = System.currentTimeMillis();
  18. private RSTile[] path = { new RSTile(2611, 3092), new RSTile(2606, 3096),
  19. new RSTile(2614, 3104), new RSTile(2620, 3114),
  20. new RSTile(2624, 3127), new RSTile(2626, 3138) };
  21. private int mined = 0, loads = 0;
  22. private int[] rocks = { 2093, 2093, 2093 }, picks = { 1265, 1267, 1269,
  23. 1273, 1271, 1275 }, empty = { 452, 452, 452 };
  24. private RSTile bankTile = path[0], ironTile = path[path.length - 1],
  25. currentTile;
  26. private final int wait1 = 300, wait2 = 500, bankID = 2213;
  27. private String doing;
  28. private boolean isMining, power;
  29. private int currentRock = rocks[0];
  30.  
  31. public String getName() {
  32. return "Yanille Iron Miner";
  33. }
  34.  
  35. public String getAuthor() {
  36. return "Nokeo and Fusion89k (For his Barb Coal Miner)";
  37. }
  38.  
  39. public double getVersion() {
  40. return 1.2;
  41. }
  42.  
  43. public String getScriptCategory() {
  44. return "Mining";
  45. }
  46.  
  47. public String getScriptDescription() {
  48. return "<html>\n"
  49. + "<head></head>\n"
  50. + "<body bgcolor=\"black\" text=\"white\">\n"
  51. + "<center>"
  52. + "<h2>"
  53. + getName()
  54. + "</h2>"
  55. + "</center>\n"
  56. + "<b>Author:</b> "
  57. + getAuthor()
  58. + "<br />"
  59. + "<b>Version:</b> "
  60. + getVersion()
  61. + "<BR>Pickaxe may be equipped or in FIRST inventory slot"
  62. + "<BR><input type='checkbox' name='power' value='true'> Check to drop Iron Ore"
  63. + "</body>\n" + "</html>";
  64. }
  65.  
  66. public boolean onStart(Map<String, String> args) {
  67. power = args.get("power") != null;
  68. Bot.getEventManager().addListener(PaintListener.class, this);
  69. return true;
  70. }
  71.  
  72. public boolean dropAllExcept(int... items) { //Djbeng
  73. int inventoryCount = getInventoryCount();
  74. int[] inventoryArray = getInventoryArray();
  75. outer: for (int off = 0; off < inventoryArray.length; off++) {
  76. if (inventoryArray[off] == -1) continue;
  77. for (int item : items) {
  78. if (inventoryArray[off] == item) {
  79. continue outer;
  80. }
  81. }
  82.  
  83. for (int tries = 0; tries < 5; tries++) {
  84. atInventoryItem(inventoryArray[off], "Drop");
  85. wait(random(100, 300));
  86. if (getInventoryCount() < inventoryCount) {
  87. break;
  88. }
  89. }
  90. if (getInventoryCount() >= inventoryCount) {
  91. // equally, otherwise
  92. // something really weird
  93. // happend :P
  94. return false;
  95. }
  96. inventoryArray = getInventoryArray();
  97. inventoryCount = getInventoryCount();
  98. }
  99. return true;
  100. }
  101.  
  102. public void onFinish() {
  103. Bot.getEventManager().removeListener(PaintListener.class, this);
  104. }
  105.  
  106. public int loop() {
  107. setCompass('w');
  108. setCameraAltitude(true);
  109. if (!isCarryingItemCustom(picks) && isLoggedIn()) {
  110. log("No PickAxe");
  111. stopAllScripts();
  112. }
  113. if (isMoving())
  114. return random(wait1, wait2);
  115. if (isMining && getMyPlayer().getAnimation() == -1)
  116. isMining = false;
  117. if (!isInventoryFull()) {
  118. if (isMining) {// Smoking rocks got some help from: Tenac
  119. try {
  120. int curID = getObjectAt(currentTile).getID();
  121. if (curID != currentRock) {
  122. isMining = false;
  123. mine();
  124. }
  125. } catch (Exception e) {
  126. log("Smoking detection error");
  127. }
  128. return random(wait1, wait2);
  129. }
  130. if (distanceTo(ironTile) > 4) {
  131. doing = "Walking to Iron";
  132. return walk(false);
  133. }
  134. doing = "Finding Iron";
  135. RSObject rock = findObject(rocks);
  136. if (rock == null) {
  137. doing = "Waiting for Iron";
  138. randomStuff();
  139. return random(wait1, wait2);
  140. }
  141. mine();
  142. } else {
  143. if (power) {
  144. dropAllExcept(picks);
  145. } else {
  146. if (distanceTo(bankTile) > 4) {
  147. doing = "Walking to Bank";
  148. return walk(true);
  149. }
  150. if (!RSInterface.getInterface(INTERFACE_BANK).isValid()) {
  151. doing = "Finding Bank";
  152. RSObject booth = findObject(bankID);
  153. if (booth == null)
  154. return random(wait1, wait2);
  155. if (!tileOnScreen(booth.getLocation())) {
  156. turnToObject(booth, random(-5, 5));
  157. RSTile boothtile = new RSTile(booth.getLocation()
  158. .getX(), booth.getLocation().getY()
  159. + random(1, 3));
  160. walkTileMM(boothtile);
  161. return random(wait1, wait2);
  162. }
  163. if (!getMyPlayer().isMoving()
  164. && getMyPlayer().getAnimation() == -1) {
  165. atObject(booth, "Use-Quickly");
  166. }
  167. return random(wait1, wait2);
  168. }
  169. if (RSInterface.getInterface(INTERFACE_BANK).isValid()) {
  170. doing = "Depositing";
  171. bank.depositAllExcept(picks);
  172. loads++;
  173. bank.close();
  174. }
  175. }
  176. }
  177. if (getEnergy() > random(50, 100))
  178. setRun(true);
  179. return random(wait1, wait2);
  180. }
  181.  
  182. private void mine() {
  183. RSObject rock = findObject(rocks);
  184. if (rock == null && !findAllEmpty()) {
  185. atTile(randomTile(getMyPlayer().getLocation()), "walk");
  186. isMining = false;
  187. return;
  188. }
  189. doing = "Mining Iron";
  190. atObject(rock, "Mine");
  191. isMining = true;
  192. currentTile = rock.getLocation();
  193. currentRock = rock.getID();
  194. openTab(TAB_INVENTORY);
  195. }
  196.  
  197. private boolean findAllEmpty() {
  198. for (int id : empty) {
  199. if (findObject(id) == null)
  200. return false;
  201. }
  202. return true;
  203. }
  204.  
  205. private int walk(boolean toBank) {
  206. RSTile start = locate();
  207. int loc = 0;
  208. for (int i = 0; i < path.length; i++) {
  209. if (start.equals(path[i])) {
  210. loc = i;
  211. break;
  212. }
  213. }
  214. if (toBank) {
  215. if (loc == 0)
  216. return random(wait1, wait2);
  217. walkTileMM(randomTile(path[loc - 1]));
  218. } else {
  219. if (loc == path.length - 1)
  220. walkTileMM(ironTile);
  221. else
  222. walkTileMM(randomTile(path[loc + 1]));
  223. }
  224. return random(wait1, wait2);
  225. }
  226.  
  227. private RSTile randomTile(RSTile tile) {
  228. return new RSTile(random(tile.getX() - 2, tile.getX() + 2), random(tile
  229. .getY() - 2, tile.getY() + 2));
  230. }
  231.  
  232. private RSTile locate() {
  233. RSTile min = path[0];
  234. for (int i = 1; i < path.length; i++) {
  235. if (distanceTo(path[i]) < distanceTo(min))
  236. min = path[i];
  237. }
  238. return min;
  239. }
  240.  
  241. private boolean isCarryingItemCustom(int... items) {
  242. for (int i : items) {
  243. if (getInventoryCount(i) > 0)
  244. return true;
  245. }
  246. for (int item : items) {
  247. if (getEquipmentInterface().getInventoryItemCount(item) > 0)
  248. return true;
  249. }
  250. return false;
  251. }
  252.  
  253. private void randomStuff() {
  254. int temp = random(1, 50);
  255. switch (temp) {
  256. case 3:
  257. case 4:
  258. moveMouse(random(150, 450), random(100, 300));
  259. break;
  260. case 2:
  261. openTab(TAB_STATS);
  262. RSTile mining = randomTile(new RSTile(680, 230));
  263. moveMouse(mining.getX(), mining.getY());
  264. break;
  265. case 6:
  266. openTab(random(0, 13));
  267. break;
  268. }
  269. }
  270.  
  271. private boolean isMoving() {
  272. if (!getMyPlayer().isMoving())
  273. return false;
  274. if (!locate().equals(path[0]) || !locate().equals(path[1])
  275. || !locate().equals(path[path.length - 1])
  276. || !locate().equals(path[path.length - 2])) {
  277. if (distanceTo(getDestination()) < 5)
  278. return false;
  279. }
  280. return true;
  281. }
  282.  
  283. public void serverMessageRecieved(ServerMessageEvent e) {
  284. String word = e.getMessage().toLowerCase();
  285. if (word.contains("iron")) {
  286. mined++;
  287. isMining = false;
  288. }
  289. }
  290.  
  291. public void onRepaint(Graphics g) {
  292. if (isLoggedIn()) {
  293. long millis = System.currentTimeMillis() - startTime;
  294. long hours = millis / (1000 * 60 * 60);
  295. millis -= hours * (1000 * 60 * 60);
  296. long minutes = millis / (1000 * 60);
  297. millis -= minutes * (1000 * 60);
  298. long seconds = millis / 1000;
  299. int topX = 515 - 173, topY = 337 - 80, x = topX + 5, y = topY + 5;
  300. g.setColor(new Color(0, 50, 100, 100));
  301. g.fill3DRect(topX, topY, 515 - topX, 337 - topY, true);
  302. g.setColor(Color.white);
  303. g.drawString("Runtime: " + hours + "h " + minutes + "min "
  304. + seconds + "sec.", x, y += 15);
  305. g.drawString("Iron Mined: " + Integer.toString(mined), x, y += 15);
  306. g.drawString("Loads Done: " + loads, x, y += 15);
  307. g.drawString("Status: " + doing, x, y += 15);
  308. }
  309. }
  310. }
Add Comment
Please, Sign In to add comment