- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import com.rarebot.script.methods.Game.Tab;
- import com.rarebot.script.methods.Skills;
- import com.rarebot.script.wrappers.RSItem;
- import com.rarebot.event.events.MessageEvent;
- import com.rarebot.event.listeners.MessageListener;
- import com.rarebot.event.listeners.PaintListener;
- import com.rarebot.script.Script;
- import com.rarebot.script.ScriptManifest;
- import com.rarebot.script.wrappers.RSArea;
- import com.rarebot.script.wrappers.RSComponent;
- import com.rarebot.script.wrappers.RSInterface;
- import com.rarebot.script.wrappers.RSObject;
- import com.rarebot.script.wrappers.RSPath;
- import com.rarebot.script.wrappers.RSTile;
- @ScriptManifest(authors = { "NathanSTG", "Ben KingOfMoria" },
- name = "CannonBallNiggas",
- version = 1.1,
- description = "Makes cannonballs at Al-Kharid, Edgeville, Falador, and Ardougne East. Auto"
- )
- public class CannonBallNiggas extends Script implements PaintListener, MessageListener{
- /************ Variables ************/
- /**
- * ==============
- * Al-Kharid ID's
- * ==============
- */
- //Areas
- private static final RSArea alKharidBankArea = new RSArea(
- new RSTile(3269, 3164), new RSTile(3276, 3170));
- private static final RSArea alKharidFurnaceArea = new RSArea(
- new RSTile(3274, 3184), new RSTile(3279, 3188));
- //IDS
- private static final int alKharidBoothID = 35647;
- private static final int alKharidFurnaceID = 11666;
- //Tiles
- private static final RSTile alKharidBankTile = new RSTile(3270, 3167);
- private static final RSTile alKharidFurnaceTile = new RSTile(3275, 3186);
- /**
- * ==============
- * Edgeville ID's
- * ==============
- */
- //Areas
- private static final RSArea edgevilleBankArea = new RSArea(
- new RSTile(3091, 3494), new RSTile(3098, 3499));
- private static final RSArea edgevilleFurnaceArea = new RSArea(
- new RSTile(3106, 3497), new RSTile(3112, 3504));
- //ID's
- private static final int edgevilleBoothID = 42377;
- private static final int edgevilleFurnaceID = 26814;
- //Tiles
- private static final RSTile edgevilleBankTile = new RSTile(3096, 3497);
- private static final RSTile edgevilleFurnaceTile = new RSTile(3109, 3501);
- /**
- * ============
- * Falador ID's
- * ============
- */
- //Areas
- private static final RSArea fallyBankArea = new RSArea(
- new RSTile(2943, 3368), new RSTile(2949, 3373));
- private static final RSArea fallyFurnaceArea = new RSArea(
- new RSTile(2970, 3367), new RSTile(2977, 3374));
- //ID's
- private static final int fallyBoothID = 1158;
- private static final int fallyFurnaceID = 11666;
- //Tiles
- private static final RSTile fallyBankTile = new RSTile(2946, 3370);
- private static final RSTile fallyFurnaceTile = new RSTile(2974, 3370);
- /**
- * =============
- * Ardougne ID's
- * =============
- */
- //Areas
- private static final RSArea ardougneBankArea = new RSArea(
- new RSTile(2616, 3332), new RSTile(2621, 3336));
- private static final RSArea ardougneFurnaceArea = new RSArea(
- new RSTile(2602, 3307), new RSTile(2605, 3313));
- //ID's
- private static final int ardougneBoothID = 34752;
- private static final int ardougneFurnaceID = 11666;
- //Tiles
- private static final RSTile ardougneBankTile = new RSTile(2617, 3333);
- private static final RSTile ardougneFurnaceTile = new RSTile(2604, 3310);
- /** Universal Variables **/
- //Areas to decide location
- private static final RSArea alKharidArea = new RSArea(new RSTile(3264, 3160), new RSTile(3285, 3195));
- private static final RSArea edgevilleArea = new RSArea(new RSTile(3080, 3484), new RSTile(3116, 3509));
- private static final RSArea fallyArea = new RSArea(new RSTile(2942, 3364), new RSTile(2980, 3382));
- private static final RSArea ardougneArea = new RSArea(new RSTile(2600, 3306), new RSTile(2623, 3340));
- //Vars to be assigned based on location
- private RSArea bankArea;
- private RSArea furnaceArea;
- private int boothID;
- private int furnaceID;
- private RSTile bankTile;
- private RSTile furnaceTile;
- //ID's
- private static final int moldID = 4;
- private static final int ballID = 2;
- private static final int steelID = 2353;
- private static final int interfaceID = 905;
- private static final int[] smeltingAnimation = { 899, 827 };
- //Paths
- private RSPath pathToBank;
- private RSPath pathToFurnace;
- //Control Variables
- private boolean atBank;
- private boolean atFurnace;
- private boolean isSmelting;
- /**
- * Integer to store the location of the player for the script
- *
- * 1 = Al Kharid,
- * 2 = Edgeville,
- * 3 = Falador,
- * 4 = Ardougne,
- * -1 = error
- */
- private int loc;
- //Interface
- private RSInterface smeltInterface = null;
- //Paint Vars
- private long timeStart;
- private String status;
- private String location;
- private int ballPrice;
- private int steelPrice;
- private int profit;
- private int ballsMade;
- private int startingExp;
- private int levelsGained;
- private int totalAntibans;
- private int startLevel;
- private URL url;
- Image bgPaint = null;
- private static final long startTime = System.currentTimeMillis();
- private final Font font1 = new Font("Old English Text MT", 0, 12);
- ScriptManifest info = getClass().getAnnotation(ScriptManifest.class);
- /************ Script Methods ************/
- public boolean onStart(){
- status = "Loading...";
- log("Loading...");
- sleep(500);
- profit = 0;
- ballPrice = loadPrice(ballID);
- steelPrice = loadPrice(steelID);
- isSmelting = false;
- ballsMade = 0;
- startingExp = skills.getCurrentExp(Skills.SMITHING);
- levelsGained = 0;
- timeStart = System.currentTimeMillis();
- totalAntibans = 0;
- startLevel = skills.getCurrentLevel(Skills.SMITHING);
- log("Balls Price: " + ballPrice);
- log("Steel Price: " + steelPrice);
- log("Finding User Location...");
- sleep(3000);
- getSmithingLocation();
- setLocationVars();
- createPaths();
- try {
- url = new URL("http://isdweather.comlu.com/images/paint_background_new.png");
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- refreshBools();
- return true;
- }
- @Override
- public int loop() {
- createPaths();
- refreshBools();
- if(!inventory.contains(steelID)){
- if(inventory.contains(ballID)){
- if(atBank){
- status = "Depositing";
- depositBalls();
- }else{
- status = "Walking to bank";
- walkToBank();
- }
- }else{
- if(atBank){
- status = "Withdrawing";
- withdrawSteel();
- }else{
- status = "Walking to bank";
- walkToBank();
- }
- }
- }else{
- if(atFurnace){
- status = "Smelting";
- smeltBalls();
- }else{
- status = "Walking to furnace";
- walkToFurnace();
- }
- }
- return random(500, 750);
- }
- public void onFinish(){
- log("Thank you for using CannonBallNiggas by NathanSTG and Ben KingOfMoria!");
- env.saveScreenshot(false);
- }
- /************ Custom methods ************/
- /**
- * Sets the integer 'loc' based on where the player is.
- */
- private void getSmithingLocation(){
- RSTile currPos = getMyPlayer().getLocation();
- if(alKharidArea.contains(currPos)){
- loc = 1;
- }else if(edgevilleArea.contains(currPos)){
- loc = 2;
- }else if(fallyArea.contains(currPos)){
- loc = 3;
- }else if(ardougneArea.contains(currPos)){
- loc = 4;
- }else{
- loc = -1;
- }
- }
- /**
- * Sets the variables for the bank and furnace and paths to use based on
- * what area the user was found in.
- */
- private void setLocationVars(){
- switch(loc){
- case 1: //Al-Kharid
- bankArea = alKharidBankArea;
- furnaceArea = alKharidFurnaceArea;
- boothID = alKharidBoothID;
- furnaceID = alKharidFurnaceID;
- bankTile = alKharidBankTile;
- furnaceTile = alKharidFurnaceTile;
- location = "Al Kharid";
- break;
- case 2: //Edgeville
- bankArea = edgevilleBankArea;
- furnaceArea = edgevilleFurnaceArea;
- boothID = edgevilleBoothID;
- furnaceID = edgevilleFurnaceID;
- bankTile = edgevilleBankTile;
- furnaceTile = edgevilleFurnaceTile;
- location = "Edgeville";
- break;
- case 3: //Falador
- bankArea = fallyBankArea;
- furnaceArea = fallyFurnaceArea;
- boothID = fallyBoothID;
- furnaceID = fallyFurnaceID;
- bankTile = fallyBankTile;
- furnaceTile = fallyFurnaceTile;
- location = "Falador";
- break;
- case 4: //Ardougne
- bankArea = ardougneBankArea;
- furnaceArea = ardougneFurnaceArea;
- boothID = ardougneBoothID;
- furnaceID = ardougneFurnaceID;
- bankTile = ardougneBankTile;
- furnaceTile = ardougneFurnaceTile;
- location = "Ardougne";
- break;
- case -1:
- log(Color.RED, "Error: Location not recognized!");
- log(Color.RED, "Please move closer to a bank or furnace in a supported area and try again.");
- stopScript();
- break;
- }
- }
- /**
- * Refreshes the values of 'atBank' and 'atFurnace'
- */
- private void refreshBools(){
- if(bankArea.contains(getMyPlayer().getLocation())){
- atBank = true;
- }else{
- atBank = false;
- }
- if(furnaceArea.contains(getMyPlayer().getLocation())){
- atFurnace = true;
- }else{
- atFurnace = false;
- }
- try {
- bgPaint = ImageIO.read(url);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Sets up the paths from the player to the given points
- */
- private void createPaths(){
- pathToBank = walking.getPath(bankTile);
- pathToFurnace = walking.getPath(furnaceTile);
- }
- /**
- * Deposits all items in the bank except for the cannon ball mold
- */
- private void depositBalls(){
- RSObject bankObj = objects.getNearest(boothID);
- if(bank.isOpen()){
- bank.depositAllExcept(moldID);
- }else{
- if(bankObj.isOnScreen()){
- bank.open();
- }else{
- camera.turnTo(bankObj);
- }
- }
- sleep(500);
- }
- /**
- * Walks to the bank
- */
- private void walkToBank(){
- isSmelting = false;
- pathToBank.traverse();
- sleep(1200, 1400);
- }
- /**
- * Walks to the furnace
- */
- private void walkToFurnace(){
- antiban();
- pathToFurnace.traverse();
- sleep(50, 150);
- }
- /**
- * Withdraws 27 steel bars from the bank
- */
- private void withdrawSteel(){
- RSObject bankObj = objects.getNearest(boothID);
- if(bank.isOpen()){
- bank.withdraw(steelID, 28);
- }else{
- if(bankObj.isOnScreen()){
- bank.open();
- }else{
- camera.turnTo(bankObj);
- }
- }
- }
- public void smeltBalls(){
- if(isSmelting){
- antiban();
- sleep(500, 800);
- }else{
- RSItem steelBar = inventory.getItem(steelID);
- RSObject furnace = objects.getNearest(furnaceID);
- int animation = getMyPlayer().getAnimation();
- if(!inventory.contains(steelID)){
- isSmelting = false;
- return;
- }
- if(animation == -1){
- if(steelBar == null){
- isSmelting = false;
- log(Color.RED, "Error: Tried to smelt cannonballs when no steel exists in inventory!");
- return;
- }//end if steelBar == null)
- if(furnace == null){
- isSmelting = false;
- log(Color.RED, "Error: Could not find the furnace!");
- return;
- }//end if(furnace == null)
- if(smeltInterface == null){
- //sleep(500);
- steelBar.interact("Use");
- sleep(500);
- furnace.doClick();
- sleep(1000);
- smeltInterface = interfaces.get(interfaceID);
- }else{
- if(smeltInterface.isValid()){
- RSComponent[] components = smeltInterface.getComponents();
- for(RSComponent c : components){
- String tooltip = c.getTooltip();
- if(tooltip == null){
- }else{
- if(tooltip.equals("Make All")){
- c.doClick();
- smeltInterface = null;
- isSmelting = true;
- return;
- }//end if(tooltip.equals("Make All")
- }
- }//end for(RSComponent c : components)
- }else{
- smeltInterface = null;
- //log(Color.RED, "Error: Invalid Interface!");
- }//end if(smeltInterface.isValid())
- }//end if(smeltInterface == null)
- }else{
- isSmelting = true;
- sleep(1500, 2500);
- }//end if(animation == -1)
- }//end if(isSmelting)
- }
- public void withdrawMold(){
- RSObject bankObj = objects.getNearest(boothID);
- if(bankObj != null){
- if(bank.isOpen()){
- if(bank.getItem(moldID) != null){
- bank.withdraw(moldID, 1);
- }else{
- log(Color.RED, "Error: No molds found in the inventory or bank! Please obtain a mold and try again");
- stopScript();
- }
- }else{
- if(bankObj.isOnScreen()){
- bank.open();
- }else{
- camera.turnTo(bankObj);
- }
- }
- }else{
- log(Color.RED, "Error: Bank does not exist.");
- }
- sleep(500, 100);
- }
- public void antiban(){
- int rand = random(0, 50);
- switch(rand){
- case 1:
- totalAntibans++;
- mouse.moveRandomly(1500);
- break;
- case 6:
- totalAntibans++;
- camera.turnTo(getMyPlayer());
- sleep(50, 200);
- break;
- case 9:
- totalAntibans++;
- camera.moveRandomly(random(50, 200));
- break;
- case 15:
- totalAntibans++;
- mouse.moveOffScreen();
- break;
- case 16:
- totalAntibans++;
- game.openTab(Tab.STATS);
- skills.doHover(Skills.SMITHING);
- sleep(50, 200);
- mouse.move(random(100, 400), random(0, 500));
- break;
- case 19:
- totalAntibans++;
- mouse.setSpeed(8);
- sleep(10);
- mouse.moveRandomly(65);
- sleep(20, 40);
- mouse.hop(200, 178);
- sleep(5000);
- break;
- case 24:
- totalAntibans++;
- game.openTab(Tab.STATS);
- sleep(50, 100);
- skills.doHover(Skills.SMITHING);
- sleep(100, 1000);
- mouse.move(random(25, 150), 385);
- break;
- case 35:
- totalAntibans++;
- camera.setPitch(85);
- sleep(1, 20);
- camera.setPitch(60);
- break;
- case 41:
- totalAntibans++;
- mouse.moveRandomly(random(10, 500));
- break;
- case 48:
- totalAntibans++;
- camera.setPitch(100);
- break;
- }
- }
- /*
- * @Author Spring
- *
- * Thank you Spring for this method :P
- */
- private int loadPrice(final int itemID) {
- int price = 0;
- boolean nextLine = false;
- boolean kill = false;
- try {
- final URL url = new URL(
- "http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj="
- + itemID);
- final BufferedReader reader = new BufferedReader(
- new InputStreamReader(url.openStream()));
- String line;
- while ((line = reader.readLine()) != null && !kill) {
- if (nextLine) {
- line = line.replace("<td>", "");
- line = line.replace("</td>", "");
- line = line.replace(".", "");
- line = line.replace(",", "");
- if (line.contains("k")) {
- line = line.replace(".", "");
- line = line.replace("k", "");
- price = Integer.parseInt(line) * 100;
- } else if (line.contains("m")) {
- line = line.replace(".", "");
- line = line.replace("m", "");
- price = Integer.parseInt(line) * 100000;
- } else {
- price = Integer.parseInt(line);
- }
- kill = true;
- }
- if (line.contains("Current guide price:"))
- nextLine = true;
- }
- } catch (final Exception ignored) {
- }
- return price;
- }
- @Override
- public void messageReceived(MessageEvent m) {
- String message = m.getMessage();
- if(message.contains("You remove the cannonballs")){
- ballsMade += 4;
- }
- }
- @Override
- public void onRepaint(Graphics arg0) {
- Graphics2D g = (Graphics2D) arg0;
- long runTime = System.currentTimeMillis() - startTime;
- long expGain = skills.getCurrentExp(Skills.SMITHING) - startingExp;
- long millis = System.currentTimeMillis() - timeStart;
- levelsGained = skills.getCurrentLevel(Skills.SMITHING) - startLevel;
- profit = ((ballPrice * 4) - steelPrice) * (ballsMade / 4);
- long temp = millis;
- long hours = temp / 3600000;
- temp = temp - (hours * 3600000);
- long minutes = temp / 60000;
- temp = temp - (minutes * 60000);
- long seconds = temp / 1000;
- int ballPH = (int) ((ballsMade) * 3600000.0 / runTime);
- int expPH = (int) ((expGain) * 3600000.0 / runTime);
- int profitPH = (int) ((profit) * 3600000.0 / runTime);
- g.drawImage(bgPaint, 0, 0, null);
- g.setFont(font1);
- g.setColor(Color.WHITE);
- int x = 200;
- int y = 400;
- g.drawString("Version: " + info.version(), 5, 15);
- g.drawString("Authors: " + info.authors()[0] + " and " + info.authors()[1], 5, 30);
- g.drawString("Location: " + location, x, y);
- y += 15;
- g.drawString("Run Time: " + hours + ":" + minutes + ":" + seconds, x, y);
- y += 15;
- g.drawString("Cannonballs Made: " + ballsMade, x, y);
- y += 15;
- g.drawString("Cannonballs/Hour: " + ballPH, x, y);
- y = 370;
- x += 150;
- g.drawString("Profit: " + profit, x, y);
- y += 15;
- g.drawString("Profit/Hour: " + profitPH, x, y);
- y += 15;
- g.drawString("XP Gained: " + expGain, x, y);
- y += 15;
- g.drawString("XP/Hour: " + expPH, x, y);
- y += 15;
- g.drawString("Levels Gained: " + levelsGained, x, y);
- y += 15;
- g.drawString("Current Level: " + skills.getCurrentLevel(Skills.SMITHING), x, y);
- y += 15;
- g.drawString("Total Antibans: " + totalAntibans, x, y);
- g.setFont(font1);
- g.drawString("Status: " + status, 10, 435);
- ProgressBar(10,445,183,20,2,skills.getPercentToNextLevel(Skills.SMITHING),Color.black,Color.RED,Color.GREEN,Color.BLACK,new Font("Arial",Font.PLAIN,12),arg0);
- }
- private void ProgressBar(int x, int y, int width, int height, int borderThickness,int progressPercent, Color border, Color background, Color fill,Color font,Font f, Graphics g){
- g.setColor(border);
- g.fillRect(x, y, width, height);
- int nx = x+borderThickness; int ny = y+borderThickness;
- int nWidth = width-(borderThickness*2); int nHeight = height-(borderThickness*2);
- g.setColor(background);
- g.fillRect(nx, ny, nWidth, nHeight);
- int percentFill = (nWidth*progressPercent)/100;
- g.setColor(fill);
- g.fillRect(nx, ny, percentFill, nHeight);
- g.setColor(font);
- g.setFont(f);
- g.drawString(progressPercent+"% to lvl " + (skills.getCurrentLevel(Skills.SMITHING) + 1),nx+ (nWidth/2)-40, ny+(nHeight/2)+(f.getSize()/2)-1);
- }
- }