Equinox

EquinoxFighter.java

Apr 21st, 2011
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 49.89 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.FontMetrics;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.Polygon;
  6. import java.awt.Rectangle;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.MouseListener;
  9. import java.text.DecimalFormat;
  10. import java.util.Arrays;
  11. import java.util.HashMap;
  12. import java.util.LinkedList;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.Random;
  16.  
  17. import javax.swing.JOptionPane;
  18.  
  19. import org.rsbot.event.events.MessageEvent;
  20. import org.rsbot.event.listeners.MessageListener;
  21. import org.rsbot.event.listeners.PaintListener;
  22. import org.rsbot.event.listeners.TextPaintListener;
  23. import org.rsbot.script.Script;
  24. import org.rsbot.script.ScriptManifest;
  25. import org.rsbot.script.methods.Bank;
  26. import org.rsbot.script.methods.Equipment;
  27. import org.rsbot.script.methods.Game;
  28. import org.rsbot.script.methods.GrandExchange;
  29. import org.rsbot.script.methods.GrandExchange.GEItem;
  30. import org.rsbot.script.methods.Prayer.Book;
  31. import org.rsbot.script.methods.Skills;
  32. import org.rsbot.script.methods.Summoning;
  33. import org.rsbot.script.util.Filter;
  34. import org.rsbot.script.wrappers.RSCharacter;
  35. import org.rsbot.script.wrappers.RSComponent;
  36. import org.rsbot.script.wrappers.RSGroundItem;
  37. import org.rsbot.script.wrappers.RSItem;
  38. import org.rsbot.script.wrappers.RSNPC;
  39. import org.rsbot.script.wrappers.RSObject;
  40. import org.rsbot.script.wrappers.RSTile;
  41.  
  42. @ScriptManifest(authors = { "Equinox_" }, name = "Equinox Fighter")
  43. public class EquinoxFighter extends Script implements PaintListener,
  44.     MessageListener, MouseListener {
  45.     private enum Potion {
  46.     SUPER_ATTACK(Skills.ATTACK, 5, .15d, false, 149, 147, 145, 2436), SUPER_STRENGH(
  47.         Skills.STRENGTH, 5, .15d, false, 161, 159, 157, 2440), SUMMONING(
  48.         Skills.SUMMONING, 7, .25d, true, 12146, 12144, 12142, 12140), SUPER_RESTORE(
  49.         new int[] { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  50.             16, 17, 18, 19, 20, 21, 22, 23, 24 }, null,
  51.         new double[] { .33d }, true, 0, 0, 0, 0);
  52.     private final int[] skillID;
  53.     private final int[] boostAmount;
  54.     private final double[] boostPercent;
  55.     private final int[] pots;
  56.     private final boolean restore;
  57.  
  58.     private Potion(int skill, int boostAmt, double boostPercent,
  59.         boolean restore, int p1, int p2, int p3, int p4) {
  60.         this.skillID = new int[] { skill };
  61.         this.boostAmount = new int[] { boostAmt };
  62.         this.boostPercent = new double[] { boostPercent };
  63.         this.pots = new int[] { p1, p2, p3, p4 };
  64.         this.restore = restore;
  65.     }
  66.  
  67.     private Potion(int skill, int boostAmt, double boostPercent,
  68.         boolean restore, int p1, int p2) {
  69.         this.skillID = new int[] { skill };
  70.         this.boostAmount = new int[] { boostAmt };
  71.         this.boostPercent = new double[] { boostPercent };
  72.         this.pots = new int[] { p1, p2 };
  73.         this.restore = restore;
  74.     }
  75.  
  76.     private Potion(int[] skill, int[] boostAmt, double[] boostPercent,
  77.         boolean restore, int p1, int p2, int p3, int p4) {
  78.         if (boostAmt == null)
  79.         boostAmt = new int[skill.length];
  80.         if (boostPercent == null)
  81.         boostPercent = new double[skill.length];
  82.         if (boostAmt.length == 1) {
  83.         int fill = boostAmt[0];
  84.         boostAmt = new int[skill.length];
  85.         Arrays.fill(boostAmt, fill);
  86.         }
  87.         if (boostPercent.length == 1) {
  88.         double fill = boostPercent[0];
  89.         boostPercent = new double[skill.length];
  90.         Arrays.fill(boostPercent, fill);
  91.         }
  92.         if (skill.length != boostAmt.length
  93.             || skill.length != boostPercent.length)
  94.         throw new IllegalArgumentException();
  95.         this.skillID = skill;
  96.         this.boostAmount = boostAmt;
  97.         this.boostPercent = boostPercent;
  98.         this.pots = new int[] { p1, p2, p3, p4 };
  99.         this.restore = restore;
  100.     }
  101.  
  102.     private Potion(int[] skill, int[] boostAmt, double[] boostPercent,
  103.         boolean restore, int p1, int p2) {
  104.         if (boostAmt == null)
  105.         boostAmt = new int[skill.length];
  106.         if (boostPercent == null)
  107.         boostPercent = new double[skill.length];
  108.         if (boostAmt.length == 1) {
  109.         int fill = boostAmt[0];
  110.         boostAmt = new int[skill.length];
  111.         Arrays.fill(boostAmt, fill);
  112.         }
  113.         if (boostPercent.length == 1) {
  114.         double fill = boostPercent[0];
  115.         boostPercent = new double[skill.length];
  116.         Arrays.fill(boostPercent, fill);
  117.         }
  118.         this.skillID = skill;
  119.         this.boostAmount = boostAmt;
  120.         this.boostPercent = boostPercent;
  121.         this.pots = new int[] { p1, p2 };
  122.         this.restore = restore;
  123.     }
  124.  
  125.     public RSItem getPot(RSItem[] items) {
  126.         for (int id : pots)
  127.         for (RSItem i : items)
  128.             if (i.getID() == id)
  129.             return i;
  130.         return null;
  131.     }
  132.  
  133.     private int getArrayIndex(int skill) {
  134.         for (int i = 0; i < skillID.length; i++)
  135.         if (skillID[i] == skill)
  136.             return i;
  137.         return -1;
  138.     }
  139.  
  140.     public int getBoostAmount(int skill, double currLevel) {
  141.         int i = getArrayIndex(skill);
  142.         if (i == -1)
  143.         return 0;
  144.         return boostAmount[i] + (int) (boostPercent[i] * currLevel);
  145.     }
  146.  
  147.     public boolean shouldBoost(Skills skills) {
  148.         for (int skill = 0; skill < Skills.SKILL_NAMES.length - 1; skill++) {
  149.         int cSkill = skills.getCurrentLevel(skill);
  150.         int rSkill = skills.getRealLevel(skill);
  151.         int max = skill == Skills.DUNGEONEERING ? 120 : 99;
  152.         if (rSkill > max)
  153.             rSkill = max;
  154.         int boostAmount = getBoostAmount(skill, rSkill);
  155.         if (boostAmount > 0) {
  156.             if ((restore && cSkill + (boostAmount + 5) < rSkill)
  157.                 || (!restore && rSkill + (boostAmount / 2) > cSkill)) {
  158.             return true;
  159.             }
  160.         }
  161.         }
  162.         return false;
  163.     }
  164.     }
  165.  
  166.     private enum Familiar {
  167.     BUNYIP(6813, 12029);
  168.     private final int npcID;
  169.     private final int pouchID;
  170.  
  171.     private Familiar(int npc, int pouch) {
  172.         this.npcID = npc;
  173.         this.pouchID = pouch;
  174.     }
  175.  
  176.     public int getNpcID() {
  177.         return npcID;
  178.     }
  179.  
  180.     public int getPouchID() {
  181.         return pouchID;
  182.     }
  183.     }
  184.  
  185.     public static Filter<RSObject> ALTER_FILTER = new Filter<RSObject>() {
  186.     @Override
  187.     public boolean accept(RSObject t) {
  188.         if (t.getDef() != null && t.getDef().getActions() != null)
  189.         for (String s : t.getDef().getActions())
  190.             if (s != null)
  191.             if (s.toLowerCase().contains("pray"))
  192.                 return true;
  193.         return false;
  194.     }
  195.     };
  196.  
  197.     GEItemLoader geItemLoader;
  198.     SkillPaint skillPaint;
  199.  
  200.     public static Filter<RSItem> ANTIPOSION_FILTER = new Filter<RSItem>() {
  201.     @Override
  202.     public boolean accept(RSItem t) {
  203.         return t.getName() != null
  204.             && (t.getName().toLowerCase().contains("anti") || t
  205.                 .getName().toLowerCase().contains("posion"));
  206.     }
  207.     };
  208.     public static Filter<RSItem> ANTIFIRE_FILTER = new Filter<RSItem>() {
  209.     @Override
  210.     public boolean accept(RSItem t) {
  211.         return t.getName() != null
  212.             && (t.getName().toLowerCase().contains("antifire"));
  213.     }
  214.     };
  215.  
  216.     public static final int[] ANTIFIRE_ID = {};
  217.  
  218.     public static final int BLOCKED = 0x1280100;
  219.     public static Filter<RSItem> BONES_AND_ASHES_FILTER = new Filter<RSItem>() {
  220.     @Override
  221.     public boolean accept(RSItem t) {
  222.         if (t.getName() != null
  223.             && (t.getName().toLowerCase().contains("long") || t
  224.                 .getName().toLowerCase().contains("curve")))
  225.         return false;
  226.         String[] actions = t.getComponent() != null ? t.getComponent()
  227.             .getActions() : new String[] { "" };
  228.         if (actions != null)
  229.         for (String act : actions)
  230.             if (act != null)
  231.             if (act.toLowerCase().contains("bury")
  232.                 || act.toLowerCase().contains("scatter"))
  233.                 return true;
  234.         return false;
  235.     }
  236.     };
  237.     public final static int POTION_DRINK = 829;
  238.     public static Filter<RSGroundItem> BONES_AND_ASHES_GROUND_FILTER = new Filter<RSGroundItem>() {
  239.     public final String[] BONES_AND_ASHES = { "bone", "impious",
  240.         "accursed", "infernal ashes" };
  241.  
  242.     @Override
  243.     public boolean accept(RSGroundItem t) {
  244.         if (t.getItem() != null && t.getItem().getName() != null)
  245.         for (String s : BONES_AND_ASHES)
  246.             if (s != null)
  247.             if (t.getItem().getName().toLowerCase()
  248.                 .contains(s.toLowerCase()))
  249.                 return true;
  250.         return false;
  251.     }
  252.     };
  253.     public static Filter<RSGroundItem> BONES_GROUND_FILTER = new Filter<RSGroundItem>() {
  254.     @Override
  255.     public boolean accept(RSGroundItem t) {
  256.         if (t.getItem() != null && t.getItem().getName() != null)
  257.         if (t.getItem().getName().toLowerCase().contains("bone"))
  258.             return true;
  259.         return false;
  260.     }
  261.     };
  262.     public static Filter<RSItem> BONES_FILTER = new Filter<RSItem>() {
  263.     @Override
  264.     public boolean accept(RSItem t) {
  265.         if (t.getName() != null
  266.             && (t.getName().toLowerCase().contains("long") || t
  267.                 .getName().toLowerCase().contains("curve")))
  268.         return false;
  269.         String[] actions = t.getComponent() != null ? t.getComponent()
  270.             .getActions() : new String[] { "" };
  271.         if (actions != null)
  272.         for (String act : actions)
  273.             if (act != null)
  274.             if (act.toLowerCase().contains("bury"))
  275.                 return true;
  276.         return false;
  277.     }
  278.     };
  279.     public static Filter<RSItem> BONES_TO_FRUIT_FILTER = new Filter<RSItem>() {
  280.     @Override
  281.     public boolean accept(RSItem t) {
  282.         return t.getName() != null
  283.             && t.getName().toLowerCase().contains("bones to");
  284.     }
  285.     };
  286.     public final static int EMPTY_VIAL = 229;
  287.     public static final int EXCALIBUR_ID = 14632;
  288.     public static Filter<RSItem> FOOD_FILTER = new Filter<RSItem>() {
  289.     @Override
  290.     public boolean accept(RSItem t) {
  291.         String[] actions = t.getComponent() != null
  292.             && t.getComponent().getActions() != null ? t.getComponent()
  293.             .getActions() : new String[] { "" };
  294.         for (String act : actions)
  295.         if (act != null)
  296.             if (act.toLowerCase().contains("eat"))
  297.             return true;
  298.         return false;
  299.     }
  300.     };
  301.     public Filter<RSNPC> INTERACTING_WITH_ME = new Filter<RSNPC>() {
  302.     @Override
  303.     public boolean accept(RSNPC t) {
  304.         try {
  305.         if (t.isInteractingWithLocalPlayer() && t.getHPPercent() > 0) {
  306.             for (final Summoning.Familiar f : Summoning.Familiar
  307.                 .values()) {
  308.             if (t.getName().equals(f.getName())) {
  309.                 return false;
  310.             }
  311.             }
  312.             return true;
  313.         }
  314.         } catch (Exception e) {
  315.         }
  316.         return false;
  317.     }
  318.     };
  319.     public static Map<Integer, Integer> npcLevels = new HashMap<Integer, Integer>();
  320.     public static final int PRAYER_BOOK = 10890;
  321.     public static Filter<RSItem> PRAYER_POT_FILTER = new Filter<RSItem>() {
  322.     @Override
  323.     public boolean accept(RSItem t) {
  324.         return t.getName() != null
  325.             && (t.getName().toLowerCase().contains("prayer") || t
  326.                 .getName().toLowerCase().contains("super restore"));
  327.     }
  328.     };
  329.     public static final int STOMP_ANIM = 4798;
  330.     public static Filter<RSItem> TAB_FOOD_FILTER = new Filter<RSItem>() {
  331.     @Override
  332.     public boolean accept(RSItem t) {
  333.         return FOOD_FILTER.accept(t)
  334.             && t.getName() != null
  335.             && (t.getName().toLowerCase().contains("peach") || t
  336.                 .getName().toLowerCase().contains("banana"));
  337.     }
  338.     };
  339.     public static final int[] UNDERGROUND_OBJECTS = { 31130, 41536, 17902 };
  340.  
  341.     public final Filter<RSGroundItem> DROPS = new Filter<RSGroundItem>() {
  342.     public final String[] DROPS = new String[] { "adamant bolts",
  343.         "air orb", "adamantite ore", "battlestaff", "clean toadflax",
  344.         "clean snapdragon", "clean torstol", "saradomin brew (3)",
  345.         "coal", "fire orb", "dragon dagger", "magic seed",
  346.         "onyx bolts", "palm tree seed", "pure essence", "raw shark",
  347.         "raw swordfish", "rune arrow", "rune bar", "runite ore",
  348.         "dragonstone", "vecna skull", "yew logs", "yew seed",
  349.         "tooth half of a key", "plank", "blood rune", "charm",
  350.         "dragon chain", "grimy", "papaya", "clue scroll", "effigy" };
  351.  
  352.     @Override
  353.     public boolean accept(RSGroundItem t) {
  354.         if (t.getItem() != null && t.getItem().getName() != null) {
  355.         String name = t.getItem().getName().toLowerCase();
  356.         if (options.takeROWDrops) {
  357.             for (String s : DROPS)
  358.             try {
  359.                 if (t.getItem().getID() == Integer.valueOf(s))
  360.                 return true;
  361.             } catch (NumberFormatException e) {
  362.                 if (name.contains(s.toLowerCase()))
  363.                 return true;
  364.             }
  365.         }
  366.         for (String s : options.pickNames)
  367.             try {
  368.             if (t.getItem().getID() == Integer.valueOf(s))
  369.                 return true;
  370.             } catch (NumberFormatException e) {
  371.             if (name.contains(s.toLowerCase()))
  372.                 return true;
  373.             }
  374.         }
  375.         return false;
  376.     }
  377.     };
  378.  
  379.     public boolean HAS_EXCALIBUR = false;
  380.  
  381.     public final Filter<RSNPC> MONSTER_FILTER = new Filter<RSNPC>() {
  382.     @Override
  383.     public boolean accept(RSNPC t) {
  384.         if (t.getName() == null || t.isInCombat() || t.getHPPercent() == 0
  385.             || !calc.canReach(t.getLocation(), true))
  386.         return false;
  387.         for (String monsterName : options.monsterNames)
  388.         try {
  389.             if (t.getID() == Integer.valueOf(monsterName))
  390.             return true;
  391.         } catch (NumberFormatException e) {
  392.             if (t.getName() != null
  393.                 && t.getName().toLowerCase()
  394.                     .contains(monsterName.toLowerCase())
  395.                 && !t.isInCombat() && t.getHPPercent() > 0)
  396.             return true;
  397.         }
  398.         return false;
  399.     }
  400.     };
  401.     public int MONSTER_PLANE = 0;
  402.  
  403.     public final OptionsClass options = new OptionsClass();
  404.  
  405.     public int WEAPON_ID = 0;
  406.     private boolean isAntifire = true;
  407.     private boolean familiarExpiry = false;
  408.  
  409.     public boolean canBank() {
  410.     return objects.getNearest(Bank.BANK_BOOTHS) != null
  411.         || objects.getNearest(Bank.BANK_CHESTS) != null
  412.         || objects.getNearest(Bank.BANK_DEPOSIT_BOX) != null
  413.         || npcs.getNearest(Bank.BANKERS) != null
  414.         || objects.getNearest(10517) != null;
  415.     }
  416.  
  417.     public int getCount(Filter<RSItem> filter) {
  418.     int ct = 0;
  419.     for (RSItem item : inventory.getCachedItems())
  420.         if (filter.accept(item))
  421.         ct++;
  422.     return ct;
  423.     }
  424.  
  425.     public RSItem getFood() {
  426.     RSItem fruit = getItemInInventory(TAB_FOOD_FILTER);
  427.     RSItem other = getItemInInventory(FOOD_FILTER);
  428.     return (fruit != null ? fruit : other);
  429.     }
  430.  
  431.     public RSItem getItemInInventory(Filter<RSItem> filter, boolean cache) {
  432.     for (RSItem item : cache ? inventory.getCachedItems() : inventory
  433.         .getItems())
  434.         if (filter.accept(item))
  435.         return item;
  436.     return null;
  437.     }
  438.  
  439.     public RSItem getItemInInventory(Filter<RSItem> filter) {
  440.     return getItemInInventory(filter, false);
  441.     }
  442.  
  443.     public Polygon getMinimapPolygon(final RSTile t) {
  444.     if (t != null) {
  445.         Polygon poly = new Polygon();
  446.         Point pt = calc.tileToMinimap(t);
  447.         poly.addPoint(pt.x, pt.y);
  448.         pt = calc.tileToMinimap(new RSTile(t.getX(), t.getY() + 1));
  449.         poly.addPoint(pt.x, pt.y);
  450.         pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY() + 1));
  451.         poly.addPoint(pt.x, pt.y);
  452.         pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY()));
  453.         poly.addPoint(pt.x, pt.y);
  454.         for (int i = 0; i < poly.npoints; i++)
  455.         if (poly.xpoints[i] < 0 || poly.ypoints[i] < 0)
  456.             return null;
  457.         return poly;
  458.     }
  459.     return null;
  460.     }
  461.  
  462.     public RSNPC getMonster() {
  463.     RSNPC interactingWithMe = npcs.getNearest(INTERACTING_WITH_ME);
  464.     RSNPC avaliableMonster = npcs.getNearest(MONSTER_FILTER);
  465.     if (options.lowestLevelFirst) {
  466.         RSNPC[] avaliableMonsters = npcs.getAll(MONSTER_FILTER);
  467.         for (RSNPC n : avaliableMonsters)
  468.         if (getLevel(n) < getLevel(avaliableMonster))
  469.             avaliableMonster = n;
  470.     }
  471.     RSCharacter interacting = getMyPlayer().getInteracting();
  472.     RSNPC imInteractingWith = (interacting != null
  473.         && interacting instanceof RSNPC && interacting.getHPPercent() > 0) ? ((RSNPC) interacting)
  474.         : null;
  475.     if (imInteractingWith != null)
  476.         return imInteractingWith;
  477.     else if (interactingWithMe != null)
  478.         return interactingWithMe;
  479.     else if (avaliableMonster != null) {
  480.         return avaliableMonster;
  481.     } else
  482.         return null;
  483.     }
  484.  
  485.     public Polygon getScreenPolygon(final RSTile t) {
  486.     if (t != null) {
  487.         Polygon poly = new Polygon();
  488.         Point pt = calc.tileToScreen(t, 0, 0, 0);
  489.         poly.addPoint(pt.x, pt.y);
  490.         pt = calc.tileToScreen(t, 0, 1, 0);
  491.         poly.addPoint(pt.x, pt.y);
  492.         pt = calc.tileToScreen(t, 1, 1, 0);
  493.         poly.addPoint(pt.x, pt.y);
  494.         pt = calc.tileToScreen(t, 1, 0, 0);
  495.         poly.addPoint(pt.x, pt.y);
  496.         for (int i = 0; i < poly.npoints; i++)
  497.         if (poly.xpoints[i] < 0 || poly.ypoints[i] < 0)
  498.             return null;
  499.         return poly;
  500.     }
  501.     return null;
  502.     }
  503.  
  504.     public State getState() {
  505.     if (((inventory.isFull() && getCount(BONES_FILTER) > 5) || (combat
  506.         .getHealth() < 50 && getFood() == null))
  507.         && options.bonesToFruit
  508.         && getItemInInventory(BONES_FILTER) != null
  509.         && getItemInInventory(BONES_TO_FRUIT_FILTER) != null)
  510.         return State.BONES_TO_FRUIT;
  511.     if (canBank() && options.bankItemNames.length > 0 && inventory.isFull())
  512.         return State.BANK_ITEMS;
  513.     if (isPraying()
  514.         && combat.getPrayerPoints() < (skills
  515.             .getRealLevel(Skills.PRAYER) / 3)
  516.         && (objects.getNearest(ALTER_FILTER) != null || (getItemInInventory(PRAYER_POT_FILTER) != null && getMyPlayer()
  517.             .getAnimation() != POTION_DRINK)))
  518.         return State.CHARGE_PRAYER;
  519.     if (getItemInInventory(ANTIFIRE_FILTER) != null && !isAntifire
  520.         && getMyPlayer().getAnimation() != POTION_DRINK)
  521.         return State.ANTIFIRE_FIX;
  522.     if (getMonster() == null || getMyPlayer().getInteracting() != null) {
  523.         if (getMyPlayer().getAnimation() != POTION_DRINK
  524.             && getPotionDrink() != null)
  525.         return State.POTION_DRINK;
  526.         if (options.familiar != null && familiarExpiry
  527.             && inventory.contains(options.familiar.getPouchID()))
  528.         return State.RENEW_FAMILIAR;
  529.         if (inventory.contains(EMPTY_VIAL))
  530.         return State.DISPOSE_VIALS;
  531.         if (combat.getHealth() < 50)
  532.         return State.EAT_FOOD;
  533.         if (inventory.contains(EXCALIBUR_ID)
  534.             && combat.getSpecialBarEnergy() >= 1000 && HAS_EXCALIBUR)
  535.         return State.EXCALIBUR_EQUIP;
  536.         if (combat.getSpecialBarEnergy() >= 1000 && HAS_EXCALIBUR
  537.             && !inventory.contains(EXCALIBUR_ID)
  538.             && inventory.contains(WEAPON_ID))
  539.         return State.EXCALIBUR_SPEC;
  540.         if (inventory.contains(WEAPON_ID))
  541.         return State.EXCALIBUR_UNEQUIP;
  542.         if (options.arrowID > 0 && inventory.contains(options.arrowID))
  543.         return State.EQUIP_ARROWS;
  544.     }
  545.     if (npcs.getNearest(INTERACTING_WITH_ME) == null
  546.         && options.arrowID > 0
  547.         && (!inventory.isFull() || inventory.contains(options.arrowID))
  548.         && groundItems.getNearest(options.arrowID) != null
  549.         && calc.canReach(groundItems.getNearest(options.arrowID)
  550.             .getLocation(), false))
  551.         return State.TAKE_ARROWS;
  552.     if (inventory.isFull()
  553.         && getItemInInventory(BONES_AND_ASHES_FILTER) != null
  554.         && options.lootPrayerExp)
  555.         return State.BURY_BONES_AND_ASHES;
  556.     RSGroundItem rowDrop = groundItems
  557.         .getNearest(new Filter<RSGroundItem>() {
  558.             @Override
  559.             public boolean accept(RSGroundItem t) {
  560.             return (DROPS.accept(t) || ((options.lootPrayerExp || options.bonesToFruit) && BONES_AND_ASHES_GROUND_FILTER
  561.                 .accept(t)))
  562.                 && calc.canReach(t.getLocation(), false);
  563.             }
  564.         });
  565.     boolean bool = false;
  566.     if (rowDrop != null)
  567.         if (rowDrop.getItem() != null)
  568.         if (inventory.getItem(rowDrop.getItem().getID()) != null)
  569.             bool = inventory.getItem(rowDrop.getItem().getID())
  570.                 .getStackSize() >= 2
  571.                 || (rowDrop.getItem().getName() != null && rowDrop
  572.                     .getItem().getName().toLowerCase()
  573.                     .contains("charm"));
  574.  
  575.     if (rowDrop != null && (!inventory.isFull() || bool)
  576.         && calc.tileOnMap(rowDrop.getLocation())
  577.         && calc.canReach(rowDrop.getLocation(), false))
  578.         return State.PICKUP;
  579.     if (!isInCombat() && combat.isPoisoned()
  580.         && combat.getPrayerPoints() > 3
  581.         && getMyPlayer().getAnimation() != POTION_DRINK)
  582.         return State.POSION_CURE;
  583.     if (getMonster() != null)
  584.         return State.FIGHT;
  585.     return State.LOST;
  586.     }
  587.  
  588.     public RSTile getTileAdjacentToBlock(RSTile base) {
  589.     RSTile best = null;
  590.     double bestD = Double.MAX_VALUE;
  591.     int[][] flags = walking.getCollisionFlags(game.getPlane());
  592.     int offX = game.getBaseX() - 1, offY = game.getBaseY() - 1;
  593.     for (int x = 0; x < flags.length; x++)
  594.         for (int y = 0; y < flags.length; y++) {
  595.         RSTile curr = new RSTile(offX + x, offY + y);
  596.         double dist = calc.distanceBetween(base, curr);
  597.         if ((flags[x][y] & BLOCKED) == 0
  598.             && isAdjacentTileBlocked(curr, flags) && dist < bestD) {
  599.             best = curr;
  600.             bestD = dist;
  601.         }
  602.         }
  603.     return best;
  604.     }
  605.  
  606.     public RSTile getTileOnMinimap(RSTile base) {
  607.     if (calc.tileOnMap(base))
  608.         return base;
  609.     RSTile me = getMyPlayer().getLocation();
  610.     int deltaX = base.getX() - me.getX();
  611.     int deltaY = base.getY() - me.getY();
  612.     double dist = calc.distanceBetween(base, me);
  613.     double eX = deltaX / dist, eY = deltaY / dist;
  614.     return new RSTile(me.getX() + (int) (eX * 14), me.getY()
  615.         + (int) (eY * 14));
  616.     }
  617.  
  618.     public boolean isAdjacentTileBlocked(RSTile base, int[][] flags) {
  619.     return successors(base, flags, true).size() > 0;
  620.     }
  621.  
  622.     public boolean isInCombat() {
  623.     RSNPC interactingWithMe = npcs.getNearest(INTERACTING_WITH_ME);
  624.     RSNPC imInteractingWith = (getMyPlayer().getInteracting() != null && getMyPlayer()
  625.         .getInteracting() instanceof RSNPC) ? (((RSNPC) getMyPlayer()
  626.         .getInteracting()).getHPPercent() > 0 ? ((RSNPC) getMyPlayer()
  627.         .getInteracting()) : null) : null;
  628.     return (imInteractingWith != null || interactingWithMe != null);
  629.     }
  630.  
  631.     public boolean isPraying() {
  632.     if (prayer.isQuickPrayerOn())
  633.         return true;
  634.     for (Book p : Book.values())
  635.         if (prayer.isPrayerOn(p))
  636.         return true;
  637.     return false;
  638.     }
  639.  
  640.     public boolean isResting() {
  641.     int anim = getMyPlayer().getAnimation();
  642.     return (anim == 12108 || anim == 2033 || anim == 2716 || anim == 11786 || anim == 5713);
  643.     }
  644.  
  645.     @Override
  646.     public int loop() {
  647.     mouse.setSpeed(random(4, 6));
  648.     if (settings.getSetting(394) <= 0 && options.stopAtEndOfTask)
  649.         if (isInCombat())
  650.         return 500;
  651.         else {
  652.         log.info("Reached the end of your task, stopping!");
  653.         triggerStop();
  654.         }
  655.     switch (getState()) {
  656.     case RENEW_FAMILIAR:
  657.         RSItem pouch = inventory.getItem(options.familiar.getPouchID());
  658.         if (pouch != null) {
  659.         if (summoning.getFamiliar() != null) {
  660.             // Renew button
  661.             if (summoning.doRenewFamiliar()) {
  662.             sleep(1000, 1500);
  663.             }
  664.         } else {
  665.             // Pouch summon
  666.             pouch.doAction("Summon");
  667.         }
  668.         }
  669.         break;
  670.     case POTION_DRINK:
  671.         RSItem potS = getPotionDrink();
  672.         if (potS != null) {
  673.         if (potS.doClick(true))
  674.             sleep(4000, 5000);
  675.         }
  676.         break;
  677.     case DISPOSE_VIALS:
  678.         RSItem[] items = inventory.getItems(EMPTY_VIAL);
  679.         for (RSItem i : items)
  680.         if (i != null) {
  681.             i.doAction("Drop");
  682.             sleep(100, 250);
  683.         }
  684.         break;
  685.     case ANTIFIRE_FIX:
  686.         RSItem aFire = getPotion(ANTIFIRE_FILTER);
  687.         if (aFire != null) {
  688.         if (aFire.doAction("Drink"))
  689.             sleep(200, 500);
  690.         }
  691.         break;
  692.     case TAKE_ARROWS:
  693.         RSGroundItem arr = groundItems.getNearest(options.arrowID);
  694.         if (arr != null
  695.             && (inventory.contains(options.arrowID) || !inventory
  696.                 .isFull())) {
  697.         if (!arr.isOnScreen()) {
  698.             walking.walkTileMM(getTileOnMinimap(arr.getLocation()));
  699.             sleep(500, 750);
  700.         }
  701.         arr.doAction("Take "
  702.             + (arr.getItem() != null ? (arr.getItem().getName() != null ? arr
  703.                 .getItem().getName() : "")
  704.                 : ""));
  705.         break;
  706.         }
  707.         break;
  708.     case EQUIP_ARROWS:
  709.         RSItem arrow = inventory.getItem(options.arrowID);
  710.         if (arrow != null)
  711.         arrow.doClick(true);
  712.         break;
  713.     case CHARGE_PRAYER:
  714.         RSObject alter = objects.getNearest(ALTER_FILTER);
  715.         RSItem pot = getPotion(PRAYER_POT_FILTER);
  716.         if (alter != null) {
  717.         if (!alter.isOnScreen()) {
  718.             if (walking.getDestination() == null
  719.                 || calc.distanceBetween(walking.getDestination(),
  720.                     getTileOnMinimap(alter.getLocation())) > 4)
  721.             walking.walkTileMM(getTileOnMinimap(alter.getLocation()));
  722.             break;
  723.         } else {
  724.             alter.doAction("Pray");
  725.             break;
  726.         }
  727.         }
  728.         if (pot != null) {
  729.         if (game.getCurrentTab() != Game.TAB_INVENTORY)
  730.             game.openTab(Game.TAB_INVENTORY, random(0, 5) == 0 ? true
  731.                 : false);
  732.         if (pot.doAction("Drink"))
  733.             sleep(1000, 1250);
  734.         }
  735.         break;
  736.     case EXCALIBUR_EQUIP:
  737.         RSItem excal = inventory.getItem(EXCALIBUR_ID);
  738.         if (excal != null)
  739.         excal.doAction("Wield");
  740.         sleep(750, 1000);
  741.         break;
  742.     case EXCALIBUR_SPEC:
  743.         final RSComponent specbar = interfaces.getComponent(884, 5);
  744.         if (game.getCurrentTab() != Game.TAB_ATTACK)
  745.         game.openTab(Game.TAB_ATTACK);
  746.  
  747.         if (game.getCurrentTab() == Game.TAB_ATTACK && specbar != null)
  748.         specbar.doClick();
  749.         sleep(750, 1000);
  750.         break;
  751.     case EXCALIBUR_UNEQUIP:
  752.         RSItem wep = inventory.getItem(WEAPON_ID);
  753.         if (wep != null)
  754.         wep.doAction("Wield");
  755.         sleep(750, 1000);
  756.         break;
  757.     case POSION_CURE:
  758.         RSItem book = inventory.getItem(PRAYER_BOOK);
  759.         RSItem anti = getPotion(ANTIPOSION_FILTER);
  760.         if (book != null)
  761.         if (book.doAction("Recite-prayer")) {
  762.             sleep(1000);
  763.             break;
  764.         }
  765.         if (anti != null)
  766.         if (anti.doAction("Drink")) {
  767.             sleep(1000);
  768.             break;
  769.         }
  770.         break;
  771.     case FIGHT:
  772.         RSNPC monster = getMonster();
  773.         if (monster != null) {
  774.         if (monster.getName() != null
  775.             && (monster.getName().toLowerCase()
  776.                 .contains("strykewyrm") || monster.getName()
  777.                 .toLowerCase().contains("mound")))
  778.             if (!isAdjacentTileBlocked(getMyPlayer().getLocation(),
  779.                 walking.getCollisionFlags(game.getPlane()))) {
  780.             walking.walkTileMM(getTileOnMinimap(getTileAdjacentToBlock(monster
  781.                 .getLocation())));
  782.             }
  783.         if (monster.isOnScreen()
  784.             && !npcLevels.containsKey(monster.getID())) {
  785.             Point p = monster.getModel() != null ? monster.getModel()
  786.                 .getCentralPoint() : calc.tileToScreen(
  787.                 monster.getLocation(), 0.5d, 0.5d,
  788.                 monster.getHeight() / 2);
  789.             if (calc.distanceBetween(p, mouse.getLocation()) > 2)
  790.             mouse.move(p);
  791.             setLevel(monster);
  792.         }
  793.         if (getMyPlayer().getInteracting() == null) {
  794.             if (!monster.isOnScreen()) {
  795.             walking.walkTileMM(getTileOnMinimap(monster
  796.                 .getLocation()));
  797.             sleep(500, 750);
  798.             } else {
  799.             if (monster.doAction("Attack")) {
  800.                 sleep(500, 750);
  801.             } else if (getMyPlayer().getAnimation() != STOMP_ANIM)
  802.                 if (monster.doAction("Investigate"))
  803.                 sleep(500, 750);
  804.             }
  805.         } else {
  806.             int dist = random(-1, 3) * random(0, 2) * random(0, 100);
  807.             if (dist > 25)
  808.             mouse.moveRandomly(dist, dist + 25);
  809.         }
  810.         slayerMonsterHandle(monster);
  811.         }
  812.         break;
  813.     case PICKUP:
  814.         RSGroundItem rowDrop = groundItems
  815.             .getNearest(new Filter<RSGroundItem>() {
  816.             @Override
  817.             public boolean accept(RSGroundItem t) {
  818.                 return DROPS.accept(t)
  819.                     || (options.lootPrayerExp && BONES_AND_ASHES_GROUND_FILTER
  820.                         .accept(t))
  821.                     || (options.bonesToFruit && BONES_GROUND_FILTER
  822.                         .accept(t));
  823.             }
  824.             });
  825.         boolean bool = false;
  826.         if (rowDrop != null)
  827.         if (rowDrop.getItem() != null)
  828.             if (inventory.getItem(rowDrop.getItem().getID()) != null)
  829.             bool = inventory.getItem(rowDrop.getItem().getID())
  830.                 .getStackSize() >= 2
  831.                 || (rowDrop.getItem().getName() != null && rowDrop
  832.                     .getItem().getName().toLowerCase()
  833.                     .contains("charm"));
  834.  
  835.         if (rowDrop != null && (!inventory.isFull() || bool)) {
  836.         if (!rowDrop.isOnScreen()) {
  837.             walking.walkTileMM(getTileOnMinimap(rowDrop.getLocation()));
  838.             sleep(500, 750);
  839.         }
  840.         rowDrop.doAction("Take "
  841.             + (rowDrop.getItem() != null ? (rowDrop.getItem()
  842.                 .getName() != null ? rowDrop.getItem()
  843.                 .getName() : "") : ""));
  844.         break;
  845.         }
  846.         break;
  847.     case EAT_FOOD:
  848.         RSItem food = getFood();
  849.         if (food == null)
  850.         triggerStop();
  851.         else if (food.doAction("Eat"))
  852.         ;
  853.         break;
  854.     case BURY_BONES_AND_ASHES:
  855.         RSItem doItem;
  856.         while ((doItem = getItemInInventory(BONES_AND_ASHES_FILTER)) != null) {
  857.         if (doItem.doAction("Bury"))
  858.             sleep(500, 600);
  859.         else if (doItem.doAction("Scatter"))
  860.             sleep(500, 600);
  861.         }
  862.         break;
  863.     case BANK_ITEMS:
  864.         if (!bank.isOpen() && !bank.isDepositOpen()) {
  865.         if (!bank.open()) {
  866.             RSObject obj = objects.getNearest(10517);
  867.             if (obj != null) {
  868.             if (!obj.isOnScreen()) {
  869.                 walking.walkTileMM(getTileOnMinimap(obj
  870.                     .getLocation()));
  871.             } else {
  872.                 obj.doAction("Use-quickly");
  873.             }
  874.             }
  875.         }
  876.         }
  877.         if (bank.isOpen() || bank.isDepositOpen()) {
  878.         for (String itemName : options.bankItemNames) {
  879.             int id;
  880.             try {
  881.             id = Integer.valueOf(itemName.trim());
  882.             } catch (NumberFormatException e) {
  883.             id = inventory.getItemID(itemName);
  884.             }
  885.             if (id > 0)
  886.             bank.deposit(id, inventory.getCount(id) > 1 ? 0 : 1);
  887.         }
  888.         }
  889.         break;
  890.     case BONES_TO_FRUIT:
  891.         RSItem tab = getItemInInventory(BONES_TO_FRUIT_FILTER);
  892.         if (tab != null)
  893.         if (tab.doClick(true)) {
  894.             for (byte b = 0; b < 100
  895.                 && getItemInInventory(BONES_FILTER) != null; b++)
  896.             sleep(100, 125);
  897.         }
  898.         break;
  899.     }
  900.     return 500;
  901.     }
  902.  
  903.     public int getDoseCount(String s) {
  904.     int a = s.lastIndexOf("(");
  905.     int b = s.lastIndexOf(")");
  906.     try {
  907.         return Integer.valueOf(s.substring(a + 1, b).trim());
  908.     } catch (NumberFormatException e) {
  909.         return 4;
  910.     }
  911.     }
  912.  
  913.     public RSItem getPotion(Filter<RSItem> itemFilter) {
  914.     int minDosage = 999;
  915.     RSItem it = null;
  916.     for (RSItem i : inventory.getItems())
  917.         if (itemFilter.accept(i)) {
  918.         int dose = getDoseCount(i.getName());
  919.         if (i.getName() != null && dose < minDosage) {
  920.             minDosage = dose;
  921.             it = i;
  922.         }
  923.         }
  924.     return it;
  925.     }
  926.  
  927.     @Override
  928.     public void onRepaint(Graphics render) {
  929.     skillPaint.drawLine(render, 0);
  930.     }
  931.  
  932.     @Override
  933.     public boolean onStart() {
  934.     String s = ((String) JOptionPane.showInputDialog(null,
  935.         "What monster do you want to attack?", "Equinox_ Fighter",
  936.         JOptionPane.QUESTION_MESSAGE));
  937.     if (s == null)
  938.         s = "";
  939.     options.monsterNames = s.split(",");
  940.     s = ((String) JOptionPane.showInputDialog(null,
  941.         "What items do you want to pick?", "Equinox_ Fighter",
  942.         JOptionPane.QUESTION_MESSAGE));
  943.     if (s == null)
  944.         s = "";
  945.     options.pickNames = s.length() > 0 ? s.split(",") : new String[] {};
  946.     if (settings.getSetting(394) > 0)
  947.         options.stopAtEndOfTask = JOptionPane.showOptionDialog(null,
  948.             "Would you like the bot to stop at the end of your task?",
  949.             "Equinox_ Fighter", JOptionPane.YES_NO_OPTION,
  950.             JOptionPane.QUESTION_MESSAGE, null, null, 0) == JOptionPane.YES_OPTION;
  951.     else
  952.         options.stopAtEndOfTask = false;
  953.  
  954.     options.lootPrayerExp = JOptionPane.showOptionDialog(null,
  955.         "Loot bones and ashes?", "Equinox_ Fighter",
  956.         JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
  957.         null, 0) == JOptionPane.YES_OPTION;
  958.     options.takeROWDrops = JOptionPane.showOptionDialog(null,
  959.         "Take ring of wealth drops?", "Equinox_ Fighter",
  960.         JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
  961.         null, 0) == JOptionPane.YES_OPTION;
  962.     options.bonesToFruit = getItemInInventory(BONES_TO_FRUIT_FILTER) != null;
  963.     HAS_EXCALIBUR = inventory.contains(EXCALIBUR_ID);
  964.     RSItem wep = equipment.getItem(Equipment.WEAPON);
  965.     RSItem quiver = equipment.getItem(Equipment.AMMO);
  966.     if (quiver != null)
  967.         options.arrowID = quiver.getID();
  968.     else
  969.         options.arrowID = -1;
  970.     if (wep != null && wep.getID() >= 0) {
  971.         WEAPON_ID = wep.getID();
  972.         log.info("Wep id: " + WEAPON_ID);
  973.     } else {
  974.         log.severe("You must start with a weapon wielded!");
  975.         return false;
  976.     }
  977.     options.familiar = getFamiliar();
  978.     if (options.familiar != null) {
  979.         log.info("Familiar: "
  980.             + PaintFormatter.properCaseAll(options.familiar.name()));
  981.     }
  982.     skillPaint = new SkillPaint(skills);
  983.     geItemLoader = new GEItemLoader(this, grandExchange);
  984.     return true;
  985.     }
  986.  
  987.     public void rest() {
  988.     for (int d = 0; d < 5; d++) {
  989.         interfaces.getComponent(walking.INTERFACE_RUN_ORB, 1).doAction(
  990.             "Rest");
  991.         mouse.moveSlightly();
  992.         sleep(random(400, 600));
  993.         int anim = players.getMyPlayer().getAnimation();
  994.         if (anim == 12108 || anim == 2033 || anim == 2716 || anim == 11786
  995.             || anim == 5713) {
  996.         break;
  997.         }
  998.     }
  999.     }
  1000.  
  1001.     public void slayerMonsterHandle(RSNPC n) {
  1002.     // Killing blows
  1003.     String name = n.getName().trim().toLowerCase();
  1004.     if (n.getHPPercent() <= 5
  1005.         || (n.getHPPercent() == 100 && n.isInCombat()))
  1006.         if (name.contains("garg")) {
  1007.         n.doAction("Smash");
  1008.         log.info("SMASH!");
  1009.         }
  1010.     }
  1011.  
  1012.     public void triggerStop() {
  1013.     for (byte b1 = 0; b1 < 5 && game.isLoggedIn(); b1++) {
  1014.         game.logout(false);
  1015.         sleep(10000, 11000);
  1016.     }
  1017.     stopScript(true);
  1018.     }
  1019.  
  1020.     private int getLevel(RSNPC monster) {
  1021.     if (monster.getLevel() >= 0)
  1022.         return monster.getLevel();
  1023.     if (npcLevels.containsKey(monster.getID()))
  1024.         return npcLevels.get(monster.getID()).intValue();
  1025.     return -1;
  1026.     }
  1027.  
  1028.     private void setLevel(RSNPC monster) {
  1029.     String promise = null;
  1030.     int pCount = 0;
  1031.     for (String s : menu.getItems())
  1032.         if (s != null && s.toLowerCase().contains("(level: ")) {
  1033.         promise = s;
  1034.         pCount++;
  1035.         }
  1036.     if (promise != null && pCount <= 2) {
  1037.         int start = promise.toLowerCase().lastIndexOf("level: ")
  1038.             + "level: ".length();
  1039.         int end = promise.toLowerCase().lastIndexOf(")");
  1040.         String lvl = promise.substring(start, end).trim();
  1041.         try {
  1042.         npcLevels.put(monster.getID(), Integer.valueOf(lvl));
  1043.         return;
  1044.         } catch (Exception e) {
  1045.  
  1046.         }
  1047.     }
  1048.     if (monster.getActions() != null)
  1049.         for (String s : monster.getActions())
  1050.         if (s != null && s.toLowerCase().contains("level: ")) {
  1051.             int start = s.toLowerCase().lastIndexOf("level: ")
  1052.                 + "level: ".length();
  1053.             int end = s.toLowerCase().lastIndexOf(")");
  1054.             String lvl = s.substring(start, end).trim();
  1055.             try {
  1056.             npcLevels.put(monster.getID(), Integer.valueOf(lvl));
  1057.             return;
  1058.             } catch (Exception e) {
  1059.  
  1060.             }
  1061.         }
  1062.     }
  1063.  
  1064.     private List<RSTile> successors(RSTile t, int[][] flags, boolean blocked) {
  1065.     LinkedList<RSTile> tiles = new LinkedList<RSTile>();
  1066.     try {
  1067.         int x = t.getX(), y = t.getY();
  1068.         int offX = game.getBaseX() - 1, offY = game.getBaseY() - 1;
  1069.         int f_x = x - offX, f_y = y - offY;
  1070.         int upper = flags.length;
  1071.         for (int modX = -1; modX <= 1; modX++) {
  1072.         for (int modY = -1; modY <= 1; modY++) {
  1073.             if ((modY != 0 || modX != 0) && f_y + modY >= 0
  1074.                 && f_y + modY < upper && f_x + modX >= 0
  1075.                 && f_x + modX < upper) {
  1076.             if (blocked
  1077.                 && (flags[f_x + modX][f_y + modY] & BLOCKED) != 0)
  1078.                 tiles.add(new RSTile(x + modX, y + modY));
  1079.             else if (!blocked
  1080.                 && (flags[f_x + modX][f_y + modY] & BLOCKED) == 0)
  1081.                 tiles.add(new RSTile(x + modX, y + modY));
  1082.             }
  1083.         }
  1084.         }
  1085.     } catch (Exception e) {
  1086.     }
  1087.     return tiles;
  1088.     }
  1089.  
  1090.     public static class OptionsClass {
  1091.     int arrowID = 0;
  1092.     String[] bankItemNames = {};
  1093.     boolean bonesToFruit = false;
  1094.     boolean lootPrayerExp = false;
  1095.     String[] monsterNames = {};
  1096.     String[] pickNames = {};
  1097.     boolean stopAtEndOfTask = false;
  1098.     boolean takeROWDrops = false;
  1099.     boolean lowestLevelFirst = false;
  1100.     Familiar familiar = null;
  1101.  
  1102.     /**
  1103.      * A range class for randomized items
  1104.      *
  1105.      * @author Equinox_
  1106.      *
  1107.      */
  1108.     public static class Range {
  1109.         public int MAX;
  1110.         public int MIN;
  1111.  
  1112.         public Range() {
  1113.         MAX = 1;
  1114.         MIN = -1;
  1115.         }
  1116.  
  1117.         /**
  1118.          *
  1119.          * @param min
  1120.          *            The inclusive lower bound
  1121.          * @param max
  1122.          *            The inclusive upper bound
  1123.          */
  1124.         public Range(int min, int max) {
  1125.         MAX = Math.max(min, max) + 1;
  1126.         MIN = Math.min(min, max);
  1127.         }
  1128.  
  1129.         /**
  1130.          * Returns a linearly distributed pseudorandom integer.
  1131.          *
  1132.          * @return Random integer min <= n < max.
  1133.          */
  1134.         public int random() {
  1135.         return MIN + (MAX == MIN ? 0 : new Random().nextInt(MAX - MIN));
  1136.         }
  1137.  
  1138.         /**
  1139.          * Returns a normally distributed pseudorandom integer about a mean
  1140.          * centered between min and max with a provided standard deviation.
  1141.          *
  1142.          * @param sd
  1143.          *            The standard deviation. A higher value will increase
  1144.          *            the probability of numbers further from the mean being
  1145.          *            returned.
  1146.          * @return Random integer min <= n < max from the normal
  1147.          *         distribution described by the parameters.
  1148.          */
  1149.         public int random(int sd) {
  1150.         int mean = MIN + (MAX - MIN) / 2;
  1151.         int rand;
  1152.         do {
  1153.             rand = (int) (new Random().nextGaussian() * sd + mean);
  1154.         } while (rand < MIN || rand >= MAX);
  1155.         return rand;
  1156.         }
  1157.  
  1158.         /**
  1159.          * Returns a normally distributed pseudorandom integer about a mean
  1160.          * centered between min and max with a calculated standard
  1161.          * deviation.
  1162.          *
  1163.          * @return Random integer min <= n < max from the normal
  1164.          *         distribution described by the parameters.
  1165.          */
  1166.         public int randomNormalDistribution() {
  1167.         int mean = MIN + (MAX - MIN) / 2;
  1168.         int rand;
  1169.         int sd = (MAX - MIN) / 3;
  1170.         do {
  1171.             rand = (int) (new Random().nextGaussian() * sd + mean);
  1172.         } while (rand < MIN || rand >= MAX);
  1173.         return rand;
  1174.         }
  1175.  
  1176.         @Override
  1177.         public String toString() {
  1178.         return MIN + "-" + MAX;
  1179.         }
  1180.     }
  1181.     }
  1182.  
  1183.     /**
  1184.      * Used to format data into more conventional formats
  1185.      *
  1186.      * @author Equinox_
  1187.      *
  1188.      */
  1189.     public static class PaintFormatter {
  1190.     /**
  1191.      * Converts an array of strings into one string, using commas and 'and' <br>
  1192.      * <br>
  1193.      * Examples: <br>
  1194.      * {"option1"} returns "option1"<br>
  1195.      * {"option1","option2"} returns "option1 and option2"<br>
  1196.      * {"op1","op2","op3"} returns "op1, op2, and op3"<br>
  1197.      * <br>
  1198.      *
  1199.      * @param list
  1200.      *            The array of strings making up the list.
  1201.      * @return The properly formatted string
  1202.      */
  1203.     public static String formatList(String[] list) {
  1204.         String s = "";
  1205.         if (list != null)
  1206.         if (list.length == 2) {
  1207.             s = list[0] + " and " + list[1];
  1208.         } else if (list.length > 2) {
  1209.             for (int i = 0; i < list.length - 1; i++)
  1210.             s += list[i] + ", ";
  1211.             s += "and " + list[list.length - 1];
  1212.         } else if (list.length == 1)
  1213.             s = list[0];
  1214.         return s;
  1215.     }
  1216.  
  1217.     /**
  1218.      * Formats a specified amount into thousands, millions or billions, then
  1219.      * adds the proper suffix
  1220.      *
  1221.      * @param money
  1222.      *            the amount of money
  1223.      * @return the formatted string
  1224.      */
  1225.     public static String getFormattedMoney(long money) {
  1226.         /*
  1227.          * String suffix = ""; int t = 1; if (money >= 10000) { t *= 1000;
  1228.          * suffix = "K"; } if (money / t > 10000) { t *= 1000; suffix = "M";
  1229.          * } if (money / t > 10000) { t *= 1000; suffix = "B"; } return
  1230.          * String.valueOf((money / t)) + suffix;
  1231.          */
  1232.         return new DecimalFormat("###,###,###,###,###,###").format(money);
  1233.     }
  1234.  
  1235.     /**
  1236.      * Converts the milliseconds to DD:HH:MM:SS with the days optional.
  1237.      *
  1238.      * @param timeMillis
  1239.      *            the number of milliseconds
  1240.      * @return the properly formatted time as a String
  1241.      */
  1242.     public static String getFormattedTime(final long timeMillis) {
  1243.         return getFormattedTime(timeMillis, ":", false);
  1244.     }
  1245.  
  1246.     /**
  1247.      * Formats time to DD:HH:MM:SS:MSMS with days and millis optional
  1248.      *
  1249.      * @param timeMillis
  1250.      *            long milliseconds of time
  1251.      * @param sep
  1252.      *            String seperation character
  1253.      * @param millisInc
  1254.      *            boolean include milliseconds
  1255.      * @return
  1256.      */
  1257.     public static String getFormattedTime(final long timeMillis,
  1258.         String sep, boolean millisInc) {
  1259.         long millis = timeMillis;
  1260.         final long days = millis / (24 * 1000 * 60 * 60);
  1261.         millis -= days * (24 * 1000 * 60 * 60);
  1262.         final long hours = millis / (1000 * 60 * 60);
  1263.         millis -= hours * 1000 * 60 * 60;
  1264.         final long minutes = millis / (1000 * 60);
  1265.         millis -= minutes * 1000 * 60;
  1266.         final long _seconds = millis / 1000;
  1267.         millis -= _seconds * 1000;
  1268.         String dayString = String.valueOf(days);
  1269.         String hoursString = String.valueOf(hours);
  1270.         String minutesString = String.valueOf(minutes);
  1271.         String secondsString = String.valueOf(_seconds);
  1272.         if (hours < 10) {
  1273.         hoursString = 0 + hoursString;
  1274.         }
  1275.         if (minutes < 10) {
  1276.         minutesString = 0 + minutesString;
  1277.         }
  1278.         if (_seconds < 10) {
  1279.         secondsString = 0 + secondsString;
  1280.         }
  1281.         String s = "";
  1282.         if (days > 0)
  1283.         s = dayString + sep;
  1284.         s += hoursString + sep + minutesString + sep + secondsString;
  1285.         if (millisInc)
  1286.         s += sep + String.valueOf(millis);
  1287.         return s;
  1288.     }
  1289.  
  1290.     /**
  1291.      * Converts the first letter of every word to uppercase, and the rest
  1292.      * lowercase.
  1293.      *
  1294.      * @param s
  1295.      *            The input String
  1296.      * @return the properly formatted string
  1297.      */
  1298.     public static String properCaseAll(String s) {
  1299.         String[] words = s.split(" ");
  1300.         String result = "";
  1301.         for (int i = 0; i < words.length; i++) {
  1302.         words[i] = words[i].substring(0, 1).toUpperCase()
  1303.             + words[i].substring(1).toLowerCase();
  1304.         result += " " + words[i];
  1305.         }
  1306.         return result.substring(1);
  1307.     }
  1308.  
  1309.     /**
  1310.      * Capitalizes the first letter of every sentence, with every other
  1311.      * letter lowercase.
  1312.      *
  1313.      * @param s
  1314.      *            The input string
  1315.      * @return The properly formatted String
  1316.      */
  1317.     public static String properCaseFirst(String s) {
  1318.         String[] sentences = new String[] { s };
  1319.         if (s.contains("."))
  1320.         sentences = s.split(".");
  1321.         String result = "";
  1322.         for (int i = 0; i < sentences.length; i++) {
  1323.         String f = sentences[i].substring(0, 1).toUpperCase();
  1324.         sentences[i] = f + sentences[i].substring(1).toLowerCase();
  1325.         result += "." + sentences[i];
  1326.         }
  1327.         return result.substring(1);
  1328.     }
  1329.     }
  1330.  
  1331.     enum State {
  1332.     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
  1333.     }
  1334.  
  1335.     public RSItem getPotionDrink() {
  1336.     for (Potion p : Potion.values()) {
  1337.         if (p.shouldBoost(skills)) {
  1338.         RSItem pot = p.getPot(inventory.getItems());
  1339.         if (pot != null)
  1340.             return pot;
  1341.         }
  1342.     }
  1343.     return null;
  1344.     }
  1345.  
  1346.     @Override
  1347.     public void messageReceived(MessageEvent e) {
  1348.     String msg = e.getMessage().toLowerCase();
  1349.     if (e.getID() == MessageEvent.MESSAGE_SERVER
  1350.         || e.getID() == MessageEvent.MESSAGE_ACTION) {
  1351.         if (msg.contains("you drink") && msg.contains("antifire potion")) {
  1352.         isAntifire = true;
  1353.         } else if ((msg.contains("resistance to dragonfire") && msg
  1354.             .contains("run out"))
  1355.             || msg.contains("your shield absorbs most of the dragon's fiery breath")
  1356.             || msg.contains("horribly burnt by the dragon")) {
  1357.         isAntifire = false;
  1358.         } else if (msg
  1359.             .contains("you have 1 minute before your familiar vanishes")) {
  1360.         familiarExpiry = true;
  1361.         } else if (msg.contains("you sacrifice a pouch to")) {
  1362.         familiarExpiry = false;
  1363.         }
  1364.     }
  1365.     }
  1366.  
  1367.     private static class GEItemLoader extends Thread {
  1368.     private static Map<Integer, Integer> prices = new HashMap<Integer, Integer>();
  1369.     private LinkedList<Integer> loadQueue = new LinkedList<Integer>();
  1370.     private final GrandExchange ge;
  1371.     private final Script script;
  1372.  
  1373.     public GEItemLoader(EquinoxFighter s, GrandExchange ge) {
  1374.         super("GEItem Loader" + s.getClass().getName());
  1375.         this.ge = ge;
  1376.         this.script = s;
  1377.         this.start();
  1378.     }
  1379.  
  1380.     public int getPrice(int id) {
  1381.         if (prices.containsKey(id))
  1382.         return prices.get(id);
  1383.         if (!loadQueue.contains(id))
  1384.         loadQueue.add(id);
  1385.         return 0;
  1386.     }
  1387.  
  1388.     @Override
  1389.     public void run() {
  1390.         while (script.isRunning()) {
  1391.         if (loadQueue.size() > 0) {
  1392.             int loadID = loadQueue.getFirst();
  1393.             GEItem itm = ge.lookup(loadID);
  1394.             if (itm != null) {
  1395.             prices.put(loadID, itm.getGuidePrice());
  1396.             loadQueue.removeFirst();
  1397.             }
  1398.         }
  1399.         }
  1400.     }
  1401.     }
  1402.  
  1403.     private static class SkillPaint implements MouseListener, TextPaintListener {
  1404.     private Skills skills;
  1405.     private SkillTracker tracker;
  1406.     private int[] goalLevels;
  1407.     private Map<Integer, Rectangle> goalMap = new HashMap<Integer, Rectangle>();
  1408.     private int[] skillIDs;
  1409.  
  1410.     public SkillTracker getTracker() {
  1411.         return tracker;
  1412.     }
  1413.  
  1414.     public SkillPaint(Skills skills, int... skillIDs) {
  1415.         this.skills = skills;
  1416.         this.skillIDs = skillIDs;
  1417.         this.tracker = new SkillTracker(skills);
  1418.         goalLevels = new int[Skills.SKILL_NAMES.length];
  1419.     }
  1420.  
  1421.     @Override
  1422.     public int drawLine(Graphics render, int line) {
  1423.         if (skillIDs.length > 0) {
  1424.         for (int skill : skillIDs) {
  1425.             if (skills.getCurrentExp(skill) == -1)
  1426.             continue;
  1427.             if (tracker.hasRecentlyTrained(skill)) {
  1428.             drawSkillLine(line, skill, render);
  1429.             line++;
  1430.             } else {
  1431.             goalMap.remove(skill);
  1432.             }
  1433.         }
  1434.         } else {
  1435.         for (int skill = 0; skill < Skills.SKILL_NAMES.length; skill++) {
  1436.             if (skills.getCurrentExp(skill) == -1)
  1437.             continue;
  1438.             if (tracker.hasRecentlyTrained(skill)) {
  1439.             drawSkillLine(line, skill, render);
  1440.             line++;
  1441.             } else {
  1442.             goalMap.remove(skill);
  1443.             }
  1444.         }
  1445.         }
  1446.         return line;
  1447.     }
  1448.  
  1449.     private void drawSkillLine(int row, int skill, Graphics render) {
  1450.         final String skillName = PaintFormatter
  1451.             .properCaseAll(Skills.SKILL_NAMES[skill]);
  1452.         if (goalLevels[skill] <= tracker.getCurrentLevel(skill))
  1453.         goalLevels[skill] = tracker.getCurrentLevel(skill) + 1;
  1454.         int goalLevel = goalLevels[skill];
  1455.         final String ttg = PaintFormatter.getFormattedTime(tracker
  1456.             .getMillisToLevel(skill, goalLevel));
  1457.         final String perHour = PaintFormatter
  1458.             .getFormattedMoney((int) tracker.getExpPerHour(skill))
  1459.             + " exp/hr";
  1460.         final String line = skillName + ": " + ttg + " 'till " + goalLevel
  1461.             + " @ " + perHour;
  1462.         final FontMetrics metrics = render.getFontMetrics();
  1463.         final int height = metrics.getHeight() + 4; // height + gap
  1464.         final int y = row * height + 15 + 19;
  1465.         final String buttons = (goalLevel > tracker.getCurrentLevel(skill) + 1 ? "<"
  1466.             : " ")
  1467.             + "  "
  1468.             + (goalLevel < tracker.getMaxLevel(skill) ? ">" : " ");
  1469.         Rectangle rect = metrics.getStringBounds(buttons, render)
  1470.             .getBounds();
  1471.         rect = new Rectangle(6, y - rect.height + 3, rect.width + 2,
  1472.             rect.height - 2);
  1473.         this.goalMap.put(skill, rect);
  1474.         render.setColor(Color.GREEN);
  1475.         render.drawString(buttons, 7, y);
  1476.         render.drawString(line, 7 + rect.width + 5, y);
  1477.     }
  1478.  
  1479.     private static class SkillTracker {
  1480.         private Skills skills;
  1481.         private int[] startExp;
  1482.         private int[] newExp;
  1483.         private long[] lastTrained;
  1484.         private long start;
  1485.  
  1486.         public SkillTracker(Skills skills) {
  1487.         this.skills = skills;
  1488.         this.start = System.currentTimeMillis();
  1489.         this.startExp = new int[Skills.SKILL_NAMES.length];
  1490.         this.lastTrained = new long[Skills.SKILL_NAMES.length];
  1491.         this.newExp = new int[Skills.SKILL_NAMES.length];
  1492.         for (int i = 0; i < Skills.SKILL_NAMES.length; i++) {
  1493.             this.startExp[i] = skills.getCurrentExp(i);
  1494.             this.newExp[i] = this.startExp[i];
  1495.         }
  1496.         }
  1497.  
  1498.         public long getElapsedTime() {
  1499.         return System.currentTimeMillis() - start;
  1500.         }
  1501.  
  1502.         public int getExpGain(int skill) {
  1503.         return skills.getCurrentExp(skill) - startExp[skill];
  1504.         }
  1505.  
  1506.         public int getLevelGain(int skill) {
  1507.         return getCurrentLevel(skill) - getStartLevel(skill);
  1508.         }
  1509.  
  1510.         private int getStartLevel(int skill) {
  1511.         int sLvl = Skills.getLevelAt(startExp[skill]);
  1512.         if (sLvl > getMaxLevel(skill))
  1513.             sLvl = getMaxLevel(skill);
  1514.         return sLvl;
  1515.         }
  1516.  
  1517.         public int getMaxLevel(int skill) {
  1518.         return skill == Skills.DUNGEONEERING ? 120 : 99;
  1519.         }
  1520.  
  1521.         private int getCurrentLevel(int skill) {
  1522.         int sLvl = skills.getRealLevel(skill);
  1523.         if (sLvl > getMaxLevel(skill))
  1524.             sLvl = getMaxLevel(skill);
  1525.         return sLvl;
  1526.         }
  1527.  
  1528.         public double getExpPerMilli(int skill) {
  1529.         double gain = getExpGain(skill);
  1530.         double time = getElapsedTime();
  1531.         return gain / time;
  1532.         }
  1533.  
  1534.         public double getExpPerSecond(int skill) {
  1535.         return getExpPerMilli(skill) * 1000d;
  1536.         }
  1537.  
  1538.         public double getExpPerHour(int skill) {
  1539.         return getExpPerSecond(skill) * 3600d;
  1540.         }
  1541.  
  1542.         public long getMillisToExp(int skill, int exp) {
  1543.         int expNeed = exp - skills.getCurrentExp(skill);
  1544.         if (expNeed <= 0 || getExpGain(skill) <= 0)
  1545.             return 0;
  1546.         return (long) (((double) expNeed) / getExpPerMilli(skill));
  1547.         }
  1548.  
  1549.         public long getMillisToLevel(int skill, int level) {
  1550.         if (level > getMaxLevel(skill) || level < 0)
  1551.             return 0;
  1552.         return getMillisToExp(skill, Skills.XP_TABLE[level]);
  1553.         }
  1554.  
  1555.         public boolean hasTrained(int skill) {
  1556.         int cExp = skills.getCurrentExp(skill);
  1557.         if (newExp[skill] < cExp) {
  1558.             lastTrained[skill] = System.currentTimeMillis();
  1559.         }
  1560.         newExp[skill] = cExp;
  1561.         return cExp > startExp[skill];
  1562.         }
  1563.  
  1564.         public boolean hasRecentlyTrained(int skill) {
  1565.         int cExp = skills.getCurrentExp(skill);
  1566.         if (newExp[skill] < cExp) {
  1567.             lastTrained[skill] = System.currentTimeMillis();
  1568.         }
  1569.         newExp[skill] = cExp;
  1570.         return lastTrained[skill] + 60000 > System.currentTimeMillis();
  1571.         }
  1572.     }
  1573.  
  1574.     @Override
  1575.     public void mouseClicked(MouseEvent e) {
  1576.         for (Integer skill : goalMap.keySet()) {
  1577.         Rectangle r = goalMap.get(skill);
  1578.         if (r.contains(e.getPoint())) {
  1579.             int cLvl = goalLevels[skill.intValue()];
  1580.             if (e.getPoint().x < r.x + (r.width / 2)) {
  1581.             cLvl -= 1;
  1582.             } else {
  1583.             cLvl += 1;
  1584.             }
  1585.             if (cLvl > tracker.getCurrentLevel(skill)
  1586.                 && cLvl <= tracker.getMaxLevel(skill)) {
  1587.             goalLevels[skill.intValue()] = cLvl;
  1588.             return;
  1589.             }
  1590.         }
  1591.         }
  1592.     }
  1593.  
  1594.     @Override
  1595.     public void mouseEntered(MouseEvent arg0) {
  1596.     }
  1597.  
  1598.     @Override
  1599.     public void mouseExited(MouseEvent arg0) {
  1600.     }
  1601.  
  1602.     @Override
  1603.     public void mousePressed(MouseEvent arg0) {
  1604.     }
  1605.  
  1606.     @Override
  1607.     public void mouseReleased(MouseEvent arg0) {
  1608.     }
  1609.     }
  1610.  
  1611.     public Familiar getFamiliar() {
  1612.     RSNPC familiar = summoning.getFamiliar() != null ? summoning
  1613.         .getFamiliar().getNPC() : null;
  1614.     if (familiar != null) {
  1615.         for (Familiar f : Familiar.values())
  1616.         if (f.getNpcID() == familiar.getID())
  1617.             return f;
  1618.     }
  1619.     return null;
  1620.     }
  1621.  
  1622.     @Override
  1623.     public void mouseClicked(MouseEvent arg0) {
  1624.     skillPaint.mouseClicked(arg0);
  1625.     }
  1626.  
  1627.     @Override
  1628.     public void mouseEntered(MouseEvent arg0) {
  1629.     }
  1630.  
  1631.     @Override
  1632.     public void mouseExited(MouseEvent arg0) {
  1633.     }
  1634.  
  1635.     @Override
  1636.     public void mousePressed(MouseEvent arg0) {
  1637.     }
  1638.  
  1639.     @Override
  1640.     public void mouseReleased(MouseEvent arg0) {
  1641.     }
  1642. }
Advertisement
Add Comment
Please, Sign In to add comment