Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.text.DecimalFormat;
- import java.util.*;
- import java.util.List;
- import org.rsbot.event.events.MessageEvent;
- import org.rsbot.event.listeners.*;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.*;
- import org.rsbot.script.methods.Game.Tab;
- import org.rsbot.script.wrappers.*;
- import org.rsbot.script.wrappers.RSPath.TraversalOption;
- import org.rsbot.util.StringUtil;
- @ScriptManifest(authors = "Equinox_", keywords = { "Runecrafting", "Graahk",
- "Nature", "Karamja" }, name = "EquinoxGraahkCrafter", version = 1.42, description = "Nature Runecrafter with Graahks, pouches and more!")
- public class EquinoxGraahkCrafter extends Script implements MessageListener,
- PaintListener, MouseListener {
- // Variables
- public final static int NATURE_RUNE_ID = 561;
- 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 NATURE_PORTAL_ID = 2460;
- public final static int NATURE_ALTER_ID = 2486;
- public final static int AIR_RUNE_ID = 556;
- public final static int SPIRIT_GRAAHK_POUCH_ID = 12810;
- public final static int OBELISK_OBJ_ID = 29938;
- public final static int KINSHIP_TELEPORT_ANIM = 13652;
- public final static int[] GRAAHK_TELEPORT_ANIM = { 8939, 8941 };
- public final static int NPC_CONTACT_ANIM = 4413;
- public final static int BANKER_ID = 9710;
- public final static int CRAFT_RUNE_ANIM = 791;
- public final static int OMNI_TIARA = 13655;
- public final static int OMNI_STAFF = 13642;
- public final static RSTile[][] DAEMONHEIM_MESH = {
- { new RSTile(3453, 3897), new RSTile(3447, 3897) },
- { new RSTile(3448, 3702), new RSTile(3451, 3702) },
- { new RSTile(3451, 3707), new RSTile(3448, 3707) },
- { new RSTile(3448, 3711), new RSTile(3451, 3711) },
- { new RSTile(3451, 3716), new RSTile(3448, 3716) },
- { new RSTile(3448, 3719), new RSTile(3449, 3719),
- new RSTile(3449, 3718) } };
- public final static RSTile[][] KARAMJA_MESH = {
- { new RSTile(2793, 3009), new RSTile(2793, 3009) },
- { new RSTile(2798, 3009), new RSTile(2796, 3008) },
- { new RSTile(2808, 3007), new RSTile(2809, 3013) },
- { new RSTile(2815, 3013), new RSTile(2815, 3007) },
- { new RSTile(2822, 3008), new RSTile(2823, 3013) },
- { new RSTile(2829, 3016), new RSTile(2834, 3009) },
- { new RSTile(2838, 3017), new RSTile(2831, 3021) },
- { new RSTile(2837, 3028), new RSTile(2842, 3025) },
- { new RSTile(2847, 3025), new RSTile(2847, 3030) },
- { new RSTile(2852, 3030), new RSTile(2852, 3025) },
- { new RSTile(2855, 3027), new RSTile(2856, 3031) },
- { new RSTile(2861, 3029), new RSTile(2859, 3024) },
- { new RSTile(2864, 3017), new RSTile(2864, 3023) },
- { new RSTile(2869, 3021), new RSTile(2866, 3021),
- new RSTile(2866, 3017), new RSTile(2869, 3017) } };
- 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 String serverMsg = "";
- public HashMap<PouchType, Boolean> pouches = new HashMap<PouchType, Boolean>();
- State currentState = State.LOST;
- public MeshPath karamjaMeshPath;
- public MeshPath daemonheimMeshPath;
- public NPCContact npcContact = new NPCContact();
- public OptionsClass Options = new OptionsClass();
- public SkillPaint skillPaint;
- public int natsMade = 0;
- public int essUsed = 0;
- public int essPrice = 0, natPrice = 0;
- public static class OptionsClass {
- public Range mouseSpeed = new Range(4, 6);
- public boolean hasAirStaff = true;
- public Range summoningRecharge = new Range(20, 25);
- public Range walkingDistance = new Range(4, 6);
- public StaffTiara stafftiara;
- public enum StaffTiara {
- OMNI_STAFF(Equipment.WEAPON, "staff", "omni"), OMNI_TIARA(
- Equipment.HELMET, "tiara", "omni"), NATURE_TIARA(
- Equipment.HELMET, "tiara", "nature");
- private String d1;
- private String d2;
- private int slot;
- private StaffTiara(int slot, String d1, String d2) {
- this.d1 = d1;
- this.d2 = d2;
- this.slot = slot;
- }
- public int getSlot() {
- return slot;
- }
- public boolean isValid(RSItem itm) {
- return itm != null
- && itm.getName() != null
- && itm.getName().toLowerCase()
- .contains(d1.toLowerCase())
- && itm.getName().toLowerCase()
- .contains(d2.toLowerCase());
- }
- public static StaffTiara getCurrent(Equipment e) {
- for (StaffTiara t : values()) {
- if (t.isValid(e.getItem(t.getSlot()))) {
- return t;
- }
- }
- return null;
- }
- public String properName() {
- String name = name().replace("_", " ");
- return name.substring(0, 1).toUpperCase()
- + name.substring(1).toLowerCase();
- }
- }
- }
- public enum State {
- TELE_TO_BANK, TRAVERSE_DAEMONHEIM, BANK_WITHDRAW_GRAAHK, SUMMON_GRAAHK, DISMISS_WRONG_FAMILIAR, BANK_WITHDRAW_ESS, BANK_DEPOSIT_STUFF, FILL_POUCH, NPC_CONTACT, TELE_TO_KARAMJA, TRAVERSE_KARAMJA, CHARGE_SUMMONING, ENTER_PORTAL, CRAFT_ESSENCE, EMPTY_POUCH, NEAR_BANK, LOST
- }
- 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;
- }
- }
- RSArea NATURE_ALTER = new RSArea(2390, 4835, 2410, 4850);
- RSArea KARAMJA_TRAVEL = new RSArea(2784, 2998, 2872, 3040);
- RSArea DAEMONHEIM_TRAVEL = new RSArea(3435, 3680, 3456, 3726);
- public State getState() throws Exception {
- if (objects.getNearest(OBELISK_OBJ_ID) != null
- && summoning.getSummoningPoints() <= Options.summoningRecharge
- .random()
- && calc.tileOnMap(objects.getNearest(OBELISK_OBJ_ID)
- .getLocation())) {
- return State.CHARGE_SUMMONING;
- }
- if (objects.getNearest(NATURE_PORTAL_ID) != null
- && calc.tileOnMap(objects.getNearest(NATURE_PORTAL_ID)
- .getLocation())) {
- return State.ENTER_PORTAL;
- }
- if (objects.getNearest(NATURE_ALTER_ID) != null
- && calc.tileOnMap(objects.getNearest(NATURE_ALTER_ID)
- .getLocation())) {
- if ((inventory.isFull() || !pouches.containsValue(true))
- && inventory.contains(PURE_ESS_ID))
- return State.CRAFT_ESSENCE;
- else if (pouches.containsValue(true))
- return State.EMPTY_POUCH;
- else
- return State.TELE_TO_BANK;
- }
- if (npcs.getNearest(Bank.BANKERS) != null) {
- if (npcs.getNearest(Bank.BANKERS) != null
- && (npcs.getNearest(Bank.BANKERS).isOnScreen() || getMyPlayer()
- .getLocation()
- .equals(npcs.getNearest(Bank.BANKERS).getLocation()))) {
- if (summoning.isFamiliarSummoned()) {
- if (summoning.getFamiliar() != null)
- if (!summoning.getFamiliar().getName().toLowerCase()
- .contains("graahk"))
- return State.DISMISS_WRONG_FAMILIAR;
- } else if (!summoning.isFamiliarSummoned()) {
- if (!inventory.contains(SPIRIT_GRAAHK_POUCH_ID))
- return State.BANK_WITHDRAW_GRAAHK;
- else
- return State.SUMMON_GRAAHK;
- }
- if (shouldRepairPouches())
- return State.NPC_CONTACT;
- else if (inventory.getCount(Pouch.ALL)
- + inventory.getCount(PURE_ESS_ID) != inventory
- .getCount())
- return State.BANK_DEPOSIT_STUFF;
- else if (inventory.contains(PURE_ESS_ID)
- && pouches.containsValue(false))
- return State.FILL_POUCH;
- else if (!inventory.isFull())
- return State.BANK_WITHDRAW_ESS;
- } else {
- return State.NEAR_BANK;
- }
- }
- if (KARAMJA_TRAVEL.contains(getMyPlayer().getLocation())) {
- return State.TRAVERSE_KARAMJA;
- }
- if (inventory.isFull() && inventory.contains(PURE_ESS_ID)
- && !inventory.contains(NATURE_RUNE_ID)
- && !pouches.containsKey(false)) {
- return State.TELE_TO_KARAMJA;
- }
- if (DAEMONHEIM_TRAVEL.contains(getMyPlayer().getLocation())) {
- return State.TRAVERSE_DAEMONHEIM;
- }
- return State.LOST;
- }
- @Override
- public void messageReceived(MessageEvent msg) {
- if (msg.getID() == MessageEvent.MESSAGE_ACTION
- || msg.getID() == MessageEvent.MESSAGE_SERVER) {
- serverMsg = msg.getMessage().toLowerCase();
- }
- }
- public void teleportToKaramja() throws Exception {
- daemonheimMeshPath.clearPath();
- if (summoning.doAction("Interact")) {
- for (byte b = 0; b < 15; b++)
- if (interfaces.getComponent(228, 3) != null
- && interfaces.getComponent(228, 3).isValid())
- break;
- else
- sleep(100, 125);
- if (interfaces.getComponent(228, 3).doClick()) {
- sleep(1000, 1250);
- for (byte b = 0; b < 15
- && players.getMyPlayer().getAnimation() == GRAAHK_TELEPORT_ANIM[0]; b++)
- sleep(125, 175);
- return;
- }
- }
- }
- public void teleportToDaemonheim() throws Exception {
- if (getMyPlayer().getAnimation() != KINSHIP_TELEPORT_ANIM)
- for (byte b = 0; b < 5; b++)
- if (equipment.getItem(Equipment.RING) != null) {
- RSComponent comp = equipment.getItem(Equipment.RING)
- .getComponent();
- Point pt = comp.getCenter();
- pt.translate(random(-2, 3), random(-2, 3));
- mouse.click(pt, false);
- sleep(500, 750);
- if (menu.doAction("Teleport")) {
- for (byte b2 = 0; b2 < 25; b2++)
- if (getMyPlayer().getAnimation() != KINSHIP_TELEPORT_ANIM)
- sleep(100, 115);
- else {
- // Paint.runsMade++;
- return;
- }
- }
- } else {
- log.severe("Somehow we are missing a ring :(");
- stopScript(true);
- }
- }
- public boolean shouldRepairPouches() {
- int degraded = inventory.getCount(Pouch.ALL_DEGRADED);
- return degraded > 0;
- }
- public boolean openBank() {
- if (bank.isOpen())
- return true;
- RSNPC npc = npcs.getNearest(BANKER_ID);
- if (npc != null)
- npc.interact("Bank F");
- sleep(750, 1000);
- return bank.isOpen();
- }
- public void deposit_non_necessities() {
- if (!openBank())
- return;
- if (inventory.getCount(Pouch.ALL) > 0)
- bank.depositAllExcept(Pouch.ALL);
- else
- bank.depositAll();
- }
- public boolean withdrawItem(int id, int amount) {
- if (!openBank())
- return false;
- boolean returns = bank.withdraw(id, amount);
- sleep(500, 750);
- return returns;
- }
- public boolean withdrawEss() {
- return withdrawItem(PURE_ESS_ID, 0);
- }
- public int getCountBankInv(int... id) {
- int count = 0;
- if (bank.isOpen())
- count += bank.getCount(id);
- count += inventory.getCount(true, id);
- return count;
- }
- public void emptyPouches() {
- for (PouchType pType : pouches.keySet()) {
- if (inventory.isFull())
- break;
- if (inventory.containsOneOf(pType.ids)) {
- if (pouches.get(pType)) {
- RSItem item = inventory.getItem(pType.ids);
- if (item != null) {
- // int invCount = inventory.getCount();
- if (item.interact("Empty"))
- 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, false);
- serverMsg = "";
- sleep(100, 150);
- break;
- }
- sleep(100, 150);
- }
- }
- }
- } else {
- pouches.remove(pType);
- }
- }
- }
- public void fillPouches() {
- for (PouchType pType : pouches.keySet()) {
- if (!inventory.contains(PURE_ESS_ID))
- break;
- if (inventory.containsOneOf(pType.ids)) {
- if (!pouches.get(pType)) {
- RSItem item = inventory.getItem(pType.ids);
- if (item != null) {
- if (item.interact("Fill")) {
- for (int i = 0; i < POUCH_TRIES; i++) {
- if (serverMsg != null)
- if (serverMsg.contains("pouch is ful")) {
- pouches.put(pType, true);
- serverMsg = "";
- break;
- }
- sleep(80, 120);
- }
- }
- }
- }
- } else {
- pouches.remove(pType);
- }
- }
- }
- public void updatePouches() {
- for (PouchType pouch : PouchType.values())
- if (inventory.containsOneOf(pouch.ids)) {
- if (!pouches.containsKey(pouch))
- pouches.put(pouch, false);
- } else if (pouches.containsKey(pouch))
- pouches.remove(pouch);
- }
- private void loadPrices() {
- log.info("Loading prices...");
- this.essPrice = grandExchange.lookup(PURE_ESS_ID).getGuidePrice();
- log.info("Essence price: " + this.essPrice);
- this.natPrice = grandExchange.lookup(NATURE_RUNE_ID).getGuidePrice();
- log.info("Nature rune price: " + this.natPrice);
- }
- @Override
- public boolean onStart() {
- new Thread() {
- @Override
- public void run() {
- loadPrices();
- }
- }.start();
- karamjaMeshPath = new MeshPath(walking, calc, players, KARAMJA_MESH,
- Options.walkingDistance);
- daemonheimMeshPath = new MeshPath(walking, calc, players,
- DAEMONHEIM_MESH, Options.walkingDistance);
- skillPaint = new SkillPaint(skills, Skills.RUNECRAFTING);
- updatePouches();
- mouse.setSpeed(Options.mouseSpeed.random());
- RSItem wep = equipment.getItem(Equipment.WEAPON);
- if (wep != null) {
- Options.hasAirStaff = (wep.getName().toLowerCase()
- .contains("staff") && wep.getName().toLowerCase()
- .contains("air"));
- }
- RSItem ring = equipment.getItem(Equipment.RING);
- if (ring == null || ring.getName() == null
- || !ring.getName().toLowerCase().contains("ring")
- || !ring.getName().toLowerCase().contains("kinship")) {
- log.severe("You must be weilding a ring of kinship!");
- return false;
- }
- Options.stafftiara = OptionsClass.StaffTiara.getCurrent(equipment);
- if (Options.stafftiara == null) {
- log.severe("You must have a Nature Tiara, Omni Tiara, or Omni Staff equipped!");
- return false;
- }
- camera.setPitch(random(0, 10));
- log.info("Script initiation successful!");
- log.info("--Setup--");
- log.info("Air staff: " + (Options.hasAirStaff ? "Yes" : "No"));
- log.info("Walking range: " + Options.walkingDistance.toString());
- log.info("Summoning recharge: " + Options.summoningRecharge.toString());
- log.info("Alter Access Item: " + Options.stafftiara.properName());
- return true;
- }
- @Override
- public int loop() {
- mouse.setSpeed(Options.mouseSpeed.random());
- int essPre = inventory.getCount(true, PURE_ESS_ID);
- int natPre = inventory.getCount(true, NATURE_RUNE_ID);
- try {
- currentState = getState();
- switch (currentState) {
- case NEAR_BANK:
- RSNPC banker = npcs.getNearest(Bank.BANKERS);
- 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_STUFF:
- this.deposit_non_necessities();
- break;
- case BANK_WITHDRAW_ESS:
- this.withdrawEss();
- break;
- case BANK_WITHDRAW_GRAAHK:
- if (openBank())
- for (byte b = 0; b < 5 && inventory.contains(PURE_ESS_ID); b++) {
- bank.deposit(PURE_ESS_ID, 1);
- sleep(450, 750);
- }
- withdrawItem(SPIRIT_GRAAHK_POUCH_ID, 1);
- break;
- case SUMMON_GRAAHK:
- RSItem p = inventory.getItem(SPIRIT_GRAAHK_POUCH_ID);
- if (p != null) {
- for (byte b = 0; b < 10 && bank.isOpen(); b++) {
- bank.close();
- sleep(500, 750);
- }
- if (summoning.getSummoningPoints() <= 0) {
- log.severe("Out of summoning points :'(");
- stopScript(true);
- } else if (!bank.isOpen())
- p.interact("Summon");
- }
- break;
- case CHARGE_SUMMONING:
- RSObject obby = objects.getNearest(OBELISK_OBJ_ID);
- if (calc.tileOnMap(obby.getLocation())) {
- if (calc.distanceTo(obby) > 5)
- walking.walkTileMM(obby.getLocation());
- if (!obby.isOnScreen())
- camera.turnTo(obby);
- sleep(125, 175);
- obby.doClick();
- sleep(250, 500);
- }
- break;
- case CRAFT_ESSENCE:
- RSObject alter = objects.getNearest(NATURE_ALTER_ID);
- if (!alter.isOnScreen() && !getMyPlayer().isMoving())
- walking.walkTileMM(alter.getArea().getNearestTile(
- getMyPlayer().getLocation()));
- if (!alter.isOnScreen())
- camera.turnTo(alter);
- alter.doClick();
- for (byte b = 0; b < 25
- && (getMyPlayer().getAnimation() == CRAFT_RUNE_ANIM || getMyPlayer()
- .isMoving()); b++)
- sleep(100, 125);
- break;
- case DISMISS_WRONG_FAMILIAR:
- this.summoning.doDismiss();
- sleep(500, 600);
- break;
- case EMPTY_POUCH:
- emptyPouches();
- break;
- case ENTER_PORTAL:
- RSObject obj = objects.getNearest(NATURE_PORTAL_ID);
- if (obj != null) {
- if (!obj.isOnScreen()) {
- walking.walkTileMM(obj.getArea().getNearestTile(
- getMyPlayer().getLocation()));
- camera.turnTo(obj);
- }
- sleep(750);
- if (obj.isOnScreen()) {
- obj.doClick();
- for (byte b = 0; b < 10
- && objects.getNearest(NATURE_ALTER_ID) == null; b++)
- sleep(80, 120);
- karamjaMeshPath.clearPath();
- }
- }
- break;
- case FILL_POUCH:
- fillPouches();
- break;
- case NPC_CONTACT:
- npcContact.main();
- break;
- case TELE_TO_BANK:
- teleportToDaemonheim();
- break;
- case TELE_TO_KARAMJA:
- this.teleportToKaramja();
- break;
- case TRAVERSE_DAEMONHEIM:
- if (!daemonheimMeshPath.hasPath())
- daemonheimMeshPath.findPath(MeshPath.MeshPathType.FULL);
- daemonheimMeshPath.traverse();
- break;
- case TRAVERSE_KARAMJA:
- if (!karamjaMeshPath.hasPath())
- karamjaMeshPath
- .findPath(MeshPath.MeshPathType.WEIGHT_CENTER);
- karamjaMeshPath.traverse();
- break;
- }
- } catch (Exception e) {
- }
- if (walking.getEnergy() > 50 && !walking.isRunEnabled())
- walking.setRun(true);
- int essUsed = essPre - inventory.getCount(true, PURE_ESS_ID);
- int natsMade = inventory.getCount(true, NATURE_RUNE_ID) - natPre;
- if (natsMade > 0)
- this.natsMade += natsMade;
- if (essUsed > 0)
- this.essUsed += essUsed;
- return random(100, 125);
- }
- @Override
- public void onFinish() {
- }
- @Override
- public void onRepaint(Graphics g1) {
- Graphics2D g = (Graphics2D) g1;
- try {
- karamjaMeshPath.paintAll(g);
- daemonheimMeshPath.paintAll(g);
- paintPouches(g);
- long elapsed = System.currentTimeMillis()
- - skillPaint.tracker.start;
- int natsHr = (int) (natsMade * 3600000l / elapsed);
- int profit = (natsMade * natPrice) - (essUsed * essPrice);
- int profitHr = (int) (profit * 3600000l / elapsed);
- StringUtil.drawLine(g1, 0,
- "Runtime: " + PaintFormatter.getFormattedTime(elapsed));
- StringUtil.drawLine(g1, 1, "Nats Made: " + natsMade + "@" + natsHr
- + "/hr");
- StringUtil.drawLine(g1, 2, "Profit: " + profit + "@" + profitHr
- + "/hr");
- skillPaint.drawLine(g1, 3);
- } catch (Exception e) {
- }
- }
- public void paintPouches(Graphics g) {
- for (PouchType pouch : pouches.keySet()) {
- if (game.getTab().equals(Tab.INVENTORY)) {
- RSItem item = inventory.getItem(pouch.ids);
- if (item != null) {
- if (!pouches.get(pouch))
- 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());
- for (int id : Pouch.ALL_DEGRADED)
- if (item.getID() == id) {
- g.setColor(Color.WHITE);
- g.drawString("Degraded", c.getAbsoluteX(),
- c.getAbsoluteY() + c.getHeight());
- break;
- }
- }
- }
- }
- }
- @Override
- public void mouseClicked(MouseEvent arg0) {
- skillPaint.mouseClicked(arg0);
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- }
- enum npcContactState {
- CAST, SCROLL, SELECT, WAIT, CONTINUE, MENU, WITHDRAW_ASTRAL, WITHDRAW_COSMIC, WITHDRAW_AIR, OUT_OF_RUNES
- }
- 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" };
- 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;
- }
- 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;
- }
- boolean invBank(int id) {
- return bank.getCount(id) > 0 || inventory.containsOneOf(id);
- }
- int invBankCount(int id) {
- return bank.getCount(id) + inventory.getCount(true, id);
- }
- public void main() {
- switch (currentState = getState()) {
- case WITHDRAW_ASTRAL:
- withdrawItem(ASTRAL_RUNE_ID, 1);
- if (!invBank(ASTRAL_RUNE_ID))
- removePouches();
- sleep(500, 650);
- break;
- case WITHDRAW_COSMIC:
- withdrawItem(COSMIC_RUNE_ID, 1);
- if (!invBank(COSMIC_RUNE_ID))
- removePouches();
- sleep(500, 650);
- break;
- case WITHDRAW_AIR:
- if (!inventory.contains(AIR_RUNE_ID))
- withdrawItem(AIR_RUNE_ID, 1);
- withdrawItem(AIR_RUNE_ID, 1);
- if (invBankCount(AIR_RUNE_ID) < 2)
- removePouches();
- sleep(500, 650);
- break;
- case CAST:
- for (byte b = 0; b < 10 && bank.isOpen(); b++) {
- bank.close();
- sleep(500, 750);
- }
- if (!bank.isOpen() && !game.getTab().equals(Tab.MAGIC))
- game.openTab(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);
- sleep(750, 1250);
- break;
- case SELECT:
- interfaces.get(MAIN_FRAME).getComponent(NPCS_CONTAINER)
- .getComponent(NPC_TO_SELECT).doClick();
- sleep(750, 1250);
- break;
- case WAIT:
- sleep(500, 600);
- break;
- case CONTINUE:
- if (interfaces.canContinue())
- interfaces.clickContinue();
- sleep(500, 650);
- 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)) {
- bank.deposit(id, 1);
- sleep(500, 600);
- }
- updatePouches();
- }
- }
- public static class MeshPath {
- public static final Color BLOCK_PATH_COLOR = new Color(0f, 1f, 0f, 1f);
- public static final Color MESH_BORDER = new Color(0.75f, 0.75f, 0.75f,
- 0.75f);
- public static final Color MESH_FILL = new Color(0.5f, 0.5f, 0.5f, 0.75f);
- public static final Color SMOOTH_PATH_COLOR = new Color(0f, 0f, 1f, 1f);
- private List<RSTile> blockPath = new ArrayList<RSTile>();
- private final Calculations calc;
- private boolean end;
- private List<RSTile[]> mesh = new ArrayList<RSTile[]>();
- private final Players players;
- private List<RSTile> smoothPath = new ArrayList<RSTile>();
- private final Walking walking;
- private final Range walkingDistance;
- public MeshPath(Walking walking, Calculations calc, Players players) {
- this(walking, calc, players, new Range(7, 9));
- }
- public MeshPath(Walking walking, Calculations calc, Players players,
- Range walkingDistance) {
- this.walking = walking;
- this.calc = calc;
- this.players = players;
- this.walkingDistance = walkingDistance;
- }
- public MeshPath(Walking walking, Calculations calc, Players players,
- RSTile[][] mesh) {
- this(walking, calc, players);
- setMesh(mesh);
- }
- public MeshPath(Walking walking, Calculations calc, Players players,
- RSTile[][] mesh, Range walkingDistance) {
- this(walking, calc, players, walkingDistance);
- setMesh(mesh);
- }
- public void addLine(RSTile... tiles) {
- if (mesh.size() == 0) {
- mesh.add(tiles);
- return;
- }
- RSTile first = tiles[0];
- RSTile last = tiles[tiles.length - 1];
- RSTile[] oLine = mesh.get(mesh.size() - 1);
- RSTile oFirst = oLine[0];
- RSTile oLast = oLine[oLine.length - 1];
- double straight = calc.distanceBetween(first, oFirst)
- + calc.distanceBetween(last, oLast);
- double crossed = calc.distanceBetween(first, oLast)
- + calc.distanceBetween(last, oFirst);
- if (straight > crossed) {
- mesh.add(tiles);
- return;
- } else {
- RSTile[] reversed = new RSTile[tiles.length];
- for (int i = 0; i < tiles.length; i++)
- reversed[i] = tiles[tiles.length - 1 - i];
- mesh.add(reversed);
- return;
- }
- }
- public void addMesh(RSTile[][] mesh) {
- for (RSTile[] line : mesh)
- addLine(line);
- }
- public void clearPath() {
- blockPath.clear();
- smoothPath.clear();
- }
- public void findPath() {
- findPath(MeshPathType.WEIGHT_CENTER);
- }
- public void findPath(MeshPathType placement) {
- findPath(placement, 0, mesh.size() - 1);
- }
- public void findPath(MeshPathType placement, int start, int end) {
- blockPath.clear();
- for (int i = start; i <= end; i++)
- blockPath.add(getTileOnLine(placement, mesh.get(i)));
- smoothPath = smoothPath(blockPath);
- }
- public RSTile getEnd() {
- if (smoothPath.size() > 0)
- return smoothPath.get(smoothPath.size() - 1);
- else
- return null;
- }
- public RSTile getNext() {
- if (smoothPath.size() > 0)
- for (int i = smoothPath.size() - 1; i >= 0; i--)
- if (calc.tileOnMap(smoothPath.get(i)))
- return smoothPath.get(i);
- return null;
- }
- public RSTile getStart() {
- if (smoothPath.size() > 0)
- return smoothPath.get(0);
- else
- return null;
- }
- 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)
- for (RSTile t : lineA) {
- double dist = calc.distanceBetween(t, tile);
- if (dist < bestDist) {
- nearest = new RSTile(t.getX(), t.getY());
- bestDist = Double.valueOf(dist);
- }
- }
- if (lineB != null)
- for (RSTile t : lineB) {
- double dist = calc.distanceBetween(t, tile);
- if (dist < bestDist) {
- nearest = new RSTile(t.getX(), t.getY());
- bestDist = Double.valueOf(dist);
- }
- }
- }
- }
- return nearest;
- }
- public RSTile getTileOnLine(MeshPathType placement, RSTile... line) {
- List<RSTile> tiles = getTilesOnLines(line);
- int index = 0;
- switch (placement) {
- case ALL_CENTER:
- index = new Range((int) (tiles.size() * .25d),
- (int) (tiles.size() * 0.75d)).random();
- break;
- case FULL:
- index = new Range(0, tiles.size()).random();
- break;
- case WEIGHT_CENTER:
- index = new Range(0, tiles.size()).random();
- 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;
- }
- public RSTile getTileOnLine(RSTile... line) {
- return getTileOnLine(MeshPathType.WEIGHT_CENTER, line);
- }
- public RSTile[] getTilePath() {
- RSTile[] tiles = new RSTile[smoothPath.size()];
- for (int i = 0; i < tiles.length; i++)
- tiles[i] = new RSTile(smoothPath.get(i).getX(), smoothPath.get(
- i).getY());
- return tiles;
- }
- 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;
- }
- 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;
- }
- public boolean hasPath() {
- return smoothPath.size() > 0;
- }
- 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;
- }
- public boolean isValid() {
- return smoothPath.size() > 0 && getNext() != null
- && !players.getMyPlayer().getLocation().equals(getEnd());
- }
- public int meshSize() {
- return mesh.size();
- }
- public void paintAll(Graphics2D g) {
- paintMesh(g);
- paintBlockPath(g);
- paintSmoothPath(g);
- }
- public void paintBlockPath(Graphics2D g) {
- if (blockPath.size() > 1) {
- g.setColor(BLOCK_PATH_COLOR);
- Point a = null;
- for (RSTile t : blockPath) {
- Point b = calc.tileToMinimap(t);
- if (b.x > 0 && b.y > 0)
- g.fillOval(b.x - 2, b.y - 2, 5, 5);
- if (a != null && a.x > 0 && a.y > 0 && b.x > 0 && b.y > 0)
- g.drawLine(a.x, a.y, b.x, b.y);
- a = b;
- }
- }
- }
- public void paintMesh(Graphics2D g) {
- if (mesh.size() > 1) {
- Point[] oldLine = null;
- for (int i = 0; i < mesh.size(); i++) {
- RSTile[] lineB = mesh.get(i);
- Point[] thisLine = new Point[lineB.length];
- Polygon poly = new Polygon();
- boolean onMap = true;
- for (int tile = 0; tile < thisLine.length; tile++) {
- Point p = calc.tileToMinimap(lineB[tile]);
- thisLine[tile] = p;
- poly.addPoint(p.x, p.y);
- if (p.x == -1 || p.y == -1)
- onMap = false;
- }
- if (oldLine != null) {
- for (Point p : oldLine) {
- poly.addPoint(p.x, p.y);
- if (p.x == -1 || p.y == -1)
- onMap = false;
- }
- if (poly.npoints >= 2 && onMap) {
- g.setColor(MESH_BORDER);
- g.draw(poly);
- g.setColor(MESH_FILL);
- g.fill(poly);
- }
- }
- oldLine = thisLine;
- }
- }
- }
- public void paintSmoothPath(Graphics2D g) {
- if (smoothPath.size() > 1) {
- g.setColor(SMOOTH_PATH_COLOR);
- Point a = null;
- for (RSTile t : smoothPath) {
- Point b = calc.tileToMinimap(t);
- if (b.x > 0 && b.y > 0)
- g.fillOval(b.x - 2, b.y - 2, 5, 5);
- if (a != null && a.x > 0 && a.y > 0 && b.x > 0 && b.y > 0)
- g.drawLine(a.x, a.y, b.x, b.y);
- a = b;
- }
- }
- }
- public MeshPath reverse() {
- MeshPath m = new MeshPath(walking, calc, players);
- for (int i = mesh.size() - 1; i >= 0; i--) {
- m.addLine(blockPath.get(i));
- }
- return m;
- }
- public void setMesh(RSTile[][] mesh) {
- this.mesh.clear();
- addMesh(mesh);
- }
- public List<RSTile> smoothPath(List<RSTile> path) {
- List<RSTile> smoothed = new ArrayList<RSTile>();
- if (path.size() >= 3) {
- for (int i = 0; i < path.size(); i++) {
- if (i + 2 < path.size()) {
- RSTile tile1 = path.get(i);
- RSTile tile2 = path.get(i + 1);
- RSTile tile3 = path.get(i + 2);
- if (i == 0)
- smoothed.add(tile1);
- double x2, y2;
- double t = 0.5d;
- x2 = (tile1.getX() + t
- * (-tile1.getX() * 3 + t
- * (3 * tile1.getX() - tile1.getX() * t)))
- + t
- * (3 * tile2.getX() + t
- * (-6 * tile2.getX() + tile2.getX() * 3
- * t))
- + t
- * t
- * (tile2.getX() * 3 - tile2.getX() * 3 * t)
- + tile3.getX() * t * t * t;
- y2 = (tile1.getY() + t
- * (-tile1.getY() * 3 + t
- * (3 * tile1.getY() - tile1.getY() * t)))
- + t
- * (3 * tile2.getY() + t
- * (-6 * tile2.getY() + tile2.getY() * 3
- * t))
- + t
- * t
- * (tile2.getY() * 3 - tile2.getY() * 3 * t)
- + tile3.getY() * t * t * t;
- smoothed.add(getTileInMesh(new RSTile((int) x2,
- (int) y2)));
- } else {
- smoothed.add(path.get(i));
- }
- }
- }
- return smoothed;
- }
- public boolean traverse() {
- return this.traverse(EnumSet.of(TraversalOption.HANDLE_RUN,
- TraversalOption.SPACE_ACTIONS));
- }
- public boolean traverse(EnumSet<TraversalOption> options) {
- RSTile next = getNext();
- if (next == null) {
- return false;
- }
- 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);
- }
- if (options.contains(TraversalOption.SPACE_ACTIONS)) {
- RSTile dest = walking.getDestination();
- if (dest != null
- && players.getMyPlayer().isMoving()
- && calc.distanceTo(dest) > 5
- && calc.distanceBetween(next, dest) < walkingDistance
- .random()) {
- return true;
- }
- }
- return walking.walkTileMM(next, 0, 0);
- }
- public int getNearestIndexTo(RSTile t) {
- int len = Integer.MAX_VALUE;
- int bestIndex = -1;
- if (hasPath())
- for (int i = 0; i < smoothPath.size(); i++)
- if (calc.distanceBetween(t, smoothPath.get(i)) < len) {
- bestIndex = i;
- len = calc.distanceTo(t);
- }
- return bestIndex;
- }
- public enum MeshPathType {
- ALL_CENTER, FULL, WEIGHT_CENTER
- }
- }
- public static class PaintFormatter {
- public static String getFormattedMoney(long money) {
- return new DecimalFormat("###,###,###,###,###,###").format(money);
- }
- public static String getFormattedTime(final long timeMillis) {
- return getFormattedTime(timeMillis, ":", false);
- }
- 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;
- }
- 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);
- }
- 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);
- }
- }
- private static class SkillPaint implements MouseListener, TextPaintListener {
- private int[] goalLevels;
- private Map<Integer, Rectangle> goalMap = new HashMap<Integer, Rectangle>();
- private Rectangle resetTracker = null;
- private int[] skillIDs;
- private Skills skills;
- private SkillTracker tracker;
- public SkillPaint(Skills skills, int... skillIDs) {
- this.skills = skills;
- this.skillIDs = skillIDs;
- this.tracker = new SkillTracker(skills);
- goalLevels = new int[Skills.SKILL_NAMES.length];
- }
- @Override
- public int drawLine(Graphics render, int line) {
- StringUtil.drawLine(render, line, "Reset Tracker");
- final FontMetrics metrics = render.getFontMetrics();
- final int height = metrics.getHeight() + 4;
- resetTracker = render.getFontMetrics()
- .getStringBounds("Reset Tracker", render).getBounds();
- resetTracker.x = 7;
- resetTracker.y = line * height + 15 + 19;
- line++;
- if (skillIDs.length > 0) {
- for (int skill : skillIDs) {
- if (skills.getCurrentExp(skill) == -1)
- continue;
- if (tracker.hasRecentlyTrained(skill)) {
- drawSkillLine(line, skill, render);
- line++;
- } else {
- goalMap.remove(skill);
- }
- }
- } else {
- for (int skill = 0; skill < Skills.SKILL_NAMES.length; skill++) {
- if (skills.getCurrentExp(skill) == -1)
- continue;
- if (tracker.hasRecentlyTrained(skill)) {
- drawSkillLine(line, skill, render);
- line++;
- } else {
- goalMap.remove(skill);
- }
- }
- }
- return line;
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- for (Integer skill : goalMap.keySet()) {
- Rectangle r = goalMap.get(skill);
- if (r.contains(e.getPoint())) {
- int cLvl = goalLevels[skill.intValue()];
- if (e.getPoint().x < r.x + (r.width / 2)) {
- cLvl -= 1;
- } else {
- cLvl += 1;
- }
- if (cLvl > tracker.getCurrentLevel(skill)
- && cLvl <= tracker.getMaxLevel(skill)) {
- goalLevels[skill.intValue()] = cLvl;
- return;
- }
- }
- }
- if (resetTracker != null && resetTracker.contains(e.getPoint())) {
- this.tracker = new SkillTracker(skills);
- goalLevels = new int[Skills.SKILL_NAMES.length];
- }
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- }
- private void drawSkillLine(int row, int skill, Graphics render) {
- final String skillName = PaintFormatter
- .properCaseAll(Skills.SKILL_NAMES[skill]);
- if (goalLevels[skill] <= tracker.getCurrentLevel(skill))
- goalLevels[skill] = tracker.getCurrentLevel(skill) + 1;
- int goalLevel = goalLevels[skill];
- final String ttg = PaintFormatter.getFormattedTime(tracker
- .getMillisToLevel(skill, goalLevel));
- final String perHour = PaintFormatter
- .getFormattedMoney((int) tracker.getExpPerHour(skill))
- + " exp/hr";
- final String line = skillName + ": " + ttg + " 'till " + goalLevel
- + " @ " + perHour;
- final FontMetrics metrics = render.getFontMetrics();
- final int height = metrics.getHeight() + 4; // height + gap
- final int y = row * height + 15 + 19;
- final String buttons = (goalLevel > tracker.getCurrentLevel(skill) + 1 ? "<"
- : " ")
- + " "
- + (goalLevel < tracker.getMaxLevel(skill) ? ">" : " ");
- Rectangle rect = metrics.getStringBounds(buttons, render)
- .getBounds();
- rect = new Rectangle(6, y - rect.height + 3, rect.width + 2,
- rect.height - 2);
- this.goalMap.put(skill, rect);
- render.setColor(Color.GREEN);
- render.drawString(buttons, 7, y);
- render.drawString(line, 7 + rect.width + 5, y);
- }
- private static class SkillTracker {
- private long[] lastTrained;
- private int[] newExp;
- private Skills skills;
- private long start;
- private int[] startExp;
- public SkillTracker(Skills skills) {
- this.skills = skills;
- this.start = System.currentTimeMillis();
- this.startExp = new int[Skills.SKILL_NAMES.length];
- this.lastTrained = new long[Skills.SKILL_NAMES.length];
- this.newExp = new int[Skills.SKILL_NAMES.length];
- for (int i = 0; i < Skills.SKILL_NAMES.length; i++) {
- this.startExp[i] = skills.getCurrentExp(i);
- this.newExp[i] = this.startExp[i];
- }
- }
- public long getElapsedTime() {
- return System.currentTimeMillis() - start;
- }
- public int getExpGain(int skill) {
- return skills.getCurrentExp(skill) - startExp[skill];
- }
- public double getExpPerHour(int skill) {
- return getExpPerSecond(skill) * 3600d;
- }
- public double getExpPerMilli(int skill) {
- double gain = getExpGain(skill);
- double time = getElapsedTime();
- return gain / time;
- }
- public double getExpPerSecond(int skill) {
- return getExpPerMilli(skill) * 1000d;
- }
- public int getMaxLevel(int skill) {
- return skill == Skills.DUNGEONEERING ? 120 : 99;
- }
- public long getMillisToExp(int skill, int exp) {
- int expNeed = exp - skills.getCurrentExp(skill);
- if (expNeed <= 0 || getExpGain(skill) <= 0)
- return 0;
- return (long) (((double) expNeed) / getExpPerMilli(skill));
- }
- public long getMillisToLevel(int skill, int level) {
- if (level > getMaxLevel(skill) || level < 0)
- return 0;
- return getMillisToExp(skill, Skills.XP_TABLE[level]);
- }
- public boolean hasRecentlyTrained(int skill) {
- int cExp = skills.getCurrentExp(skill);
- if (newExp[skill] < cExp) {
- lastTrained[skill] = System.currentTimeMillis();
- }
- newExp[skill] = cExp;
- return lastTrained[skill] + 600000 > System.currentTimeMillis();
- }
- private int getCurrentLevel(int skill) {
- int sLvl = skills.getRealLevel(skill);
- if (sLvl > getMaxLevel(skill))
- sLvl = getMaxLevel(skill);
- return sLvl;
- }
- }
- }
- public static class Range {
- private int min, max;
- public Range(int min, int max) {
- this.min = min;
- this.max = max;
- }
- public int random() {
- return (int) ((Math.random() * (max - min)) + min);
- }
- @Override
- public String toString() {
- return min + " to " + max;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment