Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.awt.font.FontRenderContext;
- import java.awt.geom.AffineTransform;
- import java.awt.geom.RoundRectangle2D;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.lang.reflect.Method;
- import java.net.URL;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.EnumSet;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.logging.Logger;
- import javax.imageio.ImageIO;
- import javax.swing.JOptionPane;
- import org.rsbot.event.events.MessageEvent;
- import org.rsbot.event.listeners.MessageListener;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.Equipment;
- import org.rsbot.script.methods.Game;
- import org.rsbot.script.methods.GrandExchange;
- import org.rsbot.script.methods.GrandExchange.GEItem;
- import org.rsbot.script.methods.Magic;
- import org.rsbot.script.methods.Skills;
- import org.rsbot.script.util.Filter;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSInterface;
- import org.rsbot.script.wrappers.RSItem;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSObject;
- import org.rsbot.script.wrappers.RSPath.TraversalOption;
- import org.rsbot.script.wrappers.RSTile;
- import org.rsbot.script.wrappers.RSTilePath;
- import org.rsbot.util.GlobalConfiguration;
- @ScriptManifest(authors = "Equinox_", keywords = "Runecrafting", name = "Equinox_ ZMI Crafter", version = 0.7, description = "Beta Version")
- /**
- * @author Equinox_
- */
- public class EquinoxZMICrafter extends Script implements MessageListener,
- PaintListener, MouseMotionListener, MouseListener {
- // Variables
- final String baseURL = "http://equinox-scripts.web44.net/scripts/natcrafter";
- final double VERSION = getClass().getAnnotation(ScriptManifest.class)
- .version();
- final String author = PaintFormatter.formatList(getClass().getAnnotation(
- ScriptManifest.class).authors());
- final String name = getClass().getAnnotation(ScriptManifest.class).name();
- public final static int COSMIC_RUNE_ID = 564;
- public final static int ASTRAL_RUNE_ID = 9075;
- public static final int AIR_STAFF_ID = 1405;
- public final static int PURE_ESS_ID = 7936;
- public final static int ZMI_ALTAR_ID = 26847;
- public final static int AIR_RUNE_ID = 556;
- public final static int NPC_CONTACT_ANIM = 4413;
- public final static int BANKER_ID = 6362;
- public final static int CRAFT_RUNE_ANIM = 791;
- public final static int FIRE_RUNE_ID = 554;
- public final static int CRACK_IN = 26844;
- public final static int CRACK_OUT = 26845;
- public final static RSTile alterDet = new RSTile(3314, 4813, 0);
- public final static int PAY_BANK_INTERFACE = 619;
- public final static int LAW_RUNE = 563;
- public final static int ASTRAL_RUNE = 9075;
- public final static int EARTH_RUNE = 557;
- public final static String[] PAY_BANKER_ORDER = { "fire", "air", "mind",
- "body", "water", "earth", "cosmic", "chaos", "astral", "law",
- "death", "blood", "nature", "soul" };
- public final static RSTile[][] SAFE_MESH = { { new RSTile(3273, 4856, 0) },
- { new RSTile(3280, 4848, 0) }, { new RSTile(3279, 4839, 0) },
- { new RSTile(3286, 4832, 0) }, { new RSTile(3297, 4834, 0) },
- { new RSTile(3309, 4836, 0) }, { new RSTile(3320, 4833, 0) },
- { new RSTile(3310, 4828, 0) }, { new RSTile(3301, 4828, 0) },
- { new RSTile(3289, 4829, 0) }, { new RSTile(3280, 4822, 0) },
- { new RSTile(3290, 4820, 0) }, { new RSTile(3301, 4820, 0) },
- { new RSTile(3308, 4820, 0) } };
- public final static RSTile[][] DANGER_MESH = {
- { new RSTile(3272, 4851, 0), new RSTile(3269, 4854, 0) },
- { new RSTile(3272, 4844, 0), new RSTile(3268, 4846, 0) },
- { new RSTile(3271, 4837, 0), new RSTile(3268, 4838, 0) },
- { new RSTile(3272, 4828, 0), new RSTile(3267, 4832, 0) },
- { new RSTile(3273, 4821, 0), new RSTile(3268, 4825, 0) },
- { new RSTile(3270, 4814, 0), new RSTile(3268, 4819, 0) },
- { new RSTile(3275, 4808, 0), new RSTile(3276, 4814, 0) },
- { new RSTile(3283, 4806, 0), new RSTile(3279, 4810, 0) },
- { new RSTile(3288, 4812, 0), new RSTile(3287, 4807, 0) },
- { new RSTile(3295, 4813, 0), new RSTile(3293, 4814, 0) },
- { new RSTile(3300, 4807, 0), new RSTile(3298, 4813, 0) },
- { new RSTile(3309, 4812, 0), new RSTile(3305, 4807, 0) } };
- public final RSTile[] OURANIA_PATH = { new RSTile(2469, 3245),
- new RSTile(2459, 3249), new RSTile(2455, 3239),
- new RSTile(2453, 3232) };
- public final static int POUCH_TRIES = 20;
- // Pouch IDs
- public static class Pouch {
- public final static int SMALL = 5509;
- public final static int MEDIUM = 5510;
- public final static int MEDIUM_DEGRADED = 5511;
- public final static int LARGE = 5512;
- public final static int LARGE_DEGRADED = 5513;
- public final static int GIANT = 5514;
- public final static int GIANT_DEGRADED = 5515;
- public final static int[] ALL = { SMALL, MEDIUM, MEDIUM_DEGRADED,
- LARGE, LARGE_DEGRADED, GIANT, GIANT_DEGRADED };
- public final static int[] ALL_REPAIRED = { SMALL, MEDIUM, LARGE, GIANT };
- public final static int[] ALL_DEGRADED = { MEDIUM_DEGRADED,
- LARGE_DEGRADED, GIANT_DEGRADED };
- public final static int[] ALL_DEGRADEABLE = { MEDIUM, MEDIUM_DEGRADED,
- LARGE, LARGE_DEGRADED, GIANT, GIANT_DEGRADED };
- }
- public static String serverMsg = "";
- public HashMap<PouchType, PouchState> pouches = new HashMap<PouchType, PouchState>();
- State currentState = State.LOST;
- public MeshPath alterMeshPath;
- public MeshPath bankMeshPath;
- public PaintInterface Paint;
- public NPCContact npcContact = new NPCContact();
- public ModifiedDrawMouse drawMouse = new ModifiedDrawMouse();
- public List<String> errorLog = new ArrayList<String>();
- public final static int[] food = { 333, 329, 379, 373, 7946, 361, 1901,
- 1899, 1897, 1895, 1893, 1891, 2142 };
- private static final int LADDER_ID = 26849;
- public Path pathTypeCurrent;
- public Options Options = new Options();
- // Options
- public class Options {
- public pouchRepairOption pouchRepair = pouchRepairOption.ONE;
- public boolean hasAirStaff = true;
- public boolean hasEarthStaff = true;
- public PouchCheckSystem pouchCheckSystem = PouchCheckSystem.SERVER_MSG;
- public Range walkingDistance = new Range(4, 6);
- public Path pathType = Path.Danger;
- public boolean chargeEnergy = true;
- public boolean tryOuraniaTeleport = true;
- public boolean onLunars = false;
- }
- public static int[] mergeArrays(int[] a1, int... a2) {
- int[] newArr = new int[a1.length + a2.length];
- for (int i = 0; i < a1.length; i++)
- newArr[i] = a1[i];
- for (int i = 0; i < a2.length; i++)
- newArr[a1.length + i] = a2[i];
- return newArr;
- }
- enum Path {
- Danger, Safe
- }
- /**
- * When to repair pouches
- *
- * @author Equinox_
- *
- */
- public enum pouchRepairOption {
- ONE, TWO, ALL, NEVER
- }
- /**
- * How to determine a pouch's state
- *
- * @author Equinox_
- *
- */
- public enum PouchCheckSystem {
- SERVER_MSG, INVENTORY_STATUS
- }
- /**
- * A range class for randomized items
- *
- * @author Equinox_
- *
- */
- public static class Range {
- public int MAX;
- public int MIN;
- public Range(int min, int max) {
- MAX = Math.max(min, max);
- MIN = Math.min(min, max);
- }
- public Range() {
- MAX = 1;
- MIN = -1;
- }
- /**
- * Get a random number in the range
- *
- * @return random int between min and max
- */
- public int random() {
- return (int) (Math.random() * (MAX - MIN)) + MIN;
- }
- public String toString() {
- return MIN + "-" + MAX;
- }
- }
- /**
- * Possible states in the process of nature runecrafting
- *
- * @author Equinox_
- *
- */
- public enum State {
- NEAR_BANK, NPC_CONTACT, BANK_WITHDRAW, BANK_DEPOSIT, FILL_POUCHES, TRAVERSE_ALTER, CRAFT_RUNES, EMPTY_POUCHES, TRAVERSE_BANK, LOST, EAT_FOOD, CHARGE_ENERGY, OURANIA_TELEPORT, LADDER_DOWN, TRAVERSE_OURANIA
- }
- /**
- * Possible states of pouches, Empty or Full
- *
- * @author Equinox_
- *
- */
- public enum PouchState {
- Empty, Full
- }
- /**
- * Different pouches and their possible IDs
- *
- * @author Equinox_
- *
- */
- public enum PouchType {
- Small(Pouch.SMALL), Medium(Pouch.MEDIUM, Pouch.MEDIUM_DEGRADED), Large(
- Pouch.LARGE, Pouch.LARGE_DEGRADED), Giant(Pouch.GIANT,
- Pouch.GIANT_DEGRADED);
- public int[] ids;
- private PouchType(int... ids) {
- this.ids = ids;
- }
- }
- /**
- * Gets the current state
- *
- * @return State the current state
- * @throws Exception
- * so we can pipe errors back to the recorder
- */
- public State getState() throws Exception {
- if (objects.getNearest(LADDER_ID) != null
- && objects.getNearest(LADDER_ID).isOnScreen())
- return State.LADDER_DOWN;
- if (objects.getNearest(ZMI_ALTAR_ID) != null)
- if (calc.tileOnMap(objects.getNearest(ZMI_ALTAR_ID).getLocation())
- && (Options.pathType.equals(Path.Danger) || calc
- .pathLengthTo(alterDet, true) <= 15)) {
- if ((inventory.isFull() || !pouches
- .containsValue(PouchState.Full))
- && inventory.contains(PURE_ESS_ID))
- return State.CRAFT_RUNES;
- else if (pouches.containsValue(PouchState.Full))
- return State.EMPTY_POUCHES;
- // Check path type change
- if (!pathTypeCurrent.equals(Options.pathType)) {
- pathTypeCurrent = Options.pathType;
- // Set up path:
- if (Options.pathType.equals(Path.Danger))
- alterMeshPath = new MeshPath(DANGER_MESH);
- else
- alterMeshPath = new MeshPath(SAFE_MESH);
- bankMeshPath = alterMeshPath.reverse();
- }
- }
- // Banking
- if (npcs.getNearest(BANKER_ID) != null) {
- if (npcs.getNearest(BANKER_ID).isOnScreen() || bank.isOpen()) {
- // Check path type change
- if (!pathTypeCurrent.equals(Options.pathType)) {
- pathTypeCurrent = Options.pathType;
- // Set up path:
- if (Options.pathType.equals(Path.Danger))
- alterMeshPath = new MeshPath(DANGER_MESH);
- else
- alterMeshPath = new MeshPath(SAFE_MESH);
- bankMeshPath = alterMeshPath.reverse();
- }
- if (!bank.isOpen() && walking.getEnergy() < 10
- && Options.chargeEnergy)
- return State.CHARGE_ENERGY;
- // Pouch Repair
- if (shouldRepairPouches())
- return State.NPC_CONTACT;
- if ((combat.getLifePoints() + 200 < skills
- .getCurrentLevel(Skills.CONSTITUTION) * 10)
- || combat.getHealth() < 50)
- return State.EAT_FOOD;
- if (inventory.getCount(Pouch.ALL)
- + inventory.getCount(PURE_ESS_ID)
- + inventory.getCount(FIRE_RUNE_ID) != inventory
- .getCount())
- return State.BANK_DEPOSIT;
- if (inventory.contains(PURE_ESS_ID)
- && pouches.containsValue(PouchState.Empty))
- return State.FILL_POUCHES;
- if (!inventory.isFull())
- return State.BANK_WITHDRAW;
- } else if (!inventory.contains(PURE_ESS_ID))
- return State.NEAR_BANK;
- }
- if (inventory.contains(PURE_ESS_ID))
- return State.TRAVERSE_ALTER;
- else {
- if (Options.tryOuraniaTeleport
- && skills.getCurrentLevel(Skills.MAGIC) >= 71
- && inventory.contains(LAW_RUNE)
- && inventory.getCount(true, ASTRAL_RUNE) >= 2
- && (inventory.getCount(true, EARTH_RUNE) >= 6 || Options.hasEarthStaff))
- return State.OURANIA_TELEPORT;
- if (objects.getNearest(LADDER_ID) != null)
- return State.TRAVERSE_OURANIA;
- return State.TRAVERSE_BANK;
- }
- // return State.LOST;
- }
- /**
- * Internal use only. When the client receives a message this method is
- * invoked, saving the message for later use.
- */
- public void messageReceived(MessageEvent msg) {
- if (msg.getID() == MessageEvent.MESSAGE_ACTION
- || msg.getID() == MessageEvent.MESSAGE_SERVER) {
- serverMsg = msg.getMessage().toLowerCase();
- }
- }
- /**
- * Determines if pouches need repairing by using the method defined in the
- * Options class
- *
- * @return boolean should repair pouches
- */
- public boolean shouldRepairPouches() {
- int degradeable = inventory.getCount(Pouch.ALL_DEGRADEABLE);
- int degraded = inventory.getCount(Pouch.ALL_DEGRADED);
- switch (Options.pouchRepair) {
- case ONE:
- return degraded > 0;
- case TWO:
- return degraded > 1 || degradeable < 2;
- case ALL:
- return degradeable == degraded;
- case NEVER:
- return false;
- default:
- return degraded > 1 || degradeable < 2;
- }
- }
- /**
- * Tries to open the bank
- *
- * @return boolean did bank open
- */
- public boolean openBank() {
- if (!alterMeshPath.hasPath())
- alterMeshPath.findPath();
- if (bankMeshPath.hasPath())
- bankMeshPath.clearPath();
- for (byte b = 0; b < 10; b++) {
- if (interfaces.get(PAY_BANK_INTERFACE) != null
- && interfaces.get(PAY_BANK_INTERFACE).isValid())
- payBankCharge();
- if (npcs.getNearest(BANKER_ID) != null) {
- if (bank.isOpen())
- return true;
- npcs.getNearest(BANKER_ID).doAction("Bank");
- sleep(100, 250);
- }
- sleep(1000);
- }
- return false;
- }
- public void payBankCharge() {
- RSInterface pay = interfaces.get(PAY_BANK_INTERFACE);
- if (pay != null && pay.isValid())
- for (String rune : PAY_BANKER_ORDER)
- for (RSComponent c : pay.getComponents())
- if (c != null
- && c.isValid()
- && c.getTooltip() != null
- && c.getTooltip().toLowerCase()
- .contains(rune.toLowerCase()))
- if (inventoryCount(rune) >= 20)
- if (c.doClick()) {
- sleep(1500);
- return;
- }
- log.severe("Unable to pay banker!");
- }
- public int inventoryCount(String name) {
- for (RSItem i : inventory.getCachedItems())
- if (i != null
- && i.getName().toLowerCase().contains(name.toLowerCase()))
- return i.getStackSize();
- return 0;
- }
- /**
- * Deposit all non necessary items.
- */
- public void deposit() {
- if (!openBank())
- return;
- int[] items = mergeArrays(Pouch.ALL, FIRE_RUNE_ID);
- for (int tries = 0; tries < 5 && inventory.getCountExcept(items) > 0; tries++)
- outer: for (RSItem item : inventory.getItems()) {
- if (item != null) {
- for (int id : items)
- if (item.getID() == id)
- continue outer;
- if (item.getID() > 0 && inventory.contains(item.getID()))
- if (bank.deposit(item.getID(), 0))
- sleep(random(200, 300));
- }
- }
- Paint.runsMade++;
- }
- /**
- * Tries to open the bank if the bank is not open, then tries to withdraw
- * the item
- *
- * @param id
- * the item to withdraw
- * @param amount
- * the amount to withdraw, 0 for all
- * @return boolean successfully withdraw
- */
- public boolean withdrawItem(int id, int amount) {
- if (!openBank())
- return false;
- boolean returns = bank.withdraw(id, amount);
- sleep(250, 500);
- return returns;
- }
- /**
- * Withdraws pure essence
- *
- * @return boolean did withdraw item
- */
- public boolean withdrawEss() {
- return withdrawItem(PURE_ESS_ID, 0);
- }
- /**
- * Gets the count of items by the provided id(s) in both the bank and
- * inventory. Includes stack sizes
- *
- * @param id
- * item ids to search
- * @return int number of items in bank and inventory
- */
- public int getCountBankInv(int... id) {
- int count = 0;
- if (bank.isOpen())
- count += bank.getCount(id);
- count += inventory.getCount(true, id);
- return count;
- }
- /**
- * Emptys pouches using the method set in the Options class
- */
- public void emptyPouches() {
- if (game.getCurrentTab() == Game.TAB_INVENTORY)
- updatePouches();
- for (PouchType pType : pouches.keySet()) {
- if (inventory.isFull())
- break;
- if (inventory.containsOneOf(pType.ids)) {
- if (pouches.get(pType).equals(PouchState.Full)) {
- RSItem item = inventory.getItem(pType.ids);
- if (item != null) {
- int invCount = inventory.getCount();
- if (item.doAction("Empty"))
- switch (Options.pouchCheckSystem) {
- case SERVER_MSG:
- for (int i = 0; i < POUCH_TRIES; i++) {
- if (serverMsg != null)
- if (serverMsg
- .contains("pouch has no ess")
- || serverMsg
- .contains("are no essences in your pouch")) {
- pouches.put(pType, PouchState.Empty);
- serverMsg = "";
- sleep(100, 150);
- break;
- }
- sleep(100, 150);
- }
- break;
- case INVENTORY_STATUS:
- for (int i = 1; i <= POUCH_TRIES; i++)
- if (inventory.getCount() == invCount
- && i != POUCH_TRIES)
- sleep(100, 150);
- else {
- if (!inventory.isFull())
- pouches.put(pType, PouchState.Empty);
- break;
- }
- break;
- }
- }
- }
- }
- }
- }
- /**
- * Fills pouches using the method set in the Options class
- */
- public void fillPouches() {
- if (game.getCurrentTab() == Game.TAB_INVENTORY)
- updatePouches();
- for (PouchType pType : pouches.keySet()) {
- if (!inventory.contains(PURE_ESS_ID))
- break;
- if (inventory.containsOneOf(pType.ids)) {
- if (pouches.get(pType).equals(PouchState.Empty)) {
- RSItem item = inventory.getItem(pType.ids);
- if (item != null) {
- int invCount = inventory.getCount();
- if (item.doAction("Fill"))
- switch (Options.pouchCheckSystem) {
- case SERVER_MSG:
- for (int i = 0; i < POUCH_TRIES; i++) {
- if (serverMsg != null)
- if (serverMsg.contains("pouch is ful")) {
- pouches.put(pType, PouchState.Full);
- serverMsg = "";
- break;
- }
- sleep(80, 120);
- }
- break;
- case INVENTORY_STATUS:
- for (int i = 1; i <= POUCH_TRIES; i++)
- if (inventory.getCount() == invCount
- && i != POUCH_TRIES)
- sleep(100, 150);
- else {
- if (inventory.contains(PURE_ESS_ID))
- pouches.put(pType, PouchState.Full);
- break;
- }
- break;
- }
- }
- }
- }
- }
- }
- /**
- * Rechecks pouches with the inventory's current contents. If a pouch in the
- * list no longer exists it removes it, if there's a pouch in the inventory
- * not in the list it adds it as an empty pouch
- */
- public void updatePouches() {
- for (PouchType pouch : PouchType.values())
- if (inventory.containsOneOf(pouch.ids)) {
- if (!pouches.containsKey(pouch))
- pouches.put(pouch, PouchState.Empty);
- } else if (pouches.containsKey(pouch))
- pouches.remove(pouch);
- }
- public int getRuneCount(boolean cache) {
- int count = 0;
- for (RSItem i : cache ? inventory.getCachedItems() : inventory
- .getItems())
- if (i.getName() != null
- && i.getName().toLowerCase().contains("rune"))
- count += i.getStackSize();
- return count;
- }
- /**
- * Crafts essence at the alter
- */
- public void craftEssence() {
- if (alterMeshPath.hasPath())
- alterMeshPath.clearPath();
- if (!bankMeshPath.hasPath())
- bankMeshPath.findPath();
- RSObject alter = objects.getNearest(ZMI_ALTAR_ID);
- if (!alter.isOnScreen() && !getMyPlayer().isMoving()
- && walking.getDestination() == null)
- walking.walkTileMM(alter.getArea().getNearestTile(
- getMyPlayer().getLocation()));
- int invBefore = inventory.getCount(PURE_ESS_ID);
- int runesBefore = getRuneCount(false);
- alter.doAction("Craft-rune");
- sleep(1000);
- for (byte b = 0; b < 50; b++)
- if (getMyPlayer().getAnimation() == CRAFT_RUNE_ANIM
- || getMyPlayer().isMoving()
- || walking.getDestination() != null)
- sleep(100, 125);
- else
- break;
- Paint.essUsed += invBefore - inventory.getCount(PURE_ESS_ID);
- Paint.runesMade += getRuneCount(false) - runesBefore;
- }
- /**
- * Turns the camera to the given angle, clicking the compass if its easier.
- * Gets within param variance of the specified angle
- *
- * @param angle
- * as int
- * @param variance
- * as int
- */
- public void turnToAngle(int angle, int variance) {
- int r1 = angle - variance;
- if (r1 < 0)
- r1 += 360;
- int r2 = angle + variance;
- if (r2 >= 360)
- r2 -= 360;
- int currAngle = camera.getAngle();
- if (Math.abs(Math.max(r1, r2) - Math.min(r1, r2)) == variance * 2) {
- if (currAngle > Math.min(r1, r2) && currAngle < Math.max(r1, r2))
- return;
- } else if (currAngle < Math.min(r1, r2) && currAngle > Math.max(r1, r2))
- return;
- if (angle > 360 - variance || angle < variance)
- camera.setNorth();
- else
- camera.setAngle(angle + random(-variance, variance));
- }
- public boolean onStart() {
- if (game.getCurrentTab() != Game.TAB_MAGIC)
- game.openTab(Game.TAB_MAGIC);
- Options.onLunars = magic.getInterface() != null
- && magic.getInterface().getIndex() == Magic.Book.LUNAR
- .getInterfaceID();
- Options.tryOuraniaTeleport = (skills.getCurrentLevel(Skills.MAGIC) >= 71 && Options.onLunars);
- pathTypeCurrent = Options.pathType;
- // Set up path:
- if (Options.pathType.equals(Path.Danger))
- alterMeshPath = new MeshPath(DANGER_MESH);
- else
- alterMeshPath = new MeshPath(SAFE_MESH);
- bankMeshPath = alterMeshPath.reverse();
- // Set up the pouches:
- updatePouches();
- RSItem wep = equipment.getItem(Equipment.WEAPON);
- if (wep != null) {
- Options.hasAirStaff = (wep.getName().toLowerCase()
- .contains("staff") && wep.getName().toLowerCase()
- .contains("air"));
- Options.hasEarthStaff = (wep.getName().toLowerCase()
- .contains("staff") && (wep.getName().toLowerCase()
- .contains("earth")
- || wep.getName().toLowerCase().contains("mud") || wep
- .getName().toLowerCase().contains("lava")));
- }
- Paint = new PaintInterface(this, log, Skills.RUNECRAFTING);
- new DataLoader(this);
- // optimal alt
- camera.setPitch(random(0, 10));
- log.info("Script initiation successful!");
- log.info("Current exp: "
- + PaintFormatter.getFormattedMoney(Paint.startExp));
- log.info("Current level: " + Paint.startLevel);
- log.info("--Setup--");
- log.info("Air staff: " + (Options.hasAirStaff ? "yes" : "no"));
- log.info("Earth staff: " + (Options.hasEarthStaff ? "yes" : "no"));
- log.info("Walking range: " + Options.walkingDistance.toString());
- log.info("Pouch method: "
- + PaintFormatter.properCaseAll(Options.pouchCheckSystem.name()
- .replaceAll("_", " ")));
- log.info("Pouch repair system: "
- + PaintFormatter.properCaseAll(Options.pouchRepair.name()
- .replaceAll("_", " ")));
- log.info("Walking style: "
- + PaintFormatter.properCaseAll(Options.pathType.name()));
- log.info("Recharge Energy: "
- + (Options.chargeEnergy ? "True" : "False"));
- log.info("Try Ourania Teleport: "
- + (Options.tryOuraniaTeleport ? "True" : "False"));
- return true;
- }
- public boolean isResting() {
- int anim = getMyPlayer().getAnimation();
- return (anim == 12108 || anim == 2033 || anim == 2716 || anim == 11786 || anim == 5713);
- }
- public void rest() {
- for (int d = 0; d < 5; d++) {
- interfaces.getComponent(walking.INTERFACE_RUN_ORB, 1).doAction(
- "Rest");
- mouse.moveSlightly();
- sleep(random(400, 600));
- int anim = players.getMyPlayer().getAnimation();
- if (anim == 12108 || anim == 2033 || anim == 2716 || anim == 11786
- || anim == 5713) {
- break;
- }
- }
- }
- public int loop() {
- mouse.setSpeed(random(4, 6));
- if (!walking.isRunEnabled() && walking.getEnergy() > 50 && !isResting())
- walking.setRun(true);
- try {
- currentState = getState();
- switch (currentState) {
- case LADDER_DOWN:
- if (objects.getNearest(LADDER_ID).isOnScreen())
- if (objects.getNearest(LADDER_ID).doAction("Climb"))
- sleep(500, 750);
- break;
- case OURANIA_TELEPORT:
- if (magic.castSpell(Magic.SPELL_OURANIA_TELEPORT))
- sleep(2500,2750);
- break;
- case TRAVERSE_OURANIA:
- RSTilePath tPath = walking.newTilePath(OURANIA_PATH).randomize(
- 2, 2);
- for (byte b = 0; b < 300 && tPath.isValid()
- && (objects.getNearest(LADDER_ID) != null) ? !objects
- .getNearest(LADDER_ID).isOnScreen() : true; b++) {
- tPath.traverse();
- sleep(95, 105);
- }
- break;
- case CHARGE_ENERGY:
- if (!isResting())
- rest();
- if (isResting())
- while (walking.getEnergy() < 100 && isResting()
- && isActive())
- sleep(200);
- break;
- case NEAR_BANK:
- RSNPC banker = npcs.getNearest(BANKER_ID);
- if (banker != null)
- if (!banker.isOnScreen()) {
- RSTile loc = banker.getLocation();
- if (calc.tileOnMap(loc)) {
- walking.walkTileMM(loc);
- for (byte b = 0; b < 22; b++)
- if (banker.isOnScreen()) {
- sleep(500);
- break;
- } else
- sleep(100, 115);
- }
- }
- break;
- case BANK_DEPOSIT:
- deposit();
- break;
- case BANK_WITHDRAW:
- withdrawEss();
- break;
- case CRAFT_RUNES:
- craftEssence();
- break;
- case EMPTY_POUCHES:
- emptyPouches();
- break;
- case EAT_FOOD:
- if (!inventory.containsOneOf(food)) {
- openBank();
- for (int id : food)
- if (bank.getCount(id) > 0)
- if (bank.withdraw(id, 1))
- break;
- }
- if (bank.isOpen())
- bank.close();
- if (inventory.containsOneOf(food)) {
- RSItem foodI = inventory.getItem(food);
- if (foodI != null)
- foodI.doAction("Eat");
- }
- break;
- case FILL_POUCHES:
- fillPouches();
- break;
- case NPC_CONTACT:
- npcContact.main();
- break;
- case TRAVERSE_BANK:
- if (!bankMeshPath.hasPath())
- bankMeshPath.findPath(MeshPathType.FULL);
- if (Options.pathType.equals(Path.Safe)
- && (bankMeshPath.getNearestByPath() == null || !bankMeshPath
- .getNearestByPath().equals(
- bankMeshPath.getEnd())))
- if (objects.getNearest(CRACK_OUT) != null) {
- if (!objects.getNearest(CRACK_OUT).isOnScreen()) {
- walking.walkTileMM(objects.getNearest(CRACK_OUT)
- .getLocation());
- sleep(1250);
- }
- if (objects.getNearest(CRACK_OUT).isOnScreen()
- && objects.getNearest(CRACK_OUT).doAction(
- "Squeeze-through")) {
- sleep(900, 1250);
- break;
- }
- }
- bankMeshPath.traverse();
- break;
- case TRAVERSE_ALTER:
- if (!alterMeshPath.hasPath())
- alterMeshPath.findPath(MeshPathType.ALL_CENTER);
- if ((calc.pathLengthTo(alterDet, true) > 25 || calc
- .pathLengthTo(alterDet, true) < 0)
- && Options.pathType.equals(Path.Safe))
- if (objects.getNearest(CRACK_IN) != null)
- if (objects.getNearest(CRACK_IN).isOnScreen()
- && objects.getNearest(CRACK_IN).doAction(
- "Squeeze-through")) {
- sleep(900, 1250);
- break;
- }
- alterMeshPath.traverse();
- break;
- }
- } catch (Exception e) {
- logError(e);
- }
- if (walking.getEnergy() > 50 && !walking.isRunEnabled())
- walking.setRun(true);
- return random(100, 125);
- }
- public void onFinish() {
- env.saveScreenshot(true);
- Paint.paintMenu.saveProggie();
- }
- /**
- * Logs an exception to the Logger and to the error cache
- *
- * @param e
- * as the Exception to log
- */
- public void logError(Exception e) {
- String s = e.getMessage();
- log.severe(s);
- for (StackTraceElement ele : e.getStackTrace()) {
- s += "\n" + ele.toString();
- log.severe(ele.toString());
- }
- errorLog.add(s);
- }
- /**
- * {@inheritDoc}
- */
- public void onRepaint(Graphics g1) {
- Graphics2D g = (Graphics2D) g1;
- try {
- // MeshPaths
- bankMeshPath.paintAll(g);
- alterMeshPath.paintAll(g);
- // Mouse Crosshair
- drawMouse.onRepaint(g1);
- // main paint:
- if (Paint != null)
- Paint.render(g);
- } catch (NullPointerException e) {
- logError(e);
- }
- }
- public void mouseDragged(MouseEvent arg0) {
- Paint.mouseLoc = arg0.getPoint();
- }
- public void mouseMoved(MouseEvent arg0) {
- Paint.mouseLoc = arg0.getPoint();
- }
- public void mouseClicked(MouseEvent arg0) {
- Paint.paintMenu.fireMouseEvent(arg0);
- }
- public void mouseEntered(MouseEvent arg0) {
- }
- public void mouseExited(MouseEvent arg0) {
- }
- public void mousePressed(MouseEvent arg0) {
- }
- public void mouseReleased(MouseEvent arg0) {
- }
- /**
- * Used to format data into more conventional formats
- *
- * @author Equinox_
- *
- */
- public static class PaintFormatter {
- /**
- * Converts the first letter of every word to uppercase, and the rest
- * lowercase.
- *
- * @param s
- * The input String
- * @return the properly formatted string
- */
- public static String properCaseAll(String s) {
- String[] words = s.split(" ");
- String result = "";
- for (int i = 0; i < words.length; i++) {
- String f = words[i].substring(0, 1).toUpperCase();
- words[i] = f + words[i].substring(1).toLowerCase();
- result += " " + words[i];
- }
- return result.substring(1);
- }
- /**
- * Capitalizes the first letter of every sentence, with every other
- * letter lowercase.
- *
- * @param s
- * The input string
- * @return The properly formatted String
- */
- public static String properCaseFirst(String s) {
- String[] sentences = new String[] { s };
- if (s.contains("."))
- sentences = s.split(".");
- String result = "";
- for (int i = 0; i < sentences.length; i++) {
- String f = sentences[i].substring(0, 1).toUpperCase();
- sentences[i] = f + sentences[i].substring(1).toLowerCase();
- result += " " + sentences[i];
- }
- return result.substring(1);
- }
- /**
- * Formats time to DD:HH:MM:SS:MSMS with days and millis optional
- *
- * @param timeMillis
- * long milliseconds of time
- * @param sep
- * String seperation character
- * @param millisInc
- * boolean include milliseconds
- * @return
- */
- public static String getFormattedTime(final long timeMillis,
- String sep, boolean millisInc) {
- long millis = timeMillis;
- final long days = millis / (24 * 1000 * 60 * 60);
- millis -= days * (24 * 1000 * 60 * 60);
- final long hours = millis / (1000 * 60 * 60);
- millis -= hours * 1000 * 60 * 60;
- final long minutes = millis / (1000 * 60);
- millis -= minutes * 1000 * 60;
- final long _seconds = millis / 1000;
- millis -= _seconds * 1000;
- String dayString = String.valueOf(days);
- String hoursString = String.valueOf(hours);
- String minutesString = String.valueOf(minutes);
- String secondsString = String.valueOf(_seconds);
- if (hours < 10) {
- hoursString = 0 + hoursString;
- }
- if (minutes < 10) {
- minutesString = 0 + minutesString;
- }
- if (_seconds < 10) {
- secondsString = 0 + secondsString;
- }
- String s = "";
- if (days > 0)
- s = dayString + sep;
- s += hoursString + sep + minutesString + sep + secondsString;
- if (millisInc)
- s += sep + String.valueOf(millis);
- return s;
- }
- /**
- * Converts the milliseconds to DD:HH:MM:SS with the days optional.
- *
- * @param timeMillis
- * the number of milliseconds
- * @return the properly formatted time as a String
- */
- public static String getFormattedTime(final long timeMillis) {
- return getFormattedTime(timeMillis, ":", false);
- }
- /**
- * Formats a specified amount into thousands, millions or billions, then
- * adds the proper suffix
- *
- * @param money
- * the amount of money
- * @return the formatted string
- */
- public static String getFormattedMoney(long money) {
- /*
- * String suffix = ""; int t = 1; if (money >= 10000) { t *= 1000;
- * suffix = "K"; } if (money / t > 10000) { t *= 1000; suffix = "M";
- * } if (money / t > 10000) { t *= 1000; suffix = "B"; } return
- * String.valueOf((money / t)) + suffix;
- */
- return new DecimalFormat("###,###,###,###,###,###").format(money);
- }
- /**
- * Converts an array of strings into one string, using commas and 'and' <br>
- * <br>
- * Examples: <br>
- * {"option1"} returns "option1"<br>
- * {"option1","option2"} returns "option1 and option2"<br>
- * {"op1","op2","op3"} returns "op1, op2, and op3"<br>
- * <br>
- *
- * @param list
- * The array of strings making up the list.
- * @return The properly formatted string
- */
- public static String formatList(String[] list) {
- String s = "";
- if (list != null)
- if (list.length == 2) {
- s = list[0] + " and " + list[1];
- } else if (list.length > 2) {
- for (int i = 0; i < list.length - 1; i++)
- s += list[i] + ", ";
- s += "and " + list[list.length - 1];
- } else if (list.length == 1)
- s = list[0];
- return s;
- }
- }
- /**
- * A class used to represent the paint interface for this script
- *
- * @author Equinox_
- *
- */
- public class PaintInterface {
- // Constant
- public final int[] SKILL_INTERFACES = { Skills.INTERFACE_ATTACK,
- Skills.INTERFACE_DEFENSE, Skills.INTERFACE_STRENGTH,
- Skills.INTERFACE_CONSTITUTION, Skills.INTERFACE_RANGE,
- Skills.INTERFACE_PRAYER, Skills.INTERFACE_MAGIC,
- Skills.INTERFACE_COOKING, Skills.INTERFACE_WOODCUTTING,
- Skills.INTERFACE_FLETCHING, Skills.INTERFACE_FISHING,
- Skills.INTERFACE_FIREMAKING, Skills.INTERFACE_CRAFTING,
- Skills.INTERFACE_SMITHING, Skills.INTERFACE_MINING,
- Skills.INTERFACE_HERBLORE, Skills.INTERFACE_AGILITY,
- Skills.INTERFACE_THIEVING, Skills.INTERFACE_SLAYER,
- Skills.INTERFACE_FARMING, Skills.INTERFACE_RUNECRAFTING,
- Skills.INTERFACE_HUNTER, Skills.INTERFACE_CONSTRUCTION,
- Skills.INTERFACE_SUMMONING, Skills.INTERFACE_DUNGEONEERING };
- // Start data
- public long startExp = 0;
- public long startTime = 0;
- public long startLevel = 1;
- // Goal data
- public int goalExp;
- public int goalLevel;
- // Usage data
- public int runesMade = 0;
- public int essUsed = 0;
- // Price data
- public long essPrice = 1;
- // Result data
- public int runsMade = 0;
- // Images
- public Map<String, Image> icons = new HashMap<String, Image>();
- public void putImage(String name, Image img) {
- icons.put(name.toLowerCase(), img);
- }
- public Image getImage(String name) {
- if (icons.containsKey(name.toLowerCase()))
- return icons.get(name.toLowerCase());
- return null;
- }
- // End Images
- public FontRenderContext frc = new FontRenderContext(
- new AffineTransform(), false, false);
- public PaintStyle style = new PaintStyle();
- public Point mouseLoc = new Point(0, 0);
- final EquinoxZMICrafter crafter;
- final Logger log;
- int SkillID = -1;
- public Menu paintMenu;
- /**
- * Constructs a PaintInterface using the provided parent and logger
- * object
- *
- * @param planker
- * the parent NatCrafter
- * @param log
- * the Logger object
- */
- public PaintInterface(EquinoxZMICrafter crafter, Logger log) {
- this(crafter, log, -1);
- }
- public PaintInterface(EquinoxZMICrafter crafter, Logger log, int SkillID) {
- this.crafter = crafter;
- this.log = log;
- this.SkillID = SkillID;
- startTime = System.currentTimeMillis();
- if (SkillID >= 0 && SkillID < Skills.SKILL_NAMES.length) {
- startExp = skills.getCurrentExp(SkillID);
- startLevel = skills.getCurrentLevel(SkillID);
- setUpGoal();
- }
- init();
- }
- public void init() {
- RSComponent screen = interfaces.get(548).getComponent(3);
- Point bottomRight = new Point(screen.getAbsoluteX()
- + screen.getWidth(), screen.getAbsoluteY()
- + screen.getHeight());
- paintMenu = new Menu(this, bottomRight, Anchor.DOWN_RIGHT);
- paintMenu.setFlowType(FlowType.HORIZONTAL);
- paintMenu.addMouseListener(new MouseListen() {
- void MouseAction(MouseEvent e) {
- if (e.getID() == MouseEvent.MOUSE_CLICKED)
- paintMenu.toggleShowAll();
- }
- });
- if (SkillID >= 0 && SkillID < Skills.SKILL_NAMES.length) {
- MenuProgressBar progressBar = new MenuProgressBar("nextlvl",
- paintMenu, new GetPercent() {
- int getPercent() {
- return skills.getPercentToNextLevel(SkillID);
- }
- }, "Next Level", new GetPopup() {
- MenuPopUp getPopUp() {
- long millis = Math.abs(System
- .currentTimeMillis() - startTime);
- if (millis <= 0)
- millis = 1;
- long expGained = skills.getCurrentExp(SkillID)
- - startExp;
- long expPerHour = (expGained * 3600000l)
- / millis;
- String TTL = "";
- int TTLunf = (int) ((expPerHour > 0) ? (((float) skills
- .getExpToNextLevel(SkillID))
- / ((float) expPerHour) * 3600000f) : 0);
- if (TTLunf != 0)
- TTL = PaintFormatter
- .getFormattedTime(TTLunf);
- else
- TTL = "No exp gained";
- String[] lines = new String[4];
- lines[0] = "Exp gained: "
- + PaintFormatter
- .getFormattedMoney(expGained);
- lines[1] = "Exp per Hour: "
- + PaintFormatter
- .getFormattedMoney(expPerHour);
- lines[2] = "Exp 'till level: "
- + PaintFormatter.getFormattedMoney(skills
- .getExpToNextLevel(SkillID));
- lines[3] = "Time 'till level: " + TTL;
- return new MenuPopUp(lines, "nextlevel");
- }
- });
- paintMenu.add(progressBar);
- if (goalExp > skills.getCurrentExp(SkillID)) {
- MenuProgressBar goalBar = new MenuProgressBar("goal",
- paintMenu, new GetPercent() {
- int getPercent() {
- float expTillGoalStart = goalExp - startExp;
- double expGained = skills
- .getCurrentExp(SkillID) - startExp;
- double result = expGained
- / expTillGoalStart;
- if (result > 1)
- result = 1;
- if (result < 0)
- result = 0;
- return (int) (result * 100);
- }
- }, "Goal", new GetPopup() {
- MenuPopUp getPopUp() {
- long millis = Math.abs(System
- .currentTimeMillis() - startTime);
- if (millis <= 0)
- millis = 1;
- long expGained = skills
- .getCurrentExp(SkillID) - startExp;
- long expPerHour = (expGained * 3600000l)
- / millis;
- int expTillGoal = goalExp
- - skills.getCurrentExp(SkillID);
- String TTG = "";
- int TTGunf = (int) ((expPerHour > 0) ? (((float) expTillGoal)
- / ((float) expPerHour) * 3600000f)
- : 0);
- if (TTGunf != 0)
- TTG = PaintFormatter
- .getFormattedTime(TTGunf);
- else
- TTG = "No exp gained";
- String[] lines = new String[goalLevel > 0 ? 6
- : 5];
- int off = goalLevel > 0 ? 1 : 0;
- if (goalLevel > 0)
- lines[0] = "Goal Level: " + goalLevel;
- lines[0 + off] = "Goal Exp: "
- + PaintFormatter
- .getFormattedMoney(goalExp);
- lines[1 + off] = "Exp gained: "
- + PaintFormatter
- .getFormattedMoney(expGained);
- lines[2 + off] = "Exp per Hour: "
- + PaintFormatter
- .getFormattedMoney(expPerHour);
- lines[3 + off] = "Exp 'till goal: "
- + PaintFormatter
- .getFormattedMoney(expTillGoal);
- lines[4 + off] = "Time 'till goal: " + TTG;
- return new MenuPopUp(lines, "goalbar");
- }
- });
- paintMenu.add(goalBar);
- }
- }
- MenuButton rcing = new MenuButton("rcing", paintMenu, "rcicon",
- new GetPopup() {
- MenuPopUp getPopUp() {
- long millis = System.currentTimeMillis()
- - crafter.Paint.startTime;
- if (millis <= 0)
- millis = 1;
- String runesPerEssence = "Runes per Ess: "
- + ((essUsed > 0) ? (new DecimalFormat(
- "#.##").format(((double) runesMade)
- / ((double) essUsed)))
- : "No essence used");
- long runesPerHour = ((runesMade * 3600000l) / millis);
- /*
- * long profit = (runesMade * natPrice) - (essUsed *
- * essPrice) - (graahksUsed * graahkPrice);
- */
- String[] lines = new String[7];
- lines[0] = "Essence Used: "
- + PaintFormatter.getFormattedMoney(essUsed);
- lines[1] = "Runes Crafted: "
- + PaintFormatter
- .getFormattedMoney(runesMade);
- lines[2] = "Runes/Hour: "
- + PaintFormatter
- .getFormattedMoney(runesPerHour);
- /*
- * lines[4] = "Profit: " +
- * PaintFormatter.getFormattedMoney(profit) + " gp";
- * lines[5] = "Profit per hour: " + PaintFormatter
- * .getFormattedMoney((profit * 3600000) / millis) +
- * " gp";
- */
- lines[3] = runesPerEssence;
- lines[4] = "Runs made: " + runsMade;
- lines[5] = "Runes per run: "
- + (runsMade > 0 ? (int) (runesMade / runsMade)
- : "No runs made");
- lines[6] = "Runes in inventory: "
- + crafter.getRuneCount(true);
- return new MenuPopUp(lines, "runes");
- }
- });
- paintMenu.add(rcing);
- MenuButton home = new MenuButton("home", paintMenu, "homeicon",
- new GetPopup() {
- MenuPopUp getPopUp() {
- long millis = System.currentTimeMillis()
- - crafter.Paint.startTime;
- if (millis <= 0)
- millis = 1;
- String[] lines = new String[5];
- lines[0] = crafter.name;
- lines[1] = "By: " + crafter.author;
- lines[2] = "Version " + crafter.VERSION;
- lines[3] = "Runtime: "
- + PaintFormatter.getFormattedTime(millis)
- + "\n";
- lines[4] = PaintFormatter
- .properCaseAll(crafter.currentState.name()
- .replace("_", " "));
- if (crafter.currentState.equals(State.NPC_CONTACT))
- lines[4] += " - "
- + PaintFormatter
- .properCaseAll(npcContact.currentState
- .name().replace("_",
- " "));
- return new MenuPopUp(lines, "home");
- }
- });
- paintMenu.add(home);
- MenuButton tools = new MenuButton("tools", paintMenu, "toolsicon",
- new GetPopup() {
- MenuPopUp getPopUp() {
- String[] lines = new String[5];
- lines[0] = "Save proggie";
- lines[1] = "Reload data";
- if (crafter.pathTypeCurrent.equals(Path.Danger))
- lines[2] = "Set to safe path";
- else
- lines[2] = "Set to dangerous path";
- if (Options.chargeEnergy)
- lines[3] = "Do not recharge energy";
- else
- lines[3] = "Recharge energy";
- if (Options.tryOuraniaTeleport)
- lines[4] = "Do not try Ourania Teleport";
- else
- lines[4] = "Try Ourania Teleport";
- MenuPopUp popUp = new MenuPopUp(lines, "tools");
- popUp.addLineListener(new LineListener() {
- void fireEvent(MouseEvent e, String line) {
- line = line.toLowerCase().trim();
- if (e.getID() == MouseEvent.MOUSE_CLICKED) {
- if (line.contains("save proggie"))
- paintMenu.saveProggie();
- else if (line.contains("reload data"))
- new DataLoader(crafter);
- else if (line.contains("safe path"))
- Options.pathType = Path.Safe;
- else if (line
- .contains("dangerous path"))
- Options.pathType = Path.Danger;
- else if (line
- .contains("do not recharge"))
- Options.chargeEnergy = false;
- else if (line.contains("recharge"))
- Options.chargeEnergy = true;
- else if (line
- .contains("do not try ourania teleport"))
- Options.tryOuraniaTeleport = false;
- else if (line
- .contains("try ourania teleport")) {
- if (skills
- .getCurrentLevel(Skills.MAGIC) < 17) {
- log.severe("You must have 71 magic to use this feature!");
- return;
- }
- if (!Options.onLunars) {
- log.severe("You must be on the Lunar spellbook to use this feature!");
- return;
- }
- Options.tryOuraniaTeleport = true;
- }
- }
- }
- boolean hasAction(String line) {
- line = line.toLowerCase().trim();
- String[] lines = new String[5];
- lines[0] = "Save proggie";
- lines[1] = "Reload data";
- if (crafter.pathTypeCurrent
- .equals(Path.Danger))
- lines[2] = "Set to safe path";
- else
- lines[2] = "Set to dangerous path";
- if (Options.chargeEnergy)
- lines[3] = "Do not recharge energy";
- else
- lines[3] = "Recharge energy";
- if (Options.tryOuraniaTeleport)
- lines[4] = "Do not try Ourania Teleport";
- else
- lines[4] = "Try Ourania Teleport";
- for (String sub : lines)
- if (sub.equalsIgnoreCase(line))
- return true;
- return false;
- }
- });
- return popUp;
- }
- });
- paintMenu.add(tools);
- paintMenu.compile();
- }
- /**
- * Gets the current Goal for the setSkill, or sets all goal variables to
- * -1 if there is no goal
- */
- public void setUpGoal() {
- try {
- for (byte b = 0; b < 10; b++)
- if (game.getCurrentTab() != Game.TAB_STATS) {
- game.openTab(Game.TAB_STATS);
- sleep(1000);
- } else
- break;
- RSInterface stats = interfaces.get(320);
- if (stats != null && stats.isValid()) {
- RSComponent mage = stats
- .getComponent(SKILL_INTERFACES[SkillID]);
- if (mage != null && mage.isValid()
- && mage.getArea() != null) {
- mouse.move((int) mage.getArea().getCenterX(),
- (int) mage.getArea().getCenterY());
- sleep(500, 750);
- // Now we see what the popup is doing
- RSComponent pop = stats.getComponent(202);
- if (pop != null && pop.isValid()) {
- RSComponent def = pop.getComponent(5);
- if (def != null && def.isValid()) {
- if (def.getText().trim()
- .equalsIgnoreCase("Target XP:")) {
- RSComponent goalXP = pop.getComponent(6);
- if (goalXP != null && goalXP.isValid()) {
- goalExp = Integer.valueOf(goalXP
- .getText().replace(",", "")
- .trim());
- goalLevel = -1;
- }
- } else {
- // Proceed
- RSComponent currExp = pop.getComponent(4);
- RSComponent goalRemainder = pop
- .getComponent(12);
- RSComponent goalLvl = pop.getComponent(10);
- if (currExp != null && currExp.isValid()
- && goalRemainder != null
- && goalRemainder.isValid()
- && goalLvl != null
- && goalLvl.isValid()) {
- goalExp = Integer.valueOf(currExp
- .getText().replace(",", "")
- .trim())
- + Integer.valueOf(goalRemainder
- .getText()
- .replace(",", "")
- .trim());
- goalLevel = Integer.valueOf(goalLvl
- .getText().replace(",", "")
- .trim());
- }
- }
- log.info("Target level: "
- + (goalLevel > 0 ? goalLevel : "None"));
- log.info("Target exp: "
- + (goalExp > 0 ? goalExp : "None"));
- return;
- }
- }
- }
- }
- } catch (Exception e) {
- }
- goalExp = -1;
- goalLevel = -1;
- }
- /**
- * Renders the current paint to the given graphics context.
- *
- * @param g
- * as the Graphics2D object to render to
- */
- public void render(Graphics2D g) {
- paintPouches(g);
- paintMenu.render(g, mouseLoc);
- int mouseX = mouseLoc.x;
- int mouseY = mouseLoc.y;
- g.setColor(Color.RED);
- g.drawLine(mouseX - 5, mouseY - 5, mouseX + 5, mouseY + 5);
- g.drawLine(mouseX - 5, mouseY + 5, mouseX + 5, mouseY - 5);
- }
- /**
- * Paints the pouches loaded into the list using red for empty and green
- * for full. Only paints if inventory is visible.
- *
- * @param g
- * as Graphics
- */
- public void paintPouches(Graphics g) {
- // Loop through pouches
- for (PouchType pouch : crafter.pouches.keySet()) {
- if (game.getCurrentTab() == Game.TAB_INVENTORY) {
- RSItem item = inventory.getItem(pouch.ids);
- if (item != null) {
- if (crafter.pouches.get(pouch).equals(PouchState.Empty))
- g.setColor(new Color(1f, 0f, 0f, 0.5f));
- else
- g.setColor(new Color(0f, 1f, 0f, 0.5f));
- RSComponent c = item.getComponent();
- g.fillRect(c.getAbsoluteX(), c.getAbsoluteY(),
- c.getWidth(), c.getHeight());
- // Decay:
- for (int id : Pouch.ALL_DEGRADED)
- if (item.getID() == id) {
- g.setColor(Color.WHITE);
- g.setFont(style.FONT.deriveFont(4));
- g.drawString("Degraded", c.getAbsoluteX(),
- c.getAbsoluteY() + c.getHeight());
- break;
- }
- }
- }
- }
- }
- /**
- * Fires a MouseEvent in the paintMenu
- *
- * @param e
- * MouseEvent
- */
- public void fireMouseEvent(MouseEvent e) {
- if (paintMenu.getBoundsFull().contains(e.getPoint()))
- paintMenu.fireMouseEvent(e);
- }
- /**
- * Represents a Menu on a PaintInterface
- *
- * @author Equinox_
- *
- */
- public class Menu {
- final int padding = 1;
- Point location;
- PaintInterface parent;
- PaintStyle style;
- List<MenuItem> components = new ArrayList<MenuItem>();
- final Anchor anchor;
- boolean showAllPopups;
- MenuPopUp visiblePopup = null;
- List<MouseListen> mouseListeners;
- LineListener defaultLineListener;
- private FlowType flowType = FlowType.HORIZONTAL;
- public Dimension bounds;
- /**
- * Constructs a Menu using the provided PaintInterface, Location,
- * Anchor, and the GameScreen as the bounds
- *
- * @param parent
- * PaintInterface
- * @param location
- * Point
- * @param anchor
- * Anchor
- */
- public Menu(PaintInterface parent, Point location, Anchor anchor) {
- this.parent = parent;
- this.style = parent.style;
- this.location = location;
- this.anchor = anchor;
- // Setup dimension
- Rectangle r = interfaces.get(548).getComponent(3).getArea();
- bounds = new Dimension(r.width, r.height);
- }
- /**
- * Sets the FlowType and recompiles the menu
- *
- * @param flowType
- * FlowType
- */
- public void setFlowType(FlowType flowType) {
- this.flowType = flowType;
- this.compile();
- }
- /**
- * Gets the FlowType
- *
- * @return FlowType
- */
- public FlowType getFlowType() {
- return flowType;
- }
- /**
- * Toggles the showAllPopups state
- * */
- public void toggleShowAll() {
- showAllPopups = !showAllPopups;
- }
- /**
- * Constructs a menu using the provided parent and location,
- * assuming Anchor.UP_LEFT
- *
- * @param parent
- * PaintInterface
- * @param location
- * Point
- */
- public Menu(PaintInterface parent, Point location) {
- this(parent, location, Anchor.UP_LEFT);
- }
- /**
- * Adds the specified menu item
- *
- * @param i
- * MenuItem
- */
- public void add(MenuItem i) {
- i.setIndex(components.size());
- components.add(i);
- compile();
- }
- /**
- * Compiles this menu
- */
- public void compile() {
- for (int i = 0; i < components.size(); i++)
- components.get(i).compile();
- }
- /**
- * Gets position x based on the menu's anchor
- *
- * @return int
- */
- public int getAbsX() {
- if (anchor.name().contains("LEFT"))
- return location.x;
- else
- return location.x - getWidth();
- }
- /**
- * Gets position y based on the menu's anchor
- *
- * @return int
- */
- public int getAbsY() {
- if (anchor.name().contains("UP"))
- return location.y;
- else
- return location.y - getHeight();
- }
- /**
- * Gets the maximum width of this menu using the menu's FlowType
- *
- * @return int
- */
- public int getWidth() {
- if (flowType.equals(FlowType.HORIZONTAL)) {
- int width = padding * components.size();
- for (MenuItem m : components)
- if (m.bounds != null)
- width += m.bounds.width;
- return width + padding;
- } else {
- int max = Integer.MIN_VALUE;
- for (MenuItem m : components)
- if (m.bounds != null)
- if (max < m.bounds.width)
- max = (int) m.bounds.width;
- return max + (2 * padding);
- }
- }
- /**
- * Gets the maximum height of this menu based of FlowType
- *
- * @return int
- */
- public int getHeight() {
- if (flowType.equals(FlowType.HORIZONTAL)) {
- int max = Integer.MIN_VALUE;
- for (MenuItem m : components)
- if (m.bounds != null)
- if (max < m.bounds.height)
- max = (int) m.bounds.height;
- return max + (2 * padding);
- } else {
- int height = padding * components.size();
- for (MenuItem m : components)
- if (m.bounds != null)
- height += m.bounds.height;
- return height + padding;
- }
- }
- /**
- * Gets the current bounds of this menu, with rounded corners if
- * specified
- *
- * @param rounded
- * boolean
- * @return RoundRectangle2D.Float
- */
- public RoundRectangle2D.Float getArea(boolean rounded) {
- float round = rounded ? style.roundCorner : 0;
- return new RoundRectangle2D.Float(getAbsX(), getAbsY(),
- getWidth(), getHeight(), round, round);
- }
- public Rectangle getBoundsFull() {
- RoundRectangle2D r1 = getArea(false);
- RoundRectangle2D r2 = visiblePopup != null ? visiblePopup.bkg
- : getArea(false);
- int x = (int) Math.min(r1.getX(), r2.getX());
- int y = (int) Math.min(r1.getY(), r2.getY());
- int width = (int) Math.max(r1.getX() + r1.getWidth(), r2.getX()
- + r2.getWidth())
- - x;
- int height = (int) Math.max(r1.getX() + r1.getHeight(),
- r2.getX() + r2.getHeight())
- - y;
- return new Rectangle(x, y, width, height);
- }
- /**
- * Renders the menu to the specified Graphics object using the
- * provided mouse location for any popups
- *
- * @param g
- * Graphics2D
- * @param mouseLoc
- * Point
- */
- public void render(Graphics2D g, Point mouseLoc) {
- g.setColor(style.bgColor);
- g.fill(getArea(true));
- MenuPopUp overPopup = null;
- for (MenuItem m : components) {
- m.render(g);
- MenuPopUp p = m.getPopUp();
- if (p != null) {
- if (m.bounds.contains(mouseLoc)
- || (m.getPopUp().name
- .equalsIgnoreCase(visiblePopup != null ? visiblePopup.name
- : "") && rectangleContainsApprox(
- visiblePopup.bkg, mouseLoc)))
- overPopup = m.getPopUp();
- }
- }
- if (showAllPopups)
- getAllPopups(true,"tools").render(g);
- else if (overPopup != null) {
- overPopup.render(g);
- }
- visiblePopup = overPopup;
- }
- /**
- * Check if the specified point is within sqrt(2) of the Rectangle
- *
- * @param r
- * RoundRectangle2D
- * @param p
- * Point
- * @return boolean contains
- */
- public boolean rectangleContainsApprox(RoundRectangle2D r, Point p) {
- for (int oX = -1; oX <= 1; oX++)
- for (int oY = -1; oY <= 1; oY++)
- if (r.contains(new Point(p.x + oX, p.y + oY)))
- return true;
- return false;
- }
- /**
- * Gets all popups in frontToBack or backToFront order and excluding
- * specified names
- *
- * @param rightToLeft
- * boolean
- * @param excludeItems
- * String...
- * @return MenuPopUp
- */
- public MenuPopUp getAllPopups(boolean backToFront,
- String... excludeItems) {
- List<String> lines = new ArrayList<String>();
- if (components.size() > 0)
- if (backToFront)
- for (int i = components.size() - 1; i >= 0; i--) {
- boolean ignored = false;
- for (String subS : excludeItems)
- if (components.get(i).name
- .equalsIgnoreCase(subS))
- ignored = true;
- if (!ignored) {
- MenuPopUp sub = components.get(i).getPopUp();
- if (sub != null)
- for (String line : sub.lines)
- if (!containsLine(lines, line))
- lines.add(line);
- }
- }
- else
- for (int i = 0; i < components.size(); i++) {
- boolean ignored = false;
- for (String subS : excludeItems)
- if (components.get(i).name
- .equalsIgnoreCase(subS))
- ignored = true;
- if (!ignored) {
- MenuPopUp sub = components.get(i).getPopUp();
- if (sub != null)
- for (String line : sub.lines)
- if (!containsLine(lines, line))
- lines.add(line);
- }
- }
- String[] linesArr = new String[lines.size()];
- for (int i = 0; i < lines.size(); i++)
- linesArr[i] = lines.get(i);
- MenuPopUp p = new MenuPopUp(linesArr, "allpopups");
- p.setParent(components.get(components.size() - 1));
- return p;
- }
- /**
- * Checks if the specified array contains the specified line, just
- * the tag, not the data if possible
- *
- * @param lines
- * List of Strings
- * @param line
- * String
- * @return boolean contains
- */
- public boolean containsLine(List<String> lines, String line) {
- for (String s : lines)
- if (s.contains(":") && line.contains(":")) {
- if (s.split(":")[0]
- .equalsIgnoreCase(line.split(":")[0]))
- return true;
- } else if (s.equalsIgnoreCase(line))
- return true;
- return false;
- }
- /**
- * Gets a proggie as a BufferedImage
- *
- * @return BufferedImage proggie
- */
- public BufferedImage getProggie() {
- String[] lines = getAllPopups(true, "tools").lines;
- Color color = style.FONT_COLOR;
- Font font = style.FONT;
- float line_height = font.getLineMetrics(lines[0], Paint.frc)
- .getHeight();
- int width = 0;
- for (String line : lines)
- if (font.getStringBounds(line, Paint.frc).getWidth() > width)
- width = (int) font.getStringBounds(line, Paint.frc)
- .getWidth();
- int height = (int) (lines.length * line_height);
- width += style.roundCorner + 2;
- height += style.roundCorner + 2;
- RoundRectangle2D.Float bkg = new RoundRectangle2D.Float(0, 0,
- width, height,
- style.roundCorner > 0 ? style.roundCorner + 1 : 0,
- style.roundCorner > 0 ? style.roundCorner + 1 : 0);
- RoundRectangle2D.Float fg = new RoundRectangle2D.Float(
- (float) bkg.getX() + 1, (float) bkg.getY() + 1,
- width - 2, height - 2, style.roundCorner,
- style.roundCorner);
- Rectangle txtBounds = new Rectangle(
- (int) (fg.getX() + (style.roundCorner / 2)),
- (int) (fg.getY() + (style.roundCorner / 2)),
- (int) (width - style.roundCorner - 2), (int) (height
- - style.roundCorner - 2));
- BufferedImage bImg = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = (Graphics2D) bImg.getGraphics();
- g.setColor(style.bgColor);
- g.fill(bkg);
- g.setColor(style.fgColor);
- g.fill(fg);
- g.setFont(font);
- g.setColor(color);
- for (int i = 0; i < lines.length; i++)
- g.drawString(lines[i], txtBounds.x,
- ((i + 1) * (line_height)) + txtBounds.y);
- return bImg;
- }
- /**
- * Saves a progress report to the Screenshots directory
- */
- public void saveProggie() {
- String name = crafter.name
- + "_"
- + PaintFormatter.getFormattedTime(
- System.currentTimeMillis() - Paint.startTime,
- "-", true);
- final File dir = new File(
- GlobalConfiguration.Paths.getScreenshotsDirectory());
- if (dir.isDirectory() || dir.mkdirs()) {
- try {
- int ext = 0;
- while (new File(dir, name
- + (ext > 0 ? ("(" + ext + ")") : "") + ".png")
- .exists())
- ext++;
- ImageIO.write(Paint.paintMenu.getProggie(), "png",
- new File(dir, name
- + (ext > 0 ? ("(" + ext + ")") : "")));
- log.info("Saved proggie!");
- log.info(new File(dir, name
- + (ext > 0 ? ("(" + ext + ")") : "") + ".png")
- .getAbsolutePath());
- } catch (IOException e) {
- log.severe("Failed to save proggie!");
- }
- }
- }
- /**
- * Adds the specified mouse listener
- *
- * @param listen
- * MouseListen
- */
- public void addMouseListener(MouseListen listen) {
- if (mouseListeners == null)
- mouseListeners = new ArrayList<MouseListen>();
- mouseListeners.add(listen);
- }
- /**
- * Sets the default line listener
- *
- * @param listen
- * LineListener
- */
- public void setDefaultLineListener(LineListener listen) {
- defaultLineListener = listen;
- }
- /**
- * Fires the MouseEvent in all containing children and this
- *
- * @param e
- * MouseEvent
- */
- public void fireMouseEvent(MouseEvent e) {
- if (getArea(true).contains(e.getPoint()))
- if (mouseListeners != null)
- for (MouseListen m : mouseListeners)
- m.MouseAction(e);
- for (MenuItem m : components)
- if (m.bounds != null)
- if (m.bounds.contains(e.getPoint()))
- m.fireMouseEvent(e);
- if (visiblePopup != null)
- visiblePopup.fireMouseEvent(e);
- }
- }
- /**
- * Represents a class containing the method for getting the popup
- *
- * @author Equinox_
- *
- */
- public abstract class GetPopup {
- abstract MenuPopUp getPopUp();
- }
- /**
- * Represents a modified MouseListener used in MenuEvents
- *
- * @author Equinox_
- *
- */
- public abstract class MouseListen {
- abstract void MouseAction(MouseEvent e);
- }
- /**
- * An abstract class representing MenuItems
- *
- * @author Equinox_
- *
- */
- public abstract class MenuItem {
- final GetPopup getPopup;
- Menu parent;
- RoundRectangle2D.Float bounds;
- int index;
- final int width;
- final int height;
- List<MouseListen> mouseListeners;
- final String name;
- /**
- * Constructs a MenuItem with the given name, parent, getPopup
- * method, width and height
- *
- * @param name
- * String
- * @param parent
- * Menu
- * @param getPopup
- * GetPopup
- * @param width
- * int
- * @param height
- * int
- */
- public MenuItem(String name, Menu parent, GetPopup getPopup,
- int width, int height) {
- this.name = name;
- this.height = height;
- this.width = width;
- this.getPopup = getPopup;
- this.parent = parent;
- this.bounds = new RoundRectangle2D.Float(0, 0, width, height,
- parent.style.roundCorner, parent.style.roundCorner);
- }
- /**
- * Constructs a MenuItem with the given name, parent, width and
- * height
- *
- * @param name
- * String
- * @param parent
- * Menu
- * @param width
- * int
- * @param height
- * int
- */
- public MenuItem(String name, Menu parent, int width, int height) {
- this(name, parent, null, width, height);
- }
- /**
- * sets this item's index
- *
- * @param idx
- * int
- */
- public void setIndex(int idx) {
- this.index = idx;
- }
- /**
- * renders this item to the given Graphics2D
- *
- * @param g
- * Graphics2D
- */
- abstract void render(Graphics2D g);
- /**
- * Compiles this item
- */
- public void compile() {
- this.bounds = new RoundRectangle2D.Float(0, 0, width, height,
- parent.style.roundCorner, parent.style.roundCorner);
- bounds.x = getX();
- bounds.y = getY();
- }
- /**
- * Gets the offset from upper left of parent depending on parent's
- * FlowType
- *
- * @return int offsetY
- */
- public int getOffX() {
- if (parent.getFlowType().equals(FlowType.HORIZONTAL)) {
- int x = 1;
- for (int i = 0; i < index; i++)
- x += 1 + parent.components.get(i).bounds.width;
- return x;
- }
- if (parent.getWidth() > bounds.width)
- return (int) (parent.getWidth() / 2 - bounds.width / 2);
- return 1;
- }
- /**
- * Gets the offset from upper left of parent depending on parent's
- * FlowType
- *
- * @return int offsetX
- */
- public int getOffY() {
- if (parent.getFlowType().equals(FlowType.VERTICAL)) {
- int y = 1;
- for (int i = 0; i < index; i++)
- y += 1 + parent.components.get(i).bounds.height;
- return y;
- }
- return 1;
- }
- /**
- * Gets the absolute x
- *
- * @return int absolute x
- */
- public int getX() {
- int x = getOffX() + parent.getAbsX();
- return x;
- }
- /**
- * Gets the absolute y
- *
- * @return int absolute y
- */
- public int getY() {
- int y = getOffY() + parent.getAbsY();
- return y;
- }
- /**
- * Gets this item's popup
- *
- * @return MenuPopUp
- */
- public MenuPopUp getPopUp() {
- if (getPopup != null) {
- MenuPopUp m = getPopup.getPopUp();
- m.setParent(this);
- if (parent.defaultLineListener != null)
- m.addLineListener(parent.defaultLineListener);
- return m;
- }
- return null;
- }
- /**
- * Adds a mouselistener
- *
- * @param listen
- * MouseListen
- */
- public void addMouseListener(MouseListen listen) {
- if (mouseListeners == null)
- mouseListeners = new ArrayList<MouseListen>();
- mouseListeners.add(listen);
- }
- /**
- * Sends the mouse event to all of this item's listeners
- *
- * @param e
- * MouseEvent
- */
- public void fireMouseEvent(MouseEvent e) {
- if (mouseListeners != null && mouseListeners.size() > 0)
- for (MouseListen m : mouseListeners)
- m.MouseAction(e);
- }
- }
- /**
- * A class representing a mouse over button on the parent menu
- *
- * @author Equinox_
- *
- */
- public class MenuButton extends MenuItem {
- final static int width = 30;
- final static int height = 30;
- String imageIcon;
- /**
- * Constructs a button using the specified name, parent, imageIcon,
- * and getPopup method.
- *
- * @param name
- * String
- * @param parent
- * Menu
- * @param imageIcon
- * String
- * @param getPopUp
- * GetPopup
- */
- public MenuButton(String name, Menu parent, String imageIcon,
- GetPopup getPopUp) {
- super(name, parent, getPopUp, width, height);
- this.imageIcon = imageIcon.toLowerCase();
- }
- /**
- * Constructs a button using the specified name, parent, and
- * imageIcon
- *
- * @param name
- * String
- * @param parent
- * Menu
- * @param imageIcon
- * String
- */
- public MenuButton(String name, Menu parent, String imageIcon) {
- this(name, parent, imageIcon, null);
- }
- /**
- * Constructs a button using the specified name and parent
- *
- * @param name
- * String
- * @param parent
- * Menu
- */
- public MenuButton(String name, Menu parent) {
- this(name, parent, "", null);
- }
- /**
- * Renders this MenuButton to the given Graphics2D context
- */
- public void render(Graphics2D g) {
- // Compiling
- if (parent.parent.icons.containsKey(imageIcon))
- if (parent.parent.icons.get(imageIcon) != null)
- if (!parent.parent.icons.containsKey("Button-"
- + imageIcon)) {
- // Scale the image
- int width = (int) (bounds.width - (parent.style.roundCorner));
- int height = (int) (bounds.height - (parent.style.roundCorner));
- int hints = Image.SCALE_FAST;
- parent.parent.icons.put(
- "Button-" + imageIcon,
- parent.parent.icons.get(imageIcon)
- .getScaledInstance(width, height,
- hints));
- }
- g.setColor(parent.style.fgColor);
- g.fill(bounds);
- if (parent.parent.icons.containsKey("Button-" + imageIcon))
- if (parent.parent.icons.get("Button-" + imageIcon) != null)
- g.drawImage(
- parent.parent.icons.get("Button-" + imageIcon),
- (int) (bounds.x + (parent.style.roundCorner / 2)),
- (int) (bounds.y + (parent.style.roundCorner / 2)),
- null);
- }
- }
- /**
- * A class representing a progress bar in a menu
- *
- * @author Equinox_
- *
- */
- public class MenuProgressBar extends MenuItem {
- final static int width = 100;
- final static int height = 30;
- final GetPercent getPercent;
- RoundRectangle2D.Float percent;
- Point textLoc;
- String prefix;
- /**
- * Constructs a MenuProgress bar using the specified name, parent,
- * getPercent method, text prefix, and getPopup method
- *
- * @param name
- * String
- * @param parent
- * Menu
- * @param getPercent
- * GetPercent
- * @param prefix
- * String
- * @param getPopup
- * GetPopup
- */
- public MenuProgressBar(String name, Menu parent,
- GetPercent getPercent, String prefix, GetPopup getPopup) {
- super(name, parent, getPopup, width, height);
- this.getPercent = getPercent;
- this.prefix = prefix;
- }
- /**
- * Renders this progress bar to the given Graphics context
- */
- public void render(Graphics2D g) {
- percent.width = getPercent.getPercent();
- g.setColor(parent.style.progressBarBG);
- g.fill(bounds);
- g.setColor(parent.style.progressBarFG);
- g.fill(percent);
- String perct = String.valueOf(getPercent.getPercent());
- if (perct.length() < 2)
- perct = "0" + perct;
- g.setFont(style.FONT);
- g.setColor(style.FONT_COLOR);
- g.drawString(prefix + ": " + perct + "%", textLoc.x, textLoc.y);
- }
- /**
- * Compiles this progress bar
- */
- public void compile() {
- super.compile();
- percent = new RoundRectangle2D.Float(bounds.x, bounds.y,
- getPercent.getPercent(), bounds.height,
- bounds.arcwidth, bounds.archeight);
- textLoc = new Point();
- textLoc.x = (int) bounds.getCenterX();
- textLoc.y = (int) bounds.getCenterY();
- textLoc.y += parent.style.FONT.getLineMetrics(prefix + ": 00%",
- parent.parent.frc).getHeight() / 2f;
- textLoc.x -= parent.style.FONT.getStringBounds(
- prefix + ": 00%", parent.parent.frc).getWidth() / 2f;
- }
- }
- /**
- * Class representing the method for getting the current percentile for
- * a progress bar
- *
- * @author Equinox_
- *
- */
- public abstract class GetPercent {
- abstract int getPercent();
- }
- /**
- * Class representing the LineListeners in popups
- *
- * @author Equinox_
- *
- */
- public abstract class LineListener {
- abstract void fireEvent(MouseEvent e, String line);
- abstract boolean hasAction(String line);
- }
- /**
- * A class representing the popups in the paint interface
- *
- * @author Equinox_
- *
- */
- public class MenuPopUp {
- private Font font;
- private Color color;
- private PaintStyle style;
- private RoundRectangle2D bkg;
- public RoundRectangle2D fg;
- public Rectangle txtBounds;
- public MenuItem parent;
- public final String name;
- public String[] lines;
- int width;
- int height;
- List<LineListener> lineListeners;
- /**
- * Creates a popup using the provided array of strings making up the
- * lines and name
- *
- * @param lines
- * as String[]
- * @param name
- * as String
- */
- public MenuPopUp(String[] lines, String name) {
- this.name = name;
- this.lines = lines;
- }
- /**
- * Set this popup's parent and compiles locations
- *
- * @param parent
- * MenuItem
- */
- public void setParent(MenuItem parent) {
- this.parent = parent;
- this.style = parent.parent.style;
- // Calc dimensions
- color = name.equals("tools") ? style.TOOLS_FONT_COLOR
- : style.FONT_COLOR;
- font = name.equals("tools") ? style.TOOLS_FONT : style.FONT;
- float line_height = font.getLineMetrics(lines[0], Paint.frc)
- .getHeight();
- width = 0;
- for (String line : lines)
- if (font.getStringBounds(line, Paint.frc).getWidth() > width)
- width = (int) font.getStringBounds(line, Paint.frc)
- .getWidth();
- height = (int) (lines.length * line_height);
- width += style.roundCorner + 2;
- height += style.roundCorner + 2;
- int halfPadding = (parent.parent.padding / 2);
- if (halfPadding < 1 && halfPadding != 0)
- halfPadding = 1;
- int x = 0;
- int y = 0;
- if (parent.parent.getFlowType().equals(FlowType.HORIZONTAL)) {
- if (parent.bounds.y - height - parent.parent.padding > 0) {
- // Above
- x = (int) (parent.bounds.x - width
- + parent.bounds.width + halfPadding);
- if (x < 0)
- x = (int) (parent.bounds.x - halfPadding);
- y = (int) (parent.parent.getAbsY() - height);
- } else {
- // Below
- x = (int) (parent.bounds.x - halfPadding);
- if (x + width > parent.parent.bounds.width)
- x = (int) (parent.bounds.x - halfPadding - width);
- y = (int) (parent.parent.getAbsY() + parent.parent
- .getHeight());
- }
- } else {
- // Vertical
- if (parent.bounds.x - width - parent.parent.padding > 0) {
- // Left
- x = (int) (parent.parent.getAbsX() - width);
- if (parent.bounds.y - height + halfPadding
- + parent.bounds.height > 0)
- y = (int) (parent.bounds.y - height + halfPadding + parent.bounds.height);
- else
- y = (int) (parent.bounds.y - halfPadding);
- } else {
- // Right
- x = (int) (parent.parent.getAbsX() + parent.parent
- .getWidth());
- if (parent.bounds.y - height + halfPadding
- + parent.bounds.height > 0)
- y = (int) (parent.bounds.y - height + halfPadding + parent.bounds.height);
- else
- y = (int) (parent.bounds.y - halfPadding);
- }
- }
- bkg = new RoundRectangle2D.Float(x, y, width, height,
- style.roundCorner > 0 ? style.roundCorner + 1 : 0,
- style.roundCorner > 0 ? style.roundCorner + 1 : 0);
- fg = new RoundRectangle2D.Float((float) bkg.getX() + 1,
- (float) bkg.getY() + 1, width - 2, height - 2,
- style.roundCorner, style.roundCorner);
- txtBounds = new Rectangle(
- (int) (fg.getX() + (style.roundCorner / 2)),
- (int) (fg.getY() + (style.roundCorner / 2)),
- (int) (width - style.roundCorner - 2), (int) (height
- - style.roundCorner - 2));
- }
- /**
- * Paints this popup to using the provided Graphics2D in relation to
- * it's parent PaintInterface
- *
- * @param g
- * as Graphics2D
- */
- public void render(Graphics2D g) {
- g.setColor(style.bgColor);
- g.fill(bkg);
- g.setColor(style.fgColor);
- g.fill(fg);
- float line_height = (txtBounds.height - 4) / lines.length;
- g.setFont(font);
- g.setColor(color);
- for (int i = 0; i < lines.length; i++) {
- if (new Rectangle(txtBounds.x,
- (int) ((i * (line_height)) + txtBounds.y),
- txtBounds.width, (int) line_height)
- .contains(parent.parent.parent.mouseLoc)
- && hasAction(lines[i])) {
- g.setColor(style.highlightColor);
- g.fill(new Rectangle(txtBounds.x,
- (int) ((i * (line_height)) + 2 + txtBounds.y),
- txtBounds.width, (int) line_height));
- }
- g.setColor(color);
- g.drawString(lines[i], txtBounds.x,
- ((i + 1) * (line_height)) + txtBounds.y);
- }
- }
- boolean hasAction(String line) {
- if (lineListeners != null)
- for (LineListener l : lineListeners)
- if (l.hasAction(line))
- return true;
- return false;
- }
- /**
- * Adds the specified line listener
- *
- * @param l
- * LineListener
- */
- public void addLineListener(LineListener l) {
- if (lineListeners == null)
- lineListeners = new ArrayList<LineListener>();
- this.lineListeners.add(l);
- }
- /**
- * fires the specified mouse event using this popup's line listeners
- *
- * @param e
- * MouseEvent
- */
- public void fireMouseEvent(MouseEvent e) {
- if (!bkg.contains(e.getPoint()) || lineListeners == null
- || lineListeners.size() == 0)
- return;
- int line_height = (txtBounds.height - 4) / lines.length;
- for (int i = 0; i < lines.length; i++) {
- Rectangle stringRect = new Rectangle(txtBounds.x,
- (i * (line_height)) + txtBounds.y, txtBounds.width,
- line_height);
- if (stringRect.contains(e.getPoint())) {
- for (LineListener lineListener : lineListeners)
- lineListener.fireEvent(e, lines[i]);
- return;
- }
- }
- }
- }
- }
- /**
- * Used for specifing the way a menu is layed out.
- *
- * @author Equinox_
- *
- */
- private enum FlowType {
- VERTICAL, HORIZONTAL
- }
- /**
- * Used for anchoring the menu bar
- *
- * @author Equinox_
- *
- */
- private enum Anchor {
- UP_LEFT, UP_RIGHT, DOWN_RIGHT, DOWN_LEFT
- }
- /**
- * Used to style the paint
- *
- * @author Equinox_
- *
- */
- public static class PaintStyle {
- public final Color FONT_COLOR = Color.BLACK;
- public final Font FONT = new Font("Arial", 1, 10)
- .deriveFont(Font.PLAIN);
- public final Font TOOLS_FONT = new Font("Arial", 1, 14)
- .deriveFont(Font.PLAIN);
- public final Color TOOLS_FONT_COLOR = Color.BLACK;
- public final float roundCorner = 10f;
- public final Color progressBarFG = new Color(0f, 1f, 0f, 1f);
- public final Color progressBarBG = new Color(.3f, .3f, .3f, 1f);
- public final Color bgColor = new Color(0f, 0f, 0f, 0.75f);
- final Color fgColor = new Color(.3f, .3f, .3f, 1f);
- final Color highlightColor = new Color(1f, 0f, 0f, 0.05f);
- }
- /**
- * Use these enums to define the type of path <br />
- * ALL_Center: All points are near the middle of the lines <br />
- * Full: Points can be anywhere on the line<br />
- * WEIGHT_CENTER: Weighted to center, possibility of being on sides, but
- * lower
- *
- * @author Equinox_
- *
- */
- enum MeshPathType {
- ALL_CENTER, FULL, WEIGHT_CENTER
- }
- /**
- * A class that will take a specified mesh, generate a path through it, then
- * round the path off with Bezier curves.
- *
- * @author Equinox_
- *
- */
- public class MeshPath {
- private final Color MESH_FILL = new Color(0.5f, 0.5f, 0.5f, 0.75f);
- private final Color MESH_BORDER = new Color(0.75f, 0.75f, 0.75f, 0.75f);
- private final Color PATH_COLOR = new Color(0f, 1f, 0f, 1f);
- private final Color SMOOTH_PATH_COLOR = new Color(0f, 0f, 1f, 1f);
- private final Color SUBDIVIDED_PATH_COLOR = new Color(1f, 0f, 1f, 1f);
- private List<RSTile[]> mesh = new ArrayList<RSTile[]>();
- private List<RSTile> blockPath = new ArrayList<RSTile>();
- private List<RSTile> smoothPath = new ArrayList<RSTile>();
- private boolean end;
- private List<RSTile> subdividedPath = new ArrayList<RSTile>();
- /**
- * Creates a MeshPath with a blank mesh
- */
- public MeshPath() {
- }
- /**
- * Creates a MeshPath using the provided mesh
- *
- * @param mesh
- * as RSTile[][]
- */
- public MeshPath(RSTile[][] mesh) {
- setMesh(mesh);
- }
- /**
- * Adds a line to the mesh with the given tiles
- *
- * @param tiles
- * the RSTiles making up the line
- */
- public void addLine(RSTile... tiles) {
- mesh.add(tiles);
- }
- /**
- * Gets the number of lines in the mesh
- *
- * @return int size
- */
- public int meshSize() {
- return mesh.size();
- }
- /**
- * Adds all the lines of a specified mesh to the current mesh.
- *
- * @param mesh
- * as RSTile[][]
- */
- public void addMesh(RSTile[][] mesh) {
- for (RSTile[] line : mesh)
- this.mesh.add(line);
- }
- /**
- * Sets the current mesh to the provided mesh
- *
- * @param mesh
- * as RSTile[][]
- */
- public void setMesh(RSTile[][] mesh) {
- this.mesh.clear();
- addMesh(mesh);
- }
- public List<RSTile> getTilesOnLine(RSTile a, RSTile b) {
- List<RSTile> sublineTiles = new ArrayList<RSTile>();
- int deltaX = b.getX() - a.getX();
- int deltaY = b.getY() - a.getY();
- double dist = calc.distanceBetween(a, b);
- if (dist == 0)
- dist = 1;
- double eX = deltaX / dist, eY = deltaY / dist;
- for (int i = 0; i <= dist; i++)
- sublineTiles.add(new RSTile(a.getX() + (int) (eX * i), a.getY()
- + (int) (eY * i)));
- return sublineTiles;
- }
- /**
- * Gets all the tiles on the provided line
- *
- * @param line
- * as RSTile...
- * @return List<RSTile> tiles on line
- */
- public List<RSTile> getTilesOnLines(RSTile... line) {
- List<RSTile> sublineTiles = new ArrayList<RSTile>();
- if (line.length == 1)
- sublineTiles.add(line[0]);
- else
- for (int i = 1; i < line.length; i++) {
- RSTile a = line[i - 1];
- RSTile b = line[i];
- sublineTiles.addAll(getTilesOnLine(a, b));
- }
- return sublineTiles;
- }
- /**
- * Gets a tile on the provided line using the ALL_CENTER method
- *
- * @param line
- * as RSTile...
- * @return RSTile tile on line
- */
- public RSTile getTileOnLine(RSTile... line) {
- return getTileOnLine(MeshPathType.ALL_CENTER, line);
- }
- /**
- * Gets a tile on the provided line using the provided method
- *
- * @param placement
- * as MeshPathType
- * @param line
- * as RSTile...
- * @return RSTile tile on line
- */
- public RSTile getTileOnLine(MeshPathType placement, RSTile... line) {
- List<RSTile> tiles = getTilesOnLines(line);
- int index = 0;
- switch (placement) {
- case ALL_CENTER:
- index = random(tiles.size() / 4, 3 * tiles.size() / 4 + 1);
- // +1 due to exclusive upper bound
- break;
- case FULL:
- index = random(0, tiles.size());
- break;
- case WEIGHT_CENTER:
- index = random(tiles.size() / 4, 3 * tiles.size() / 4 + 1);
- // +1 due to exclusive upper bound
- int rand = random(-10, tiles.size() / 4);
- index += rand > 0 ? rand : 0;
- break;
- }
- if (index < 0)
- index = 0;
- if (index >= tiles.size())
- index = tiles.size() - 1;
- if (tiles.size() > 0)
- return tiles.get(index);
- else
- return null;
- }
- /**
- * Paints the mesh to the provided graphics context in the minimap
- *
- * @param g
- * as Graphics2D
- */
- public void paintMesh(Graphics2D g) {
- if (mesh.size() > 1) {
- for (int i = 1; i < mesh.size(); i++) {
- RSTile[] lineA = mesh.get(i - 1).clone();
- RSTile[] lineB = mesh.get(i).clone();
- Polygon poly = new Polygon();
- RSTile a = lineA[0];
- RSTile b = lineB[0];
- RSTile c = lineA[lineA.length - 1];
- RSTile d = lineB[lineB.length - 1];
- boolean onMap = true;
- double distA = calc.distanceBetween(c, b)
- + calc.distanceBetween(a, d);
- double distB = calc.distanceBetween(a, b)
- + calc.distanceBetween(c, d);
- if (distA > distB) {
- // Reverse lineB.
- RSTile[] newLineB = new RSTile[lineB.length];
- int start = lineB.length - 1;
- for (RSTile t : lineB) {
- if (start >= 0)
- newLineB[start] = t;
- start--;
- }
- lineB = newLineB;
- }
- if (lineA != null)
- for (RSTile t : lineA) {
- Point p = calc.tileToMinimap(t);
- if (p.x == -1 || p.y == -1) {
- onMap = false;
- break;
- }
- poly.addPoint(p.x, p.y);
- }
- if (lineB != null)
- for (RSTile t : lineB) {
- Point p = calc.tileToMinimap(t);
- if (p.x == -1 || p.y == -1) {
- onMap = false;
- break;
- }
- poly.addPoint(p.x, p.y);
- }
- if (onMap) {
- g.setColor(MESH_BORDER);
- g.draw(poly);
- g.setColor(MESH_FILL);
- g.fill(poly);
- }
- }
- }
- }
- public RSTile getTileOnMap(RSTile t) {
- List<RSTile> tiles = getTilesOnLine(t, getMyPlayer().getLocation());
- for (RSTile tt : tiles)
- if (calc.tileOnMap(tt))
- return tt;
- return null;
- }
- /**
- * Paints the current un-smoothed path to the minimap using the provided
- * graphics object
- *
- * @param g
- * as Graphics2D
- */
- public void paintPath(Graphics2D g) {
- if (blockPath.size() > 1) {
- g.setColor(PATH_COLOR);
- for (int i = 1; i < blockPath.size(); i++) {
- Point a = calc.tileToMinimap(blockPath.get(i - 1));
- Point b = calc.tileToMinimap(blockPath.get(i));
- if (a.x > 0 && a.y > 0)
- g.fillOval(a.x - 2, a.y - 2, 5, 5);
- if (b.x > 0 && b.y > 0)
- g.fillOval(b.x - 2, b.y - 2, 5, 5);
- if (a.x > 0 && a.y > 0 && b.x > 0 && b.y > 0)
- g.drawLine(a.x, a.y, b.x, b.y);
- }
- }
- }
- /**
- * Paints the smoothed version of the current path to the minimap using
- * the provided graphics object
- *
- * @param g
- * as Graphics2D
- */
- public void paintSmoothPath(Graphics2D g) {
- if (smoothPath.size() > 1) {
- g.setColor(SMOOTH_PATH_COLOR);
- for (int i = 1; i < smoothPath.size(); i++) {
- Point a = calc.tileToMinimap(smoothPath.get(i - 1));
- Point b = calc.tileToMinimap(smoothPath.get(i));
- if (a.x > 0 && a.y > 0)
- g.fillOval(a.x - 2, a.y - 2, 5, 5);
- if (b.x > 0 && b.y > 0)
- g.fillOval(b.x - 2, b.y - 2, 5, 5);
- if (a.x > 0 && a.y > 0 && b.x > 0 && b.y > 0)
- g.drawLine(a.x, a.y, b.x, b.y);
- }
- }
- }
- /**
- * Paints the subdivided smoothed version of the current path to the
- * minimap using the provided graphics object
- *
- * @param g
- * as Graphics2D
- */
- public void paintSubdividedPath(Graphics2D g) {
- if (subdividedPath.size() > 0) {
- g.setColor(SUBDIVIDED_PATH_COLOR);
- for (RSTile t : subdividedPath) {
- Point tileLoc = calc.tileToMinimap(t);
- if (tileLoc.x > 0 && tileLoc.y > 0)
- g.fillOval(tileLoc.x, tileLoc.y, 5, 5);
- }
- }
- }
- /**
- * Paints the mesh, and all versions of the current path to the minimap
- * using the provided graphics object
- *
- * @param g
- * as Graphics2D
- */
- public void paintAll(Graphics2D g) {
- paintMesh(g);
- paintPath(g);
- paintSmoothPath(g);
- paintSubdividedPath(g);
- }
- /**
- * Finds a path between the start index and the end index using the
- * provided placement type, then sets the current path to the found path
- *
- * @param placement
- * as MeshPathType
- * @param start
- * index
- * @param end
- * index
- */
- public void findPath(MeshPathType placement, int start, int end) {
- blockPath.clear();
- RSTile lineTile = getTileOnLine(mesh.get(start));
- String s = lineTile.toString();
- blockPath.add(lineTile);
- for (int i = start + 1; i <= end; i++) {
- lineTile = getTileOnLine(placement, mesh.get(i));
- blockPath.add(lineTile);
- s += "," + lineTile.toString();
- }
- smoothPath = smoothPath(blockPath);
- subdividedPath = subdividePath(smoothPath);
- }
- /**
- * Finds a path between the beginning and end of the mesh using the
- * provided placement type, then sets the current path to the found path
- *
- * @param placement
- * as MeshPathType
- */
- public void findPath(MeshPathType placement) {
- findPath(placement, 0, mesh.size() - 1);
- }
- /**
- * Finds a path between the beginning and end of the mesh using the
- * ALL_CENTER placement type, then sets the current path to the found
- * path
- */
- public void findPath() {
- findPath(MeshPathType.ALL_CENTER);
- }
- /**
- * Clears the current path and all refined versions of it.
- */
- public void clearPath() {
- blockPath.clear();
- smoothPath.clear();
- subdividedPath.clear();
- }
- /**
- * Smoothes the provided List of RSTiles using Bezier curves
- *
- * @param path
- * as List
- * @return List<RSTile> smoothed path
- */
- public List<RSTile> smoothPath(List<RSTile> path) {
- List<RSTile> smoothed = new ArrayList<RSTile>();
- smoothed.addAll(path);
- if (path.size() >= 3) {
- for (int b = 0; b < path.size(); b++) {
- if (b + 2 < path.size()) {
- double x2, y2;
- double t = 0.5;
- // use Berstein polynomials
- x2 = (path.get(b + 0).getX() + t
- * (-path.get(b + 0).getX() * 3 + t
- * (3 * path.get(b + 0).getX() - path
- .get(b + 0).getX() * t)))
- + t
- * (3 * path.get(b + 1).getX() + t
- * (-6 * path.get(b + 1).getX() + path
- .get(b + 1).getX() * 3 * t))
- + t
- * t
- * (path.get(b + 1).getX() * 3 - path.get(b + 1)
- .getX() * 3 * t)
- + path.get(b + 2).getX() * t * t * t;
- y2 = (path.get(b + 0).getY() + t
- * (-path.get(b + 0).getY() * 3 + t
- * (3 * path.get(b + 0).getY() - path
- .get(b + 0).getY() * t)))
- + t
- * (3 * path.get(b + 1).getY() + t
- * (-6 * path.get(b + 1).getY() + path
- .get(b + 1).getY() * 3 * t))
- + t
- * t
- * (path.get(b + 1).getY() * 3 - path.get(b + 1)
- .getY() * 3 * t)
- + path.get(b + 2).getY() * t * t * t;
- RSTile loc = new RSTile((int) x2, (int) y2);
- smoothed.set(b + 1, getTileInMesh(loc));
- }
- }
- }
- return smoothed;
- }
- /**
- * Gets the nearest tile in the mesh to the provided RSTile
- *
- * @param tile
- * the RSTile to use
- * @return RSTile tile in mesh
- */
- public RSTile getTileInMesh(RSTile tile) {
- if (inMesh(tile))
- return tile;
- double bestDist = Double.MAX_VALUE;
- RSTile nearest = null;
- if (mesh.size() > 1) {
- for (int i = 1; i < mesh.size(); i++) {
- RSTile[] lineA = mesh.get(i - 1);
- RSTile[] lineB = mesh.get(i);
- if (lineA != null && lineB != null) {
- RSTile a = lineA[0];
- RSTile b = lineB[0];
- RSTile c = lineA[lineA.length - 1];
- RSTile d = lineB[lineB.length - 1];
- if (calc.distanceBetween(a, b) > calc.distanceBetween(
- a, d)) {
- // Wrong order, switch b and d.
- RSTile clone = new RSTile(b.getX(), b.getY(),
- b.getZ());
- b = new RSTile(d.getX(), d.getY(), d.getZ());
- d = clone;
- }
- for (RSTile t : getTilesOnLine(a, b)) {
- double dist = calc.distanceBetween(tile, t);
- if (dist < bestDist) {
- bestDist = dist;
- nearest = t;
- }
- }
- for (RSTile t : getTilesOnLine(c, d)) {
- double dist = calc.distanceBetween(tile, t);
- if (dist < bestDist) {
- bestDist = dist;
- nearest = t;
- }
- }
- }
- }
- }
- return nearest;
- }
- /**
- * Checks to see if the provided RSTile is inside the mesh
- *
- * @param tile
- * the RSTile to check
- * @return boolean is in mesh
- */
- public boolean inMesh(RSTile tile) {
- if (mesh.size() > 1) {
- for (int i = 1; i < mesh.size(); i++) {
- RSTile[] lineA = mesh.get(i - 1);
- RSTile[] lineB = mesh.get(i);
- Polygon poly = new Polygon();
- if (lineA != null)
- for (RSTile t : lineA)
- poly.addPoint(t.getX(), t.getY());
- if (lineB != null)
- for (RSTile t : lineB)
- poly.addPoint(t.getX(), t.getY());
- if (poly.npoints >= 2)
- if (poly.contains(new Point(tile.getX(), tile.getY())))
- return true;
- }
- }
- return false;
- }
- /**
- * Takes the provided path and subdivides it using the length provided
- * in the Options class
- *
- * @param smoothPath
- * path to subdivide as a List<RSTile>
- * @return List<RSTile> subdivided path
- */
- public List<RSTile> subdividePath(List<RSTile> smoothPath) {
- RSTile[] smoothpathArray = new RSTile[smoothPath.size()];
- List<RSTile> path = getTilesOnLines(smoothPath
- .toArray(smoothpathArray));
- List<RSTile> subdividedPath = new ArrayList<RSTile>();
- RSTile previous = null;
- for (RSTile next : path) {
- if ((previous == null ? true : calc.distanceBetween(previous,
- next) > Options.walkingDistance.random())
- || next == path.get(path.size() - 1)) {
- previous = new RSTile(next.getX(), next.getY());
- subdividedPath.add(previous);
- }
- }
- return subdividedPath;
- }
- /**
- * Takes a step along this path if appropriate. Specifies only
- * TraversalOption.SPACE_ACTIONS.
- *
- * @return <tt>true</tt> if this path is currently valid for the player;
- * otherwise <tt>false</tt>.
- * @see #traverse(EnumSet)
- */
- public boolean traverse() {
- return this.traverse(EnumSet.of(TraversalOption.HANDLE_RUN,
- TraversalOption.SPACE_ACTIONS));
- }
- /**
- * Takes a step along this path if appropriate. If the path cannot be
- * traversed due to the player being too far from its vertices or
- * already at the end vertex, <tt>false</tt> will be returned. In all
- * other cases, <tt>true</tt> will be returned, but an action will not
- * necessarily be performed (based on the given options).
- *
- * @param options
- * Walking style options.
- * @return <tt>true</tt> if this path is currently valid for the player;
- * otherwise <tt>false</tt>.
- */
- public boolean traverse(EnumSet<TraversalOption> options) {
- RSTile next = getNext();
- if (next == null)
- return false;
- int nextIdx = getNearestIndexTo(next);
- if (next.equals(getEnd())) {
- if (calc.distanceTo(next) <= 1
- || (end && players.getMyPlayer().isMoving())
- || next.equals(walking.getDestination())) {
- return false;
- }
- end = true;
- } else {
- end = false;
- }
- if (options.contains(TraversalOption.HANDLE_RUN)
- && !walking.isRunEnabled() && walking.getEnergy() > 50) {
- walking.setRun(true);
- sleep(300);
- }
- if (walking.getDestination() != null
- && getNearestIndexTo(walking.getDestination()) >= nextIdx)
- return false;
- if (options.contains(TraversalOption.SPACE_ACTIONS)) {
- RSTile dest = walking.getDestination();
- if (dest != null && players.getMyPlayer().isMoving()
- && calc.distanceTo(dest) > 5
- && calc.distanceBetween(next, dest) < 7) {
- return true;
- }
- }
- return walking.walkTileMM(next, 0, 0);
- }
- /**
- * Checks whether or not this path can be traversed by the player. This
- * will be the case provided that the player near to one of its
- * vertices, but not already standing on the end vertex.
- *
- * @return <tt>true</tt> if the player can walk along this path;
- * otherwise <tt>false</tt>.
- */
- public boolean isValid() {
- return subdividedPath.size() > 0 && getNext() != null
- && !players.getMyPlayer().getLocation().equals(getEnd());
- }
- /**
- * Gets the start tile of this path.
- *
- * @return The start <code>RSTile</code>.
- */
- public RSTile getStart() {
- if (subdividedPath.size() > 0)
- return subdividedPath.get(0);
- else
- return null;
- }
- /**
- * Gets the next immediately available vertex in this path.
- *
- * @return The next walkable <code>RSTile</code>.
- */
- public RSTile getNext() {
- if (subdividedPath.size() > 0) {
- for (int i = subdividedPath.size() - 1; i >= 0; i--)
- if (calc.tileOnMap(subdividedPath.get(i)))
- return subdividedPath.get(i);
- return getTileOnMinimap(getNearest());
- } else
- return null;
- }
- public RSTile getTileOnMinimap(RSTile base) {
- if (calc.tileOnMap(base))
- return base;
- RSTile me = getMyPlayer().getLocation();
- int deltaX = base.getX() - me.getX();
- int deltaY = base.getY() - me.getY();
- double dist = calc.distanceBetween(base, me);
- double eX = deltaX / dist, eY = deltaY / dist;
- return new RSTile(me.getX() + (int) (eX * 14), me.getY()
- + (int) (eY * 14));
- }
- public RSTile getNearest() {
- int len = Integer.MAX_VALUE;
- RSTile best = null;
- for (RSTile t : subdividedPath)
- if (calc.distanceTo(t) < len) {
- best = t;
- len = calc.distanceTo(t);
- }
- return best;
- }
- public RSTile getNearestByPath() {
- int len = Integer.MAX_VALUE;
- RSTile best = null;
- for (RSTile t : subdividedPath) {
- int pLen = calc.pathLengthTo(t, false);
- if (pLen < len && pLen >= 0) {
- best = t;
- len = pLen;
- }
- }
- return best;
- }
- public int getNearestIndexTo(RSTile t) {
- int len = Integer.MAX_VALUE;
- int bestIndex = -1;
- if (walking.getDestination() != null)
- for (int i = 0; i < subdividedPath.size(); i++)
- if (calc.distanceBetween(t, subdividedPath.get(i)) < len) {
- bestIndex = i;
- len = calc.distanceTo(t);
- }
- return bestIndex;
- }
- /**
- * Gets the end tile of this path.
- *
- * @return The end <code>RSTile</code>.
- */
- public RSTile getEnd() {
- if (subdividedPath.size() > 0)
- return subdividedPath.get(subdividedPath.size() - 1);
- else
- return null;
- }
- /**
- * Reverses this mesh.
- *
- * @return
- *
- * @return This path.
- */
- public MeshPath reverse() {
- MeshPath newPath = new MeshPath();
- for (int i = mesh.size() - 1; i >= 0; i--)
- newPath.addLine(mesh.get(i));
- return newPath;
- }
- /**
- * Returns an array containing all of the vertices in this path.
- *
- * @return an array containing all of the vertices in this path.
- */
- public RSTile[] getTilePath() {
- RSTile[] tiles = new RSTile[subdividedPath.size()];
- for (int i = 0; i < tiles.length; i++)
- tiles[i] = new RSTile(subdividedPath.get(i).getX(),
- subdividedPath.get(i).getY());
- return tiles;
- }
- /**
- * Checks if we have a path
- *
- * @return boolean has a path
- */
- public boolean hasPath() {
- return subdividedPath.size() > 0;
- }
- }
- /**
- * The different states the NPC contact process can be in
- *
- * @author Equinox_
- *
- */
- enum npcContactState {
- CAST, SCROLL, SELECT, WAIT, CONTINUE, MENU, WITHDRAW_ASTRAL, WITHDRAW_COSMIC, WITHDRAW_AIR, OUT_OF_RUNES
- }
- /**
- * A class to contact people using NPC contact
- *
- * @author Equinox_
- *
- */
- class NPCContact {
- public npcContactState currentState = npcContactState.WAIT;
- private final int MAIN_FRAME = 88;
- private final int SCROLL_BAR = 20;
- private final int SCROLL_BAR_DOWN = 0;
- private final int VISIBLE_NPCS_CONTAINER = 21;
- private final int NPCS_CONTAINER = 22;
- private final int NPC_CONTACT_ANIM = 4413;
- private final int NPC_TO_SELECT = 14;
- private final String[] MENU_ITEM = { "repair", "pouch" };
- /**
- * Gets the current npcContactState
- *
- * @return the current npcContactState
- */
- private npcContactState getState() {
- if (interfaces.get(MAIN_FRAME).isValid()) {
- if (interfaces.get(MAIN_FRAME).getComponent(NPCS_CONTAINER)
- .isValid()) {
- Point npcPoint = interfaces.get(MAIN_FRAME)
- .getComponent(NPCS_CONTAINER)
- .getComponent(NPC_TO_SELECT).getCenter();
- Rectangle visible = interfaces.get(MAIN_FRAME)
- .getComponent(VISIBLE_NPCS_CONTAINER).getArea();
- if (!visible.contains(npcPoint))
- return npcContactState.SCROLL;
- else
- return npcContactState.SELECT;
- }
- }
- if (interfaces.canContinue())
- return npcContactState.CONTINUE;
- if (getComponent(MENU_ITEM) != null)
- return npcContactState.MENU;
- if (!interfaces.canContinue()
- && getMyPlayer().getAnimation() != NPC_CONTACT_ANIM
- && getComponent(MENU_ITEM) == null
- && getComponent("lease wai") == null) {
- if (!inventory.contains(ASTRAL_RUNE_ID))
- return npcContactState.WITHDRAW_ASTRAL;
- if (!inventory.contains(COSMIC_RUNE_ID))
- return npcContactState.WITHDRAW_COSMIC;
- if (inventory.getCount(true, AIR_RUNE_ID) < 2
- && !Options.hasAirStaff)
- return npcContactState.WITHDRAW_AIR;
- return npcContactState.CAST;
- }
- return npcContactState.WAIT;
- }
- /**
- * Finds a RSComponent with the specified string
- *
- * @param s
- * The String to search
- * @return RSComponent with string, otherwise null
- */
- private RSComponent getComponent(String... s) {
- RSInterface[] valid = interfaces.getAll();
- for (RSInterface iface : valid) {
- if (iface.getIndex() != 137) {
- int len = iface.getChildCount();
- for (int i = 0; i < len; i++) {
- RSComponent child = iface.getComponent(i);
- boolean b = (child.isValid()
- && child.getAbsoluteX() > 10 && child
- .getAbsoluteY() > 300);
- for (String sub : s)
- if (!child.getText().toLowerCase()
- .contains(sub.toLowerCase()))
- b = false;
- if (b)
- return child;
- }
- }
- }
- return null;
- }
- /**
- * Checks if the inventory or bank contains the specified item
- *
- * @param id
- * the item id
- * @return <tt>true</tt> if the bank or inventory contains the item,
- * otherwise, <tt>false</tt>
- */
- boolean invBank(int id) {
- return bank.getCount(id) > 0 || inventory.containsOneOf(id);
- }
- /**
- * Gets the count of a specified item in the inventory and bank
- *
- * @param int itemId
- * @return the item count
- */
- int invBankCount(int id) {
- return bank.getCount(id) + inventory.getCount(true, id);
- }
- /**
- * The main loop. Call this to do the next action for the contact
- * process.
- */
- public void main() {
- switch (currentState = getState()) {
- case WITHDRAW_ASTRAL:
- withdrawItem(ASTRAL_RUNE_ID, 1);
- if (!invBank(ASTRAL_RUNE_ID))
- removePouches();
- break;
- case WITHDRAW_COSMIC:
- withdrawItem(COSMIC_RUNE_ID, 1);
- if (!invBank(COSMIC_RUNE_ID))
- removePouches();
- break;
- case WITHDRAW_AIR:
- if (!inventory.contains(AIR_RUNE_ID)) {
- if (inventory.isFull())
- bank.deposit(PURE_ESS_ID, 1);
- withdrawItem(AIR_RUNE_ID, 1);
- }
- withdrawItem(AIR_RUNE_ID, 1);
- if (invBankCount(AIR_RUNE_ID) < 2)
- removePouches();
- break;
- case CAST:
- for (byte b = 0; b < 5; b++)
- if (bank.isOpen()) {
- bank.close();
- for (byte b2 = 0; b2 < 25; b2++)
- if (bank.isOpen())
- break;
- else
- sleep(95, 115);
- }
- if (game.getCurrentTab() != Game.TAB_MAGIC)
- game.openTab(Game.TAB_MAGIC);
- sleep(500, 1250);
- magic.castSpell(Magic.SPELL_NPC_CONTACT);
- sleep(750, 1250);
- break;
- case SCROLL:
- // Scroll
- RSComponent bar = interfaces.get(MAIN_FRAME)
- .getComponent(SCROLL_BAR).getComponent(SCROLL_BAR_DOWN);
- Point p = bar.getCenter();
- p.y = bar.getAbsoluteY() + bar.getHeight() - 5;
- mouse.click(p, true);
- break;
- case SELECT:
- interfaces.get(MAIN_FRAME).getComponent(NPCS_CONTAINER)
- .getComponent(NPC_TO_SELECT).doClick();
- break;
- case WAIT:
- break;
- case CONTINUE:
- if (interfaces.canContinue())
- interfaces.clickContinue();
- break;
- case MENU:
- if (getComponent(MENU_ITEM) != null)
- getComponent(MENU_ITEM).doClick();
- break;
- }
- sleep(900, 1200);
- }
- public void removePouches() {
- if (!openBank())
- return;
- // not enough runes, bank pouches:
- for (int id : Pouch.ALL_DEGRADED)
- if (inventory.contains(id)) {
- if (bank.deposit(id, 1))
- sleep(500, 600);
- }
- updatePouches();
- }
- }
- /**
- * Loads script data as the actual script runs. Useful for images that are
- * non-essential.
- *
- * @author Equinox_
- *
- */
- public static class DataLoader extends Thread {
- EquinoxZMICrafter crafter;
- public DataLoader(EquinoxZMICrafter crafter) {
- super("Data Loader");
- this.crafter = crafter;
- this.start();
- }
- // Item Info
- public void checkGE() {
- long before = System.currentTimeMillis();
- GEItem item = crafter.getGE().lookup(PURE_ESS_ID);
- if (item != null) {
- crafter.Paint.essPrice = getItemPrice(item);
- crafter.log("Price of " + item.getName() + ": "
- + getItemPrice(item));
- crafter.log("Loaded essence information in "
- + PaintFormatter.getFormattedTime(System
- .currentTimeMillis() - before));
- }
- }
- public void run() {
- checkGE();
- try {
- if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(
- null, "Would you like to load some images?",
- "Equinox_ Data Loader", JOptionPane.YES_NO_OPTION))
- throw new Exception();
- long before = System.currentTimeMillis();
- crafter.Paint.putImage(
- "homeicon",
- ImageIO.read(new URL(crafter.baseURL
- + "/images/houseIcon.png")));
- crafter.log("Loaded home image in "
- + PaintFormatter.getFormattedTime(System
- .currentTimeMillis() - before));
- before = System.currentTimeMillis();
- crafter.Paint
- .putImage(
- "rcicon",
- ImageIO.read(new URL(
- "http://www.runescape.com/img/hiscores/skill_icon_Runecrafting1.gif")));
- crafter.log("Loaded runecrafting image in "
- + PaintFormatter.getFormattedTime(System
- .currentTimeMillis() - before));
- before = System.currentTimeMillis();
- crafter.Paint.putImage(
- "toolsicon",
- ImageIO.read(new URL(crafter.baseURL
- + "/images/tools.png")));
- crafter.log("Loaded tools icon in "
- + PaintFormatter.getFormattedTime(System
- .currentTimeMillis() - before));
- } catch (Exception e) {
- crafter.log("Failed to load images");
- }
- }
- }
- /**
- * Gets the grandExchange singleton for reference by other classes
- *
- * @return GrandExchange reference
- */
- public GrandExchange getGE() {
- return grandExchange;
- }
- /**
- * gets the item price based on class. Works with all versions of
- * grandExchange.class
- *
- * @param item
- * the GEItem to get the price from
- * @return int the price
- *
- * @author Equinox_
- */
- public static int getItemPrice(GEItem item) {
- for (Method m : item.getClass().getMethods())
- if (m.getName().equals("getGuidePrice")
- || m.getName().equals("getMinPrice"))
- try {
- return (Integer) (m.invoke(item));
- } catch (Exception e) {
- }
- return 0;
- }
- /**
- * Modified Copy of DrawMouse
- */
- public class ModifiedDrawMouse {
- private MouseTrailing mouseTrailing = new MouseTrailing();
- private ArrayList<Mouses> Click = new ArrayList<Mouses>();
- private long clickLifeTime = 1500;
- public void onRepaint(final Graphics render) {
- if (mouse != null) {
- Point Location = mouse.getLocation();
- if (mouse.isPressed())
- if (Click.size() <= 5)
- Click.add(new Mouses(System.currentTimeMillis(),
- Location));
- mouseTrailing.draw((Graphics2D) render, Color.WHITE);
- render.setColor(Color.GREEN);
- render.drawLine(Location.x - 5, Location.y, Location.x + 5,
- Location.y);
- render.drawLine(Location.x, Location.y - 5, Location.x,
- Location.y + 5);
- if (Click.size() > 1)
- for (Mouses click : Click) {
- if (mouse.isPressed())
- if (Click.size() <= 10)
- Click.add(new Mouses(
- System.currentTimeMillis(), Location));
- float i = ((float) (click.getTime() + clickLifeTime - System
- .currentTimeMillis()) / (float) clickLifeTime) + 0.25f;
- if (i > 0) {
- render.setColor(new Color(1, 0, 0, i > 1 ? 1 : i));
- render.drawLine(click.getLocation().x - 5,
- click.getLocation().y,
- click.getLocation().x + 5,
- click.getLocation().y);
- render.drawLine(click.getLocation().x,
- click.getLocation().y - 5,
- click.getLocation().x,
- click.getLocation().y + 5);
- } else if (System.currentTimeMillis() - click.getTime() >= 1000) {
- Click.remove(click);
- }
- }
- }
- }
- /**
- * @author Baheer (Doout).
- */
- public class MouseTrailing {
- private int LifeTime = 1500;
- private ArrayList<Mouses> Info = new ArrayList<Mouses>();
- private void getLocation() {
- Point m = mouse.getLocation();
- if (Add(m)) {
- Info.add(new Mouses(System.currentTimeMillis(), m));
- }
- }
- public boolean Add(Point p) {
- for (Mouses Trailing : Info)
- if (Trailing.getLocation().equals(p))
- return false;
- return true;
- }
- public void draw(Graphics2D g, Color c) {
- getLocation();
- if (Info.size() > 1)
- for (int t = 1; t < Info.size(); t++) {
- Mouses Trailing1 = Info.get(t);
- Mouses Trailing2 = Info.get(t - 1);
- float i = (float) (Trailing1.getTime() + LifeTime - System
- .currentTimeMillis()) / (float) LifeTime;
- if (i > 0) {
- g.setColor(new Color(c.getRed() / 255f, c
- .getGreen() / 255f, c.getBlue() / 255f, (c
- .getAlpha() / 255f) * i));
- g.drawLine(Trailing1.getLocation().x,
- Trailing1.getLocation().y,
- Trailing2.getLocation().x,
- Trailing2.getLocation().y);
- }
- }
- if (Info.size() > 1) {
- if (System.currentTimeMillis() > Info.get(0).getTime()
- + LifeTime) {
- Info.remove(0);
- }
- }
- }
- }
- private class Mouses {
- private long Time;
- private Point Location;
- public Mouses(long time, Point loc) {
- Time = time;
- Location = loc;
- }
- public long getTime() {
- return Time;
- }
- public Point getLocation() {
- return Location;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment