Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.20 KB | None | 0 0
  1. package scripts.gfirecrafter;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Image;
  8. import java.io.IOException;
  9. import java.net.URL;
  10.  
  11. import javax.imageio.ImageIO;
  12.  
  13. import org.tribot.api.General;
  14. import org.tribot.api.Timing;
  15. import org.tribot.api.util.abc.ABCUtil;
  16. import org.tribot.api2007.Banking;
  17. import org.tribot.api2007.Equipment;
  18. import org.tribot.api2007.Game;
  19. import org.tribot.api2007.Interfaces;
  20. import org.tribot.api2007.Login;
  21. import org.tribot.api2007.Objects;
  22. import org.tribot.api2007.Options;
  23. import org.tribot.api2007.Player;
  24. import org.tribot.api2007.Skills;
  25. import org.tribot.api2007.Walking;
  26. import org.tribot.api2007.Equipment.SLOTS;
  27. import org.tribot.api2007.Login.STATE;
  28. import org.tribot.api2007.Skills.SKILLS;
  29. import org.tribot.api2007.Inventory;
  30. import org.tribot.api2007.types.RSInterface;
  31. import org.tribot.api2007.types.RSItem;
  32. import org.tribot.api2007.types.RSObject;
  33. import org.tribot.api2007.types.RSTile;
  34. import org.tribot.script.Script;
  35. import org.tribot.script.ScriptManifest;
  36. import org.tribot.script.interfaces.Painting;
  37.  
  38. @ScriptManifest(authors = { "Genka" }, category = "Runecrafting", name = "GFireCrafter")
  39. public class Main extends Script implements Painting{
  40.         private ABCUtil abc = new ABCUtil();
  41.         private boolean alive = true;  
  42.         private int[] rodIds = new int[] {2552, 2554, 2556, 2558, 2560, 2562, 2564};
  43.         private RSTile chestPosition = new RSTile(2444, 3083);
  44.         private RSTile duelArenaPosition = new RSTile(3316, 3236);
  45.         private RSTile altarPosition = new RSTile(2584, 4837);
  46.         private RSTile ruinsPosition = new RSTile(3312, 3254);
  47.         private int startXp = Skills.getXP(SKILLS.RUNECRAFTING);
  48.         private int nextRun = abc.generateRunActivation();
  49.        
  50.         @Override
  51.         public void run() {
  52.             Walking.setWalkingTimeout(500);
  53.             while(alive){
  54.                 if(needToBank()){
  55.                    bank();
  56.                 } else {
  57.                     traverse();
  58.                     setRunOn();
  59.                     doTimedActions();
  60.                 }
  61.                 sleep(10,50);
  62.             }  
  63.         }
  64.        
  65.         private void setRunOn(){
  66.             if(Game.getRunEnergy() >= nextRun){
  67.                 Options.setRunOn(true);
  68.                 nextRun = abc.generateRunActivation();
  69.             }
  70.         }
  71.        
  72.         private void bank(){
  73.             if(!Banking.isBankScreenOpen()){
  74.                     checkROD();
  75.             } else if(Banking.isBankScreenOpen()){
  76.                 if(Inventory.getAll().length > 0){
  77.                         Banking.depositAll();
  78.                 }
  79.                 if(!Equipment.isEquipped(rodIds)){
  80.                     Banking.withdraw(1, rodIds);
  81.                     long t = System.currentTimeMillis();
  82.                     while(Inventory.find(rodIds).length == 0 && Timing.timeFromMark(t) < 2000){
  83.                             sleep(10, 250);
  84.                     }
  85.                     Banking.close();
  86.                 } else {
  87.                    withdrawEss();
  88.                 }
  89.             }
  90.         }
  91.        
  92.         private void withdrawEss() {
  93.              RSItem[] ess = Banking.find("Rune essence", "Pure essence");
  94.              if(ess.length == 0 && isBankItemsLoaded()){
  95.                      killScript();
  96.              } else {
  97.                  Banking.withdraw(0, "Rune essence", "Pure essence");
  98.                  long t = System.currentTimeMillis();
  99.                  while(Inventory.find("Rune essence", "Pure essence").length == 0 && Timing.timeFromMark(t) < 1000){
  100.                          sleep(10,250);
  101.                  }
  102.              }
  103.              
  104.         }
  105.        
  106.         private void killScript() {
  107.             println("Out of essence");
  108.             long t = System.currentTimeMillis();
  109.             while(Login.getLoginState() == STATE.INGAME && Timing.timeFromMark(t) < 20000){
  110.                     sleep(100,500);
  111.                     Banking.close();
  112.                     Login.logout();
  113.             }
  114.             if(Login.getLoginState() == STATE.LOGINSCREEN){
  115.                     alive = false;
  116.             }
  117.         }
  118.        
  119.         //Thanks Erickho123 for the snippet
  120.         private boolean isBankItemsLoaded() {
  121.             return getCurrentBankSpace() == Banking.getAll().length;
  122.         }
  123.         //Thanks Erickho123 for the snippet
  124.         private int getCurrentBankSpace() {  
  125.              RSInterface amount = Interfaces.get(12,5);
  126.              if(amount != null) {  
  127.                  String text = amount.getText();  
  128.                  if(text != null) {  
  129.                      try {        
  130.                          int parse = Integer.parseInt(text);
  131.                          if(parse > 0)
  132.                              return parse;  
  133.                          } catch(NumberFormatException e) {  
  134.                              return -1;        
  135.                              }        
  136.                      }
  137.                  }      
  138.              return -1;  
  139.         }
  140.        
  141.         private void checkROD() {
  142.             if(isLastCharge()){
  143.                     Equipment.remove(SLOTS.RING);
  144.             } else if (Inventory.find(rodIds).length == 0){
  145.                     RSObject[] bankChest = Objects.getAt(chestPosition);
  146.                     if(bankChest.length > 0){
  147.                             if(bankChest[0].isClickable()){
  148.                                     Banking.openBank();
  149.                             } else if(!Player.isMoving() && Game.getDestination() == null){
  150.                                     Walking.blindWalkTo(new RSTile(chestPosition.getX() + General.random(-1, 1), chestPosition.getY() + General.random(-1, 1)));
  151.                                     sleep(50,100);
  152.                             }
  153.                     }
  154.             } else if(Inventory.find(rodIds).length > 0 && !Equipment.isEquipped(rodIds)){
  155.                     RSItem[] rod = Inventory.find(rodIds);
  156.                     if(rod.length > 0){
  157.                             rod[0].click("Wear");
  158.                             sleep(50, 100);
  159.                     }
  160.             }
  161.         }
  162.        
  163.         private void traverse(){
  164.                 if(Inventory.find("Rune essence", "Pure essence").length > 0){
  165.                         if(getLocation() == "Castle Wars" || getLocation() == "Lost"){
  166.                                 if(Banking.isBankScreenOpen()){
  167.                                         Banking.close();
  168.                                 }
  169.                                 rodTele("Duel Arena");
  170.                         } else if (getLocation() == "Duel Arena"){
  171.                              moveToRuins();
  172.                         } else if (getLocation() == "Fire Altar"){
  173.                              craftRunes();
  174.                         }
  175.                 } else if(Inventory.find("Rune essence", "Pure essence").length == 0 && getLocation() != "Castle Wars"){
  176.                         rodTele("Castle Wars");
  177.                 }
  178.         }
  179.        
  180.         private void moveToRuins() {
  181.                if(Player.getPosition().distanceTo(ruinsPosition) > 3 && !Player.isMoving()){
  182.                    sleep(100);
  183.                    if(getLocation() == "Duel Arena"){
  184.                        if(Player.getPosition().distanceTo(ruinsPosition) > 2 && Game.getDestination() == null){
  185.                                Walking.blindWalkTo(ruinsPosition);
  186.                                sleep(50,260);
  187.                        }
  188.                    }
  189.                } else {
  190.                    RSObject[] ruins = Objects.getAt(ruinsPosition);
  191.                    if(ruins.length > 0){
  192.                            if(ruins[0].isClickable()){
  193.                                    if(ruins[0].click("Enter")){
  194.                                        long t = System.currentTimeMillis();
  195.                                        while(Player.getPosition().distanceTo(altarPosition) > 50 && Timing.timeFromMark(t) < 5000) {
  196.                                            sleep(10, 500);
  197.                                        }
  198.                                    }
  199.                            }
  200.                    }
  201.                }
  202.         }
  203.        
  204.         private void craftRunes() {
  205.             RSTile dest = Game.getDestination();
  206.              if(Player.getPosition().distanceTo(altarPosition) > 2 && (!Player.isMoving() || (dest != null && dest.distanceTo(altarPosition) > 2))){
  207.                  Walking.blindWalkTo(altarPosition);
  208.              } else {
  209.                  RSObject[] altar = Objects.getAt(altarPosition);
  210.                  if(Inventory.find("Rune essence", "Pure essence").length > 0 && altar.length > 0){
  211.                          if(altar[0].click("Craft")) {
  212.                              sleep(600);
  213.                              long t = System.currentTimeMillis();
  214.                              while(Player.getAnimation() != -1 && Timing.timeFromMark(t) < 2000) {
  215.                               sleep(10, 500);
  216.                              }
  217.                          }
  218.                  }
  219.              }
  220.         }
  221.        
  222.         private void rodTele(String location){
  223.                 RSItem[] rod = Equipment.find(SLOTS.RING);
  224.                 if(rod.length > 0 && Game.getGameState() == 30 && Player.getAnimation() != 714){
  225.                         if(rod[0].click(location)) {
  226.                             long t = System.currentTimeMillis();
  227.                             while(getLocation() != location && Timing.timeFromMark(t) < 5000){
  228.                                     sleep(10,150);
  229.                             }
  230.                             while(Game.getGameState() == 25 && Timing.timeFromMark(t) < 20000){
  231.                                     sleep(10,50);
  232.                             }
  233.                         }
  234.                 }
  235.         }
  236.        
  237.         private boolean needToBank(){
  238.                 return Inventory.find("Rune essence", "Pure essence").length == 0 && getLocation().equals("Castle Wars");
  239.         }
  240.        
  241.        
  242.         private boolean isLastCharge(){
  243.                 RSItem[] ring = Equipment.find(SLOTS.RING);
  244.                 if(ring.length > 0){
  245.                        return ring[0].getID() == 2566;
  246.                 }
  247.                 return false;
  248.         }
  249.        
  250.         private String getLocation(){
  251.                 if(Player.getPosition().distanceTo(chestPosition) < 20){
  252.                         return "Castle Wars";
  253.                 } else if(Player.getPosition().distanceTo(altarPosition) < 20){
  254.                         return "Fire Altar";
  255.                 } else if(Player.getPosition().distanceTo(duelArenaPosition) < 40){
  256.                         return "Duel Arena";
  257.                 }              
  258.                 return "Lost";
  259.         }
  260.        
  261.         private void doTimedActions() {
  262.             if (abc.shouldCheckTabs()) {
  263.                 abc.checkTabs();
  264.             }
  265.             if (abc.shouldCheckXP()) { 
  266.                 abc.checkXP();
  267.             }
  268.             if (abc.shouldExamineEntity()) {
  269.                 abc.examineEntity();
  270.             }
  271.             if (abc.shouldMoveMouse()) {
  272.                 abc.moveMouse();
  273.             }
  274.             if (abc.shouldPickupMouse()) {
  275.                 abc.pickupMouse();
  276.             }
  277.             if (abc.shouldRightClick()) {
  278.                 abc.rightClick();
  279.             }
  280.             if (abc.shouldRotateCamera()) {
  281.                 abc.rotateCamera();
  282.             }
  283.             if (abc.shouldLeaveGame()) {
  284.                 abc.leaveGame();
  285.             }
  286.         }
  287.        
  288.     //START: Code generated using Enfilade's Easel
  289.     private Image getImage(String url) {
  290.         try {
  291.             return ImageIO.read(new URL(url));
  292.         } catch(IOException e) {
  293.             return null;
  294.         }
  295.     }
  296.  
  297.     private final Color color1 = new Color(255, 255, 255);
  298.     private final Font font1 = new Font("Arial", 0, 10);
  299.     private final Image img1 = getImage("http://i.imgur.com/NVV4Xv1.png");
  300.  
  301.     public void onPaint(Graphics g1) {
  302.         double multiplier = getRunningTime() / 3600000.0D;
  303.             int xpPerHour = (int) ((Skills.getXP(SKILLS.RUNECRAFTING) - startXp) / multiplier);        
  304.                 Graphics2D g = (Graphics2D)g1;
  305.         g.drawImage(img1, 277, 345, null);
  306.         g.setFont(font1);
  307.         g.setColor(color1);
  308.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  309.         g.drawString("RC level: " + Skills.getActualLevel(SKILLS.RUNECRAFTING), 366, 421);
  310.         g.drawString("XP: "  + (Skills.getXP(SKILLS.RUNECRAFTING) - startXp) + " (" + xpPerHour + ")", 366, 433);
  311.     }
  312.     //END: Code generated using Enfilade's Easel
  313.        
  314.  
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement