Thondar

ss

Oct 10th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 128.44 KB | None | 0 0
  1. import java.awt.AlphaComposite;
  2. import java.awt.BasicStroke;
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import java.awt.Point;
  9. import java.awt.Rectangle;
  10. import java.awt.RenderingHints;
  11. import java.awt.event.KeyEvent;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import java.awt.event.MouseMotionListener;
  15. import java.awt.image.BufferedImage;
  16. import java.io.BufferedReader;
  17. import java.io.File;
  18. import java.io.IOException;
  19. import java.io.InputStreamReader;
  20. import java.net.URL;
  21. import java.text.DecimalFormat;
  22. import java.util.LinkedList;
  23. import java.util.Locale;
  24. import java.util.regex.Matcher;
  25. import java.util.regex.Pattern;
  26.  
  27. import javax.imageio.ImageIO;
  28.  
  29. import org.rsbot.Configuration;
  30. import org.rsbot.event.events.MessageEvent;
  31. import org.rsbot.event.listeners.MessageListener;
  32. import org.rsbot.event.listeners.PaintListener;
  33. import org.rsbot.gui.AccountManager;
  34. import org.rsbot.script.Script;
  35. import org.rsbot.script.ScriptManifest;
  36. import org.rsbot.script.methods.Bank;
  37. import org.rsbot.script.methods.Environment;
  38. import org.rsbot.script.methods.Game.Tab;
  39. import org.rsbot.script.methods.GrandExchange;
  40. import org.rsbot.script.methods.Magic;
  41. import org.rsbot.script.methods.Magic.Spell;
  42. import org.rsbot.script.methods.Skills;
  43. import org.rsbot.script.util.Timer;
  44. import org.rsbot.script.wrappers.RSArea;
  45. import org.rsbot.script.wrappers.RSComponent;
  46. import org.rsbot.script.wrappers.RSGroundItem;
  47. import org.rsbot.script.wrappers.RSInterface;
  48. import org.rsbot.script.wrappers.RSItem;
  49. import org.rsbot.script.wrappers.RSNPC;
  50. import org.rsbot.script.wrappers.RSObject;
  51. import org.rsbot.script.wrappers.RSPath;
  52. import org.rsbot.script.wrappers.RSPlayer;
  53. import org.rsbot.script.wrappers.RSTile;
  54. import org.rsbot.script.wrappers.RSWeb;
  55.  
  56. @ScriptManifest(website = "http://goo.gl/WEQX6", authors = { "hlunnb" }, keywords = { "Woodcutting, Firemaking" },
  57. name = "Dynamic Woodcutter", version = 1.85,
  58. description = "Independently trains Woodcutting and Firemaking from a low level.")
  59. public class Dwc extends Script implements PaintListener, MouseListener, MouseMotionListener, MessageListener {
  60. final RSArea adviserHouse = new RSArea(new RSTile(3229, 3236), new RSTile(3232, 3241));
  61. final RSArea bobsArea = new RSArea(new RSTile(3227, 3201), new RSTile(3233, 3205));
  62. final RSTile bobsTile = new RSTile(3230, 3203);
  63. final RSTile treeTile = new RSTile(3172, 3224);
  64. final RSTile oakTreeTile = new RSTile(3101, 3286); // North East
  65. final RSTile oakTreeTile2 = new RSTile(3115, 3245); // East
  66. final RSTile oakTreeTile3 = new RSTile(3082, 3298); // North
  67. final RSTile willowTreeTile = new RSTile(2971, 3195); // Rimm
  68. final RSTile willowTreeTile2 = new RSTile(3165, 3272); // Lumb
  69. final RSTile willowTreeTile3 = new RSTile(3060, 3254); // Port Sarim
  70. final RSTile willowTreeTile4 = new RSTile(3086, 3233); // Dray
  71. final RSTile yewTreeTile = new RSTile(2930, 3229);// Rimm
  72. final RSTile yewTreeTile2 = new RSTile(3166, 3234); // Lumb
  73. final RSTile yewTreeTile3 = new RSTile(3048, 3270); // Port Sarim
  74. final RSArea generalStoreArea = new RSArea(new RSTile(3210, 3238), new RSTile(3219, 3246));
  75. final RSTile generalStoreTile = new RSTile(3215, 3243);
  76. final RSArea generalStoreArea2 = new RSArea(new RSTile(2946, 3211), new RSTile(2950, 3218));
  77. final RSTile generalStoreTile2 = new RSTile(2948, 3215);
  78. final RSArea draynorBankArea = new RSArea(new RSTile(3092, 3240), new RSTile(3097, 3246));
  79. final RSTile draynorBankTile = new RSTile(3093, 3244);
  80. final RSTile[] toGe = { new RSTile(3095, 3261), new RSTile(3094, 3266), new RSTile(3093, 3272),
  81. new RSTile(3095, 3278), new RSTile(3095, 3283), new RSTile(3095, 3288), new RSTile(3089, 3291),
  82. new RSTile(3089, 3294), new RSTile(3095, 3300), new RSTile(3098, 3304), new RSTile(3098, 3309),
  83. new RSTile(3102, 3311), new RSTile(3108, 3311), new RSTile(3114, 3312), new RSTile(3118, 3315),
  84. new RSTile(3123, 3317), new RSTile(3126, 3319), new RSTile(3131, 3324), new RSTile(3135, 3329),
  85. new RSTile(3140, 3333), new RSTile(3144, 3333), new RSTile(3146, 3337), new RSTile(3146, 3342),
  86. new RSTile(3145, 3347), new RSTile(3143, 3351), new RSTile(3141, 3356), new RSTile(3143, 3362),
  87. new RSTile(3140, 3367), new RSTile(3139, 3372), new RSTile(3136, 3377) };
  88. final RSTile[] toGe2 = { new RSTile(3008, 3273), new RSTile(3008, 3274), new RSTile(3008, 3277),
  89. new RSTile(3008, 3280), new RSTile(3008, 3284), new RSTile(3007, 3287), new RSTile(3007, 3291),
  90. new RSTile(3007, 3295), new RSTile(3006, 3298), new RSTile(3006, 3301), new RSTile(3006, 3305),
  91. new RSTile(3010, 3310), new RSTile(3010, 3312), new RSTile(3015, 3317), new RSTile(3018, 3317),
  92. new RSTile(3021, 3320), new RSTile(3025, 3320), new RSTile(3029, 3320), new RSTile(3032, 3320),
  93. new RSTile(3035, 3319), new RSTile(3038, 3320), new RSTile(3043, 3322), new RSTile(3046, 3322),
  94. new RSTile(3049, 3322), new RSTile(3053, 3323), new RSTile(3058, 3321), new RSTile(3061, 3321),
  95. new RSTile(3066, 3325), new RSTile(3067, 3330), new RSTile(3070, 3333), new RSTile(3072, 3337),
  96. new RSTile(3072, 3340), new RSTile(3072, 3344), new RSTile(3072, 3348), new RSTile(3072, 3350),
  97. new RSTile(3072, 3354), new RSTile(3072, 3357), new RSTile(3072, 3358), new RSTile(3072, 3363),
  98. new RSTile(3072, 3368), new RSTile(3073, 3373), new RSTile(3073, 3377) };
  99. final RSTile[] willowsToBank = { new RSTile(2968, 3198), new RSTile(2972, 3199), new RSTile(2975, 3202),
  100. new RSTile(2978, 3205), new RSTile(2982, 3206), new RSTile(2985, 3209), new RSTile(2989, 3211),
  101. new RSTile(2992, 3214), new RSTile(2995, 3217), new RSTile(2998, 3220), new RSTile(3000, 3224),
  102. new RSTile(3002, 3228), new RSTile(3003, 3232), new RSTile(3004, 3236), new RSTile(3006, 3240),
  103. new RSTile(3010, 3242), new RSTile(3014, 3242), new RSTile(3018, 3242), new RSTile(3022, 3243),
  104. new RSTile(3026, 3242), new RSTile(3030, 3242), new RSTile(3034, 3244), new RSTile(3036, 3248),
  105. new RSTile(3039, 3251), new RSTile(3041, 3255), new RSTile(3044, 3259), new RSTile(3046, 3263),
  106. new RSTile(3049, 3266), new RSTile(3053, 3268), new RSTile(3057, 3270), new RSTile(3060, 3273),
  107. new RSTile(3064, 3274), new RSTile(3068, 3276), new RSTile(3072, 3275), new RSTile(3075, 3272),
  108. new RSTile(3076, 3268), new RSTile(3076, 3264), new RSTile(3077, 3260), new RSTile(3079, 3256),
  109. new RSTile(3082, 3253), new RSTile(3086, 3251), new RSTile(3089, 3248), new RSTile(3093, 3247),
  110. new RSTile(3094, 3243) };
  111. RSPath willowsToBankPath;
  112. RSPath bankToWillowsPath;
  113. RSPath pathToGE;
  114. RSPath pathToGE2;
  115. final RSTile GETile = new RSTile(3153, 3480);
  116. final RSArea grandExchangeArea = new RSArea(new RSTile(3144, 3473), new RSTile(3155, 3483));
  117. public static final int bronzeHatchetId = 1351;
  118. public static final int ironHatchetId = 1349;
  119. public static final int steelHatchetId = 1353;
  120. public static final int blackHatchetId = 1361;
  121. public static final int mithrilHatchetId = 1355;
  122. public static final int adamantHatchetId = 1357;
  123. public static final int runeHatchetId = 1359;
  124. public static final int tinderboxId = 590;
  125. public static final int regularLogId = 1511;
  126. public static final int oakLogId = 1521;
  127. public static final int willowLogId = 1519;
  128. public static final int yewLogId = 1515;
  129. public static final int notedOakId = 1522;
  130. final int[] hatchetIds = { runeHatchetId, adamantHatchetId, mithrilHatchetId, blackHatchetId, steelHatchetId,
  131. ironHatchetId, bronzeHatchetId };
  132. final int[] moveIds = { bronzeHatchetId, ironHatchetId, steelHatchetId, blackHatchetId, mithrilHatchetId,
  133. adamantHatchetId, runeHatchetId, 995, tinderboxId };
  134. final int[] logIds = { regularLogId, oakLogId, willowLogId, yewLogId };
  135. final int[] invOkIds = { regularLogId, oakLogId, willowLogId, yewLogId, 995, bronzeHatchetId, ironHatchetId,
  136. steelHatchetId, blackHatchetId, mithrilHatchetId, adamantHatchetId, runeHatchetId, notedOakId, tinderboxId,
  137. 14664, 13439 }; // Random event lamp 14664, Starter lamp 13439
  138. final int[] dontDepositIds = { bronzeHatchetId, ironHatchetId, steelHatchetId, blackHatchetId, mithrilHatchetId,
  139. adamantHatchetId, runeHatchetId, tinderboxId };
  140. final RSTile[] logStart = { new RSTile(3199, 3243), new RSTile(3199, 3244), new RSTile(3199, 3245),
  141. new RSTile(3199, 3246), new RSTile(3196, 3237), new RSTile(3202, 3236) };
  142. final RSTile[] oakStart = { new RSTile(3093, 3288), new RSTile(3093, 3290), new RSTile(3093, 3289),
  143. new RSTile(3106, 3273), new RSTile(3118, 3263), new RSTile(3105, 3249), new RSTile(3105, 3250),
  144. new RSTile(3101, 3248) };
  145. final RSTile[] willowRimmStart = { new RSTile(2968, 3194), new RSTile(2968, 3193), new RSTile(2976, 3192),
  146. new RSTile(2968, 3199), new RSTile(2968, 3200), new RSTile(2960, 3199) };
  147. final RSTile[] willowLumbStart = { new RSTile(3199, 3243), new RSTile(3199, 3244), new RSTile(3199, 3245),
  148. new RSTile(3199, 3246), new RSTile(3183, 3275), new RSTile(3183, 3276) };
  149. final RSTile[] willowPortStart = { new RSTile(3061, 3253), new RSTile(3061, 3254), new RSTile(3068, 3274),
  150. new RSTile(3068, 3275), new RSTile(3068, 3276) };
  151. final RSTile[] willowDrayStart = { new RSTile(3113, 3239), new RSTile(3108, 3238), new RSTile(3101, 3248),
  152. new RSTile(3105, 3249), new RSTile(3105, 3250), new RSTile(3112, 3251) };
  153. RSTile[] start;
  154. final int[] treeId = { 38782, 38783, 38784, 38785, 38786, 38787, 38788, 38760 };
  155. final int[] oakId = { 38731, 38732 };
  156. final int[] willowId = { 38616, 38627, 38616, 58006 };
  157. final int[] yewId = { 38755 };
  158. int runeHatchetPrice = -1;
  159. int oakPrice = -1;
  160. int totalCash = 0;
  161. int bankCash = 0;
  162. int oakCash = 0;
  163. int run = random(5, 30);
  164. boolean checkBank = false;
  165. boolean useBank = false;
  166. boolean useDeposit = false;
  167. boolean needTutoring = false;
  168. String status = "";
  169. String antiBan = "";
  170. boolean offeredOaks = false;
  171. boolean sentOffer = false;
  172. boolean sawLamp = false;
  173. boolean burnLogs = false;
  174. boolean trainFM = false;
  175. boolean trainFMHovered = false;
  176. RSItem dontClick = null;
  177. RSTile dest = null;
  178. boolean end = false;
  179. boolean showPaint = false;
  180. boolean checkedGE = false;
  181. long startTime;
  182. long antibanTimer = 0;
  183. long timer2;
  184. long clickTimer = 1000000000000000l;
  185. int initialXP = -1;
  186. int initialXP2 = -1;
  187. int initialLevel = -1;
  188. int initialLevel2 = -1;
  189. boolean wasLoggedOut = false;
  190. double scriptVersion = Dwc.class.getAnnotation(ScriptManifest.class).version();
  191. double currVer = -1;
  192. boolean loading = false;
  193. final Timer dotTimer = new Timer(200);
  194. Timer screenshotTimer;
  195. final Timer dropTimer = new Timer(1300);
  196. Timer rpTimer = null;
  197. boolean wait = true;
  198. int bankFails = 0;
  199. int treeFails = 0;
  200. boolean dropLogs;
  201. boolean scriptRunning = true;
  202. boolean moving = false;
  203. Paint mp;
  204. private final static int[] dropPath1 = { 1, 2, 3, 4, 8, 7, 6, 5, 9, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19, 20, 24,
  205. 23, 22, 21, 25, 26, 27, 28 };
  206. private final static int[] dropPath2 = { 1, 5, 2, 9, 6, 3, 13, 10, 7, 4, 17, 14, 11, 8, 21, 18, 15, 12, 25, 22, 19,
  207. 16, 26, 23, 20, 27, 24, 28 };
  208. private final static int[] dropPath3 = { 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23,
  209. 27, 4, 8, 12, 16, 20, 24, 28 };
  210. private final static int[] dropPath4 = { 4, 3, 2, 1, 5, 6, 7, 8, 12, 11, 10, 9, 13, 14, 15, 16, 20, 19, 18, 17, 21,
  211. 22, 23, 24, 28, 27, 26, 25 };
  212. private final static int[] dropPath5 = { 1, 2, 6, 5, 9, 10, 14, 13, 17, 18, 22, 21, 25, 26, 3, 4, 8, 7, 11, 12, 16,
  213. 15, 19, 20, 24, 23, 27, 28 };
  214.  
  215. private enum State {
  216. BUYHATCHET, TREE, OAK, WILLOWRIMM, WILLOWLUMB, WILLOWPORT, WILLOWDRAY, BUYRUNEHATCHET, CHECKBANK, DEPOSIT,
  217. GETUTOR, LAMPS, BURN, BUYTINDERBOX, YEW, error
  218. }
  219. @Override
  220. public boolean onStart() {
  221. mouse.setSpeed(6);
  222. new PaintUpdater();
  223. mp = new Paint();
  224. return true;
  225. }
  226. @Override
  227. public void onFinish() {
  228. env.enableRandom("Improved Login");
  229. scriptRunning = false;
  230. log(Color.BLUE, "Thanks for using my script, please leave your feedback on my thread.");
  231. }
  232. public int loop() {
  233. try {
  234. final int check = checkStuff();
  235. if (check != -1)
  236. return check;
  237. } catch (Exception e) {
  238. log(e);
  239. }
  240. switch (getState()) {
  241. case BUYTINDERBOX:
  242. RSItem coins = inventory.getItem(995);
  243. if (store.isOpen()) {
  244. if (interfaces.getComponent(620, 20).isValid()
  245. && interfaces.getComponent(620, 20).containsText("Rimmington")) {
  246. store.buy(tinderboxId, 1);
  247. return 1000;
  248. }
  249. if (interfaces.get(620).isValid()) {
  250. interfaces.get(620).getComponent(26).getComponent(0).interact("Take 1");
  251. return 1000;
  252. }
  253. }
  254. if (inventory.isFull()) {
  255. final RSItem[] inv = inventory.getItems();
  256. outer: for (final RSItem r : inv)
  257. for (final int i : logIds)
  258. if (r.getID() == i) {
  259. inventory.dropItem(r);
  260. break outer;
  261. }
  262. }
  263. RSTile dest = calc.distanceTo(generalStoreTile) < calc.distanceTo(generalStoreTile2) ? dest = generalStoreTile
  264. : generalStoreTile2;
  265. if (coins == null || dest.equals(generalStoreTile)) {
  266. if (calc.distanceTo(generalStoreTile) > 100) {
  267. if (!isAnimated())
  268. magic.castSpell(Magic.SPELL_HOME_TELEPORT);
  269. return 2000;
  270. }
  271. if (!generalStoreArea.contains(myLocation())) {
  272. webWalk(generalStoreTile);
  273. return random(500, 1000);
  274. } else {
  275. final RSNPC shopKeeper = npcs.getNearest(521, 520);
  276. if (shopKeeper != null)
  277. if (shopKeeper.isOnScreen()) {
  278. if (!shopKeeper.interact("Trade Shop"))
  279. return 0;
  280. chill();
  281. } else
  282. new Camera(shopKeeper);
  283. }
  284. }
  285. if (dest.equals(generalStoreTile2)) {
  286. if (!generalStoreArea2.contains(myLocation())) {
  287. webWalk(generalStoreTile2);
  288. return random(500, 1000);
  289. }
  290. final RSNPC shopKeeper = npcs.getNearest(530, 531);
  291. if (shopKeeper != null)
  292. if (shopKeeper.isOnScreen()) {
  293. if (!shopKeeper.interact("Trade Shop"))
  294. return 0;
  295. chill();
  296. } else
  297. new Camera(shopKeeper);
  298. }
  299. break;
  300. case BURN:
  301. if (getMyPlayer().isInCombat()
  302. || inventory.getCount(regularLogId, oakLogId, willowLogId, yewLogId) == 0 && isIdle())
  303. burnLogs = false;
  304. if (this.dest != null)
  305. return walkDest();
  306. if (!isSelected()) {
  307. if (clickLog())
  308. return random(50, 100);
  309. return 0;
  310. }
  311. if (isTileFree(myLocation())) {
  312. burnLog();
  313. if (inventory.getCount(regularLogId, oakLogId, willowLogId, yewLogId) == 1)
  314. return random(1600, 1700);
  315. } else if (isIdle())
  316. if (inventory.getCount(regularLogId, oakLogId, willowLogId, yewLogId) < 4
  317. || !findNewTile(start, false))
  318. burnLogs = false;
  319. if (antibanTimer < System.currentTimeMillis()) {
  320. new Camera(1000, 2000);
  321. antibanTimer = System.currentTimeMillis() + random(10000, 25000);
  322. }
  323. break;
  324. case GETUTOR:
  325. if (interfaces.canContinue()) {
  326. if (interfaces.get(241).getComponent(4).containsText("Good luck"))
  327. needTutoring = false;
  328. interfaces.clickContinue();
  329. return random(1000, 2000);
  330. }
  331. if (interfaces.get(230).isValid()) {
  332. interfaces.get(230).getComponent(2).doClick();
  333. return random(500, 1000);
  334. }
  335. final RSNPC tutor = npcs.getNearest(6521);
  336. if (tutor.isOnScreen()) {
  337. if (tutor.interact("Talk-to"))
  338. chill();
  339. return 0;
  340. } else {
  341. walking.walkTileMM(tutor.getLocation());
  342. return random(500, 1000);
  343. }
  344. case CHECKBANK:
  345. return useDraynorBank();
  346. case DEPOSIT:
  347. return useDeposit();
  348. case BUYRUNEHATCHET:
  349. if (!grandExchangeArea.contains(myLocation()))
  350. return walkToGE();
  351. if (!sentOffer
  352. && (inventory.contains(995) && inventory.getItem(995).getStackSize() < runeHatchetPrice * 1.1 || !inventory.contains(995)))
  353. if (!offeredOaks)
  354. if (!bank.isOpen() && !inventory.contains(1522)) {
  355. final RSNPC i = npcs.getNearest(BANKERS);
  356. mouse.move(i.getPoint());
  357. sleep(100, 200);
  358. mouse.click(false);
  359. if (menu.contains("Bank") && menu.clickIndex(menu.getIndex("Bank") + 1))
  360. return random(1500, 2000);
  361. } else if (bank.isOpen()) {
  362. if (bank.getItem(runeHatchetId) != null && !inventory.contains(runeHatchetId)) {
  363. bank.withdraw(runeHatchetId, 1);
  364. return 2000;
  365. }
  366. if (interfaces.getComponent(762, Bank.INTERFACE_BANK_BUTTON_NOTE).getTextureID() == 1431)
  367. bank.setWithdrawModeToNote();
  368. else {
  369. if (bank.getItem(995) != null) {
  370. bank.withdraw(995, random(25, 30) * 1000);
  371. sleep(1000);
  372. }
  373. if (bank.getItem(oakLogId) != null) {
  374. bank.withdraw(oakLogId, 0);
  375. sleep(1000);
  376. }
  377. bank.close();
  378. }
  379. return random(1200, 1500);
  380. }
  381. if (bankCollectIsOpen())
  382. bankCollectClose();
  383. if (!isOpen())
  384. open();
  385. if (isOpen()) {
  386. final int t = getEmptySlot();
  387. if (t > 0) {
  388. if (inventory.contains(1522) && getAllEmptySlots() > 0 && !offeredOaks)
  389. sell("Oak logs", t, inventory.getItem(1522).getStackSize(), (int) (oakPrice * 0.8));
  390. if (inventory.contains(995) && !sentOffer)
  391. if (inventory.getItem(995).getStackSize() >= runeHatchetPrice * 1.1)
  392. buy("Rune hatchet", t, 1, (int) (runeHatchetPrice * 1.1));
  393. for (int i = 1; i <= getTotalSlots();) {
  394. if (random(0, 10) == 0)
  395. mouse.moveSlightly();
  396. sleep(random(700, 1000));
  397. if (isAnOfferCompleted()) {
  398. log("Offer completed.");
  399. if (isOpen())
  400. close();
  401. if (!bankCollectIsOpen())
  402. bankCollectOpen();
  403. if (bankCollectIsOpen())
  404. bankCollectAll();
  405. }
  406. i++;
  407. }
  408. } else
  409. for (int i = 1; i <= getTotalSlots();) {
  410. if (random(0, 10) == 0)
  411. mouse.moveSlightly();
  412. sleep(random(700, 1000));
  413. if (isAnOfferCompleted()) {
  414. log("Offer completed.");
  415. if (isOpen())
  416. close();
  417. if (!bankCollectIsOpen())
  418. bankCollectOpen();
  419. if (bankCollectIsOpen())
  420. bankCollectAll();
  421. }
  422. i++;
  423. }
  424. }
  425. break;
  426. case BUYHATCHET:
  427. if (isAnimated())
  428. return random(500, 1500);
  429. if (adviserHouse.contains(myLocation())) {
  430. final RSObject door1 = objects.getTopAt(new RSTile(3228, 3240));
  431. if (door1 != null)
  432. if (door1.getID() == 45476) {
  433. if (door1.isOnScreen())
  434. door1.interact("Open");
  435. else
  436. walking.walkTileMM(door1.getLocation());
  437. chill();
  438. return 0;
  439. }
  440. walking.walkTileMM(bobsTile);
  441. }
  442. if (bobsArea.contains(myLocation()))
  443. if (interfaces.get(620).isValid()) {
  444. if (!inventory.contains(bronzeHatchetId)) {
  445. interfaces.get(620).getComponent(26).getComponent(4).interact("Take 1");
  446. return 1000;
  447. }
  448. if (!inventory.contains(steelHatchetId)) {
  449. store.getItem(steelHatchetId).interact("Buy 1");
  450. return 1000;
  451. }
  452. } else {
  453. final RSNPC bob = npcs.getNearest(519);
  454. if (bob != null)
  455. if (bob.isOnScreen()) {
  456. if (bob.interact("Trade Bob"))
  457. chill();
  458. return 0;
  459. } else {
  460. walking.walkTileMM(bob.getLocation());
  461. new Camera(bob);
  462. return 1000;
  463. }
  464. }
  465. if (!bobsArea.contains(myLocation())) {
  466. final RSObject door = objects.getTopAt(new RSTile(3234, 3203, 0));
  467. if (door != null)
  468. if (door.getID() == 45476) {
  469. if (door.isOnScreen())
  470. door.interact("Open");
  471. else
  472. walking.walkTileMM(door.getLocation());
  473. chill();
  474. return 0;
  475. }
  476. if (calc.distanceTo(bobsTile) > 100) {
  477. if (!isAnimated()) {
  478. magic.castSpell(Spell.LUMBRIDGE_HOME_TELEPORT);
  479. }
  480. return 2000;
  481. }
  482. webWalk(bobsTile);
  483. return random(500, 1000);
  484. }
  485. break;
  486. case TREE:
  487. if (store.isOpen()) {
  488. if ("Bob's Brilliant Axes".contains(interfaces.get(620).getComponent(20).getText())) {
  489. store.close();
  490. return 1000;
  491. }
  492. if (inventory.contains("Logs")) {
  493. inventory.getItem("Logs").interact("Sell 50");
  494. return 1500;
  495. }
  496. }
  497. if (dropLogs)
  498. return dropLogs();
  499. if (inventory.isFull()) {
  500. if (trainFM) {
  501. start = logStart;
  502. burnLogs = true;
  503. findNewTile(start, false);
  504. return 0;
  505. }
  506. if (drop) {
  507. dropLogs = true;
  508. return 0;
  509. }
  510. if (useBank) {
  511. checkBank = true;
  512. return 0;
  513. }
  514. if (!generalStoreArea.contains(myLocation())) {
  515. webWalk(generalStoreTile);
  516. return random(500, 1000);
  517. }
  518. final RSNPC shopKeeper = npcs.getNearest(521, 520);
  519. if (shopKeeper != null)
  520. if (shopKeeper.isOnScreen()) {
  521. if (!shopKeeper.interact("Trade Shop"))
  522. return 0;
  523. chill();
  524. } else
  525. new Camera(shopKeeper);
  526. return 0;
  527. }
  528. final int h = handleCoins();
  529. if (h != -1)
  530. return h;
  531. return chopTree(35, 25, treeTile, "Tree", treeId);
  532. case OAK:
  533. if (dropLogs)
  534. return dropLogs();
  535. if (inventory.isFull()) {
  536. if (trainFM) {
  537. start = oakStart;
  538. burnLogs = true;
  539. findNewTile(start, false);
  540. return 0;
  541. }
  542. if (drop || powerchop) {
  543. dropLogs = true;
  544. return 0;
  545. }
  546. checkBank = true;
  547. return 0;
  548. }
  549. if (oakLocation == 1)
  550. return chopTree(20, 10, oakTreeTile, "Oak", oakId);
  551. else if (oakLocation == 2)
  552. return chopTree(30, 20, oakTreeTile2, "Oak", oakId);
  553. else if (oakLocation == 3)
  554. return chopTree(15, 6, oakTreeTile3, "Oak", oakId);
  555. break;
  556. case WILLOWLUMB:
  557. if (dropLogs)
  558. return dropLogs();
  559. if (inventory.isFull()) {
  560. if (store.isOpen())
  561. return useStore();
  562. if (trainFM) {
  563. start = willowLumbStart;
  564. burnLogs = true;
  565. findNewTile(start, false);
  566. return 0;
  567. }
  568. if (drop || powerchop) {
  569. dropLogs = true;
  570. return 0;
  571. }
  572. if (useBank) {
  573. checkBank = true;
  574. return 0;
  575. }
  576. if (!generalStoreArea.contains(myLocation())) {
  577. webWalk(generalStoreTile);
  578. return random(500, 1000);
  579. }
  580. final RSNPC shopKeeper = npcs.getNearest(521, 520);
  581. if (shopKeeper != null)
  582. if (shopKeeper.isOnScreen()) {
  583. if (!shopKeeper.interact("Trade Shop"))
  584. return 0;
  585. chill();
  586. } else
  587. new Camera(shopKeeper);
  588. return 0;
  589. }
  590. return chopTree(30, 20, willowTreeTile2, "Willow", willowId);
  591. case WILLOWRIMM:
  592. if (dropLogs)
  593. return dropLogs();
  594. if (inventory.isFull()) {
  595. if (store.isOpen())
  596. return useStore();
  597. if (trainFM) {
  598. start = willowRimmStart;
  599. burnLogs = true;
  600. findNewTile(start, false);
  601. return 0;
  602. }
  603. if (drop || powerchop) {
  604. dropLogs = true;
  605. return 0;
  606. }
  607. if (useBank) {
  608. useDeposit = true;
  609. return 0;
  610. }
  611. if (!generalStoreArea2.contains(myLocation())) {
  612. webWalk(generalStoreTile2);
  613. return random(500, 1000);
  614. }
  615. final RSNPC shopKeeper = npcs.getNearest(530, 531);
  616. if (shopKeeper != null)
  617. if (shopKeeper.isOnScreen()) {
  618. if (!shopKeeper.interact("Trade Shop"))
  619. return 0;
  620. chill();
  621. } else
  622. new Camera(shopKeeper);
  623. return 0;
  624. }
  625. if (calc.distanceTo(draynorBankTile) < 40 && inventory.getCount(invOkIds) > 10) {
  626. checkBank = true;
  627. return 0;
  628. }
  629. if (calc.distanceTo(willowTreeTile) > 20) {
  630. bankToWillowsPath = walking.newTilePath(willowsToBank).reverse();
  631. if (bankToWillowsPath.isValid()) {
  632. bankToWillowsPath.traverse();
  633. return random(500, 2700);
  634. }
  635. webWalk(willowTreeTile);
  636. return random(500, 1000);
  637. }
  638. return chopTree(20, 10, willowTreeTile, "Willow", willowId);
  639. case WILLOWPORT:
  640. if (dropLogs)
  641. return dropLogs();
  642. if (inventory.isFull()) {
  643. if (trainFM) {
  644. start = willowPortStart;
  645. burnLogs = true;
  646. findNewTile(start, true);
  647. return 0;
  648. }
  649. if (drop || powerchop) {
  650. dropLogs = true;
  651. return 0;
  652. }
  653. if (useBank) {
  654. useDeposit = true;
  655. return 0;
  656. }
  657. checkBank = true;
  658. return 0;
  659. }
  660. return chopTree(25, 15, willowTreeTile3, "Willow", willowId);
  661. case WILLOWDRAY:
  662. if (dropLogs)
  663. return dropLogs();
  664. if (inventory.isFull()) {
  665. if (trainFM) {
  666. start = willowDrayStart;
  667. burnLogs = true;
  668. findNewTile(start, true);
  669. return 0;
  670. }
  671. if (drop || powerchop) {
  672. dropLogs = true;
  673. return 0;
  674. }
  675. checkBank = true;
  676. return 0;
  677. }
  678. return chopTree(15, 15, willowTreeTile4, "Willow", willowId);
  679. case YEW:
  680. useBank = true; // Always bank Yew logs.
  681. if (inventory.isFull()) {
  682. if (yewLocation == 1 || yewLocation == 3)
  683. useDeposit = true;
  684. else if (yewLocation == 2)
  685. checkBank = true;
  686. return 0;
  687. }
  688. if (yewLocation == 1)
  689. return chopTree(45, 30, yewTreeTile, "Yew", yewId);
  690. else if (yewLocation == 2)
  691. return chopTree(40, 30, yewTreeTile2, "Yew", yewId);
  692. else if (yewLocation == 3)
  693. return chopTree(25, 15, yewTreeTile3, "Yew", yewId);
  694. break;
  695. case LAMPS:
  696. final RSObject downLadder = objects.getNearest(37683);
  697. final RSObject door = objects.getTopAt(new RSTile(3228, 3240));
  698. final RSNPC sirVant = npcs.getNearest(7942);
  699. final RSItem lamp = inventory.getItem(13439);
  700. if (sawLamp && lamp == null) {
  701. final RSObject upLadder = objects.getNearest(37684);
  702. if (upLadder != null) {
  703. if (upLadder.isOnScreen())
  704. upLadder.interact("Climb-up");
  705. else
  706. walking.walkTileMM(upLadder.getLocation());
  707. chill();
  708. return 1000;
  709. }
  710. }
  711. if (interfaces.get(1139).isValid()) {
  712. interfaces.get(1139).getComponent(17).interact("Select");
  713. sleep(50, 200);
  714. interfaces.get(1139).getComponent(2).interact("Confirm");
  715. return 1000;
  716. }
  717. if (lamp != null) {
  718. sawLamp = true;
  719. if (lamp.interact("Rub"))
  720. return 1500;
  721. }
  722. if (interfaces.get(243).isValid())
  723. if (interfaces.get(243).getComponent(4).containsText("much for the offer")) {
  724. sawLamp = true;
  725. return 0;
  726. }
  727. if (interfaces.get(228).isValid())
  728. if (interfaces.get(228).getComponent(2).containsText("I could kill the")) {
  729. interfaces.get(228).getComponent(2).doClick();
  730. return 1000;
  731. }
  732. if (interfaces.canContinue()) {
  733. interfaces.clickContinue();
  734. return random(800, 1900);
  735. }
  736. if (sirVant != null && calc.distanceTo(sirVant) < 10) {
  737. if (sirVant.isOnScreen()) {
  738. if (!sirVant.interact("Talk-to"))
  739. return 0;
  740. else
  741. chill();
  742. } else {
  743. walking.walkTileMM(sirVant.getLocation());
  744. chill();
  745. }
  746. return 500;
  747. }
  748. if (!adviserHouse.contains(myLocation())) {
  749. if (door != null && door.getID() == 45476)
  750. if (door.isOnScreen()) {
  751. door.interact("Open");
  752. chill();
  753. return 1000;
  754. } else {
  755. walking.walkTileMM(door.getLocation());
  756. return random(500, 1700);
  757. }
  758. }
  759. if (downLadder != null) {
  760. if (downLadder.isOnScreen()) {
  761. if (!downLadder.interact("Climb-down"))
  762. return 0;
  763. } else {
  764. walking.walkTileMM(downLadder.getLocation());
  765. new Camera(downLadder);
  766. }
  767. chill();
  768. return 1000;
  769. }
  770. webWalk(new RSTile(3226, 3240, 0));
  771. sleep(random(500, 1000));
  772. break;
  773. } // end of switch
  774. return random(300, 500);
  775. }
  776. private int[] reverse(int[] b) {
  777. for (int left = 0, right = b.length - 1; left < right; left++, right--) {
  778. int temp = b[left];
  779. b[left] = b[right];
  780. b[right] = temp;
  781. }
  782. return b;
  783. }
  784. private int dropLogs() {
  785. final RSItem[] logs = inventory.getItems(logIds);
  786. if (logs.length == 0)
  787. dropLogs = false;
  788. int[] chosenPath = null;
  789. switch (random(0, 6)) {
  790. case 0:
  791. if (random(0, 2) == 0)
  792. for (int i = random(0, logs.length - 1); i < logs.length && i >= 0; i++) {
  793. logs[i].interact("Drop");
  794. final int count = inventory.getCount(logIds);
  795. if (count > 5 && random(0, 10) == 0)
  796. i++;
  797. }
  798. else
  799. for (int i = random(0, logs.length - 1); i >= 0; i--) {
  800. logs[i].interact("Drop");
  801. final int count = inventory.getCount(logIds);
  802. if (count > 5 && random(0, 10) == 0)
  803. i--;
  804. }
  805. return 0;
  806. case 1:
  807. if (random(0, 2) == 0)
  808. chosenPath = dropPath1;
  809. else
  810. chosenPath = reverse(dropPath1);
  811. break;
  812. case 2:
  813. if (random(0, 2) == 0)
  814. chosenPath = dropPath2;
  815. else
  816. chosenPath = reverse(dropPath2);
  817. break;
  818. case 3:
  819. if (random(0, 2) == 0)
  820. chosenPath = dropPath3;
  821. else
  822. chosenPath = reverse(dropPath3);
  823. break;
  824. case 4:
  825. if (random(0, 2) == 0)
  826. chosenPath = dropPath4;
  827. else
  828. chosenPath = reverse(dropPath4);
  829. break;
  830. case 5:
  831. if (random(0, 2) == 0)
  832. chosenPath = dropPath5;
  833. else
  834. chosenPath = reverse(dropPath5);
  835. break;
  836. }
  837. for (int i : chosenPath) {
  838. RSItem log = inventory.getItemAt(i - 1);
  839. inner: for (int id : logIds) {
  840. if (log.getID() == id) {
  841. if (log != null && !log.interact("Drop"))
  842. log = inventory.getItemAt(i - 1);
  843. break inner;
  844. }
  845. }
  846. }
  847. if (inventory.getCount(logIds) < 3)
  848. dropLogs = false;
  849. return random(100, 300);
  850. }
  851. private int walkToGE() {
  852. pathToGE = walking.newTilePath(toGe);
  853. pathToGE2 = walking.newTilePath(toGe2);
  854. if (calc.distanceTo(pathToGE.getEnd()) > 25 && pathToGE.isValid()) {
  855. pathToGE.traverse();
  856. return random(500, 2700);
  857. }
  858. if (calc.distanceTo(pathToGE2.getEnd()) > 25 && pathToGE2.isValid()) {
  859. pathToGE2.traverse();
  860. return random(500, 2700);
  861. }
  862. webWalk(GETile);
  863. return random(300, 1500);
  864. }
  865. private int useStore() {
  866. for (final int i : logIds)
  867. if (inventory.contains(i) && inventory.getItem(i).interact("Sell 50"))
  868. return random(1000, 1500);
  869. return 0;
  870. }
  871. private int useDeposit() {
  872. if (bank.isDepositOpen()) {
  873. if (depositAllExcept(dontDepositIds))
  874. useDeposit = false;
  875. return 0;
  876. }
  877. final RSObject depositBox = objects.getNearest(Bank.DEPOSIT_BOXES);
  878. if (depositBox != null && depositBox.isOnScreen()) {
  879. if (!depositBox.interact("Deposit " + depositBox.getName())) {
  880. new Camera(depositBox);
  881. return 0;
  882. }
  883. chill();
  884. return random(700, 1500);
  885. }
  886. webWalk(new RSTile(3047, 3235));
  887. return random(500, 1000);
  888. }
  889. private boolean depositAllExcept(int[] ids) {
  890. int money = inventory.contains(995) ? inventory.getItem(995).getStackSize() : 0;
  891. RSItem deposit = null;
  892. outer: for (RSItem r : inventory.getItems()) {
  893. for (int i : ids) {
  894. if (r.getID() == i) {
  895. continue outer;
  896. }
  897. }
  898. if (!r.hasAction("Drop")) {
  899. continue;
  900. } else if (deposit == null || r.getID() != deposit.getID()) {
  901. deposit = r;
  902. if (bank.deposit(deposit.getID(), 0)) {
  903. if (deposit.getID() == 995)
  904. bankCash += money;
  905. sleep(random(300, 500));
  906. }
  907. continue outer;
  908. }
  909. }
  910. if (deposit == null)
  911. return true;
  912. return false;
  913. }
  914. private int checkStuff() {
  915. if (end) {
  916. env.disableRandom("Improved Login");
  917. if (!game.isLoggedIn())
  918. stopScript(false);
  919. game.logout(false);
  920. log("Ending...");
  921. return 1000;
  922. }
  923. if (!loading) {
  924. loading = true;
  925. if (currVer == -1) {
  926. new InformationLoader(InformationLoader.VERSION);
  927. return 0;
  928. }
  929. if (!checkedGE) {
  930. new InformationLoader(InformationLoader.CHECKGE);
  931. return 0;
  932. }
  933. }
  934. if (isLoggedIn()) {
  935. if (initialXP == -1) {
  936. initialXP = skills.getCurrentExp(Skills.WOODCUTTING);
  937. initialXP2 = skills.getCurrentExp(Skills.FIREMAKING);
  938. initialLevel = wcLvl();
  939. initialLevel2 = fmLvl();
  940. startTime = System.currentTimeMillis();
  941. screenshotTimer = new Timer(7200000);
  942. antibanTimer = startTime + random(5000, 10000);
  943. status = "";
  944. }
  945. } else {
  946. return 1000;
  947. }
  948. if (wait) {
  949. return 100;
  950. }
  951. if (screenshotTimer != null && !screenshotTimer.isRunning()) {
  952. log("Taking screenshot.");
  953. env.saveScreenshot(true);
  954. screenshotTimer.reset();
  955. }
  956. totalCash = inventory.getItem(995) == null ? bankCash + oakCash : inventory.getItem(995).getStackSize()
  957. + bankCash + oakCash;
  958. final RSItem[] invent = inventory.getItems();
  959. outer: for (final RSItem r : invent) {
  960. if (r.hasAction("Eat")) {
  961. r.interact("Eat");
  962. sleep(700);
  963. }
  964. if (!r.hasAction("Drop") || r.getName().toLowerCase().contains("hatchet"))
  965. continue;
  966. for (final int h : invOkIds) {
  967. if (r.getID() == h)
  968. continue outer;
  969. }
  970. r.interact("Drop");
  971. }
  972. if (interfaces.get(149).isValid()) {
  973. sleep(random(300, 500));
  974. if (!interfaces.get(149).getComponent(230).interact("Select"))
  975. return 500;
  976. log("Closed level 10 Woodcutting solicitation message.");
  977. }
  978. if (interfaces.get(1066).isValid()) {
  979. sleep(random(300, 500));
  980. interfaces.get(1066).getComponent(34).doHover();
  981. if (!interfaces.get(1066).getComponent(34).interact("Close"))
  982. return 500;
  983. log("Closed Entrana monk solicitation message.");
  984. }
  985. if (!checkBank && !store.isOpen() && !bank.isOpen() && !bank.isDepositOpen()) {
  986. bestHatchetAvailable = bestHatchetAvailable();
  987. for (int i : hatchetIds)
  988. if (!useAvailableHatchets && i != bestHatchetAvailable && inventory.contains(i))
  989. inventory.dropItem(i);
  990. }
  991. if (!walking.isRunEnabled() && run < walking.getEnergy()) {
  992. interfaces.getComponent(walking.INTERFACE_RUN_ORB, 0).doHover();
  993. if (!interfaces.getComponent(walking.INTERFACE_RUN_ORB, 0).interact("Turn run mode on")) {
  994. mouse.moveRandomly(20);
  995. return 0;
  996. }
  997. run = random(5, 30);
  998. sleep(500, 800);
  999. }
  1000. if (myLocation().getZ() != 0) {
  1001. final int myFloor = myLocation().getZ();
  1002. log("How did you get up there?");
  1003. int dist = 20;
  1004. RSObject stairs = null;
  1005. for (final RSObject o : objects.getAll(2348, 9471, 9559, 36769, 36770, 36774, 36775, 36777, 36778, 39329,
  1006. 40059, 45482, 45484, 55450))
  1007. if (o.getLocation().getZ() == myFloor) {
  1008. if (calc.distanceTo(o) < dist) {
  1009. dist = calc.distanceTo(o);
  1010. stairs = o;
  1011. }
  1012. }
  1013. if (stairs == null) {
  1014. log("There is no way to get down.");
  1015. end = true;
  1016. return 0;
  1017. }
  1018. if (calc.tileOnScreen(stairs.getLocation())) {
  1019. mouse.move(stairs.getPoint());
  1020. if (stairs.hasAction("Climb-up") && myLocation().getZ() < 0) {
  1021. stairs.interact("Climb-up");
  1022. } else if (stairs.hasAction("Climb-down") && myLocation().getZ() > 0) {
  1023. stairs.interact("Climb-down");
  1024. } else if (stairs.doClick()) {
  1025. log("Climbing...");
  1026. chill();
  1027. sleep(2000);
  1028. } else
  1029. end = true;
  1030. } else {
  1031. walking.walkTileMM(stairs.getLocation());
  1032. new Camera(stairs);
  1033. chill();
  1034. }
  1035. return random(1000, 1500);
  1036. }
  1037. return -1;
  1038. }
  1039. private boolean isLoggedIn() {
  1040. return interfaces.get(137).isValid() && (game.getClientState() == 11 || game.isLoading());
  1041. }
  1042. private String manageDots() {
  1043. if (!dotTimer.isRunning()) {
  1044. dotTimer.reset();
  1045. if (dots.length() >= 3)
  1046. dots = "";
  1047. else
  1048. dots = dots + ".";
  1049. }
  1050. return dots;
  1051. }
  1052. private void webWalk(final RSTile dest) {
  1053. RSWeb walkWeb = null;
  1054. try {
  1055. walkWeb = web.getWeb(dest);
  1056. } catch (final Exception e) {
  1057. log("Exception: " + e);
  1058. }
  1059. if (bobsArea.contains(myLocation())) {
  1060. final RSObject door = objects.getTopAt(new RSTile(3234, 3203, 0));
  1061. if (door != null) {
  1062. if (door.getID() == 45476) {
  1063. if (door.isOnScreen())
  1064. door.interact("Open");
  1065. else
  1066. walking.walkTileMM(door.getLocation());
  1067. chill();
  1068. }
  1069. return;
  1070. }
  1071. }
  1072. if (adviserHouse.contains(myLocation())) {
  1073. final RSObject door1 = objects.getTopAt(new RSTile(3228, 3240));
  1074. if (door1 != null) {
  1075. if (door1.getID() == 45476) {
  1076. if (door1.isOnScreen())
  1077. door1.interact("Open");
  1078. else
  1079. walking.walkTileMM(door1.getLocation());
  1080. chill();
  1081. }
  1082. return;
  1083. }
  1084. }
  1085. if (walkWeb != null) {
  1086. if (!getMyPlayer().isMoving() || calc.distanceTo(walking.getDestination()) < 5) {
  1087. walkWeb.step();
  1088. if (calc.distanceTo(dest) <= 5)
  1089. walking.walkTileMM(walkWeb.getEnd().randomize(2, 2));
  1090. antiBan();
  1091. }
  1092. } else {
  1093. if (calc.distanceTo(walking.getDestination()) <= 5) {
  1094. walking.walkTileMM(dest.randomize(2, 2));
  1095. }
  1096. }
  1097. }
  1098. private RSTile myLocation() {
  1099. return getMyPlayer().getLocation();
  1100. }
  1101. private int wcLvl() {
  1102. return skills.getRealLevel(Skills.WOODCUTTING);
  1103. }
  1104. private int fmLvl() {
  1105. return skills.getRealLevel(Skills.FIREMAKING);
  1106. }
  1107. private void chill() {
  1108. sleep(1000);
  1109. while (getMyPlayer().isMoving() && !isPaused()) {
  1110. if (store.isOpen())
  1111. break;
  1112. sleep(100);
  1113. }
  1114. }
  1115. private int useDraynorBank() {
  1116. final RSNPC banker = npcs.getNearest(Bank.BANKERS);
  1117. if (!bank.isOpen() && banker != null && calc.distanceTo(banker) < 20) {
  1118. if (banker.isOnScreen()) {
  1119. mouse.move(banker.getPoint());
  1120. mouse.click(false);
  1121. sleep(random(10, 40));
  1122. if (!menu.contains("Bank"))
  1123. mouse.moveRandomly(200);
  1124. if (menu.contains("Bank") && !menu.clickIndex(menu.getIndex("Bank") + 1))
  1125. return 0;
  1126. } else {
  1127. new Camera(banker);
  1128. walking.walkTileMM(banker.getLocation());
  1129. }
  1130. // banker.interact("Talk-to"); // TODO ... "Bank" clicks "Talk-to"
  1131. chill();
  1132. return 0;
  1133. } else if (bank.isOpen()) {
  1134. if (inventory.getCount() > 0 && !bank.depositAll())
  1135. return 0;
  1136. sleep(random(1500, 2000));
  1137. final RSItem[] bankItems = bank.getItems();
  1138. for (final RSItem r : bankItems) {
  1139. final String name = r.getName();
  1140. if (name.contains("Bronze hatchet"))
  1141. hasBronzeHatchet = true;
  1142. if (name.contains("Iron hatchet"))
  1143. hasIronHatchet = true;
  1144. if (name.contains("Steel hatchet"))
  1145. hasSteelHatchet = true;
  1146. if (name.contains("Black hatchet"))
  1147. hasBlackHatchet = true;
  1148. if (name.contains("Mithril hatchet"))
  1149. hasMithrilHatchet = true;
  1150. if (name.contains("Adamant hatchet"))
  1151. hasAdamantHatchet = true;
  1152. if (name.contains("Rune hatchet"))
  1153. hasRuneHatchet = true;
  1154. }
  1155. bestHatchetAvailable = bestHatchetAvailable();
  1156. final RSItem coins = bank.getItem("Coins");
  1157. if (coins != null)
  1158. bankCash = coins.getStackSize();
  1159. else
  1160. bankCash = 0;
  1161. final RSItem oaks = bank.getItem("Oak logs");
  1162. if (oaks != null)
  1163. oakCash = oaks.getStackSize() * oakPrice;
  1164. else
  1165. oakCash = 0;
  1166. if (bestHatchetAvailable != -1 && bank.getItem(bestHatchetAvailable) != null
  1167. && !inventory.contains(bestHatchetAvailable)) {
  1168. bank.withdraw(bestHatchetAvailable, 1);
  1169. bankFails = 0;
  1170. sleep(random(1500, 2000));
  1171. } else if (inventory.contains(bestHatchetAvailable))
  1172. sleep(random(500, 1000));
  1173. else if (bankFails > 3) {
  1174. log("No hatchet available for your current level");
  1175. end = true;
  1176. return 0;
  1177. } else {
  1178. log("Bank fail count: " + ++bankFails);
  1179. return random(1000, 2000);
  1180. }
  1181. if (trainFM && !inventory.contains(tinderboxId)) {
  1182. if (bank.getItem(tinderboxId) != null)
  1183. bank.withdraw(tinderboxId, 1);
  1184. sleep(random(1500, 2000));
  1185. }
  1186. if (inventory.contains(bestHatchetAvailable) && bestHatchetAvailable != -1
  1187. && (!trainFM || trainFM && inventory.contains(tinderboxId))) {
  1188. checkBank = false;
  1189. checkedBank = true;
  1190. bank.close();
  1191. }
  1192. }
  1193. if (!draynorBankArea.contains(myLocation())) {
  1194. willowsToBankPath = walking.newTilePath(willowsToBank);
  1195. if (willowsToBankPath.isValid()) {
  1196. willowsToBankPath.traverse();
  1197. return random(500, 2700);
  1198. }
  1199. webWalk(draynorBankTile);
  1200. return random(500, 1000);
  1201. }
  1202. return 0;
  1203. }
  1204. /**
  1205. * @author hlunnb
  1206. * @param farDist The distance away from the centre where web walking is used to get back.
  1207. * @param closeDist The distance away from the centre where it will click the centre and wait until it walks back,
  1208. * trees should be inside this area.
  1209. * @param t The centre tile.
  1210. * @param treeName The name of the tree. "Willow"
  1211. * @param treeId An array tree Ids
  1212. * @return A number representing the amount of time to sleep based on the action completed. Should return this value
  1213. * in loop.
  1214. */
  1215. private int chopTree(final int farDist, final int closeDist, final RSTile t, final String treeName,
  1216. final int[] treeId) {
  1217. if (powerchop && !trainFM) {
  1218. final RSItem item1 = inventory.getItem(moveIds);
  1219. final int idx = item1.getComponent().getComponentIndex();
  1220. if (idx == 0 || idx == 1 || idx == 4 || idx == 5) {
  1221. int x = 24;
  1222. RSItem item2 = inventory.getItemAt(x);
  1223. checkIds: for (final int i : moveIds)
  1224. if (item2.getID() == i) {
  1225. x += 1;
  1226. item2 = inventory.getItemAt(x);
  1227. break checkIds;
  1228. }
  1229. item1.getComponent().doHover();
  1230. RSComponent component = item2.getComponent();
  1231. mouse.drag(random(component.getAbsoluteX(), component.getAbsoluteX() + component.getWidth()),
  1232. random(component.getAbsoluteY(), component.getAbsoluteY() + component.getHeight()));
  1233. logCount = inventory.getCount(regularLogId, oakLogId, willowLogId);
  1234. }
  1235. }
  1236. if (calc.distanceTo(t) > farDist) {
  1237. webWalk(t);
  1238. return random(500, 1000);
  1239. }
  1240. if (calc.distanceTo(t) > closeDist) {
  1241. walking.walkTileMM(t);
  1242. chill();
  1243. }
  1244. if (calc.distanceTo(t) <= closeDist) {
  1245. RSObject tree = getNearestTree(treeId, t, closeDist);
  1246. if (tree != null) {
  1247. if (clickTree && calc.tileOnScreen(tree.getLocation())) {
  1248. new Camera(Camera.PITCH);
  1249. if (!tiles.interact(tree.getLocation(), "Chop down " + treeName))
  1250. return 0;
  1251. clickTree = false;
  1252. dropTimer.reset();
  1253. return 0;
  1254. }
  1255. if (!dropTimer.isRunning()
  1256. && ((treeId == this.treeId || treeId == willowId) && distanceTo(tree) > 1 || (treeId == oakId || treeId == yewId)
  1257. && distanceTo(tree) > 2))
  1258. if (tree.isOnScreen()) {
  1259. if (tree.getModel().interact("Chop down " + treeName)) {
  1260. treeFails = 0;
  1261. chill();
  1262. logCount = inventory.getCount(regularLogId, oakLogId, willowLogId);
  1263. clickTree = false;
  1264. } else {
  1265. treeFails++;
  1266. if (treeFails > 5)
  1267. new Camera(tree);
  1268. }
  1269. return 0;
  1270. } else {
  1271. if (camera.getAngleTo(camera.getObjectAngle(tree)) > 30)
  1272. new Camera(tree);
  1273. if (calc.distanceTo(walking.getDestination()) < 7 || isIdle()) {
  1274. walking.walkTileMM(tree.getLocation());
  1275. return random(800, 1500);
  1276. }
  1277. return 0;
  1278. }
  1279. if (!dropTimer.isRunning() && !isAnimated()) {
  1280. tree = getNearestTree(treeId, t, closeDist);
  1281. if (tree == null)
  1282. return 0;
  1283. if (tree.isOnScreen()) {
  1284. if (tree.getModel().interact("Chop down " + treeName)) {
  1285. treeFails = 0;
  1286. chill();
  1287. logCount = inventory.getCount(regularLogId, oakLogId, willowLogId);
  1288. clickTree = false;
  1289. } else {
  1290. treeFails++;
  1291. if (treeFails > 3)
  1292. new Camera(tree);
  1293. }
  1294. return 0;
  1295. } else {
  1296. if (camera.getAngleTo(camera.getObjectAngle(tree)) > 30)
  1297. new Camera(tree);
  1298. if (calc.distanceTo(walking.getDestination()) < 7 || isIdle()) {
  1299. walking.walkTileMM(tree.getLocation());
  1300. return random(800, 1500);
  1301. }
  1302. return 0;
  1303. }
  1304. }
  1305. } else if (calc.distanceTo(t) > 5) {
  1306. webWalk(t.randomize(3, 3));
  1307. return random(800, 1500);
  1308. }
  1309. }
  1310. if (!powerchop && isAnimated())
  1311. antiBan();
  1312. if (powerchop && !trainFM) {
  1313. if (invLog == null || !invLog.hasAction("Drop"))
  1314. invLog = inventory.getItem(regularLogId, oakLogId, willowLogId);
  1315. final int logs = inventory.getCount(regularLogId, oakLogId, willowLogId);
  1316. if (!dropTimer.isRunning() && logCount < logs
  1317. && inventory.getCount(regularLogId, oakLogId, willowLogId) > 3 && inventory.getCount() < 27) {
  1318. new Camera(Camera.PITCH);
  1319. if (!invLog.getComponent().contains(mouse.getLocation().x, mouse.getLocation().y)) {
  1320. invLog.getComponent().doHover();
  1321. return 0;
  1322. }
  1323. mouse.click(false);
  1324. sleep(random(10, 40));
  1325. mouse.hop(mouse.getLocation().x, mouse.getLocation().y + 37);
  1326. sleep(random(10, 40));
  1327. mouse.click(true);
  1328. logCount = logs - 1;
  1329. clickTree = true;
  1330. final RSItem invLogOld = invLog;
  1331. boolean continued = false;
  1332. for (final RSItem i : inventory.getItems())
  1333. if (i.getName().toLowerCase(Locale.ENGLISH).contains("logs")
  1334. && !i.getPoint().equals(invLog.getPoint()) && i.hasAction("Drop")) {
  1335. if (random(0, 10) == 0 && !continued) {
  1336. continued = true;
  1337. continue;
  1338. }
  1339. invLog = i;
  1340. break;
  1341. }
  1342. if (random(0, 5) == 0) {
  1343. if (!invLog.getComponent().doHover())
  1344. return 0;
  1345. mouse.click(false);
  1346. sleep(random(10, 40));
  1347. mouse.hop(mouse.getLocation().x, mouse.getLocation().y + 50);
  1348. sleep(random(10, 40));
  1349. mouse.click(true);
  1350. logCount--;
  1351. for (final RSItem i : inventory.getItems())
  1352. if (i.getName().toLowerCase(Locale.ENGLISH).contains("logs")
  1353. && !i.getPoint().equals(invLog.getPoint())
  1354. && !i.getPoint().equals(invLogOld.getPoint()) && i.hasAction("Drop")) {
  1355. invLog = i;
  1356. break;
  1357. }
  1358. }
  1359. }
  1360. if (invLog != null && !clickTree)
  1361. if (!invLog.getComponent().contains(mouse.getLocation().x, mouse.getLocation().y)) {
  1362. new Camera(Camera.PITCH);
  1363. invLog.getComponent().doHover();
  1364. } else if (rpTimer == null || !rpTimer.isRunning()) {
  1365. final Rectangle r = invLog.getComponent().getArea();
  1366. final Point rp = new Point((int) (r.getX() + r.getWidth() * random(0, 1000) / 1000),
  1367. (int) (r.getY() + r.getHeight() * random(0, 1000) / 1000));
  1368. mouse.move(rp);
  1369. rpTimer = new Timer(random(2000, 15000));
  1370. } else {
  1371. antiBan();
  1372. logCount = inventory.getCount(regularLogId, oakLogId, willowLogId);
  1373. }
  1374. }
  1375. return 0;
  1376. }
  1377. private int distanceTo(final RSObject t) {
  1378. final int xDist = Math.abs(myLocation().getX() - t.getLocation().getX());
  1379. final int yDist = Math.abs(myLocation().getY() - t.getLocation().getY());
  1380. return xDist > yDist ? xDist : yDist;
  1381. }
  1382. /**
  1383. * Returns the <tt>RSObject</tt> that is nearest and a within certain distance away a centre tile.
  1384. * @param treeId The array of tree ids.
  1385. * @param t The centre tile.
  1386. * @param closeDist The maximum distance from the centre tile.
  1387. * @return An <tt>RSObject</tt> representing the nearest tree within the approved distance or null if a tree cannot
  1388. * be found.
  1389. */
  1390. private RSObject getNearestTree(final int[] treeId, final RSTile t, final int closeDist) {
  1391. RSObject tree = null;
  1392. RSObject tree2;
  1393. int dist = 100000000;
  1394. for (final int i : treeId) {
  1395. tree2 = objects.getNearest(i);
  1396. if (tree2 == null || calc.distanceBetween(t, tree2.getLocation()) >= closeDist)
  1397. continue;
  1398. if (calc.distanceTo(tree2.getLocation()) < dist) {
  1399. dist = calc.distanceTo(tree2.getLocation());
  1400. tree = objects.getNearest(i);
  1401. }
  1402. }
  1403. return tree;
  1404. }
  1405. private void burnLog() {
  1406. if (isSelected())
  1407. if (timer2 < System.currentTimeMillis() && isIdle()) {
  1408. if (clickTin())
  1409. timer2 = System.currentTimeMillis() + random(1600, 1700);
  1410. } else
  1411. hoverTin();
  1412. }
  1413. private void hoverTin() {
  1414. final RSItem tin = inventory.getItem(tinderboxId);
  1415. tin.getComponent().doHover();
  1416. }
  1417. private boolean clickTin() {
  1418. final RSItem tin = inventory.getItem(tinderboxId);
  1419. if (tin != null && tin.interact("Use"))
  1420. return true;
  1421. return false;
  1422. }
  1423. private boolean clickLog() {
  1424. final RSItem[] logs = inventory.getItems(false);
  1425. RSItem log = null;
  1426. outer: for (final RSItem l : logs) {
  1427. if (l == null)
  1428. continue;
  1429. if (dontClick != null)
  1430. if (l.getComponent().equals(dontClick.getComponent()))
  1431. continue;
  1432. if (!canBurn(l)) {
  1433. inventory.dropItem(l);
  1434. sleep(random(500, 750));
  1435. continue;
  1436. }
  1437. for (int i : logIds) {
  1438. if (l.getID() == i) {
  1439. log = l;
  1440. break outer;
  1441. }
  1442. }
  1443. }
  1444. if (log != null)
  1445. if (log.interact("Use")) {
  1446. if (inventory.getCount(logIds) > 1)
  1447. dontClick = log;
  1448. return true;
  1449. }
  1450. return false;
  1451. }
  1452. private boolean canBurn(final RSItem l) {
  1453. if (l.getID() == yewLogId)
  1454. return fmLvl() >= 60 ? true : false;
  1455. if (l.getID() == willowLogId)
  1456. return fmLvl() >= 30 ? true : false;
  1457. if (l.getID() == oakLogId)
  1458. return fmLvl() >= 15 ? true : false;
  1459. if (l.getID() == regularLogId)
  1460. return fmLvl() >= 1 ? true : false;
  1461. return false;
  1462. }
  1463. /**
  1464. * @return True, if the player is not moving and has no animation.
  1465. */
  1466. private boolean isIdle() {
  1467. return !isAnimated() && !getMyPlayer().isMoving();
  1468. }
  1469. /**
  1470. * @return True, if the local player is animated.
  1471. */
  1472. private boolean isAnimated() {
  1473. return getMyPlayer().getAnimation() != -1;
  1474. }
  1475. private boolean isSelected() {
  1476. final RSItem inv = inventory.getSelectedItem();
  1477. if (inv != null) {
  1478. for (int i : logIds) {
  1479. if (inv.getID() == i)
  1480. return true;
  1481. }
  1482. }
  1483. return false;
  1484. }
  1485. /**
  1486. * @param t
  1487. * @return True if there is a no fire on the tile, otherwise false.
  1488. */
  1489. private boolean isTileFree(final RSTile t) {
  1490. final RSObject[] objs = objects.getAllAt(t);
  1491. for (final RSObject o : objs)
  1492. if (o.getID() == 2732)
  1493. return false;
  1494. return true;
  1495. }
  1496. /**
  1497. * @param r An array of starting tiles.
  1498. * @param p True to use priority, false to use closest method.
  1499. * @return True if a new destination was choosen, false otherwise.
  1500. */
  1501. private boolean findNewTile(final RSTile[] r, final boolean p) {
  1502. if (!p) {
  1503. int dist = 1000000000;
  1504. for (final RSTile t : start)
  1505. if (isTileFree(t))
  1506. if (calc.distanceTo(t) < dist) {
  1507. dest = t;
  1508. dist = calc.distanceTo(t);
  1509. }
  1510. } else
  1511. for (final RSTile t : start)
  1512. if (isTileFree(t)) {
  1513. RSTile alt = start[random(0, start.length)];
  1514. if (t == start[0] && random(0, 5) == 0 && isTileFree(alt)) {
  1515. dest = alt;
  1516. break;
  1517. }
  1518. dest = t;
  1519. }
  1520. if (dest == null)
  1521. return false;
  1522. return true;
  1523. }
  1524. private int walkDest() {
  1525. if (myLocation().equals(dest) && !getMyPlayer().isMoving()) {
  1526. dest = null;
  1527. return 0;
  1528. }
  1529. new Camera(Camera.PITCH);
  1530. final Point p = calc.tileToScreen(dest);
  1531. if (calc.pointOnScreen(p)) {
  1532. mouse.move(p);
  1533. if (inventory.getSelectedItem() == null) {
  1534. tiles.interact(dest, "Walk here");
  1535. chill();
  1536. return 0;
  1537. } else {
  1538. walking.walkTileMM(dest);
  1539. return random(700, 1500);
  1540. }
  1541. }
  1542. webWalk(dest);
  1543. return random(500, 1000);
  1544. }
  1545. private int take(final RSGroundItem g) {
  1546. if (calc.tileOnScreen(g.getLocation())) {
  1547. if (g.interact("Take " + g.getItem().getName()))
  1548. chill();
  1549. } else if (!getMyPlayer().isMoving()) {
  1550. walking.walkTileMM(g.getLocation());
  1551. antiBan();
  1552. return random(500, 2000);
  1553. }
  1554. return 0;
  1555. }
  1556. private int handleCoins() {
  1557. if (!isAnimated() && (bestHatchetAvailable == -1 || bestHatchetAvailable == bronzeHatchetId)) {
  1558. final RSGroundItem coins = groundItems.getNearest(995);
  1559. if (coins != null
  1560. && calc.distanceTo(coins.getLocation()) < 20
  1561. && (inventory.getItem(995) == null || inventory.getItem(995) != null
  1562. && inventory.getItem(995).getStackSize() < 200))
  1563. return take(coins);
  1564. }
  1565. return -1;
  1566. }
  1567. /**
  1568. * @return The highest tier hatchet in the players inventory or bank for the current level.
  1569. */
  1570. private int bestHatchetAvailable() {
  1571. final int wcLvl = wcLvl();
  1572. if (hasRuneHatchet || inventory.contains(runeHatchetId))
  1573. if (wcLvl >= 41)
  1574. return runeHatchetId;
  1575. if (hasAdamantHatchet || inventory.contains(adamantHatchetId))
  1576. if (wcLvl >= 31)
  1577. return adamantHatchetId;
  1578. if (hasMithrilHatchet || inventory.contains(mithrilHatchetId))
  1579. if (wcLvl >= 21)
  1580. return mithrilHatchetId;
  1581. if (hasBlackHatchet || inventory.contains(blackHatchetId))
  1582. if (wcLvl >= 6)
  1583. return blackHatchetId;
  1584. if (hasSteelHatchet || inventory.contains(steelHatchetId))
  1585. if (wcLvl >= 6)
  1586. return steelHatchetId;
  1587. if (hasIronHatchet || inventory.contains(ironHatchetId))
  1588. return ironHatchetId;
  1589. if (hasBronzeHatchet || inventory.contains(bronzeHatchetId))
  1590. return bronzeHatchetId;
  1591. return -1;
  1592. }
  1593. private double getCurrentVersion() {
  1594. try {
  1595. final BufferedReader r = new BufferedReader(new InputStreamReader(new URL(
  1596. "http://pastebin.com/raw.php?i=SePHdUFV").openStream()));
  1597. final double d = Double.parseDouble(r.readLine());
  1598. r.close();
  1599. return d;
  1600. } catch (final Exception e) {
  1601. log.warning("Error checking for latest version.");
  1602. }
  1603. return scriptVersion;
  1604. }
  1605. private void sendToURL(final String url) {
  1606. try {
  1607. java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
  1608. } catch (IOException e) {}
  1609. }
  1610.  
  1611. class InformationLoader extends Thread {
  1612. public static final int VERSION = 0;
  1613. public static final int CHECKGE = 1;
  1614. int i;
  1615. InformationLoader(int i) {
  1616. this.i = i;
  1617. this.start();
  1618. }
  1619. public void run() {
  1620. switch (i) {
  1621. case 0:
  1622. currVer = 0;
  1623. currVer = getCurrentVersion();
  1624. DecimalFormat format = new DecimalFormat("0.00");
  1625. if (scriptVersion >= currVer)
  1626. log(Color.green, "Your version: " + format.format(scriptVersion) + ", Latest version: "
  1627. + format.format(currVer) + ". Your script is up to date.");
  1628. else
  1629. log(Color.red,
  1630. "Your version: " + format.format(scriptVersion) + ", Latest version: "
  1631. + format.format(currVer) + ". You should get the latest version.");
  1632. break;
  1633. case 1:
  1634. checkedGE = true;
  1635. try {
  1636. log("Loading prices from Grand Exchange.");
  1637. oakPrice = grandExchange.lookup("Oak logs").getGuidePrice();
  1638. runeHatchetPrice = grandExchange.lookup("Rune hatchet").getGuidePrice();
  1639. } catch (final Exception e) {
  1640. checkedGE = true;
  1641. log.severe("Could not get Grand Exchange prices.");
  1642. final int sleep = random(60, 300);
  1643. log("Will try again in: " + sleep + " seconds.");
  1644. final long stopTime = System.currentTimeMillis() + sleep * 1000;
  1645. while (System.currentTimeMillis() < stopTime && scriptRunning)
  1646. try {
  1647. sleep(100);
  1648. } catch (final InterruptedException e1) {
  1649. e1.printStackTrace();
  1650. }
  1651. checkedGE = false;
  1652. return;
  1653. }
  1654. if (oakPrice != -1 && runeHatchetPrice != -1)
  1655. log("Rune hatchet price: " + runeHatchetPrice + " gp, " + "Oak price: " + oakPrice + " gp.");
  1656. else {
  1657. oakPrice = 30; // Set lower.
  1658. runeHatchetPrice = 10000; // Set higher.
  1659. }
  1660. break;
  1661. }
  1662. loading = false;
  1663. }
  1664. }
  1665.  
  1666. class Camera extends Thread {
  1667. public static final int ADVANCED = 0;
  1668. public static final int PITCH = 1;
  1669. private RSTile r = null;
  1670. private int antiban = -1;
  1671. private int min = 500;
  1672. private int max = 1500;
  1673. private Camera(final RSObject r) {
  1674. this.r = r.getLocation();
  1675. this.start();
  1676. }
  1677. private Camera(final RSNPC r) {
  1678. this.r = r.getLocation();
  1679. this.start();
  1680. }
  1681. private Camera(final RSTile r) {
  1682. this.r = r;
  1683. this.start();
  1684. }
  1685. private Camera(final int antiban) {
  1686. this.antiban = antiban;
  1687. this.start();
  1688. }
  1689. private Camera(final int min, final int max) {
  1690. antiban = ADVANCED;
  1691. this.min = min;
  1692. this.max = max;
  1693. this.start();
  1694. }
  1695. @Override
  1696. public void run() {
  1697. try {
  1698. if (r != null)
  1699. if (camera.getPitch() < 25 || random(0, 2) == 0 && camera.getPitch() < 60) {
  1700. keyboard.pressKey((char) KeyEvent.VK_UP);
  1701. final Timer t = new Timer(random(500, 1000));
  1702. if (camera.getAngleTo(camera.getTileAngle(r)) > random(45, 70))
  1703. camera.turnTo(r, 30);
  1704. sleep(t.getRemaining());
  1705. keyboard.releaseKey((char) KeyEvent.VK_UP);
  1706. } else
  1707. camera.turnTo(r, 30);
  1708. if (antiban != -1)
  1709. switch (antiban) {
  1710. case ADVANCED:
  1711. advancedCameraMovement(min, max);
  1712. break;
  1713. case PITCH:
  1714. if (camera.getPitch() < random(30, 55)) {
  1715. camera.setPitch(random(70, 100));
  1716. }
  1717. break;
  1718. }
  1719. antiBan = "";
  1720. } catch (final InterruptedException e) {}
  1721. }
  1722. }
  1723.  
  1724. class PaintUpdater extends Thread {
  1725. PaintUpdater() {
  1726. this.start();
  1727. }
  1728. public void run() {
  1729. while (scriptRunning) {
  1730. if (isPaused())
  1731. env.setUserInput(Environment.INPUT_MOUSE | Environment.INPUT_KEYBOARD);
  1732. else
  1733. env.setUserInput(Environment.INPUT_KEYBOARD);
  1734. if (!globeSelected && !locked) {
  1735. final int wc = wcLvl();
  1736. if (trainFM) {
  1737. final int fm = fmLvl();
  1738. if (fm >= 30) {
  1739. willowSelected = true;
  1740. treeSelected = false;
  1741. oakSelected = false;
  1742. } else if (fm >= 15) {
  1743. oakSelected = true;
  1744. treeSelected = false;
  1745. willowSelected = false;
  1746. } else {
  1747. treeSelected = true;
  1748. oakSelected = false;
  1749. willowSelected = false;
  1750. }
  1751. } else if (wc >= 60 && yewAfter60) {
  1752. yewSelected = true;
  1753. treeSelected = false;
  1754. oakSelected = false;
  1755. willowSelected = false;
  1756. } else if (wc >= 30) {
  1757. willowSelected = true;
  1758. treeSelected = false;
  1759. oakSelected = false;
  1760. yewSelected = false;
  1761. } else if (wc >= 15) {
  1762. oakSelected = true;
  1763. treeSelected = false;
  1764. willowSelected = false;
  1765. yewSelected = false;
  1766. } else {
  1767. treeSelected = true;
  1768. oakSelected = false;
  1769. willowSelected = false;
  1770. yewSelected = false;
  1771. }
  1772. }
  1773. try {
  1774. sleep(100);
  1775. } catch (final InterruptedException e) {}
  1776. }
  1777. }
  1778. }
  1779. public void mouseEntered(final MouseEvent e) {}
  1780. public void mouseExited(final MouseEvent e) {}
  1781. public void mouseReleased(final MouseEvent e) {
  1782. if (moving) {
  1783. mp.x = e.getX() - mp.xLoc;
  1784. mp.y = e.getY() - mp.yLoc;
  1785. }
  1786. moving = false;
  1787. }
  1788. public void mouseDragged(final MouseEvent e) {
  1789. if (moving) {
  1790. mp.x = e.getX() - mp.xLoc;
  1791. mp.y = e.getY() - mp.yLoc;
  1792. }
  1793. }
  1794. public void mouseMoved(final MouseEvent e) {
  1795. final Rectangle infoArea = new Rectangle(490, 59, 25, 25);
  1796. final Rectangle clickArea = new Rectangle(240, 150, 50, 50);
  1797. final Rectangle settingsArea = new Rectangle(490, 86, 25, 25);
  1798. final Rectangle fmArea = new Rectangle(490, 32, 25, 25);
  1799. final Rectangle worldArea = new Rectangle(490, 5, 25, 25);
  1800. final Rectangle optionsOpenArea = new Rectangle(285, 0, 205, 110);
  1801. final Rectangle showArea = new Rectangle(mp.x + mp.w - 34, mp.y + mp.h - 19, 34, 19);
  1802. final Point a = e.getPoint();
  1803. if (showArea.contains(a))
  1804. showSelected = true;
  1805. else
  1806. showSelected = false;
  1807. if (mp.moveBox.contains(a))
  1808. paintSelected = true;
  1809. else
  1810. paintSelected = false;
  1811. if (infoArea.contains(a))
  1812. infoSelected = true;
  1813. else
  1814. infoSelected = false;
  1815. if (!playClicked && clickArea.contains(a))
  1816. playSelected = true;
  1817. else
  1818. playSelected = false;
  1819. if (settingsArea.contains(a))
  1820. settingsSelected = true;
  1821. else
  1822. settingsSelected = false;
  1823. if (fmArea.contains(a))
  1824. trainFMHovered = true;
  1825. else
  1826. trainFMHovered = false;
  1827. if (worldArea.contains(a))
  1828. globeSelected = true;
  1829. else if (!optionsOpenArea.contains(a))
  1830. globeSelected = false;
  1831. }
  1832. public void mousePressed(final MouseEvent e) {
  1833. if (!isLoggedIn())
  1834. return;
  1835. final Rectangle showArea = new Rectangle(mp.x + mp.w - 34, mp.y + mp.h - 19, 34, 19);
  1836. final Rectangle fmArea = new Rectangle(490, 32, 25, 25);
  1837. final Rectangle lockArea = new Rectangle(462, 5, 24, 24);
  1838. final Rectangle infoArea = new Rectangle(490, 59, 25, 25);
  1839. final Rectangle settingsArea = new Rectangle(490, 86, 25, 25);
  1840. final Rectangle startArea = new Rectangle(240, 150, 50, 50);
  1841. final Rectangle logArea = new Rectangle(336, 3, 31, 25);
  1842. final Rectangle oakArea = new Rectangle(367, 3, 31, 25);
  1843. final Rectangle willowArea = new Rectangle(398, 3, 31, 25);
  1844. final Rectangle yewArea = new Rectangle(429, 3, 31, 25);
  1845. final Rectangle idx1 = new Rectangle(341, 28, 124, 20);
  1846. final Rectangle idx2 = new Rectangle(341, 48, 124, 20);
  1847. final Rectangle idx3 = new Rectangle(341, 68, 124, 20);
  1848. final Rectangle idx4 = new Rectangle(341, 105 - 17, 124, 20);
  1849. final Rectangle mode1 = new Rectangle(285, 28, 51, 20);
  1850. final Rectangle mode2 = new Rectangle(285, 48, 51, 20);
  1851. final Rectangle mode3 = new Rectangle(285, 68, 51, 20);
  1852. final Rectangle mode4 = new Rectangle(285, 88, 51, 20);
  1853. final Rectangle cutYewArea = new Rectangle(469, 345, 25, 25);
  1854. final Rectangle indHatchet = new Rectangle(469, 395, 25, 25);
  1855. final Rectangle aHatchet = new Rectangle(469, 425, 25, 25);
  1856. final Rectangle checkBankArea = new Rectangle(200, 345, 25, 25);
  1857. final Point a = e.getPoint();
  1858. if (showPaint && mp.moveBox.contains(a) && !showArea.contains(a)) {
  1859. moving = true;
  1860. mp.xLoc = e.getX() - mp.x;
  1861. mp.yLoc = e.getY() - mp.y;
  1862. }
  1863. if (!playClicked) {
  1864. if (indHatchet.contains(a))
  1865. useAvailableHatchetsSelected = false;
  1866. if (aHatchet.contains(a))
  1867. useAvailableHatchetsSelected = true;
  1868. if (cutYewArea.contains(a))
  1869. yewsAfter60Selected = !yewsAfter60Selected;
  1870. if (checkBankArea.contains(a))
  1871. checkBankSelected = !checkBankSelected;
  1872. if (startArea.contains(a)) {
  1873. if (wait) {
  1874. startTime = System.currentTimeMillis();
  1875. screenshotTimer = new Timer(7200000);
  1876. antibanTimer = startTime + random(5000, 10000);
  1877. initialXP = skills.getCurrentExp(Skills.WOODCUTTING);
  1878. initialXP2 = skills.getCurrentExp(Skills.FIREMAKING);
  1879. }
  1880. playClicked = true;
  1881. showSettings = false;
  1882. wait = false;
  1883. showPaint = true;
  1884. useAvailableHatchets = useAvailableHatchetsSelected;
  1885. yewAfter60 = yewsAfter60Selected;
  1886. checkBank = checkBankSelected;
  1887. }
  1888. }
  1889. if (fmArea.contains(a))
  1890. trainFM = !trainFM;
  1891. if (infoArea.contains(a))
  1892. sendToURL("http://goo.gl/WEQX6");
  1893. if (settingsArea.contains(a))
  1894. if (!showSettings) {
  1895. playClicked = false;
  1896. showSettings = true;
  1897. } else
  1898. showSettings = false;
  1899. if (globeSelected) {
  1900. if (lockArea.contains(a))
  1901. locked = !locked;
  1902. if (logArea.contains(a))
  1903. if (!treeSelected) {
  1904. treeSelected = true;
  1905. oakSelected = false;
  1906. willowSelected = false;
  1907. yewSelected = false;
  1908. }
  1909. if (oakArea.contains(a))
  1910. if (!oakSelected) {
  1911. treeSelected = false;
  1912. oakSelected = true;
  1913. willowSelected = false;
  1914. yewSelected = false;
  1915. }
  1916. if (willowArea.contains(a))
  1917. if (!willowSelected) {
  1918. treeSelected = false;
  1919. oakSelected = false;
  1920. willowSelected = true;
  1921. yewSelected = false;
  1922. }
  1923. if (yewArea.contains(a))
  1924. if (!yewSelected) {
  1925. treeSelected = false;
  1926. oakSelected = false;
  1927. willowSelected = false;
  1928. yewSelected = true;
  1929. }
  1930. if (treeSelected) {
  1931. if (idx1.contains(a))
  1932. treeLocation = 1;
  1933. if (mode1.contains(a)) {
  1934. bankTree = false;
  1935. dropTree = false;
  1936. }
  1937. if (mode2.contains(a)) {
  1938. dropTree = true;
  1939. bankTree = false;
  1940. }
  1941. if (mode3.contains(a)) {
  1942. bankTree = true;
  1943. dropTree = false;
  1944. }
  1945. }
  1946. if (oakSelected) {
  1947. if (idx1.contains(a))
  1948. oakLocation = 1;
  1949. if (idx2.contains(a))
  1950. oakLocation = 2;
  1951. if (idx3.contains(a))
  1952. oakLocation = 3;
  1953. if (mode1.contains(a)) {
  1954. bankOak = true;
  1955. dropOak = false;
  1956. powerchopOak = false;
  1957. }
  1958. if (mode2.contains(a)) {
  1959. dropOak = true;
  1960. bankOak = false;
  1961. powerchopOak = false;
  1962. }
  1963. if (mode3.contains(a)) {
  1964. bankOak = false;
  1965. dropOak = false;
  1966. powerchopOak = true;
  1967. }
  1968. }
  1969. if (willowSelected) {
  1970. if (idx1.contains(a))
  1971. willowLocation = 1;
  1972. if (idx2.contains(a))
  1973. willowLocation = 2;
  1974. if (idx3.contains(a))
  1975. willowLocation = 3;
  1976. if (idx4.contains(a))
  1977. willowLocation = 4;
  1978. if (willowLocation == 1 || willowLocation == 2) {
  1979. if (mode1.contains(a)) {
  1980. bankWillow = false;
  1981. dropWillow = false;
  1982. powerchopWillow = false;
  1983. }
  1984. if (mode2.contains(a)) {
  1985. dropWillow = false;
  1986. bankWillow = true;
  1987. powerchopWillow = false;
  1988. }
  1989. if (mode3.contains(a)) {
  1990. bankWillow = false;
  1991. dropWillow = true;
  1992. powerchopWillow = false;
  1993. }
  1994. if (mode4.contains(a)) {
  1995. bankWillow = false;
  1996. dropWillow = false;
  1997. powerchopWillow = true;
  1998. }
  1999. }
  2000. if (willowLocation == 3 || willowLocation == 4) {
  2001. if (mode1.contains(a)) {
  2002. dropWillow = false;
  2003. bankWillow = true;
  2004. powerchopWillow = false;
  2005. }
  2006. if (mode2.contains(a)) {
  2007. bankWillow = false;
  2008. dropWillow = true;
  2009. powerchopWillow = false;
  2010. }
  2011. if (mode3.contains(a)) {
  2012. bankWillow = false;
  2013. dropWillow = false;
  2014. powerchopWillow = true;
  2015. }
  2016. if (!bankWillow && !powerchopWillow && !dropWillow)
  2017. bankWillow = true;
  2018. }
  2019. }
  2020. if (yewSelected) {
  2021. if (idx1.contains(a))
  2022. yewLocation = 1;
  2023. if (idx2.contains(a))
  2024. yewLocation = 2;
  2025. if (idx3.contains(a))
  2026. yewLocation = 3;
  2027. }
  2028. }
  2029. if (showArea.contains(a))
  2030. showPaint = !showPaint;
  2031. }
  2032. @Override
  2033. public void mouseClicked(final MouseEvent e) {}
  2034. @Override
  2035. public void messageReceived(final MessageEvent e) {
  2036. final String m = e.getMessage();
  2037. if (e.getID() == MessageEvent.MESSAGE_ACTION || e.getID() == MessageEvent.MESSAGE_SERVER) {
  2038. if (m.contains("can't light a fire"))
  2039. findNewTile(start, false);
  2040. if (m.contains("the ladder has been completely destroyed"))
  2041. sawLamp = true;
  2042. if (m.contains("You've just advanced") && !m.contains("Firemaking")) {
  2043. clickTree = true;
  2044. }
  2045. }
  2046. }
  2047. final Color colorGreenL = new Color(40, 255, 50, 180); // back
  2048. final Color colorGreenH = new Color(50, 255, 50, 200);
  2049. final Color colorRed = new Color(255, 50, 50, 150); // red
  2050. final Color colorWhiteL = new Color(255, 255, 255, 100); // White
  2051. final Color colorBlack = new Color(0, 0, 0, 200);
  2052. final Color colorShadow = new Color(20, 20, 20, 100);
  2053. final BasicStroke stroke1 = new BasicStroke(1);
  2054. final Font cordia = new Font("CordiaUPC", 0, 24);
  2055. final Font arialS = new Font("Arial", 0, 9);
  2056. final Font arialL = new Font("Arial", 0, 12);
  2057. final Font dotum = new Font("Dotum", 0, 12);
  2058. String dots = "";
  2059. final BufferedImage imgFlameSelected = getImage("flameSelected.png", "http://i.imgur.com/CyNp4.png");
  2060. final BufferedImage imgFlame = getImage("flame.png", "http://i.imgur.com/97RDO.png");
  2061. final BufferedImage imgGlobeSelected = getImage("globeSelected.png", "http://i.imgur.com/KGZjx.png");
  2062. final BufferedImage imgGlobe = getImage("globe.png", "http://i.imgur.com/ETx9r.png");
  2063. final BufferedImage imgInfoSelected = getImage("infoSelected.png", "http://i.imgur.com/6HJoR.png");
  2064. final BufferedImage imgInfo = getImage("info.png", "http://i.imgur.com/hRYtG.png");
  2065. final BufferedImage imgPlaySelected = getImage("playSelected.png", "http://i.imgur.com/Q4Efo.png");
  2066. final BufferedImage imgPlay = getImage("play.png", "http://i.imgur.com/CPp7m.png");
  2067. final BufferedImage imgTickSelected = getImage("tickSelected.png", "http://i.imgur.com/mBUvC.png");
  2068. final BufferedImage imgTick = getImage("tick.png", "http://i.imgur.com/fwlC1.png");
  2069. final BufferedImage imgTickSmall = getImage("tickSmall.png", "http://i.imgur.com/0J7me.png");
  2070. final BufferedImage imgSettingsSelected = getImage("settingsSelected.png", "http://i.imgur.com/ZErbl.png");
  2071. final BufferedImage imgSettings = getImage("settings.png", "http://i.imgur.com/fFnrl.png");
  2072. final BufferedImage imgCursor = getImage("cursor.png", "http://i.imgur.com/OLnoP.png");
  2073. final BufferedImage imgCursorSelected = getImage("cursorSelected.png", "http://i.imgur.com/GpbLy.png");
  2074. final BufferedImage imgLockOpen = getImage("lockOpen.png", "http://i.imgur.com/Wn8M8.png");
  2075. final BufferedImage imgLockClosed = getImage("lockClosed.png", "http://i.imgur.com/W4EhD.png");
  2076. final BufferedImage optionsBackground = getImage("optionsBackground.png", "http://i.imgur.com/3L58P.png");
  2077. boolean paintSelected = false;
  2078. boolean showSelected = false;
  2079. boolean treeSelected = true;
  2080. boolean oakSelected = false;
  2081. boolean willowSelected = false;
  2082. boolean yewSelected = false;
  2083. boolean globeSelected = false;
  2084. boolean infoSelected = false;
  2085. boolean playSelected = false;
  2086. boolean playClicked = false;
  2087. boolean settingsSelected = false;
  2088. boolean showSettings = true;
  2089. boolean locked = false;
  2090. boolean checkBankSelected = false;
  2091. boolean yewsAfter60Selected = false;
  2092. boolean useAvailableHatchetsSelected = false;
  2093. int treeLocation = 1;
  2094. int oakLocation = 1;
  2095. int willowLocation = 1;
  2096. int yewLocation = 1;
  2097. long hours = 0;
  2098. long minutes = 0;
  2099. long seconds = 0;
  2100. public void onRepaint(final Graphics g1) {
  2101. final Graphics2D g = (Graphics2D) g1;
  2102. g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  2103. long millis = System.currentTimeMillis() - startTime;
  2104. hours = millis / (1000 * 60 * 60);
  2105. millis -= hours * (1000 * 60 * 60);
  2106. minutes = millis / (1000 * 60);
  2107. millis -= minutes * (1000 * 60);
  2108. seconds = millis / 1000;
  2109. if (isLoggedIn()) {
  2110. if (globeSelected) {
  2111. if (treeSelected) {
  2112. g.setColor(colorBlack); // Largest box
  2113. g.fillRect(336, 3, 124, 25 + 20 * 1);
  2114. g.setColor(Color.BLACK);
  2115. g.drawRect(336, 3, 124, 25 + 20 * 1);
  2116. g.setColor(colorBlack); // Thin middle box
  2117. g.fillRect(460, 3, 27, 25 + 20 * 1);
  2118. g.setColor(Color.BLACK);
  2119. g.drawRect(460, 3, 27, 25 + 20 * 1);
  2120. g.drawImage(imgTickSmall, 466, 32 + 20 * (treeLocation - 1), null); // Tick
  2121. g.setColor(colorGreenH);
  2122. g.setFont(dotum);
  2123. g.drawString("Lumbridge", 341, 44);
  2124. }
  2125. if (oakSelected) {
  2126. g.setColor(colorBlack); // Largest box
  2127. g.fillRect(336, 3, 124, 25 + 20 * 3);
  2128. g.setColor(Color.BLACK);
  2129. g.drawRect(336, 3, 124, 25 + 20 * 3);
  2130. g.setColor(colorBlack); // Thin middle box
  2131. g.fillRect(460, 3, 27, 25 + 20 * 3);
  2132. g.setColor(Color.BLACK);
  2133. g.drawRect(460, 3, 27, 25 + 20 * 3);
  2134. g.drawImage(imgTickSmall, 466, 32 + 20 * (oakLocation - 1), null); // Tick
  2135. g.setColor(colorGreenH);
  2136. g.setFont(dotum);
  2137. g.drawString("North East Draynor", 341, 44);
  2138. g.drawString("East Draynor", 341, 64);
  2139. g.drawString("North Draynor", 341, 84);
  2140. }
  2141. if (willowSelected) {
  2142. g.setColor(colorBlack); // Largest box
  2143. g.fillRect(336, 3, 124, 25 + 20 * 4);
  2144. g.setColor(Color.BLACK);
  2145. g.drawRect(336, 3, 124, 25 + 20 * 4);
  2146. g.setColor(colorBlack); // Thin middle box
  2147. g.fillRect(460, 3, 27, 25 + 20 * 4);
  2148. g.setColor(Color.BLACK);
  2149. g.drawRect(460, 3, 27, 25 + 20 * 4);
  2150. g.drawImage(imgTickSmall, 466, 32 + 20 * (willowLocation - 1), null); // Tick
  2151. g.setColor(colorGreenH);
  2152. g.setFont(dotum);
  2153. g.drawString("Rimmington", 341, 44);
  2154. g.drawString("Lumbridge", 341, 64);
  2155. g.drawString("Port Sarim", 341, 84);
  2156. g.drawString("Draynor", 341, 104);
  2157. }
  2158. if (yewSelected) {
  2159. g.setColor(colorBlack); // Largest box
  2160. g.fillRect(336, 3, 124, 25 + 20 * 3);
  2161. g.setColor(Color.BLACK);
  2162. g.drawRect(336, 3, 124, 25 + 20 * 3);
  2163. g.setColor(colorBlack); // Thin middle box
  2164. g.fillRect(460, 3, 27, 25 + 20 * 3);
  2165. g.setColor(Color.BLACK);
  2166. g.drawRect(460, 3, 27, 25 + 20 * 3);
  2167. g.drawImage(imgTickSmall, 466, 32 + 20 * (yewLocation - 1), null); // Tick
  2168. g.setColor(colorGreenH);
  2169. g.setFont(dotum);
  2170. g.drawString("Rimmington", 341, 44);
  2171. g.drawString("Lumbridge", 341, 64);
  2172. g.drawString("Port Sarim", 341, 84);
  2173. }
  2174. if (treeSelected) {
  2175. g.setColor(colorGreenH);
  2176. g.setFont(arialS);
  2177. g.drawString("Tree", 342, 21);
  2178. if (treeLocation == 1) {
  2179. g.setColor(colorBlack);
  2180. g.fillRect(285, 28, 51, 60);
  2181. g.setColor(Color.BLACK);
  2182. g.drawRect(285, 28, 51, 60);
  2183. if (bankTree)
  2184. g.setColor(colorGreenH);
  2185. else
  2186. g.setColor(Color.WHITE);
  2187. g.drawString("Deposit", 290, 81);
  2188. if (dropTree)
  2189. g.setColor(colorGreenH);
  2190. else
  2191. g.setColor(Color.WHITE);
  2192. g.drawString("Drop", 290, 61);
  2193. if (!bankTree && !dropTree)
  2194. g.setColor(colorGreenH);
  2195. else
  2196. g.setColor(Color.WHITE);
  2197. g.drawString("Sell", 290, 41);
  2198. }
  2199. } else {
  2200. g.setFont(arialS);
  2201. g.setColor(Color.WHITE);
  2202. g.drawString("Tree", 342, 21);
  2203. }
  2204. if (oakSelected) {
  2205. g.setColor(colorGreenH);
  2206. g.setFont(arialS);
  2207. g.drawString("Oak", 374, 21);
  2208. if (oakLocation == 1) { // All modes for oaks are the same.
  2209. g.setColor(colorBlack);
  2210. g.fillRect(285, 28, 51, 60);
  2211. g.setColor(Color.BLACK);
  2212. g.drawRect(285, 28, 51, 60);
  2213. g.setColor(Color.WHITE);
  2214. if (bankOak || !dropOak && !powerchopOak)
  2215. g.setColor(colorGreenH);
  2216. else
  2217. g.setColor(Color.WHITE);
  2218. g.drawString("Deposit", 290, 41);
  2219. if (dropOak)
  2220. g.setColor(colorGreenH);
  2221. else
  2222. g.setColor(Color.WHITE);
  2223. g.drawString("Drop", 290, 61);
  2224. if (powerchopOak)
  2225. g.setColor(colorGreenH);
  2226. else
  2227. g.setColor(Color.WHITE);
  2228. g.drawString("Powerchop", 290, 81);
  2229. }
  2230. if (oakLocation == 2) {
  2231. g.setColor(colorBlack);
  2232. g.fillRect(285, 28, 51, 60);
  2233. g.setColor(Color.BLACK);
  2234. g.drawRect(285, 28, 51, 60);
  2235. if (bankOak || !dropOak && !powerchopOak)
  2236. g.setColor(colorGreenH);
  2237. else
  2238. g.setColor(Color.WHITE);
  2239. g.drawString("Deposit", 290, 41);
  2240. if (dropOak)
  2241. g.setColor(colorGreenH);
  2242. else
  2243. g.setColor(Color.WHITE);
  2244. g.drawString("Drop", 290, 61);
  2245. if (powerchopOak)
  2246. g.setColor(colorGreenH);
  2247. else
  2248. g.setColor(Color.WHITE);
  2249. g.drawString("Powerchop", 290, 81);
  2250. }
  2251. if (oakLocation == 3) {
  2252. g.setColor(colorBlack);
  2253. g.fillRect(285, 28, 51, 60);
  2254. g.setColor(Color.BLACK);
  2255. g.drawRect(285, 28, 51, 60);
  2256. if (bankOak || !dropOak && !powerchopOak)
  2257. g.setColor(colorGreenH);
  2258. else
  2259. g.setColor(Color.WHITE);
  2260. g.drawString("Deposit", 290, 41);
  2261. if (dropOak)
  2262. g.setColor(colorGreenH);
  2263. else
  2264. g.setColor(Color.WHITE);
  2265. g.drawString("Drop", 290, 61);
  2266. if (powerchopOak)
  2267. g.setColor(colorGreenH);
  2268. else
  2269. g.setColor(Color.WHITE);
  2270. g.drawString("Powerchop", 290, 81);
  2271. }
  2272. } else {
  2273. g.setColor(Color.WHITE);
  2274. g.setFont(arialS);
  2275. g.drawString("Oak", 374, 21);
  2276. }
  2277. if (willowSelected) {
  2278. g.setColor(colorGreenH);
  2279. g.setFont(arialS);
  2280. g.drawString("Willow", 401, 21);
  2281. if (willowLocation == 1) {
  2282. g.setColor(colorBlack);
  2283. g.fillRect(285, 28, 51, 80);
  2284. g.setColor(Color.BLACK);
  2285. g.drawRect(285, 28, 51, 80);
  2286. if (!bankWillow && !dropWillow && !powerchopWillow)
  2287. g.setColor(colorGreenH);
  2288. else
  2289. g.setColor(Color.WHITE);
  2290. g.drawString("Sell", 290, 41);
  2291. if (bankWillow)
  2292. g.setColor(colorGreenH);
  2293. else
  2294. g.setColor(Color.WHITE);
  2295. g.drawString("Deposit", 290, 61);
  2296. if (dropWillow)
  2297. g.setColor(colorGreenH);
  2298. else
  2299. g.setColor(Color.WHITE);
  2300. g.drawString("Drop", 290, 81);
  2301. if (powerchopWillow)
  2302. g.setColor(colorGreenH);
  2303. else
  2304. g.setColor(Color.WHITE);
  2305. g.drawString("Powerchop", 290, 101);
  2306. }
  2307. if (willowLocation == 2) {
  2308. g.setColor(colorBlack);
  2309. g.fillRect(285, 28, 51, 80);
  2310. g.setColor(Color.BLACK);
  2311. g.drawRect(285, 28, 51, 80);
  2312. if (!bankWillow && !dropWillow && !powerchopWillow)
  2313. g.setColor(colorGreenH);
  2314. else
  2315. g.setColor(Color.WHITE);
  2316. g.drawString("Sell", 290, 41);
  2317. if (bankWillow)
  2318. g.setColor(colorGreenH);
  2319. else
  2320. g.setColor(Color.WHITE);
  2321. g.drawString("Deposit", 290, 61);
  2322. if (dropWillow)
  2323. g.setColor(colorGreenH);
  2324. else
  2325. g.setColor(Color.WHITE);
  2326. g.drawString("Drop", 290, 81);
  2327. if (powerchopWillow)
  2328. g.setColor(colorGreenH);
  2329. else
  2330. g.setColor(Color.WHITE);
  2331. g.drawString("Powerchop", 290, 101);
  2332. }
  2333. if (willowLocation == 3) {
  2334. g.setColor(colorBlack);
  2335. g.fillRect(285, 28, 51, 60);
  2336. g.setColor(Color.BLACK);
  2337. g.drawRect(285, 28, 51, 60);
  2338. if (bankWillow)
  2339. g.setColor(colorGreenH);
  2340. else
  2341. g.setColor(Color.WHITE);
  2342. g.drawString("Deposit", 290, 41);
  2343. if (dropWillow)
  2344. g.setColor(colorGreenH);
  2345. else
  2346. g.setColor(Color.WHITE);
  2347. g.drawString("Drop", 290, 61);
  2348. if (powerchopWillow)
  2349. g.setColor(colorGreenH);
  2350. else
  2351. g.setColor(Color.WHITE);
  2352. g.drawString("Powerchop", 290, 81);
  2353. }
  2354. if (willowLocation == 4) {
  2355. g.setColor(colorBlack);
  2356. g.fillRect(285, 28, 51, 60);
  2357. g.setColor(Color.BLACK);
  2358. g.drawRect(285, 28, 51, 60);
  2359. if (bankWillow)
  2360. g.setColor(colorGreenH);
  2361. else
  2362. g.setColor(Color.WHITE);
  2363. g.drawString("Deposit", 290, 41);
  2364. if (dropWillow)
  2365. g.setColor(colorGreenH);
  2366. else
  2367. g.setColor(Color.WHITE);
  2368. g.drawString("Drop", 290, 61);
  2369. if (powerchopWillow)
  2370. g.setColor(colorGreenH);
  2371. else
  2372. g.setColor(Color.WHITE);
  2373. g.drawString("Powerchop", 290, 81);
  2374. }
  2375. } else {
  2376. g.setColor(Color.WHITE);
  2377. g.setFont(arialS);
  2378. g.drawString("Willow", 401, 21);
  2379. }
  2380. if (yewSelected) {
  2381. g.setColor(colorGreenH);
  2382. g.setFont(arialS);
  2383. g.drawString("Yew", 435, 21);
  2384. g.setColor(colorBlack);
  2385. g.fillRect(285, 28, 51, 20);
  2386. g.setColor(colorBlack);
  2387. g.drawRect(285, 28, 51, 20);
  2388. if (yewLocation == 1) { // All yew modes are the same.
  2389. g.setColor(colorGreenH);
  2390. g.drawString("Deposit", 290, 41);
  2391. }
  2392. if (yewLocation == 2) {
  2393. g.setColor(colorGreenH);
  2394. g.drawString("Deposit", 290, 41);
  2395. }
  2396. if (yewLocation == 3) {
  2397. g.setColor(colorGreenH);
  2398. g.drawString("Deposit", 290, 41);
  2399. }
  2400. } else {
  2401. g.setColor(Color.WHITE);
  2402. g.setFont(arialS);
  2403. g.drawString("Yew", 435, 21);
  2404. }
  2405. g.setColor(Color.BLACK);
  2406. g.drawRect(285, 3, 51, 25);
  2407. g.setColor(colorBlack);
  2408. g.fillRect(285, 3, 51, 25);
  2409. g.setColor(Color.WHITE);
  2410. g.drawString("MODE", 290, 21);
  2411. g.setColor(Color.BLACK);
  2412. g.drawRect(336, 3, 31, 25);
  2413. g.setColor(Color.BLACK);
  2414. g.drawRect(367, 3, 31, 25);
  2415. g.setColor(Color.BLACK);
  2416. g.drawRect(398, 3, 31, 25);
  2417. g.setColor(Color.BLACK);
  2418. g.drawRect(429, 3, 31, 25);
  2419. g.setFont(arialS);
  2420. }
  2421. if (globeSelected) {
  2422. g.drawImage(imgGlobeSelected, 490, 5, null); // Globe
  2423. if (!locked)
  2424. g.drawImage(imgLockOpen, 462, 5, null);
  2425. else
  2426. g.drawImage(imgLockClosed, 462, 5, null);
  2427. } else
  2428. g.drawImage(imgGlobe, 490, 5, null);
  2429. if (trainFM || trainFMHovered)
  2430. g.drawImage(imgFlameSelected, 490, 32, null); // Flame
  2431. else
  2432. g.drawImage(imgFlame, 490, 32, null);
  2433. if (infoSelected)
  2434. g.drawImage(imgInfoSelected, 490, 59, null);
  2435. else
  2436. g.drawImage(imgInfo, 490, 59, null);
  2437. if (settingsSelected)
  2438. g.drawImage(imgSettingsSelected, 490, 86, null);
  2439. else
  2440. g.drawImage(imgSettings, 490, 86, null);
  2441. if (!playClicked) {
  2442. if (showSettings) {
  2443. g.drawImage(optionsBackground, 0, 338, null);
  2444. g.setFont(dotum);
  2445. g.setColor(Color.BLACK);
  2446. g.drawString("Cut Yews after 60 WC.", 338, 362);
  2447. if (yewsAfter60Selected)
  2448. g.drawImage(imgTickSelected, 469, 345, null);
  2449. else
  2450. g.drawImage(imgTick, 469, 345, null);
  2451. g.drawString("Buy my own hatchets.", 341, 412);
  2452. g.drawString("Use hatchets in bank or inventory.", 273, 442);
  2453. if (useAvailableHatchetsSelected) {
  2454. g.drawImage(imgTickSelected, 469, 425, null);
  2455. g.drawImage(imgTick, 469, 395, null);
  2456. } else {
  2457. g.drawImage(imgTickSelected, 469, 395, null);
  2458. g.drawImage(imgTick, 469, 425, null);
  2459. }
  2460. g.drawString("Force one bank.", 10, 362);
  2461. if (checkBankSelected)
  2462. g.drawImage(imgTickSelected, 200, 345, null);
  2463. else
  2464. g.drawImage(imgTick, 200, 345, null);
  2465. }
  2466. if (playSelected)
  2467. g.drawImage(imgPlaySelected, 240, 150, null);
  2468. else
  2469. g.drawImage(imgPlay, 240, 150, null);
  2470. }
  2471. mp.drawPaint(g);
  2472. }
  2473. if (playClicked)
  2474. drawMouse(g);
  2475. }
  2476.  
  2477. class Paint {
  2478. long start;
  2479. int x = 550;
  2480. int y = 327;
  2481. int w = 176 + 10;
  2482. int h = 111 + 15; // TODO
  2483. int xLoc = x;
  2484. int yLoc = y;
  2485. Rectangle moveBox = new Rectangle(x, y, 176, 96);
  2486. public void drawPaint(Graphics g1) {
  2487. if (mp.x < 0)
  2488. mp.x = 0;
  2489. if (mp.y < 0)
  2490. mp.y = 0;
  2491. if (mp.x > 764 - w)
  2492. mp.x = 764 - w;
  2493. if (mp.y > 502 - h)
  2494. mp.y = 502 - h;
  2495. moveBox = new Rectangle(x, y, 176, 96);
  2496. final Graphics2D g = (Graphics2D) g1;
  2497. if (showPaint) {
  2498. g.setColor(colorGreenL);
  2499. g.fillRect(x, y, w, h); // Green back
  2500. g.setColor(Color.BLACK);
  2501. g.setStroke(stroke1);
  2502. g.drawRect(x, y, w, h);
  2503. g.setColor(colorRed); // Red bar
  2504. g.fillRect(x, y - 21, w, 18);
  2505. g.setColor(Color.BLACK);
  2506. g.drawRect(x, y - 21, w, 18);
  2507. g.setColor(colorGreenH); // Green bar
  2508. g.fillRect(x + 2, y - 19 + 1, skills.getPercentToNextLevel(Skills.WOODCUTTING) * (w - 1) / 100, 15 - 2);
  2509. g.setColor(colorWhiteL); // White bar
  2510. g.fillRect(x + 1, y - 12, w - 1, 9);
  2511. g.setFont(arialL);
  2512. g.setColor(Color.BLACK);
  2513. drawCenteredString(Integer.toString(wcLvl()) + " WC", x, y - 20, w, 18, g);
  2514. if (trainFM) {
  2515. g.setColor(colorGreenL);
  2516. g.fillRect(x, y - 73, w, 49); // Green back
  2517. g.setColor(Color.BLACK);
  2518. g.setStroke(stroke1);
  2519. g.drawRect(x, y - 73, w, 49);
  2520. g.setColor(colorRed); // Red bar
  2521. g.fillRect(x, y - 94, w, 18);
  2522. g.setColor(Color.BLACK);
  2523. g.drawRect(x, y - 94, w, 18);
  2524. g.setColor(colorGreenH); // Green bar
  2525. g.fillRect(x + 2, y - 91, skills.getPercentToNextLevel(Skills.FIREMAKING) * (w - 1) / 100, 13);
  2526. g.setColor(colorWhiteL); // White bar
  2527. g.fillRect(x + 1, y - 85, w - 1, 9);
  2528. g.setFont(arialL);
  2529. g.setColor(Color.BLACK);
  2530. drawCenteredString(Integer.toString(fmLvl()) + " FM", x, y - 76 - 17, w, 18, g);
  2531. g.drawString(fmLvl() - initialLevel2 + " levels, "
  2532. + (skills.getCurrentExp(Skills.FIREMAKING) - initialXP2) + " xp", x + 5, y - 42 - 17);
  2533. g.drawString(
  2534. (double) Math.round((skills.getCurrentExp(Skills.FIREMAKING) - initialXP2) * 3600D
  2535. / (System.currentTimeMillis() - startTime) * 10)
  2536. / 10
  2537. + "k xp/hr "
  2538. + (double) Math.round((skills.getCurrentExp(Skills.FIREMAKING)
  2539. + skills.getCurrentExp(Skills.WOODCUTTING) - initialXP - initialXP2)
  2540. * 3600D / (System.currentTimeMillis() - startTime) * 10) / 10 + "k total xp/hr",
  2541. x + 5, y - 27 - 17);
  2542. double ttlFm = Math.round((double) (skills.getExpToNextLevel(Skills.FIREMAKING))
  2543. / (double) (skills.getCurrentExp(Skills.FIREMAKING) - initialXP2)
  2544. * (double) (System.currentTimeMillis() - startTime) / 36000) / 10d;
  2545. if (ttlFm > 1000)
  2546. ttlFm = 0;
  2547. g.drawString(ttlFm + " hours until " + (fmLvl() + 1) + " fm.", x + 5, y - 27 - 2);
  2548. if (burnLogs) {
  2549. g.setColor(Color.WHITE);
  2550. long timeRemaining = timer2 - System.currentTimeMillis();
  2551. if (timeRemaining >= 0)
  2552. g.drawString(Long.toString(timeRemaining), 255, 180);
  2553. }
  2554. }
  2555. g.setFont(cordia);
  2556. if (paintSelected) {
  2557. g.setColor(colorShadow);
  2558. g.drawString("Dynamic Woodcutter", x + 5, y + 17);
  2559. }
  2560. g.setColor(Color.BLACK);
  2561. g.drawString("Dynamic Woodcutter", x + 6, y + 18);
  2562. g.setFont(arialS);
  2563. g.setColor(Color.BLACK);
  2564. g.drawString("v" + scriptVersion, x + 156, y + 18);
  2565. g.setFont(arialL); // General text
  2566. if (status != null && !status.contains("unavailable"))
  2567. g.drawString("Status: " + status, x + 5, y + 33);
  2568. else {
  2569. g.setColor(Color.RED);
  2570. g.drawString("Status: " + status, x + 5, y + 33);
  2571. g.setColor(Color.BLACK);
  2572. }
  2573. DecimalFormat a = new DecimalFormat("00");
  2574. g.drawString("Time: " + a.format(hours) + ":" + a.format(minutes) + ":" + a.format(seconds), x + 5,
  2575. y + 48);
  2576. if (totalCash > 1000000)
  2577. g.drawString("Available wealth: " + Double.toString(Math.round(totalCash / 100000) / 10d) + "m",
  2578. x + 5, y + 63);
  2579. else if (totalCash > 1000)
  2580. g.drawString("Available wealth: " + Double.toString(Math.round(totalCash / 100) / 10d) + "k",
  2581. x + 5, y + 63);
  2582. else
  2583. g.drawString("Available wealth: " + Integer.toString(totalCash), x + 5, y + 63);
  2584. g.drawString(wcLvl() - initialLevel + " levels and "
  2585. + (skills.getCurrentExp(Skills.WOODCUTTING) - initialXP) + " xp gained.", x + 5, y + 78);
  2586. double ttlWc = Math.round((double) (skills.getExpToNextLevel(Skills.WOODCUTTING))
  2587. / (double) (skills.getCurrentExp(Skills.WOODCUTTING) - initialXP)
  2588. * (double) (System.currentTimeMillis() - startTime) / 36000) / 10d;
  2589. if (ttlWc > 1000) {
  2590. ttlWc = 0;
  2591. }
  2592. g.drawString(
  2593. (double) Math.round((skills.getCurrentExp(Skills.WOODCUTTING) - initialXP) * 3600D
  2594. / (System.currentTimeMillis() - startTime) * 10)
  2595. / 10 + "k exp/hour.", x + 5, y + 93);
  2596. g.drawString(ttlWc + " hours until " + (wcLvl() + 1) + " wc.", x + 5, y + 108);
  2597. if (antiBan.length() > 0) {
  2598. g.setFont(arialS);
  2599. g.setColor(colorWhiteL);
  2600. g.fillRect(100, 323, g.getFontMetrics().stringWidth("Antiban: " + antiBan) + 3, 15);
  2601. g.setColor(Color.BLACK);
  2602. g.drawRect(100, 323, g.getFontMetrics().stringWidth("Antiban: " + antiBan) + 3, 15);
  2603. g.drawString("Antiban: " + antiBan, 102, 333);
  2604. }
  2605. g.setFont(arialL); // Hide button
  2606. g.drawRect(x + w - 34, y + h - 19, 34, 19);
  2607. if (showSelected) {
  2608. g.setColor(colorShadow);
  2609. g.drawString("Hide", x + w - 30, y + h - 5);
  2610. }
  2611. g.setColor(Color.BLACK);
  2612. g.drawString("Hide", x + w - 29, y + h - 4);
  2613. } else {
  2614. g.setColor(colorGreenL); // Show button
  2615. g.fillRect(x + w - 34, y + h + -19, 34, 19);
  2616. g.setColor(Color.BLACK);
  2617. g.drawRect(x + w - 34, y + h - 19, 34, 19);
  2618. g.setFont(arialL);
  2619. if (showSelected) {
  2620. g.setColor(colorShadow);
  2621. g.drawString("Show", x + w - 33, y + h - 5);
  2622. }
  2623. g.setColor(Color.BLACK);
  2624. g.drawString("Show", x + w - 32, y + h - 4);
  2625. }
  2626. }
  2627. public void drawCenteredString(String s, int x, int y, int w, int h, Graphics g) {
  2628. FontMetrics fm = g.getFontMetrics();
  2629. int xx = x + (w - fm.stringWidth(s)) / 2;
  2630. int yy = y + (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
  2631. g.drawString(s, xx, yy);
  2632. }
  2633. }
  2634. private void drawMouse(final Graphics2D g) {
  2635. g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  2636. final Point p = mouse.getLocation();
  2637. while (!mousePath.isEmpty() && mousePath.peek().isUp())
  2638. mousePath.remove();
  2639. final MousePathPoint mpp = new MousePathPoint(p.x, p.y, 1000); // 1000 = lasting time/MS
  2640. if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
  2641. mousePath.add(mpp);
  2642. MousePathPoint lastPoint = null;
  2643. for (final MousePathPoint a : mousePath) {
  2644. if (lastPoint != null) {
  2645. g.setColor(a.getColor());
  2646. g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
  2647. }
  2648. lastPoint = a;
  2649. }
  2650. final long mpt = System.currentTimeMillis() - mouse.getPressTime();
  2651. if (mpt < 100 || mouse.isPressed()) {
  2652. clickTimer = System.currentTimeMillis();
  2653. g.drawImage(imgCursorSelected, p.x, p.y, null);
  2654. } else {
  2655. final double fadeTime = 800;
  2656. final double timeDiff = fadeTime - (System.currentTimeMillis() - clickTimer);
  2657. final float alpha = (float) (timeDiff / fadeTime);
  2658. g.drawImage(imgCursor, p.x, p.y, null);
  2659. if (timeDiff <= fadeTime && timeDiff >= 0) { // alpha value [0.0, 1.0]
  2660. g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
  2661. g.drawImage(imgCursorSelected, p.x, p.y, null);
  2662. }
  2663. }
  2664. }
  2665. private final LinkedList<MousePathPoint> mousePath = new LinkedList<MousePathPoint>();
  2666.  
  2667. @SuppressWarnings("serial")
  2668. private class MousePathPoint extends Point { // Enfilade.
  2669. private final long finishTime;
  2670. private final double lastingTime;
  2671. private int toColor(final double d) {
  2672. return Math.min(255, Math.max(0, (int) d));
  2673. }
  2674. public MousePathPoint(final int x, final int y, final int lastingTime) {
  2675. super(x, y);
  2676. this.lastingTime = lastingTime;
  2677. finishTime = System.currentTimeMillis() + lastingTime;
  2678. }
  2679. public boolean isUp() {
  2680. return System.currentTimeMillis() > finishTime;
  2681. }
  2682. public Color getColor() {
  2683. return new Color(0, 100, 255, toColor(256 * ((finishTime - System.currentTimeMillis()) / lastingTime)));
  2684. }
  2685. }
  2686. int logCount = 0;
  2687. RSItem invLog;
  2688. boolean yewAfter60 = false;
  2689. boolean clickTree = false;
  2690. boolean powerchop = false;
  2691. boolean drop = false;
  2692. boolean dropTree = false;
  2693. boolean bankTree = false;
  2694. boolean bankOak = false;
  2695. boolean dropOak = false;
  2696. boolean powerchopOak = false;
  2697. boolean bankWillow = false;
  2698. boolean dropWillow = false;
  2699. boolean powerchopWillow = false;
  2700. boolean useAvailableHatchets = false;
  2701. boolean checkedBank = false;
  2702. boolean hasBronzeHatchet = false;
  2703. boolean hasIronHatchet = false;
  2704. boolean hasSteelHatchet = false;
  2705. boolean hasBlackHatchet = false;
  2706. boolean hasMithrilHatchet = false;
  2707. boolean hasAdamantHatchet = false;
  2708. boolean hasRuneHatchet = false;
  2709. int bestHatchetAvailable = -1;
  2710. public final int CLERKS = 2593; // 2241, 2240, 2593, 1419
  2711. public final int BANKERS = 3416; // 3293, 3416, 2718, 3418
  2712. public final int GE_INTERFACE = 105;
  2713. public final int GE_CLOSE = 14;
  2714. public final int SEARCH = 389;
  2715. public final int COLLECT_INTERFACE = 109;
  2716. public int SLOT = 0;
  2717. private final Pattern PATTERN = Pattern.compile("(?i)<td><img src=\".+obj_sprite\\.gif\\?id=(\\d+)\" alt=\"(.+)\"");
  2718. private final String HOST = "http://services.runescape.com";
  2719. private final String GET = "/m=itemdb_rs/viewitem.ws?obj=";
  2720. /**
  2721. * Buys items from the Grand Exchange if it's open
  2722. * @param itemName item to buy
  2723. * @param slotNumber slot number to buy from (1-5)
  2724. * @param quantity amount to buy
  2725. * @param price Price to buy from. 0 will leave it as default price
  2726. * @return <tt>true</tt> if bought successfully; otherwise <tt>false</tt>
  2727. */
  2728. public boolean buy(String itemName, final int slotNumber, final int quantity, final int price) {
  2729. SLOT = slotNumber;
  2730. itemName = itemName.substring(0, 1).toUpperCase() + itemName.substring(1).toLowerCase();
  2731. final String Sep[] = itemName.split(" ");
  2732. String searchName = null;
  2733. for (int i = 0; i < Sep.length;) {
  2734. if (!Sep[i].contains("("))
  2735. if (searchName == null)
  2736. searchName = Sep[i].toLowerCase(Locale.ENGLISH);
  2737. else
  2738. searchName += " " + Sep[i].toLowerCase(Locale.ENGLISH);
  2739. i++;
  2740. }
  2741. if (slotNumber == 0 || slotNumber > 5)
  2742. return false;
  2743. if (isOpen()) {
  2744. final GEBuyMethods t = new GEBuy(slotNumber);
  2745. final int buyClick = t.getBuyClick();
  2746. if (!isSearching()) {
  2747. interfaces.getComponent(GE_INTERFACE, buyClick).doClick();
  2748. sleep(random(1500, 2000));
  2749. }
  2750. if (isSearching() && !hasSearched(searchName)) {
  2751. keyboard.sendText(searchName, true);
  2752. sleep(random(1000, 1500));
  2753. }
  2754. if (isSearching() && hasSearched(searchName)) {
  2755. boolean foundItem = false;
  2756. if (findItem() && !foundItem) {
  2757. boolean done = false;
  2758. int index = 0;
  2759. if (!done)
  2760. for (int i = 0; interfaces.getComponent(389, 4).getComponent(i) != null;) {
  2761. if (interfaces.getComponent(389, 4).getComponent(i).getText().equals(itemName))
  2762. index = i;
  2763. i++;
  2764. if (interfaces.getComponent(389, 4).getComponent(i + 1) == null)
  2765. done = true;
  2766. }
  2767. if (done && index == 0)
  2768. return false;
  2769. if (done && index > 0) {
  2770. if (!interfaces.getComponent(389, 4).getComponent(index).isValid()
  2771. && interfaces.getComponent(389, 8).getComponent(5).isValid()) {
  2772. interfaces.getComponent(389, 8).getComponent(5).doClick();
  2773. sleep(random(200, 500));
  2774. }
  2775. if (interfaces.getComponent(389, 4).getComponent(index).isValid()) {
  2776. interfaces.getComponent(389, 4).getComponent(index).doClick();
  2777. sleep(random(700, 900));
  2778. foundItem = true;
  2779. }
  2780. }
  2781. }
  2782. if (foundItem) {
  2783. boolean changeQuantity = true;
  2784. boolean changePrice;
  2785. changePrice = price > 1;
  2786. int times = 0;
  2787. while (changeQuantity) {
  2788. if (times >= 3) {
  2789. close();
  2790. return false;
  2791. }
  2792. if (isOpen()) {
  2793. if (interfaces.getComponent(GE_INTERFACE, 148).getText() != null
  2794. && interfaces.getComponent(GE_INTERFACE, 148).getText().contains(
  2795. "" + formatNumb(quantity))) {
  2796. changeQuantity = false;
  2797. break;
  2798. }
  2799. if (interfaces.getComponent(GE_INTERFACE, 168).getText() != null
  2800. && interfaces.getComponent(GE_INTERFACE, 168).getText().contains("...")) {
  2801. interfaces.getComponent(GE_INTERFACE, 168).doClick();
  2802. sleep(random(1000, 1200));
  2803. }
  2804. if (interfaces.getComponent(752, 4).getText().contains("you wish to purchase"))
  2805. keyboard.sendText("" + quantity, true);
  2806. sleep(random(1000, 2000));
  2807. if (interfaces.getComponent(GE_INTERFACE, 148).getText() != null
  2808. && interfaces.getComponent(GE_INTERFACE, 148).getText().contains(
  2809. "" + formatNumb(quantity))) {
  2810. changeQuantity = false;
  2811. sleep(random(1000, 1200));
  2812. }
  2813. } else
  2814. return false;
  2815. times++;
  2816. }
  2817. times = 0;
  2818. while (changePrice && !changeQuantity) {
  2819. if (times >= 3) {
  2820. close();
  2821. return false;
  2822. }
  2823. if (isOpen()) {
  2824. if (interfaces.getComponent(GE_INTERFACE, 153).getText() != null
  2825. && interfaces.getComponent(GE_INTERFACE, 153).getText().contains(
  2826. "" + formatNumb(price))) {
  2827. changePrice = false;
  2828. break;
  2829. }
  2830. if (interfaces.getComponent(GE_INTERFACE, 177).getText() != null
  2831. && interfaces.getComponent(GE_INTERFACE, 177).getText().contains("...")) {
  2832. interfaces.getComponent(GE_INTERFACE, 177).doClick();
  2833. sleep(random(1000, 1200));
  2834. }
  2835. if (interfaces.getComponent(752, 4).getText().contains("you wish to buy"))
  2836. keyboard.sendText("" + price, true);
  2837. sleep(random(1000, 2000));
  2838. if (interfaces.getComponent(GE_INTERFACE, 153).getText() != null
  2839. && interfaces.getComponent(GE_INTERFACE, 153).getText().contains(
  2840. "" + formatNumb(price))) {
  2841. changePrice = false;
  2842. sleep(random(1000, 1200));
  2843. }
  2844. } else
  2845. return false;
  2846. times++;
  2847. }
  2848. if (!changePrice && !changeQuantity) {
  2849. if (interfaces.getComponent(GE_INTERFACE, 187).getText() != null)
  2850. interfaces.getComponent(GE_INTERFACE, 187).doClick();
  2851. close();
  2852. sentOffer = true;
  2853. return true;
  2854. }
  2855. }
  2856. }
  2857. close();
  2858. return false;
  2859. }
  2860. return false;
  2861. }
  2862. // Credits to Dwarfeh for most of the Grand Exchange methods :)
  2863. /**
  2864. * Sells items to the Grand Exchange if it's open
  2865. * @param itemName item to sell
  2866. * @param slotNumber slot number to sell from (1-5)
  2867. * @param quantity amount to sell
  2868. * @param price Price to sell from. 0 will leave it as default price
  2869. * @return <tt>true</tt> if sold successfully; otherwise <tt>false</tt>
  2870. */
  2871. public boolean sell(final String itemName, final int slotNumber, final int quantity, final int price) {
  2872. SLOT = slotNumber;
  2873. if (slotNumber == 0 || slotNumber > 5)
  2874. return false;
  2875. if (!inventory.contains(itemName))
  2876. return false;
  2877. if (isOpen()) {
  2878. final GEBuyMethods t = new GEBuy(slotNumber);
  2879. final int sellClick = t.getSellClick();
  2880. boolean offerItem = false;
  2881. boolean offeredItem = false;
  2882. if (!isSelling()) {
  2883. interfaces.getComponent(GE_INTERFACE, sellClick).doClick();
  2884. sleep(random(700, 900));
  2885. offerItem = true;
  2886. }
  2887. if (!isSelling() && offerItem) {
  2888. inventory.getItem(itemName).doClick(true);
  2889. sleep(random(500, 700));
  2890. offeredItem = true;
  2891. }
  2892. if (isSelling()) {
  2893. close();
  2894. return false;
  2895. }
  2896. if (!isSelling() && offeredItem) {
  2897. boolean changeQuantity;
  2898. changeQuantity = quantity > 1;
  2899. boolean changePrice;
  2900. changePrice = price > 1;
  2901. int times = 0;
  2902. while (changeQuantity) {
  2903. if (times == 3) {
  2904. close();
  2905. return false;
  2906. }
  2907. if (isOpen()) {
  2908. if (interfaces.getComponent(GE_INTERFACE, 148).getText() != null
  2909. && interfaces.getComponent(GE_INTERFACE, 148).getText().contains(
  2910. "" + formatNumb(quantity))) {
  2911. changeQuantity = false;
  2912. break;
  2913. }
  2914. if (interfaces.getComponent(GE_INTERFACE, 168).getText() != null
  2915. && interfaces.getComponent(GE_INTERFACE, 168).getText().contains("...")) {
  2916. interfaces.getComponent(GE_INTERFACE, 168).doClick();
  2917. sleep(random(700, 900));
  2918. }
  2919. if (interfaces.getComponent(752, 4).getText().contains("amount you wish to"))
  2920. keyboard.sendTextInstant("" + quantity, true);
  2921. sleep(random(1000, 2000));
  2922. if (interfaces.getComponent(GE_INTERFACE, 148).getText() != null
  2923. && interfaces.getComponent(GE_INTERFACE, 148).getText().contains(
  2924. "" + formatNumb(quantity)))
  2925. changeQuantity = false;
  2926. } else
  2927. return false;
  2928. times++;
  2929. }
  2930. times = 0;
  2931. while (changePrice && !changeQuantity) {
  2932. if (times == 3) {
  2933. close();
  2934. return false;
  2935. }
  2936. if (isOpen()) {
  2937. if (interfaces.getComponent(GE_INTERFACE, 177).getText() != null
  2938. && interfaces.getComponent(GE_INTERFACE, 168).getText().contains("...")) {
  2939. interfaces.getComponent(GE_INTERFACE, 177).doClick();
  2940. sleep(random(700, 900));
  2941. }
  2942. if (interfaces.getComponent(752, 4).getText().contains("you wish to sell"))
  2943. keyboard.sendTextInstant("" + price, true);
  2944. sleep(random(1000, 2000));
  2945. if (interfaces.getComponent(GE_INTERFACE, 153).getText() != null
  2946. && interfaces.getComponent(GE_INTERFACE, 153).getText().contains("" + formatNumb(price)))
  2947. changePrice = false;
  2948. } else
  2949. return false;
  2950. times++;
  2951. }
  2952. if (!changeQuantity && !changePrice)
  2953. if (interfaces.getComponent(GE_INTERFACE, 187).getText() != null)
  2954. interfaces.getComponent(GE_INTERFACE, 187).doClick();
  2955. close();
  2956. offeredOaks = true;
  2957. return true;
  2958. }
  2959. close();
  2960. return false;
  2961. }
  2962. return false;
  2963. }
  2964. /**
  2965. * @return <tt>true</tt> if selling; otherwise <tt>false</tt>
  2966. */
  2967. public boolean isSelling() {
  2968. return interfaces.getComponent(GE_INTERFACE, 142).isValid()
  2969. && !interfaces.getComponent(GE_INTERFACE, 142).getText().equals("Choose an item to exchange");
  2970. }
  2971. /**
  2972. * Determines membership
  2973. * @return <tt>true</tt> if members is selected for the account; otherwise <tt>false</tt>
  2974. */
  2975. public boolean isMember() {
  2976. return AccountManager.isMember(account.getName());
  2977. }
  2978. /**
  2979. * Sets the number format as the same as GrandExchange's
  2980. * @param money GrandExchange's money
  2981. * @return number to match GrandExchange's
  2982. */
  2983. public static String formatNumb(final long money) {
  2984. return new DecimalFormat("###,###,###,###,###,###").format(money);
  2985. }
  2986. /**
  2987. * Gets the total slots there are for the person
  2988. * @return number of slots if account is member
  2989. */
  2990. public int getTotalSlots() {
  2991. return isMember() ? 6 : 2;
  2992. }
  2993. /**
  2994. * Checks to see if the GE slot is empty
  2995. * @param slot gets the correct interface
  2996. * @return <tt>true</tt> if empty; otherwise <tt>false</tt>
  2997. */
  2998. public boolean isSlotEmpty(final int slot) {
  2999. final GEBuyMethods check2 = new GEBuy(slot);
  3000. final int check = check2.getInterface();
  3001. if (isOpen())
  3002. if (interfaces.getComponent(GE_INTERFACE, check).getComponent(10).getText().equals("Empty"))
  3003. return true;
  3004. return false;
  3005. }
  3006. /**
  3007. * Will determine the total amount of empty slots
  3008. * @return total amount of empty slots
  3009. */
  3010. public int getAllEmptySlots() {
  3011. if (isOpen()) {
  3012. int total = 0;
  3013. for (int i = 1; i <= getTotalSlots();) {
  3014. SLOT = i;
  3015. final GEBuyMethods check2 = new GEBuy(i);
  3016. final int check = check2.getInterface();
  3017. if (interfaces.getComponent(GE_INTERFACE, check).getComponent(10).getText().equals("Empty"))
  3018. total++;
  3019. if (i == getTotalSlots())
  3020. return total;
  3021. i++;
  3022. }
  3023. }
  3024. return 0;
  3025. }
  3026. /**
  3027. * Checks for nearest empty slot
  3028. * @return an empty spot in the GE if there is one. If not, 0
  3029. */
  3030. public int getEmptySlot() {
  3031. if (isOpen()) {
  3032. for (int i = 1; i <= getTotalSlots();) {
  3033. SLOT = i;
  3034. final GEBuyMethods check2 = new GEBuy(i);
  3035. final int check = check2.getInterface();
  3036. if (interfaces.getComponent(GE_INTERFACE, check).getComponent(10).getText().equals("Empty"))
  3037. return i;
  3038. i++;
  3039. }
  3040. return 0;
  3041. }
  3042. return 0;
  3043. }
  3044. /**
  3045. * Determines if an offer has completed or not
  3046. * @return <tt>true</tt> if an offer is completed; otherwise <tt>false</tt>
  3047. */
  3048. public boolean isAnOfferCompleted() {
  3049. final GEBuyMethods check2 = new GEBuy();
  3050. return check2.isAnOfferCompleted();
  3051. }
  3052. /**
  3053. * Determines if there is an item by the name
  3054. * @return <tt>true</tt> if an item was found; otherwise <tt>false</tt>
  3055. */
  3056. public boolean findItem() {
  3057. return interfaces.getComponent(SEARCH, 4).getComponent(0) != null
  3058. && interfaces.getComponent(SEARCH, 4).getComponent(0).getText() != null
  3059. && !interfaces.getComponent(SEARCH, 4).getComponent(0).getText().equals("No matching items found.");
  3060. }
  3061. /**
  3062. * Determines if the person has searched or not
  3063. * @param itemName is defined by buy/sell item
  3064. * @return <tt>true</tt> if they have searched; otherwise <tt>false</tt>
  3065. */
  3066. public boolean hasSearched(final String itemName) {
  3067. if (!Character.isUpperCase(itemName.charAt(0)))
  3068. Character.toUpperCase(itemName.charAt(0));
  3069. return interfaces.getComponent(GE_INTERFACE, 142).getText().contains(itemName)
  3070. || interfaces.getComponent(SEARCH, 4).getComponent(1) != null
  3071. && interfaces.getComponent(SEARCH, 9).getText().contains(itemName);
  3072. }
  3073. /**
  3074. * Determines if the player is searching
  3075. * @return <tt>true</tt> if interface is valid; otherwise <tt>false</tt>
  3076. */
  3077. public boolean isSearching() {
  3078. return interfaces.getComponent(GE_INTERFACE, 134).isValid();
  3079. }
  3080. /**
  3081. * Checks whether the GE is open
  3082. * @return <tt>true</tt> if the GE interface is valid; otherwise <tt>false</tt>
  3083. */
  3084. public boolean isOpen() {
  3085. return getInterface().isValid();
  3086. }
  3087. /**
  3088. * Gets the bank's interface.
  3089. * @return <tt>true</tt> if interface is valid
  3090. */
  3091. public RSInterface getInterface() {
  3092. return interfaces.get(GE_INTERFACE);
  3093. }
  3094. /**
  3095. * Gets the general interface for the slot
  3096. * @param slot determines which one to take from
  3097. * @return interface for the slot
  3098. */
  3099. public int bankGetInterface(final int slot) {
  3100. final BankCollectMethods collect = new BankCollect(slot);
  3101. return collect.getBankInterface();
  3102. }
  3103. /**
  3104. * Gets the left interface for the slot
  3105. * @param slot determines which one to take from
  3106. * @return left interface for the slot
  3107. */
  3108. public int bankGetLeftInterface(final int slot) {
  3109. final BankCollectMethods collect = new BankCollect(slot);
  3110. return collect.getBankLeftCollect();
  3111. }
  3112. /**
  3113. * Gets the right interface for the slot
  3114. * @param slot determines which one to take from
  3115. * @return right interface for the slot
  3116. */
  3117. public int bankGetRightInterface(final int slot) {
  3118. final BankCollectMethods collect = new BankCollect(slot);
  3119. return collect.getBankRightCollect();
  3120. }
  3121. /**
  3122. * Collects everything from the interface
  3123. * @return <tt>true</tt> if collected all successfully; otherwise <tt>false</tt>
  3124. */
  3125. public boolean bankCollectAll() {
  3126. final BankCollectMethods collect = new BankCollect();
  3127. return collect.bankCollectAll();
  3128. }
  3129. /**
  3130. * Opens collection interface
  3131. * @return <tt>true</tt> if opened successfully; otherwise <tt>false</tt>
  3132. */
  3133. public boolean bankCollectOpen() {
  3134. final BankCollectMethods collect = new BankCollect();
  3135. return collect.bankOpen();
  3136. }
  3137. /**
  3138. * Closes collection interface
  3139. * @return <tt>true</tt> if closed successfully; otherwise <tt>false</tt>
  3140. */
  3141. public boolean bankCollectClose() {
  3142. final BankCollectMethods collect = new BankCollect();
  3143. return collect.bankClose();
  3144. }
  3145. /**
  3146. * Checks collection interface
  3147. * @return <tt>true</tt> if opened; otherwise <tt>false</tt>
  3148. */
  3149. public boolean bankCollectIsOpen() {
  3150. final BankCollectMethods collect = new BankCollect();
  3151. return collect.bankIsOpen();
  3152. }
  3153. /**
  3154. * Closes the GE.
  3155. * @return <tt>true</tt> if the GE is no longer open; otherwise <tt>false</tt>
  3156. */
  3157. public boolean close() {
  3158. if (isOpen()) {
  3159. interfaces.getComponent(GE_INTERFACE, GE_CLOSE).doClick();
  3160. sleep(random(1500, 2000));
  3161. return !isOpen();
  3162. }
  3163. return !isOpen();
  3164. }
  3165. /**
  3166. * Opens the GrandExchange
  3167. * @return <tt>true</tt> if open; otherwise <tt>false</tt>
  3168. */
  3169. public boolean open() {
  3170. if (!isOpen()) {
  3171. final RSNPC i = npcs.getNearest(CLERKS);
  3172. if (!i.isValid())
  3173. return false;
  3174. mouse.move(i.getPoint());
  3175. mouse.click(false);
  3176. // i.interact("Exchange ") // TODO Clicked Talk-to
  3177. if (menu.clickIndex(menu.getIndex("Exchange") + 1)) {
  3178. chill();
  3179. for (int j = 0; j < 10 && !isOpen(); j++)
  3180. sleep(random(100, 200));
  3181. sleep(random(700, 900));
  3182. return isOpen();
  3183. } else
  3184. return false;
  3185. }
  3186. return true;
  3187. }
  3188. /**
  3189. * Gets the name of the given item ID. Should not be used.
  3190. * @param itemID The item ID to look for.
  3191. * @return The name of the given item ID or an empty String if unavailable.
  3192. * @see GrandExchange#lookup(int)
  3193. */
  3194. public String getItemName(final int itemID) {
  3195. final GEItem geItem = lookup(itemID);
  3196. if (geItem != null)
  3197. return geItem.getName();
  3198. return "";
  3199. }
  3200. /**
  3201. * Gets the ID of the given item name. Should not be used.
  3202. * @param itemName The name of the item to look for.
  3203. * @return The ID of the given item name or -1 if unavailable.
  3204. * @see GrandExchange#lookup(java.lang.String)
  3205. */
  3206. public int getItemID(final String itemName) {
  3207. final GEItem geItem = lookup(itemName);
  3208. if (geItem != null)
  3209. return geItem.getID();
  3210. return -1;
  3211. }
  3212. /**
  3213. * Collects data for a given item ID from the Grand Exchange website.
  3214. * @param itemID The item ID.
  3215. * @return An instance of GrandExchange.GEItem; <code>null</code> if unable to fetch data.
  3216. */
  3217. public GEItem lookup(final int itemID) {
  3218. try {
  3219. final URL url = new URL(HOST + GET + itemID);
  3220. final BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
  3221. String input;
  3222. boolean exists = false;
  3223. int i = 0;
  3224. final double[] values = new double[4];
  3225. String name = "", examine = "";
  3226. while ((input = br.readLine()) != null)
  3227. if (input.contains("<div class=\"brown_box main_ge_page") && !exists) {
  3228. if (!input.contains("vertically_spaced"))
  3229. return null;
  3230. exists = true;
  3231. br.readLine();
  3232. br.readLine();
  3233. name = br.readLine();
  3234. } else if (input.contains("<img id=\"item_image\" src=\""))
  3235. examine = br.readLine();
  3236. else if (input.matches("(?i).+ (price|days):</b> .+")) {
  3237. values[i] = parse(input);
  3238. i++;
  3239. } else if (input.matches("<div id=\"legend\">"))
  3240. break;
  3241. return new GEItem(name, examine, itemID, values);
  3242. } catch (final IOException ignore) {}
  3243. return null;
  3244. }
  3245. /**
  3246. * Collects data for a given item name from the Grand Exchange website.
  3247. * @param itemName The name of the item.
  3248. * @return An instance of GrandExchange.GEItem; <code>null</code> if unable to fetch data.
  3249. */
  3250. public GEItem lookup(final String itemName) {
  3251. try {
  3252. final URL url = new URL(HOST + "/m=itemdb_rs/results.ws?query=" + itemName + "&price=all&members=");
  3253. final BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
  3254. String input;
  3255. while ((input = br.readLine()) != null)
  3256. if (input.contains("<div id=\"search_results_text\">")) {
  3257. input = br.readLine();
  3258. if (input.contains("Your search for"))
  3259. return null;
  3260. } else if (input.startsWith("<td><img src=")) {
  3261. final Matcher matcher = PATTERN.matcher(input);
  3262. if (matcher.find())
  3263. if (matcher.group(2).contains(itemName))
  3264. return lookup(Integer.parseInt(matcher.group(1)));
  3265. }
  3266. } catch (final IOException ignored) {}
  3267. return null;
  3268. }
  3269. public double parse(String str) {
  3270. if (str != null && !str.isEmpty()) {
  3271. str = stripFormatting(str);
  3272. str = str.substring(str.indexOf(58) + 2, str.length());
  3273. str = str.replace(",", "");
  3274. str = str.trim();
  3275. if (!str.endsWith("%")) {
  3276. if (!str.endsWith("k") && !str.endsWith("m") && !str.endsWith("b"))
  3277. return Double.parseDouble(str);
  3278. return Double.parseDouble(str.substring(0, str.length() - 1))
  3279. * (str.endsWith("b") ? 1000000000 : str.endsWith("m") ? 1000000 : 1000);
  3280. }
  3281. final int k = str.startsWith("+") ? 1 : -1;
  3282. str = str.substring(1);
  3283. return Double.parseDouble(str.substring(0, str.length() - 1)) * k;
  3284. }
  3285. return -1D;
  3286. }
  3287. public String stripFormatting(final String str) {
  3288. if (str != null && !str.isEmpty())
  3289. return str.replaceAll("(^[^<]+>|<[^>]+>|<[^>]+$)", "");
  3290. return "";
  3291. }
  3292.  
  3293. /**
  3294. * Provides access to GEItem Information.
  3295. */
  3296. public class GEItem {
  3297. private final String name;
  3298. private final String examine;
  3299. private final int id;
  3300. private final int guidePrice;
  3301. private final double change30;
  3302. private final double change90;
  3303. private final double change180;
  3304. GEItem(final String name, final String examine, final int id, final double[] values) {
  3305. this.name = name;
  3306. this.examine = examine;
  3307. this.id = id;
  3308. guidePrice = (int) values[0];
  3309. change30 = values[1];
  3310. change90 = values[2];
  3311. change180 = values[3];
  3312. }
  3313. /**
  3314. * Gets the change in price for the last 30 days of this item.
  3315. * @return The change in price for the last 30 days of this item.
  3316. */
  3317. public double getChange30Days() {
  3318. return change30;
  3319. }
  3320. /**
  3321. * Gets the change in price for the last 90 days of this item.
  3322. * @return The change in price for the last 90 days of this item.
  3323. */
  3324. public double getChange90Days() {
  3325. return change90;
  3326. }
  3327. /**
  3328. * Gets the change in price for the last 180 days of this item.
  3329. * @return The change in price for the last 180 days of this item.
  3330. */
  3331. public double getChange180Days() {
  3332. return change180;
  3333. }
  3334. /**
  3335. * Gets the ID of this item.
  3336. * @return The ID of this item.
  3337. */
  3338. public int getID() {
  3339. return id;
  3340. }
  3341. /**
  3342. * Gets the market price of this item.
  3343. * @return The market price of this item.
  3344. */
  3345. public int getGuidePrice() {
  3346. return guidePrice;
  3347. }
  3348. /**
  3349. * Gets the name of this item.
  3350. * @return The name of this item.
  3351. */
  3352. public String getName() {
  3353. return name;
  3354. }
  3355. /**
  3356. * Gets the description of this item.
  3357. * @return The description of this item.
  3358. */
  3359. public String getDescription() {
  3360. return examine;
  3361. }
  3362. }
  3363.  
  3364. private interface BankCollectMethods {
  3365. public int getBankInterface();
  3366. public int getBankLeftCollect();
  3367. public int getBankRightCollect();
  3368. public boolean bankCollectAll();
  3369. public boolean bankIsOpen();
  3370. public boolean bankOpen();
  3371. public boolean bankClose();
  3372. }
  3373.  
  3374. private class BankCollect implements BankCollectMethods {
  3375. private int Interface = 0;
  3376. private int leftCollect = 0;
  3377. private int rightCollect = 0;
  3378. private final int COLLECT_CLOSE = 14;
  3379. public BankCollect(final int slot) {
  3380. SLOT = slot;
  3381. switch (slot) {
  3382. case 1:
  3383. Interface = 19;
  3384. leftCollect = 0;
  3385. rightCollect = 2;
  3386. break;
  3387. case 2:
  3388. Interface = 23;
  3389. leftCollect = 0;
  3390. rightCollect = 2;
  3391. break;
  3392. case 3:
  3393. Interface = 27;
  3394. leftCollect = 0;
  3395. rightCollect = 2;
  3396. break;
  3397. case 4:
  3398. Interface = 32;
  3399. leftCollect = 0;
  3400. rightCollect = 2;
  3401. break;
  3402. case 5:
  3403. Interface = 37;
  3404. leftCollect = 0;
  3405. rightCollect = 2;
  3406. break;
  3407. case 6:
  3408. Interface = 42;
  3409. leftCollect = 0;
  3410. rightCollect = 2;
  3411. break;
  3412. }
  3413. }
  3414. public BankCollect() {}
  3415. public int getBankInterface() {
  3416. return this.Interface;
  3417. }
  3418. public int getBankLeftCollect() {
  3419. return this.leftCollect;
  3420. }
  3421. public int getBankRightCollect() {
  3422. return this.rightCollect;
  3423. }
  3424. public boolean bankIsOpen() {
  3425. return interfaces.get(COLLECT_INTERFACE).isValid();
  3426. }
  3427. public boolean bankOpen() {
  3428. if (!bankIsOpen()) {
  3429. final RSNPC i = npcs.getNearest(BANKERS);
  3430. if (!i.isValid())
  3431. return false;
  3432. mouse.move(i.getPoint());
  3433. mouse.click(false);
  3434. // TODO Interact clicked wrong menu item.
  3435. if (menu.clickIndex(menu.getIndex("Collect"))) {
  3436. if (calc.distanceTo(i) > 1) {
  3437. final long time = System.currentTimeMillis();
  3438. final int max = random(2000, 4000);
  3439. while (System.currentTimeMillis() - time < max) {
  3440. if (players.getMyPlayer().isMoving()) {
  3441. do
  3442. sleep(random(5, 15));
  3443. while (players.getMyPlayer().isMoving() || !i.isOnScreen());
  3444. break;
  3445. }
  3446. sleep(random(5, 15));
  3447. }
  3448. }
  3449. for (int j = 0; j < 10 && !bankIsOpen(); j++)
  3450. sleep(random(100, 200));
  3451. sleep(random(700, 900));
  3452. return bankIsOpen();
  3453. } else
  3454. return false;
  3455. }
  3456. return true;
  3457. }
  3458. public boolean bankCollectAll() {
  3459. if (bankIsOpen()) {
  3460. int boxToCollect;
  3461. boxToCollect = getTotalSlots();
  3462. for (int i = 1; i <= boxToCollect;) {
  3463. final BankCollectMethods k = new BankCollect(i);
  3464. final int inter = k.getBankInterface();
  3465. final int left = k.getBankLeftCollect();
  3466. final int right = k.getBankRightCollect();
  3467. if (interfaces.getComponent(COLLECT_INTERFACE, inter).getComponent(left).getActions() != null
  3468. && interfaces.getComponent(COLLECT_INTERFACE, inter).getComponent(left).getActions().length >= 1) {
  3469. interfaces.getComponent(COLLECT_INTERFACE, inter).getComponent(left).doClick();
  3470. sleep(random(300, 500));
  3471. }
  3472. if (interfaces.getComponent(COLLECT_INTERFACE, inter).getComponent(right).getActions() != null
  3473. && interfaces.getComponent(COLLECT_INTERFACE, inter).getComponent(right).getActions().length >= 1) {
  3474. interfaces.getComponent(COLLECT_INTERFACE, inter).getComponent(right).doClick();
  3475. sleep(random(300, 500));
  3476. }
  3477. i++;
  3478. }
  3479. bankClose();
  3480. return true;
  3481. }
  3482. return false;
  3483. }
  3484. public boolean bankClose() {
  3485. if (bankIsOpen()) {
  3486. if (!interfaces.getComponent(COLLECT_INTERFACE, COLLECT_CLOSE).doClick()) {
  3487. return false;
  3488. }
  3489. }
  3490. sleep(random(700, 900));
  3491. return true;
  3492. }
  3493. }
  3494.  
  3495. private interface GEBuyMethods {
  3496. public int getInterface();
  3497. public int getBuyClick();
  3498. public int getSellClick();
  3499. public boolean isAnOfferCompleted();
  3500. }
  3501.  
  3502. private class GEBuy implements GEBuyMethods {
  3503. private int Interface = 0;
  3504. private int buyClick = 0;
  3505. private int sellClick = 0;
  3506. private final int completeWidth = 124;
  3507. private final int height = 13;
  3508. private final int COMPLETION_BAR_INTERFACE = 13;
  3509. public GEBuy(final int slot) {
  3510. switch (slot) {
  3511. case 1:
  3512. this.Interface = 19;
  3513. this.buyClick = 30;
  3514. this.sellClick = 29;
  3515. break;
  3516. case 2:
  3517. this.Interface = 35;
  3518. this.buyClick = 46;
  3519. this.sellClick = 45;
  3520. break;
  3521. case 3:
  3522. this.Interface = 51;
  3523. this.buyClick = 62;
  3524. this.sellClick = 61;
  3525. break;
  3526. case 4:
  3527. this.Interface = 70;
  3528. this.buyClick = 81;
  3529. this.sellClick = 80;
  3530. break;
  3531. case 5:
  3532. this.Interface = 89;
  3533. this.buyClick = 100;
  3534. this.sellClick = 99;
  3535. break;
  3536. case 6:
  3537. this.Interface = 108;
  3538. this.buyClick = 119;
  3539. this.sellClick = 118;
  3540. break;
  3541. }
  3542. }
  3543. public GEBuy() {}
  3544. public int getInterface() {
  3545. return this.Interface;
  3546. }
  3547. public int getBuyClick() {
  3548. return this.buyClick;
  3549. }
  3550. public int getSellClick() {
  3551. return this.sellClick;
  3552. }
  3553. public boolean isAnOfferCompleted() {
  3554. if (grandExchange.isOpen()) {
  3555. final int boxToCollect = getTotalSlots();
  3556. for (int i = 1; i <= boxToCollect;) {
  3557. final GEBuyMethods k = new GEBuy(i);
  3558. final int inter = k.getInterface();
  3559. if (interfaces.getComponent(GE_INTERFACE, inter).getComponent(COMPLETION_BAR_INTERFACE) != null
  3560. && interfaces.getComponent(GE_INTERFACE, inter).getComponent(COMPLETION_BAR_INTERFACE).getHeight() == height
  3561. && interfaces.getComponent(GE_INTERFACE, inter).getComponent(COMPLETION_BAR_INTERFACE).getWidth() == completeWidth)
  3562. return true;
  3563. i++;
  3564. }
  3565. }
  3566. return false;
  3567. }
  3568. }
  3569. private BufferedImage getImage(final String fileName, final String imageURL) {
  3570. try {
  3571. final File dir = new File(Configuration.Paths.getScriptCacheDirectory(), "DynamicWoodcutter");
  3572. if (!dir.exists())
  3573. dir.mkdir();
  3574. final File f = new File(dir + File.separator + fileName);
  3575. if (!f.exists()) {
  3576. BufferedImage image = null;
  3577. final URL url = new URL(imageURL);
  3578. image = ImageIO.read(url);
  3579. ImageIO.write(image, "PNG", f);
  3580. return image;
  3581. }
  3582. final BufferedImage img = ImageIO.read(f);
  3583. return img;
  3584. } catch (final Exception e) {}
  3585. return null;
  3586. }
  3587. private int chooseAntiban() {
  3588. final int num = random(0, 100);
  3589. int k = 35;
  3590. if (num < k)
  3591. return 0;; // Mouse
  3592. if (num >= k && num < k + 55)
  3593. return 1; // Advanced camera
  3594. k += 55;
  3595. if (num >= k && num < k + 2)
  3596. return 2; // Check skill
  3597. k += 2;
  3598. if (num >= k && num < k + 5)
  3599. return 3; // Examine/Misc
  3600. return -1;
  3601. }
  3602. /**
  3603. * @return True if an Anti-ban was performed, false otherwise.
  3604. */
  3605. private boolean antiBan() {
  3606. final int j = chooseAntiban();
  3607. if (j == -1)
  3608. return false;
  3609. if (antibanTimer < System.currentTimeMillis()) {
  3610. switch (j) {
  3611. case 0: // Mouse.
  3612. switch (random(0, 5)) {
  3613. case 0:
  3614. antiBan = "Moving mouse off screen.";
  3615. mouse.moveOffScreen();
  3616. sleep(random(1000, 1500));
  3617. break;
  3618. case 1:
  3619. antiBan = "Moving mouse randomly and sleeping.";
  3620. mouse.moveRandomly(200, 400);
  3621. sleep(random(300, 500));
  3622. break;
  3623. case 2:
  3624. antiBan = "Moving mouse randomly.";
  3625. mouse.moveRandomly(random(100, 500));
  3626. break;
  3627. case 3:
  3628. antiBan = "Moving mouse slightly.";
  3629. mouse.moveSlightly();
  3630. sleep(random(300, 500));
  3631. break;
  3632. case 4:
  3633. antiBan = "Moving mouse to random point.";
  3634. mouse.move(random(527, 200), random(744, 464));
  3635. break;
  3636. }
  3637. break;
  3638. case 1:
  3639. antiBan = "Advanced camera movement.";
  3640. new Camera(Camera.ADVANCED);
  3641. break;
  3642. case 2: // Check a skill.
  3643. antiBan = "Checking skill.";
  3644. if (trainFM && random(0, 2) == 0)
  3645. skills.doHover(Skills.INTERFACE_FIREMAKING);
  3646. else
  3647. skills.doHover(Skills.INTERFACE_WOODCUTTING);
  3648. sleep(random(500, 2500));
  3649. break;
  3650. case 3: // Examine
  3651. outer: switch (random(0, 6)) {
  3652. case 0:
  3653. final RSItem tinderbox = inventory.getItem(tinderboxId);
  3654. if (trainFM && tinderbox != null) {
  3655. antiBan = "Moving Tinderbox.";
  3656. final int idx = tinderbox.getComponent().getComponentIndex();
  3657. RSItem dest = inventory.getItemAt(random(8, 20));
  3658. while (dest.getComponent().getIndex() == idx)
  3659. dest = inventory.getItemAt(random(8, 20));
  3660. tinderbox.getComponent().doHover();
  3661. RSComponent component = dest.getComponent();
  3662. mouse.drag(
  3663. random(component.getAbsoluteX(), component.getAbsoluteX() + component.getWidth()),
  3664. random(component.getAbsoluteY(), component.getAbsoluteY() + component.getHeight()));
  3665. } else
  3666. break outer;
  3667. case 1:
  3668. antiBan = "Right clicking a player.";
  3669. RSPlayer target = null;
  3670. for (final RSPlayer p : players.getAll())
  3671. if (p.isOnScreen() && !players.getMyPlayer().equals(p)) {
  3672. target = p;
  3673. break;
  3674. }
  3675. if (target != null) {
  3676. final Point p = target.getScreenLocation();
  3677. mouse.click(p, false);
  3678. sleep(300, 1000);
  3679. mouse.moveSlightly();
  3680. }
  3681. break;
  3682. case 2:
  3683. antiBan = "Right clicking an object.";
  3684. RSObject objTarg = null;
  3685. for (final RSObject p : objects.getAll())
  3686. if (p.isOnScreen()) {
  3687. objTarg = p;
  3688. break;
  3689. }
  3690. if (objTarg != null) {
  3691. objTarg.doClick(false);
  3692. if (random(0, 5) == 0) {
  3693. sleep(random(500, 1000));
  3694. menu.click("Examine");
  3695. sleep(random(100, 300));
  3696. }
  3697. mouse.moveSlightly();
  3698. }
  3699. break;
  3700. case 3:
  3701. antiBan = "Right clicking an item.";
  3702. RSItem itemTarg = null;
  3703. for (final RSItem p : inventory.getItems())
  3704. if (p != null) {
  3705. itemTarg = p;
  3706. break;
  3707. }
  3708. if (itemTarg != null) {
  3709. itemTarg.doClick(false);
  3710. sleep(300, 700);
  3711. if (random(0, 5) == 0) {
  3712. menu.click("Examine");
  3713. sleep(random(100, 300));
  3714. }
  3715. mouse.moveSlightly();
  3716. }
  3717. break;
  3718. case 4:
  3719. antiBan = "Checking XP total.";
  3720. if (interfaces.getComponent(548, 0).interact("Toggle XP Total")) {
  3721. sleep(700, 2200);
  3722. interfaces.getComponent(548, 0).interact("Toggle XP Total");
  3723. sleep(random(100, 400));
  3724. mouse.moveSlightly();
  3725. }
  3726. break;
  3727. case 5:
  3728. antiBan = "Opening random tab.";
  3729. if (random(0, 2) == 0)
  3730. game.openTab(Tab.values()[random(0, 16)]);
  3731. else
  3732. game.openTab(Tab.values()[random(0, 16)], true);
  3733. sleep(random(500, 1500));
  3734. break;
  3735. }
  3736. break;
  3737. }
  3738. if (powerchop && !trainFM)
  3739. antibanTimer = System.currentTimeMillis() + random(15000, 60000);
  3740. else
  3741. antibanTimer = System.currentTimeMillis() + random(8000, 25000);
  3742. } else
  3743. return false;
  3744. if (!antiBan.contains("Moving camera randomly.") && !antiBan.contains("Advanced camera movement."))
  3745. antiBan = "";
  3746. return true;
  3747. }
  3748. private void advancedCameraMovement(int timeOutMin, int timeOutMax) {
  3749. final int random1 = random(timeOutMin / 4, timeOutMax / 4);
  3750. final int random2 = random(timeOutMin / 4, timeOutMax / 4);
  3751. final int random3 = random(timeOutMin / 2, timeOutMax / 2);
  3752. if (random(0, 2) == 0)
  3753. keyboard.pressKey((char) KeyEvent.VK_RIGHT);
  3754. else
  3755. keyboard.pressKey((char) KeyEvent.VK_LEFT);
  3756. sleep(random3);
  3757. if (random(0, 4) == 0)
  3758. keyboard.pressKey((char) KeyEvent.VK_DOWN);
  3759. else
  3760. keyboard.pressKey((char) KeyEvent.VK_UP);
  3761. if (random(0, 2) == 0) {
  3762. sleep(random1);
  3763. keyboard.releaseKey((char) KeyEvent.VK_RIGHT);
  3764. keyboard.releaseKey((char) KeyEvent.VK_LEFT);
  3765. sleep(random2);
  3766. keyboard.releaseKey((char) KeyEvent.VK_UP);
  3767. keyboard.releaseKey((char) KeyEvent.VK_DOWN);
  3768. } else {
  3769. sleep(random1);
  3770. keyboard.releaseKey((char) KeyEvent.VK_UP);
  3771. keyboard.releaseKey((char) KeyEvent.VK_DOWN);
  3772. sleep(random2);
  3773. keyboard.releaseKey((char) KeyEvent.VK_RIGHT);
  3774. keyboard.releaseKey((char) KeyEvent.VK_LEFT);
  3775. }
  3776. }
  3777. private State getState() {
  3778. if (interfaces.get(244).containsText("may I ask you to speak") || needTutoring) {
  3779. status = "GE Tutor";
  3780. needTutoring = true;
  3781. return State.GETUTOR;
  3782. }
  3783. if (checkBank) {
  3784. status = "Banking";
  3785. return State.CHECKBANK;
  3786. }
  3787. if (useDeposit) {
  3788. status = "Depositing";
  3789. return State.DEPOSIT;
  3790. }
  3791. if (!inventory.contains(runeHatchetId)
  3792. && (runeHatchetPrice * 1.2 < totalCash && runeHatchetPrice != -1 && wcLvl() >= 41
  3793. && !useAvailableHatchets || sentOffer)) {
  3794. status = "Rune hatchet";
  3795. return State.BUYRUNEHATCHET;
  3796. }
  3797. if (skills.getCurrentExp(Skills.WOODCUTTING) < 500 && !sawLamp || inventory.contains(13439)
  3798. || npcs.getNearest(7942) != null && calc.distanceTo(npcs.getNearest(7942)) < 10) {
  3799. status = "Lamps";
  3800. return State.LAMPS;
  3801. }
  3802. if (trainFM && !inventory.contains(tinderboxId)) {
  3803. status = "Tinderbox";
  3804. return State.BUYTINDERBOX;
  3805. }
  3806. if (!useAvailableHatchets) {
  3807. bestHatchetAvailable = bestHatchetAvailable();
  3808. if (bestHatchetAvailable == -1) {
  3809. status = "Buying hatchet";
  3810. return State.BUYHATCHET;
  3811. }
  3812. if (inventory.contains(bronzeHatchetId) && !inventory.contains(steelHatchetId) && inventory.contains(995)
  3813. && inventory.getItem(995).getStackSize() >= 200) {
  3814. status = "Buying hatchet";
  3815. return State.BUYHATCHET;
  3816. }
  3817. if (bestHatchetAvailable == bronzeHatchetId) {
  3818. status = "Trees";
  3819. return State.TREE;
  3820. }
  3821. if (!inventory.contains(bestHatchetAvailable)) {
  3822. status = "Upgrading Hatchet";
  3823. return State.CHECKBANK;
  3824. }
  3825. }
  3826. if (burnLogs) {
  3827. status = "Burning logs";
  3828. return State.BURN;
  3829. }
  3830. if (useAvailableHatchets) {
  3831. if (!checkedBank) {
  3832. status = "Hatchet count";
  3833. return State.CHECKBANK;
  3834. }
  3835. bestHatchetAvailable = bestHatchetAvailable();
  3836. final RSItem r = inventory.getItem(bestHatchetAvailable);
  3837. if (bestHatchetAvailable != -1 && r == null) {
  3838. status = "Upgrading Hatchet";
  3839. return State.CHECKBANK;
  3840. }
  3841. if (checkedBank && bestHatchetAvailable == -1) {
  3842. log("No hatchet available in your bank or inventory for your level.");
  3843. end = true;
  3844. }
  3845. }
  3846. if (wcLvl() >= 60 && (yewAfter60 || locked && yewSelected)) {
  3847. status = "Yews";
  3848. useBank = true;
  3849. return State.YEW;
  3850. }
  3851. if (trainFM) {
  3852. if (fmLvl() >= 30)
  3853. if (wcLvl() >= 30 && (!locked || locked && willowSelected)) {
  3854. status = "Burning Willows";
  3855. if (willowLocation == 1)
  3856. return State.WILLOWRIMM;
  3857. if (willowLocation == 2)
  3858. return State.WILLOWLUMB;
  3859. if (willowLocation == 3)
  3860. return State.WILLOWPORT;
  3861. if (willowLocation == 4)
  3862. return State.WILLOWDRAY;
  3863. }
  3864. if (fmLvl() >= 15) {
  3865. if (wcLvl() < 15 && (!locked || locked && treeSelected)) {
  3866. status = "Burn Trees";
  3867. return State.TREE;
  3868. }
  3869. if (wcLvl() >= 15 && (!locked || locked && oakSelected)) {
  3870. status = "Burn Oaks";
  3871. return State.OAK;
  3872. }
  3873. }
  3874. if (fmLvl() < 15 && (!locked || locked && treeSelected)) {
  3875. status = "Burn Trees";
  3876. return State.TREE;
  3877. }
  3878. status = "Option unavailable" + manageDots();
  3879. return State.error;
  3880. }
  3881. if (wcLvl() >= 30 && (!locked || locked && willowSelected)) {
  3882. status = "Willows";
  3883. switch (willowLocation) {
  3884. case 1:
  3885. if (bankWillow)
  3886. useBank = true;
  3887. else
  3888. useBank = false;
  3889. if (dropWillow)
  3890. drop = true;
  3891. else
  3892. drop = false;
  3893. if (powerchopWillow)
  3894. powerchop = true;
  3895. else
  3896. powerchop = false;
  3897. return State.WILLOWRIMM;
  3898. case 2:
  3899. if (bankWillow)
  3900. useBank = true;
  3901. else
  3902. useBank = false;
  3903. if (dropWillow)
  3904. drop = true;
  3905. else
  3906. drop = false;
  3907. if (powerchopWillow)
  3908. powerchop = true;
  3909. else
  3910. powerchop = false;
  3911. return State.WILLOWLUMB;
  3912. case 3:
  3913. if (bankWillow)
  3914. useBank = true;
  3915. else
  3916. useBank = false;
  3917. if (dropWillow)
  3918. drop = true;
  3919. else
  3920. drop = false;
  3921. if (powerchopWillow)
  3922. powerchop = true;
  3923. else
  3924. powerchop = false;
  3925. return State.WILLOWPORT;
  3926. case 4:
  3927. if (bankWillow)
  3928. useBank = true;
  3929. else
  3930. useBank = false;
  3931. if (dropWillow)
  3932. drop = true;
  3933. else
  3934. drop = false;
  3935. if (powerchopWillow)
  3936. powerchop = true;
  3937. else
  3938. powerchop = false;
  3939. return State.WILLOWDRAY;
  3940. }
  3941. }
  3942. if (wcLvl() >= 15 && (!locked && wcLvl() < 30 || locked && oakSelected)) {
  3943. status = "Oaks";
  3944. if (bankOak)
  3945. useBank = true;
  3946. else
  3947. useBank = false;
  3948. if (dropOak)
  3949. drop = true;
  3950. else
  3951. drop = false;
  3952. if (powerchopOak)
  3953. powerchop = true;
  3954. else
  3955. powerchop = false;
  3956. return State.OAK;
  3957. }
  3958. if (wcLvl() < 15 && (!locked || locked && treeSelected)) {
  3959. status = "Trees";
  3960. if (dropTree)
  3961. drop = true;
  3962. else
  3963. drop = false;
  3964. if (bankTree)
  3965. useBank = true;
  3966. else
  3967. useBank = false;
  3968. if (!dropTree && !bankTree) {
  3969. drop = false;
  3970. useBank = false;
  3971. }
  3972. return State.TREE;
  3973. }
  3974. status = "Option unavailable" + manageDots();
  3975. return State.error;
  3976. }
  3977. }
  3978.  
Add Comment
Please, Sign In to add comment