Equinox

EquinoxLividFarm.java (Paint BETA)

Oct 2nd, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.02 KB | None | 0 0
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.FontMetrics;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Image;
  8. import java.awt.Point;
  9. import java.awt.Polygon;
  10. import java.io.IOException;
  11. import java.net.URL;
  12. import java.text.DecimalFormat;
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17.  
  18. import javax.imageio.ImageIO;
  19.  
  20. import org.rsbot.event.listeners.PaintListener;
  21. import org.rsbot.script.Script;
  22. import org.rsbot.script.ScriptManifest;
  23. import org.rsbot.script.methods.Game.Tab;
  24. import org.rsbot.script.methods.Objects;
  25. import org.rsbot.script.methods.Settings;
  26. import org.rsbot.script.methods.Skills;
  27. import org.rsbot.script.util.Filter;
  28. import org.rsbot.script.wrappers.RSComponent;
  29. import org.rsbot.script.wrappers.RSInterface;
  30. import org.rsbot.script.wrappers.RSItem;
  31. import org.rsbot.script.wrappers.RSNPC;
  32. import org.rsbot.script.wrappers.RSObject;
  33. import org.rsbot.script.wrappers.RSTile;
  34.  
  35. @ScriptManifest(authors = { "Equinox_" }, name = "Equinox Livid Farm", version = 2.1, description = "Does the Livid Farm Minigame")
  36. public class EquinoxLividFarm extends Script implements PaintListener {
  37.     public final static int[] ANIM_IDS = {/* 7898, 4432, 4413 */897 };
  38.     public final static int ASTRAL_ID = 9075, NATURE_ID = 561, LAW_RUNE = 563;
  39.     public final static RSTile CENTRAL_FARM = new RSTile(2111, 3946);
  40.     public final static int CURE_INTERFACE = 1081;
  41.     public final static String[] ENCOURAGE_STRINGS = {
  42.         "keep going! we can do this", "keep going! you're doing so well",
  43.         "come on, you're doing so well", "extraordinary",
  44.         "look at all the produce being made", "lokar will really",
  45.         "you're doing a fantastic job" };
  46.     public final static RSTile[] FENCE = { new RSTile(2116, 3953),
  47.         new RSTile(2118, 3953), new RSTile(2108, 3953),
  48.         new RSTile(2120, 3945), new RSTile(2120, 3951),
  49.         new RSTile(2120, 3946) };
  50.     public final static int LIVID_BUNDLE = 20705;
  51.     public final static int LIVID_PLANT_ITEM = 20704;
  52.     public final static RSTile[] LIVID_PLANTS = { new RSTile(2098, 3943),
  53.         new RSTile(2100, 3943), new RSTile(2102, 3943),
  54.         new RSTile(2104, 3943), new RSTile(2106, 3943),
  55.         new RSTile(2098, 3946), new RSTile(2100, 3946),
  56.         new RSTile(2102, 3946), new RSTile(2104, 3946),
  57.         new RSTile(2106, 3946), new RSTile(2098, 3949),
  58.         new RSTile(2100, 3949), new RSTile(2102, 3949),
  59.         new RSTile(2104, 3949), new RSTile(2106, 3949) };
  60.     public final static int[] LIVID_STRAIN_ID = { 64739, 64734, 64735, 64743 };
  61.     public final static int[][] LIVID_STRAINS = {
  62.         { 40461, 40462, 40460, 40463 }, { 40464, 40486, 40488, 40487 },
  63.         { 40499, 40492, 40504 }, { 40534, 40532, 40533, 40505 } };
  64.     public final static int LOG_BIN = 40444;
  65.     public final static int LUNAR_LOGS = 20702;
  66.     public final static int LUNAR_PLANKS = 20703;
  67.     public final static int PAULINE = 13621;
  68.     public final static int PRODUCE_BIN = 40441;
  69.     public final static int TRADE_WAGON = 40443;
  70.     public State state = State.Wait;
  71.     Priority[] priorityMap = { Priority.Harvesting, Priority.Farming,
  72.         Priority.Fencing,
  73.         /* Priority.Harvesting, */Priority.Randoms };
  74.     private int produceStart;
  75.     private SkillTracker skillTracker;
  76.     private long startTime = 0;
  77.     private boolean onScreenDebug = false;
  78.     private boolean onMinimapDebug = false;
  79.  
  80.     public RSTile getBrokenFencePost() {
  81.     for (RSTile t : FENCE) {
  82.         if (!SettingsData.isFencePostRepaired(settings, t)) {
  83.         return t;
  84.         }
  85.     }
  86.     return null;
  87.     }
  88.  
  89.     public RSComponent getChatComponent(String... reqContainsOneOf) {
  90.     RSInterface[] valid = interfaces.getAll();
  91.     for (RSInterface iface : valid) {
  92.         if (iface.getIndex() != 137) {
  93.         int len = iface.getChildCount();
  94.         for (int i = 0; i < len; i++) {
  95.             RSComponent child = iface.getComponent(i);
  96.             if (child.isValid() && child.getAbsoluteY() > 300) {
  97.             for (String s : reqContainsOneOf)
  98.                 if (child.getText().toLowerCase()
  99.                     .contains(s.toLowerCase())
  100.                     || s.toLowerCase().contains(
  101.                         child.getText().toLowerCase()))
  102.                 return child;
  103.             }
  104.         }
  105.         }
  106.     }
  107.     return null;
  108.     }
  109.  
  110.     public State getFarmingState() {
  111.     RSObject lividPlant = getLividPlant(LividState.Empty, LividState.Sick);
  112.     LividState chosenState = lividPlant != null ? getLividState(lividPlant)
  113.         : null;
  114.     if (lividPlant != null && chosenState == LividState.Empty
  115.         && inventory.getCount(true, ASTRAL_ID) >= 3
  116.         && inventory.getCount(true, NATURE_ID) >= 2)
  117.         return State.Fertilize;
  118.     else if (lividPlant != null && chosenState == LividState.Sick
  119.         && inventory.contains(ASTRAL_ID))
  120.         return State.Cure;
  121.     return null;
  122.     }
  123.  
  124.     public RSTile getFenceWalk(RSTile t) {
  125.     int deltaX = CENTRAL_FARM.getX() - t.getX();
  126.     int deltaY = CENTRAL_FARM.getY() - t.getY();
  127.     double dist = calc.distanceBetween(t, CENTRAL_FARM);
  128.     double eX = deltaX / dist, eY = deltaY / dist;
  129.     return new RSTile(t.getX() + (int) (eX * 3), t.getY() + (int) (eY * 3));
  130.     }
  131.  
  132.     public State getFencingState() {
  133.     if (inventory.contains(LUNAR_LOGS)
  134.         && inventory.getCount(true, ASTRAL_ID) >= 2
  135.         && inventory.contains(NATURE_ID))
  136.         return State.Make_Planks;
  137.     else if (inventory.getCount(LUNAR_LOGS, LUNAR_PLANKS) < 3)
  138.         return State.Get_Logs;
  139.     else if (getBrokenFencePost() != null
  140.         && inventory.contains(LUNAR_PLANKS))
  141.         return State.Repair_Fence;
  142.     return null;
  143.     }
  144.  
  145.     public RSTile getHalfTile(RSTile base) {
  146.     RSTile me = getMyPlayer().getLocation();
  147.     int deltaX = (int) ((base.getX() - me.getX()) / 2f);
  148.     int deltaY = (int) ((base.getY() - me.getY()) / 2f);
  149.     return new RSTile(me.getX() + deltaX, me.getY() + deltaY);
  150.     }
  151.  
  152.     public State getHarvestingState() {
  153.     if (inventory.getCount(LIVID_PLANT_ITEM) >= 5
  154.         && inventory.getCount(true, ASTRAL_ID) >= 2)
  155.         return State.Bundle_Produce;
  156.     else if (inventory.getCount(LIVID_BUNDLE) >= 2
  157.         || (inventory.contains(LIVID_BUNDLE) && !SettingsData
  158.             .isProduceBinFull(settings)))
  159.         return State.Deposit_Produce;
  160.     else if (SettingsData.isProduceBinFull(settings))
  161.         return State.Take_Produce;
  162.     return null;
  163.     }
  164.  
  165.     public RSComponent getLividCure(int lividNum) {
  166.     RSInterface inter = interfaces.get(CURE_INTERFACE);
  167.     if (inter != null && inter.isValid() && inter.getComponents() != null)
  168.         for (RSComponent c : inter.getComponents())
  169.         if (c != null && c.isValid())
  170.             if (c.getModelID() == LIVID_STRAIN_ID[lividNum])
  171.             return c;
  172.     return null;
  173.     }
  174.  
  175.     public RSObject getLividPlant(final LividState... states) {
  176.     return objects.getNearest(new Filter<RSObject>() {
  177.         @Override
  178.         public boolean accept(RSObject t) {
  179.         if (isLividPlant(t)) {
  180.             LividState ls = getLividState(t);
  181.             for (LividState lState : states)
  182.             if (ls == lState)
  183.                 return true;
  184.         }
  185.         return false;
  186.         }
  187.     });
  188.     }
  189.  
  190.     public LividState getLividState(RSObject o) {
  191.     return o != null ? getLividState(o.getLocation()) : null;
  192.     }
  193.  
  194.     public LividState getLividState(RSTile t) {
  195.     switch (SettingsData.getPlantNibble(settings, t)) {
  196.     case 0:
  197.         return LividState.Empty;
  198.     case 1:
  199.         return LividState.Fertile;
  200.     case 2:
  201.         return LividState.Grown;
  202.     case 3:
  203.         return LividState.Sick;
  204.     case 4:
  205.         return LividState.Grown;
  206.     default:
  207.         return null;
  208.     }
  209.     }
  210.  
  211.     public int getLividStrain(RSObject o) {
  212.     for (int i = 0; i < LIVID_STRAINS.length; i++) {
  213.         for (int id : LIVID_STRAINS[i])
  214.         if (id == o.getID())
  215.             return i;
  216.     }
  217.     return -1;
  218.     }
  219.  
  220.     public Polygon getMinimapPolygon(final RSTile t) {
  221.     if (t != null) {
  222.         Polygon poly = new Polygon();
  223.         Point pt = calc.tileToMinimap(t);
  224.         poly.addPoint(pt.x, pt.y);
  225.         pt = calc.tileToMinimap(new RSTile(t.getX(), t.getY() + 1));
  226.         poly.addPoint(pt.x, pt.y);
  227.         pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY() + 1));
  228.         poly.addPoint(pt.x, pt.y);
  229.         pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY()));
  230.         poly.addPoint(pt.x, pt.y);
  231.         for (int i = 0; i < poly.npoints; i++)
  232.         if (poly.xpoints[i] < 0 || poly.ypoints[i] < 0)
  233.             return null;
  234.         return poly;
  235.     }
  236.     return null;
  237.     }
  238.  
  239.     public State getRandomsState() {
  240.     if (inventory.getCount(true, ASTRAL_ID) >= 3
  241.         && inventory.getCount(true, LAW_RUNE) >= 2
  242.         && inventory.contains(NATURE_ID)
  243.         && SettingsData.Random.ENERGISE.isActive(settings))
  244.         return State.Energise;
  245.     return null;
  246.     }
  247.  
  248.     public State getState() {
  249.     if (!isInFarm(getMyPlayer().getLocation()))
  250.         return State.Failsafe;
  251.     else if (isCastingSpell())
  252.         return State.Wait;
  253.     for (Priority prior : priorityMap) {
  254.         State state = null;
  255.         switch (prior) {
  256.         case Randoms:
  257.         state = getRandomsState();
  258.         break;
  259.         case Farming:
  260.         state = getFarmingState();
  261.         break;
  262.         case Fencing:
  263.         state = getFencingState();
  264.         break;
  265.         case Harvesting:
  266.         state = getHarvestingState();
  267.         break;
  268.         }
  269.         if (state != null)
  270.         return state;
  271.     }
  272.     return State.Wait;
  273.     }
  274.  
  275.     public RSTile getTileOnMinimap(RSTile base) {
  276.     if (calc.tileOnMap(base))
  277.         return base;
  278.     RSTile me = getMyPlayer().getLocation();
  279.     int deltaX = base.getX() - me.getX();
  280.     int deltaY = base.getY() - me.getY();
  281.     double dist = calc.distanceBetween(base, me);
  282.     double eX = deltaX / dist, eY = deltaY / dist;
  283.     return new RSTile(me.getX() + (int) (eX * 15), me.getY()
  284.         + (int) (eY * 15));
  285.     }
  286.  
  287.     public boolean isCastingSpell() {
  288.     for (int i : ANIM_IDS)
  289.         if (getMyPlayer().getAnimation() == i)
  290.         return true;
  291.     return false;
  292.     }
  293.  
  294.     public boolean isInFarm(RSTile t) {
  295.     int x = t.getX();
  296.     int y = t.getY();
  297.     if (x >= 2097 && y >= 3942 && x <= 2107 && y <= 3950)
  298.         return true;
  299.     if (x >= 2108 && y >= 3940 && x <= 2114 && y <= 3952)
  300.         return true;
  301.     if (x >= 2115 && y >= 3942 && x <= 2119 && y <= 3952)
  302.         return true;
  303.     return false;
  304.     }
  305.  
  306.     public boolean isLividPlant(RSObject o) {
  307.     if (o.getType() == RSObject.Type.INTERACTABLE)
  308.         for (RSTile t : LIVID_PLANTS)
  309.         if (t.equals(o.getLocation()))
  310.             return true;
  311.     return false;
  312.     }
  313.  
  314.     @Override
  315.     public int loop() {
  316.     if (game.getTab().equals(Tab.INVENTORY)
  317.         && !inventory.contains(ASTRAL_ID))
  318.         stopScript(true);
  319.     switch (state = getState()) {
  320.     case Deposit_Produce:
  321.         RSObject cart = objects.getNearest(TRADE_WAGON);
  322.         if (cart != null) {
  323.         if (cart.isOnScreen()) {
  324.             if (cart.interact("Deposit"))
  325.             sleep(500, 600);
  326.         } else {
  327.             RSTile walk = getTileOnMinimap(cart.getLocation());
  328.             if (walking.getDestination() == null
  329.                 || calc.distanceBetween(walking.getDestination(),
  330.                     walk) > 4) {
  331.             walking.walkTileMM(walk);
  332.             sleep(1000, 2000);
  333.             }
  334.         }
  335.         }
  336.         break;
  337.     case Take_Produce:
  338.         RSObject bin = objects.getNearest(PRODUCE_BIN);
  339.         RSNPC pauline = npcs.getNearest(PAULINE);
  340.         if (bin != null) {
  341.         if (bin.isOnScreen()) {
  342.             if (bin.interact("Take"))
  343.             sleep(1500, 1600);
  344.         } else {
  345.             RSTile walk = getTileOnMinimap(new RSTile(bin.getArea()
  346.                 .getX(), bin.getArea().getY() - 1));
  347.             if (walking.getDestination() == null
  348.                 || calc.distanceBetween(walking.getDestination(),
  349.                     walk) > 4) {
  350.             walking.walkTileMM(walk);
  351.             }
  352.         }
  353.         }
  354.         break;
  355.     case Bundle_Produce:
  356.         RSItem lividPlantItem = inventory.getItem(LIVID_PLANT_ITEM);
  357.         if (lividPlantItem != null)
  358.         if (lividPlantItem.interact("Bunch"))
  359.             sleep(500, 600);
  360.         break;
  361.     case Fertilize:
  362.         RSObject patch = getLividPlant(LividState.Empty);
  363.         if (patch != null) {
  364.         if (patch.isOnScreen()) {
  365.             if (patch.interact("Fertilise E")) {
  366.             for (byte b = 0; b < 50; b++) {
  367.                 RSObject newO = objects.getTopAt(
  368.                     patch.getLocation(),
  369.                     Objects.TYPE_INTERACTABLE);
  370.                 if (newO != null
  371.                     && getLividState(newO) == LividState.Fertile) {
  372.                 break;
  373.                 }
  374.                 sleep(100, 125);
  375.             }
  376.             }
  377.         } else {
  378.             RSTile walk = getTileOnMinimap(getHalfTile(patch
  379.                 .getLocation()));
  380.             if (walking.getDestination() == null
  381.                 || calc.distanceBetween(walking.getDestination(),
  382.                     walk) > 4) {
  383.             walking.walkTileMM(walk);
  384.             sleep(1000, 2000);
  385.             }
  386.         }
  387.         }
  388.         break;
  389.     case Cure:
  390.         RSObject plant = getLividPlant(LividState.Sick);
  391.         if (plant != null) {
  392.         if (plant.isOnScreen()) {
  393.             if (interfaces.get(CURE_INTERFACE) == null
  394.                 || !interfaces.get(CURE_INTERFACE).isValid())
  395.             if (plant.interact("Cure-plant D"))
  396.                 for (byte b = 0; b < 10
  397.                     && (interfaces.get(CURE_INTERFACE) == null || !interfaces
  398.                         .get(CURE_INTERFACE).isValid()); b++)
  399.                 sleep(500, 600);
  400.             RSComponent c = getLividCure(getLividStrain(plant));
  401.             if (c != null && c.isValid())
  402.             if (c.doClick()) {
  403.                 for (byte b = 0; b < 30; b++) {
  404.                 RSObject newO = objects.getTopAt(
  405.                     plant.getLocation(),
  406.                     Objects.TYPE_INTERACTABLE);
  407.                 if (newO != null
  408.                     && getLividState(newO) == LividState.Grown) {
  409.                     break;
  410.                 }
  411.                 sleep(100, 125);
  412.                 }
  413.             }
  414.         } else {
  415.             RSTile walk = getTileOnMinimap(getHalfTile(plant
  416.                 .getLocation()));
  417.             if (walking.getDestination() == null
  418.                 || calc.distanceBetween(walking.getDestination(),
  419.                     walk) > 4) {
  420.             walking.walkTileMM(walk);
  421.             sleep(1000, 2000);
  422.             }
  423.         }
  424.         }
  425.         break;
  426.     case Energise:
  427.         pauline = npcs.getNearest(PAULINE);
  428.         if (pauline != null) {
  429.         for (byte b = 0; b < 100 && !pauline.isOnScreen(); b++) {
  430.             RSTile t = getTileOnMinimap(pauline.getLocation());
  431.             if (walking.getDestination() == null
  432.                 || calc.distanceBetween(t, walking.getDestination()) > 4)
  433.             walking.walkTileMM(t);
  434.             sleep(200, 300);
  435.         }
  436.         if (pauline.interact("Energise")) {
  437.             sleep(1500);
  438.             RSComponent c = null;
  439.             for (byte b = 0; b < 20
  440.                 && (c = getChatComponent(ENCOURAGE_STRINGS)) == null; b++)
  441.             sleep(100, 125);
  442.             if (c != null)
  443.             for (byte b = 0; b < 5; b++)
  444.                 if (c.doClick()) {
  445.                 break;
  446.                 }
  447.         }
  448.         }
  449.         break;
  450.     case Failsafe:
  451.         if (calc.distanceTo(CENTRAL_FARM) > 100) {
  452.         log.severe("Not anywhere near the livid farm!  Quitting.");
  453.         stopScript(true);
  454.         } else {
  455.         RSTile dest = getTileOnMinimap(CENTRAL_FARM);
  456.         if (walking.getDestination() == null
  457.             || calc.distanceBetween(dest, walking.getDestination()) > 5)
  458.             walking.walkTileMM(dest);
  459.         }
  460.         break;
  461.     case Make_Planks:
  462.         RSItem[] itms = inventory.getItems(LUNAR_LOGS);
  463.         if (itms != null && itms.length > 0) {
  464.         for (RSItem itm : itms) {
  465.             if (!(inventory.getCount(true, ASTRAL_ID) >= 2 && inventory
  466.                 .contains(NATURE_ID)))
  467.             break;
  468.             if (itm.interact("Convert")) {
  469.             for (byte b = 0; b < 10 && itm.getID() == LUNAR_LOGS; b++)
  470.                 sleep(100);
  471.             }
  472.         }
  473.         }
  474.         break;
  475.     case Get_Logs:
  476.         RSObject log_bin = objects.getNearest(LOG_BIN);
  477.         if (log_bin != null) {
  478.         if (log_bin.isOnScreen()) {
  479.             int count = inventory.getCount(LUNAR_LOGS, LUNAR_PLANKS);
  480.             log_bin.interact("Take-5");
  481.             sleep(500);
  482.             int to = getMyPlayer().isMoving() ? 50 : 15;
  483.             for (byte b = 0; b < to
  484.                 && inventory.getCount(LUNAR_LOGS, LUNAR_PLANKS) == count; b++)
  485.             sleep(100);
  486.         } else {
  487.             RSTile dest = getTileOnMinimap(log_bin.getLocation());
  488.             if (walking.getDestination() == null
  489.                 || calc.distanceBetween(dest,
  490.                     walking.getDestination()) > 5)
  491.             walking.walkTileMM(dest);
  492.         }
  493.         }
  494.         break;
  495.     case Repair_Fence:
  496.         RSTile broken = getBrokenFencePost();
  497.         if (broken != null && inventory.contains(LUNAR_PLANKS)) {
  498.         RSObject fence = objects.getTopAt(broken);
  499.         if (fence != null && inventory.contains(LUNAR_PLANKS)) {
  500.             if (fence.isOnScreen()) {
  501.             fence.interact("Fix");
  502.             sleep(100, 1250);
  503.             } else {
  504.             RSTile dest = getTileOnMinimap(getFenceWalk(broken));
  505.             if (walking.getDestination() == null
  506.                 || calc.distanceBetween(dest,
  507.                     walking.getDestination()) > 5)
  508.                 walking.walkTileMM(dest);
  509.             }
  510.         }
  511.         }
  512.         break;
  513.     }
  514.     return random(250, 500);
  515.     }
  516.  
  517.     private Image getImage(String url) {
  518.     try {
  519.         return ImageIO.read(new URL(url));
  520.     } catch (IOException e) {
  521.         return null;
  522.     }
  523.     }
  524.  
  525.     private final Color color1 = new Color(102, 102, 102, 211);
  526.     private final Color color2 = new Color(0, 0, 0);
  527.     private final Color color3 = new Color(51, 51, 51, 211);
  528.     private final Color color4 = new Color(0, 255, 51);
  529.  
  530.     private final BasicStroke stroke1 = new BasicStroke(1);
  531.  
  532.     private final Font font1 = new Font("Arial", 0, 10);
  533.     private final Font font2 = new Font("Arial", 0, 12);
  534.     private final Font font3 = new Font("Arial", 0, 11);
  535.     private final Font font4 = new Font("Arial", 0, 9);
  536.  
  537.     private Image img1;
  538.     private Image img2;
  539.  
  540.     public void paint(Graphics g1) {
  541.     long millis = System.currentTimeMillis() - startTime;
  542.     int produceProduced = SettingsData.getProduce(settings) - produceStart;
  543.     Graphics2D g = (Graphics2D) g1;
  544.     g.setColor(color1);
  545.         g.fillRect(270, 274, 187, 59);
  546.         g.setColor(color2);
  547.         g.setStroke(stroke1);
  548.         g.drawRect(270, 274, 187, 59);
  549.         g.setColor(color3);
  550.         g.fillRect(13, 353, 487, 102);
  551.         g.setColor(color2);
  552.         g.drawRect(13, 353, 487, 102);
  553.         g.setFont(font1);
  554.         g.setColor(color4);
  555.     g.drawString(
  556.         "State: "
  557.             + PaintFormatter.properCaseAll(state.name().replace(
  558.                 "_", " ")), 276, 290);
  559.     g.drawString(
  560.         "Produce: "
  561.             + PaintFormatter.getFormattedMoney(produceProduced)
  562.             + " @ "
  563.             + PaintFormatter
  564.                 .getFormattedMoney((produceProduced * 3600000l / millis))
  565.             + " /hr", 276, 306);
  566.     g.setFont(font2);
  567.     g.drawString(getSkillLine(Skills.MAGIC), 18, 374);
  568.     g.drawString(getSkillLine(Skills.CRAFTING), 19, 413);
  569.     g.drawString(getSkillLine(Skills.FARMING), 19, 394);
  570.     g.drawString(getSkillLine(Skills.CONSTRUCTION), 19, 431);
  571.     g.drawString(getSkillLine(Skills.AGILITY), 19, 450);
  572.     if (img1 != null)
  573.         g.drawImage(img1, 402, 177, null);
  574.     if (img2 != null)
  575.         g.drawImage(img2, 260, 380, null);
  576.     g.setFont(font3);
  577.     g.drawString("Time running: " + PaintFormatter.getFormattedTime(millis), 276, 324);
  578.     g.setFont(font4);
  579.     g.drawString("ATXiceman512", 380, 453);
  580.     g.drawString("Paint created by:", 307, 452);
  581.     }
  582.  
  583.     private String getSkillLine(int skill) {
  584.     final String skillName = PaintFormatter
  585.         .properCaseAll(Skills.SKILL_NAMES[skill]);
  586.     final String gained = PaintFormatter.getFormattedMoney(skillTracker
  587.         .getExpGain(skill));
  588.     final String perHour = PaintFormatter
  589.         .getFormattedMoney((int) skillTracker.getExpPerHour(skill))
  590.         + " exp/hr";
  591.     return skillName + ": " + gained + " exp @ " + perHour;
  592.     }
  593.  
  594.     @Override
  595.     public void onRepaint(Graphics uncast) {
  596.     Graphics2D g = (Graphics2D) uncast;
  597.     try {
  598.         final FontMetrics metrics = g.getFontMetrics();
  599.         final int tHeight = metrics.getHeight();
  600.         if (onMinimapDebug) {
  601.         for (RSTile t : FENCE) {
  602.             g.setColor(SettingsData.isFencePostRepaired(settings, t) ? new Color(
  603.                 0f, 1f, 0f, 0.75f) : new Color(1f, 0f, 0f, .75f));
  604.             Polygon p = getMinimapPolygon(t);
  605.             if (p != null)
  606.             g.fill(p);
  607.         }
  608.         RSObject pBin = objects.getNearest(PRODUCE_BIN);
  609.         if (pBin != null) {
  610.             g.setColor(SettingsData.isProduceBinFull(settings) ? new Color(
  611.                 0f, 1f, 0f, 0.75f) : new Color(1f, 0f, 0f, 0.75f));
  612.             Polygon p = getMinimapPolygon(new RSTile(pBin.getArea()
  613.                 .getX(), pBin.getArea().getY()));
  614.             if (p != null)
  615.             g.fill(p);
  616.         }
  617.         }
  618.         if (onMinimapDebug || onScreenDebug) {
  619.         for (RSTile t : LIVID_PLANTS) {
  620.             LividState lividState = getLividState(t);
  621.             if (onMinimapDebug) {
  622.             if (lividState != null) {
  623.                 g.setColor(new Color(lividState.color.getRed(),
  624.                     lividState.color.getGreen(),
  625.                     lividState.color.getBlue(), 75));
  626.                 Polygon p = getMinimapPolygon(t);
  627.                 if (p != null)
  628.                 g.fill(p);
  629.             }
  630.             }
  631.             if (onScreenDebug) {
  632.             RSObject object = objects.getTopAt(t,
  633.                 Objects.TYPE_INTERACTABLE);
  634.             if (object.isOnScreen()) {
  635.                 Point real = calc.tileToScreen(object.getArea()
  636.                     .getCentralTile());
  637.                 if (!calc.pointOnScreen(real))
  638.                 continue;
  639.                 final String s = (lividState != null ? lividState
  640.                     .name() : "Unidentified")
  641.                     + "\nStrain: "
  642.                     + getLividStrain(object);
  643.                 final String[] lines = s.split("\n");
  644.                 for (int i = 0; i < lines.length; i++) {
  645.                 final int ty = real.y - tHeight / 2 - (i * 15);
  646.                 final int tx = real.x
  647.                     - metrics.stringWidth(lines[i]) / 2;
  648.                 g.setColor(Color.WHITE);
  649.                 g.drawString(lines[i], tx, ty);
  650.                 }
  651.             }
  652.             }
  653.         }
  654.         }
  655.     } catch (Exception e) {
  656.     }
  657.     paint(g);
  658.     }
  659.  
  660.     @Override
  661.     public boolean onStart() {
  662.     startTime = System.currentTimeMillis();
  663.     produceStart = SettingsData.getProduce(settings);
  664.     skillTracker = new SkillTracker(skills);
  665.     new Thread() {
  666.         @Override
  667.         public void run() {
  668.         log.info("Loading image 1...");
  669.         img1 = getImage("http://images2.wikia.nocookie.net/__cb20091126223644/runescape/images/archive/8/87/20100213062624!Farming_Cape.PNG");
  670.         log.info("Loading image 2...");
  671.         img2 = getImage("http://images.cooltext.com/2279909.png");
  672.         }
  673.     }.start();
  674.     return true;
  675.     }
  676.  
  677.     enum LividState {
  678.     Empty(new Color(1f, 0f, 0f, 0.2f)),
  679.     Fertile(new Color(0f, 1f, 0f, 0.2f)),
  680.     Grown(new Color(0f, 1f, 0f, 0.2f)),
  681.     Sick(new Color(1f, 0f, 0f, 0.2f));
  682.     final Color color;
  683.  
  684.     private LividState(Color c) {
  685.         this.color = c;
  686.     }
  687.     }
  688.  
  689.     enum State {
  690.     Bundle_Produce,
  691.     Cure,
  692.     Deposit_Produce,
  693.     Energise,
  694.     Failsafe,
  695.     Fertilize,
  696.     Get_Logs,
  697.     Make_Planks,
  698.     Repair_Fence,
  699.     Take_Produce,
  700.     Wait;
  701.     }
  702.  
  703.     public enum Priority {
  704.     Farming, Fencing, Harvesting, Randoms
  705.     }
  706.  
  707.     public static class PaintFormatter {
  708.     public static String getFormattedMoney(long money) {
  709.         return new DecimalFormat("###,###,###,###,###,###").format(money);
  710.     }
  711.  
  712.     public static String getFormattedTime(final long timeMillis) {
  713.         return getFormattedTime(timeMillis, ":", false);
  714.     }
  715.  
  716.     public static String getFormattedTime(final long timeMillis,
  717.         String sep, boolean millisInc) {
  718.         long millis = timeMillis;
  719.         final long days = millis / (24 * 1000 * 60 * 60);
  720.         millis -= days * (24 * 1000 * 60 * 60);
  721.         final long hours = millis / (1000 * 60 * 60);
  722.         millis -= hours * 1000 * 60 * 60;
  723.         final long minutes = millis / (1000 * 60);
  724.         millis -= minutes * 1000 * 60;
  725.         final long _seconds = millis / 1000;
  726.         millis -= _seconds * 1000;
  727.         String dayString = String.valueOf(days);
  728.         String hoursString = String.valueOf(hours);
  729.         String minutesString = String.valueOf(minutes);
  730.         String secondsString = String.valueOf(_seconds);
  731.         if (hours < 10) {
  732.         hoursString = 0 + hoursString;
  733.         }
  734.         if (minutes < 10) {
  735.         minutesString = 0 + minutesString;
  736.         }
  737.         if (_seconds < 10) {
  738.         secondsString = 0 + secondsString;
  739.         }
  740.         String s = "";
  741.         if (days > 0)
  742.         s = dayString + sep;
  743.         s += hoursString + sep + minutesString + sep + secondsString;
  744.         if (millisInc)
  745.         s += sep + String.valueOf(millis);
  746.         return s;
  747.     }
  748.  
  749.     public static String properCaseAll(String s) {
  750.         String[] words = s.split(" ");
  751.         String result = "";
  752.         for (int i = 0; i < words.length; i++) {
  753.         words[i] = words[i].substring(0, 1).toUpperCase()
  754.             + words[i].substring(1).toLowerCase();
  755.         result += " " + words[i];
  756.         }
  757.         return result.substring(1);
  758.     }
  759.  
  760.     public static String properCaseFirst(String s) {
  761.         String[] sentences = new String[] { s };
  762.         if (s.contains("."))
  763.         sentences = s.split(".");
  764.         String result = "";
  765.         for (int i = 0; i < sentences.length; i++) {
  766.         String f = sentences[i].substring(0, 1).toUpperCase();
  767.         sentences[i] = f + sentences[i].substring(1).toLowerCase();
  768.         result += "." + sentences[i];
  769.         }
  770.         return result.substring(1);
  771.     }
  772.     }
  773.  
  774.     public static class SettingsData {
  775.     public static final int ENERGISE_PAULINE = 2087;
  776.     public static final Map<RSTile, int[]> FENCE_MAP = new HashMap<RSTile, int[]>();
  777.     public static final int[][][] LIVID_SETTINGS = new int[3][5][2];
  778.     public static final int[] PRODUCE_BIN = { 2085, 25 };
  779.     public static final int PRODUCE_GATHERED = 2088;
  780.  
  781.     public static List<Random> getActiveRandoms(Settings settings) {
  782.         List<Random> rand = new ArrayList<Random>();
  783.         for (Random r : Random.values()) {
  784.         if (r.isActive(settings)) {
  785.             rand.add(r);
  786.         }
  787.         }
  788.         return rand;
  789.     }
  790.  
  791.     public static int getPlantNibble(Settings settings, int pX, int pY) {
  792.         if (pX < 5 && pX >= 0 && pY < 3 && pY >= 0) {
  793.         return subBitSet(
  794.             settings.getSetting(LIVID_SETTINGS[pY][pX][0]),
  795.             LIVID_SETTINGS[pY][pX][1], 3);
  796.         }
  797.         return Integer.MAX_VALUE;
  798.     }
  799.  
  800.     public static int getPlantNibble(Settings settings, RSTile t) {
  801.         int x = (t.getX() - 2098) / 2;
  802.         int y = (t.getY() - 3943) / 3;
  803.         return getPlantNibble(settings, x, y);
  804.     }
  805.  
  806.     public static int getProduce(Settings settings) {
  807.         int setting = settings.getSetting(PRODUCE_GATHERED);
  808.         int value = 0;
  809.         value = (value << 8) + ((byte) (setting >>> 8) & 0xff);
  810.         value = (value << 8) + ((byte) (setting) & 0xff);
  811.         return value * 10;
  812.     }
  813.  
  814.     public static boolean isFencePostRepaired(Settings settings, RSTile t) {
  815.         int[] dt = FENCE_MAP.get(t);
  816.         if (dt != null && dt.length == 2) {
  817.         return subBitSet(settings.getSetting(dt[0]), dt[1], 1) == 0;
  818.         }
  819.         return false;
  820.     }
  821.  
  822.     public static boolean isProduceBinFull(Settings settings) {
  823.         return subBitSet(settings.getSetting(PRODUCE_BIN[0]),
  824.             PRODUCE_BIN[1], 1) == 1;
  825.     }
  826.  
  827.     public static int subBitSet(int value, int bit_start, int bit_length) {
  828.         String bits = Integer.toBinaryString(value).trim();
  829.         while (bits.length() < 32) {
  830.         bits = "0" + bits;
  831.         }
  832.         try {
  833.         String sub = bits.substring(bit_start, bit_start + bit_length);
  834.         return Integer.valueOf(sub, 2);
  835.         } catch (Exception e) {
  836.         return Integer.MAX_VALUE;
  837.         }
  838.     }
  839.  
  840.     static {
  841.         // {Setting ID, Start Bit}
  842.         // 3 bits of data
  843.         LIVID_SETTINGS[2][0] = new int[] { 2085, 19 };
  844.         LIVID_SETTINGS[2][1] = new int[] { 2085, 22 };
  845.         LIVID_SETTINGS[2][2] = new int[] { 2085, 13 };
  846.         LIVID_SETTINGS[2][3] = new int[] { 2085, 1 };
  847.         LIVID_SETTINGS[2][4] = new int[] { 2085, 16 };
  848.  
  849.         LIVID_SETTINGS[1][0] = new int[] { 2086, 14 };
  850.         LIVID_SETTINGS[1][1] = new int[] { 2086, 26 };
  851.         LIVID_SETTINGS[1][2] = new int[] { 2085, 4 };
  852.         LIVID_SETTINGS[1][3] = new int[] { 2085, 10 };
  853.         LIVID_SETTINGS[1][4] = new int[] { 2085, 7 };
  854.  
  855.         LIVID_SETTINGS[0][0] = new int[] { 2086, 23 };
  856.         LIVID_SETTINGS[0][1] = new int[] { 2086, 17 };
  857.         LIVID_SETTINGS[0][2] = new int[] { 2086, 11 };
  858.         LIVID_SETTINGS[0][3] = new int[] { 2086, 20 };
  859.         LIVID_SETTINGS[0][4] = new int[] { 2086, 29 };
  860.  
  861.         // {Setting ID, Start Bit}
  862.         // 1 bit of data
  863.         FENCE_MAP.put(new RSTile(2116, 3953), new int[] { 2085, 26 });
  864.         FENCE_MAP.put(new RSTile(2118, 3953), new int[] { 2085, 31 });
  865.         FENCE_MAP.put(new RSTile(2108, 3953), new int[] { 2085, 30 });
  866.         FENCE_MAP.put(new RSTile(2120, 3945), new int[] { 2085, 28 });
  867.         FENCE_MAP.put(new RSTile(2120, 3951), new int[] { 2085, 29 });
  868.         FENCE_MAP.put(new RSTile(2120, 3946), new int[] { 2085, 27 });
  869.     }
  870.  
  871.     public enum Random {
  872.         ENERGISE(2087, 27);
  873.         final int bit;
  874.         final int setting;
  875.  
  876.         private Random(int setting, int bit) {
  877.         this.setting = setting;
  878.         this.bit = bit;
  879.         }
  880.  
  881.         public boolean isActive(Settings settings) {
  882.         return subBitSet(settings.getSetting(setting), bit, 1) == 1;
  883.         }
  884.     }
  885.     }
  886.  
  887.     private static class SkillTracker {
  888.     private long[] lastTrained;
  889.     private int[] newExp;
  890.     private Skills skills;
  891.     private long start;
  892.     private int[] startExp;
  893.  
  894.     public SkillTracker(Skills skills) {
  895.         this.skills = skills;
  896.         this.start = System.currentTimeMillis();
  897.         this.startExp = new int[Skills.SKILL_NAMES.length];
  898.         this.lastTrained = new long[Skills.SKILL_NAMES.length];
  899.         this.newExp = new int[Skills.SKILL_NAMES.length];
  900.         for (int i = 0; i < Skills.SKILL_NAMES.length; i++) {
  901.         this.startExp[i] = skills.getCurrentExp(i);
  902.         this.newExp[i] = this.startExp[i];
  903.         }
  904.     }
  905.  
  906.     public long getElapsedTime() {
  907.         return System.currentTimeMillis() - start;
  908.     }
  909.  
  910.     public int getExpGain(int skill) {
  911.         return skills.getCurrentExp(skill) - startExp[skill];
  912.     }
  913.  
  914.     public double getExpPerHour(int skill) {
  915.         return getExpPerSecond(skill) * 3600d;
  916.     }
  917.  
  918.     public double getExpPerMilli(int skill) {
  919.         double gain = getExpGain(skill);
  920.         double time = getElapsedTime();
  921.         return gain / time;
  922.     }
  923.  
  924.     public double getExpPerSecond(int skill) {
  925.         return getExpPerMilli(skill) * 1000d;
  926.     }
  927.  
  928.     public boolean hasRecentlyTrained(int skill) {
  929.         int cExp = skills.getCurrentExp(skill);
  930.         if (newExp[skill] < cExp) {
  931.         lastTrained[skill] = System.currentTimeMillis();
  932.         }
  933.         newExp[skill] = cExp;
  934.         return lastTrained[skill] + 600000 > System.currentTimeMillis();
  935.     }
  936.     }
  937. }
Advertisement
Add Comment
Please, Sign In to add comment