Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created June 30, 2012 00:29
Show Gist options
  • Select an option

  • Save phl0w/3021577 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/3021577 to your computer and use it in GitHub Desktop.
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