Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.io.IOException;
- import java.net.URL;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.imageio.ImageIO;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.Game.Tab;
- import org.rsbot.script.methods.Objects;
- import org.rsbot.script.methods.Settings;
- import org.rsbot.script.methods.Skills;
- import org.rsbot.script.util.Filter;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSInterface;
- import org.rsbot.script.wrappers.RSItem;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSObject;
- import org.rsbot.script.wrappers.RSTile;
- @ScriptManifest(authors = { "Equinox_" }, name = "Equinox Livid Farm", version = 2.1, description = "Does the Livid Farm Minigame")
- public class EquinoxLividFarm extends Script implements PaintListener {
- public final static int[] ANIM_IDS = {/* 7898, 4432, 4413 */897 };
- public final static int ASTRAL_ID = 9075, NATURE_ID = 561, LAW_RUNE = 563;
- public final static RSTile CENTRAL_FARM = new RSTile(2111, 3946);
- public final static int CURE_INTERFACE = 1081;
- public final static String[] ENCOURAGE_STRINGS = {
- "keep going! we can do this", "keep going! you're doing so well",
- "come on, you're doing so well", "extraordinary",
- "look at all the produce being made", "lokar will really",
- "you're doing a fantastic job" };
- public final static RSTile[] FENCE = { new RSTile(2116, 3953),
- new RSTile(2118, 3953), new RSTile(2108, 3953),
- new RSTile(2120, 3945), new RSTile(2120, 3951),
- new RSTile(2120, 3946) };
- public final static int LIVID_BUNDLE = 20705;
- public final static int LIVID_PLANT_ITEM = 20704;
- public final static RSTile[] LIVID_PLANTS = { new RSTile(2098, 3943),
- new RSTile(2100, 3943), new RSTile(2102, 3943),
- new RSTile(2104, 3943), new RSTile(2106, 3943),
- new RSTile(2098, 3946), new RSTile(2100, 3946),
- new RSTile(2102, 3946), new RSTile(2104, 3946),
- new RSTile(2106, 3946), new RSTile(2098, 3949),
- new RSTile(2100, 3949), new RSTile(2102, 3949),
- new RSTile(2104, 3949), new RSTile(2106, 3949) };
- public final static int[] LIVID_STRAIN_ID = { 64739, 64734, 64735, 64743 };
- public final static int[][] LIVID_STRAINS = {
- { 40461, 40462, 40460, 40463 }, { 40464, 40486, 40488, 40487 },
- { 40499, 40492, 40504 }, { 40534, 40532, 40533, 40505 } };
- public final static int LOG_BIN = 40444;
- public final static int LUNAR_LOGS = 20702;
- public final static int LUNAR_PLANKS = 20703;
- public final static int PAULINE = 13621;
- public final static int PRODUCE_BIN = 40441;
- public final static int TRADE_WAGON = 40443;
- public State state = State.Wait;
- Priority[] priorityMap = { Priority.Harvesting, Priority.Farming,
- Priority.Fencing,
- /* Priority.Harvesting, */Priority.Randoms };
- private int produceStart;
- private SkillTracker skillTracker;
- private long startTime = 0;
- private boolean onScreenDebug = false;
- private boolean onMinimapDebug = false;
- public RSTile getBrokenFencePost() {
- for (RSTile t : FENCE) {
- if (!SettingsData.isFencePostRepaired(settings, t)) {
- return t;
- }
- }
- return null;
- }
- public RSComponent getChatComponent(String... reqContainsOneOf) {
- RSInterface[] valid = interfaces.getAll();
- for (RSInterface iface : valid) {
- if (iface.getIndex() != 137) {
- int len = iface.getChildCount();
- for (int i = 0; i < len; i++) {
- RSComponent child = iface.getComponent(i);
- if (child.isValid() && child.getAbsoluteY() > 300) {
- for (String s : reqContainsOneOf)
- if (child.getText().toLowerCase()
- .contains(s.toLowerCase())
- || s.toLowerCase().contains(
- child.getText().toLowerCase()))
- return child;
- }
- }
- }
- }
- return null;
- }
- public State getFarmingState() {
- RSObject lividPlant = getLividPlant(LividState.Empty, LividState.Sick);
- LividState chosenState = lividPlant != null ? getLividState(lividPlant)
- : null;
- if (lividPlant != null && chosenState == LividState.Empty
- && inventory.getCount(true, ASTRAL_ID) >= 3
- && inventory.getCount(true, NATURE_ID) >= 2)
- return State.Fertilize;
- else if (lividPlant != null && chosenState == LividState.Sick
- && inventory.contains(ASTRAL_ID))
- return State.Cure;
- return null;
- }
- public RSTile getFenceWalk(RSTile t) {
- int deltaX = CENTRAL_FARM.getX() - t.getX();
- int deltaY = CENTRAL_FARM.getY() - t.getY();
- double dist = calc.distanceBetween(t, CENTRAL_FARM);
- double eX = deltaX / dist, eY = deltaY / dist;
- return new RSTile(t.getX() + (int) (eX * 3), t.getY() + (int) (eY * 3));
- }
- public State getFencingState() {
- if (inventory.contains(LUNAR_LOGS)
- && inventory.getCount(true, ASTRAL_ID) >= 2
- && inventory.contains(NATURE_ID))
- return State.Make_Planks;
- else if (inventory.getCount(LUNAR_LOGS, LUNAR_PLANKS) < 3)
- return State.Get_Logs;
- else if (getBrokenFencePost() != null
- && inventory.contains(LUNAR_PLANKS))
- return State.Repair_Fence;
- return null;
- }
- public RSTile getHalfTile(RSTile base) {
- RSTile me = getMyPlayer().getLocation();
- int deltaX = (int) ((base.getX() - me.getX()) / 2f);
- int deltaY = (int) ((base.getY() - me.getY()) / 2f);
- return new RSTile(me.getX() + deltaX, me.getY() + deltaY);
- }
- public State getHarvestingState() {
- if (inventory.getCount(LIVID_PLANT_ITEM) >= 5
- && inventory.getCount(true, ASTRAL_ID) >= 2)
- return State.Bundle_Produce;
- else if (inventory.getCount(LIVID_BUNDLE) >= 2
- || (inventory.contains(LIVID_BUNDLE) && !SettingsData
- .isProduceBinFull(settings)))
- return State.Deposit_Produce;
- else if (SettingsData.isProduceBinFull(settings))
- return State.Take_Produce;
- return null;
- }
- public RSComponent getLividCure(int lividNum) {
- RSInterface inter = interfaces.get(CURE_INTERFACE);
- if (inter != null && inter.isValid() && inter.getComponents() != null)
- for (RSComponent c : inter.getComponents())
- if (c != null && c.isValid())
- if (c.getModelID() == LIVID_STRAIN_ID[lividNum])
- return c;
- return null;
- }
- public RSObject getLividPlant(final LividState... states) {
- return objects.getNearest(new Filter<RSObject>() {
- @Override
- public boolean accept(RSObject t) {
- if (isLividPlant(t)) {
- LividState ls = getLividState(t);
- for (LividState lState : states)
- if (ls == lState)
- return true;
- }
- return false;
- }
- });
- }
- public LividState getLividState(RSObject o) {
- return o != null ? getLividState(o.getLocation()) : null;
- }
- public LividState getLividState(RSTile t) {
- switch (SettingsData.getPlantNibble(settings, t)) {
- case 0:
- return LividState.Empty;
- case 1:
- return LividState.Fertile;
- case 2:
- return LividState.Grown;
- case 3:
- return LividState.Sick;
- case 4:
- return LividState.Grown;
- default:
- return null;
- }
- }
- public int getLividStrain(RSObject o) {
- for (int i = 0; i < LIVID_STRAINS.length; i++) {
- for (int id : LIVID_STRAINS[i])
- if (id == o.getID())
- return i;
- }
- return -1;
- }
- public Polygon getMinimapPolygon(final RSTile t) {
- if (t != null) {
- Polygon poly = new Polygon();
- Point pt = calc.tileToMinimap(t);
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToMinimap(new RSTile(t.getX(), t.getY() + 1));
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY() + 1));
- poly.addPoint(pt.x, pt.y);
- pt = calc.tileToMinimap(new RSTile(t.getX() + 1, t.getY()));
- poly.addPoint(pt.x, pt.y);
- for (int i = 0; i < poly.npoints; i++)
- if (poly.xpoints[i] < 0 || poly.ypoints[i] < 0)
- return null;
- return poly;
- }
- return null;
- }
- public State getRandomsState() {
- if (inventory.getCount(true, ASTRAL_ID) >= 3
- && inventory.getCount(true, LAW_RUNE) >= 2
- && inventory.contains(NATURE_ID)
- && SettingsData.Random.ENERGISE.isActive(settings))
- return State.Energise;
- return null;
- }
- public State getState() {
- if (!isInFarm(getMyPlayer().getLocation()))
- return State.Failsafe;
- else if (isCastingSpell())
- return State.Wait;
- for (Priority prior : priorityMap) {
- State state = null;
- switch (prior) {
- case Randoms:
- state = getRandomsState();
- break;
- case Farming:
- state = getFarmingState();
- break;
- case Fencing:
- state = getFencingState();
- break;
- case Harvesting:
- state = getHarvestingState();
- break;
- }
- if (state != null)
- return state;
- }
- return State.Wait;
- }
- public RSTile getTileOnMinimap(RSTile base) {
- if (calc.tileOnMap(base))
- return base;
- RSTile me = getMyPlayer().getLocation();
- int deltaX = base.getX() - me.getX();
- int deltaY = base.getY() - me.getY();
- double dist = calc.distanceBetween(base, me);
- double eX = deltaX / dist, eY = deltaY / dist;
- return new RSTile(me.getX() + (int) (eX * 15), me.getY()
- + (int) (eY * 15));
- }
- public boolean isCastingSpell() {
- for (int i : ANIM_IDS)
- if (getMyPlayer().getAnimation() == i)
- return true;
- return false;
- }
- public boolean isInFarm(RSTile t) {
- int x = t.getX();
- int y = t.getY();
- if (x >= 2097 && y >= 3942 && x <= 2107 && y <= 3950)
- return true;
- if (x >= 2108 && y >= 3940 && x <= 2114 && y <= 3952)
- return true;
- if (x >= 2115 && y >= 3942 && x <= 2119 && y <= 3952)
- return true;
- return false;
- }
- public boolean isLividPlant(RSObject o) {
- if (o.getType() == RSObject.Type.INTERACTABLE)
- for (RSTile t : LIVID_PLANTS)
- if (t.equals(o.getLocation()))
- return true;
- return false;
- }
- @Override
- public int loop() {
- if (game.getTab().equals(Tab.INVENTORY)
- && !inventory.contains(ASTRAL_ID))
- stopScript(true);
- switch (state = getState()) {
- case Deposit_Produce:
- RSObject cart = objects.getNearest(TRADE_WAGON);
- if (cart != null) {
- if (cart.isOnScreen()) {
- if (cart.interact("Deposit"))
- sleep(500, 600);
- } else {
- RSTile walk = getTileOnMinimap(cart.getLocation());
- if (walking.getDestination() == null
- || calc.distanceBetween(walking.getDestination(),
- walk) > 4) {
- walking.walkTileMM(walk);
- sleep(1000, 2000);
- }
- }
- }
- break;
- case Take_Produce:
- RSObject bin = objects.getNearest(PRODUCE_BIN);
- RSNPC pauline = npcs.getNearest(PAULINE);
- if (bin != null) {
- if (bin.isOnScreen()) {
- if (bin.interact("Take"))
- sleep(1500, 1600);
- } else {
- RSTile walk = getTileOnMinimap(new RSTile(bin.getArea()
- .getX(), bin.getArea().getY() - 1));
- if (walking.getDestination() == null
- || calc.distanceBetween(walking.getDestination(),
- walk) > 4) {
- walking.walkTileMM(walk);
- }
- }
- }
- break;
- case Bundle_Produce:
- RSItem lividPlantItem = inventory.getItem(LIVID_PLANT_ITEM);
- if (lividPlantItem != null)
- if (lividPlantItem.interact("Bunch"))
- sleep(500, 600);
- break;
- case Fertilize:
- RSObject patch = getLividPlant(LividState.Empty);
- if (patch != null) {
- if (patch.isOnScreen()) {
- if (patch.interact("Fertilise E")) {
- for (byte b = 0; b < 50; b++) {
- RSObject newO = objects.getTopAt(
- patch.getLocation(),
- Objects.TYPE_INTERACTABLE);
- if (newO != null
- && getLividState(newO) == LividState.Fertile) {
- break;
- }
- sleep(100, 125);
- }
- }
- } else {
- RSTile walk = getTileOnMinimap(getHalfTile(patch
- .getLocation()));
- if (walking.getDestination() == null
- || calc.distanceBetween(walking.getDestination(),
- walk) > 4) {
- walking.walkTileMM(walk);
- sleep(1000, 2000);
- }
- }
- }
- break;
- case Cure:
- RSObject plant = getLividPlant(LividState.Sick);
- if (plant != null) {
- if (plant.isOnScreen()) {
- if (interfaces.get(CURE_INTERFACE) == null
- || !interfaces.get(CURE_INTERFACE).isValid())
- if (plant.interact("Cure-plant D"))
- for (byte b = 0; b < 10
- && (interfaces.get(CURE_INTERFACE) == null || !interfaces
- .get(CURE_INTERFACE).isValid()); b++)
- sleep(500, 600);
- RSComponent c = getLividCure(getLividStrain(plant));
- if (c != null && c.isValid())
- if (c.doClick()) {
- for (byte b = 0; b < 30; b++) {
- RSObject newO = objects.getTopAt(
- plant.getLocation(),
- Objects.TYPE_INTERACTABLE);
- if (newO != null
- && getLividState(newO) == LividState.Grown) {
- break;
- }
- sleep(100, 125);
- }
- }
- } else {
- RSTile walk = getTileOnMinimap(getHalfTile(plant
- .getLocation()));
- if (walking.getDestination() == null
- || calc.distanceBetween(walking.getDestination(),
- walk) > 4) {
- walking.walkTileMM(walk);
- sleep(1000, 2000);
- }
- }
- }
- break;
- case Energise:
- pauline = npcs.getNearest(PAULINE);
- if (pauline != null) {
- for (byte b = 0; b < 100 && !pauline.isOnScreen(); b++) {
- RSTile t = getTileOnMinimap(pauline.getLocation());
- if (walking.getDestination() == null
- || calc.distanceBetween(t, walking.getDestination()) > 4)
- walking.walkTileMM(t);
- sleep(200, 300);
- }
- if (pauline.interact("Energise")) {
- sleep(1500);
- RSComponent c = null;
- for (byte b = 0; b < 20
- && (c = getChatComponent(ENCOURAGE_STRINGS)) == null; b++)
- sleep(100, 125);
- if (c != null)
- for (byte b = 0; b < 5; b++)
- if (c.doClick()) {
- break;
- }
- }
- }
- break;
- case Failsafe:
- if (calc.distanceTo(CENTRAL_FARM) > 100) {
- log.severe("Not anywhere near the livid farm! Quitting.");
- stopScript(true);
- } else {
- RSTile dest = getTileOnMinimap(CENTRAL_FARM);
- if (walking.getDestination() == null
- || calc.distanceBetween(dest, walking.getDestination()) > 5)
- walking.walkTileMM(dest);
- }
- break;
- case Make_Planks:
- RSItem[] itms = inventory.getItems(LUNAR_LOGS);
- if (itms != null && itms.length > 0) {
- for (RSItem itm : itms) {
- if (!(inventory.getCount(true, ASTRAL_ID) >= 2 && inventory
- .contains(NATURE_ID)))
- break;
- if (itm.interact("Convert")) {
- for (byte b = 0; b < 10 && itm.getID() == LUNAR_LOGS; b++)
- sleep(100);
- }
- }
- }
- break;
- case Get_Logs:
- RSObject log_bin = objects.getNearest(LOG_BIN);
- if (log_bin != null) {
- if (log_bin.isOnScreen()) {
- int count = inventory.getCount(LUNAR_LOGS, LUNAR_PLANKS);
- log_bin.interact("Take-5");
- sleep(500);
- int to = getMyPlayer().isMoving() ? 50 : 15;
- for (byte b = 0; b < to
- && inventory.getCount(LUNAR_LOGS, LUNAR_PLANKS) == count; b++)
- sleep(100);
- } else {
- RSTile dest = getTileOnMinimap(log_bin.getLocation());
- if (walking.getDestination() == null
- || calc.distanceBetween(dest,
- walking.getDestination()) > 5)
- walking.walkTileMM(dest);
- }
- }
- break;
- case Repair_Fence:
- RSTile broken = getBrokenFencePost();
- if (broken != null && inventory.contains(LUNAR_PLANKS)) {
- RSObject fence = objects.getTopAt(broken);
- if (fence != null && inventory.contains(LUNAR_PLANKS)) {
- if (fence.isOnScreen()) {
- fence.interact("Fix");
- sleep(100, 1250);
- } else {
- RSTile dest = getTileOnMinimap(getFenceWalk(broken));
- if (walking.getDestination() == null
- || calc.distanceBetween(dest,
- walking.getDestination()) > 5)
- walking.walkTileMM(dest);
- }
- }
- }
- break;
- }
- return random(250, 500);
- }
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch (IOException e) {
- return null;
- }
- }
- private final Color color1 = new Color(102, 102, 102, 211);
- private final Color color2 = new Color(0, 0, 0);
- private final Color color3 = new Color(51, 51, 51, 211);
- private final Color color4 = new Color(0, 255, 51);
- private final BasicStroke stroke1 = new BasicStroke(1);
- private final Font font1 = new Font("Arial", 0, 10);
- private final Font font2 = new Font("Arial", 0, 12);
- private final Font font3 = new Font("Arial", 0, 11);
- private final Font font4 = new Font("Arial", 0, 9);
- private Image img1;
- private Image img2;
- public void paint(Graphics g1) {
- long millis = System.currentTimeMillis() - startTime;
- int produceProduced = SettingsData.getProduce(settings) - produceStart;
- Graphics2D g = (Graphics2D) g1;
- g.setColor(color1);
- g.fillRect(270, 274, 187, 59);
- g.setColor(color2);
- g.setStroke(stroke1);
- g.drawRect(270, 274, 187, 59);
- g.setColor(color3);
- g.fillRect(13, 353, 487, 102);
- g.setColor(color2);
- g.drawRect(13, 353, 487, 102);
- g.setFont(font1);
- g.setColor(color4);
- g.drawString(
- "State: "
- + PaintFormatter.properCaseAll(state.name().replace(
- "_", " ")), 276, 290);
- g.drawString(
- "Produce: "
- + PaintFormatter.getFormattedMoney(produceProduced)
- + " @ "
- + PaintFormatter
- .getFormattedMoney((produceProduced * 3600000l / millis))
- + " /hr", 276, 306);
- g.setFont(font2);
- g.drawString(getSkillLine(Skills.MAGIC), 18, 374);
- g.drawString(getSkillLine(Skills.CRAFTING), 19, 413);
- g.drawString(getSkillLine(Skills.FARMING), 19, 394);
- g.drawString(getSkillLine(Skills.CONSTRUCTION), 19, 431);
- g.drawString(getSkillLine(Skills.AGILITY), 19, 450);
- if (img1 != null)
- g.drawImage(img1, 402, 177, null);
- if (img2 != null)
- g.drawImage(img2, 260, 380, null);
- g.setFont(font3);
- g.drawString("Time running: " + PaintFormatter.getFormattedTime(millis), 276, 324);
- g.setFont(font4);
- g.drawString("ATXiceman512", 380, 453);
- g.drawString("Paint created by:", 307, 452);
- }
- private String getSkillLine(int skill) {
- final String skillName = PaintFormatter
- .properCaseAll(Skills.SKILL_NAMES[skill]);
- final String gained = PaintFormatter.getFormattedMoney(skillTracker
- .getExpGain(skill));
- final String perHour = PaintFormatter
- .getFormattedMoney((int) skillTracker.getExpPerHour(skill))
- + " exp/hr";
- return skillName + ": " + gained + " exp @ " + perHour;
- }
- @Override
- public void onRepaint(Graphics uncast) {
- Graphics2D g = (Graphics2D) uncast;
- try {
- final FontMetrics metrics = g.getFontMetrics();
- final int tHeight = metrics.getHeight();
- if (onMinimapDebug) {
- for (RSTile t : FENCE) {
- g.setColor(SettingsData.isFencePostRepaired(settings, t) ? new Color(
- 0f, 1f, 0f, 0.75f) : new Color(1f, 0f, 0f, .75f));
- Polygon p = getMinimapPolygon(t);
- if (p != null)
- g.fill(p);
- }
- RSObject pBin = objects.getNearest(PRODUCE_BIN);
- if (pBin != null) {
- g.setColor(SettingsData.isProduceBinFull(settings) ? new Color(
- 0f, 1f, 0f, 0.75f) : new Color(1f, 0f, 0f, 0.75f));
- Polygon p = getMinimapPolygon(new RSTile(pBin.getArea()
- .getX(), pBin.getArea().getY()));
- if (p != null)
- g.fill(p);
- }
- }
- if (onMinimapDebug || onScreenDebug) {
- for (RSTile t : LIVID_PLANTS) {
- LividState lividState = getLividState(t);
- if (onMinimapDebug) {
- if (lividState != null) {
- g.setColor(new Color(lividState.color.getRed(),
- lividState.color.getGreen(),
- lividState.color.getBlue(), 75));
- Polygon p = getMinimapPolygon(t);
- if (p != null)
- g.fill(p);
- }
- }
- if (onScreenDebug) {
- RSObject object = objects.getTopAt(t,
- Objects.TYPE_INTERACTABLE);
- if (object.isOnScreen()) {
- Point real = calc.tileToScreen(object.getArea()
- .getCentralTile());
- if (!calc.pointOnScreen(real))
- continue;
- final String s = (lividState != null ? lividState
- .name() : "Unidentified")
- + "\nStrain: "
- + getLividStrain(object);
- final String[] lines = s.split("\n");
- for (int i = 0; i < lines.length; i++) {
- final int ty = real.y - tHeight / 2 - (i * 15);
- final int tx = real.x
- - metrics.stringWidth(lines[i]) / 2;
- g.setColor(Color.WHITE);
- g.drawString(lines[i], tx, ty);
- }
- }
- }
- }
- }
- } catch (Exception e) {
- }
- paint(g);
- }
- @Override
- public boolean onStart() {
- startTime = System.currentTimeMillis();
- produceStart = SettingsData.getProduce(settings);
- skillTracker = new SkillTracker(skills);
- new Thread() {
- @Override
- public void run() {
- log.info("Loading image 1...");
- img1 = getImage("http://images2.wikia.nocookie.net/__cb20091126223644/runescape/images/archive/8/87/20100213062624!Farming_Cape.PNG");
- log.info("Loading image 2...");
- img2 = getImage("http://images.cooltext.com/2279909.png");
- }
- }.start();
- return true;
- }
- enum LividState {
- Empty(new Color(1f, 0f, 0f, 0.2f)),
- Fertile(new Color(0f, 1f, 0f, 0.2f)),
- Grown(new Color(0f, 1f, 0f, 0.2f)),
- Sick(new Color(1f, 0f, 0f, 0.2f));
- final Color color;
- private LividState(Color c) {
- this.color = c;
- }
- }
- enum State {
- Bundle_Produce,
- Cure,
- Deposit_Produce,
- Energise,
- Failsafe,
- Fertilize,
- Get_Logs,
- Make_Planks,
- Repair_Fence,
- Take_Produce,
- Wait;
- }
- public enum Priority {
- Farming, Fencing, Harvesting, Randoms
- }
- public static class PaintFormatter {
- public static String getFormattedMoney(long money) {
- return new DecimalFormat("###,###,###,###,###,###").format(money);
- }
- public static String getFormattedTime(final long timeMillis) {
- return getFormattedTime(timeMillis, ":", false);
- }
- public static String getFormattedTime(final long timeMillis,
- String sep, boolean millisInc) {
- long millis = timeMillis;
- final long days = millis / (24 * 1000 * 60 * 60);
- millis -= days * (24 * 1000 * 60 * 60);
- final long hours = millis / (1000 * 60 * 60);
- millis -= hours * 1000 * 60 * 60;
- final long minutes = millis / (1000 * 60);
- millis -= minutes * 1000 * 60;
- final long _seconds = millis / 1000;
- millis -= _seconds * 1000;
- String dayString = String.valueOf(days);
- String hoursString = String.valueOf(hours);
- String minutesString = String.valueOf(minutes);
- String secondsString = String.valueOf(_seconds);
- if (hours < 10) {
- hoursString = 0 + hoursString;
- }
- if (minutes < 10) {
- minutesString = 0 + minutesString;
- }
- if (_seconds < 10) {
- secondsString = 0 + secondsString;
- }
- String s = "";
- if (days > 0)
- s = dayString + sep;
- s += hoursString + sep + minutesString + sep + secondsString;
- if (millisInc)
- s += sep + String.valueOf(millis);
- return s;
- }
- public static String properCaseAll(String s) {
- String[] words = s.split(" ");
- String result = "";
- for (int i = 0; i < words.length; i++) {
- words[i] = words[i].substring(0, 1).toUpperCase()
- + words[i].substring(1).toLowerCase();
- result += " " + words[i];
- }
- return result.substring(1);
- }
- public static String properCaseFirst(String s) {
- String[] sentences = new String[] { s };
- if (s.contains("."))
- sentences = s.split(".");
- String result = "";
- for (int i = 0; i < sentences.length; i++) {
- String f = sentences[i].substring(0, 1).toUpperCase();
- sentences[i] = f + sentences[i].substring(1).toLowerCase();
- result += "." + sentences[i];
- }
- return result.substring(1);
- }
- }
- public static class SettingsData {
- public static final int ENERGISE_PAULINE = 2087;
- public static final Map<RSTile, int[]> FENCE_MAP = new HashMap<RSTile, int[]>();
- public static final int[][][] LIVID_SETTINGS = new int[3][5][2];
- public static final int[] PRODUCE_BIN = { 2085, 25 };
- public static final int PRODUCE_GATHERED = 2088;
- public static List<Random> getActiveRandoms(Settings settings) {
- List<Random> rand = new ArrayList<Random>();
- for (Random r : Random.values()) {
- if (r.isActive(settings)) {
- rand.add(r);
- }
- }
- return rand;
- }
- public static int getPlantNibble(Settings settings, int pX, int pY) {
- if (pX < 5 && pX >= 0 && pY < 3 && pY >= 0) {
- return subBitSet(
- settings.getSetting(LIVID_SETTINGS[pY][pX][0]),
- LIVID_SETTINGS[pY][pX][1], 3);
- }
- return Integer.MAX_VALUE;
- }
- public static int getPlantNibble(Settings settings, RSTile t) {
- int x = (t.getX() - 2098) / 2;
- int y = (t.getY() - 3943) / 3;
- return getPlantNibble(settings, x, y);
- }
- public static int getProduce(Settings settings) {
- int setting = settings.getSetting(PRODUCE_GATHERED);
- int value = 0;
- value = (value << 8) + ((byte) (setting >>> 8) & 0xff);
- value = (value << 8) + ((byte) (setting) & 0xff);
- return value * 10;
- }
- public static boolean isFencePostRepaired(Settings settings, RSTile t) {
- int[] dt = FENCE_MAP.get(t);
- if (dt != null && dt.length == 2) {
- return subBitSet(settings.getSetting(dt[0]), dt[1], 1) == 0;
- }
- return false;
- }
- public static boolean isProduceBinFull(Settings settings) {
- return subBitSet(settings.getSetting(PRODUCE_BIN[0]),
- PRODUCE_BIN[1], 1) == 1;
- }
- public static int subBitSet(int value, int bit_start, int bit_length) {
- String bits = Integer.toBinaryString(value).trim();
- while (bits.length() < 32) {
- bits = "0" + bits;
- }
- try {
- String sub = bits.substring(bit_start, bit_start + bit_length);
- return Integer.valueOf(sub, 2);
- } catch (Exception e) {
- return Integer.MAX_VALUE;
- }
- }
- static {
- // {Setting ID, Start Bit}
- // 3 bits of data
- LIVID_SETTINGS[2][0] = new int[] { 2085, 19 };
- LIVID_SETTINGS[2][1] = new int[] { 2085, 22 };
- LIVID_SETTINGS[2][2] = new int[] { 2085, 13 };
- LIVID_SETTINGS[2][3] = new int[] { 2085, 1 };
- LIVID_SETTINGS[2][4] = new int[] { 2085, 16 };
- LIVID_SETTINGS[1][0] = new int[] { 2086, 14 };
- LIVID_SETTINGS[1][1] = new int[] { 2086, 26 };
- LIVID_SETTINGS[1][2] = new int[] { 2085, 4 };
- LIVID_SETTINGS[1][3] = new int[] { 2085, 10 };
- LIVID_SETTINGS[1][4] = new int[] { 2085, 7 };
- LIVID_SETTINGS[0][0] = new int[] { 2086, 23 };
- LIVID_SETTINGS[0][1] = new int[] { 2086, 17 };
- LIVID_SETTINGS[0][2] = new int[] { 2086, 11 };
- LIVID_SETTINGS[0][3] = new int[] { 2086, 20 };
- LIVID_SETTINGS[0][4] = new int[] { 2086, 29 };
- // {Setting ID, Start Bit}
- // 1 bit of data
- FENCE_MAP.put(new RSTile(2116, 3953), new int[] { 2085, 26 });
- FENCE_MAP.put(new RSTile(2118, 3953), new int[] { 2085, 31 });
- FENCE_MAP.put(new RSTile(2108, 3953), new int[] { 2085, 30 });
- FENCE_MAP.put(new RSTile(2120, 3945), new int[] { 2085, 28 });
- FENCE_MAP.put(new RSTile(2120, 3951), new int[] { 2085, 29 });
- FENCE_MAP.put(new RSTile(2120, 3946), new int[] { 2085, 27 });
- }
- public enum Random {
- ENERGISE(2087, 27);
- final int bit;
- final int setting;
- private Random(int setting, int bit) {
- this.setting = setting;
- this.bit = bit;
- }
- public boolean isActive(Settings settings) {
- return subBitSet(settings.getSetting(setting), bit, 1) == 1;
- }
- }
- }
- private static class SkillTracker {
- private long[] lastTrained;
- private int[] newExp;
- private Skills skills;
- private long start;
- private int[] startExp;
- public SkillTracker(Skills skills) {
- this.skills = skills;
- this.start = System.currentTimeMillis();
- this.startExp = new int[Skills.SKILL_NAMES.length];
- this.lastTrained = new long[Skills.SKILL_NAMES.length];
- this.newExp = new int[Skills.SKILL_NAMES.length];
- for (int i = 0; i < Skills.SKILL_NAMES.length; i++) {
- this.startExp[i] = skills.getCurrentExp(i);
- this.newExp[i] = this.startExp[i];
- }
- }
- public long getElapsedTime() {
- return System.currentTimeMillis() - start;
- }
- public int getExpGain(int skill) {
- return skills.getCurrentExp(skill) - startExp[skill];
- }
- public double getExpPerHour(int skill) {
- return getExpPerSecond(skill) * 3600d;
- }
- public double getExpPerMilli(int skill) {
- double gain = getExpGain(skill);
- double time = getElapsedTime();
- return gain / time;
- }
- public double getExpPerSecond(int skill) {
- return getExpPerMilli(skill) * 1000d;
- }
- public boolean hasRecentlyTrained(int skill) {
- int cExp = skills.getCurrentExp(skill);
- if (newExp[skill] < cExp) {
- lastTrained[skill] = System.currentTimeMillis();
- }
- newExp[skill] = cExp;
- return lastTrained[skill] + 600000 > System.currentTimeMillis();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment