Advertisement
Guest User

main.java

a guest
Dec 20th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.15 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.Skills.SKILLS;
  27. import org.tribot.api2007.Inventory;
  28. import org.tribot.api2007.types.RSItem;
  29. import org.tribot.api2007.types.RSItemDefinition;
  30. import org.tribot.api2007.types.RSObject;
  31. import org.tribot.api2007.types.RSTile;
  32. import org.tribot.script.Script;
  33. import org.tribot.script.ScriptManifest;
  34. import org.tribot.script.interfaces.Painting;
  35.  
  36. @ScriptManifest(authors = { "Genka" }, category = "Runecrafting", name = "GFireCrafter")
  37. public class main extends Script implements Painting{
  38.     private ABCUtil abc = new ABCUtil();
  39.     private boolean alive = true;  
  40.     private int[] rodIds = new int[] {2552, 2554, 2556, 2558, 2560, 2562, 2564};
  41.     private int essId = 7936;
  42.     private long lastAction = System.currentTimeMillis();
  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.    
  49.     @Override
  50.     public void run() {
  51.         General.useAntiBanCompliance(true);
  52.         Walking.setWalkingTimeout(500);
  53.         while(alive){
  54.             if(needToBank()){
  55.                 bank();
  56.             } else {
  57.                 travelAndCraft();
  58.             }
  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.getCount(rodIds) == 0){
  78.                 RSObject[] bankChest = Objects.getAt(chestPosition);
  79.                 if(bankChest.length > 0){
  80.                     openBank(bankChest[0]);
  81.                 }
  82.             } else if(Inventory.getCount(rodIds) > 0 && !Equipment.isEquipped(rodIds)){
  83.                 equipRod();
  84.             }
  85.         } else if(Banking.isBankScreenOpen()){
  86.             if(Inventory.getAll().length > 0){
  87.                 Banking.depositAll();
  88.             } else if(!Equipment.isEquipped(rodIds)){
  89.                 withDraw(rodIds, 1, "ring of dueling");
  90.                 Banking.close();
  91.             } else {
  92.                 withDraw(new int[] {essId}, 0, "pure ess");
  93.             }
  94.         }
  95.     }
  96.    
  97.     private boolean openBank(RSObject bankChest){
  98.         if(bankChest.isClickable()){
  99.             Banking.openBank();
  100.         } else if(!Player.isMoving()){
  101.             if(Walking.blindWalkTo(new RSTile(chestPosition.getX() + General.random(-1, 1), chestPosition.getY() + General.random(-1, 1)))){
  102.                 sleep(600,1000);
  103.             }
  104.         }
  105.         return false;
  106.     }
  107.    
  108.     private void equipRod(){
  109.         RSItem[] rod = Inventory.find(rodIds);
  110.         if(rod.length > 0){
  111.             if(rod[0].click("Wear")){
  112.                 abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
  113.             }
  114.         }
  115.     }
  116.    
  117.     private void travelAndCraft(){
  118.         if(Inventory.getCount(essId) > 0){
  119.             if(getLocation().equals(POSITION.CWARS) || getLocation().equals(POSITION.LOST)){
  120.                 if(Banking.isBankScreenOpen()){
  121.                     Banking.close();
  122.                 } else {
  123.                     rodTele("Duel Arena");
  124.                 }
  125.             } else if (getLocation().equals(POSITION.ARENA)){
  126.                 if(toRuins()){
  127.                     enterRuins();
  128.                 }
  129.             } else if (getLocation().equals(POSITION.ALTAR)){
  130.                 if(Player.getPosition().distanceTo(altarPosition) > 2 && !Player.isMoving()){
  131.                     Walking.blindWalkTo(altarPosition);
  132.                 } else {
  133.                     craft();
  134.                 }
  135.             }
  136.         } else if(Inventory.getCount(essId) == 0 && !getLocation().equals(POSITION.CWARS)){
  137.             rodTele("Castle Wars");
  138.         }
  139.     }
  140.    
  141.     private void craft(){
  142.         RSObject[] altar = Objects.getAt(altarPosition);
  143.         if(Inventory.getCount(essId) > 0 && altar.length > 0){
  144.             altar[0].click("Craft");
  145.             abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
  146.         }
  147.     }
  148.    
  149.     private boolean enterRuins(){
  150.         RSObject[] ruins = Objects.getAt(ruinsPosition);
  151.         if(ruins.length > 0){
  152.             if(ruins[0].isClickable()){
  153.                 ruins[0].click("Enter");
  154.                 abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
  155.             }
  156.         }
  157.         return false;
  158.     }
  159.    
  160.     private boolean toRuins(){
  161.         if(Player.getPosition().distanceTo(ruinsPosition) > 3 && !Player.isMoving()){
  162.             sleep(100);
  163.             if(getLocation().equals(POSITION.ARENA)){
  164.                 if(!Walking.clickTileMM(new RSTile(ruinsPosition.getX() + General.random(-1, 1), ruinsPosition.getY() + General.random(-1, 1)), 1)){
  165.                     Walking.clickTileMM(new RSTile(3308 + General.random(-1, 1), 3247 + General.random(-1, 1)), 1);
  166.                     sleep(50,260);
  167.                 }
  168.             }
  169.         } else if(Player.getPosition().distanceTo(ruinsPosition) <= 3){
  170.             return true;
  171.         }
  172.         return false;
  173.     }
  174.    
  175.     private void withDraw(int itemID[], int amount, String itemName){
  176.         if(bankIsLoaded()){
  177.             RSItem[] item = Banking.find(itemID);
  178.             if(item.length > 0){
  179.                 Banking.withdraw(amount, itemID);
  180.                 long t =System.currentTimeMillis();
  181.                 while(Inventory.getCount(itemID) == 0 && Timing.timeFromMark(t) < 2000){
  182.                     sleep(10,200);
  183.                 }
  184.             } else {
  185.                 stopScript("Out of " + itemName);
  186.             }
  187.         }
  188.     }
  189.    
  190.     private void stopScript(String message){
  191.         println(message);
  192.         Banking.close();
  193.         Login.logout();
  194.         alive = false;
  195.     }
  196.    
  197.     private boolean bankIsLoaded(){
  198.         if(Banking.isBankScreenOpen()){
  199.             if(Banking.getAll().length > 0){
  200.                 return true;
  201.             }
  202.         }
  203.         return false;
  204.     }
  205.    
  206.     private void rodTele(String location){
  207.         RSItem[] rod = Equipment.find(SLOTS.RING);
  208.         if(rod.length > 0 && Game.getGameState() == 30 && Player.getAnimation() != 714){
  209.             rod[0].click(location);
  210.             RSTile startpos = Player.getPosition();
  211.             long t = System.currentTimeMillis();
  212.             while(Player.getPosition().equals(startpos) && Timing.timeFromMark(t) < 5000){
  213.                 sleep(10,150);
  214.             }
  215.             while(Game.getGameState() == 25 && Timing.timeFromMark(t) < 20000){
  216.                 sleep(10,50);
  217.             }
  218.         }
  219.     }
  220.    
  221.     private boolean needToBank(){
  222.         if(Inventory.getCount(essId) == 0 && getLocation().equals(POSITION.CWARS)){
  223.             return true;
  224.         }
  225.         return false;
  226.     }
  227.    
  228.    
  229.     private boolean isLastCharge(){
  230.         RSItem[] ring = Equipment.find(SLOTS.RING);
  231.         if(ring.length > 0){
  232.             RSItemDefinition def = ring[0].getDefinition();
  233.             if(def != null){
  234.             return def.getName().contains("1");
  235.             }
  236.         }
  237.         return false;
  238.     }
  239.    
  240.     private POSITION getLocation(){
  241.         if(Player.getPosition().distanceTo(chestPosition) < 20){
  242.             return POSITION.CWARS;
  243.         } else if(Player.getPosition().distanceTo(altarPosition) < 20){
  244.             return POSITION.ALTAR;
  245.         } else if(Player.getPosition().distanceTo(duelArenaPosition) < 40){
  246.             return POSITION.ARENA;
  247.         }      
  248.         return POSITION.LOST;
  249.     }
  250.    
  251.     //START: Code generated using Enfilade's Easel
  252.     private Image getImage(String url) {
  253.         try {
  254.             return ImageIO.read(new URL(url));
  255.         } catch(IOException e) {
  256.             return null;
  257.         }
  258.     }
  259.  
  260.     private final Color color1 = new Color(255, 255, 255);
  261.  
  262.     private final Font font1 = new Font("Arial", 0, 10);
  263.  
  264.     private final Image img1 = getImage("http://i.imgur.com/NVV4Xv1.png");
  265.  
  266.     public void onPaint(Graphics g1) {
  267.         double multiplier = getRunningTime() / 3600000.0D;
  268.         int xpPerHour = (int) ((Skills.getXP(SKILLS.RUNECRAFTING) - startXp) / multiplier);    
  269.         Graphics2D g = (Graphics2D)g1;
  270.         g.drawImage(img1, 277, 345, null);
  271.         g.setFont(font1);
  272.         g.setColor(color1);
  273.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  274.         g.drawString("RC level: " + Skills.getActualLevel(SKILLS.RUNECRAFTING), 366, 421);
  275.         g.drawString("XP: "  + (Skills.getXP(SKILLS.RUNECRAFTING) - startXp) + " (" + xpPerHour + ")", 366, 433);
  276.     }
  277.     //END: Code generated using Enfilade's Easel
  278.    
  279.  
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement