Advertisement
Guest User

main.java

a guest
Dec 17th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.87 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.                     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.getCount(rodIds) > 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.getCount(rodIds) == 0 && Timing.timeFromMark(t) < 2000){
  100.                     sleep(10, 250);
  101.                 }
  102.                 Banking.close();
  103.             } else {
  104.                 withDraw(essId, 0, "pure ess");
  105.                 long t = System.currentTimeMillis();
  106.                 while(Inventory.getCount(essId) == 0 && Timing.timeFromMark(t) < 1000){
  107.                     sleep(10,250);
  108.                 }
  109.             }
  110.         }
  111.     }
  112.    
  113.     private void travelAndCraft(){
  114.         if(Inventory.getCount(essId) > 0){
  115.             if(getLocation().equals(POSITION.CWARS) || getLocation().equals(POSITION.LOST)){
  116.                 if(Banking.isBankScreenOpen()){
  117.                     Banking.close();
  118.                 }
  119.                 rodTele("Duel Arena");
  120.             } else if (getLocation().equals(POSITION.ARENA)){
  121.                 if(Player.getPosition().distanceTo(ruinsPosition) > 3 && !Player.isMoving()){
  122.                     sleep(100);
  123.                     if(getLocation().equals(POSITION.ARENA)){
  124.                         if(!Walking.clickTileMM(new RSTile(ruinsPosition.getX() + General.random(-1, 1), ruinsPosition.getY() + General.random(-1, 1)), 1)){
  125.                             Walking.clickTileMM(new RSTile(3308 + General.random(-1, 1), 3247 + General.random(-1, 1)), 1);
  126.                             sleep(50,260);
  127.                         }
  128.                     }
  129.                 } else {
  130.                     RSObject[] ruins = Objects.getAt(ruinsPosition);
  131.                     if(ruins.length > 0){
  132.                         if(ruins[0].isClickable()){
  133.                             ruins[0].click("Enter");
  134.                             lastAction = System.currentTimeMillis();
  135.                             abc.waitNewOrSwitchDelay(lastAction, false);
  136.                         }
  137.                     }
  138.                 }
  139.             } else if (getLocation().equals(POSITION.ALTAR)){
  140.                 if(Player.getPosition().distanceTo(altarPosition) > 2 && !Player.isMoving()){
  141.                     Walking.blindWalkTo(altarPosition);
  142.                 } else {
  143.                     RSObject[] altar = Objects.getAt(altarPosition);
  144.                     if(Inventory.getCount(essId) > 0 && altar.length > 0){
  145.                         altar[0].click("Craft");
  146.                         lastAction = System.currentTimeMillis();
  147.                         abc.waitNewOrSwitchDelay(lastAction, false);
  148.                     }
  149.                 }
  150.             }
  151.         } else if(Inventory.getCount(essId) == 0 && !getLocation().equals(POSITION.CWARS)){
  152.             rodTele("Castle Wars");
  153.         }
  154.     }
  155.    
  156.     private void withDraw(int itemID, int amount, String itemName){
  157.         if(bankIsLoaded()){
  158.             RSItem[] item = Banking.find(itemID);
  159.             if(item.length > 0){
  160.                 Banking.withdraw(amount, itemID);
  161.             } else {
  162.                 stopScript("Out of " + itemName);
  163.             }
  164.         }
  165.     }
  166.    
  167.     private void stopScript(String message){
  168.         println(message);
  169.         Banking.close();
  170.         Login.logout();
  171.         alive = false;
  172.     }
  173.    
  174.     private boolean bankIsLoaded(){
  175.         if(Banking.isBankScreenOpen()){
  176.             if(Banking.getAll().length > 0){
  177.                 return true;
  178.             }
  179.         }
  180.         return false;
  181.     }
  182.    
  183.     private void rodTele(String location){
  184.         RSItem[] rod = Equipment.find(SLOTS.RING);
  185.         if(rod.length > 0 && Game.getGameState() == 30 && Player.getAnimation() != 714){
  186.             rod[0].click(location);
  187.             RSTile startpos = Player.getPosition();
  188.             long t = System.currentTimeMillis();
  189.             while(Player.getPosition().equals(startpos) && Timing.timeFromMark(t) < 5000){
  190.                 sleep(10,150);
  191.             }
  192.             while(Game.getGameState() == 25 && Timing.timeFromMark(t) < 20000){
  193.                 sleep(10,50);
  194.             }
  195.         }
  196.     }
  197.    
  198.     private boolean needToBank(){
  199.         if(Inventory.getCount(essId) == 0 && getLocation().equals(POSITION.CWARS)){
  200.             return true;
  201.         }
  202.         return false;
  203.     }
  204.    
  205.    
  206.     private boolean isLastCharge(){
  207.         RSItem[] ring = Equipment.find(SLOTS.RING);
  208.         if(ring.length > 0){
  209.             RSItemDefinition def = ring[0].getDefinition();
  210.             if(def != null){
  211.             return def.getName().contains("1");
  212.             }
  213.         }
  214.         return false;
  215.     }
  216.    
  217.     private POSITION getLocation(){
  218.         if(Player.getPosition().distanceTo(chestPosition) < 20){
  219.             return POSITION.CWARS;
  220.         } else if(Player.getPosition().distanceTo(altarPosition) < 20){
  221.             return POSITION.ALTAR;
  222.         } else if(Player.getPosition().distanceTo(duelArenaPosition) < 40){
  223.             return POSITION.ARENA;
  224.         }      
  225.         return POSITION.LOST;
  226.     }
  227.    
  228.     //START: Code generated using Enfilade's Easel
  229.     private Image getImage(String url) {
  230.         try {
  231.             return ImageIO.read(new URL(url));
  232.         } catch(IOException e) {
  233.             return null;
  234.         }
  235.     }
  236.  
  237.     private final Color color1 = new Color(255, 255, 255);
  238.  
  239.     private final Font font1 = new Font("Arial", 0, 10);
  240.  
  241.     private final Image img1 = getImage("http://i.imgur.com/NVV4Xv1.png");
  242.  
  243.     public void onPaint(Graphics g1) {
  244.         double multiplier = getRunningTime() / 3600000.0D;
  245.         int xpPerHour = (int) ((Skills.getXP(SKILLS.RUNECRAFTING) - startXp) / multiplier);    
  246.         Graphics2D g = (Graphics2D)g1;
  247.         g.drawImage(img1, 277, 345, null);
  248.         g.setFont(font1);
  249.         g.setColor(color1);
  250.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  251.         g.drawString("RC level: " + Skills.getActualLevel(SKILLS.RUNECRAFTING), 366, 421);
  252.         g.drawString("XP: "  + (Skills.getXP(SKILLS.RUNECRAFTING) - startXp) + " (" + xpPerHour + ")", 366, 433);
  253.     }
  254.     //END: Code generated using Enfilade's Easel
  255.    
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement