Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.text.DecimalFormat;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- 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.event.listeners.TextPaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.Bank;
- 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.Prayer.Book;
- import org.rsbot.script.methods.Skills;
- import org.rsbot.script.methods.Summoning;
- import org.rsbot.script.util.Filter;
- import org.rsbot.script.wrappers.RSCharacter;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSGroundItem;
- import org.rsbot.script.wrappers.RSItem;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSObject;
- import org.rsbot.script.wrappers.RSTile;
- @ScriptManifest(authors = { "Equinox_" }, name = "Equinox Fighter")
- public class EquinoxFighter extends Script implements PaintListener,
- MessageListener, MouseListener {
- private enum Potion {
- SUPER_ATTACK(Skills.ATTACK, 5, .15d, false, 149, 147, 145, 2436), SUPER_STRENGH(
- Skills.STRENGTH, 5, .15d, false, 161, 159, 157, 2440), SUMMONING(
- Skills.SUMMONING, 7, .25d, true, 12146, 12144, 12142, 12140), SUPER_RESTORE(
- new int[] { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24 }, null,
- new double[] { .33d }, true, 0, 0, 0, 0);
- private final int[] skillID;
- private final int[] boostAmount;
- private final double[] boostPercent;
- private final int[] pots;
- private final boolean restore;
- private Potion(int skill, int boostAmt, double boostPercent,
- boolean restore, int p1, int p2, int p3, int p4) {
- this.skillID = new int[] { skill };
- this.boostAmount = new int[] { boostAmt };
- this.boostPercent = new double[] { boostPercent };
- this.pots = new int[] { p1, p2, p3, p4 };
- this.restore = restore;
- }
- private Potion(int skill, int boostAmt, double boostPercent,
- boolean restore, int p1, int p2) {
- this.skillID = new int[] { skill };
- this.boostAmount = new int[] { boostAmt };
- this.boostPercent = new double[] { boostPercent };
- this.pots = new int[] { p1, p2 };
- this.restore = restore;
- }
- private Potion(int[] skill, int[] boostAmt, double[] boostPercent,
- boolean restore, int p1, int p2, int p3, int p4) {
- if (boostAmt == null)
- boostAmt = new int[skill.length];
- if (boostPercent == null)
- boostPercent = new double[skill.length];
- if (boostAmt.length == 1) {
- int fill = boostAmt[0];
- boostAmt = new int[skill.length];
- Arrays.fill(boostAmt, fill);
- }
- if (boostPercent.length == 1) {
- double fill = boostPercent[0];
- boostPercent = new double[skill.length];
- Arrays.fill(boostPercent, fill);
- }
- if (skill.length != boostAmt.length
- || skill.length != boostPercent.length)
- throw new IllegalArgumentException();
- this.skillID = skill;
- this.boostAmount = boostAmt;
- this.boostPercent = boostPercent;
- this.pots = new int[] { p1, p2, p3, p4 };
- this.restore = restore;
- }
- private Potion(int[] skill, int[] boostAmt, double[] boostPercent,
- boolean restore, int p1, int p2) {
- if (boostAmt == null)
- boostAmt = new int[skill.length];
- if (boostPercent == null)
- boostPercent = new double[skill.length];
- if (boostAmt.length == 1) {
- int fill = boostAmt[0];
- boostAmt = new int[skill.length];
- Arrays.fill(boostAmt, fill);
- }
- if (boostPercent.length == 1) {
- double fill = boostPercent[0];
- boostPercent = new double[skill.length];
- Arrays.fill(boostPercent, fill);
- }
- this.skillID = skill;
- this.boostAmount = boostAmt;
- this.boostPercent = boostPercent;
- this.pots = new int[] { p1, p2 };
- this.restore = restore;
- }
- public RSItem getPot(RSItem[] items) {
- for (int id : pots)
- for (RSItem i : items)
- if (i.getID() == id)
- return i;
- return null;
- }
- private int getArrayIndex(int skill) {
- for (int i = 0; i < skillID.length; i++)
- if (skillID[i] == skill)
- return i;
- return -1;
- }
- public int getBoostAmount(int skill, double currLevel) {
- int i = getArrayIndex(skill);
- if (i == -1)
- return 0;
- return boostAmount[i] + (int) (boostPercent[i] * currLevel);
- }
- public boolean shouldBoost(Skills skills) {
- for (int skill = 0; skill < Skills.SKILL_NAMES.length - 1; skill++) {
- int cSkill = skills.getCurrentLevel(skill);
- int rSkill = skills.getRealLevel(skill);
- int max = skill == Skills.DUNGEONEERING ? 120 : 99;
- if (rSkill > max)
- rSkill = max;
- int boostAmount = getBoostAmount(skill, rSkill);
- if (boostAmount > 0) {
- if ((restore && cSkill + (boostAmount + 5) < rSkill)
- || (!restore && rSkill + (boostAmount / 2) > cSkill)) {
- return true;
- }
- }
- }
- return false;
- }
- }
- private enum Familiar {
- BUNYIP(6813, 12029);
- private final int npcID;
- private final int pouchID;
- private Familiar(int npc, int pouch) {
- this.npcID = npc;
- this.pouchID = pouch;
- }
- public int getNpcID() {
- return npcID;
- }
- public int getPouchID() {
- return pouchID;
- }
- }
- public static Filter<RSObject> ALTER_FILTER = new Filter<RSObject>() {
- @Override
- public boolean accept(RSObject t) {
- if (t.getDef() != null && t.getDef().getActions() != null)
- for (String s : t.getDef().getActions())
- if (s != null)
- if (s.toLowerCase().contains("pray"))
- return true;
- return false;
- }
- };
- GEItemLoader geItemLoader;
- SkillPaint skillPaint;
- public static Filter<RSItem> ANTIPOSION_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- return t.getName() != null
- && (t.getName().toLowerCase().contains("anti") || t
- .getName().toLowerCase().contains("posion"));
- }
- };
- public static Filter<RSItem> ANTIFIRE_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- return t.getName() != null
- && (t.getName().toLowerCase().contains("antifire"));
- }
- };
- public static final int[] ANTIFIRE_ID = {};
- public static final int BLOCKED = 0x1280100;
- public static Filter<RSItem> BONES_AND_ASHES_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- if (t.getName() != null
- && (t.getName().toLowerCase().contains("long") || t
- .getName().toLowerCase().contains("curve")))
- return false;
- String[] actions = t.getComponent() != null ? t.getComponent()
- .getActions() : new String[] { "" };
- if (actions != null)
- for (String act : actions)
- if (act != null)
- if (act.toLowerCase().contains("bury")
- || act.toLowerCase().contains("scatter"))
- return true;
- return false;
- }
- };
- public final static int POTION_DRINK = 829;
- public static Filter<RSGroundItem> BONES_AND_ASHES_GROUND_FILTER = new Filter<RSGroundItem>() {
- public final String[] BONES_AND_ASHES = { "bone", "impious",
- "accursed", "infernal ashes" };
- @Override
- public boolean accept(RSGroundItem t) {
- if (t.getItem() != null && t.getItem().getName() != null)
- for (String s : BONES_AND_ASHES)
- if (s != null)
- if (t.getItem().getName().toLowerCase()
- .contains(s.toLowerCase()))
- return true;
- return false;
- }
- };
- public static Filter<RSGroundItem> BONES_GROUND_FILTER = new Filter<RSGroundItem>() {
- @Override
- public boolean accept(RSGroundItem t) {
- if (t.getItem() != null && t.getItem().getName() != null)
- if (t.getItem().getName().toLowerCase().contains("bone"))
- return true;
- return false;
- }
- };
- public static Filter<RSItem> BONES_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- if (t.getName() != null
- && (t.getName().toLowerCase().contains("long") || t
- .getName().toLowerCase().contains("curve")))
- return false;
- String[] actions = t.getComponent() != null ? t.getComponent()
- .getActions() : new String[] { "" };
- if (actions != null)
- for (String act : actions)
- if (act != null)
- if (act.toLowerCase().contains("bury"))
- return true;
- return false;
- }
- };
- public static Filter<RSItem> BONES_TO_FRUIT_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- return t.getName() != null
- && t.getName().toLowerCase().contains("bones to");
- }
- };
- public final static int EMPTY_VIAL = 229;
- public static final int EXCALIBUR_ID = 14632;
- public static Filter<RSItem> FOOD_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- String[] actions = t.getComponent() != null
- && t.getComponent().getActions() != null ? t.getComponent()
- .getActions() : new String[] { "" };
- for (String act : actions)
- if (act != null)
- if (act.toLowerCase().contains("eat"))
- return true;
- return false;
- }
- };
- public Filter<RSNPC> INTERACTING_WITH_ME = new Filter<RSNPC>() {
- @Override
- public boolean accept(RSNPC t) {
- try {
- if (t.isInteractingWithLocalPlayer() && t.getHPPercent() > 0) {
- for (final Summoning.Familiar f : Summoning.Familiar
- .values()) {
- if (t.getName().equals(f.getName())) {
- return false;
- }
- }
- return true;
- }
- } catch (Exception e) {
- }
- return false;
- }
- };
- public static Map<Integer, Integer> npcLevels = new HashMap<Integer, Integer>();
- public static final int PRAYER_BOOK = 10890;
- public static Filter<RSItem> PRAYER_POT_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- return t.getName() != null
- && (t.getName().toLowerCase().contains("prayer") || t
- .getName().toLowerCase().contains("super restore"));
- }
- };
- public static final int STOMP_ANIM = 4798;
- public static Filter<RSItem> TAB_FOOD_FILTER = new Filter<RSItem>() {
- @Override
- public boolean accept(RSItem t) {
- return FOOD_FILTER.accept(t)
- && t.getName() != null
- && (t.getName().toLowerCase().contains("peach") || t
- .getName().toLowerCase().contains("banana"));
- }
- };
- public static final int[] UNDERGROUND_OBJECTS = { 31130, 41536, 17902 };
- public final Filter<RSGroundItem> DROPS = new Filter<RSGroundItem>() {
- public final String[] DROPS = new String[] { "adamant bolts",
- "air orb", "adamantite ore", "battlestaff", "clean toadflax",
- "clean snapdragon", "clean torstol", "saradomin brew (3)",
- "coal", "fire orb", "dragon dagger", "magic seed",
- "onyx bolts", "palm tree seed", "pure essence", "raw shark",
- "raw swordfish", "rune arrow", "rune bar", "runite ore",
- "dragonstone", "vecna skull", "yew logs", "yew seed",
- "tooth half of a key", "plank", "blood rune", "charm",
- "dragon chain", "grimy", "papaya", "clue scroll", "effigy" };
- @Override
- public boolean accept(RSGroundItem t) {
- if (t.getItem() != null && t.getItem().getName() != null) {
- String name = t.getItem().getName().toLowerCase();
- if (options.takeROWDrops) {
- for (String s : DROPS)
- try {
- if (t.getItem().getID() == Integer.valueOf(s))
- return true;
- } catch (NumberFormatException e) {
- if (name.contains(s.toLowerCase()))
- return true;
- }
- }
- for (String s : options.pickNames)
- try {
- if (t.getItem().getID() == Integer.valueOf(s))
- return true;
- } catch (NumberFormatException e) {
- if (name.contains(s.toLowerCase()))
- return true;
- }
- }
- return false;
- }
- };
- public boolean HAS_EXCALIBUR = false;
- public final Filter<RSNPC> MONSTER_FILTER = new Filter<RSNPC>() {
- @Override
- public boolean accept(RSNPC t) {
- if (t.getName() == null || t.isInCombat() || t.getHPPercent() == 0
- || !calc.canReach(t.getLocation(), true))
- return false;
- for (String monsterName : options.monsterNames)
- try {
- if (t.getID() == Integer.valueOf(monsterName))
- return true;
- } catch (NumberFormatException e) {
- if (t.getName() != null
- && t.getName().toLowerCase()
- .contains(monsterName.toLowerCase())
- && !t.isInCombat() && t.getHPPercent() > 0)
- return true;
- }
- return false;
- }
- };
- public int MONSTER_PLANE = 0;
- public final OptionsClass options = new OptionsClass();
- public int WEAPON_ID = 0;
- private boolean isAntifire = true;
- private boolean familiarExpiry = false;
- public boolean canBank() {
- return objects.getNearest(Bank.BANK_BOOTHS) != null
- || objects.getNearest(Bank.BANK_CHESTS) != null
- || objects.getNearest(Bank.BANK_DEPOSIT_BOX) != null
- || npcs.getNearest(Bank.BANKERS) != null
- || objects.getNearest(10517) != null;
- }
- public int getCount(Filter<RSItem> filter) {
- int ct = 0;
- for (RSItem item : inventory.getCachedItems())
- if (filter.accept(item))
- ct++;
- return ct;
- }
- public RSItem getFood() {
- RSItem fruit = getItemInInventory(TAB_FOOD_FILTER);
- RSItem other = getItemInInventory(FOOD_FILTER);
- return (fruit != null ? fruit : other);
- }
- public RSItem getItemInInventory(Filter<RSItem> filter, boolean cache) {
- for (RSItem item : cache ? inventory.getCachedItems() : inventory
- .getItems())
- if (filter.accept(item))
- return item;
- return null;
- }
- public RSItem getItemInInventory(Filter<RSItem> filter) {
- return getItemInInventory(filter, false);
- }
- public Polygon getMinimapPolygon(final RSTile t) {
- if (t != null) {
- Polygon poly = new Polygon();
- Point pt = calc.tileToMinimap(t);
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToMinimap(new RSTile(t.getX(), t.getY() + 1));
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY() + 1));
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY()));
- poly.addPoint(pt.x, pt.y);
- for (int i = 0; i < poly.npoints; i++)
- if (poly.xpoints[i] < 0 || poly.ypoints[i] < 0)
- return null;
- return poly;
- }
- return null;
- }
- public RSNPC getMonster() {
- RSNPC interactingWithMe = npcs.getNearest(INTERACTING_WITH_ME);
- RSNPC avaliableMonster = npcs.getNearest(MONSTER_FILTER);
- if (options.lowestLevelFirst) {
- RSNPC[] avaliableMonsters = npcs.getAll(MONSTER_FILTER);
- for (RSNPC n : avaliableMonsters)
- if (getLevel(n) < getLevel(avaliableMonster))
- avaliableMonster = n;
- }
- RSCharacter interacting = getMyPlayer().getInteracting();
- RSNPC imInteractingWith = (interacting != null
- && interacting instanceof RSNPC && interacting.getHPPercent() > 0) ? ((RSNPC) interacting)
- : null;
- if (imInteractingWith != null)
- return imInteractingWith;
- else if (interactingWithMe != null)
- return interactingWithMe;
- else if (avaliableMonster != null) {
- return avaliableMonster;
- } else
- return null;
- }
- public Polygon getScreenPolygon(final RSTile t) {
- if (t != null) {
- Polygon poly = new Polygon();
- Point pt = calc.tileToScreen(t, 0, 0, 0);
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToScreen(t, 0, 1, 0);
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToScreen(t, 1, 1, 0);
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToScreen(t, 1, 0, 0);
- poly.addPoint(pt.x, pt.y);
- for (int i = 0; i < poly.npoints; i++)
- if (poly.xpoints[i] < 0 || poly.ypoints[i] < 0)
- return null;
- return poly;
- }
- return null;
- }
- public State getState() {
- if (((inventory.isFull() && getCount(BONES_FILTER) > 5) || (combat
- .getHealth() < 50 && getFood() == null))
- && options.bonesToFruit
- && getItemInInventory(BONES_FILTER) != null
- && getItemInInventory(BONES_TO_FRUIT_FILTER) != null)
- return State.BONES_TO_FRUIT;
- if (canBank() && options.bankItemNames.length > 0 && inventory.isFull())
- return State.BANK_ITEMS;
- if (isPraying()
- && combat.getPrayerPoints() < (skills
- .getRealLevel(Skills.PRAYER) / 3)
- && (objects.getNearest(ALTER_FILTER) != null || (getItemInInventory(PRAYER_POT_FILTER) != null && getMyPlayer()
- .getAnimation() != POTION_DRINK)))
- return State.CHARGE_PRAYER;
- if (getItemInInventory(ANTIFIRE_FILTER) != null && !isAntifire
- && getMyPlayer().getAnimation() != POTION_DRINK)
- return State.ANTIFIRE_FIX;
- if (getMonster() == null || getMyPlayer().getInteracting() != null) {
- if (getMyPlayer().getAnimation() != POTION_DRINK
- && getPotionDrink() != null)
- return State.POTION_DRINK;
- if (options.familiar != null && familiarExpiry
- && inventory.contains(options.familiar.getPouchID()))
- return State.RENEW_FAMILIAR;
- if (inventory.contains(EMPTY_VIAL))
- return State.DISPOSE_VIALS;
- if (combat.getHealth() < 50)
- return State.EAT_FOOD;
- if (inventory.contains(EXCALIBUR_ID)
- && combat.getSpecialBarEnergy() >= 1000 && HAS_EXCALIBUR)
- return State.EXCALIBUR_EQUIP;
- if (combat.getSpecialBarEnergy() >= 1000 && HAS_EXCALIBUR
- && !inventory.contains(EXCALIBUR_ID)
- && inventory.contains(WEAPON_ID))
- return State.EXCALIBUR_SPEC;
- if (inventory.contains(WEAPON_ID))
- return State.EXCALIBUR_UNEQUIP;
- if (options.arrowID > 0 && inventory.contains(options.arrowID))
- return State.EQUIP_ARROWS;
- }
- if (npcs.getNearest(INTERACTING_WITH_ME) == null
- && options.arrowID > 0
- && (!inventory.isFull() || inventory.contains(options.arrowID))
- && groundItems.getNearest(options.arrowID) != null
- && calc.canReach(groundItems.getNearest(options.arrowID)
- .getLocation(), false))
- return State.TAKE_ARROWS;
- if (inventory.isFull()
- && getItemInInventory(BONES_AND_ASHES_FILTER) != null
- && options.lootPrayerExp)
- return State.BURY_BONES_AND_ASHES;
- RSGroundItem rowDrop = groundItems
- .getNearest(new Filter<RSGroundItem>() {
- @Override
- public boolean accept(RSGroundItem t) {
- return (DROPS.accept(t) || ((options.lootPrayerExp || options.bonesToFruit) && BONES_AND_ASHES_GROUND_FILTER
- .accept(t)))
- && calc.canReach(t.getLocation(), false);
- }
- });
- boolean bool = false;
- if (rowDrop != null)
- if (rowDrop.getItem() != null)
- if (inventory.getItem(rowDrop.getItem().getID()) != null)
- bool = inventory.getItem(rowDrop.getItem().getID())
- .getStackSize() >= 2
- || (rowDrop.getItem().getName() != null && rowDrop
- .getItem().getName().toLowerCase()
- .contains("charm"));
- if (rowDrop != null && (!inventory.isFull() || bool)
- && calc.tileOnMap(rowDrop.getLocation())
- && calc.canReach(rowDrop.getLocation(), false))
- return State.PICKUP;
- if (!isInCombat() && combat.isPoisoned()
- && combat.getPrayerPoints() > 3
- && getMyPlayer().getAnimation() != POTION_DRINK)
- return State.POSION_CURE;
- if (getMonster() != null)
- return State.FIGHT;
- return State.LOST;
- }
- public RSTile getTileAdjacentToBlock(RSTile base) {
- RSTile best = null;
- double bestD = Double.MAX_VALUE;
- int[][] flags = walking.getCollisionFlags(game.getPlane());
- int offX = game.getBaseX() - 1, offY = game.getBaseY() - 1;
- for (int x = 0; x < flags.length; x++)
- for (int y = 0; y < flags.length; y++) {
- RSTile curr = new RSTile(offX + x, offY + y);
- double dist = calc.distanceBetween(base, curr);
- if ((flags[x][y] & BLOCKED) == 0
- && isAdjacentTileBlocked(curr, flags) && dist < bestD) {
- best = curr;
- bestD = dist;
- }
- }
- return best;
- }
- 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 boolean isAdjacentTileBlocked(RSTile base, int[][] flags) {
- return successors(base, flags, true).size() > 0;
- }
- public boolean isInCombat() {
- RSNPC interactingWithMe = npcs.getNearest(INTERACTING_WITH_ME);
- RSNPC imInteractingWith = (getMyPlayer().getInteracting() != null && getMyPlayer()
- .getInteracting() instanceof RSNPC) ? (((RSNPC) getMyPlayer()
- .getInteracting()).getHPPercent() > 0 ? ((RSNPC) getMyPlayer()
- .getInteracting()) : null) : null;
- return (imInteractingWith != null || interactingWithMe != null);
- }
- public boolean isPraying() {
- if (prayer.isQuickPrayerOn())
- return true;
- for (Book p : Book.values())
- if (prayer.isPrayerOn(p))
- return true;
- return false;
- }
- public boolean isResting() {
- int anim = getMyPlayer().getAnimation();
- return (anim == 12108 || anim == 2033 || anim == 2716 || anim == 11786 || anim == 5713);
- }
- @Override
- public int loop() {
- mouse.setSpeed(random(4, 6));
- if (settings.getSetting(394) <= 0 && options.stopAtEndOfTask)
- if (isInCombat())
- return 500;
- else {
- log.info("Reached the end of your task, stopping!");
- triggerStop();
- }
- switch (getState()) {
- case RENEW_FAMILIAR:
- RSItem pouch = inventory.getItem(options.familiar.getPouchID());
- if (pouch != null) {
- if (summoning.getFamiliar() != null) {
- // Renew button
- if (summoning.doRenewFamiliar()) {
- sleep(1000, 1500);
- }
- } else {
- // Pouch summon
- pouch.doAction("Summon");
- }
- }
- break;
- case POTION_DRINK:
- RSItem potS = getPotionDrink();
- if (potS != null) {
- if (potS.doClick(true))
- sleep(4000, 5000);
- }
- break;
- case DISPOSE_VIALS:
- RSItem[] items = inventory.getItems(EMPTY_VIAL);
- for (RSItem i : items)
- if (i != null) {
- i.doAction("Drop");
- sleep(100, 250);
- }
- break;
- case ANTIFIRE_FIX:
- RSItem aFire = getPotion(ANTIFIRE_FILTER);
- if (aFire != null) {
- if (aFire.doAction("Drink"))
- sleep(200, 500);
- }
- break;
- case TAKE_ARROWS:
- RSGroundItem arr = groundItems.getNearest(options.arrowID);
- if (arr != null
- && (inventory.contains(options.arrowID) || !inventory
- .isFull())) {
- if (!arr.isOnScreen()) {
- walking.walkTileMM(getTileOnMinimap(arr.getLocation()));
- sleep(500, 750);
- }
- arr.doAction("Take "
- + (arr.getItem() != null ? (arr.getItem().getName() != null ? arr
- .getItem().getName() : "")
- : ""));
- break;
- }
- break;
- case EQUIP_ARROWS:
- RSItem arrow = inventory.getItem(options.arrowID);
- if (arrow != null)
- arrow.doClick(true);
- break;
- case CHARGE_PRAYER:
- RSObject alter = objects.getNearest(ALTER_FILTER);
- RSItem pot = getPotion(PRAYER_POT_FILTER);
- if (alter != null) {
- if (!alter.isOnScreen()) {
- if (walking.getDestination() == null
- || calc.distanceBetween(walking.getDestination(),
- getTileOnMinimap(alter.getLocation())) > 4)
- walking.walkTileMM(getTileOnMinimap(alter.getLocation()));
- break;
- } else {
- alter.doAction("Pray");
- break;
- }
- }
- if (pot != null) {
- if (game.getCurrentTab() != Game.TAB_INVENTORY)
- game.openTab(Game.TAB_INVENTORY, random(0, 5) == 0 ? true
- : false);
- if (pot.doAction("Drink"))
- sleep(1000, 1250);
- }
- break;
- case EXCALIBUR_EQUIP:
- RSItem excal = inventory.getItem(EXCALIBUR_ID);
- if (excal != null)
- excal.doAction("Wield");
- sleep(750, 1000);
- break;
- case EXCALIBUR_SPEC:
- final RSComponent specbar = interfaces.getComponent(884, 5);
- if (game.getCurrentTab() != Game.TAB_ATTACK)
- game.openTab(Game.TAB_ATTACK);
- if (game.getCurrentTab() == Game.TAB_ATTACK && specbar != null)
- specbar.doClick();
- sleep(750, 1000);
- break;
- case EXCALIBUR_UNEQUIP:
- RSItem wep = inventory.getItem(WEAPON_ID);
- if (wep != null)
- wep.doAction("Wield");
- sleep(750, 1000);
- break;
- case POSION_CURE:
- RSItem book = inventory.getItem(PRAYER_BOOK);
- RSItem anti = getPotion(ANTIPOSION_FILTER);
- if (book != null)
- if (book.doAction("Recite-prayer")) {
- sleep(1000);
- break;
- }
- if (anti != null)
- if (anti.doAction("Drink")) {
- sleep(1000);
- break;
- }
- break;
- case FIGHT:
- RSNPC monster = getMonster();
- if (monster != null) {
- if (monster.getName() != null
- && (monster.getName().toLowerCase()
- .contains("strykewyrm") || monster.getName()
- .toLowerCase().contains("mound")))
- if (!isAdjacentTileBlocked(getMyPlayer().getLocation(),
- walking.getCollisionFlags(game.getPlane()))) {
- walking.walkTileMM(getTileOnMinimap(getTileAdjacentToBlock(monster
- .getLocation())));
- }
- if (monster.isOnScreen()
- && !npcLevels.containsKey(monster.getID())) {
- Point p = monster.getModel() != null ? monster.getModel()
- .getCentralPoint() : calc.tileToScreen(
- monster.getLocation(), 0.5d, 0.5d,
- monster.getHeight() / 2);
- if (calc.distanceBetween(p, mouse.getLocation()) > 2)
- mouse.move(p);
- setLevel(monster);
- }
- if (getMyPlayer().getInteracting() == null) {
- if (!monster.isOnScreen()) {
- walking.walkTileMM(getTileOnMinimap(monster
- .getLocation()));
- sleep(500, 750);
- } else {
- if (monster.doAction("Attack")) {
- sleep(500, 750);
- } else if (getMyPlayer().getAnimation() != STOMP_ANIM)
- if (monster.doAction("Investigate"))
- sleep(500, 750);
- }
- } else {
- int dist = random(-1, 3) * random(0, 2) * random(0, 100);
- if (dist > 25)
- mouse.moveRandomly(dist, dist + 25);
- }
- slayerMonsterHandle(monster);
- }
- break;
- case PICKUP:
- RSGroundItem rowDrop = groundItems
- .getNearest(new Filter<RSGroundItem>() {
- @Override
- public boolean accept(RSGroundItem t) {
- return DROPS.accept(t)
- || (options.lootPrayerExp && BONES_AND_ASHES_GROUND_FILTER
- .accept(t))
- || (options.bonesToFruit && BONES_GROUND_FILTER
- .accept(t));
- }
- });
- boolean bool = false;
- if (rowDrop != null)
- if (rowDrop.getItem() != null)
- if (inventory.getItem(rowDrop.getItem().getID()) != null)
- bool = inventory.getItem(rowDrop.getItem().getID())
- .getStackSize() >= 2
- || (rowDrop.getItem().getName() != null && rowDrop
- .getItem().getName().toLowerCase()
- .contains("charm"));
- if (rowDrop != null && (!inventory.isFull() || bool)) {
- if (!rowDrop.isOnScreen()) {
- walking.walkTileMM(getTileOnMinimap(rowDrop.getLocation()));
- sleep(500, 750);
- }
- rowDrop.doAction("Take "
- + (rowDrop.getItem() != null ? (rowDrop.getItem()
- .getName() != null ? rowDrop.getItem()
- .getName() : "") : ""));
- break;
- }
- break;
- case EAT_FOOD:
- RSItem food = getFood();
- if (food == null)
- triggerStop();
- else if (food.doAction("Eat"))
- ;
- break;
- case BURY_BONES_AND_ASHES:
- RSItem doItem;
- while ((doItem = getItemInInventory(BONES_AND_ASHES_FILTER)) != null) {
- if (doItem.doAction("Bury"))
- sleep(500, 600);
- else if (doItem.doAction("Scatter"))
- sleep(500, 600);
- }
- break;
- case BANK_ITEMS:
- if (!bank.isOpen() && !bank.isDepositOpen()) {
- if (!bank.open()) {
- RSObject obj = objects.getNearest(10517);
- if (obj != null) {
- if (!obj.isOnScreen()) {
- walking.walkTileMM(getTileOnMinimap(obj
- .getLocation()));
- } else {
- obj.doAction("Use-quickly");
- }
- }
- }
- }
- if (bank.isOpen() || bank.isDepositOpen()) {
- for (String itemName : options.bankItemNames) {
- int id;
- try {
- id = Integer.valueOf(itemName.trim());
- } catch (NumberFormatException e) {
- id = inventory.getItemID(itemName);
- }
- if (id > 0)
- bank.deposit(id, inventory.getCount(id) > 1 ? 0 : 1);
- }
- }
- break;
- case BONES_TO_FRUIT:
- RSItem tab = getItemInInventory(BONES_TO_FRUIT_FILTER);
- if (tab != null)
- if (tab.doClick(true)) {
- for (byte b = 0; b < 100
- && getItemInInventory(BONES_FILTER) != null; b++)
- sleep(100, 125);
- }
- break;
- }
- return 500;
- }
- public int getDoseCount(String s) {
- int a = s.lastIndexOf("(");
- int b = s.lastIndexOf(")");
- try {
- return Integer.valueOf(s.substring(a + 1, b).trim());
- } catch (NumberFormatException e) {
- return 4;
- }
- }
- public RSItem getPotion(Filter<RSItem> itemFilter) {
- int minDosage = 999;
- RSItem it = null;
- for (RSItem i : inventory.getItems())
- if (itemFilter.accept(i)) {
- int dose = getDoseCount(i.getName());
- if (i.getName() != null && dose < minDosage) {
- minDosage = dose;
- it = i;
- }
- }
- return it;
- }
- @Override
- public void onRepaint(Graphics render) {
- skillPaint.drawLine(render, 0);
- }
- @Override
- public boolean onStart() {
- String s = ((String) JOptionPane.showInputDialog(null,
- "What monster do you want to attack?", "Equinox_ Fighter",
- JOptionPane.QUESTION_MESSAGE));
- if (s == null)
- s = "";
- options.monsterNames = s.split(",");
- s = ((String) JOptionPane.showInputDialog(null,
- "What items do you want to pick?", "Equinox_ Fighter",
- JOptionPane.QUESTION_MESSAGE));
- if (s == null)
- s = "";
- options.pickNames = s.length() > 0 ? s.split(",") : new String[] {};
- if (settings.getSetting(394) > 0)
- options.stopAtEndOfTask = JOptionPane.showOptionDialog(null,
- "Would you like the bot to stop at the end of your task?",
- "Equinox_ Fighter", JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE, null, null, 0) == JOptionPane.YES_OPTION;
- else
- options.stopAtEndOfTask = false;
- options.lootPrayerExp = JOptionPane.showOptionDialog(null,
- "Loot bones and ashes?", "Equinox_ Fighter",
- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
- null, 0) == JOptionPane.YES_OPTION;
- options.takeROWDrops = JOptionPane.showOptionDialog(null,
- "Take ring of wealth drops?", "Equinox_ Fighter",
- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
- null, 0) == JOptionPane.YES_OPTION;
- options.bonesToFruit = getItemInInventory(BONES_TO_FRUIT_FILTER) != null;
- HAS_EXCALIBUR = inventory.contains(EXCALIBUR_ID);
- RSItem wep = equipment.getItem(Equipment.WEAPON);
- RSItem quiver = equipment.getItem(Equipment.AMMO);
- if (quiver != null)
- options.arrowID = quiver.getID();
- else
- options.arrowID = -1;
- if (wep != null && wep.getID() >= 0) {
- WEAPON_ID = wep.getID();
- log.info("Wep id: " + WEAPON_ID);
- } else {
- log.severe("You must start with a weapon wielded!");
- return false;
- }
- options.familiar = getFamiliar();
- if (options.familiar != null) {
- log.info("Familiar: "
- + PaintFormatter.properCaseAll(options.familiar.name()));
- }
- skillPaint = new SkillPaint(skills);
- geItemLoader = new GEItemLoader(this, grandExchange);
- return true;
- }
- 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 void slayerMonsterHandle(RSNPC n) {
- // Killing blows
- String name = n.getName().trim().toLowerCase();
- if (n.getHPPercent() <= 5
- || (n.getHPPercent() == 100 && n.isInCombat()))
- if (name.contains("garg")) {
- n.doAction("Smash");
- log.info("SMASH!");
- }
- }
- public void triggerStop() {
- for (byte b1 = 0; b1 < 5 && game.isLoggedIn(); b1++) {
- game.logout(false);
- sleep(10000, 11000);
- }
- stopScript(true);
- }
- private int getLevel(RSNPC monster) {
- if (monster.getLevel() >= 0)
- return monster.getLevel();
- if (npcLevels.containsKey(monster.getID()))
- return npcLevels.get(monster.getID()).intValue();
- return -1;
- }
- private void setLevel(RSNPC monster) {
- String promise = null;
- int pCount = 0;
- for (String s : menu.getItems())
- if (s != null && s.toLowerCase().contains("(level: ")) {
- promise = s;
- pCount++;
- }
- if (promise != null && pCount <= 2) {
- int start = promise.toLowerCase().lastIndexOf("level: ")
- + "level: ".length();
- int end = promise.toLowerCase().lastIndexOf(")");
- String lvl = promise.substring(start, end).trim();
- try {
- npcLevels.put(monster.getID(), Integer.valueOf(lvl));
- return;
- } catch (Exception e) {
- }
- }
- if (monster.getActions() != null)
- for (String s : monster.getActions())
- if (s != null && s.toLowerCase().contains("level: ")) {
- int start = s.toLowerCase().lastIndexOf("level: ")
- + "level: ".length();
- int end = s.toLowerCase().lastIndexOf(")");
- String lvl = s.substring(start, end).trim();
- try {
- npcLevels.put(monster.getID(), Integer.valueOf(lvl));
- return;
- } catch (Exception e) {
- }
- }
- }
- private List<RSTile> successors(RSTile t, int[][] flags, boolean blocked) {
- LinkedList<RSTile> tiles = new LinkedList<RSTile>();
- try {
- int x = t.getX(), y = t.getY();
- int offX = game.getBaseX() - 1, offY = game.getBaseY() - 1;
- int f_x = x - offX, f_y = y - offY;
- int upper = flags.length;
- for (int modX = -1; modX <= 1; modX++) {
- for (int modY = -1; modY <= 1; modY++) {
- if ((modY != 0 || modX != 0) && f_y + modY >= 0
- && f_y + modY < upper && f_x + modX >= 0
- && f_x + modX < upper) {
- if (blocked
- && (flags[f_x + modX][f_y + modY] & BLOCKED) != 0)
- tiles.add(new RSTile(x + modX, y + modY));
- else if (!blocked
- && (flags[f_x + modX][f_y + modY] & BLOCKED) == 0)
- tiles.add(new RSTile(x + modX, y + modY));
- }
- }
- }
- } catch (Exception e) {
- }
- return tiles;
- }
- public static class OptionsClass {
- int arrowID = 0;
- String[] bankItemNames = {};
- boolean bonesToFruit = false;
- boolean lootPrayerExp = false;
- String[] monsterNames = {};
- String[] pickNames = {};
- boolean stopAtEndOfTask = false;
- boolean takeROWDrops = false;
- boolean lowestLevelFirst = false;
- Familiar familiar = null;
- /**
- * A range class for randomized items
- *
- * @author Equinox_
- *
- */
- public static class Range {
- public int MAX;
- public int MIN;
- public Range() {
- MAX = 1;
- MIN = -1;
- }
- /**
- *
- * @param min
- * The inclusive lower bound
- * @param max
- * The inclusive upper bound
- */
- public Range(int min, int max) {
- MAX = Math.max(min, max) + 1;
- MIN = Math.min(min, max);
- }
- /**
- * Returns a linearly distributed pseudorandom integer.
- *
- * @return Random integer min <= n < max.
- */
- public int random() {
- return MIN + (MAX == MIN ? 0 : new Random().nextInt(MAX - MIN));
- }
- /**
- * Returns a normally distributed pseudorandom integer about a mean
- * centered between min and max with a provided standard deviation.
- *
- * @param sd
- * The standard deviation. A higher value will increase
- * the probability of numbers further from the mean being
- * returned.
- * @return Random integer min <= n < max from the normal
- * distribution described by the parameters.
- */
- public int random(int sd) {
- int mean = MIN + (MAX - MIN) / 2;
- int rand;
- do {
- rand = (int) (new Random().nextGaussian() * sd + mean);
- } while (rand < MIN || rand >= MAX);
- return rand;
- }
- /**
- * Returns a normally distributed pseudorandom integer about a mean
- * centered between min and max with a calculated standard
- * deviation.
- *
- * @return Random integer min <= n < max from the normal
- * distribution described by the parameters.
- */
- public int randomNormalDistribution() {
- int mean = MIN + (MAX - MIN) / 2;
- int rand;
- int sd = (MAX - MIN) / 3;
- do {
- rand = (int) (new Random().nextGaussian() * sd + mean);
- } while (rand < MIN || rand >= MAX);
- return rand;
- }
- @Override
- public String toString() {
- return MIN + "-" + MAX;
- }
- }
- }
- /**
- * Used to format data into more conventional formats
- *
- * @author Equinox_
- *
- */
- public static class PaintFormatter {
- /**
- * 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;
- }
- /**
- * 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 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 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 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++) {
- words[i] = words[i].substring(0, 1).toUpperCase()
- + 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);
- }
- }
- enum State {
- DISPOSE_VIALS, ANTIFIRE_FIX, BANK_ITEMS, BONES_TO_FRUIT, BURY_BONES_AND_ASHES, CHARGE_PRAYER, EAT_FOOD, EQUIP_ARROWS, EXCALIBUR_EQUIP, EXCALIBUR_SPEC, EXCALIBUR_UNEQUIP, FIGHT, LOST, PICKUP, POSION_CURE, TAKE_ARROWS, TAKE_BONES_AND_ASHES, POTION_DRINK, RENEW_FAMILIAR
- }
- public RSItem getPotionDrink() {
- for (Potion p : Potion.values()) {
- if (p.shouldBoost(skills)) {
- RSItem pot = p.getPot(inventory.getItems());
- if (pot != null)
- return pot;
- }
- }
- return null;
- }
- @Override
- public void messageReceived(MessageEvent e) {
- String msg = e.getMessage().toLowerCase();
- if (e.getID() == MessageEvent.MESSAGE_SERVER
- || e.getID() == MessageEvent.MESSAGE_ACTION) {
- if (msg.contains("you drink") && msg.contains("antifire potion")) {
- isAntifire = true;
- } else if ((msg.contains("resistance to dragonfire") && msg
- .contains("run out"))
- || msg.contains("your shield absorbs most of the dragon's fiery breath")
- || msg.contains("horribly burnt by the dragon")) {
- isAntifire = false;
- } else if (msg
- .contains("you have 1 minute before your familiar vanishes")) {
- familiarExpiry = true;
- } else if (msg.contains("you sacrifice a pouch to")) {
- familiarExpiry = false;
- }
- }
- }
- private static class GEItemLoader extends Thread {
- private static Map<Integer, Integer> prices = new HashMap<Integer, Integer>();
- private LinkedList<Integer> loadQueue = new LinkedList<Integer>();
- private final GrandExchange ge;
- private final Script script;
- public GEItemLoader(EquinoxFighter s, GrandExchange ge) {
- super("GEItem Loader" + s.getClass().getName());
- this.ge = ge;
- this.script = s;
- this.start();
- }
- public int getPrice(int id) {
- if (prices.containsKey(id))
- return prices.get(id);
- if (!loadQueue.contains(id))
- loadQueue.add(id);
- return 0;
- }
- @Override
- public void run() {
- while (script.isRunning()) {
- if (loadQueue.size() > 0) {
- int loadID = loadQueue.getFirst();
- GEItem itm = ge.lookup(loadID);
- if (itm != null) {
- prices.put(loadID, itm.getGuidePrice());
- loadQueue.removeFirst();
- }
- }
- }
- }
- }
- private static class SkillPaint implements MouseListener, TextPaintListener {
- private Skills skills;
- private SkillTracker tracker;
- private int[] goalLevels;
- private Map<Integer, Rectangle> goalMap = new HashMap<Integer, Rectangle>();
- private int[] skillIDs;
- public SkillTracker getTracker() {
- return 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) {
- 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;
- }
- 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 Skills skills;
- private int[] startExp;
- private int[] newExp;
- private long[] lastTrained;
- private long start;
- 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 int getLevelGain(int skill) {
- return getCurrentLevel(skill) - getStartLevel(skill);
- }
- private int getStartLevel(int skill) {
- int sLvl = Skills.getLevelAt(startExp[skill]);
- if (sLvl > getMaxLevel(skill))
- sLvl = getMaxLevel(skill);
- return sLvl;
- }
- public int getMaxLevel(int skill) {
- return skill == Skills.DUNGEONEERING ? 120 : 99;
- }
- private int getCurrentLevel(int skill) {
- int sLvl = skills.getRealLevel(skill);
- if (sLvl > getMaxLevel(skill))
- sLvl = getMaxLevel(skill);
- return sLvl;
- }
- 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 double getExpPerHour(int skill) {
- return getExpPerSecond(skill) * 3600d;
- }
- 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 hasTrained(int skill) {
- int cExp = skills.getCurrentExp(skill);
- if (newExp[skill] < cExp) {
- lastTrained[skill] = System.currentTimeMillis();
- }
- newExp[skill] = cExp;
- return cExp > startExp[skill];
- }
- public boolean hasRecentlyTrained(int skill) {
- int cExp = skills.getCurrentExp(skill);
- if (newExp[skill] < cExp) {
- lastTrained[skill] = System.currentTimeMillis();
- }
- newExp[skill] = cExp;
- return lastTrained[skill] + 60000 > System.currentTimeMillis();
- }
- }
- @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;
- }
- }
- }
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- }
- }
- public Familiar getFamiliar() {
- RSNPC familiar = summoning.getFamiliar() != null ? summoning
- .getFamiliar().getNPC() : null;
- if (familiar != null) {
- for (Familiar f : Familiar.values())
- if (f.getNpcID() == familiar.getID())
- return f;
- }
- return null;
- }
- @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) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment