Skip to content

Instantly share code, notes, and snippets.

@Sovietaced
Created April 15, 2012 06:16
Show Gist options
  • Save Sovietaced/2390375 to your computer and use it in GitHub Desktop.
Save Sovietaced/2390375 to your computer and use it in GitHub Desktop.
import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Condition;
import org.powerbot.concurrent.strategy.Strategy;
import org.powerbot.game.api.ActiveScript;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Calculations;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.node.SceneEntities;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.methods.tab.Skills;
import org.powerbot.game.api.methods.widget.Camera;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.wrappers.Area;
import org.powerbot.game.api.wrappers.Tile;
import org.powerbot.game.api.wrappers.node.SceneObject;
import org.powerbot.game.bot.event.MessageEvent;
import org.powerbot.game.bot.event.listener.MessageListener;
import org.powerbot.game.bot.event.listener.PaintListener;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
@Manifest(authors = {"Soviet"}, name = "RedexGuildMiner", description = "Flawless GuildMining", version = 1.4)
public class RedexGuildMiner extends ActiveScript implements PaintListener,MessageListener {
private int[] coalID = {5770, 5771, 5772};
private int[] mixedID = {5784, 5785, 5786, 5770, 5771, 5772};
private int[] rock;
private final int BOOTHS = 11758;
private int oresMined = 0;
private int coalPrice, mithrilPrice, mithrilMined, coalMined, profit;
private final Area BANK = new Area(new Tile(3009, 3355, 0), new Tile(3018, 3358, 0));
private final Area MINE = new Area(new Tile(3026, 9730, 0), new Tile(3060, 9756, 0));
private final Area BELOW_LADDER = new Area(new Tile(3017, 9735, 0), new Tile(3025, 9742, 0));
private final Area ABOVE_LADDER = new Area(new Tile(3014, 3336, 0), new Tile(3024, 3343, 0));
private final Tile MID_BANK = new Tile(3013, 3355, 0);
private final Tile MINE_LADDER_ABOVE_TILE = new Tile(3021, 3340, 0);
private final Tile MINE_LADDER_BELOW_TILE = new Tile(3021, 9739, 0);
private final Tile CENTER_MINE = new Tile(3044, 9740, 0);
private final int BELOW_MINE_LADDER = 6226;
private final int ABOVE_MINE_LADDER = 2113;
private final int CAMRANGE = 90;
public static String status = "", User, ROOT;
int startExp, expGained, carriedItems;
long startTime, profitHour;
public static boolean start = false;
public static boolean invoked = false;
GrandExchange ge = new GrandExchange();
private double getVersion() {
return 1.4;
}
@Override
protected void setup() {
// Dynamic Sigs
try {
ROOT = new File(".").getCanonicalPath();
System.out.println(ROOT);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
File f = new File(ROOT + File.separatorChar + "user.txt");
try {
System.out.println(f.getCanonicalPath());
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
if (f.exists()) {
log.info("Save Exists");
FileReader fr = null;
try {
fr = new FileReader(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader br = new BufferedReader(fr);
try {
User = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("User: " + User);
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
User = JOptionPane.showInputDialog(null,
"Enter a Sig Username: ");
}
});
Writer out = null;
try {
out = new OutputStreamWriter(new FileOutputStream(f));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out.write(User);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// Create instances
ShowGUI show = new ShowGUI();
provide(new Strategy(show, show));
WaitGUI wait = new WaitGUI();
provide(new Strategy(wait, wait));
SkillGuide skillguide = new SkillGuide();
provide(new Strategy(skillguide,skillguide));
AntiLag antilag = new AntiLag();
provide(new Strategy(antilag,antilag));
WalkBelowLadder wBL = new WalkBelowLadder();
provide(new Strategy(wBL, wBL));
WalkMine wM = new WalkMine();
provide(new Strategy(wM, wM));
GoUpLadder gUL = new GoUpLadder();
provide(new Strategy(gUL, gUL));
WalkAboveLadder wAL = new WalkAboveLadder();
provide(new Strategy(wAL, wAL));
GoDownLadder gDL = new GoDownLadder();
provide(new Strategy(gDL, gDL));
WalkBank wB = new WalkBank();
provide(new Strategy(wB, wB));
Bank b = new Bank();
provide(new Strategy(b, b));
Mine m = new Mine();
provide(new Strategy(m, m));
startExp = Skills.getExperiences()[14];
startTime = System.currentTimeMillis();
Camera.setPitch(true);
Camera.setAngle(180);
try{
coalPrice = ge.getCurrentGuidePrice(453);
mithrilPrice = ge.getCurrentGuidePrice(447);
}
catch(Exception e){
log.info("Failed to get prices");
}
if(Inventory.getCount(1275) == 1){
carriedItems = 1;
}
}
private class ShowGUI implements Task, Condition {
public boolean validate() {
return !invoked;
}
public void run() {
log.info("we inside showgui nigga");
try {
new GUI().setVisible(true);
while (!start) {
Time.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
}
invoked = true;
}
}
private class WaitGUI implements Task, Condition {
public boolean validate() {
return !start;
}
public void run() {
log.info("Waiting for the user to complete the gui");
Time.sleep(1000);
}
}
private class SkillGuide implements Task, Condition {
public boolean validate() {
return Widgets.get(1218).getChild(1).isVisible() && Widgets.get(1218).getChild(1).validate() ;
}
public void run() {
status = "Closing out of the skill guide";
if(Widgets.get(1218).getChild(73).isVisible()){
Widgets.get(1218).getChild(73).click(true);
Time.sleep(Random.nextInt(500,1000));
}
}
}
private class AntiLag implements Task, Condition {
public boolean validate() {
return !MINE.contains(Players.getLocal().getLocation())
&& !BANK.contains(Players.getLocal().getLocation())
&& !ABOVE_LADDER.contains(Players.getLocal().getLocation())
&& !BELOW_LADDER.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Antilag engaged";
Time.sleep(5000);
}
}
private class WalkBelowLadder implements Task, Condition {
public boolean validate() {
return Inventory.getCount() == 28
&& MINE.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Walking to the mine ladder";
while (!BELOW_LADDER.contains(Players.getLocal().getLocation())) {
Walking.walkTileMM(MINE_LADDER_BELOW_TILE, 0);
}
}
}
private class WalkAboveLadder implements Task, Condition {
public boolean validate() {
return Inventory.getCount() < 28
&& !MINE.contains(Players.getLocal().getLocation())
&& !BELOW_LADDER.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Walking to the guild ladder";
while (!ABOVE_LADDER.contains(Players.getLocal().getLocation())) {
Walking.walkTileMM(MINE_LADDER_ABOVE_TILE, 0);
}
}
}
private class GoUpLadder implements Task, Condition {
public boolean validate() {
return Inventory.getCount() == 28
&& BELOW_LADDER.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Going up the ladder";
SceneObject loc = SceneEntities.getNearest(BELOW_MINE_LADDER);
if (loc.isOnScreen() && loc != null) {
loc.click(true);
Time.sleep(2000);
}
}
}
private class GoDownLadder implements Task, Condition {
public boolean validate() {
return Inventory.getCount() < 28 && ABOVE_LADDER.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Going down the ladder";
SceneObject loc = SceneEntities.getNearest(ABOVE_MINE_LADDER);
if (loc.isOnScreen() && loc != null) {
loc.click(true);
Time.sleep(Random.nextInt(1500, 2500));
}
}
}
private class WalkBank implements Task, Condition {
public boolean validate() {
return Inventory.getCount() == 28
&& !BANK.contains(Players.getLocal().getLocation())
&& !MINE.contains(Players.getLocal().getLocation())
&& !BELOW_LADDER.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Walking to the bank";
while (!BANK.contains(Players.getLocal().getLocation())) {
Walking.walkTileMM(MID_BANK, 0);
Time.sleep(Random.nextInt(3000, 4000));
}
}
}
private class WalkMine implements Task, Condition {
public boolean validate() {
return Inventory.getCount() < 28 && BELOW_LADDER.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Walking to the rocks";
while (!MINE.contains(Players.getLocal().getLocation())) {
Walking.walkTileMM(CENTER_MINE, 0);
Time.sleep(Random.nextInt(3000, 4000));
}
}
}
private class Bank implements Task, Condition {
public boolean validate() {
return Inventory.getCount() == 28 && BANK.contains(Players.getLocal().getLocation());
}
public void run() {
status = "Banking";
SceneObject loc = SceneEntities.getNearest(BOOTHS);
if (!bankIsOpen()) {
if (loc.isOnScreen() && loc != null) {
loc.click(true);
Time.sleep(Random.nextInt(1500, 2500));
}
}
if (bankIsOpen()) {
depositAll();
Time.sleep(Random.nextInt(100, 300));
}
}
}
private class Mine implements Task, Condition {
public boolean validate() {
return Inventory.getCount() < 28 && MINE.contains(Players.getLocal().getLocation());
}
public void run() {
SceneObject loc = SceneEntities.getNearest(rock);
if (Players.getLocal().getAnimation() == -1) {
status = "Mining";
Antiban();
if (loc.isOnScreen() && loc != null && MINE.contains(loc.getLocation())) {
loc.click(true);
Time.sleep(Random.nextInt(1500, 2500));
}
} else if (Walking.distanceTo(SceneEntities.getNearest(rock).getLocation()) == 1 && (Players.getLocal().getAnimation() != -1)){
status = "Chillen";
Time.sleep(Random.nextInt(10, 100));
}
else{
status = "Mining";
Antiban();
if (loc.isOnScreen() && loc != null && MINE.contains(loc.getLocation())) {
loc.click(true);
Time.sleep(Random.nextInt(1500, 2500));
}
}
}
}
private boolean bankIsOpen() {
return Widgets.get(762).getChild(45).isVisible();
}
private void depositAll() {
Widgets.get(762).getChild(33).interact("Deposit");
}
static class Walking {
public static int angleTo(Tile tile) {
final double ydif = tile.getY() - Players.getLocal().getLocation().getY();
final double xdif = tile.getX() - Players.getLocal().getLocation().getX();
return (int) (Math.atan2(ydif, xdif) * 180 / Math.PI);
}
public static float distanceTo(Tile tile) {
return (float) Calculations.distance(Players.getLocal()
.getLocation(), tile);
}
public static boolean walkTileMM(Tile tile, int rnd) {
float angle = angleTo(tile) - Camera.getAngleTo(0);
float distance = distanceTo(tile);
if (distance > 18) {
distance = 18;
}
angle = (float) (angle * Math.PI / 180);
int x = 627, y = 85;
int dx = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
.cos(angle));
int dy = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
.sin(angle));
return Mouse.click(x + dx, y - dy, true);
}
}
private void Antiban() {
int i = Random.nextInt(1, 20);
if (i == 5) {
Camera.setAngle(Random.nextInt(CAMRANGE - 40, CAMRANGE + 40));
}
}
public String formatTime(final long milliseconds) {
final long t_seconds = milliseconds / 1000;
final long t_minutes = t_seconds / 60;
final long t_hours = t_minutes / 60;
final long seconds = t_seconds % 60;
final long minutes = t_minutes % 60;
final long hours = t_hours % 500;
return hours + ":" + minutes + ":" + seconds;
}
public String formatXP(long paramLong) {
if (paramLong >= 1000000000L) {
return paramLong / 1000000000L + "BIL";
}
if (paramLong >= 10000000L) {
return paramLong / 1000000L + "MIL";
}
if (paramLong >= 1000L) {
return paramLong / 1000L + "K";
}
return "" + paramLong;
}
public void onRepaint(Graphics g) {
expGained = Skills.getExperiences()[14] - startExp;
long xpHour = (long) (3600000.0 / (System.currentTimeMillis() - startTime) * (expGained));
oresMined = coalMined + mithrilMined;
profit = coalPrice*coalMined + mithrilPrice*mithrilMined;
profitHour = (long) (3600000.0 / (System.currentTimeMillis() - startTime) * (profit));
g.setColor(new Color(0, 0, 0));
g.fillRect(547, 404, 191, 61);
g.setColor(new Color(255, 255, 255));
g.setFont(new Font("Arial", 1, 10));
g.drawString("RedexGuildMiner by Soviet v" + getVersion(), 555, 415);
g.drawString("Status : " + status, 555, 460);
g.drawString("" + formatTime(System.currentTimeMillis() - startTime), 555, 445);
g.drawString("XP/H : " + formatXP(xpHour), 555, 430);
g.drawString("Profit : " + formatXP(profit), 650, 430);
g.drawString("Profit/H : " + formatXP(profitHour), 650, 445);
g.drawString("Ores Mined : " + oresMined, 650, 460);
}
public class GUI extends javax.swing.JFrame {
/**
* Creates new form GUI
*/
public GUI() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel1.setText("Redex Guild Miner by Soviet");
jRadioButton1.setText("Mine Mithril");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jButton1.setText("Start ");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(47, 47, 47))
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioButton1)
.addGap(35, 35, 35)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(35, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jRadioButton1))
.addGap(0, 13, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if (jRadioButton1.isSelected()) {
rock = mixedID;
} else {
rock = coalID;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
start = true;
dispose();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JRadioButton jRadioButton1;
// End of variables declaration
}
//Dynamic sig log
public void onStop() {
try {
URL SIG = new URL(
"http://redexscripting.org/php/miner/MinerSig.php?user=" + User
+ "&time="
+ (System.currentTimeMillis() - startTime)
+ "&exp=" + expGained + "&ores=" + oresMined );
SIG.openStream().read();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @author iJava
*/
static class GrandExchange {
String[] currGuidePriceData;
public String readPage(URL url, String referer) throws IOException,
InterruptedException {
URLConnection uc = url.openConnection();
uc.addRequestProperty(
"Accept",
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
uc.addRequestProperty("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
uc.addRequestProperty("Accept-Encoding", "gzip,deflate");
uc.addRequestProperty("Accept-Language", "en-gb,en;q=0.5");
uc.addRequestProperty("Connection", "keep-alive");
uc.addRequestProperty("Host", "www.runescape.com");
uc.addRequestProperty("Keep-Alive", "300");
if (referer != null && !referer.trim().equals("")) {
uc.addRequestProperty("Referer", referer);
}
uc.addRequestProperty(
"User-Agent",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6");
DataInputStream di = new DataInputStream(uc.getInputStream());
byte[] buffer = new byte[uc.getContentLength()];
di.readFully(buffer);
di.close();
Thread.sleep(250 + (int) Math.random() * 500);
return new String(buffer);
}
public int getCurrentGuidePrice(int itemID) throws IOException,
InterruptedException {
URL url = new URL(
"http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item="
+ itemID);
String html = readPage(url, "http://google.com");
currGuidePriceData = html
.split("\"current\":\\{\"trend\":\"neutral\",\"price\":|\\},\"today\":\\{\"trend\"");
return Integer.parseInt(currGuidePriceData[1].replace(",", "")
.replace("\"", ""));
}
}
public void messageReceived(MessageEvent e) {
String x = e.getMessage().toLowerCase();
if (x.contains("you manage to mine some coal")){
coalMined++;
}
else if (x.contains("you manage to mine some mithril")){
mithrilMined++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment