Created
June 30, 2012 00:29
-
-
Save phl0w/3021577 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
| public class Drops extends Strategy implements Task { | |
| private int profit; | |
| GroundItem loot; | |
| private Map<Integer, Integer> prices = new HashMap<Integer, Integer>(); | |
| @Override | |
| public boolean validate() { | |
| return GroundItems.getNearest(GroundItems.ALL_FILTER) != null; | |
| } | |
| @Override | |
| public void run() { | |
| loot = GroundItems.getNearest(GroundItems.ALL_FILTER); | |
| if (!prices.containsKey(loot.getId())) { | |
| prices.put(loot.getId(), getPrice(loot.getId())); | |
| profit += prices.get(loot.getId()); | |
| } else { | |
| if (loot.interact("Take", loot.getGroundItem().getName())) { | |
| profit += prices.get(loot.getId()); | |
| } | |
| } | |
| } | |
| private int getPrice(int id) { | |
| try { | |
| URLConnection con = new URL("http://open.tip.it/json/ge_single_item?item=" + id).openConnection(); | |
| String line; | |
| BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); | |
| line = in.readLine(); | |
| if (line.contains("mark_price")) { | |
| line = line.substring(line.indexOf("mark_price\":\"") + "mark_price\":\"".length()); | |
| line = line.substring(0, line.indexOf("\"")); | |
| return Integer.parseInt(line.replaceAll(",", "")); | |
| } | |
| in.close(); | |
| } catch (Exception e) { | |
| } | |
| return -1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment