Created
February 18, 2015 12:26
-
-
Save MathiasDeWeerdt/a352931cab73c54ef29c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package api; | |
| import java.io.BufferedReader; | |
| import java.io.InputStreamReader; | |
| import java.net.URL; | |
| import java.net.URLConnection; | |
| import java.util.regex.Matcher; | |
| import java.util.regex.Pattern; | |
| public enum PriceChecker { | |
| LOGS("818-logs"), | |
| OAK_LOGS("823-oak-logs"), | |
| WILLOW_LOGS("822-willow-logs"), | |
| MAPLE_LOGS("821-maple-logs"), | |
| YEW_LOGS("820-yew-logs"), | |
| MAGIC_LOGS("819-magic-logs"); | |
| private final String URL_BASE = "http://forums.zybez.net/runescape-2007-prices/"; | |
| private final String URL_END; | |
| PriceChecker(String URL_END) { | |
| this.URL_END = URL_END; | |
| } | |
| public int getPrice() throws Exception { | |
| Pattern p = Pattern.compile("~\\d{1,5}.\\d{1,5} GP|~\\d{2}"); | |
| Matcher m = p.matcher(getText(URL_BASE + URL_END)); | |
| while (m.find()) { | |
| return Integer.parseInt(m.group().replace("~", "").replace(",", "").replace(" ", "").replace("GP", "")); | |
| } | |
| return 0; | |
| } | |
| public String getText(String url) throws Exception { | |
| URL website = new URL(url); | |
| URLConnection connection = website.openConnection(); | |
| connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"); | |
| BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
| StringBuilder response = new StringBuilder(); | |
| String inputLine; | |
| while ((inputLine = in.readLine()) != null) | |
| response.append(inputLine); | |
| in.close(); | |
| return response.toString(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package api; | |
| public class Time { | |
| private long hours; | |
| private long minutes; | |
| private long seconds; | |
| private long millis; | |
| private long startTime; | |
| public Time() { | |
| startTime = System.currentTimeMillis(); | |
| } | |
| public String format(long f) { | |
| return (String.valueOf(f).length() == 1) ? 0 + "" + f : "" + f; | |
| } | |
| public String timeTillNewLevel(int xpTNL, float f) { | |
| long Tmillis = (long) ((xpTNL / (f / 3600)) * 1000); | |
| long Thours = Tmillis / 3600000; | |
| Tmillis -= Thours * 3600000; | |
| long Tminutes = Tmillis / 60000; | |
| Tmillis -= Tminutes * 60000; | |
| long Tseconds = Tmillis / 1000; | |
| if (xpTNL > 0) { | |
| return format(Thours) + ":" + format(Tminutes) + ":" + format(Tseconds); | |
| } | |
| return null; | |
| } | |
| public float calculatePerHour(int variableToCalculate) { | |
| float xpsec = 0; | |
| if (((minutes > 0) || (hours > 0) || (seconds > 0)) | |
| && (variableToCalculate > 0)) { | |
| xpsec = variableToCalculate / (float) (seconds + minutes * 60 + hours * 60 * 60); | |
| } | |
| float xpmin = xpsec * 60; | |
| float xphour = xpmin * 60; | |
| return Math.round(xphour); | |
| } | |
| public String display() { | |
| millis = System.currentTimeMillis() - startTime; | |
| hours = millis / (1000 * 60 * 60); | |
| millis -= hours * (1000 * 60 * 60); | |
| minutes = millis / (1000 * 60); | |
| millis -= minutes * (1000 * 60); | |
| seconds = millis / 1000; | |
| return format(hours) + ":" + format(minutes) + ":" + format(seconds); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package api; | |
| public class Timer { | |
| private long end; | |
| private final long start; | |
| private final long period; | |
| public Timer(final long period) { | |
| this.period = period; | |
| start = System.currentTimeMillis(); | |
| end = start + period; | |
| } | |
| public long getElapsed() { | |
| return System.currentTimeMillis() - start; | |
| } | |
| public long getRemaining() { | |
| if (isRunning()) { | |
| return end - System.currentTimeMillis(); | |
| } | |
| return 0; | |
| } | |
| public boolean isRunning() { | |
| return System.currentTimeMillis() < end; | |
| } | |
| public void reset() { | |
| end = System.currentTimeMillis() + period; | |
| } | |
| public long setEndIn(final long ms) { | |
| end = System.currentTimeMillis() + ms; | |
| return end; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package api; | |
| import org.osbot.rs07.api.map.Position; | |
| import org.osbot.rs07.input.mouse.MiniMapTileDestination; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| public class Walking { | |
| Script script; | |
| public Walking(Script script) { | |
| this.script = script; | |
| } | |
| public void walkPath(Position[] path) throws InterruptedException { | |
| for (Position p : path) { | |
| if (script.myPosition().distance(p) > 16 | |
| || script.myPosition().distance(p) < 3) | |
| continue; | |
| boolean success; | |
| do { | |
| success = walkTile(p); | |
| } while (!success); | |
| } | |
| } | |
| public boolean walkTile(Position p) throws InterruptedException { | |
| if (script.myPosition().distance(p) > 13) { | |
| Position pos = new Position( | |
| ((p.getX() + script.myPosition().getX()) / 2) | |
| + MethodProvider.random(-3, 3), ((p.getY() + script | |
| .myPosition().getY()) / 2) | |
| + MethodProvider.random(-3, 3), script.myPosition() | |
| .getZ()); | |
| walkTile(pos); | |
| } | |
| script.mouse.click(new MiniMapTileDestination(script.bot, p), false); | |
| int fail = 0; | |
| while (script.myPosition().distance(p) > 2 && fail < 10) { | |
| MethodProvider.sleep(500); | |
| if (!script.myPlayer().isMoving()) | |
| fail++; | |
| } | |
| return fail != 10; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package api; | |
| import org.osbot.rs07.api.ui.Skill; | |
| import org.osbot.rs07.script.Script; | |
| public class XpDistance { | |
| private final static int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, | |
| 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, | |
| 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, | |
| 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, | |
| 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, | |
| 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, | |
| 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, | |
| 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, | |
| 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, | |
| 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, | |
| 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, | |
| 7944614, 8771558, 9684577, 10692629, 11805606, 13034431 }; | |
| public static int getLevelExperience(int level) { | |
| return XP[level - 1]; | |
| } | |
| public static int getDistanceBetweenLevels(int lower, int higher) { | |
| int x = XP[higher - 1] - XP[lower - 1]; | |
| return x > 0 ? x : 0; | |
| } | |
| public static int getXpUntilLevel(Script script, Skill skill, int level) { | |
| int x = XP[level - 1] - script.skills.getExperience(skill); | |
| return x > 0 ? x : 0; | |
| } | |
| public static int getXpUntilNextLevel(Script script, Skill skill) { | |
| int x = XpDistance.XP[script.skills.getStatic(skill)] | |
| - script.skills.getExperience(skill); | |
| return x > 0 ? x : 0; | |
| } | |
| public static int getXpPastCurrentLevel(Script script, Skill skill) { | |
| int x = script.skills.getExperience(skill) | |
| - XpDistance.XP[script.skills.getStatic(skill) - 1]; | |
| return x > 0 ? x : 0; | |
| } | |
| public static int getPercentageUntilNextLevelFromZero(Script script, Skill skill) { | |
| int p = script.skills.getExperience(skill) * 100 | |
| / XpDistance.XP[script.skills.getStatic(skill)]; | |
| return p > 0 ? p : 0; | |
| } | |
| public static int getPercentageUntilNextLevelFromCurrentLevel(Script script, | |
| Skill skill) { | |
| int p = XpDistance.getXpUntilNextLevel(script, skill) | |
| * 100 | |
| / (XpDistance.XP[script.skills.getStatic(skill)] - XpDistance.XP[script.skills | |
| .getStatic(skill) - 1]); | |
| return p > 0 ? p : 0; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package core; | |
| import org.osbot.rs07.script.Script; | |
| public abstract class AbstractNode { | |
| public Script script; | |
| public AbstractNode(Script script) { | |
| this.script = script; | |
| } | |
| public abstract boolean activate() throws InterruptedException; | |
| public abstract void execute() throws InterruptedException; | |
| public abstract String status(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| import core.AbstractNode; | |
| import org.osbot.rs07.api.model.Item; | |
| import org.osbot.rs07.api.model.Player; | |
| import org.osbot.rs07.api.ui.Skill; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| /** | |
| * Created by Single Core on 16/02/2015. | |
| */ | |
| public class Attack extends AbstractNode { | |
| public Attack(Script script) { | |
| super(script); | |
| } | |
| @Override | |
| public boolean activate() throws InterruptedException { | |
| return !script.myPlayer().isUnderAttack() && inDual(); | |
| } | |
| @Override | |
| public void execute() throws InterruptedException { | |
| script.log("Trying to attack: " + Config.getUsernameToAttack()); | |
| Player p = script.getPlayers().closest(Config.getUsernameToAttack()); | |
| if(p != null && p.isAttackable() && p.getHealth() > 0) { | |
| p.interact("Fight"); | |
| MethodProvider.sleep(MethodProvider.random(500, 3000)); | |
| } | |
| } | |
| public boolean inDual() { | |
| return script.myPlayer().getPosition().getY() < 3264; | |
| } | |
| @Override | |
| public String status() { | |
| return "Eating"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| import api.Walking; | |
| import core.AbstractNode; | |
| import org.osbot.rs07.api.map.Position; | |
| import org.osbot.rs07.api.model.Player; | |
| import org.osbot.rs07.api.model.RS2Object; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| /** | |
| * Created by Single Core on 16/02/2015. | |
| */ | |
| public class Bank extends AbstractNode { | |
| private final Position[] path = new Position[] { | |
| new Position(3358, 3272, 0), | |
| new Position(3364, 3269, 0), | |
| new Position(3371, 3268, 0), | |
| new Position(3375, 3265, 0), | |
| new Position(3382, 3267, 0) | |
| }; | |
| public Bank(Script script) { | |
| super(script); | |
| } | |
| @Override | |
| public boolean activate() throws InterruptedException { | |
| return (!inDual() && !script.getInventory().isFull()) || script.getInventory().isFull() && script.getBank().isOpen(); | |
| } | |
| @Override | |
| public void execute() throws InterruptedException { | |
| MethodProvider.sleep(1000); | |
| if(script.inventory.isFull()) { | |
| script.getBank().close(); | |
| MethodProvider.sleep(MethodProvider.random(500, 2200)); | |
| } else { | |
| if(script.getBank().isOpen()) { | |
| script.getBank().withdraw(Config.getFoodName(), 0); | |
| MethodProvider.sleep(MethodProvider.random(500, 2000)); | |
| } else { | |
| RS2Object closedBank = script.getObjects().closestThatContains("Closed chest"); | |
| RS2Object bank = script.getObjects().closestThatContains("Open chest"); | |
| if (bank == null && closedBank != null) { | |
| closedBank.interact("Open"); | |
| MethodProvider.sleep(MethodProvider.random(1000, 3000)); | |
| } | |
| if (bank != null) { | |
| if (bank.getPosition().distance(script.myPlayer().getPosition()) > 4) { | |
| Walking walker = new Walking(script); | |
| walker.walkPath(path); | |
| } else { | |
| bank.interact("Bank"); | |
| MethodProvider.sleep(MethodProvider.random(1200, 3000)); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| public boolean inDual() { | |
| return script.myPlayer().getPosition().getY() < 3264; | |
| } | |
| @Override | |
| public String status() { | |
| return "Banking"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| import core.AbstractNode; | |
| import org.osbot.rs07.api.model.Player; | |
| import org.osbot.rs07.api.model.RS2Object; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| /** | |
| * Created by Single Core on 16/02/2015. | |
| */ | |
| public class Challenge extends AbstractNode { | |
| public Challenge(Script script) { | |
| super(script); | |
| } | |
| @Override | |
| public boolean activate() throws InterruptedException { | |
| return script.getInventory().isFull() && !script.getBank().isOpen() && !inDual(); | |
| } | |
| @Override | |
| public void execute() throws InterruptedException { | |
| script.log("Trying to challenge: " + Config.getUsernameToAttack()); | |
| Player p = script.getPlayers().closest(Config.getUsernameToAttack()); | |
| if(p != null) { | |
| p.interact("Challenge"); | |
| MethodProvider.sleep(MethodProvider.random(3500, 5000)); | |
| } | |
| } | |
| public boolean inDual() { | |
| return script.myPlayer().getPosition().getY() < 3264; | |
| } | |
| @Override | |
| public String status() { | |
| return "Attempting to Challenge"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| /** | |
| * Created by Single Core on 17/02/2015. | |
| */ | |
| public class Config { | |
| private static String USERNAME_TO_ATTACK = "NULL"; | |
| public static String getUsernameToAttack() { | |
| return USERNAME_TO_ATTACK; | |
| } | |
| public static void setUsernameToAttack(String usr) { | |
| USERNAME_TO_ATTACK = usr; | |
| } | |
| private static String FOOD_NAME = "NULL"; | |
| public static String getFoodName() { | |
| return FOOD_NAME; | |
| } | |
| public static void setFoodName(String foodname) { | |
| FOOD_NAME = foodname; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| import core.AbstractNode; | |
| import org.osbot.rs07.api.model.RS2Object; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| /** | |
| * Created by Single Core on 16/02/2015. | |
| */ | |
| public class Dual extends AbstractNode { | |
| public Dual(Script script) { | |
| super(script); | |
| } | |
| @Override | |
| public boolean activate() throws InterruptedException { | |
| return !inDual() && script.getInventory().isFull() && !script.getBank().isOpen(); | |
| } | |
| @Override | |
| public void execute() throws InterruptedException { | |
| //TODO | |
| } | |
| public boolean inDual() { | |
| return script.myPlayer().getPosition().getY() < 3264; | |
| } | |
| @Override | |
| public String status() { | |
| return "Attempting to dual"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| import core.AbstractNode; | |
| import org.osbot.rs07.api.model.Item; | |
| import org.osbot.rs07.api.ui.Skill; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| /** | |
| * Created by Single Core on 16/02/2015. | |
| */ | |
| public class Eat extends AbstractNode { | |
| public Eat(Script script) { | |
| super(script); | |
| } | |
| @Override | |
| public boolean activate() throws InterruptedException { | |
| int hp = script.getSkills().getDynamic(Skill.HITPOINTS); | |
| script.log(hp); | |
| return hp <= 15; | |
| } | |
| @Override | |
| public void execute() throws InterruptedException { | |
| script.log("Trying to eat: " + Config.getFoodName()); | |
| Item food = script.getInventory().getItem(Config.getFoodName()); | |
| if(food != null) { | |
| food.interact("Eat"); | |
| MethodProvider.sleep(500); | |
| } | |
| } | |
| @Override | |
| public String status() { | |
| return "Eating"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dualarena; | |
| import core.AbstractNode; | |
| import org.osbot.rs07.api.Interfaces; | |
| import org.osbot.rs07.api.model.RS2Object; | |
| import org.osbot.rs07.api.ui.RS2Interface; | |
| import org.osbot.rs07.api.ui.RS2InterfaceChild; | |
| import org.osbot.rs07.script.MethodProvider; | |
| import org.osbot.rs07.script.Script; | |
| /** | |
| * Created by Single Core on 16/02/2015. | |
| */ | |
| public class InterfaceHandler extends AbstractNode { | |
| RS2InterfaceChild winInterface; | |
| RS2InterfaceChild dualAcceptInterfaceOne; | |
| RS2InterfaceChild dualAcceptInterfaceTwo; | |
| public InterfaceHandler(Script script) { | |
| super(script); | |
| } | |
| @Override | |
| public boolean activate() throws InterruptedException { | |
| winInterface = script.interfaces.getChild(110, 31); | |
| dualAcceptInterfaceOne = script.interfaces.getChild(107, 47); | |
| dualAcceptInterfaceTwo = script.interfaces.getChild(106, 54); | |
| return (!inDual() && interfaceIsUp()) || (script.getBank().isOpen() && script.getInventory().isFull()); | |
| } | |
| @Override | |
| public void execute() throws InterruptedException { | |
| if(winInterface != null) { | |
| winInterface.interact("Close"); | |
| MethodProvider.sleep(MethodProvider.random(500, 3000)); | |
| } | |
| if(dualAcceptInterfaceOne != null) { | |
| dualAcceptInterfaceOne.interact("Accept"); | |
| MethodProvider.sleep(MethodProvider.random(500, 3000)); | |
| } | |
| if(dualAcceptInterfaceTwo != null) { | |
| dualAcceptInterfaceTwo.interact("Accept"); | |
| MethodProvider.sleep(MethodProvider.random(500, 3000)); | |
| } | |
| } | |
| public boolean inDual() { | |
| return script.myPlayer().getPosition().getY() < 3264; | |
| } | |
| @Override | |
| public String status() { | |
| return "Banking"; | |
| } | |
| public boolean interfaceIsUp() { | |
| return winInterface != null || dualAcceptInterfaceOne != null || dualAcceptInterfaceTwo != null; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import api.Time; | |
| import core.AbstractNode; | |
| import dualarena.*; | |
| import org.osbot.rs07.script.Script; | |
| import org.osbot.rs07.script.ScriptManifest; | |
| import javax.swing.*; | |
| import java.util.ArrayList; | |
| /** | |
| * Created by Single Core on 13/02/2015. | |
| */ | |
| @ScriptManifest(version = 0.21, info = "info", name = "DualArena", logo = "", author = "Single Core") | |
| public class Main extends Script { | |
| private ArrayList<AbstractNode> nodes = new ArrayList<AbstractNode>(); | |
| private Time time = new Time(); | |
| public void onStart() throws InterruptedException { | |
| String username = ""; | |
| String foodName = ""; | |
| username = JOptionPane.showInputDialog("Enter the username you would like to attack.", "SnipeDatN"); | |
| foodName = JOptionPane.showInputDialog("What food would you like to use..", "Trout"); | |
| Config.setUsernameToAttack(username); | |
| Config.setFoodName(foodName); | |
| nodes.add(new Eat(this)); | |
| nodes.add(new Attack(this)); | |
| nodes.add(new Bank(this)); | |
| nodes.add(new Dual(this)); | |
| nodes.add(new InterfaceHandler(this)); | |
| nodes.add(new Challenge(this)); | |
| } | |
| @Override | |
| public int onLoop() throws InterruptedException { | |
| for (AbstractNode node : nodes) { | |
| log("Trying to activate node"); | |
| if (node.activate()) { | |
| log("Node Activated: " + node.status()); | |
| node.execute(); | |
| } | |
| } | |
| return 100; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment