gamemaste789

help

May 1st, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.54 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Image;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6. import java.io.IOException;
  7. import java.net.URL;
  8.  
  9. import javax.imageio.ImageIO;
  10.  
  11. import org.powerbot.concurrent.Task;
  12. import org.powerbot.concurrent.strategy.Condition;
  13. import org.powerbot.concurrent.strategy.Strategy;
  14. import org.powerbot.game.api.ActiveScript;
  15. import org.powerbot.game.api.Manifest;
  16. import org.powerbot.game.api.methods.Tabs;
  17. import org.powerbot.game.api.methods.Walking;
  18. import org.powerbot.game.api.methods.Widgets;
  19. import org.powerbot.game.api.methods.input.Keyboard;
  20. import org.powerbot.game.api.methods.input.Mouse;
  21. import org.powerbot.game.api.methods.interactive.Players;
  22. import org.powerbot.game.api.methods.node.SceneEntities;
  23. import org.powerbot.game.api.methods.tab.Inventory;
  24. import org.powerbot.game.api.methods.tab.Skills;
  25. import org.powerbot.game.api.methods.widget.Camera;
  26. import org.powerbot.game.api.util.Filter;
  27. import org.powerbot.game.api.util.Random;
  28. import org.powerbot.game.api.util.Time;
  29. import org.powerbot.game.api.wrappers.Area;
  30. import org.powerbot.game.api.wrappers.Tile;
  31. import org.powerbot.game.api.wrappers.node.SceneObject;
  32. import org.powerbot.game.bot.event.MessageEvent;
  33. import org.powerbot.game.bot.event.listener.MessageListener;
  34. import org.powerbot.game.bot.event.listener.PaintListener;
  35.  
  36. @Manifest(name = "Mining Guild Miner", description = "Mines coal in the mining guild. And banks!", version = 2.2, authors = {"Tobdan"})
  37. public class MiningGuildMiner extends ActiveScript implements PaintListener, MessageListener, MouseListener{
  38. final static int Coal_IDS[] = {5770, 5771, 5772, 5786, 5785, 5784};
  39. final static int Mith_IDS[] = {5786, 5785, 5784};
  40. final static int Item_IDS[] = {453, 1617, 1619, 1621, 1623};
  41. final static int Bank_ID = 11758;
  42. int Picks[] = {1271, 1265, 15259, 1267, 1273, 1275, 1269};
  43. final static int Ladder_Up_ID = 6226;
  44. final static int Ladder_Down_ID = 2113;
  45. final static Area MINING_AREA = new Area(new Tile(3017,9756,0), new Tile(3055,9732,0));
  46. final static Area BANK_AREA = new Area(new Tile(3009,3355,0), new Tile(3018,3358,0));
  47. final static Tile[] Exit_MG = {new Tile(3045, 9745, 0), new Tile(3033,9738,0), new Tile(3024,9738,0)};
  48. final static Tile[] StairsToBank = {new Tile(3030,3345,0), new Tile(3025,3359,0), new Tile(3012,3356,0)};
  49. final static Tile[] BankToStairs = {new Tile(3025,3359,0), new Tile(3030,3345,0), new Tile(3019,3337,0)};
  50. SceneObject oldRock;
  51. static Image img1 = null;
  52. static boolean hidePaint = false;
  53. long startTime;
  54. static int startExp, startLvl, oresMined;
  55. final static int coalPrice = 250;
  56. static String status = "";
  57.  
  58. @Override
  59. protected void setup() {
  60. final Walk walk = new Walk();
  61. final MineCoal mineCoal = new MineCoal();
  62. final Bank bank = new Bank();
  63. final AntiBan antiBan = new AntiBan();
  64. final ImageLoader iL = new ImageLoader();
  65. final WidgetCloser wCloser = new WidgetCloser();
  66.  
  67. final Strategy walkStrategy = new Strategy(walk,walk);
  68. final Strategy mineCoalStrategy = new Strategy(mineCoal, mineCoal);
  69. final Strategy bankStrategy = new Strategy(bank, bank);
  70. final Strategy antiBanStrategy = new Strategy(antiBan, antiBan);
  71. final Strategy iLStrategy = new Strategy(iL,iL);
  72. final Strategy wCloserStrategy = new Strategy(wCloser,wCloser);
  73.  
  74. provide(walkStrategy);
  75. provide(mineCoalStrategy);
  76. provide(bankStrategy);
  77. provide(antiBanStrategy);
  78. provide(iLStrategy);
  79. provide(wCloserStrategy);
  80.  
  81. startTime = System.currentTimeMillis();
  82. startExp = Skills.getExperiences()[Skills.MINING];
  83. startLvl = Skills.getLevels()[Skills.MINING];
  84. }
  85.  
  86. private final class Walk implements Task, Condition {
  87. private boolean toBank = false;
  88. public boolean validate() {
  89. return Inventory.getCount() == 28 && !BANK_AREA.contains(Players.getLocal().getLocation()) || Inventory.getCount() != 28 && !MINING_AREA.contains(Players.getLocal().getLocation());
  90. }
  91.  
  92. @Override
  93. public void run() {
  94. if(Widgets.get(762, 1).validate())
  95. {
  96. Widgets.get(762, 45).click(true);
  97. Time.sleep(Random.nextInt(875, 1450));
  98. }
  99. if(Inventory.getCount() == 28) {
  100. toBank = true;
  101. } else {
  102. toBank = false;
  103. }
  104.  
  105. if(toBank){
  106. if(MINING_AREA.contains(Players.getLocal().getLocation())){
  107. if(SceneEntities.getNearest(Ladder_Up_ID).isOnScreen()){
  108. status = "Going Up Ladder";
  109. SceneEntities.getNearest(Ladder_Up_ID).click(true);
  110. } else {
  111. status = "Walking Towards Ladder Up";
  112. Walking.newTilePath(Exit_MG).traverse();
  113. }
  114. } else {
  115. status = "Walking Towards Bank";
  116. Walking.newTilePath(StairsToBank).traverse();
  117. }
  118. } else {
  119. if(!MINING_AREA.contains(Players.getLocal().getLocation())){
  120. if(!SceneEntities.getNearest(Ladder_Down_ID).isOnScreen())
  121. {
  122. status = "Walking Towards Ladder Down";
  123. Walking.newTilePath(BankToStairs).traverse();
  124. } else {
  125. status = "Going Down Ladder";
  126. SceneEntities.getNearest(Ladder_Down_ID).click(true);
  127. }
  128. }
  129. }
  130. Time.sleep(Random.nextInt(1450, 1925));
  131. }
  132. }
  133. private final class MineCoal implements Task, Condition {
  134. public boolean validate() {
  135. return Inventory.getCount() != 28 && MINING_AREA.contains(Players.getLocal().getLocation()) && !Players.getLocal().isMoving();
  136. }
  137.  
  138. @Override
  139. public void run() {
  140. if(Tabs.getCurrent() != Tabs.INVENTORY) Tabs.INVENTORY.open();
  141. if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled()) Walking.setRun(true);
  142.  
  143. SceneObject ore = SceneEntities.getNearest(new Filter<SceneObject>(){
  144. public boolean accept(final SceneObject loc) {
  145. for(int id : Coal_IDS) {
  146. if(loc.getId() == id && MINING_AREA.contains(loc.getLocation())){
  147. return true;
  148. }
  149. }
  150. return false;
  151. }
  152. });
  153.  
  154. if(ore != null)
  155. {
  156. if(oldRock == null || !ore.getLocation().equals(oldRock.getLocation()) || Players.getLocal().getAnimation() == -1)
  157. {
  158. if(ore.isOnScreen())
  159. {
  160. status = "Mining Ore";
  161. if(ore.click(true))
  162. {
  163. Camera.turnTo(ore);
  164. oldRock = ore;
  165. Time.sleep(Random.nextInt(250, 850));
  166. }
  167. }else{
  168. status = "Walking Towards Ore";
  169. Walking.walk(ore.getLocation());
  170. Camera.turnTo(ore);
  171. }
  172. }
  173. }
  174. }
  175. }
  176. private final class Bank implements Task, Condition {
  177. public boolean validate() {
  178. return Inventory.getCount() == 28 && BANK_AREA.contains(Players.getLocal().getLocation());
  179. }
  180.  
  181. @Override
  182. public run depositAllExcept(Picks);
  183.  
  184. private final class AntiBan implements Task, Condition {
  185. public boolean validate() {
  186. return Players.getLocal().getAnimation() != -1;
  187. }
  188.  
  189. @Override
  190. public void run() {
  191. int rnd = Random.nextInt(1, 100);
  192. switch(rnd)
  193. {
  194. case 1:
  195. status = "Antiban - Camera Angle";
  196. Camera.setAngle(Random.nextInt(1, 100));
  197. break;
  198. case 2:
  199. status = "Antiban - Camera Pitch";
  200. Camera.setPitch(Camera.getPitch() + Random.nextInt(-50, 50));
  201. break;
  202. case 3:
  203. status = "Antiban - Enable Run";
  204. if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled())
  205. Walking.setRun(true);
  206. break;
  207. case 5:
  208. status = "Antiban - Check Friends";
  209. if (Tabs.getCurrent() != Tabs.FRIENDS) Tabs.FRIENDS.open();
  210. break;
  211. case 10:
  212. status = "Antiban - Check Stats";
  213. if (Tabs.getCurrent() != Tabs.STATS) Tabs.STATS.open();
  214. break;
  215. case 15:
  216. status = "Antiban - Move Mouse";
  217. Mouse.move(Random.nextInt(0, 250), Random.nextInt(0, 200));
  218. break;
  219. }
  220. Time.sleep(Random.nextInt(800, 1250));
  221. }
  222. }
  223. private final class ImageLoader implements Task, Condition {
  224.  
  225. @Override
  226. public boolean validate() {
  227. if(img1 == null){
  228. return true;
  229. }
  230. return false;
  231. }
  232. @Override
  233. public void run() {
  234. status = "Loading Paint";
  235. img1 = getImage("http://i47.tinypic.com/2cohm5z.png");
  236. }
  237. }
  238.  
  239. private final class WidgetCloser implements Task, Condition {
  240. public boolean validate() {
  241. return Widgets.get(1218, 1).validate();
  242. }
  243.  
  244. @Override
  245. public void run() {
  246. status = "Closing Widget";
  247. Widgets.get(1218, 76).click(true);
  248. Time.sleep(Random.nextInt(875, 1450));
  249. }
  250. }
  251.  
  252. //START: Code generated using Enfilade's Easel
  253. private Image getImage(String url) {
  254. try {
  255. return ImageIO.read(new URL(url));
  256. } catch(IOException e) {
  257. return null;
  258. }
  259. }
  260.  
  261. public void onRepaint(Graphics g1) {
  262. Graphics2D g = (Graphics2D)g1;
  263. if(hidePaint)
  264. {
  265. g.drawString("Show Paint", 320, 358);
  266. } else {
  267. int levelsGained = Skills.getLevels()[14] - startLvl;
  268. int expGained = Skills.getExperiences()[14] - startExp;
  269. long elapsedTime = System.currentTimeMillis() - startTime;
  270. int expPerHour = (int) ((3600000.0 / elapsedTime) * expGained);
  271. int moneyGained = coalPrice * oresMined;
  272. int moneyPerHour = (int) ((3600000.0 / elapsedTime) * moneyGained);
  273.  
  274. g.drawImage(img1, 5, 343, null);
  275. g.drawString(Integer.toString(expGained) + " (" + Integer.toString(expPerHour) + "/Hr)", 110, 385);
  276. g.drawString(Integer.toString(Skills.getLevels()[Skills.MINING]) + " (" + Integer.toString(levelsGained) + ")", 120, 419);
  277. g.drawString(status, 75, 452);
  278. g.drawString(Integer.toString(moneyGained) + " (" + Integer.toString(moneyPerHour) + "/Hr)", 333, 385);
  279. g.drawString(Integer.toString(oresMined), 316, 419);
  280. g.drawString(formatTime(elapsedTime), 320, 452);
  281. g.drawString("Hide Paint", 320, 358);
  282. }
  283. }
  284. //END: Code generated using Enfilade's Easel
  285.  
  286. private String formatTime(long time) {
  287. final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
  288. return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
  289. + (s < 10 ? "0" + s : s);
  290. }
  291.  
  292. public void messageReceived(MessageEvent msg) {
  293. String i = msg.getMessage().toLowerCase();
  294. if (i.contains("you manage to mine some")) {
  295. oresMined++;
  296. }
  297. if(i.contains("Mining Level") || i.contains("Mining Lvl")) {
  298. Keyboard.sendText("I'm level " + Skills.getLevels()[Skills.MINING] + " :D", true);
  299. }
  300. }
  301.  
  302. public void mouseClicked(MouseEvent mouse) {
  303. int x = mouse.getX();
  304. int y = mouse.getY();
  305. if (x >= 320 && x <= 390 && y >= 345 && y <= 358) {
  306. hidePaint = !hidePaint;
  307. }
  308. }
  309. public void mouseEntered(MouseEvent arg0) {
  310. }
  311. public void mouseExited(MouseEvent arg0) {
  312. }
  313. public void mousePressed(MouseEvent arg0) {
  314. }
  315. public void mouseReleased(MouseEvent arg0) {
  316. }
  317.  
  318. private void depositAllExcept(Picks) {
  319. ArrayList<Integer> ids = new ArrayList<Integer>();
  320. int ninvCount = -1;
  321. int invCount = Inventory.getCount();
  322. for (int id : item) {
  323. ids.add(id);
  324. }
  325. for (int i = 0; i < 28; i++) {
  326. WidgetChild slot = Widgets.get(679, 0).getChild(i);
  327. int slotId = slot.getChildId();
  328. if (slot.validate() && Inventory.getCount(slotId) > 0) {
  329. if (!ids.contains(slotId)) {
  330. for (int tries = 0; tries < 5; tries++) {
  331. if (Inventory.getCount(slotId) > 1) {
  332. if (slot.interact("Deposit-All"));
  333. else
  334. tries = 5;
  335. } else {
  336. if (slot.interact("Deposit"));
  337. else
  338. tries = 5;
  339. }
  340. Time.sleep(625, 902);
  341. ninvCount = Inventory.getCount();
  342. if (invCount > ninvCount) {
  343. invCount = ninvCount;
  344. tries = 5;
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
Advertisement
Add Comment
Please, Sign In to add comment