Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.88 KB | None | 0 0
  1. package Fighter;
  2.  
  3. import com.kbotpro.scriptsystem.events.PaintEventListener;
  4. import com.kbotpro.scriptsystem.events.ServerMessageListener;
  5. import com.kbotpro.scriptsystem.fetch.Game;
  6. import com.kbotpro.scriptsystem.fetch.Skills;
  7. import com.kbotpro.scriptsystem.input.jobs.MouseHoverJob;
  8. import com.kbotpro.scriptsystem.interfaces.Looped;
  9. import com.kbotpro.scriptsystem.runnable.Script;
  10. import com.kbotpro.scriptsystem.various.KTimer;
  11. import com.kbotpro.scriptsystem.wrappers.Character;
  12. import com.kbotpro.scriptsystem.wrappers.*;
  13.  
  14. import javax.swing.*;
  15. import java.awt.*;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.MouseAdapter;
  19. import java.awt.event.MouseEvent;
  20. import java.awt.geom.RoundRectangle2D;
  21. import java.io.*;
  22. import java.text.DecimalFormat;
  23. import java.text.DecimalFormatSymbols;
  24. import java.util.ArrayList;
  25. import java.util.Hashtable;
  26.  
  27. /**
  28. * Created by IntelliJ IDEA.
  29. * User: Vartan
  30. * Date: May 23, 2010
  31. * Time: 4:39:27 PM
  32. * To change this template use File | Settings | File Templates.
  33. */
  34. public class Fighter extends Script implements ServerMessageListener,
  35. PaintEventListener {
  36. int failSafe = 0;
  37. NPC fighting;
  38. NPC nextMonster;
  39. Tile seen;
  40. GroundItem[] before;
  41. KTimer failTimer;
  42. boolean bankFull;
  43. int xp=0;
  44. int startingXp=0;
  45.  
  46. int maxDist = 20;
  47. NPC last;
  48. String debug = "";
  49. int glow = 75;
  50. boolean glowd = false;
  51. MouseHoverJob hover;
  52. KTimer movingTimer;
  53. int deathTime = 3000;
  54. KTimer deathTimer;
  55. KTimer dropTimer;
  56. MainFrame main;
  57. Tile startingLoc;
  58. ItemSettings itemSettings;
  59. MonsterSettings monsterSettings;
  60. OtherSettings otherSettings;
  61. ConsumableSettings consumableSettings;
  62. BankWalkSettings bankWalkSettings;
  63. ArrayList<SavedItem> savedItems = new ArrayList<SavedItem>();
  64. ArrayList<SavedMonster> savedMonsters = new ArrayList<SavedMonster>();
  65. ArrayList<SavedConsumable> savedConsumables = new ArrayList<SavedConsumable>();
  66. ArrayList<SavedObstacle> savedObstacles = new ArrayList<SavedObstacle>();
  67. ArrayList<BWT> path = new ArrayList<BWT>();
  68. KTimer runTime;
  69.  
  70. KTimer underAttackTimer;
  71.  
  72. JFrame control;
  73. boolean started = false;
  74. KTimer fightingTimer;
  75. boolean isBanking = false;
  76. Hashtable<Integer,
  77. Integer> food = new Hashtable<Integer,
  78. Integer>();
  79.  
  80. public String[] statsArray = {
  81. "Attack", "Defence", "Strength", "Health", "Ranged",
  82. "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking",
  83. "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer",
  84. "Farming", "Runecrafting", "Hunter", "Construction", "Summoning", "Dungeoneering"
  85. };
  86.  
  87. public void onRepaint(Graphics graphics) {
  88. Graphics2D g = (Graphics2D) graphics;
  89. g.setColor(new Color(255, glow, 0, 255));
  90.  
  91. long ms = runTime.getTimeElapsed();
  92. double hours = (double) ms / 1000 / 60 / 60;
  93. drawDefaultPaint((Graphics2D) g, 20, 20, 200,
  94. "Running for:" + runTime.getFormattedTime(runTime.getTimeElapsed()), "Experience gained: " + format(xp - startingXp), "Experience per hour:" + format((int) ((xp - startingXp) / hours)));
  95. if (glowd) glow += 3;
  96. else glow -= 3;
  97. if (glow >= 150 || glow <= 50) glowd = !glowd;
  98. g.setColor(new Color(0, glow, 255, glow + 20));
  99.  
  100. try {
  101. if (nextMonster != null && onScreen(nextMonster))
  102. nextMonster.getModel().fillWireFrame(g);
  103. g.setColor(new Color(255, glow, 0, glow - 20));
  104. if (fighting != null && onScreen(fighting)) {
  105. fighting.getModel().fillWireFrame(g);
  106. g.setColor(new Color(255, glow, 0, 255));
  107. g.drawString("" + fighting.getHPPercent(), 50, 50);
  108. }
  109. int lastX = -1;
  110. int lastY = -1;
  111. for (SavedObstacle o : savedObstacles) {
  112. if (o.location.plane != game.getCurrentFloor())
  113. continue;
  114. Point m = calculations.tileToMinimap(o.location.toTile());
  115. PhysicalObject[] po = objects.getObjectsAt(o.location.toTile(), new int[]{o.ID});
  116. g.setColor(new Color(255, 255, 255, 50));
  117. if (po.length > 0 && po[0].onScreen())
  118. po[0].getModel().fillWireFrame(g);
  119. if (walking.mapCircle().contains(m)) {
  120. g.setColor(new Color(50, 100, 255));
  121. g.fillOval(m.x - 3, m.y - 3, 6, 6);
  122. }
  123. }
  124. if (isBanking || !started) {
  125. for (BWT tile : path) {
  126. Point m = calculations.tileToMinimap(tile.toTile());
  127. if (tile.plane != game.getCurrentFloor())
  128. continue;
  129. if (walking.mapCircle().contains(m)) {
  130. if (lastX != -1) {
  131. g.setColor(Color.GREEN);
  132. g.drawLine(lastX, lastY, m.x, m.y);
  133. }
  134. g.setColor(Color.RED);
  135. g.fillRect(m.x - 2, m.y - 2, 4, 4);
  136. lastX = m.x;
  137. lastY = m.y;
  138. } else {
  139. lastX = -1;
  140. lastY = -1;
  141. }
  142. }
  143. }
  144. if (bankWalkSettings.isVisible()) {
  145. PhysicalObject[] near = objects.getObjects(2);
  146. for (PhysicalObject o : near) {
  147. if (distanceTo(o.getLocation()) > 1)
  148. continue;
  149. Point p = calculations.tileToScreen(o.getLocation().getX(), o.getLocation().getY(), .5, .5, 0);
  150. g.setColor(Color.RED);
  151. g.fillOval(p.x - 2, p.y - 2, 4, 4);
  152. String write = o.getID() + ":" + "(" + o.getLocation().getX() + "," + o.getLocation().getY() + "," + game.getCurrentFloor() + ")";
  153. for (int i = 4; i > 0; i--) {
  154. g.setColor(new Color(255 - (51 * i), 0, 0, 255 - (51 * i)));
  155. g.drawString(write, p.x + 5 - i, p.y + 3);
  156. g.drawString(write, p.x + 5 + i, p.y + 3);
  157. g.drawString(write, p.x + 5, p.y + 3 - i);
  158. g.drawString(write, p.x + 5, p.y + i);
  159. g.drawString(write, p.x + 5 - i, p.y + 3 + i);
  160. g.drawString(write, p.x + 5 + i, p.y + 3 - i);
  161.  
  162. }
  163. g.setColor(Color.BLACK);
  164. g.drawString(write, p.x + 5, p.y + 3);
  165. g.setColor(Color.WHITE);
  166. g.drawString(write, p.x + 4, p.y + 2);
  167. }
  168.  
  169. }
  170. } catch (Exception e) {
  171.  
  172. }
  173.  
  174.  
  175. }
  176.  
  177. public void onServerMessage(String s) {
  178. if (s.contains("is fighting that")) movingTimer = new KTimer(1);
  179. if (s.equalsIgnoreCase("I'm already under attack.")) underAttackTimer = new KTimer(7000);
  180.  
  181. }
  182.  
  183.  
  184. @Override
  185. public void registerWorkers() {
  186. createWorker(new Looped() {
  187. public int loop() {
  188. try {
  189. mouse.setDefaultSpeed(random(3.0, 4.0));
  190.  
  191. if (failTimer.isDone()) {
  192. game.exitGame();
  193. stopAllScripts();
  194. return -1;
  195. }
  196. if (!started) {
  197. if (isLoggedIn() && path.size() > 0) {
  198. startingLoc = path.get(path.size() - 1).toTile();
  199. }
  200. failTimer = new KTimer(300000);
  201. return 50;
  202. }
  203. if(startingXp==0) {
  204. startingXp = skills.getExperience(Skills.SKILL_ATTACK) + skills.getExperience(Skills.SKILL_STRENGTH) + skills.getExperience(Skills.SKILL_DEFENSE) + skills.getExperience(Skills.SKILL_HITPOINTS) + skills.getExperience(Skills.SKILL_RANGE);
  205. }
  206. xp = skills.getExperience(Skills.SKILL_ATTACK) + skills.getExperience(Skills.SKILL_STRENGTH) + skills.getExperience(Skills.SKILL_DEFENSE) + skills.getExperience(Skills.SKILL_HITPOINTS) + skills.getExperience(Skills.SKILL_RANGE);
  207. game.openTab(Game.TAB_INVENTORY);
  208. int dist = 0;
  209. if (path.size() > 0) {
  210. if (bankFull) {
  211. if (inventory.isFull()) {
  212. return walkToBank();
  213. }
  214. }
  215. for (SavedConsumable c : savedConsumables) {
  216. if (c.bank < 0)
  217. continue;
  218. if (c.type.equals("Health")) {
  219. if (!inventory.contains(c.name)) {
  220. log("Inventory doesn't contain food: " + c.name);
  221.  
  222. return walkToBank();
  223. } else {
  224. }
  225. } else {
  226. boolean has = false;
  227.  
  228. for (Item i : inventory.getItems()) {
  229.  
  230. if (i.getName().toLowerCase().startsWith(c.name.toLowerCase())) {
  231. has = true;
  232. }
  233. }
  234. if (!has) {
  235. log("Inventory doesn't contain drink:" + c.name);
  236. return walkToBank();
  237. }
  238. }
  239. }
  240. }
  241. if (getDistanceTo(startingLoc) > maxDist || !calculations.canReach(startingLoc, false) || (dist = getRealDistanceTo(startingLoc, false)) > maxDist || dist < 0) {
  242. if (path.size() > 0)
  243. return walkFromBank();
  244. }
  245. isBanking = false;
  246. return fight();
  247. } catch (Exception e) {
  248. e.printStackTrace();
  249. }
  250. return 50; //wtf
  251.  
  252. }
  253. });
  254. createWorker(new Looped() {
  255.  
  256. public int loop() {
  257. if (failTimer.isDone()) return -1;
  258. nextMonster = nearest(15, true);
  259. if (fighting != null) seen = fighting.getLocation();
  260. return 100;
  261. }
  262. });
  263. }
  264.  
  265. public int bank() {
  266. camera.setAngleTo(path.get(0).toTile());
  267.  
  268. if (!bank.isOpen()) {
  269. bank.openClosestBank();
  270. return 2000;
  271. }
  272. bank.depositAllInventory();
  273. SavedConsumable last = null;
  274. for (SavedConsumable c : savedConsumables) {
  275. if (c.bank == 0) {
  276. last = c;
  277. continue;
  278. }
  279. if (!withdraw(c))
  280. return 50;
  281. }
  282. if (last != null)
  283. withdraw(last);
  284. bank.close();
  285. return 2000;
  286. }
  287.  
  288. public boolean withdraw(SavedConsumable c) {
  289. Item[] bankItems = bank.getItems();
  290. for (Item item : bankItems) {
  291. boolean good = false;
  292.  
  293. if (c.type.equalsIgnoreCase("Health")) {
  294. if (c.name.trim().equalsIgnoreCase(item.getName().trim()))
  295. good = true;
  296. } else {
  297. if (item.getName().toLowerCase().startsWith(c.name.toLowerCase()))
  298. good = true;
  299. }
  300. if (good) {
  301. bank.scrollToItem(item);
  302. if (c.bank != 0)
  303. bank.withdrawX(item.getID(), c.bank);
  304. else
  305. bank.withdrawAll(item.getID());
  306. return true;
  307. }
  308. }
  309. return false;
  310. }
  311.  
  312. public int walkFromBank() {
  313. isBanking = true;
  314. if (getMyPlayer().isMoving())
  315. return 50;
  316. if (bank.isOpen())
  317. bank.close();
  318. int bestIndex = -1;
  319. for (int i = 0; i < path.size(); i++) {
  320. BWT tile = path.get(i);
  321. if (distanceTo(tile.toTile()) > 30 || !calculations.canReach(tile.toTile(), false))
  322. continue;
  323. if (walking.mapCircle().contains(getCalculations().tileToMinimap(tile.toTile()))) {
  324. bestIndex = i;
  325. }
  326.  
  327. }
  328. if (bestIndex == -1)
  329. return 50; //nooooo
  330. PhysicalObject closest = null;
  331. int closestDist = 999;
  332. String closestAction = "";
  333.  
  334. if (bestIndex < path.size() && (distanceTo(path.get(bestIndex + 1).toTile()) > 30 || !calculations.canReach(path.get(bestIndex + 1).toTile(), false))) {
  335. for (SavedObstacle o : savedObstacles) {
  336. try {
  337. if (distanceTo(o.location.toTile()) > 30)
  338. continue;
  339. if (game.getCurrentFloor() != o.location.plane || o.direction == SavedObstacle.TO_BANK)
  340. continue;
  341. PhysicalObject[] po = objects.getObjectsAt(o.location.toTile(), new int[]{o.ID});
  342. if (po.length <= 0)
  343. continue;
  344. PhysicalObject obstacle = po[0];
  345. if (obstacle == null || !calculations.canReach(obstacle.getLocation(), true))
  346. continue;
  347.  
  348. if (path.get(bestIndex).toTile().distanceTo(obstacle.getLocation()) < closestDist) {
  349. closestDist = path.get(bestIndex).toTile().distanceTo(obstacle.getLocation());
  350. closest = obstacle;
  351. closestAction = o.action;
  352. log(closestAction);
  353. }
  354. } catch (Exception e) {
  355.  
  356. }
  357. }
  358. if (closest == null) {
  359. return 50;
  360. }
  361. log(closestAction);
  362. if (calculations.canReach(closest.getLocation(), true)) {
  363. if (closest.doAction(closestAction) && menu.contains(closestAction))
  364. return 2000;
  365. }
  366. }
  367. failTimer = new KTimer(300000);
  368. walkPath(fixPath(path.get(bestIndex).toTile()));
  369. return 1800;
  370. }
  371.  
  372. public int walkToBank() {
  373. isBanking = true;
  374. if (calculations.canReach(path.get(0).toTile(), false) && distanceTo(path.get(0).toTile()) < 14) {
  375. return bank();
  376. }
  377. if (getMyPlayer().isMoving())
  378. return 50;
  379.  
  380. int bestIndex = -1;
  381. for (int i = path.size() - 1; i >= 0; i--) {
  382. BWT tile = path.get(i);
  383. if (distanceTo(tile.toTile()) > 30 || !calculations.canReach(tile.toTile(), false))
  384. continue;
  385. if (walking.mapCircle().contains(getCalculations().tileToMinimap(tile.toTile()))) {
  386. bestIndex = i;
  387. }
  388.  
  389. }
  390. if (bestIndex == -1)
  391. return 50; //nooooo
  392. PhysicalObject closest = null;
  393. int closestDist = 999;
  394. String closestAction = "";
  395.  
  396. if (bestIndex > 0 && (distanceTo(path.get(bestIndex - 1).toTile()) > 30 || !calculations.canReach(path.get(bestIndex - 1).toTile(), false))) {
  397. for (SavedObstacle o : savedObstacles) {
  398. try {
  399. if (distanceTo(o.location.toTile()) > 30)
  400. continue;
  401. if (game.getCurrentFloor() != o.location.plane || o.direction == SavedObstacle.FROM_BANK)
  402. continue;
  403. PhysicalObject[] po = objects.getObjectsAt(o.location.toTile(), new int[]{o.ID});
  404. if (po.length <= 0)
  405. continue;
  406. PhysicalObject obstacle = po[0];
  407. if (obstacle == null || !calculations.canReach(obstacle.getLocation(), true))
  408. continue;
  409.  
  410. if (path.get(bestIndex).toTile().distanceTo(obstacle.getLocation()) < closestDist) {
  411. closestDist = path.get(bestIndex).toTile().distanceTo(obstacle.getLocation());
  412. closest = obstacle;
  413. closestAction = o.action;
  414. log(closestAction);
  415. }
  416. } catch (Exception e) {
  417.  
  418. }
  419. }
  420. if (closest == null) {
  421. return 50;
  422. }
  423. log(closestAction);
  424. if (calculations.canReach(closest.getLocation(), true)) {
  425. if (closest.doAction(closestAction) && menu.contains(closestAction))
  426. return 2000;
  427. }
  428. }
  429. failTimer = new KTimer(300000);
  430. walkPath(fixPath(path.get(bestIndex).toTile()));
  431. return 1800;
  432. }
  433.  
  434. private boolean inCombat() {
  435.  
  436.  
  437. Character c;
  438. if (fighting == null || fighting.getHPPercent() == 0) return false;
  439.  
  440. if (getMyPlayer().getAnimation() != -1) {
  441. fightingTimer = new KTimer(10000);
  442. return true;
  443. }
  444. if (fightingTimer.isDone()) return false;
  445. return (fighting) != null && (c = fighting.getInteracting()) != null && c.equals(getMyPlayer());
  446.  
  447. }
  448.  
  449. public boolean consume() {
  450. for (SavedConsumable c : savedConsumables) {
  451. if (c.type.equals("Health")) {
  452. if (eat(c))
  453. return true;
  454. continue;
  455. }
  456. if (getCurrentLevel(statIndex(c.type)) <= c.at) {
  457. for (Item i : inventory.getItems()) {
  458. if (i.getName().toLowerCase().startsWith(c.name.toLowerCase())) {
  459. if (i.doClick())
  460. return true;
  461. }
  462. }
  463. }
  464. }
  465.  
  466. return false;
  467. }
  468.  
  469. public int getCurrentLevel(int skill) {
  470. int[] levels = getClient().getLevels();
  471. if (levels == null || levels.length == 0 || skill < 0 || skill >= levels.length)
  472. return -1;
  473. return levels[skill];
  474. }
  475.  
  476. public boolean eat(SavedConsumable c) {
  477. int hp = hp();
  478. int startingHp = hp;
  479. boolean wait = false;
  480. if (hp > c.at) return false;
  481.  
  482. for (Item i : inventory.getItems()) {
  483. if (hp + c.heal >= skills.getLevel(Skills.SKILL_HITPOINTS) * 10) break;
  484. if (i.getName().startsWith(c.name)) {
  485. if (wait) sleep(random(1800, 2000));
  486. if (i.doClick()) {
  487. hp += c.heal;
  488. }
  489. wait = true;
  490.  
  491. }
  492. }
  493.  
  494. return hp != startingHp;
  495. }
  496.  
  497. public int statIndex(String
  498. s) {
  499. for (int i = 0; i < statsArray.length; i++)
  500. if (s.equals(statsArray[i])) return i;
  501. return -1;
  502. }
  503.  
  504. public boolean canRace(NPC
  505. m) {
  506. if (m == null || m.isInCombat() || !calculations.canReach(m.getLocation(), false)) return false;
  507. Player[] people = players.getPlayers();
  508. int max = -1;
  509. for (Player person : people) {
  510. if (person != getMyPlayer()) {
  511. if (person.getInteracting() == m && (getRealDistanceTo(person.getLocation(), m.getLocation(), false) < getRealDistanceTo(m.getLocation(), false) + 1 || person.getAnimation() != -1))
  512. return false;
  513.  
  514. }
  515. }
  516.  
  517.  
  518. return true;
  519. }
  520.  
  521. public int hp() {
  522. return game.getLifePoints();
  523. /*
  524. try {
  525. IComponent hpi = interfaces.getComponent(748, 8);
  526. return Integer.parseInt(hpi.getText());
  527. } catch (Exception e) {
  528. e.printStackTrace();
  529. }
  530. return -1; */
  531.  
  532. }
  533.  
  534. public NPC nearest(
  535. int range, boolean next) {
  536. NPC[] list = npcs.getNPCs();
  537. NPC best = null;
  538. for (NPC cur : list) {
  539. try {
  540. boolean pass = false;
  541. for (int i = 0; i < savedMonsters.size(); i++) {
  542. if ((savedMonsters.get(i).ID == -1 || savedMonsters.get(i).ID == cur.getID()) && cur.getName().equalsIgnoreCase(savedMonsters.get(i).name)) {
  543. deathTime = savedMonsters.get(i).deathTime;
  544. pass = true;
  545. break;
  546. }
  547. }
  548. int extra = 0;
  549. if (getMyPlayer().isMoving()) extra = 4;
  550. if (!cur.equals(fighting) && getRealDistanceTo(cur.getLocation(), startingLoc, true) < maxDist && pass && cur.getHPPercent() >= 1 && getRealDistanceTo(cur.getLocation(), false) <= range) {
  551. if (!next && cur.getInteracting() == getMyPlayer()) return cur;
  552. if (!cur.isInCombat() && canRace(cur) && cur.getHPPercent() != 0) {
  553. if (best == null || getRealDistanceTo(cur.getLocation(), false) + extra <= getRealDistanceTo(best.getLocation(), false) || (!best.onScreen() && getRealDistanceTo(cur.getLocation(), false) + 7 <= distanceTo(best)))
  554. best = cur;
  555. }
  556. }
  557.  
  558. } catch (Exception e) {
  559.  
  560. }
  561. }
  562.  
  563. return best;
  564. }
  565.  
  566. public void onResume() {
  567. failTimer = new KTimer(300000);
  568. }
  569.  
  570. private int fight() {
  571.  
  572. try {
  573. if (consume()) return random(2400, 2500);
  574. if (walking.getEnergy() > random(random(random(random(30, 90), 90), 90), 90)) {
  575. walking.setRunning(true);
  576. sleep(1000);
  577. }
  578. fighting = (NPC) getMyPlayer().getInteracting();
  579. boolean shouldChange = false;
  580. if (fighting != null && nextMonster != null && getRealDistanceTo(fighting.getLocation(), false) > getRealDistanceTo(nextMonster.getLocation(), false) + 5)
  581. shouldChange = true;
  582. if (!shouldChange && getMyPlayer().isMoving() && canRace(fighting)) {
  583. movingTimer = new KTimer(1300);
  584. return 50;
  585. }
  586. if (deathTimer.isDone() && fighting != null && fighting.getHPPercent() == 0) {
  587. Point loc = calculations.tileToScreen(fighting.getLocation().getX(), fighting.getLocation().getY(), random(.4, .6), random(.4, .6), 0);
  588. if (deathTime > 0) mouse.moveMouse(loc);
  589.  
  590. }
  591. if (inCombat()) {
  592. fightingTimer = new KTimer(10000);
  593. last = fighting;
  594. dropTimer = new KTimer(deathTime);
  595. deathTimer = new KTimer(5000);
  596. before = groundItems.getItemsAt(seen);
  597. failTimer = new KTimer(300000);
  598.  
  599. } else {
  600. if (!underAttackTimer.isDone()) return 50;
  601. if (!shouldChange && !movingTimer.isDone()) return 50;
  602.  
  603. if (last == null || (seen != null && groundItems.getItemsAt(seen).length != before.length))
  604. dropTimer = new KTimer(0);
  605.  
  606. int[] dropIdArray = new int[savedItems.size()];
  607. for (int i = 0; i < savedItems.size(); i++) {
  608. dropIdArray[i] = savedItems.get(i).ID;
  609. }
  610. GroundItem[] ground = groundItems.getItems(3, dropIdArray);
  611. for (GroundItem g : ground) {
  612. for (SavedItem savedItem : savedItems)
  613. if (savedItem.ID == g.getID()) {
  614. if (!inventory.isFull() || inventory.getCount(true, savedItem.ID) != inventory.getCount(false, savedItem.ID)) {
  615. if (g.doAction("Take " + savedItem.name)) {
  616. dropTimer = new KTimer(0);
  617. return random(1200, 1300);
  618. }
  619. }
  620. }
  621. }
  622.  
  623. if (getRealDistanceTo(startingLoc, false) > maxDist) {
  624. walkPath(fixPath(startingLoc));
  625. movingTimer = new KTimer(1300);
  626. return 50;
  627. }
  628. if (!dropTimer.isDone()) return 50;
  629. if (nextMonster.onScreen() && nextMonster.doAction("Attack " + nextMonster.getName()) && menu.contains("Attack " + nextMonster.getName())) {
  630. movingTimer = new KTimer(1300);
  631. failSafe = 0;
  632. return random(600, 750);
  633. } else {
  634. if (failSafe > 3 || getRealDistanceTo(nextMonster.getLocation(), false) > 4) {
  635. walkPath(fixPath(nextMonster.getLocation()));
  636. movingTimer = new KTimer(1300);
  637. int angleTo = camera.getAngleTo(nextMonster.getLocation());
  638. double angle = camera.getAngle();
  639. if((angleTo-angle)%360>40)
  640. camera.setAngle(angleTo);
  641. } else if (failSafe > 1 || !nextMonster.onScreen()) {
  642. camera.setAngleTo(nextMonster.getLocation());
  643. int angleTo = camera.getAngleTo(nextMonster.getLocation());
  644. double angle = camera.getAngle();
  645. if((angleTo-angle)%360>40)
  646. camera.setAngle(angleTo);
  647. }
  648. camera.setAltitude(false);
  649. failSafe++;
  650. }
  651. return 50;
  652. }
  653. if (nextMonster == null) return 50;
  654. if (!nextMonster.onScreen() && getRealDistanceTo(nextMonster.getLocation(), false) > 6)
  655. camera.setAngleTo(nextMonster.getLocation());
  656.  
  657. } catch (Exception e) {
  658. e.printStackTrace();
  659. }
  660. return 50;
  661.  
  662. }
  663. public boolean onScreen(NPC n) {
  664. Tile l = n.getLocation();
  665. Point p = calculations.tileToScreen(l.getX(),l.getY(),.5,.5,1);
  666. return calculations.onScreen(p);
  667. }
  668. @Override
  669. public void stop() {
  670. closeWindows(true);
  671.  
  672. }
  673.  
  674. public void closeWindows(boolean m) {
  675. if (m && main != null) main.dispose();
  676. if (monsterSettings != null) monsterSettings.dispose();
  677. if (itemSettings != null) itemSettings.dispose();
  678. if (consumableSettings != null) consumableSettings.dispose();
  679. if (otherSettings != null) otherSettings.dispose();
  680. if (control != null) control.dispose();
  681. if (bankWalkSettings != null) bankWalkSettings.dispose();
  682. }
  683.  
  684. @Override
  685. public void onStart() {
  686. runTime = new KTimer();
  687. failTimer = new KTimer(300000);
  688. main = new MainFrame();
  689. deathTimer = new KTimer(0);
  690. dropTimer = new KTimer(0);
  691. fightingTimer = new KTimer(10000);
  692. underAttackTimer = new KTimer(1);
  693. startingLoc = getMyPlayer().getLocation();
  694.  
  695. movingTimer = new KTimer(0);
  696. mouse.setDefaultSpeed(random(3.0, 4.0));
  697. }
  698.  
  699. @Override
  700. public String getName() {
  701. return "Mike's Fighter";
  702.  
  703. }
  704.  
  705. private Tile[] fixPath(Tile
  706. t) {
  707. int startX = getMyPlayer().getLocation().getX();
  708. int startY = getMyPlayer().getLocation().getY();
  709. int destinationX = t.getX();
  710. int destinationY = t.getY();
  711. double dx,
  712. dy;
  713. ArrayList<Tile> list = new ArrayList<Tile>();
  714. list.add(new Tile(startX, startY));
  715. while (Math.hypot(destinationY - startY, destinationX - startX) > 8) {
  716. dx = destinationX - startX;
  717. dy = destinationY - startY;
  718. int gamble = random(1, 4);
  719. while (Math.hypot(dx, dy) > gamble) {
  720. dx *= .95;
  721. dy *= .95;
  722. }
  723. startX += (int) dx + random(-2, 3);
  724. startY += (int) dy + random(-2, 3);
  725. list.add(new Tile(startX, startY));
  726. }
  727. list.add(new Tile(destinationX, destinationY));
  728.  
  729. return list.toArray(new Tile[list.size()]);
  730. }
  731.  
  732. public boolean walkPath(Tile[] path) {
  733. if (path == null || path.length == 0) {
  734. throw new IllegalArgumentException("path can not be null or empty");
  735. }
  736. if (walking.getEnergy() > random(30, 99)) {
  737. walking.setRunning(true);
  738. }
  739. Tile last = null;
  740. for (Tile aPath : path) {
  741. if (walking.mapCircle().contains(getCalculations().tileToMinimap(aPath))) {
  742. last = aPath;
  743. }
  744. }
  745. if (last != null) {
  746. walking.walkToMM(new Tile(last.getX(), last.getY()));
  747. return true;
  748. }
  749. return false;
  750. }
  751.  
  752. public void saveSettings(File f) {
  753. String raw = "";
  754. for (SavedMonster m : savedMonsters) {
  755. raw += "monster\t" + m.name + "\t" + m.ID + "\t" + m.deathTime + "\n";
  756. }
  757. for (SavedItem i : savedItems) {
  758. raw += "item\t" + i.name + "\t" + i.ID + "\t" + i.alch + "\n";
  759. }
  760. for (SavedConsumable c : savedConsumables) {
  761. raw += "consumable\t" + c.name + "\t" + c.at + "\t" + c.type + "\t" + c.bank + "\t" + c.heal + "\n";
  762. }
  763. for (SavedObstacle o : savedObstacles) {
  764. raw += "obstacle\t" + o.location.x + "\t" + o.location.y + "\t" + o.location.plane + "\t" + o.ID + "\t" + o.action + "\t" + o.direction + "\n";
  765. }
  766. for (BWT tile : path) {
  767. raw += "path\t" + tile.x + "\t" + tile.y + "\t" + tile.plane + "\n";
  768.  
  769. }
  770. raw += "maxdistance\t" + otherSettings.maxDistField.getText() + "\n";
  771. raw += "bankfull\t" + bankFull;
  772. try {
  773. PrintWriter pw = new PrintWriter(new FileWriter(f, false));
  774. pw.println(raw);
  775. pw.close();
  776. } catch (Exception e) {
  777. JOptionPane.showMessageDialog(new JFrame("ERROR"), "You cannot save it here! Save it to the same folder as your KBot jar!");
  778. log(e.getMessage());
  779. }
  780. }
  781.  
  782. private String readFile(String filePath) throws java.io.IOException {
  783. byte[] buffer = new byte[(int) new File(filePath).length()];
  784. BufferedInputStream f = new BufferedInputStream(new FileInputStream(filePath));
  785. f.read(buffer);
  786. return new String(buffer);
  787. }
  788.  
  789. public void loadSettings(File f) {
  790. BufferedReader br;
  791. savedItems = new ArrayList<SavedItem>();
  792. savedMonsters = new ArrayList<SavedMonster>();
  793. savedConsumables = new ArrayList<SavedConsumable>();
  794. savedObstacles = new ArrayList<SavedObstacle>();
  795. path = new ArrayList<BWT>();
  796. try {
  797. String[] s = readFile(f.getPath()).split("\n");
  798.  
  799. // dis.available() returns 0 if the file does not have more lines.
  800. for (String line : s) {
  801. String[] v = line.split("\t");
  802. log(line);
  803. if (v[0].equals("monster")) {
  804. savedMonsters.add(new SavedMonster(Integer.parseInt(v[2]), v[1], Integer.parseInt(v[3])));
  805. continue;
  806. }
  807. if (v[0].equals("item")) {
  808. savedItems.add(new SavedItem(Integer.parseInt(v[2]), v[1], Boolean.parseBoolean(v[3])));
  809. continue;
  810. }
  811. if (v[0].equals("consumable")) {
  812. savedConsumables.add(new SavedConsumable(v[1], Integer.parseInt(v[2]), v[3], Integer.parseInt(v[4]), Integer.parseInt(v[5])));
  813. continue;
  814. }
  815. if (v[0].equals("obstacle")) {
  816. savedObstacles.add(new SavedObstacle(new BWT(Integer.parseInt(v[1]), Integer.parseInt(v[2]), Integer.parseInt(v[3])), Integer.parseInt(v[4]), v[5], Integer.parseInt(v[6])));
  817. continue;
  818. }
  819. if (v[0].equals("path")) {
  820. path.add(new BWT(Integer.parseInt(v[1]), Integer.parseInt(v[2]), Integer.parseInt(v[3])));
  821. continue;
  822. }
  823.  
  824. if (v[0].equals("maxdistance"))
  825. maxDist = Integer.parseInt(v[1]);
  826. if (v[0].equals("bankfull"))
  827. bankFull = Boolean.parseBoolean(v[1]);
  828.  
  829. }
  830.  
  831. // dispose all the resources after using them.
  832. } catch (Exception e) {
  833. e.printStackTrace();
  834. log(e.getMessage());
  835. }
  836. }
  837.  
  838.  
  839. class MainFrame extends JFrame {
  840. JButton itemSettingsButton;
  841. JButton combatSettingsButton;
  842. JButton otherSettingsButton;
  843. JButton consumableSettingsButton;
  844. JButton startScript;
  845. JButton exportButton;
  846. JButton importButton;
  847. JButton bankWalkSettingsButton;
  848.  
  849. public MainFrame() {
  850.  
  851. itemSettings = new ItemSettings();
  852. monsterSettings = new MonsterSettings();
  853. otherSettings = new OtherSettings();
  854. consumableSettings = new ConsumableSettings();
  855. bankWalkSettings = new BankWalkSettings();
  856. setLayout(new GridBagLayout());
  857. GridBagConstraints c = new GridBagConstraints();
  858. c.fill = GridBagConstraints.HORIZONTAL;
  859. c.weightx = 1.0; //request any extra vertical space
  860. c.insets = new Insets(3, 3, 3, 3);
  861. setTitle("Mike's Fighter");
  862. itemSettingsButton = new JButton("Item Settings");
  863. c.gridx = 0;
  864. c.gridy = 0;
  865. add(itemSettingsButton, c);
  866. itemSettingsButton.addMouseListener(new MouseAdapter() {
  867. public void mouseClicked(MouseEvent e) {
  868. itemSettings.setVisible(true);
  869. }
  870. });
  871. combatSettingsButton = new JButton("Monster Settings");
  872. c.gridx = 1;
  873. add(combatSettingsButton, c);
  874. combatSettingsButton.addMouseListener(new MouseAdapter() {
  875. public void mouseClicked(MouseEvent e) {
  876. monsterSettings.setVisible(true);
  877. }
  878. });
  879. consumableSettingsButton = new JButton("Consumable Settings");
  880. c.gridy = 0;
  881. c.gridx = 2;
  882. add(consumableSettingsButton, c);
  883. consumableSettingsButton.addMouseListener(new MouseAdapter() {
  884. public void mouseClicked(MouseEvent e) {
  885. consumableSettings.setVisible(true);
  886. }
  887. });
  888. otherSettingsButton = new JButton("Other Settings");
  889. c.gridy = 1;
  890. c.gridx = 0;
  891. add(otherSettingsButton, c);
  892. otherSettingsButton.addMouseListener(new MouseAdapter() {
  893. public void mouseClicked(MouseEvent e) {
  894. otherSettings.setVisible(true);
  895. }
  896. });
  897. exportButton = new JButton("Save Settings");
  898. exportButton.addMouseListener(new MouseAdapter() {
  899. public void mouseClicked(MouseEvent e) {
  900. bankFull = otherSettings.bankType.isSelected();
  901. JFileChooser fc = new JFileChooser();
  902. int rc = fc.showDialog(null, "WILL ONLY SAVE IN YOUR FOLDER WITH kbot.jar");
  903. fc.setCurrentDirectory(new File("."));
  904. if (rc == JFileChooser.APPROVE_OPTION) {
  905. File file = fc.getSelectedFile();
  906. String filename = file.getAbsolutePath();
  907. saveSettings(file);
  908. }
  909. }
  910. });
  911. c.gridx = 1;
  912. add(exportButton, c);
  913.  
  914. importButton = new JButton("Load Settings");
  915. importButton.addMouseListener(new MouseAdapter() {
  916. public void mouseClicked(MouseEvent e) {
  917. JFileChooser fc = new JFileChooser();
  918. int rc = fc.showDialog(null, "Load fighter settings");
  919. if (rc == JFileChooser.APPROVE_OPTION) {
  920. File file = fc.getSelectedFile();
  921. String filename = file.getAbsolutePath();
  922. loadSettings(file);
  923. closeWindows(false);
  924.  
  925. itemSettings = new ItemSettings();
  926. monsterSettings = new MonsterSettings();
  927. otherSettings = new OtherSettings();
  928. consumableSettings = new ConsumableSettings();
  929. bankWalkSettings = new BankWalkSettings();
  930. }
  931. }
  932. });
  933. c.gridx = 2;
  934. add(importButton, c);
  935.  
  936. bankWalkSettingsButton = new JButton("Bank Walk");
  937. c.gridx = 0;
  938. c.gridy = 2;
  939. add(bankWalkSettingsButton, c);
  940. bankWalkSettingsButton.addMouseListener(new MouseAdapter() {
  941. public void mouseClicked(MouseEvent e) {
  942. bankWalkSettings.setVisible(true);
  943. }
  944. });
  945.  
  946. startScript = new JButton("Start Script");
  947. c.gridx = 1;
  948. c.gridy = 2;
  949. c.gridwidth = 2;
  950.  
  951. add(startScript, c);
  952. startScript.addMouseListener(new MouseAdapter() {
  953. public void mouseClicked(MouseEvent e) {
  954. dispose();
  955. started = true;
  956. bankFull = otherSettings.bankType.isSelected();
  957. runTime = new KTimer();
  958. maxDist = Integer.parseInt(otherSettings.maxDistField.getText());
  959. }
  960. });
  961. setVisible(true);
  962. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  963. setSize(400, 120);
  964. setResizable(false);
  965. setLocationRelativeTo(getRootPane());
  966. }
  967.  
  968. }
  969.  
  970.  
  971. class ItemSettings extends JFrame {
  972. JLabel label;
  973.  
  974.  
  975. public ItemSettings() {
  976.  
  977. setTitle("Item Settings");
  978. setSize(300, 300);
  979. setResizable(false);
  980.  
  981. JScrollPane scroll = new JScrollPane();
  982. JPanel panel = new JPanel();
  983. panel.setSize(300, 300);
  984. setLocationRelativeTo(getRootPane());
  985. scroll.setPreferredSize(new Dimension(200, 200));
  986.  
  987. panel.setLayout(new GridBagLayout());
  988. GridBagConstraints c = new GridBagConstraints();
  989. c.fill = GridBagConstraints.HORIZONTAL;
  990. c.weightx = 1.0; //request any extra vertical space
  991. c.insets = new Insets(3, 3, 3, 3);
  992. c.gridx = 0;
  993. c.gridy = 0;
  994. add(scroll);
  995. scroll.getViewport().add(panel);
  996. JButton newb = new JButton("Create new Item");
  997. panel.add(newb, c);
  998. newb.addMouseListener(new MouseAdapter() {
  999. public void mouseClicked(MouseEvent e) {
  1000. savedItems.add(new SavedItem(-1, "New Item", false));
  1001. itemSettings.dispose();
  1002. itemSettings = new ItemSettings();
  1003. itemSettings.setVisible(true);
  1004.  
  1005. }
  1006. });
  1007. for (int i = 0; i < savedItems.size(); i++) {
  1008. c.gridy++;
  1009. final int s = i;
  1010. JButton item = new JButton(savedItems.get(i).name);
  1011. panel.add(item, c);
  1012. item.addMouseListener(new MouseAdapter() {
  1013. public void mouseClicked(MouseEvent e) {
  1014. if (control != null) control.dispose();
  1015. control = new ItemControl(s);
  1016. control.setVisible(true);
  1017. }
  1018. });
  1019.  
  1020. }
  1021.  
  1022. }
  1023. }
  1024.  
  1025. class ItemControl extends JFrame {
  1026. public ItemControl(final int index) {
  1027. setLayout(new FlowLayout());
  1028.  
  1029. final String itemName = savedItems.get(index).name;
  1030. final int itemID = savedItems.get(index).ID;
  1031. final boolean alch = savedItems.get(index).alch;
  1032. setTitle("Item Control - " + itemName);
  1033. final JTextField nameField = new JTextField("" + itemName);
  1034. nameField.setColumns(10);
  1035. final JTextField idField = new JTextField("" + itemID);
  1036. idField.setColumns(5);
  1037. final JCheckBox alchField = new JCheckBox("Alch");
  1038. alchField.setSelected(alch);
  1039. final JButton save = new JButton("Save");
  1040. final JButton delete = new JButton("Delete");
  1041. final JLabel info = new JLabel("Use the Grand Exchange or the built-in inventory debugger to get item IDs.");
  1042. Container c = getContentPane();
  1043. setSize(420, 80);
  1044. setLocationRelativeTo(getRootPane());
  1045. c.add(nameField);
  1046. c.add(idField);
  1047. c.add(alchField);
  1048. c.add(save);
  1049. c.add(delete);
  1050. c.add(info);
  1051. save.addMouseListener(new MouseAdapter() {
  1052. public void mouseClicked(MouseEvent e) {
  1053. savedItems.get(index).name = nameField.getText();
  1054. savedItems.get(index).ID = Integer.parseInt(idField.getText());
  1055. savedItems.get(index).alch = alchField.isSelected();
  1056. itemSettings.dispose();
  1057. itemSettings = new ItemSettings();
  1058. itemSettings.setVisible(true);
  1059. control.dispose();
  1060.  
  1061. }
  1062. });
  1063. delete.addMouseListener(new MouseAdapter() {
  1064. public void mouseClicked(MouseEvent e) {
  1065. savedItems.remove(index);
  1066. itemSettings.dispose();
  1067. itemSettings = new ItemSettings();
  1068. itemSettings.setVisible(true);
  1069. control.dispose();
  1070.  
  1071. }
  1072. });
  1073. setResizable(false);
  1074. }
  1075. }
  1076.  
  1077. class ConsumableSettings extends JFrame {
  1078. JLabel label;
  1079.  
  1080.  
  1081. public ConsumableSettings() {
  1082.  
  1083. setTitle("Consumable Settings");
  1084. setSize(300, 300);
  1085. setResizable(false);
  1086.  
  1087. JScrollPane scroll = new JScrollPane();
  1088. JPanel panel = new JPanel();
  1089. panel.setSize(300, 300);
  1090. setLocationRelativeTo(getRootPane());
  1091. scroll.setPreferredSize(new Dimension(200, 200));
  1092.  
  1093. panel.setLayout(new GridBagLayout());
  1094. GridBagConstraints c = new GridBagConstraints();
  1095. c.fill = GridBagConstraints.HORIZONTAL;
  1096. c.weightx = 1.0; //request any extra vertical space
  1097. c.insets = new Insets(3, 3, 3, 3);
  1098. c.gridx = 0;
  1099. c.gridy = 0;
  1100. add(scroll);
  1101. scroll.getViewport().add(panel);
  1102. JButton newb = new JButton("Add Consumable");
  1103. panel.add(newb, c);
  1104. newb.addMouseListener(new MouseAdapter() {
  1105. public void mouseClicked(MouseEvent e) {
  1106. savedConsumables.add(new SavedConsumable("New Consumable", -1, "Health", 0, -1));
  1107. consumableSettings.dispose();
  1108. consumableSettings = new ConsumableSettings();
  1109. consumableSettings.setVisible(true);
  1110.  
  1111. }
  1112. });
  1113. for (int i = 0; i < savedConsumables.size(); i++) {
  1114. c.gridy++;
  1115. final int s = i;
  1116. JButton item = new JButton(savedConsumables.get(i).name);
  1117. panel.add(item, c);
  1118. item.addMouseListener(new MouseAdapter() {
  1119. public void mouseClicked(MouseEvent e) {
  1120. if (control != null) control.dispose();
  1121. control = new ConsumableControl(s);
  1122. control.setVisible(true);
  1123. }
  1124. });
  1125.  
  1126. }
  1127.  
  1128. }
  1129. }
  1130.  
  1131. class ConsumableControl extends JFrame {
  1132. public ConsumableControl(final int index) {
  1133. setLayout(new FlowLayout());
  1134. /*
  1135. String name;
  1136. int at;
  1137. String type;
  1138. int bank;
  1139. int heal;*/
  1140. Container c = getContentPane();
  1141. final String name = savedConsumables.get(index).name;
  1142. final int at = savedConsumables.get(index).at;
  1143. final String type = savedConsumables.get(index).type;
  1144. final int bank = savedConsumables.get(index).bank;
  1145. final int heal = savedConsumables.get(index).heal;
  1146. setTitle("Consumable Control - " + name);
  1147. final JTextField nameField = new JTextField("" + name);
  1148. nameField.setToolTipText("<html>Consumable name; There is no need to add a consumable for<br/> each potion dose. Use \"Attack potion\" instead of \"Attack potion (1)\". <br/>For food, however, you DO need to put the amount. use \"2/3 Cake\", etc.</html>");
  1149. nameField.setColumns(10);
  1150. final JTextField atField = new JTextField("" + at);
  1151. atField.setToolTipText("<html>When we want to consume item. If we want to drink an attack potion<br>when our attack level reaches 65, we would set this to 65, and the next field to \"Attack\".<br/>Likewise, if we want to eat this item at 650 health, we would set this field to 650, <br>and the next field to \"Health\"</html>");
  1152. atField.setColumns(3);
  1153. final JComboBox typeList = new JComboBox(statsArray);
  1154. typeList.setToolTipText("What type is this consumable?");
  1155. final JTextField bankField = new JTextField("" + bank);
  1156. bankField.setToolTipText("<html>How many do we want to withdraw from bank? Set as 0 if we want to <br>use the \"all\" function. Set as -1 if we do not want to bank.</html>");
  1157. bankField.setColumns(3);
  1158. final JTextField healField = new JTextField("" + heal);
  1159. healField.setToolTipText("<html>How much does this food heal? Only<br> enabled when the consumable type is Health.</html>");
  1160. healField.setColumns(3);
  1161.  
  1162. int atIndex = 3;
  1163. for (int i = 0; i < statsArray.length; i++) {
  1164. if (statsArray[i].equals(type)) atIndex = i;
  1165. }
  1166. typeList.addActionListener(new ActionListener() {
  1167. public void actionPerformed(ActionEvent e) {
  1168. JComboBox cb = (JComboBox) e.getSource();
  1169. String petName = (String) cb.getSelectedItem();
  1170. healField.setEnabled(false);
  1171. if (cb.getSelectedIndex() == 3) {
  1172. healField.setEnabled(true);
  1173. }
  1174. }
  1175. });
  1176. typeList.setSelectedIndex(atIndex);
  1177. final JButton save = new JButton("Save");
  1178. final JButton delete = new JButton("Delete");
  1179. final JLabel info = new JLabel("Hover over a box to find its function.");
  1180. setSize(500, 80);
  1181. setLocationRelativeTo(getRootPane());
  1182. c.add(nameField);
  1183. c.add(atField);
  1184. c.add(typeList);
  1185. c.add(healField);
  1186. c.add(bankField);
  1187. c.add(save);
  1188. c.add(delete);
  1189. c.add(info);
  1190. save.addMouseListener(new MouseAdapter() {
  1191. public void mouseClicked(MouseEvent e) {
  1192. savedConsumables.set(index, new SavedConsumable(nameField.getText(), Integer.parseInt(atField.getText().trim()), statsArray[typeList.getSelectedIndex()], Integer.parseInt(bankField.getText().trim()), Integer.parseInt(healField.getText().trim())));
  1193. consumableSettings.dispose();
  1194. consumableSettings = new ConsumableSettings();
  1195. consumableSettings.setVisible(true);
  1196. control.dispose();
  1197.  
  1198. }
  1199. });
  1200. delete.addMouseListener(new MouseAdapter() {
  1201. public void mouseClicked(MouseEvent e) {
  1202. savedConsumables.remove(index);
  1203. consumableSettings.dispose();
  1204. consumableSettings = new ConsumableSettings();
  1205. consumableSettings.setVisible(true);
  1206. control.dispose();
  1207.  
  1208. }
  1209. });
  1210. setResizable(false);
  1211. }
  1212. }
  1213.  
  1214. class MonsterSettings extends JFrame {
  1215. JLabel label;
  1216.  
  1217.  
  1218. public MonsterSettings() {
  1219.  
  1220. setTitle("Monster Settings");
  1221. setSize(300, 300);
  1222. setResizable(false);
  1223. setLocationRelativeTo(getRootPane());
  1224. JScrollPane scroll = new JScrollPane();
  1225. JPanel panel = new JPanel();
  1226. panel.setSize(300, 300);
  1227. scroll.setPreferredSize(new Dimension(300, 300));
  1228. panel.setLayout(new GridBagLayout());
  1229. GridBagConstraints c = new GridBagConstraints();
  1230. c.fill = GridBagConstraints.HORIZONTAL;
  1231. c.weightx = 1.0; //request any extra vertical space
  1232. c.insets = new Insets(3, 3, 3, 3);
  1233. c.gridx = 0;
  1234. c.gridy = 0;
  1235. add(scroll);
  1236. scroll.getViewport().add(panel);
  1237. JButton newb = new JButton("Create new Monster");
  1238. panel.add(newb, c);
  1239. newb.addMouseListener(new MouseAdapter() {
  1240. public void mouseClicked(MouseEvent e) {
  1241. savedMonsters.add(new SavedMonster(-1, "New Monster", 3000));
  1242. monsterSettings.dispose();
  1243. monsterSettings = new MonsterSettings();
  1244. monsterSettings.setVisible(true);
  1245.  
  1246. }
  1247. });
  1248. for (int i = 0; i < savedMonsters.size(); i++) {
  1249. c.gridy++;
  1250. final int s = i;
  1251. JButton monster = new JButton(savedMonsters.get(i).name);
  1252. panel.add(monster, c);
  1253. monster.addMouseListener(new MouseAdapter() {
  1254. public void mouseClicked(MouseEvent e) {
  1255. if (control != null) control.dispose();
  1256. control = new MonsterControl(s);
  1257. control.setVisible(true);
  1258. }
  1259. });
  1260.  
  1261. }
  1262.  
  1263. }
  1264. }
  1265.  
  1266. class MonsterControl extends JFrame {
  1267. public MonsterControl(final int index) {
  1268. setLayout(new FlowLayout());
  1269. final String monsterName = savedMonsters.get(index).name;
  1270. final int monsterID = savedMonsters.get(index).ID;
  1271. final int deathWait = savedMonsters.get(index).deathTime;
  1272. setTitle("Monster Control - " + monsterName);
  1273. final JTextField nameField = new JTextField("" + monsterName);
  1274. nameField.setColumns(10);
  1275. final JTextField idField = new JTextField("" + monsterID);
  1276. idField.setColumns(5);
  1277.  
  1278. final JSlider deathWaitField = new JSlider(0, 10000, deathWait);
  1279. deathWaitField.setMajorTickSpacing(2000);
  1280. deathWaitField.setMinorTickSpacing(1000);
  1281. deathWaitField.setPaintTicks(true);
  1282. deathWaitField.setPaintLabels(true);
  1283. deathWaitField.setToolTipText("Maximum time to wait after a monster dies to pick up its items.");
  1284. final JButton save = new JButton("Save");
  1285. final JButton delete = new JButton("Delete");
  1286. final JLabel info = new JLabel("Slider function: Maximum time (in milliseconds) to wait after a monster dies to pick up its items.");
  1287. final JLabel info2 = new JLabel("Monster ID is optional; Keep it at -1 if you don't need to use it.");
  1288. Container c = getContentPane();
  1289. setSize(550, 120);
  1290. c.add(nameField);
  1291. c.add(idField);
  1292. c.add(deathWaitField);
  1293. c.add(save);
  1294. c.add(delete);
  1295. c.add(info);
  1296. c.add(info2);
  1297. save.addMouseListener(new MouseAdapter() {
  1298. public void mouseClicked(MouseEvent e) {
  1299. savedMonsters.get(index).name = nameField.getText();
  1300. savedMonsters.get(index).ID = Integer.parseInt(idField.getText());
  1301. savedMonsters.get(index).deathTime = deathWaitField.getValue();
  1302. monsterSettings.dispose();
  1303. monsterSettings = new MonsterSettings();
  1304. monsterSettings.setVisible(true);
  1305. control.dispose();
  1306.  
  1307. }
  1308. });
  1309. delete.addMouseListener(new MouseAdapter() {
  1310. public void mouseClicked(MouseEvent e) {
  1311. savedMonsters.remove(index);
  1312. monsterSettings.dispose();
  1313. monsterSettings = new MonsterSettings();
  1314. monsterSettings.setVisible(true);
  1315. control.dispose();
  1316.  
  1317. }
  1318. });
  1319. setResizable(false);
  1320. }
  1321. }
  1322.  
  1323. class OtherSettings extends JFrame {
  1324. JTextField maxDistField;
  1325. JCheckBox bankType;
  1326.  
  1327. public OtherSettings() {
  1328. setLayout(new FlowLayout());
  1329.  
  1330. Container c = getContentPane();
  1331. c.add(new JLabel("Max Distance:"));
  1332.  
  1333. maxDistField = new JTextField();
  1334. maxDistField.setText("" + maxDist);
  1335. c.add(maxDistField);
  1336.  
  1337. c.add((bankType = new JCheckBox("<html>Bank when inventory is full. <br>(DO NOT LET YOUR WITHDRAWING FILL INVENTORY WHEN YOU SET THIS OPTION!)</html>")));
  1338. bankType.setSelected(bankFull);
  1339.  
  1340. setSize(550, 120);
  1341. setResizable(false);
  1342. }
  1343. }
  1344.  
  1345. class BankWalkSettings extends JFrame {
  1346.  
  1347. public BankWalkSettings() {
  1348.  
  1349. setTitle("Bankwalk Settings");
  1350. setSize(300, 300);
  1351. setResizable(false);
  1352. setLocationRelativeTo(getRootPane());
  1353. JScrollPane scroll = new JScrollPane();
  1354. JPanel panel = new JPanel();
  1355. panel.setSize(300, 300);
  1356. scroll.setPreferredSize(new Dimension(300, 300));
  1357. panel.setLayout(new GridBagLayout());
  1358. GridBagConstraints c = new GridBagConstraints();
  1359. c.fill = GridBagConstraints.HORIZONTAL;
  1360. c.weightx = 1.0; //request any extra vertical space
  1361. c.insets = new Insets(3, 3, 3, 3);
  1362. c.gridx = 0;
  1363. c.gridy = 0;
  1364. add(scroll);
  1365. scroll.getViewport().add(panel);
  1366. final JButton newTile = new JButton("Add tile (" + path.size() + ")");
  1367. newTile.addMouseListener(new MouseAdapter() {
  1368. public void mouseClicked(MouseEvent e) {
  1369. path.add(new BWT(getMyPlayer().getLocation().getX(), getMyPlayer().getLocation().getY(), game.getCurrentFloor()));
  1370. newTile.setText("Add tile (" + path.size() + ")");
  1371. }
  1372. });
  1373. panel.add(newTile, c);
  1374. c.gridy = 1;
  1375. JButton newb = new JButton("Create new Obstacle");
  1376. panel.add(newb, c);
  1377. newb.addMouseListener(new MouseAdapter() {
  1378. public void mouseClicked(MouseEvent e) {
  1379. savedObstacles.add(new SavedObstacle(new BWT(0, 0, game.getCurrentFloor()), -1, "Open Door", 0));
  1380. bankWalkSettings.dispose();
  1381. bankWalkSettings = new BankWalkSettings();
  1382. bankWalkSettings.setVisible(true);
  1383.  
  1384. }
  1385. });
  1386.  
  1387. for (int i = 0; i < savedObstacles.size(); i++) {
  1388. c.gridy++;
  1389. final int s = i;
  1390. JButton monster = new JButton(savedObstacles.get(i).ID + ": " + savedObstacles.get(i).action);
  1391. panel.add(monster, c);
  1392. monster.addMouseListener(new MouseAdapter() {
  1393. public void mouseClicked(MouseEvent e) {
  1394. if (control != null) control.dispose();
  1395. control = new ObstacleControl(s);
  1396. control.setVisible(true);
  1397. }
  1398. });
  1399.  
  1400. }
  1401.  
  1402. }
  1403. }
  1404.  
  1405.  
  1406. class ObstacleControl extends JFrame {
  1407. public ObstacleControl(final int index) {
  1408. setLayout(new FlowLayout());
  1409. final SavedObstacle o = savedObstacles.get(index);
  1410. setTitle("Obstacle Control - " + o.action + " - " + o.location.toTile().toString());
  1411. final JTextField actionField = new JTextField("" + o.action);
  1412. actionField.setColumns(10);
  1413. final JTextField idField = new JTextField("" + o.ID);
  1414. idField.setColumns(5);
  1415. final JTextField xField = new JTextField("" + o.location.x);
  1416. final JTextField yField = new JTextField("" + o.location.y);
  1417. final JTextField planeField = new JTextField("" + o.location.plane);
  1418. final String[] combo = {"Both Ways", "From Bank", "To Bank"};
  1419.  
  1420. final JComboBox directionField = new JComboBox(combo);
  1421. directionField.setSelectedIndex(o.direction);
  1422. xField.setColumns(4);
  1423. yField.setColumns(4);
  1424. planeField.setColumns(4);
  1425. actionField.setColumns(12);
  1426.  
  1427. final JButton save = new JButton("Save");
  1428. final JButton delete = new JButton("Delete");
  1429. Container c = getContentPane();
  1430. setSize(700, 60);
  1431. c.add(new JLabel("Action:"));
  1432. c.add(actionField);
  1433. c.add(new JLabel("ID:"));
  1434. c.add(idField);
  1435. c.add(new JLabel("x:"));
  1436.  
  1437. c.add(xField);
  1438. c.add(new JLabel("y:"));
  1439.  
  1440. c.add(yField);
  1441. c.add(new JLabel("height:"));
  1442. c.add(planeField);
  1443. c.add(directionField);
  1444. c.add(save);
  1445. c.add(delete);
  1446.  
  1447. save.addMouseListener(new MouseAdapter() {
  1448. public void mouseClicked(MouseEvent e) {
  1449. savedObstacles.set(index, new SavedObstacle(new BWT(Integer.parseInt(xField.getText().trim()),
  1450. Integer.parseInt(yField.getText().trim()),
  1451. Integer.parseInt(planeField.getText().trim())),
  1452. Integer.parseInt(idField.getText().trim()),
  1453. actionField.getText(), directionField.getSelectedIndex()));
  1454. bankWalkSettings.dispose();
  1455. bankWalkSettings = new BankWalkSettings();
  1456. bankWalkSettings.setVisible(true);
  1457. control.dispose();
  1458.  
  1459. }
  1460. });
  1461. delete.addMouseListener(new MouseAdapter() {
  1462. public void mouseClicked(MouseEvent e) {
  1463. savedObstacles.remove(index);
  1464. bankWalkSettings.dispose();
  1465. bankWalkSettings = new BankWalkSettings();
  1466. bankWalkSettings.setVisible(true);
  1467. control.dispose();
  1468.  
  1469. }
  1470. });
  1471. setResizable(false);
  1472. }
  1473. }
  1474.  
  1475. private final int BLOCKED_0_NORTH = 0x2;
  1476. private final int BLOCKED_0_NORTH_EAST = 0x4;
  1477. private final int BLOCKED_0_EAST = 0x8;
  1478. private final int BLOCKED_0_SOUTH_EAST = 0x10;
  1479. private final int BLOCKED_0_SOUTH = 0x20;
  1480. private final int BLOCKED_0_SOUTH_WEST = 0x40;
  1481. private final int BLOCKED_0_WEST = 0x80;
  1482. private final int BLOCKED_0_NORTH_WEST = 0x200;
  1483.  
  1484. private final int BLOCKED_1_NORTH = 0x400;
  1485. private final int BLOCKED_1_NORTH_EAST = 0x800;
  1486. private final int BLOCKED_1_EAST = 0x1000;
  1487. private final int BLOCKED_1_SOUTH_EAST = 0x2000;
  1488. private final int BLOCKED_1_SOUTH = 0x4000;
  1489. private final int BLOCKED_1_SOUTH_WEST = 0x8000;
  1490. private final int BLOCKED_1_WEST = 0x10000;
  1491. private final int BLOCKED_1_NORTH_WEST = 0x40000;
  1492.  
  1493. private final int BLOCKED_2_NORTH = 0x800000;
  1494. private final int BLOCKED_2_NORTH_EAST = 0x1000000;
  1495. private final int BLOCKED_2_EAST = 0x2000000;
  1496. private final int BLOCKED_2_SOUTH_EAST = 0x4000000;
  1497. private final int BLOCKED_2_SOUTH = 0x8000000;
  1498. private final int BLOCKED_2_SOUTH_WEST = 0x10000000;
  1499. private final int BLOCKED_2_WEST = 0x20000000;
  1500. private final int BLOCKED_2_NORTH_WEST = 0x80000000;
  1501.  
  1502.  
  1503. private final int BLOCK_0 = 0x100;
  1504. private final int BLOCK_1 = 0x40000;
  1505. private final int BLOCK_2 = 0x200000;
  1506. private final int BLOCK_3 = 0x40000000;
  1507. private final int FULL_BLOCK = /*BLOCK_0 | */
  1508. BLOCK_1 | BLOCK_2 | BLOCK_3;
  1509.  
  1510. public int getRealDistanceTo(Tile
  1511. dest, final boolean isObject) {
  1512. return getRealDistanceTo(getMyPlayer().getLocation(), dest, isObject);
  1513. }
  1514.  
  1515. public int getRealDistanceTo(Tile
  1516. start, Tile
  1517. dest, final boolean isObject) {
  1518. final int startX = (start.getX() - getClient().getBaseX() + 1);
  1519. final int startY = (start.getY() - getClient().getBaseY() + 1);
  1520. final int destX = dest.getX() - getClient().getBaseX();
  1521. final int destY = dest.getY() - getClient().getBaseY();
  1522. final int[][] via = new int[104][104];
  1523. final int[][] cost = new int[104][104];
  1524. final int[] tileQueueX = new int[4000];
  1525. final int[] tileQueueY = new int[4000];
  1526.  
  1527. for (int xx = 0; xx < 104; xx++) {
  1528. for (int yy = 0; yy < 104; yy++) {
  1529. via[xx][yy] = 0;
  1530. cost[xx][yy] = 99999999;
  1531. }
  1532. }
  1533.  
  1534. int curX = startX;
  1535. int curY = startY;
  1536. via[startX][startY] = 99;
  1537. cost[startX][startY] = 0;
  1538. int head = 0;
  1539. int tail = 0;
  1540. tileQueueX[head] = startX;
  1541. tileQueueY[head++] = startY;
  1542. boolean foundPath = false;
  1543. final int pathLength = tileQueueX.length;
  1544. final int blocks[][] = getClient().getMapDataArray()[getClient().getCurrentPlane()].getTileData();
  1545. while (tail != head) {
  1546. curX = tileQueueX[tail];
  1547. curY = tileQueueY[tail];
  1548.  
  1549. if (!isObject && (curX == destX) && (curY == destY)) {
  1550. foundPath = true;
  1551. break;
  1552. } else if (isObject) {
  1553. if (((curX == destX) && (curY == destY + 1)) || ((curX == destX) && (curY == destY - 1)) || ((curX == destX + 1) && (curY == destY)) || ((curX == destX - 1) && (curY == destY))) {
  1554. foundPath = true;
  1555. break;
  1556. }
  1557. }
  1558. tail = (tail + 1) % pathLength;
  1559.  
  1560. // Big and ugly block of code
  1561. final int thisCost = cost[curX][curY] + 1;
  1562. if ((curY > 0) && (via[curX][curY - 1] == 0) && ((blocks[curX][curY - 1] & (FULL_BLOCK | BLOCKED_0_NORTH | BLOCKED_1_NORTH | BLOCKED_2_NORTH)) == 0)) {
  1563. tileQueueX[head] = curX;
  1564. tileQueueY[head] = curY - 1;
  1565. head = (head + 1) % pathLength;
  1566. via[curX][curY - 1] = 1;
  1567. cost[curX][curY - 1] = thisCost;
  1568. }
  1569. if ((curX > 0) && (via[curX - 1][curY] == 0) && ((blocks[curX - 1][curY] & (FULL_BLOCK | BLOCKED_0_EAST | BLOCKED_1_EAST | BLOCKED_2_EAST)) == 0)) {
  1570. tileQueueX[head] = curX - 1;
  1571. tileQueueY[head] = curY;
  1572. head = (head + 1) % pathLength;
  1573. via[curX - 1][curY] = 2;
  1574. cost[curX - 1][curY] = thisCost;
  1575. }
  1576. if ((curY < 104 - 1) && (via[curX][curY + 1] == 0) && ((blocks[curX][curY + 1] & (FULL_BLOCK | BLOCKED_0_SOUTH | BLOCKED_1_SOUTH | BLOCKED_2_SOUTH)) == 0)) {
  1577. tileQueueX[head] = curX;
  1578. tileQueueY[head] = curY + 1;
  1579. head = (head + 1) % pathLength;
  1580. via[curX][curY + 1] = 4;
  1581. cost[curX][curY + 1] = thisCost;
  1582. }
  1583. if ((curX < 104 - 1) && (via[curX + 1][curY] == 0) && ((blocks[curX + 1][curY] & (FULL_BLOCK | BLOCKED_0_WEST | BLOCKED_1_WEST | BLOCKED_2_WEST)) == 0)) {
  1584. tileQueueX[head] = curX + 1;
  1585. tileQueueY[head] = curY;
  1586. head = (head + 1) % pathLength;
  1587. via[curX + 1][curY] = 8;
  1588. cost[curX + 1][curY] = thisCost;
  1589. }
  1590. if ((curX > 0) && (curY > 0) && (via[curX - 1][curY - 1] == 0) && ((blocks[curX - 1][curY - 1] & (FULL_BLOCK | BLOCKED_1_NORTH_EAST | BLOCKED_2_NORTH_EAST)) == 0) && ((blocks[curX - 1][curY] & (FULL_BLOCK | BLOCKED_1_EAST | BLOCKED_2_EAST)) == 0) && ((blocks[curX][curY - 1] & (FULL_BLOCK | BLOCKED_1_NORTH | BLOCKED_2_NORTH)) == 0)) {
  1591. tileQueueX[head] = curX - 1;
  1592. tileQueueY[head] = curY - 1;
  1593. head = (head + 1) % pathLength;
  1594. via[curX - 1][curY - 1] = 3;
  1595. cost[curX - 1][curY - 1] = thisCost;
  1596. }
  1597. if ((curX > 0) && (curY < 104 - 1) && (via[curX - 1][curY + 1] == 0) && ((blocks[curX - 1][curY + 1] & (FULL_BLOCK | BLOCKED_1_SOUTH_EAST | BLOCKED_2_SOUTH_EAST)) == 0) && ((blocks[curX - 1][curY] & (FULL_BLOCK | BLOCKED_1_EAST | BLOCKED_2_EAST)) == 0) && ((blocks[curX][curY + 1] & (FULL_BLOCK | BLOCKED_1_SOUTH | BLOCKED_2_SOUTH)) == 0)) {
  1598. tileQueueX[head] = curX - 1;
  1599. tileQueueY[head] = curY + 1;
  1600. head = (head + 1) % pathLength;
  1601. via[curX - 1][curY + 1] = 6;
  1602. cost[curX - 1][curY + 1] = thisCost;
  1603. }
  1604. if ((curX < 105) && (curY > 0) && (via[curX + 1][curY - 1] == 0) && ((blocks[curX + 1][curY - 1] & (FULL_BLOCK | BLOCKED_1_NORTH_WEST | BLOCKED_2_NORTH_WEST)) == 0) && ((blocks[curX + 1][curY] & (FULL_BLOCK | BLOCKED_1_WEST | BLOCKED_2_WEST)) == 0) && ((blocks[curX][curY - 1] & (FULL_BLOCK | BLOCKED_1_NORTH | BLOCKED_2_NORTH)) == 0)) {
  1605. tileQueueX[head] = curX + 1;
  1606. tileQueueY[head] = curY - 1;
  1607. head = (head + 1) % pathLength;
  1608. via[curX + 1][curY - 1] = 9;
  1609. cost[curX + 1][curY - 1] = thisCost;
  1610. }
  1611. if ((curX < 105) && (curY < 104 - 1) && (via[curX + 1][curY + 1] == 0) && ((blocks[curX + 1][curY + 1] & (FULL_BLOCK | BLOCKED_1_SOUTH_WEST | BLOCKED_2_SOUTH_WEST)) == 0) && ((blocks[curX + 1][curY] & (FULL_BLOCK | BLOCKED_1_WEST | BLOCKED_2_WEST)) == 0) && ((blocks[curX][curY + 1] & (FULL_BLOCK | BLOCKED_1_SOUTH | BLOCKED_2_SOUTH)) == 0)) {
  1612. tileQueueX[head] = curX + 1;
  1613. tileQueueY[head] = curY + 1;
  1614. head = (head + 1) % pathLength;
  1615. via[curX + 1][curY + 1] = 12;
  1616. cost[curX + 1][curY + 1] = thisCost;
  1617. }
  1618. }
  1619. if (foundPath) return cost[curX][curY];
  1620. return -1;
  1621. }
  1622.  
  1623. RoundRectangle2D mainPaintBox;
  1624. GradientPaint gp;
  1625.  
  1626. public void drawDefaultPaint(Graphics2D g, int x, int y, int width, String... strings) {
  1627. int height = strings.length * 15;
  1628. if (mainPaintBox == null) {
  1629. mainPaintBox = new RoundRectangle2D.Double(x, y, width, height, 5, 5);
  1630. gp = new GradientPaint(x, y, new Color(0, 0, 0, 50), x, y + height, new Color(0, 0, 0, 200), false);
  1631. }
  1632. g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  1633. g.setFont(new Font("Arial", Font.BOLD, 10));
  1634.  
  1635. g.setPaint(gp);
  1636. g.fill(mainPaintBox);
  1637. g.setColor(Color.black);
  1638. g.draw(mainPaintBox);
  1639.  
  1640. g.setColor(Color.white);
  1641. x += 2;
  1642. y += 10;
  1643. for (String s : strings) {
  1644. g.drawString(s, x, y);
  1645. y += 15;
  1646. }
  1647. }
  1648.  
  1649. public String format(int num) {
  1650. DecimalFormat df = new DecimalFormat();
  1651. DecimalFormatSymbols dfs = new DecimalFormatSymbols();
  1652. dfs.setGroupingSeparator(',');
  1653. df.setDecimalFormatSymbols(dfs);
  1654. return df.format(num);
  1655. }
  1656.  
  1657. class SavedItem {
  1658. int ID;
  1659. String name;
  1660. boolean alch;
  1661.  
  1662. public SavedItem(int ID, String name, boolean alch) {
  1663. this.ID = ID;
  1664. this.name = name;
  1665. this.alch = alch;
  1666. }
  1667. }
  1668.  
  1669. class SavedMonster {
  1670. int ID;
  1671. String name;
  1672. int deathTime;
  1673.  
  1674. public SavedMonster(int ID, String name, int deathTime) {
  1675. this.ID = ID;
  1676. this.name = name;
  1677. this.deathTime = deathTime;
  1678. }
  1679. }
  1680.  
  1681. class SavedConsumable {
  1682. String name;
  1683. int at;
  1684. String type;
  1685. int bank;
  1686. int heal;
  1687.  
  1688. public SavedConsumable(String name, int at, String type, int bank, int heal) {
  1689. this.name = name;
  1690. this.at = at;
  1691. this.type = type;
  1692. this.bank = bank;
  1693. this.heal = heal;
  1694. }
  1695. }
  1696.  
  1697. class BWT {
  1698. int x;
  1699. int y;
  1700. int plane;
  1701.  
  1702. public BWT(int x, int y, int plane) {
  1703. this.x = x;
  1704. this.y = y;
  1705. this.plane = plane;
  1706. }
  1707.  
  1708. public Tile toTile() {
  1709. return new Tile(x, y);
  1710. }
  1711. }
  1712.  
  1713. class SavedObstacle {
  1714. BWT location;
  1715. int ID;
  1716. String action;
  1717. int direction;
  1718. final static int BOTH_WAYS = 0;
  1719. final static int FROM_BANK = 1;
  1720. final static int TO_BANK = 2;
  1721.  
  1722. public SavedObstacle(BWT location, int ID, String action, int direction) {
  1723. this.location = location;
  1724. this.ID = ID;
  1725. this.action = action;
  1726. this.direction = direction;
  1727. }
  1728. }
  1729. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement