Guest User

main.java

a guest
Dec 17th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.95 KB | None | 0 0
  1. package scripts.genchant;
  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.input.Mouse;
  16. import org.tribot.api.util.ABCUtil;
  17. import org.tribot.api2007.Banking;
  18. import org.tribot.api2007.GameTab;
  19. import org.tribot.api2007.GameTab.TABS;
  20. import org.tribot.api2007.Inventory;
  21. import org.tribot.api2007.Login;
  22. import org.tribot.api2007.Magic;
  23. import org.tribot.api2007.Skills;
  24. import org.tribot.api2007.Skills.SKILLS;
  25. import org.tribot.api2007.types.RSItem;
  26. import org.tribot.script.Script;
  27. import org.tribot.script.ScriptManifest;
  28. import org.tribot.script.interfaces.Painting;
  29.  
  30. @ScriptManifest(authors = { "Genka" }, category = "Magic", name = "GEnchant")
  31. public class main extends Script implements Painting{
  32.     private ABCUtil abc = new ABCUtil();
  33.     public static boolean alive = false;
  34.     private int startXp = Skills.getXP(SKILLS.MAGIC);
  35.     public static String spell = "";
  36.     public static int itemToEnchant = 1639;
  37.     private int cosmicID = 564;
  38.    
  39.     @Override
  40.     public void run() {
  41.         GUI.handleGui();
  42.         while(!alive){
  43.             sleep(300);
  44.         }
  45.         General.useAntiBanCompliance(true);
  46.         while(alive){
  47.             if(Inventory.getCount(itemToEnchant) == 0 || Inventory.getCount(cosmicID) == 0){
  48.                 bank();
  49.             } else {
  50.                 if(Banking.isBankScreenOpen()){
  51.                     Banking.close();
  52.                 } else {
  53.                     enchant();
  54.                     abc.performTimedActions(SKILLS.MAGIC);
  55.                 }
  56.             }
  57.             sleep(10, 50);
  58.         }
  59.        
  60.     }
  61.    
  62.     private void enchant(){
  63.         if(!Magic.isSpellSelected()){
  64.             Magic.selectSpell(spell);
  65.             abc.waitNewOrSwitchDelay(System.currentTimeMillis(), true);
  66.         } else {
  67.             RSItem[] item = Inventory.find(itemToEnchant);
  68.             if(item.length > 0 && Magic.getSelectedSpellName().equals(spell) && GameTab.getOpen().equals(TABS.INVENTORY)){
  69.                 item[0].click("Cast");
  70.                 abc.waitNewOrSwitchDelay(System.currentTimeMillis(), true);
  71.             } else if (item.length > 0 && Magic.getSelectedSpellName().equals(spell) && !GameTab.getOpen().equals(TABS.INVENTORY)){
  72.                 fixStuck();        
  73.             }
  74.             if(!Magic.getSelectedSpellName().equals(spell)){
  75.                 Mouse.click(1);
  76.             }
  77.         }
  78.     }
  79.    
  80.     private void bank(){
  81.         if(!Banking.isBankScreenOpen()){
  82.             if(Magic.isSpellSelected()){
  83.                 Mouse.click(1);
  84.             } else {
  85.                 Banking.openBank();
  86.             }
  87.         } else {
  88.             if(Inventory.getCount(cosmicID) == 0){
  89.                 if(Inventory.getAll().length == 28){
  90.                     Banking.depositAll();
  91.                     abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
  92.                 } else {
  93.                     withDraw(cosmicID, 1000, "Cosmic runes");
  94.                 }
  95.             } else if (Inventory.getCount(itemToEnchant) == 0){
  96.                 if(Inventory.getAll().length > 1){
  97.                     Banking.depositAllExcept(cosmicID);
  98.                     abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
  99.                 } else {
  100.                     withDraw(itemToEnchant, 0, "items to enchant");
  101.                     abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
  102.                 }
  103.             }
  104.         }
  105.     }
  106.    
  107.     private void fixStuck(){
  108.         long t = System.currentTimeMillis();
  109.         while(!GameTab.getOpen().equals(TABS.INVENTORY) && Timing.timeFromMark(t) < 1500){
  110.             sleep(10,150);
  111.         }
  112.         if (Magic.getSelectedSpellName().equals(spell) && !GameTab.getOpen().equals(TABS.INVENTORY)){
  113.             Mouse.click(1);
  114.         }          
  115.     }
  116.    
  117.     private void withDraw(int itemID, int amount, String itemName){
  118.         if(bankIsLoaded()){
  119.             RSItem[] item = Banking.find(itemID);
  120.             if(item.length > 0){
  121.                 Banking.withdraw(amount, itemID);
  122.             } else {
  123.                 stopScript("Out of " + itemName);
  124.             }
  125.         }
  126.     }
  127.    
  128.     private void stopScript(String message){
  129.         println(message);
  130.         Banking.close();
  131.         Login.logout();
  132.         alive = false;
  133.     }
  134.    
  135.     private boolean bankIsLoaded(){
  136.         if(Banking.isBankScreenOpen()){
  137.             if(Banking.getAll().length > 0){
  138.                 return true;
  139.             }
  140.         }
  141.         return false;
  142.     }
  143.    
  144.     //START: Code generated using Enfilade's Easel
  145.     private Image getImage(String url) {
  146.         try {
  147.             return ImageIO.read(new URL(url));
  148.         } catch(IOException e) {
  149.             return null;
  150.         }
  151.     }
  152.  
  153.     private final Color color1 = new Color(255, 255, 255);
  154.  
  155.     private final Font font1 = new Font("Arial", 0, 10);
  156.  
  157.     private final Image img1 = getImage("http://i.imgur.com/zwBUJ0i.png");
  158.  
  159.     public void onPaint(Graphics g1) {
  160.         double multiplier = getRunningTime() / 3600000.0D;
  161.         int xpPerHour = (int) ((Skills.getXP(SKILLS.MAGIC) - startXp) / multiplier);       
  162.         Graphics2D g = (Graphics2D)g1;
  163.         g.drawImage(img1, 277, 345, null);
  164.         g.setFont(font1);
  165.         g.setColor(color1);
  166.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  167.         g.drawString("Magic level: " + Skills.getActualLevel(SKILLS.MAGIC), 366, 421);
  168.         g.drawString("XP: "  + (Skills.getXP(SKILLS.MAGIC) - startXp) + " (" + xpPerHour + ")", 366, 433);
  169.     }
  170.     //END: Code generated using Enfilade's Easel
  171.  
  172. }
Add Comment
Please, Sign In to add comment