Skip to content

Instantly share code, notes, and snippets.

@TheBatScripts
Created May 3, 2012 04:01
Show Gist options
  • Save TheBatScripts/2583044 to your computer and use it in GitHub Desktop.
Save TheBatScripts/2583044 to your computer and use it in GitHub Desktop.
BatRuneSpan 1.2
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import com.rarebot.event.listeners.PaintListener;
import com.rarebot.script.Script;
import com.rarebot.script.ScriptManifest;
import com.rarebot.script.methods.Skills;
import com.rarebot.script.util.SkillData;
import com.rarebot.script.util.Timer;
import com.rarebot.script.wrappers.RSItem;
import com.rarebot.script.wrappers.RSNPC;
import com.rarebot.script.wrappers.RSObject;
import com.rarebot.script.wrappers.RSTile;
@ScriptManifest(authors = {"TheBat"},
keywords = {"Runecrafting"},
name = "BatRuneSpan",
description = "Trains RC in RuneSpan",
version = 1.2)
public class BatRuneSpan extends Script implements PaintListener, MouseListener{
public static double version = 1.2;
private NumberFormat k = new DecimalFormat("###,###,###");
public Timer runTime = new Timer(0);
public SkillData info;
public Long START_TIME;
private double initPoints = 0;
public int[] SKILLS_ARRAY = new int[25];
private String status = "Starting up";
Rectangle hideR = new Rectangle(450,300,50,20);
Rectangle opR = new Rectangle(450,275,50,20);
boolean hide = false;
private RSTile START_TILE;
private ArrayList<String> monsterNames = new ArrayList<String>();
private ArrayList<String> nodeNames = new ArrayList<String>();
private ArrayList<String> allNodes = new ArrayList<String>();
private ArrayList<String> allMonsters = new ArrayList<String>();
private GUI gui;
private String curNode = "";
private boolean useNodes = true;
private boolean origUseNodes = true;
private int mouseSpeed = 7;
private int nodeRad = 12;
private int monRad = 12;
private int rockRad = 15;
public boolean onStart() {
info = skills.getSkillDataInstance();
initPoints = calcPoints();
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
gui = new GUI(info.level(20),true);
gui.setVisible(true);
}
});
} catch (InterruptedException ex) {
} catch (InvocationTargetException ex) {
}
while(gui.isVisible()){
sleep(100);
}
grabGUIInfo();
getSkillData();
START_TIME = System.currentTimeMillis();
return true;
}
private void grabGUIInfo() {
START_TILE = getMyPlayer().getLocation();
useNodes = origUseNodes;
if(origUseNodes)status = "Searching for Nodes";
else status = "Searching for Monsters";
}
public int loop() {
mouse.setSpeed(mouseSpeed);
while(gui.isVisible()){
sleep(100);
}
if(!useNodes && origUseNodes)try{
if(inventory.getItem(24227).getStackSize() > 300)useNodes = true;
}catch(NullPointerException e){}
try{
inventory.getItem(24227).getStackSize();
}catch(NullPointerException e){
status = "Finding floating essence";
try{
RSNPC rock = npcs.getNearest(15402);
if(calc.distanceBetween(START_TILE, rock.getLocation()) <= rockRad){
if (!rock.isOnScreen())camera.turnTo(rock);
rock.interact("Collect");
sleep(400);
while(getMyPlayer().isMoving()){
sleep(200);
}
useNodes = false;
sleep(400);
status = "Searching for Monsters";
}else throw new NullPointerException();
}catch(NullPointerException np){
log(Color.RED,"OH GOD! I RAN OUT OF ESSENCE AND COULDN'T FIND THE FLOATING ROCK, I HAD TO SHUT DOWN!");
return -1;
}
}
if(status.equals("Siphoning Node")){
if(getMyPlayer().getAnimation() != 16596){
status = "Searching for Nodes";
return 100;
}
for(String name:nodeNames){
if(name == curNode)break;
try{
RSObject node = objects.getNearest(name);
if(calc.distanceBetween(START_TILE, node.getLocation()) <= nodeRad){
if (!node.isOnScreen())camera.turnTo(node);
node.interact("Siphon");
sleep(1000);
while(getMyPlayer().isMoving()){
sleep(200);
}
curNode = "";
status = "Siphoning Node";
if(getMyPlayer().getAnimation() == 16596)return 100;
}
}catch(NullPointerException np){}
}
if(random.nextInt(600)<10){
camera.moveRandomly(random.nextInt(1000));
}
return 100;
}
if(useNodes)if(status.equals("Searching for Nodes")){
for(String name:nodeNames){
try{
RSObject node = objects.getNearest(name);
if(calc.distanceBetween(START_TILE, node.getLocation()) <= nodeRad){
if (!node.isOnScreen())camera.turnTo(node);
node.interact("Siphon");
sleep(1000);
while(getMyPlayer().isMoving()){
sleep(200);
}
curNode = name;
status = "Siphoning Node";
if(getMyPlayer().getAnimation() == 16596)return 100;
else status = "Searching for Nodes";
}
}catch(NullPointerException np){}
}
this.
status = "Searching for Monsters";
return 100;
}
if(status.equals("Searching for Monsters")){
for(String name:monsterNames){
try{
RSNPC monster = npcs.getNearest(name);
int dyingAni = 0;
if(name.contains("essling"))dyingAni = 16661;
if(name.contains("esshound"))dyingAni = 16571;
if(name.contains("esswraith"))dyingAni = 16641;
if(monster.getAnimation() != dyingAni && calc.distanceBetween(START_TILE, monster.getLocation()) <= monRad){
if (!monster.isOnScreen())camera.turnTo(monster);
monster.interact("Siphon");
sleep(1000);
while(getMyPlayer().isMoving()){
sleep(200);
}
status = "Siphoning Monster";
return 100;
}
}catch(NullPointerException np){}
}
return 100;
}
if(status.equals("Siphoning Monster")){
if(getMyPlayer().getAnimation() != 16596){
if(useNodes)status = "Searching for Nodes";
else status = "Searching for Monsters";
return 100;
}
for(String name:nodeNames){
if(getMyPlayer().getAnimation() != 16596){
if(useNodes)status = "Searching for Nodes";
else status = "Searching for Monsters";
return 100;
}
if(useNodes)try{
RSObject node = objects.getNearest(name);
if(calc.distanceBetween(START_TILE, node.getLocation()) <= nodeRad){
node.interact("Siphon");
sleep(1000);
while(getMyPlayer().isMoving()){
sleep(200);
}
status = "Siphoning Node";
return 100;
}
}catch(NullPointerException np){}
}
if(random.nextInt(600)<10){
camera.moveRandomly(random.nextInt(1000));
}
return 100;
}
return 100;
}
public void onRepaint(Graphics g) {
int curskill = 20;
long pt = (long) (calcPoints()-initPoints);
final Color OPAQUE_BLACK2 = new Color(0, 0, 0, 180);
final Color GREEN = new Color(85, 110, 36, 180);
final int CUR_XP = info.exp(curskill);
final int CUR_LVL = skills.getRealLevel(curskill);
final double percentage = (double)((double)(CUR_XP - Skills.XP_TABLE[CUR_LVL]) / (double)(Skills.XP_TABLE[CUR_LVL + 1] - Skills.XP_TABLE[CUR_LVL]));
if(!hide){
g.setColor(new Color(0,0,0,175));
g.fill3DRect(1, 215, 515, 123, true);
g.setColor(Color.WHITE);
g.drawRect(hideR.x, hideR.y, hideR.width, hideR.height);
g.drawRect(opR.x, opR.y, opR.width, opR.height);
g.drawString("Options",opR.x+3,opR.y+15);
g.drawString("Hide",hideR.x+13,hideR.y+15);
g.drawLine(0, (int) mouse.getLocation().getY(), game.getWidth(), (int) mouse.getLocation().getY());
g.drawLine((int) mouse.getLocation().getX(), 0, (int) mouse.getLocation().getX(), game.getHeight());
int idx = 213;
g.drawString("Runtime: " + runTime.toElapsedString(), 5, idx+=20);
g.drawString("Status: " + status, 5, idx+=20);
g.drawString("Points/H: " + (int)((3600000*pt)/(System.currentTimeMillis() - START_TIME)), 5, idx+=20);
g.drawString(Skills.SKILL_NAMES[curskill] + " lvl: " + skills.getRealLevel(curskill) + " (" + levelsGained(curskill) +
") | XP: " + k.format(info.expGain(curskill)) + " | XP/H: " + k.format(info.hourlyExp(curskill))
+ " | TTL: " + timeTillLvl(curskill), 5, idx+=20);
g.setColor(OPAQUE_BLACK2);
g.fill3DRect(5, idx+=5, 270, 17, true);
g.setColor(GREEN);
g.fillRect(6, idx+1, (int) (268 * percentage), 15);
g.setColor(Color.WHITE);
g.drawString((int)(100*percentage) +"%",140,idx+=13);
g.drawString("Version " + version, 270,233);
}else{
g.setColor(Color.BLACK);
g.drawRect(hideR.x, hideR.y, hideR.width, hideR.height);
g.drawString("Show",hideR.x+10,hideR.y+15);
}
}
public int levelsGained(final int idx) {
return skills.getRealLevel(idx) - Skills.getLevelAt(info.getStartExp()[idx]);
}
public void getSkillData() {
for (int counter = 0; counter <= 24; counter++) {
SKILLS_ARRAY[counter] = skills.getCurrentExp(counter);
}
}
public String timeTillLvl(final int idx) {
return Timer.format(skills.getTimeTillNextLevel(idx, info.getStartExp()[idx], runTime.getElapsed()));
}
private double calcPoints(){
double points = 0.0;
for(int i = 0; i < 28; i++){
RSItem item = inventory.getItemAt(i);
if(item.getID() == 24215){
points = points + (double)item.getStackSize()*.1;
}else if(item.getID() == 24217){
points = points + (double)item.getStackSize()*.2;
}else if(item.getID() == 24214){
points = points + (double)item.getStackSize()*.3;
}else if(item.getID() == 24216){
points = points + (double)item.getStackSize()*.4;
}else if(item.getID() == 24213){
points = points + (double)item.getStackSize()*.6;
}else if(item.getID() == 24218){
points = points + (double)item.getStackSize()*.7;
}else if(item.getID() == 24223){
points = points + (double)item.getStackSize()*.9;
}else if(item.getID() == 24221){
points = points + (double)item.getStackSize()*1.1;
}else if(item.getID() == 24224){
points = points + (double)item.getStackSize()*1.3;
}else if(item.getID() == 24220){
points = points + (double)item.getStackSize()*1.5;
}else if(item.getID() == 24222){
points = points + (double)item.getStackSize()*1.7;
}else if(item.getID() == 24219){
points = points + (double)item.getStackSize()*2.5;
}else if(item.getID() == 24225){
points = points + (double)item.getStackSize()*3.0;
}else if(item.getID() == 24226){
points = points + (double)item.getStackSize()*3.5;
}
}
return points;
}
class GUI extends JFrame implements ActionListener{
private static final long serialVersionUID = 1356665975000514548L;
GridBagConstraints c;
Container tab1;
Container tab2;
Container tab3;
JTabbedPane tabbedPane = new JTabbedPane();
public boolean OPEN = true;
private JButton startB1 = new JButton("Start");
private JButton startB2 = new JButton("Start");
private JButton startB3 = new JButton("Start");
private JTextField rockRadT = new JTextField(""+rockRad);
private JTextField monRadT = new JTextField(""+monRad);
private JTextField nodeRadT = new JTextField(""+nodeRad);
ArrayList<JCheckBox> mTypes = new ArrayList<JCheckBox>();
ArrayList<JCheckBox> nTypes = new ArrayList<JCheckBox>();
int RCLevel;
static final int minMouse = 0;
static final int maxMouse = 15;
JSlider mouseSpeedSlide = new JSlider(JSlider.HORIZONTAL, minMouse, maxMouse, mouseSpeed);
public GUI(int level, boolean onStart){
super("BatRuneSpan " + version);
RCLevel = level;
tabbedPane = new JTabbedPane();
tab1 = new Container();
tab1.setLayout(new GridBagLayout());
tab2 = new Container();
tab2.setLayout(new GridBagLayout());
tab3 = new Container();
tab3.setLayout(new GridBagLayout());
c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = c.ipadx = 3;
c.insets = new Insets(5, 5, 5, 5);
makeMList();
makeNList();
init();
build();
makeGrey();
if(!onStart)reCheck();
this.setLocationRelativeTo(getParent());
}
private void reCheck() {
for(JCheckBox cb: mTypes){
cb.setSelected(false);
for(String s: monsterNames){
if(cb.getText().toLowerCase().equals(s.toLowerCase())){
cb.setSelected(true);
break;
}
}
}
for(JCheckBox cb: nTypes){
cb.setSelected(false);
for(String s: nodeNames){
if(cb.getText().toLowerCase().equals(s.toLowerCase())){
cb.setSelected(true);
break;
}
}
}
}
private void makeMList(){
mTypes.clear();
mTypes.add(new JCheckBox("Soul esswraith"));
mTypes.add(new JCheckBox("Blood esswraith"));
mTypes.add(new JCheckBox("Death esswraith"));
mTypes.add(new JCheckBox("Law esshound"));
mTypes.add(new JCheckBox("Nature esshound"));
mTypes.add(new JCheckBox("Astral esshound"));
mTypes.add(new JCheckBox("Chaos esshound"));
mTypes.add(new JCheckBox("Cosmic esshound"));
mTypes.add(new JCheckBox("Body esshound"));
mTypes.add(new JCheckBox("Fire essling"));
mTypes.add(new JCheckBox("Earth essling"));
mTypes.add(new JCheckBox("Water essling"));
mTypes.add(new JCheckBox("Mind essling"));
mTypes.add(new JCheckBox("Air essling"));
}
private void makeNList(){
nTypes.clear();
nTypes.add(new JCheckBox("Undead soul"));
nTypes.add(new JCheckBox("Living soul"));
nTypes.add(new JCheckBox("Bloody skulls"));
nTypes.add(new JCheckBox("Blood pool"));
nTypes.add(new JCheckBox("Skulls"));
nTypes.add(new JCheckBox("Jumper"));
nTypes.add(new JCheckBox("Shifter"));
nTypes.add(new JCheckBox("Nebula"));
nTypes.add(new JCheckBox("Chaotic cloud"));
nTypes.add(new JCheckBox("Fire storm"));
nTypes.add(new JCheckBox("Fleshy growth"));
nTypes.add(new JCheckBox("Vine"));
nTypes.add(new JCheckBox("Fireball"));
nTypes.add(new JCheckBox("Rock fragment"));
nTypes.add(new JCheckBox("Water pool"));
nTypes.add(new JCheckBox("Mind storm"));
nTypes.add(new JCheckBox("Cyclone"));
}
private void makeGrey(){
for(int i = 0; i < nTypes.size()-2; i++){
nTypes.get(i).setEnabled(false);
nTypes.get(i).setSelected(false);
}
if(RCLevel >= 5) nTypes.get(14).setEnabled(true);
if(RCLevel >= 9) nTypes.get(13).setEnabled(true);
if(RCLevel >= 14) nTypes.get(12).setEnabled(true);
if(RCLevel >= 17) nTypes.get(11).setEnabled(true);
if(RCLevel >= 20) nTypes.get(10).setEnabled(true);
if(RCLevel >= 27) nTypes.get(9).setEnabled(true);
if(RCLevel >= 35) nTypes.get(8).setEnabled(true);
if(RCLevel >= 40) nTypes.get(7).setEnabled(true);
if(RCLevel >= 44) nTypes.get(6).setEnabled(true);
if(RCLevel >= 54) nTypes.get(5).setEnabled(true);
if(RCLevel >= 65) nTypes.get(4).setEnabled(true);
if(RCLevel >= 77) nTypes.get(3).setEnabled(true);
if(RCLevel >= 83) nTypes.get(2).setEnabled(true);
if(RCLevel >= 90) nTypes.get(1).setEnabled(true);
if(RCLevel >= 95) nTypes.get(0).setEnabled(true);
for(int i = 0; i < nTypes.size()-2; i++){
if(nTypes.get(i).isEnabled())nTypes.get(i).setSelected(true);
}
}
private void build(){
//Start tab1\\
int row = 0;
int col = 0;
for(JCheckBox cb: mTypes){
addToGrid(cb,row,col++,1,.25, tab1);
if(col == 7){
col = 0;
row++;
}
}
addToGrid(startB1,1,8,1,.25, tab1);
//End tab1\\
//Start tab2\\
row = 0;
col = 0;
for(JCheckBox cb: nTypes){
addToGrid(cb,row,col++,1,.25, tab2);
if(col == 9){
col = 0;
row++;
}
}
addToGrid(startB2,1,8,1,.25, tab2);
//End tab2\\
//Start tab3\\
JLabel mLab = new JLabel("MouseSpeed:");
JLabel mLab1 = new JLabel("Fast");
JLabel mLab2 = new JLabel("Slow", JLabel.RIGHT);
addToGrid(mLab1,0,0,1,.25, tab3);
addToGrid(mLab1,1,0,1,.25, tab3);
addToGrid(mLab2,2,0,1,.25, tab3);
addToGrid(mLab,0,1,1,.25, tab3);
addToGrid(mouseSpeedSlide,1,1,2,.25, tab3);
JLabel lab1 = new JLabel("Foating Essence Radius:");
addToGrid(lab1,0,2,1,.25, tab3);
addToGrid(rockRadT,1,2,1,.25, tab3);
JLabel lab2 = new JLabel("Monster Radius:");
addToGrid(lab2,0,3,1,.25, tab3);
addToGrid(monRadT,1,3,1,.25, tab3);
JLabel lab3 = new JLabel("Node Radius:");
addToGrid(lab3,0,4,1,.25, tab3);
addToGrid(nodeRadT,1,4,1,.25, tab3);
addToGrid(startB3,1,8,1,.25, tab3);
//End tab3\\
tabbedPane.addTab("Monsters", tab1);
tabbedPane.addTab("Nodes", tab2);
tabbedPane.addTab("Options", tab3);
getContentPane().add(tabbedPane);
pack();
setVisible(true);
}
private void init(){
for(int i = 0; i < nTypes.size(); i++){
nTypes.get(i).setSelected(true);
}
mouseSpeedSlide.setMajorTickSpacing(5);
mouseSpeedSlide.setMinorTickSpacing(1);
mouseSpeedSlide.setPaintTicks(true);
mouseSpeedSlide.setPaintLabels(true);
startB1.addActionListener(this);
startB2.addActionListener(this);
startB3.addActionListener(this);
}
private void addToGrid(Component comp, int gridx, int gridy, int gridwidth,
double weightx, Container pane) {
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.weightx = weightx;
pane.add(comp, c);
}
public void actionPerformed(ActionEvent e) {
allMonsters.clear();
monsterNames.clear();
for(JCheckBox cb: mTypes){
if(cb.isSelected())monsterNames.add(cb.getText().toLowerCase());
allMonsters.add(cb.getText().toLowerCase());
}
allNodes.clear();
nodeNames.clear();
for(JCheckBox cb: nTypes){
if(cb.isSelected())nodeNames.add(cb.getText().toLowerCase());
allNodes.add(cb.getText().toLowerCase());
}
if(nodeNames.size() == 0)origUseNodes = false;
else origUseNodes = true;
mouseSpeed = mouseSpeedSlide.getValue();
try{
rockRadT.setForeground(Color.BLACK);
rockRadT.setBackground(Color.WHITE);
rockRad = Integer.parseInt(rockRadT.getText());
}catch(NumberFormatException ex){
rockRadT.setForeground(Color.WHITE);
rockRadT.setBackground(Color.RED);
return;
}
try{
monRadT.setForeground(Color.BLACK);
monRadT.setBackground(Color.WHITE);
monRad = Integer.parseInt(monRadT.getText());
}catch(NumberFormatException ex){
monRadT.setForeground(Color.WHITE);
monRadT.setBackground(Color.RED);
return;
}
try{
nodeRadT.setForeground(Color.BLACK);
nodeRadT.setBackground(Color.WHITE);
nodeRad = Integer.parseInt(nodeRadT.getText());
}catch(NumberFormatException ex){
nodeRadT.setForeground(Color.WHITE);
nodeRadT.setBackground(Color.RED);
return;
}
OPEN = false;
dispose();
}
}
public void mouseClicked(MouseEvent e){
if(hideR.contains(e.getPoint()))hide = !hide;
else if(!hide && opR.contains(e.getPoint())){
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
gui = new GUI(info.level(20),false);
gui.setVisible(true);
}
});
} catch (InterruptedException ex) {
} catch (InvocationTargetException ex) {
}
}
grabGUIInfo();
}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent arg0) {}
public void mouseReleased(MouseEvent arg0) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment