Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Fighter;
- import com.kbotpro.scriptsystem.events.PaintEventListener;
- import com.kbotpro.scriptsystem.events.ServerMessageListener;
- import com.kbotpro.scriptsystem.fetch.Game;
- import com.kbotpro.scriptsystem.fetch.Skills;
- import com.kbotpro.scriptsystem.input.jobs.MouseHoverJob;
- import com.kbotpro.scriptsystem.interfaces.Looped;
- import com.kbotpro.scriptsystem.runnable.Script;
- import com.kbotpro.scriptsystem.various.KTimer;
- import com.kbotpro.scriptsystem.wrappers.Character;
- import com.kbotpro.scriptsystem.wrappers.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.geom.RoundRectangle2D;
- import java.io.*;
- import java.text.DecimalFormat;
- import java.text.DecimalFormatSymbols;
- import java.util.ArrayList;
- import java.util.Hashtable;
- /**
- * Created by IntelliJ IDEA.
- * User: Vartan
- * Date: May 23, 2010
- * Time: 4:39:27 PM
- * To change this template use File | Settings | File Templates.
- */
- public class Fighter extends Script implements ServerMessageListener,
- PaintEventListener {
- int failSafe = 0;
- NPC fighting;
- NPC nextMonster;
- Tile seen;
- GroundItem[] before;
- KTimer failTimer;
- boolean bankFull;
- int xp=0;
- int startingXp=0;
- int maxDist = 20;
- NPC last;
- String debug = "";
- int glow = 75;
- boolean glowd = false;
- MouseHoverJob hover;
- KTimer movingTimer;
- int deathTime = 3000;
- KTimer deathTimer;
- KTimer dropTimer;
- MainFrame main;
- Tile startingLoc;
- ItemSettings itemSettings;
- MonsterSettings monsterSettings;
- OtherSettings otherSettings;
- ConsumableSettings consumableSettings;
- BankWalkSettings bankWalkSettings;
- ArrayList<SavedItem> savedItems = new ArrayList<SavedItem>();
- ArrayList<SavedMonster> savedMonsters = new ArrayList<SavedMonster>();
- ArrayList<SavedConsumable> savedConsumables = new ArrayList<SavedConsumable>();
- ArrayList<SavedObstacle> savedObstacles = new ArrayList<SavedObstacle>();
- ArrayList<BWT> path = new ArrayList<BWT>();
- KTimer runTime;
- KTimer underAttackTimer;
- JFrame control;
- boolean started = false;
- KTimer fightingTimer;
- boolean isBanking = false;
- Hashtable<Integer,
- Integer> food = new Hashtable<Integer,
- Integer>();
- public String[] statsArray = {
- "Attack", "Defence", "Strength", "Health", "Ranged",
- "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking",
- "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer",
- "Farming", "Runecrafting", "Hunter", "Construction", "Summoning", "Dungeoneering"
- };
- public void onRepaint(Graphics graphics) {
- Graphics2D g = (Graphics2D) graphics;
- g.setColor(new Color(255, glow, 0, 255));
- long ms = runTime.getTimeElapsed();
- double hours = (double) ms / 1000 / 60 / 60;
- drawDefaultPaint((Graphics2D) g, 20, 20, 200,
- "Running for:" + runTime.getFormattedTime(runTime.getTimeElapsed()), "Experience gained: " + format(xp - startingXp), "Experience per hour:" + format((int) ((xp - startingXp) / hours)));
- if (glowd) glow += 3;
- else glow -= 3;
- if (glow >= 150 || glow <= 50) glowd = !glowd;
- g.setColor(new Color(0, glow, 255, glow + 20));
- try {
- if (nextMonster != null && onScreen(nextMonster))
- nextMonster.getModel().fillWireFrame(g);
- g.setColor(new Color(255, glow, 0, glow - 20));
- if (fighting != null && onScreen(fighting)) {
- fighting.getModel().fillWireFrame(g);
- g.setColor(new Color(255, glow, 0, 255));
- g.drawString("" + fighting.getHPPercent(), 50, 50);
- }
- int lastX = -1;
- int lastY = -1;
- for (SavedObstacle o : savedObstacles) {
- if (o.location.plane != game.getCurrentFloor())
- continue;
- Point m = calculations.tileToMinimap(o.location.toTile());
- PhysicalObject[] po = objects.getObjectsAt(o.location.toTile(), new int[]{o.ID});
- g.setColor(new Color(255, 255, 255, 50));
- if (po.length > 0 && po[0].onScreen())
- po[0].getModel().fillWireFrame(g);
- if (walking.mapCircle().contains(m)) {
- g.setColor(new Color(50, 100, 255));
- g.fillOval(m.x - 3, m.y - 3, 6, 6);
- }
- }
- if (isBanking || !started) {
- for (BWT tile : path) {
- Point m = calculations.tileToMinimap(tile.toTile());
- if (tile.plane != game.getCurrentFloor())
- continue;
- if (walking.mapCircle().contains(m)) {
- if (lastX != -1) {
- g.setColor(Color.GREEN);
- g.drawLine(lastX, lastY, m.x, m.y);
- }
- g.setColor(Color.RED);
- g.fillRect(m.x - 2, m.y - 2, 4, 4);
- lastX = m.x;
- lastY = m.y;
- } else {
- lastX = -1;
- lastY = -1;
- }
- }
- }
- if (bankWalkSettings.isVisible()) {
- PhysicalObject[] near = objects.getObjects(2);
- for (PhysicalObject o : near) {
- if (distanceTo(o.getLocation()) > 1)
- continue;
- Point p = calculations.tileToScreen(o.getLocation().getX(), o.getLocation().getY(), .5, .5, 0);
- g.setColor(Color.RED);
- g.fillOval(p.x - 2, p.y - 2, 4, 4);
- String write = o.getID() + ":" + "(" + o.getLocation().getX() + "," + o.getLocation().getY() + "," + game.getCurrentFloor() + ")";
- for (int i = 4; i > 0; i--) {
- g.setColor(new Color(255 - (51 * i), 0, 0, 255 - (51 * i)));
- g.drawString(write, p.x + 5 - i, p.y + 3);
- g.drawString(write, p.x + 5 + i, p.y + 3);
- g.drawString(write, p.x + 5, p.y + 3 - i);
- g.drawString(write, p.x + 5, p.y + i);
- g.drawString(write, p.x + 5 - i, p.y + 3 + i);
- g.drawString(write, p.x + 5 + i, p.y + 3 - i);
- }
- g.setColor(Color.BLACK);
- g.drawString(write, p.x + 5, p.y + 3);
- g.setColor(Color.WHITE);
- g.drawString(write, p.x + 4, p.y + 2);
- }
- }
- } catch (Exception e) {
- }
- }
- public void onServerMessage(String s) {
- if (s.contains("is fighting that")) movingTimer = new KTimer(1);
- if (s.equalsIgnoreCase("I'm already under attack.")) underAttackTimer = new KTimer(7000);
- }
- @Override
- public void registerWorkers() {
- createWorker(new Looped() {
- public int loop() {
- try {
- mouse.setDefaultSpeed(random(3.0, 4.0));
- if (failTimer.isDone()) {
- game.exitGame();
- stopAllScripts();
- return -1;
- }
- if (!started) {
- if (isLoggedIn() && path.size() > 0) {
- startingLoc = path.get(path.size() - 1).toTile();
- }
- failTimer = new KTimer(300000);
- return 50;
- }
- if(startingXp==0) {
- 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);
- }
- 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);
- game.openTab(Game.TAB_INVENTORY);
- int dist = 0;
- if (path.size() > 0) {
- if (bankFull) {
- if (inventory.isFull()) {
- return walkToBank();
- }
- }
- for (SavedConsumable c : savedConsumables) {
- if (c.bank < 0)
- continue;
- if (c.type.equals("Health")) {
- if (!inventory.contains(c.name)) {
- log("Inventory doesn't contain food: " + c.name);
- return walkToBank();
- } else {
- }
- } else {
- boolean has = false;
- for (Item i : inventory.getItems()) {
- if (i.getName().toLowerCase().startsWith(c.name.toLowerCase())) {
- has = true;
- }
- }
- if (!has) {
- log("Inventory doesn't contain drink:" + c.name);
- return walkToBank();
- }
- }
- }
- }
- if (getDistanceTo(startingLoc) > maxDist || !calculations.canReach(startingLoc, false) || (dist = getRealDistanceTo(startingLoc, false)) > maxDist || dist < 0) {
- if (path.size() > 0)
- return walkFromBank();
- }
- isBanking = false;
- return fight();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return 50; //wtf
- }
- });
- createWorker(new Looped() {
- public int loop() {
- if (failTimer.isDone()) return -1;
- nextMonster = nearest(15, true);
- if (fighting != null) seen = fighting.getLocation();
- return 100;
- }
- });
- }
- public int bank() {
- camera.setAngleTo(path.get(0).toTile());
- if (!bank.isOpen()) {
- bank.openClosestBank();
- return 2000;
- }
- bank.depositAllInventory();
- SavedConsumable last = null;
- for (SavedConsumable c : savedConsumables) {
- if (c.bank == 0) {
- last = c;
- continue;
- }
- if (!withdraw(c))
- return 50;
- }
- if (last != null)
- withdraw(last);
- bank.close();
- return 2000;
- }
- public boolean withdraw(SavedConsumable c) {
- Item[] bankItems = bank.getItems();
- for (Item item : bankItems) {
- boolean good = false;
- if (c.type.equalsIgnoreCase("Health")) {
- if (c.name.trim().equalsIgnoreCase(item.getName().trim()))
- good = true;
- } else {
- if (item.getName().toLowerCase().startsWith(c.name.toLowerCase()))
- good = true;
- }
- if (good) {
- bank.scrollToItem(item);
- if (c.bank != 0)
- bank.withdrawX(item.getID(), c.bank);
- else
- bank.withdrawAll(item.getID());
- return true;
- }
- }
- return false;
- }
- public int walkFromBank() {
- isBanking = true;
- if (getMyPlayer().isMoving())
- return 50;
- if (bank.isOpen())
- bank.close();
- int bestIndex = -1;
- for (int i = 0; i < path.size(); i++) {
- BWT tile = path.get(i);
- if (distanceTo(tile.toTile()) > 30 || !calculations.canReach(tile.toTile(), false))
- continue;
- if (walking.mapCircle().contains(getCalculations().tileToMinimap(tile.toTile()))) {
- bestIndex = i;
- }
- }
- if (bestIndex == -1)
- return 50; //nooooo
- PhysicalObject closest = null;
- int closestDist = 999;
- String closestAction = "";
- if (bestIndex < path.size() && (distanceTo(path.get(bestIndex + 1).toTile()) > 30 || !calculations.canReach(path.get(bestIndex + 1).toTile(), false))) {
- for (SavedObstacle o : savedObstacles) {
- try {
- if (distanceTo(o.location.toTile()) > 30)
- continue;
- if (game.getCurrentFloor() != o.location.plane || o.direction == SavedObstacle.TO_BANK)
- continue;
- PhysicalObject[] po = objects.getObjectsAt(o.location.toTile(), new int[]{o.ID});
- if (po.length <= 0)
- continue;
- PhysicalObject obstacle = po[0];
- if (obstacle == null || !calculations.canReach(obstacle.getLocation(), true))
- continue;
- if (path.get(bestIndex).toTile().distanceTo(obstacle.getLocation()) < closestDist) {
- closestDist = path.get(bestIndex).toTile().distanceTo(obstacle.getLocation());
- closest = obstacle;
- closestAction = o.action;
- log(closestAction);
- }
- } catch (Exception e) {
- }
- }
- if (closest == null) {
- return 50;
- }
- log(closestAction);
- if (calculations.canReach(closest.getLocation(), true)) {
- if (closest.doAction(closestAction) && menu.contains(closestAction))
- return 2000;
- }
- }
- failTimer = new KTimer(300000);
- walkPath(fixPath(path.get(bestIndex).toTile()));
- return 1800;
- }
- public int walkToBank() {
- isBanking = true;
- if (calculations.canReach(path.get(0).toTile(), false) && distanceTo(path.get(0).toTile()) < 14) {
- return bank();
- }
- if (getMyPlayer().isMoving())
- return 50;
- int bestIndex = -1;
- for (int i = path.size() - 1; i >= 0; i--) {
- BWT tile = path.get(i);
- if (distanceTo(tile.toTile()) > 30 || !calculations.canReach(tile.toTile(), false))
- continue;
- if (walking.mapCircle().contains(getCalculations().tileToMinimap(tile.toTile()))) {
- bestIndex = i;
- }
- }
- if (bestIndex == -1)
- return 50; //nooooo
- PhysicalObject closest = null;
- int closestDist = 999;
- String closestAction = "";
- if (bestIndex > 0 && (distanceTo(path.get(bestIndex - 1).toTile()) > 30 || !calculations.canReach(path.get(bestIndex - 1).toTile(), false))) {
- for (SavedObstacle o : savedObstacles) {
- try {
- if (distanceTo(o.location.toTile()) > 30)
- continue;
- if (game.getCurrentFloor() != o.location.plane || o.direction == SavedObstacle.FROM_BANK)
- continue;
- PhysicalObject[] po = objects.getObjectsAt(o.location.toTile(), new int[]{o.ID});
- if (po.length <= 0)
- continue;
- PhysicalObject obstacle = po[0];
- if (obstacle == null || !calculations.canReach(obstacle.getLocation(), true))
- continue;
- if (path.get(bestIndex).toTile().distanceTo(obstacle.getLocation()) < closestDist) {
- closestDist = path.get(bestIndex).toTile().distanceTo(obstacle.getLocation());
- closest = obstacle;
- closestAction = o.action;
- log(closestAction);
- }
- } catch (Exception e) {
- }
- }
- if (closest == null) {
- return 50;
- }
- log(closestAction);
- if (calculations.canReach(closest.getLocation(), true)) {
- if (closest.doAction(closestAction) && menu.contains(closestAction))
- return 2000;
- }
- }
- failTimer = new KTimer(300000);
- walkPath(fixPath(path.get(bestIndex).toTile()));
- return 1800;
- }
- private boolean inCombat() {
- Character c;
- if (fighting == null || fighting.getHPPercent() == 0) return false;
- if (getMyPlayer().getAnimation() != -1) {
- fightingTimer = new KTimer(10000);
- return true;
- }
- if (fightingTimer.isDone()) return false;
- return (fighting) != null && (c = fighting.getInteracting()) != null && c.equals(getMyPlayer());
- }
- public boolean consume() {
- for (SavedConsumable c : savedConsumables) {
- if (c.type.equals("Health")) {
- if (eat(c))
- return true;
- continue;
- }
- if (getCurrentLevel(statIndex(c.type)) <= c.at) {
- for (Item i : inventory.getItems()) {
- if (i.getName().toLowerCase().startsWith(c.name.toLowerCase())) {
- if (i.doClick())
- return true;
- }
- }
- }
- }
- return false;
- }
- public int getCurrentLevel(int skill) {
- int[] levels = getClient().getLevels();
- if (levels == null || levels.length == 0 || skill < 0 || skill >= levels.length)
- return -1;
- return levels[skill];
- }
- public boolean eat(SavedConsumable c) {
- int hp = hp();
- int startingHp = hp;
- boolean wait = false;
- if (hp > c.at) return false;
- for (Item i : inventory.getItems()) {
- if (hp + c.heal >= skills.getLevel(Skills.SKILL_HITPOINTS) * 10) break;
- if (i.getName().startsWith(c.name)) {
- if (wait) sleep(random(1800, 2000));
- if (i.doClick()) {
- hp += c.heal;
- }
- wait = true;
- }
- }
- return hp != startingHp;
- }
- public int statIndex(String
- s) {
- for (int i = 0; i < statsArray.length; i++)
- if (s.equals(statsArray[i])) return i;
- return -1;
- }
- public boolean canRace(NPC
- m) {
- if (m == null || m.isInCombat() || !calculations.canReach(m.getLocation(), false)) return false;
- Player[] people = players.getPlayers();
- int max = -1;
- for (Player person : people) {
- if (person != getMyPlayer()) {
- if (person.getInteracting() == m && (getRealDistanceTo(person.getLocation(), m.getLocation(), false) < getRealDistanceTo(m.getLocation(), false) + 1 || person.getAnimation() != -1))
- return false;
- }
- }
- return true;
- }
- public int hp() {
- return game.getLifePoints();
- /*
- try {
- IComponent hpi = interfaces.getComponent(748, 8);
- return Integer.parseInt(hpi.getText());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return -1; */
- }
- public NPC nearest(
- int range, boolean next) {
- NPC[] list = npcs.getNPCs();
- NPC best = null;
- for (NPC cur : list) {
- try {
- boolean pass = false;
- for (int i = 0; i < savedMonsters.size(); i++) {
- if ((savedMonsters.get(i).ID == -1 || savedMonsters.get(i).ID == cur.getID()) && cur.getName().equalsIgnoreCase(savedMonsters.get(i).name)) {
- deathTime = savedMonsters.get(i).deathTime;
- pass = true;
- break;
- }
- }
- int extra = 0;
- if (getMyPlayer().isMoving()) extra = 4;
- if (!cur.equals(fighting) && getRealDistanceTo(cur.getLocation(), startingLoc, true) < maxDist && pass && cur.getHPPercent() >= 1 && getRealDistanceTo(cur.getLocation(), false) <= range) {
- if (!next && cur.getInteracting() == getMyPlayer()) return cur;
- if (!cur.isInCombat() && canRace(cur) && cur.getHPPercent() != 0) {
- if (best == null || getRealDistanceTo(cur.getLocation(), false) + extra <= getRealDistanceTo(best.getLocation(), false) || (!best.onScreen() && getRealDistanceTo(cur.getLocation(), false) + 7 <= distanceTo(best)))
- best = cur;
- }
- }
- } catch (Exception e) {
- }
- }
- return best;
- }
- public void onResume() {
- failTimer = new KTimer(300000);
- }
- private int fight() {
- try {
- if (consume()) return random(2400, 2500);
- if (walking.getEnergy() > random(random(random(random(30, 90), 90), 90), 90)) {
- walking.setRunning(true);
- sleep(1000);
- }
- fighting = (NPC) getMyPlayer().getInteracting();
- boolean shouldChange = false;
- if (fighting != null && nextMonster != null && getRealDistanceTo(fighting.getLocation(), false) > getRealDistanceTo(nextMonster.getLocation(), false) + 5)
- shouldChange = true;
- if (!shouldChange && getMyPlayer().isMoving() && canRace(fighting)) {
- movingTimer = new KTimer(1300);
- return 50;
- }
- if (deathTimer.isDone() && fighting != null && fighting.getHPPercent() == 0) {
- Point loc = calculations.tileToScreen(fighting.getLocation().getX(), fighting.getLocation().getY(), random(.4, .6), random(.4, .6), 0);
- if (deathTime > 0) mouse.moveMouse(loc);
- }
- if (inCombat()) {
- fightingTimer = new KTimer(10000);
- last = fighting;
- dropTimer = new KTimer(deathTime);
- deathTimer = new KTimer(5000);
- before = groundItems.getItemsAt(seen);
- failTimer = new KTimer(300000);
- } else {
- if (!underAttackTimer.isDone()) return 50;
- if (!shouldChange && !movingTimer.isDone()) return 50;
- if (last == null || (seen != null && groundItems.getItemsAt(seen).length != before.length))
- dropTimer = new KTimer(0);
- int[] dropIdArray = new int[savedItems.size()];
- for (int i = 0; i < savedItems.size(); i++) {
- dropIdArray[i] = savedItems.get(i).ID;
- }
- GroundItem[] ground = groundItems.getItems(3, dropIdArray);
- for (GroundItem g : ground) {
- for (SavedItem savedItem : savedItems)
- if (savedItem.ID == g.getID()) {
- if (!inventory.isFull() || inventory.getCount(true, savedItem.ID) != inventory.getCount(false, savedItem.ID)) {
- if (g.doAction("Take " + savedItem.name)) {
- dropTimer = new KTimer(0);
- return random(1200, 1300);
- }
- }
- }
- }
- if (getRealDistanceTo(startingLoc, false) > maxDist) {
- walkPath(fixPath(startingLoc));
- movingTimer = new KTimer(1300);
- return 50;
- }
- if (!dropTimer.isDone()) return 50;
- if (nextMonster.onScreen() && nextMonster.doAction("Attack " + nextMonster.getName()) && menu.contains("Attack " + nextMonster.getName())) {
- movingTimer = new KTimer(1300);
- failSafe = 0;
- return random(600, 750);
- } else {
- if (failSafe > 3 || getRealDistanceTo(nextMonster.getLocation(), false) > 4) {
- walkPath(fixPath(nextMonster.getLocation()));
- movingTimer = new KTimer(1300);
- int angleTo = camera.getAngleTo(nextMonster.getLocation());
- double angle = camera.getAngle();
- if((angleTo-angle)%360>40)
- camera.setAngle(angleTo);
- } else if (failSafe > 1 || !nextMonster.onScreen()) {
- camera.setAngleTo(nextMonster.getLocation());
- int angleTo = camera.getAngleTo(nextMonster.getLocation());
- double angle = camera.getAngle();
- if((angleTo-angle)%360>40)
- camera.setAngle(angleTo);
- }
- camera.setAltitude(false);
- failSafe++;
- }
- return 50;
- }
- if (nextMonster == null) return 50;
- if (!nextMonster.onScreen() && getRealDistanceTo(nextMonster.getLocation(), false) > 6)
- camera.setAngleTo(nextMonster.getLocation());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return 50;
- }
- public boolean onScreen(NPC n) {
- Tile l = n.getLocation();
- Point p = calculations.tileToScreen(l.getX(),l.getY(),.5,.5,1);
- return calculations.onScreen(p);
- }
- @Override
- public void stop() {
- closeWindows(true);
- }
- public void closeWindows(boolean m) {
- if (m && main != null) main.dispose();
- if (monsterSettings != null) monsterSettings.dispose();
- if (itemSettings != null) itemSettings.dispose();
- if (consumableSettings != null) consumableSettings.dispose();
- if (otherSettings != null) otherSettings.dispose();
- if (control != null) control.dispose();
- if (bankWalkSettings != null) bankWalkSettings.dispose();
- }
- @Override
- public void onStart() {
- runTime = new KTimer();
- failTimer = new KTimer(300000);
- main = new MainFrame();
- deathTimer = new KTimer(0);
- dropTimer = new KTimer(0);
- fightingTimer = new KTimer(10000);
- underAttackTimer = new KTimer(1);
- startingLoc = getMyPlayer().getLocation();
- movingTimer = new KTimer(0);
- mouse.setDefaultSpeed(random(3.0, 4.0));
- }
- @Override
- public String getName() {
- return "Mike's Fighter";
- }
- private Tile[] fixPath(Tile
- t) {
- int startX = getMyPlayer().getLocation().getX();
- int startY = getMyPlayer().getLocation().getY();
- int destinationX = t.getX();
- int destinationY = t.getY();
- double dx,
- dy;
- ArrayList<Tile> list = new ArrayList<Tile>();
- list.add(new Tile(startX, startY));
- while (Math.hypot(destinationY - startY, destinationX - startX) > 8) {
- dx = destinationX - startX;
- dy = destinationY - startY;
- int gamble = random(1, 4);
- while (Math.hypot(dx, dy) > gamble) {
- dx *= .95;
- dy *= .95;
- }
- startX += (int) dx + random(-2, 3);
- startY += (int) dy + random(-2, 3);
- list.add(new Tile(startX, startY));
- }
- list.add(new Tile(destinationX, destinationY));
- return list.toArray(new Tile[list.size()]);
- }
- public boolean walkPath(Tile[] path) {
- if (path == null || path.length == 0) {
- throw new IllegalArgumentException("path can not be null or empty");
- }
- if (walking.getEnergy() > random(30, 99)) {
- walking.setRunning(true);
- }
- Tile last = null;
- for (Tile aPath : path) {
- if (walking.mapCircle().contains(getCalculations().tileToMinimap(aPath))) {
- last = aPath;
- }
- }
- if (last != null) {
- walking.walkToMM(new Tile(last.getX(), last.getY()));
- return true;
- }
- return false;
- }
- public void saveSettings(File f) {
- String raw = "";
- for (SavedMonster m : savedMonsters) {
- raw += "monster\t" + m.name + "\t" + m.ID + "\t" + m.deathTime + "\n";
- }
- for (SavedItem i : savedItems) {
- raw += "item\t" + i.name + "\t" + i.ID + "\t" + i.alch + "\n";
- }
- for (SavedConsumable c : savedConsumables) {
- raw += "consumable\t" + c.name + "\t" + c.at + "\t" + c.type + "\t" + c.bank + "\t" + c.heal + "\n";
- }
- for (SavedObstacle o : savedObstacles) {
- raw += "obstacle\t" + o.location.x + "\t" + o.location.y + "\t" + o.location.plane + "\t" + o.ID + "\t" + o.action + "\t" + o.direction + "\n";
- }
- for (BWT tile : path) {
- raw += "path\t" + tile.x + "\t" + tile.y + "\t" + tile.plane + "\n";
- }
- raw += "maxdistance\t" + otherSettings.maxDistField.getText() + "\n";
- raw += "bankfull\t" + bankFull;
- try {
- PrintWriter pw = new PrintWriter(new FileWriter(f, false));
- pw.println(raw);
- pw.close();
- } catch (Exception e) {
- JOptionPane.showMessageDialog(new JFrame("ERROR"), "You cannot save it here! Save it to the same folder as your KBot jar!");
- log(e.getMessage());
- }
- }
- private String readFile(String filePath) throws java.io.IOException {
- byte[] buffer = new byte[(int) new File(filePath).length()];
- BufferedInputStream f = new BufferedInputStream(new FileInputStream(filePath));
- f.read(buffer);
- return new String(buffer);
- }
- public void loadSettings(File f) {
- BufferedReader br;
- savedItems = new ArrayList<SavedItem>();
- savedMonsters = new ArrayList<SavedMonster>();
- savedConsumables = new ArrayList<SavedConsumable>();
- savedObstacles = new ArrayList<SavedObstacle>();
- path = new ArrayList<BWT>();
- try {
- String[] s = readFile(f.getPath()).split("\n");
- // dis.available() returns 0 if the file does not have more lines.
- for (String line : s) {
- String[] v = line.split("\t");
- log(line);
- if (v[0].equals("monster")) {
- savedMonsters.add(new SavedMonster(Integer.parseInt(v[2]), v[1], Integer.parseInt(v[3])));
- continue;
- }
- if (v[0].equals("item")) {
- savedItems.add(new SavedItem(Integer.parseInt(v[2]), v[1], Boolean.parseBoolean(v[3])));
- continue;
- }
- if (v[0].equals("consumable")) {
- savedConsumables.add(new SavedConsumable(v[1], Integer.parseInt(v[2]), v[3], Integer.parseInt(v[4]), Integer.parseInt(v[5])));
- continue;
- }
- if (v[0].equals("obstacle")) {
- 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])));
- continue;
- }
- if (v[0].equals("path")) {
- path.add(new BWT(Integer.parseInt(v[1]), Integer.parseInt(v[2]), Integer.parseInt(v[3])));
- continue;
- }
- if (v[0].equals("maxdistance"))
- maxDist = Integer.parseInt(v[1]);
- if (v[0].equals("bankfull"))
- bankFull = Boolean.parseBoolean(v[1]);
- }
- // dispose all the resources after using them.
- } catch (Exception e) {
- e.printStackTrace();
- log(e.getMessage());
- }
- }
- class MainFrame extends JFrame {
- JButton itemSettingsButton;
- JButton combatSettingsButton;
- JButton otherSettingsButton;
- JButton consumableSettingsButton;
- JButton startScript;
- JButton exportButton;
- JButton importButton;
- JButton bankWalkSettingsButton;
- public MainFrame() {
- itemSettings = new ItemSettings();
- monsterSettings = new MonsterSettings();
- otherSettings = new OtherSettings();
- consumableSettings = new ConsumableSettings();
- bankWalkSettings = new BankWalkSettings();
- setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 1.0; //request any extra vertical space
- c.insets = new Insets(3, 3, 3, 3);
- setTitle("Mike's Fighter");
- itemSettingsButton = new JButton("Item Settings");
- c.gridx = 0;
- c.gridy = 0;
- add(itemSettingsButton, c);
- itemSettingsButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- itemSettings.setVisible(true);
- }
- });
- combatSettingsButton = new JButton("Monster Settings");
- c.gridx = 1;
- add(combatSettingsButton, c);
- combatSettingsButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- monsterSettings.setVisible(true);
- }
- });
- consumableSettingsButton = new JButton("Consumable Settings");
- c.gridy = 0;
- c.gridx = 2;
- add(consumableSettingsButton, c);
- consumableSettingsButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- consumableSettings.setVisible(true);
- }
- });
- otherSettingsButton = new JButton("Other Settings");
- c.gridy = 1;
- c.gridx = 0;
- add(otherSettingsButton, c);
- otherSettingsButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- otherSettings.setVisible(true);
- }
- });
- exportButton = new JButton("Save Settings");
- exportButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- bankFull = otherSettings.bankType.isSelected();
- JFileChooser fc = new JFileChooser();
- int rc = fc.showDialog(null, "WILL ONLY SAVE IN YOUR FOLDER WITH kbot.jar");
- fc.setCurrentDirectory(new File("."));
- if (rc == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- String filename = file.getAbsolutePath();
- saveSettings(file);
- }
- }
- });
- c.gridx = 1;
- add(exportButton, c);
- importButton = new JButton("Load Settings");
- importButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- JFileChooser fc = new JFileChooser();
- int rc = fc.showDialog(null, "Load fighter settings");
- if (rc == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- String filename = file.getAbsolutePath();
- loadSettings(file);
- closeWindows(false);
- itemSettings = new ItemSettings();
- monsterSettings = new MonsterSettings();
- otherSettings = new OtherSettings();
- consumableSettings = new ConsumableSettings();
- bankWalkSettings = new BankWalkSettings();
- }
- }
- });
- c.gridx = 2;
- add(importButton, c);
- bankWalkSettingsButton = new JButton("Bank Walk");
- c.gridx = 0;
- c.gridy = 2;
- add(bankWalkSettingsButton, c);
- bankWalkSettingsButton.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- bankWalkSettings.setVisible(true);
- }
- });
- startScript = new JButton("Start Script");
- c.gridx = 1;
- c.gridy = 2;
- c.gridwidth = 2;
- add(startScript, c);
- startScript.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- dispose();
- started = true;
- bankFull = otherSettings.bankType.isSelected();
- runTime = new KTimer();
- maxDist = Integer.parseInt(otherSettings.maxDistField.getText());
- }
- });
- setVisible(true);
- setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- setSize(400, 120);
- setResizable(false);
- setLocationRelativeTo(getRootPane());
- }
- }
- class ItemSettings extends JFrame {
- JLabel label;
- public ItemSettings() {
- setTitle("Item Settings");
- setSize(300, 300);
- setResizable(false);
- JScrollPane scroll = new JScrollPane();
- JPanel panel = new JPanel();
- panel.setSize(300, 300);
- setLocationRelativeTo(getRootPane());
- scroll.setPreferredSize(new Dimension(200, 200));
- panel.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 1.0; //request any extra vertical space
- c.insets = new Insets(3, 3, 3, 3);
- c.gridx = 0;
- c.gridy = 0;
- add(scroll);
- scroll.getViewport().add(panel);
- JButton newb = new JButton("Create new Item");
- panel.add(newb, c);
- newb.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedItems.add(new SavedItem(-1, "New Item", false));
- itemSettings.dispose();
- itemSettings = new ItemSettings();
- itemSettings.setVisible(true);
- }
- });
- for (int i = 0; i < savedItems.size(); i++) {
- c.gridy++;
- final int s = i;
- JButton item = new JButton(savedItems.get(i).name);
- panel.add(item, c);
- item.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (control != null) control.dispose();
- control = new ItemControl(s);
- control.setVisible(true);
- }
- });
- }
- }
- }
- class ItemControl extends JFrame {
- public ItemControl(final int index) {
- setLayout(new FlowLayout());
- final String itemName = savedItems.get(index).name;
- final int itemID = savedItems.get(index).ID;
- final boolean alch = savedItems.get(index).alch;
- setTitle("Item Control - " + itemName);
- final JTextField nameField = new JTextField("" + itemName);
- nameField.setColumns(10);
- final JTextField idField = new JTextField("" + itemID);
- idField.setColumns(5);
- final JCheckBox alchField = new JCheckBox("Alch");
- alchField.setSelected(alch);
- final JButton save = new JButton("Save");
- final JButton delete = new JButton("Delete");
- final JLabel info = new JLabel("Use the Grand Exchange or the built-in inventory debugger to get item IDs.");
- Container c = getContentPane();
- setSize(420, 80);
- setLocationRelativeTo(getRootPane());
- c.add(nameField);
- c.add(idField);
- c.add(alchField);
- c.add(save);
- c.add(delete);
- c.add(info);
- save.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedItems.get(index).name = nameField.getText();
- savedItems.get(index).ID = Integer.parseInt(idField.getText());
- savedItems.get(index).alch = alchField.isSelected();
- itemSettings.dispose();
- itemSettings = new ItemSettings();
- itemSettings.setVisible(true);
- control.dispose();
- }
- });
- delete.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedItems.remove(index);
- itemSettings.dispose();
- itemSettings = new ItemSettings();
- itemSettings.setVisible(true);
- control.dispose();
- }
- });
- setResizable(false);
- }
- }
- class ConsumableSettings extends JFrame {
- JLabel label;
- public ConsumableSettings() {
- setTitle("Consumable Settings");
- setSize(300, 300);
- setResizable(false);
- JScrollPane scroll = new JScrollPane();
- JPanel panel = new JPanel();
- panel.setSize(300, 300);
- setLocationRelativeTo(getRootPane());
- scroll.setPreferredSize(new Dimension(200, 200));
- panel.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 1.0; //request any extra vertical space
- c.insets = new Insets(3, 3, 3, 3);
- c.gridx = 0;
- c.gridy = 0;
- add(scroll);
- scroll.getViewport().add(panel);
- JButton newb = new JButton("Add Consumable");
- panel.add(newb, c);
- newb.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedConsumables.add(new SavedConsumable("New Consumable", -1, "Health", 0, -1));
- consumableSettings.dispose();
- consumableSettings = new ConsumableSettings();
- consumableSettings.setVisible(true);
- }
- });
- for (int i = 0; i < savedConsumables.size(); i++) {
- c.gridy++;
- final int s = i;
- JButton item = new JButton(savedConsumables.get(i).name);
- panel.add(item, c);
- item.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (control != null) control.dispose();
- control = new ConsumableControl(s);
- control.setVisible(true);
- }
- });
- }
- }
- }
- class ConsumableControl extends JFrame {
- public ConsumableControl(final int index) {
- setLayout(new FlowLayout());
- /*
- String name;
- int at;
- String type;
- int bank;
- int heal;*/
- Container c = getContentPane();
- final String name = savedConsumables.get(index).name;
- final int at = savedConsumables.get(index).at;
- final String type = savedConsumables.get(index).type;
- final int bank = savedConsumables.get(index).bank;
- final int heal = savedConsumables.get(index).heal;
- setTitle("Consumable Control - " + name);
- final JTextField nameField = new JTextField("" + name);
- 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>");
- nameField.setColumns(10);
- final JTextField atField = new JTextField("" + at);
- 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>");
- atField.setColumns(3);
- final JComboBox typeList = new JComboBox(statsArray);
- typeList.setToolTipText("What type is this consumable?");
- final JTextField bankField = new JTextField("" + bank);
- 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>");
- bankField.setColumns(3);
- final JTextField healField = new JTextField("" + heal);
- healField.setToolTipText("<html>How much does this food heal? Only<br> enabled when the consumable type is Health.</html>");
- healField.setColumns(3);
- int atIndex = 3;
- for (int i = 0; i < statsArray.length; i++) {
- if (statsArray[i].equals(type)) atIndex = i;
- }
- typeList.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JComboBox cb = (JComboBox) e.getSource();
- String petName = (String) cb.getSelectedItem();
- healField.setEnabled(false);
- if (cb.getSelectedIndex() == 3) {
- healField.setEnabled(true);
- }
- }
- });
- typeList.setSelectedIndex(atIndex);
- final JButton save = new JButton("Save");
- final JButton delete = new JButton("Delete");
- final JLabel info = new JLabel("Hover over a box to find its function.");
- setSize(500, 80);
- setLocationRelativeTo(getRootPane());
- c.add(nameField);
- c.add(atField);
- c.add(typeList);
- c.add(healField);
- c.add(bankField);
- c.add(save);
- c.add(delete);
- c.add(info);
- save.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- 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())));
- consumableSettings.dispose();
- consumableSettings = new ConsumableSettings();
- consumableSettings.setVisible(true);
- control.dispose();
- }
- });
- delete.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedConsumables.remove(index);
- consumableSettings.dispose();
- consumableSettings = new ConsumableSettings();
- consumableSettings.setVisible(true);
- control.dispose();
- }
- });
- setResizable(false);
- }
- }
- class MonsterSettings extends JFrame {
- JLabel label;
- public MonsterSettings() {
- setTitle("Monster Settings");
- setSize(300, 300);
- setResizable(false);
- setLocationRelativeTo(getRootPane());
- JScrollPane scroll = new JScrollPane();
- JPanel panel = new JPanel();
- panel.setSize(300, 300);
- scroll.setPreferredSize(new Dimension(300, 300));
- panel.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 1.0; //request any extra vertical space
- c.insets = new Insets(3, 3, 3, 3);
- c.gridx = 0;
- c.gridy = 0;
- add(scroll);
- scroll.getViewport().add(panel);
- JButton newb = new JButton("Create new Monster");
- panel.add(newb, c);
- newb.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedMonsters.add(new SavedMonster(-1, "New Monster", 3000));
- monsterSettings.dispose();
- monsterSettings = new MonsterSettings();
- monsterSettings.setVisible(true);
- }
- });
- for (int i = 0; i < savedMonsters.size(); i++) {
- c.gridy++;
- final int s = i;
- JButton monster = new JButton(savedMonsters.get(i).name);
- panel.add(monster, c);
- monster.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (control != null) control.dispose();
- control = new MonsterControl(s);
- control.setVisible(true);
- }
- });
- }
- }
- }
- class MonsterControl extends JFrame {
- public MonsterControl(final int index) {
- setLayout(new FlowLayout());
- final String monsterName = savedMonsters.get(index).name;
- final int monsterID = savedMonsters.get(index).ID;
- final int deathWait = savedMonsters.get(index).deathTime;
- setTitle("Monster Control - " + monsterName);
- final JTextField nameField = new JTextField("" + monsterName);
- nameField.setColumns(10);
- final JTextField idField = new JTextField("" + monsterID);
- idField.setColumns(5);
- final JSlider deathWaitField = new JSlider(0, 10000, deathWait);
- deathWaitField.setMajorTickSpacing(2000);
- deathWaitField.setMinorTickSpacing(1000);
- deathWaitField.setPaintTicks(true);
- deathWaitField.setPaintLabels(true);
- deathWaitField.setToolTipText("Maximum time to wait after a monster dies to pick up its items.");
- final JButton save = new JButton("Save");
- final JButton delete = new JButton("Delete");
- final JLabel info = new JLabel("Slider function: Maximum time (in milliseconds) to wait after a monster dies to pick up its items.");
- final JLabel info2 = new JLabel("Monster ID is optional; Keep it at -1 if you don't need to use it.");
- Container c = getContentPane();
- setSize(550, 120);
- c.add(nameField);
- c.add(idField);
- c.add(deathWaitField);
- c.add(save);
- c.add(delete);
- c.add(info);
- c.add(info2);
- save.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedMonsters.get(index).name = nameField.getText();
- savedMonsters.get(index).ID = Integer.parseInt(idField.getText());
- savedMonsters.get(index).deathTime = deathWaitField.getValue();
- monsterSettings.dispose();
- monsterSettings = new MonsterSettings();
- monsterSettings.setVisible(true);
- control.dispose();
- }
- });
- delete.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedMonsters.remove(index);
- monsterSettings.dispose();
- monsterSettings = new MonsterSettings();
- monsterSettings.setVisible(true);
- control.dispose();
- }
- });
- setResizable(false);
- }
- }
- class OtherSettings extends JFrame {
- JTextField maxDistField;
- JCheckBox bankType;
- public OtherSettings() {
- setLayout(new FlowLayout());
- Container c = getContentPane();
- c.add(new JLabel("Max Distance:"));
- maxDistField = new JTextField();
- maxDistField.setText("" + maxDist);
- c.add(maxDistField);
- 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>")));
- bankType.setSelected(bankFull);
- setSize(550, 120);
- setResizable(false);
- }
- }
- class BankWalkSettings extends JFrame {
- public BankWalkSettings() {
- setTitle("Bankwalk Settings");
- setSize(300, 300);
- setResizable(false);
- setLocationRelativeTo(getRootPane());
- JScrollPane scroll = new JScrollPane();
- JPanel panel = new JPanel();
- panel.setSize(300, 300);
- scroll.setPreferredSize(new Dimension(300, 300));
- panel.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 1.0; //request any extra vertical space
- c.insets = new Insets(3, 3, 3, 3);
- c.gridx = 0;
- c.gridy = 0;
- add(scroll);
- scroll.getViewport().add(panel);
- final JButton newTile = new JButton("Add tile (" + path.size() + ")");
- newTile.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- path.add(new BWT(getMyPlayer().getLocation().getX(), getMyPlayer().getLocation().getY(), game.getCurrentFloor()));
- newTile.setText("Add tile (" + path.size() + ")");
- }
- });
- panel.add(newTile, c);
- c.gridy = 1;
- JButton newb = new JButton("Create new Obstacle");
- panel.add(newb, c);
- newb.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedObstacles.add(new SavedObstacle(new BWT(0, 0, game.getCurrentFloor()), -1, "Open Door", 0));
- bankWalkSettings.dispose();
- bankWalkSettings = new BankWalkSettings();
- bankWalkSettings.setVisible(true);
- }
- });
- for (int i = 0; i < savedObstacles.size(); i++) {
- c.gridy++;
- final int s = i;
- JButton monster = new JButton(savedObstacles.get(i).ID + ": " + savedObstacles.get(i).action);
- panel.add(monster, c);
- monster.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (control != null) control.dispose();
- control = new ObstacleControl(s);
- control.setVisible(true);
- }
- });
- }
- }
- }
- class ObstacleControl extends JFrame {
- public ObstacleControl(final int index) {
- setLayout(new FlowLayout());
- final SavedObstacle o = savedObstacles.get(index);
- setTitle("Obstacle Control - " + o.action + " - " + o.location.toTile().toString());
- final JTextField actionField = new JTextField("" + o.action);
- actionField.setColumns(10);
- final JTextField idField = new JTextField("" + o.ID);
- idField.setColumns(5);
- final JTextField xField = new JTextField("" + o.location.x);
- final JTextField yField = new JTextField("" + o.location.y);
- final JTextField planeField = new JTextField("" + o.location.plane);
- final String[] combo = {"Both Ways", "From Bank", "To Bank"};
- final JComboBox directionField = new JComboBox(combo);
- directionField.setSelectedIndex(o.direction);
- xField.setColumns(4);
- yField.setColumns(4);
- planeField.setColumns(4);
- actionField.setColumns(12);
- final JButton save = new JButton("Save");
- final JButton delete = new JButton("Delete");
- Container c = getContentPane();
- setSize(700, 60);
- c.add(new JLabel("Action:"));
- c.add(actionField);
- c.add(new JLabel("ID:"));
- c.add(idField);
- c.add(new JLabel("x:"));
- c.add(xField);
- c.add(new JLabel("y:"));
- c.add(yField);
- c.add(new JLabel("height:"));
- c.add(planeField);
- c.add(directionField);
- c.add(save);
- c.add(delete);
- save.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedObstacles.set(index, new SavedObstacle(new BWT(Integer.parseInt(xField.getText().trim()),
- Integer.parseInt(yField.getText().trim()),
- Integer.parseInt(planeField.getText().trim())),
- Integer.parseInt(idField.getText().trim()),
- actionField.getText(), directionField.getSelectedIndex()));
- bankWalkSettings.dispose();
- bankWalkSettings = new BankWalkSettings();
- bankWalkSettings.setVisible(true);
- control.dispose();
- }
- });
- delete.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- savedObstacles.remove(index);
- bankWalkSettings.dispose();
- bankWalkSettings = new BankWalkSettings();
- bankWalkSettings.setVisible(true);
- control.dispose();
- }
- });
- setResizable(false);
- }
- }
- private final int BLOCKED_0_NORTH = 0x2;
- private final int BLOCKED_0_NORTH_EAST = 0x4;
- private final int BLOCKED_0_EAST = 0x8;
- private final int BLOCKED_0_SOUTH_EAST = 0x10;
- private final int BLOCKED_0_SOUTH = 0x20;
- private final int BLOCKED_0_SOUTH_WEST = 0x40;
- private final int BLOCKED_0_WEST = 0x80;
- private final int BLOCKED_0_NORTH_WEST = 0x200;
- private final int BLOCKED_1_NORTH = 0x400;
- private final int BLOCKED_1_NORTH_EAST = 0x800;
- private final int BLOCKED_1_EAST = 0x1000;
- private final int BLOCKED_1_SOUTH_EAST = 0x2000;
- private final int BLOCKED_1_SOUTH = 0x4000;
- private final int BLOCKED_1_SOUTH_WEST = 0x8000;
- private final int BLOCKED_1_WEST = 0x10000;
- private final int BLOCKED_1_NORTH_WEST = 0x40000;
- private final int BLOCKED_2_NORTH = 0x800000;
- private final int BLOCKED_2_NORTH_EAST = 0x1000000;
- private final int BLOCKED_2_EAST = 0x2000000;
- private final int BLOCKED_2_SOUTH_EAST = 0x4000000;
- private final int BLOCKED_2_SOUTH = 0x8000000;
- private final int BLOCKED_2_SOUTH_WEST = 0x10000000;
- private final int BLOCKED_2_WEST = 0x20000000;
- private final int BLOCKED_2_NORTH_WEST = 0x80000000;
- private final int BLOCK_0 = 0x100;
- private final int BLOCK_1 = 0x40000;
- private final int BLOCK_2 = 0x200000;
- private final int BLOCK_3 = 0x40000000;
- private final int FULL_BLOCK = /*BLOCK_0 | */
- BLOCK_1 | BLOCK_2 | BLOCK_3;
- public int getRealDistanceTo(Tile
- dest, final boolean isObject) {
- return getRealDistanceTo(getMyPlayer().getLocation(), dest, isObject);
- }
- public int getRealDistanceTo(Tile
- start, Tile
- dest, final boolean isObject) {
- final int startX = (start.getX() - getClient().getBaseX() + 1);
- final int startY = (start.getY() - getClient().getBaseY() + 1);
- final int destX = dest.getX() - getClient().getBaseX();
- final int destY = dest.getY() - getClient().getBaseY();
- final int[][] via = new int[104][104];
- final int[][] cost = new int[104][104];
- final int[] tileQueueX = new int[4000];
- final int[] tileQueueY = new int[4000];
- for (int xx = 0; xx < 104; xx++) {
- for (int yy = 0; yy < 104; yy++) {
- via[xx][yy] = 0;
- cost[xx][yy] = 99999999;
- }
- }
- int curX = startX;
- int curY = startY;
- via[startX][startY] = 99;
- cost[startX][startY] = 0;
- int head = 0;
- int tail = 0;
- tileQueueX[head] = startX;
- tileQueueY[head++] = startY;
- boolean foundPath = false;
- final int pathLength = tileQueueX.length;
- final int blocks[][] = getClient().getMapDataArray()[getClient().getCurrentPlane()].getTileData();
- while (tail != head) {
- curX = tileQueueX[tail];
- curY = tileQueueY[tail];
- if (!isObject && (curX == destX) && (curY == destY)) {
- foundPath = true;
- break;
- } else if (isObject) {
- if (((curX == destX) && (curY == destY + 1)) || ((curX == destX) && (curY == destY - 1)) || ((curX == destX + 1) && (curY == destY)) || ((curX == destX - 1) && (curY == destY))) {
- foundPath = true;
- break;
- }
- }
- tail = (tail + 1) % pathLength;
- // Big and ugly block of code
- final int thisCost = cost[curX][curY] + 1;
- if ((curY > 0) && (via[curX][curY - 1] == 0) && ((blocks[curX][curY - 1] & (FULL_BLOCK | BLOCKED_0_NORTH | BLOCKED_1_NORTH | BLOCKED_2_NORTH)) == 0)) {
- tileQueueX[head] = curX;
- tileQueueY[head] = curY - 1;
- head = (head + 1) % pathLength;
- via[curX][curY - 1] = 1;
- cost[curX][curY - 1] = thisCost;
- }
- if ((curX > 0) && (via[curX - 1][curY] == 0) && ((blocks[curX - 1][curY] & (FULL_BLOCK | BLOCKED_0_EAST | BLOCKED_1_EAST | BLOCKED_2_EAST)) == 0)) {
- tileQueueX[head] = curX - 1;
- tileQueueY[head] = curY;
- head = (head + 1) % pathLength;
- via[curX - 1][curY] = 2;
- cost[curX - 1][curY] = thisCost;
- }
- 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)) {
- tileQueueX[head] = curX;
- tileQueueY[head] = curY + 1;
- head = (head + 1) % pathLength;
- via[curX][curY + 1] = 4;
- cost[curX][curY + 1] = thisCost;
- }
- 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)) {
- tileQueueX[head] = curX + 1;
- tileQueueY[head] = curY;
- head = (head + 1) % pathLength;
- via[curX + 1][curY] = 8;
- cost[curX + 1][curY] = thisCost;
- }
- 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)) {
- tileQueueX[head] = curX - 1;
- tileQueueY[head] = curY - 1;
- head = (head + 1) % pathLength;
- via[curX - 1][curY - 1] = 3;
- cost[curX - 1][curY - 1] = thisCost;
- }
- 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)) {
- tileQueueX[head] = curX - 1;
- tileQueueY[head] = curY + 1;
- head = (head + 1) % pathLength;
- via[curX - 1][curY + 1] = 6;
- cost[curX - 1][curY + 1] = thisCost;
- }
- 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)) {
- tileQueueX[head] = curX + 1;
- tileQueueY[head] = curY - 1;
- head = (head + 1) % pathLength;
- via[curX + 1][curY - 1] = 9;
- cost[curX + 1][curY - 1] = thisCost;
- }
- 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)) {
- tileQueueX[head] = curX + 1;
- tileQueueY[head] = curY + 1;
- head = (head + 1) % pathLength;
- via[curX + 1][curY + 1] = 12;
- cost[curX + 1][curY + 1] = thisCost;
- }
- }
- if (foundPath) return cost[curX][curY];
- return -1;
- }
- RoundRectangle2D mainPaintBox;
- GradientPaint gp;
- public void drawDefaultPaint(Graphics2D g, int x, int y, int width, String... strings) {
- int height = strings.length * 15;
- if (mainPaintBox == null) {
- mainPaintBox = new RoundRectangle2D.Double(x, y, width, height, 5, 5);
- gp = new GradientPaint(x, y, new Color(0, 0, 0, 50), x, y + height, new Color(0, 0, 0, 200), false);
- }
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g.setFont(new Font("Arial", Font.BOLD, 10));
- g.setPaint(gp);
- g.fill(mainPaintBox);
- g.setColor(Color.black);
- g.draw(mainPaintBox);
- g.setColor(Color.white);
- x += 2;
- y += 10;
- for (String s : strings) {
- g.drawString(s, x, y);
- y += 15;
- }
- }
- public String format(int num) {
- DecimalFormat df = new DecimalFormat();
- DecimalFormatSymbols dfs = new DecimalFormatSymbols();
- dfs.setGroupingSeparator(',');
- df.setDecimalFormatSymbols(dfs);
- return df.format(num);
- }
- class SavedItem {
- int ID;
- String name;
- boolean alch;
- public SavedItem(int ID, String name, boolean alch) {
- this.ID = ID;
- this.name = name;
- this.alch = alch;
- }
- }
- class SavedMonster {
- int ID;
- String name;
- int deathTime;
- public SavedMonster(int ID, String name, int deathTime) {
- this.ID = ID;
- this.name = name;
- this.deathTime = deathTime;
- }
- }
- class SavedConsumable {
- String name;
- int at;
- String type;
- int bank;
- int heal;
- public SavedConsumable(String name, int at, String type, int bank, int heal) {
- this.name = name;
- this.at = at;
- this.type = type;
- this.bank = bank;
- this.heal = heal;
- }
- }
- class BWT {
- int x;
- int y;
- int plane;
- public BWT(int x, int y, int plane) {
- this.x = x;
- this.y = y;
- this.plane = plane;
- }
- public Tile toTile() {
- return new Tile(x, y);
- }
- }
- class SavedObstacle {
- BWT location;
- int ID;
- String action;
- int direction;
- final static int BOTH_WAYS = 0;
- final static int FROM_BANK = 1;
- final static int TO_BANK = 2;
- public SavedObstacle(BWT location, int ID, String action, int direction) {
- this.location = location;
- this.ID = ID;
- this.action = action;
- this.direction = direction;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement