Advertisement
Guest User

main.java

a guest
Sep 10th, 2015
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.65 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.ABCUtil;
  16. import org.tribot.api2007.Banking;
  17. import org.tribot.api2007.Equipment;
  18. import org.tribot.api2007.Game;
  19. import org.tribot.api2007.Login;
  20. import org.tribot.api2007.Objects;
  21. import org.tribot.api2007.Options;
  22. import org.tribot.api2007.Player;
  23. import org.tribot.api2007.Skills;
  24. import org.tribot.api2007.Walking;
  25. import org.tribot.api2007.Equipment.SLOTS;
  26. import org.tribot.api2007.Login.STATE;
  27. import org.tribot.api2007.Skills.SKILLS;
  28. import org.tribot.api2007.Inventory;
  29. import org.tribot.api2007.types.RSItem;
  30. import org.tribot.api2007.types.RSItemDefinition;
  31. import org.tribot.api2007.types.RSObject;
  32. import org.tribot.api2007.types.RSTile;
  33. import org.tribot.script.Script;
  34. import org.tribot.script.ScriptManifest;
  35. import org.tribot.script.interfaces.Painting;
  36.  
  37. @ScriptManifest(authors = { "Genka" }, category = "Runecrafting", name = "GFireCrafter")
  38. public class main extends Script implements Painting{
  39.     ABCUtil abc = new ABCUtil();
  40.     private boolean alive = true;  
  41.     private int[] rodIds = new int[] {2552, 2554, 2556, 2558, 2560, 2562, 2564};
  42.     private int essId = 7936;
  43.     long lastAction = System.currentTimeMillis();
  44.     private RSTile chestPosition = new RSTile(2444, 3083);
  45.     private RSTile duelArenaPosition = new RSTile(3316, 3236);
  46.     private RSTile altarPosition = new RSTile(2584, 4837);
  47.     private RSTile ruinsPosition = new RSTile(3312, 3254);
  48.     private int startXp = Skills.getXP(SKILLS.RUNECRAFTING);
  49.    
  50.     @Override
  51.     public void run() {
  52.         General.useAntiBanCompliance(true);
  53.         Walking.setWalkingTimeout(500);
  54.         while(alive){
  55.             if(needToBank()){
  56.                 bank();
  57.             }
  58.             travelAndCraft();
  59.             abc.performTimedActions(SKILLS.RUNECRAFTING);
  60.             setRunOn();
  61.             sleep(10,50);
  62.         }
  63.        
  64.     }
  65.    
  66.     private void setRunOn(){
  67.         if(Game.getRunEnergy() >= abc.INT_TRACKER.NEXT_RUN_AT.next()){
  68.             Options.setRunOn(true);
  69.             abc.INT_TRACKER.NEXT_RUN_AT.reset();
  70.         }
  71.     }
  72.    
  73.     private void bank(){
  74.         if(!Banking.isBankScreenOpen()){
  75.             if(isLastCharge()){
  76.                 Equipment.remove(SLOTS.RING);
  77.             } else if (Inventory.find(rodIds).length == 0){
  78.                 RSObject[] bankChest = Objects.getAt(chestPosition);
  79.                 if(bankChest.length > 0){
  80.                     if(bankChest[0].isClickable()){
  81.                         Banking.openBank();
  82.                     } else if(!Player.isMoving()){
  83.                         Walking.blindWalkTo(new RSTile(chestPosition.getX() + General.random(-1, 1), chestPosition.getY() + General.random(-1, 1)));
  84.                     }
  85.                 }
  86.             } else if(Inventory.find(rodIds).length > 0 && !Equipment.isEquipped(rodIds)){
  87.                 RSItem[] rod = Inventory.find(rodIds);
  88.                 if(rod.length > 0){
  89.                     rod[0].click("Wear");
  90.                 }
  91.             }
  92.         } else if(Banking.isBankScreenOpen()){
  93.             if(Inventory.getAll().length > 0){
  94.                 Banking.depositAll();
  95.             }
  96.             if(!Equipment.isEquipped(rodIds)){
  97.                 Banking.withdraw(1, rodIds);
  98.                 long t = System.currentTimeMillis();
  99.                 while(Inventory.find(rodIds).length == 0 && Timing.timeFromMark(t) < 2000){
  100.                     sleep(10, 250);
  101.                 }
  102.                 Banking.close();
  103.             } else {
  104.                 RSItem[] ess = Banking.find(essId);
  105.                 if(ess.length == 0 && Banking.getAll().length > 0){
  106.                     println("Out of ess");
  107.                     long t = System.currentTimeMillis();
  108.                     while(Login.getLoginState() == STATE.INGAME && Timing.timeFromMark(t) < 20000){
  109.                         sleep(100,500);
  110.                         Banking.close();
  111.                         Login.logout();
  112.                     }
  113.                     if(Login.getLoginState() == STATE.LOGINSCREEN){
  114.                         alive = false;
  115.                     }
  116.                 }
  117.                 Banking.withdraw(0, essId);
  118.                 long t = System.currentTimeMillis();
  119.                 while(Inventory.find(essId).length == 0 && Timing.timeFromMark(t) < 1000){
  120.                     sleep(10,250);
  121.                 }
  122.             }
  123.         }
  124.     }
  125.    
  126.     private void travelAndCraft(){
  127.         if(Inventory.find(essId).length > 0){
  128.             if(getLocation() == "Castle Wars" || getLocation() == "Lost"){
  129.                 if(Banking.isBankScreenOpen()){
  130.                     Banking.close();
  131.                 }
  132.                 rodTele("Duel Arena");
  133.             } else if (getLocation() == "Duel Arena"){
  134.                 if(Player.getPosition().distanceTo(ruinsPosition) > 3 && !Player.isMoving()){
  135.                     sleep(100);
  136.                     if(getLocation() == "Duel Arena"){
  137.                     if(!Walking.clickTileMM(new RSTile(ruinsPosition.getX() + General.random(-1, 1), ruinsPosition.getY() + General.random(-1, 1)), 1)){
  138.                         Walking.clickTileMM(new RSTile(3308 + General.random(-1, 1), 3247 + General.random(-1, 1)), 1);
  139.                         sleep(50,260);
  140.                     }
  141.                     }
  142.                 } else {
  143.                     RSObject[] ruins = Objects.getAt(ruinsPosition);
  144.                     if(ruins.length > 0){
  145.                         if(ruins[0].isClickable()){
  146.                             ruins[0].click("Enter");
  147.                             lastAction = System.currentTimeMillis();
  148.                             abc.waitNewOrSwitchDelay(lastAction, false);
  149.                         }
  150.                     }
  151.                 }
  152.             } else if (getLocation() == "Fire Altar"){
  153.                 if(Player.getPosition().distanceTo(altarPosition) > 2 && !Player.isMoving()){
  154.                     Walking.blindWalkTo(altarPosition);
  155.                 } else {
  156.                     RSObject[] altar = Objects.getAt(altarPosition);
  157.                     if(Inventory.find(essId).length > 0 && altar.length > 0){
  158.                         altar[0].click("Craft");
  159.                         lastAction = System.currentTimeMillis();
  160.                         abc.waitNewOrSwitchDelay(lastAction, false);
  161.                     }
  162.                 }
  163.             }
  164.         } else if(Inventory.find(essId).length == 0 && getLocation() != "Castle Wars"){
  165.             rodTele("Castle Wars");
  166.         }
  167.     }
  168.    
  169.     private void rodTele(String location){
  170.         RSItem[] rod = Equipment.find(SLOTS.RING);
  171.         if(rod.length > 0 && Game.getGameState() == 30 && Player.getAnimation() != 714){
  172.             rod[0].click(location);
  173.             long t = System.currentTimeMillis();
  174.             while(getLocation() != location && Timing.timeFromMark(t) < 5000){
  175.                 sleep(10,150);
  176.             }
  177.             while(Game.getGameState() == 25 && Timing.timeFromMark(t) < 20000){
  178.                 sleep(10,50);
  179.             }
  180.         }
  181.     }
  182.    
  183.     private boolean needToBank(){
  184.         if(Inventory.find(essId).length == 0 && getLocation() == "Castle Wars"){
  185.             return true;
  186.         }
  187.         return false;
  188.     }
  189.    
  190.    
  191.     private boolean isLastCharge(){
  192.         RSItem[] ring = Equipment.find(SLOTS.RING);
  193.         if(ring.length > 0){
  194.             RSItemDefinition def = ring[0].getDefinition();
  195.             if(def != null){
  196.             return def.getName().contains("1");
  197.             }
  198.         }
  199.         return false;
  200.     }
  201.    
  202.     private String getLocation(){
  203.         if(Player.getPosition().distanceTo(chestPosition) < 20){
  204.             return "Castle Wars";
  205.         } else if(Player.getPosition().distanceTo(altarPosition) < 20){
  206.             return "Fire Altar";
  207.         } else if(Player.getPosition().distanceTo(duelArenaPosition) < 40){
  208.             return "Duel Arena";
  209.         }      
  210.         return "Lost";
  211.     }
  212.    
  213.     //START: Code generated using Enfilade's Easel
  214.     private Image getImage(String url) {
  215.         try {
  216.             return ImageIO.read(new URL(url));
  217.         } catch(IOException e) {
  218.             return null;
  219.         }
  220.     }
  221.  
  222.     private final Color color1 = new Color(255, 255, 255);
  223.  
  224.     private final Font font1 = new Font("Arial", 0, 10);
  225.  
  226.     private final Image img1 = getImage("http://i.imgur.com/NVV4Xv1.png");
  227.  
  228.     public void onPaint(Graphics g1) {
  229.         double multiplier = getRunningTime() / 3600000.0D;
  230.         int xpPerHour = (int) ((Skills.getXP(SKILLS.RUNECRAFTING) - startXp) / multiplier);    
  231.         Graphics2D g = (Graphics2D)g1;
  232.         g.drawImage(img1, 277, 345, null);
  233.         g.setFont(font1);
  234.         g.setColor(color1);
  235.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  236.         g.drawString("RC level: " + Skills.getActualLevel(SKILLS.RUNECRAFTING), 366, 421);
  237.         g.drawString("XP: "  + (Skills.getXP(SKILLS.RUNECRAFTING) - startXp) + " (" + xpPerHour + ")", 366, 433);
  238.     }
  239.     //END: Code generated using Enfilade's Easel
  240.    
  241.  
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement