Skip to content

Instantly share code, notes, and snippets.

@TheBatScripts
Created April 21, 2012 05:46
Show Gist options
  • Save TheBatScripts/2434463 to your computer and use it in GitHub Desktop.
Save TheBatScripts/2434463 to your computer and use it in GitHub Desktop.
BatNatureRunes
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.runedream.api.Script;
import org.runedream.api.ScriptManifest;
import org.runedream.api.methods.Bank;
import org.runedream.api.methods.Game;
import org.runedream.api.methods.Inventory;
import org.runedream.api.methods.Mouse;
import org.runedream.api.methods.OCR;
import org.runedream.api.methods.Tabs;
import org.runedream.api.util.Log;
import org.runedream.api.util.Random;
import org.runedream.api.util.Time;
import org.runedream.api.wrappers.GeItem;
import org.runedream.api.wrappers.Menu;
import org.runedream.api.wrappers.Tab;
@ScriptManifest(
authors = { "TheBat"},
name = "BatNatureRunes",
version = 1.0,
description = "Crafts Natures by doing shit",
keywords = {},
language = { true, true, true, true })
public class BatNatureRunes extends Script{
final private static Rectangle MINIMAP = new Rectangle(548,6,156,156);
final private static Rectangle VIEWPORT = new Rectangle(4,4,513,335);
//dtm for spirit graahk
Point[] SPIRIT_GR_DTM_PTS = { new Point( 580, 231), new Point( 582, 219), new Point( 589, 235), new Point( 575, 233)};
Color[] SPIRIT_GR_DTM_RGB = { new Color( 193, 111, 59), new Color( 193, 188, 167), new Color( 174, 169, 150), new Color( 195, 190, 168)};
DTemp dtmSpiritGraahk1 = new DTemp(SPIRIT_GR_DTM_PTS, SPIRIT_GR_DTM_RGB);
//dtm for ring of duelling
Point[] RING_OF_DUELLING_DTM_PTS = { new Point( 93, 112), new Point( 103, 109), new Point( 92, 103), new Point( 104, 101)};
Color[] RING_OF_DUELLING_DTM_RGB = { new Color( 192, 165, 27), new Color( 124, 107, 17), new Color( 111, 95, 15), new Color( 17, 121, 20)};
DTemp dtmRing1 = new DTemp(RING_OF_DUELLING_DTM_PTS, RING_OF_DUELLING_DTM_RGB);
//dtm for swords
Point[] SWORDS1_DTM_PTS = { new Point( 337, 158), new Point( 347, 155), new Point( 339, 170)};
Color[] SWORDS1_DTM_RGB = { new Color( 253, 250, 36), new Color( 253, 218, 36), new Color( 231, 229, 33)};
DTemp dtmSwords1 = new DTemp(SWORDS1_DTM_PTS, SWORDS1_DTM_RGB);
Point[] SWORDS2_DTM_PTS = { new Point( 330, 164), new Point( 331, 173), new Point( 341, 157)};
Color[] SWORDS2_DTM_RGB = { new Color( 247, 245, 36), new Color( 237, 235, 34), new Color( 220, 190, 32)};
DTemp dtmSwords2 = new DTemp(SWORDS2_DTM_PTS, SWORDS2_DTM_RGB);
//dtm for bank symbol
Point[] BANK_SYM_DTM_PTS = { new Point( 634, 86), new Point( 634, 94)};
Color[] BANK_SYM_DTM_RGB = { new Color( 239, 226, 172), new Color( 238, 210, 36)};
DTemp dtmBankSym1 = new DTemp(BANK_SYM_DTM_PTS, BANK_SYM_DTM_RGB);
//dtm for obelisk symbol
Point[] OBE_SYM_DTM_PTS = { new Point( 612, 87), new Point( 613, 81), new Point( 618, 86), new Point( 608, 86)};
Color[] OBE_SYM_DTM_RGB = { new Color( 225, 227, 225), new Color( 225, 227, 225), new Color( 192, 192, 192), new Color( 192, 192, 192)};
DTemp dtmObeSym1 = new DTemp(OBE_SYM_DTM_PTS, OBE_SYM_DTM_RGB);
//dtm for RC symbol
Point[] RC_DTM_PTS = { new Point( 691, 97), new Point( 688, 94), new Point( 694, 101)};
Color[] RC_DTM_RGB = { new Color( 246, 183, 1), new Color( 247, 16, 3), new Color( 246, 183, 1)};
DTemp dtmRCSym1 = new DTemp(RC_DTM_PTS, RC_DTM_RGB);
//dtm for Trans symbol
Point[] TRANS_SYM_DTM_PTS = { new Point( 613, 92), new Point( 608, 96), new Point( 620, 96)};
Color[] TRANS_SYM_DTM_RGB = { new Color( 233, 106, 24), new Color( 233, 106, 24), new Color( 233, 106, 24)};
DTemp dtmTransSym1 = new DTemp(TRANS_SYM_DTM_PTS, TRANS_SYM_DTM_RGB);
//dtm for ruins
Point[] RUINS_DTM_PTS = { new Point( 297, 230)};
Color[] RUINS_DTM_RGB = { new Color( 149, 253, 76)};
DTemp dtmRuins1 = new DTemp(RUINS_DTM_PTS, RUINS_DTM_RGB);
//dtm for obelisk
Point[] OBE_DTM_PTS = { new Point( 379, 124), new Point( 372, 137)};
Color[] OBE_DTM_RGB = { new Color( 206, 189, 114), new Color( 210, 192, 116)};
DTemp dtmObe1 = new DTemp(OBE_DTM_PTS, OBE_DTM_RGB);
//dtm for equippment
Point[] EQUIP_DTM_PTS = { new Point( 496, 330), new Point( 23, 11), new Point( 486, 20)};
Color[] EQUIP_DTM_RGB = { new Color( 147, 147, 147), new Color( 210, 210, 210), new Color( 252, 176, 44)};
DTemp dtmEquip = new DTemp(EQUIP_DTM_PTS, EQUIP_DTM_RGB);
//dtm for nature rune
Point[] NAT_DTM_PTS = { new Point( 577, 226), new Point( 586, 229), new Point( 569, 229)};
Color[] NAT_DTM_RGB = { new Color( 17, 123, 19), new Color( 127, 121, 121), new Color( 97, 93, 93)};
DTemp dtmNat1 = new DTemp(NAT_DTM_PTS, NAT_DTM_RGB);
private static BufferedImage back = null;
private static long TIME = 0;
private String status = "Finding bank";
private boolean needNewRing = false, needNewPouch = false;
public static boolean stopAtOb = false;
public static boolean staminaFull = true;
public static int walkmod = 1;
private Menu menu;
private int remainingCharges = 0;
private SummoningChecker sumChk = new SummoningChecker();
private int profit = 0;
private int crafted = 0;
private String version = "1.0";
private int exp = 9;
private boolean showPaint = true;
private int priceNat = 0;
private int priceEss = 0;
private int totUsed = 0;
private StaminaChecker staminaCheck = new StaminaChecker();
private int trys = 0;
private static boolean rest = false;
public boolean onStart(){
try {
back = ImageIO.read(new File("./Storage/BatScripts/backPick.png"));
}catch (FileNotFoundException e) {
}catch (IOException e) {
try {
Log.log("Images not found, retrieving from internet.",Color.RED);
back = ImageIO.read(new URL("http://i1066.photobucket.com/albums/u406/bootsncats/underPaint.png"));
File file = new File("./Storage/BatScripts/backPick.png");
file.getParentFile().mkdirs();
ImageIO.write(back, "png",file);
} catch (IOException ex) {
}
}
priceNat = GeItem.lookup(2351).getPrice();
priceEss = GeItem.lookup(440).getPrice();
sumChk.start();
staminaCheck .start();
TIME = System.currentTimeMillis();
status = "Finding bank";
return true;
}
public void onStop(){
staminaCheck.interrupt();
sumChk.interrupt();
}
/**********************************************************************************/
/******************************* LOOP *********************************************/
/**********************************************************************************/
public int loop() {
Mouse.setSpeed(Random.random(2,4));
if(dtmEquip.findDTMS(20)){
Mouse.click(486,20);
}
if(Integer.parseInt(OCR.findString(new Rectangle(735,103,25,18), null, true)) >= 50 && !checkColor(new Color(217,180,58), new Point(723,105), 10)){
Mouse.click(725,100);
}
if(rest){
Mouse.click(725,100,false);
Time.sleep(400);
Mouse.click(725,140);
Time.sleep(400);
try{
while(Integer.parseInt(OCR.findString(new Rectangle(735,103,25,18), null, true)) != 100){
Time.sleep(100);
}
}catch(Exception e){}
Mouse.click(725,100);
rest = false;
}
if(status.equals("Finding bank")){
if(trys >= 6){
trys = 0;
status = "Teleporting via ring";
return 100;
}
if(!Bank.isOpen()){
if(dtmSwords1.findDTMS(20, VIEWPORT)){
int i = Random.random(0,dtmSwords1.getList().size()-1);
Point bankPt = dtmSwords1.getDTM(i);
if(!Bank.isOpen()) Mouse.click(bankPt.x-35,bankPt.y);
Time.sleep(1000);
}else if(dtmSwords2.findDTMS(20, VIEWPORT)){
int i = Random.random(0,dtmSwords2.getList().size()-1);
Point bankPt = dtmSwords2.getDTM(i);
if(!Bank.isOpen())Mouse.click(bankPt.x-35,bankPt.y);
Time.sleep(1000);
}else if(dtmBankSym1.findDTMS(20, MINIMAP)){
int i = Random.random(0,dtmBankSym1.getList().size()-1);
Point SymPt = dtmBankSym1.getDTM(i);
Time.sleep(400);
if(!Bank.isOpen())Mouse.click(SymPt);
else {
status = "Banking";
return 100;
}
Time.sleep(3500);
}else{
trys ++;
}
}
if(Bank.isOpen()){
status = "Banking";
}
return 100;
}
if(status.equals("Banking")){
if(Bank.isOpen()){
Bank.depositAll();
}
Time.sleep(600);
if(needNewRing){
if(dtmRing1.findDTMS(20, VIEWPORT)){
int i = Random.random(0,dtmRing1.getList().size()-1);
Point ringPt = dtmRing1.getDTM(i);
Mouse.click(ringPt);
}
int k = 0;
while(k <= 15 && !dtmRing1.findDTMS(20, Inventory.getSlotAt(0).getBounds())){
Time.sleep(100);
k++;
}
Time.sleep(800);
if(k < 15){
int i = Random.random(0,dtmRing1.getList().size()-1);
Point ringPt = dtmRing1.getDTM(i);
Mouse.click(ringPt,false);
Time.sleep(400);
Mouse.click(ringPt.x,ringPt.y+40);
needNewRing = false;
}
Time.sleep(500);
return 100;
}
if(needNewPouch){
if(dtmSpiritGraahk1.findDTMS(20, VIEWPORT)){
int i = Random.random(0,dtmSpiritGraahk1.getList().size()-1);
Point pouchPt = dtmSpiritGraahk1.getDTM(i);
Mouse.click(pouchPt);
}
int k = 0;
while(k <= 15 && !dtmSpiritGraahk1.findDTMS(20, Inventory.getSlotAt(0).getBounds())){
Time.sleep(100);
k++;
}
Time.sleep(800);
if(k < 15){
Mouse.click(489,30);
Time.sleep(800);
if(!Bank.isOpen()){
int i = Random.random(0,dtmSpiritGraahk1.getList().size()-1);
Point pouchPt = dtmSpiritGraahk1.getDTM(i);
Mouse.click(pouchPt,false);
Time.sleep(400);
Mouse.click(pouchPt.x,pouchPt.y+43);
status = "Finding bank";
needNewPouch = false;
}
}
Time.sleep(500);
return 100;
}
Mouse.move(55,110);
Time.sleep(500);
withdrawAll();
Time.sleep(500);
Mouse.click(489,30);
status = "Teleporting via Graahk";
return 100;
}
if(status.equals("Teleporting via Graahk")){
sumChk.interrupt();
Mouse.click(710,145,false);
Time.sleep(300);
try{
menu.getActions();
if(!menu.contains("nterac")){
needNewPouch = true ;
status = "Finding bank";
return 100;
}
menu.interact("nterac");
}catch(NullPointerException e){
needNewPouch = true;
status = "Finding bank";
return 100;
}
sumChk = new SummoningChecker();
sumChk.start();
Time.sleep(1000);
if(checkColor(new Color(11,17,19),new Point(26,351),20)) Mouse.click(255,434);
else return 100;
int k = 0;
while(k <= 30 && !dtmTransSym1.findDTMS(20, MINIMAP)){
Time.sleep(100);
k++;
}
status = "Running to ruins";
return 100;
}
if(status.equals("Running to ruins")){
Time.sleep(300);
if(stopAtOb){
int k = 0;
while(k <= 35 && !dtmObeSym1.findDTMS(20, MINIMAP)){
if(rest){
Mouse.click(725,100,false);
Time.sleep(400);
Mouse.click(725,140);
Time.sleep(400);
try{
while(Integer.parseInt(OCR.findString(new Rectangle(735,103,25,18), null, true)) != 100){
Time.sleep(100);
}
}catch(Exception e){}
Mouse.click(725,100);
rest = false;
}
Time.sleep(2400);
Mouse.click(680,70);
k++;
}
if(k < 70){
Mouse.click(dtmObeSym1.getDTM(0));
k = 0;
while(k <= 70 && !dtmObe1.findDTMS(20, VIEWPORT)){
if(rest){
Mouse.click(725,100,false);
Time.sleep(400);
Mouse.click(725,140);
Time.sleep(400);
try{
while(Integer.parseInt(OCR.findString(new Rectangle(735,103,25,18), null, true)) != 100){
Time.sleep(100);
}
}catch(Exception e){}
Mouse.click(725,100);
rest = false;
}
Time.sleep(100);
k++;
}
if(k < 70){
Mouse.click(dtmObe1.getDTM(0));
int temp = Integer.parseInt(OCR.findString(new Rectangle(721,141,20,14), null, true));
k = 0;
while(k <= 50 && Integer.parseInt(OCR.findString(new Rectangle(721,141,20,14), null, true)) == temp){
Time.sleep(100);
}
if(k < 50){
stopAtOb = false;
return 100;
}else{
if(dtmObe1.findDTMS(20, VIEWPORT)){
Mouse.click(dtmObe1.getDTM(0));
}else{
if(dtmObeSym1.findDTMS(20, MINIMAP)){
Mouse.click(dtmObeSym1.getDTM(0));
}
}
}
}
}
return 100;
}
int k = 0;
while(k <= 50 && !dtmRCSym1.findDTMS(20, MINIMAP)){
if(rest){
Mouse.click(725,100,false);
Time.sleep(400);
Mouse.click(725,140);
Time.sleep(400);
try{
while(Integer.parseInt(OCR.findString(new Rectangle(735,103,25,18), null, true)) != 100){
Time.sleep(100);
}
}catch(Exception e){}
Mouse.click(725,100);
rest = false;
}
Time.sleep(600);
Mouse.click(690,80);
k++;
}
if(k < 50){
Mouse.click(dtmRCSym1.getDTM(0).x, dtmRCSym1.getDTM(0).y + 15);
k = 0;
while(k <= 40 && !dtmRuins1.findDTMS(20, VIEWPORT)){
Time.sleep(100);
k++;
}
if(k <= 40){
Mouse.click(dtmRuins1.getDTM(0));
status = "Crafting runes";
}else{
if(dtmRCSym1.findDTMS(20, MINIMAP)){
Mouse.click(dtmRCSym1.getDTM(0));
}
}
}
return 100;
}
if(status.equals("Crafting runes")){
try{
if(!Tabs.getOpenTab().equals(Tab.INVENTORY)){
Tabs.openTab(Tab.INVENTORY);
}
}catch(NullPointerException e){
if(dtmEquip.findDTMS(20)){
Mouse.click(486,20);
}
Tabs.openTab(Tab.INVENTORY);
}
int k = 0;
while(k <= 70 && !dtmTransSym1.findDTMS(20, MINIMAP)){
Time.sleep(100);
k++;
}
if(k > 70){
status = "Running to ruins";
if(dtmRuins1.findDTMS(20, VIEWPORT)){
Mouse.click(dtmRuins1.getDTM(0));
status = "Crafting runes";
}else return 100;
}
Mouse.click(254,4);
k = 0;
while(k <= 30 && !dtmNat1.findDTMS(20, Inventory.getSlotAt(0).getBounds())){
Time.sleep(100);
k++;
}
try{
crafted += Integer.parseInt(OCR.findString(new Rectangle(558,208,29,16), null, true));
totUsed += 28;
}catch(Exception e){}
status = "Teleporting via ring";
return 100;
}
if(status.equals("Teleporting via ring")){
if(!Tabs.getOpenTab().equals(Tab.EQUIPMENT)){
Tabs.openTab(Tab.EQUIPMENT);
}
Time.sleep(400);
Mouse.click(696,385,false);
Time.sleep(400);
menu.getActions();
String getNum = menu.getActionStrings()[1];
try{
remainingCharges = Integer.parseInt(getNum.charAt(getNum.length()-1) + "");
}catch(StringIndexOutOfBoundsException e){
Mouse.click(696,385,false);
Time.sleep(400);
remainingCharges = Integer.parseInt(getNum.charAt(getNum.length()-1) + "");
}
if(remainingCharges == 1)needNewRing = true;
menu.interact("Castle Wars");
Time.sleep(400);
if(!Tabs.getOpenTab().equals(Tab.INVENTORY)){
Tabs.openTab(Tab.INVENTORY);
}
if(dtmEquip.findDTMS(20)){
Mouse.click(486,20);
}
int k = 0;
while(k <= 30 && !dtmBankSym1.findDTMS(20, MINIMAP)){
Time.sleep(100);
k++;
}
status = "Finding bank";
return 100;
}
return 100;
}
/**********************************************************************************/
/******************************* END LOOP *****************************************/
/**********************************************************************************/
private void withdrawAll(){
Mouse.click(false);
Time.sleep(400);
Mouse.click(Mouse.getLocation().x, (Mouse.getLocation().y + Random.random(102,114)));
}
/**
* Returns whether the given point is a certain color.
* Accounts for the variable colors that runescape produces whenever you log in.
* @param col
* - Color to check for.
* @param p
* - Point to check at.
* @return
*/
private static boolean checkColor(Color col, Point p, int tol){
if(Math.abs(col.getRed() - Game.getColorAt(p).getRed()) < tol)
if(Math.abs(col.getGreen() - Game.getColorAt(p).getGreen()) < tol)
if(Math.abs(col.getBlue() - Game.getColorAt(p).getBlue()) < tol)
return true;
return false;
}
public void onRepaint(Graphics g){
profit = priceNat * crafted - priceEss * totUsed;
if(showPaint ){
g.drawImage(back, 5, 343, null);
g.setColor(Color.BLACK);
g.setFont(new Font("Salaryman", 1, 14));
g.drawString("Time Running: " + Time.getTimeString(System.currentTimeMillis() - TIME), 11, 358);
g.drawString("TotalCrafted: " + crafted ,11,373);
try{
g.drawString("Crafted/Hour: " + (3600000*(long)crafted)/(int)(System.currentTimeMillis() - TIME),11,388);
g.drawString("Exp./Hour: " + (int)(exp *(3600000*(long)crafted)/(int)(System.currentTimeMillis() - TIME)),11,403);
g.drawString("Profit/Hour: " + (int)((long)profit *(3600000/(System.currentTimeMillis() - TIME))),11,418);
}catch(ArithmeticException e){}
g.drawString("Status: " + status ,11,433);
g.setFont(new Font("Salaryman", 1, 25));
g.drawString("BatNatureRunes",270,390);
g.drawString("Version " + version,265,420);
g.setColor(Color.RED);
g.drawString("x",500,360);
}else{
g.setColor(Color.GREEN);
g.setFont(new Font("Salaryman", 1, 25));
g.drawString("o",500,360);
}
g.setColor(Color.CYAN);
g.drawLine(Mouse.getLocation().x,0,Mouse.getLocation().x,2100);
g.drawLine(0,Mouse.getLocation().y,2100,Mouse.getLocation().y);
}
class SummoningChecker extends Thread implements Runnable {
private Rectangle readIn = new Rectangle(721,141,20,14);
private int test = 300;
public SummoningChecker() {
this.setPriority(MIN_PRIORITY);
}
@Override
public void run() {
try{
while (!Thread.interrupted()) {
sleep(1000);
try{
test = Integer.parseInt(OCR.findString(readIn, null, true));
}catch(NumberFormatException e){
test = 300;
}
if (test <= 10){
BatNatureRunes.stopAtOb = true;
}
if(Thread.interrupted()) return;
}
} catch (InterruptedException e) {
} finally{}
}
}
class StaminaChecker extends Thread implements Runnable {
private Rectangle readIn = new Rectangle(735,103,25,18);
private int test = 300;
public StaminaChecker() {
this.setPriority(MIN_PRIORITY);
}
@Override
public void run() {
try{
while (!Thread.interrupted()) {
sleep(1000);
try{
test = Integer.parseInt(OCR.findString(readIn, null, true));
}catch(NumberFormatException e){
test = 300;
}
if (test <= 1){
BatNatureRunes.rest = true;
}
if(Thread.interrupted()) return;
}
} catch (InterruptedException e) {
} finally{}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment