Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.77 KB | None | 0 0
  1. package scripts.genchant;
  2.  
  3. import java.awt.Color;
  4. import java.awt.EventQueue;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import java.awt.Image;
  9. import java.io.IOException;
  10. import java.net.URL;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. import org.tribot.api.Timing;
  15. import org.tribot.api.input.Mouse;
  16. import org.tribot.api.util.abc.ABCUtil;
  17. import org.tribot.api2007.Banking;
  18. import org.tribot.api2007.GameTab;
  19. import org.tribot.api2007.Interfaces;
  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.Login.STATE;
  25. import org.tribot.api2007.Skills.SKILLS;
  26. import org.tribot.api2007.types.RSInterface;
  27. import org.tribot.api2007.types.RSItem;
  28. import org.tribot.script.Script;
  29. import org.tribot.script.ScriptManifest;
  30. import org.tribot.script.interfaces.Painting;
  31.  
  32.  
  33. @ScriptManifest(authors = { "Genka" }, category = "Magic", name = "GEnchant")
  34. public class Main extends Script implements Painting{
  35.         ABCUtil abc = new ABCUtil();
  36.         boolean alive = true;
  37.         private int startXp = Skills.getXP(SKILLS.MAGIC);
  38.         static String spell = "";
  39.         static int itemToEnchant = 1639;
  40.         int cosmicID = 564;
  41.         private GUI frame;
  42.  
  43.         @Override
  44.         public void run() {
  45.                 initGUI();
  46.                 while(frame == null || frame.isVisible()) {
  47.                     sleep(100);
  48.                 }
  49.                 println("script started");
  50.                 while(alive){                              
  51.                     if(Banking.isBankScreenOpen()) {
  52.                         bank();
  53.                     } else {
  54.                         enchant();
  55.                         doTimedActions();
  56.                     }
  57.                     sleep(10, 50);
  58.                 }
  59.                
  60.         }
  61.        
  62.         private void initGUI(){
  63.             EventQueue.invokeLater(new Runnable() {
  64.                 public void run() {
  65.                     try {
  66.                         frame = new GUI();
  67.                         frame.setVisible(true);
  68.                     } catch (Exception e) {
  69.                         e.printStackTrace();
  70.                     }
  71.                 }
  72.             });
  73.         }      
  74.        
  75.         private void enchant() {
  76.             if(Inventory.find(itemToEnchant).length > 0 && Inventory.find(cosmicID).length > 0){
  77.                 if(!Magic.isSpellSelected()){
  78.                         Magic.selectSpell(spell);
  79.                 } else {
  80.                     if(!Magic.getSelectedSpellName().equals(spell)){
  81.                             println(Magic.getSelectedSpellName());
  82.                             Mouse.click(1);
  83.                     }
  84.                     RSItem[] toEnchant = Inventory.find(itemToEnchant);
  85.                     if(toEnchant.length > 0){
  86.                         if(GameTab.getOpen().equals(GameTab.TABS.INVENTORY)) {
  87.                             if(toEnchant[0].click("Cast")) {
  88.                                 long t = System.currentTimeMillis();
  89.                                 while(Timing.timeFromMark(t) < 2000 && !GameTab.getOpen().equals(GameTab.TABS.MAGIC)) {
  90.                                     sleep(10, 200);
  91.                                 }
  92.                                
  93.                             }
  94.                         } else {
  95.                             Mouse.click(1);
  96.                         }
  97.                     }
  98.                 }
  99.             }  else if(!Banking.isBankScreenOpen()){
  100.                 if(Magic.isSpellSelected()){
  101.                     Mouse.click(1);
  102.                 } else {
  103.                     Banking.openBank();
  104.                 }
  105.             }
  106.         }
  107.        
  108.         private void bank() {
  109.             if(Inventory.getAll().length > 1 && Inventory.find(itemToEnchant).length == 0){
  110.                     Banking.depositAllExcept(cosmicID);
  111.                     long t = System.currentTimeMillis();
  112.                     while(Inventory.getAll().length > 1 && Timing.timeFromMark(t) < 2000){
  113.                             sleep(10,300);
  114.                     }
  115.             } else if(Inventory.find(itemToEnchant).length > 0) {
  116.                 Banking.close();
  117.             } else {
  118.                     if(Magic.isSpellSelected()){
  119.                             Mouse.click(1);
  120.                     }
  121.                     if(Inventory.find(cosmicID).length == 0){
  122.                             RSItem[] cosmics = Banking.find(cosmicID);
  123.                             RSItem[] enchant = Banking.find(itemToEnchant);
  124.                             if((cosmics.length == 0 || enchant.length == 0) && isBankItemsLoaded()){
  125.                                     println("Out of supplies");
  126.                                     long t = System.currentTimeMillis();
  127.                                     while(Login.getLoginState() == STATE.INGAME && Timing.timeFromMark(t) < 20000){
  128.                                             sleep(100,500);
  129.                                             Banking.close();
  130.                                             Login.logout();
  131.                                     }
  132.                                     if(Login.getLoginState() == STATE.LOGINSCREEN){
  133.                                             alive = false;
  134.                                     }
  135.                             }
  136.                             Banking.withdraw(1000, cosmicID);
  137.                     }
  138.                     Banking.withdraw(0, itemToEnchant);
  139.                     long t = System.currentTimeMillis();
  140.                     while(Inventory.find(itemToEnchant).length == 0 && Timing.timeFromMark(t) < 3000){
  141.                             sleep(10,300);
  142.                     }
  143.             }
  144.         }
  145.        
  146.         //Thanks Erickho123 for the snippet
  147.         private boolean isBankItemsLoaded() {
  148.             return getCurrentBankSpace() == Banking.getAll().length;
  149.         }
  150.         //Thanks Erickho123 for the snippet
  151.         private int getCurrentBankSpace() {  
  152.              RSInterface amount = Interfaces.get(12,5);
  153.              if(amount != null) {  
  154.                  String text = amount.getText();  
  155.                  if(text != null) {  
  156.                      try {        
  157.                          int parse = Integer.parseInt(text);
  158.                          if(parse > 0)
  159.                              return parse;  
  160.                          } catch(NumberFormatException e) {  
  161.                              return -1;        
  162.                              }        
  163.                      }
  164.                  }      
  165.              return -1;  
  166.         }
  167.        
  168.         private void doTimedActions() {
  169.             if (abc.shouldCheckTabs()) {
  170.                 abc.checkTabs();
  171.             }
  172.             if (abc.shouldCheckXP()) { 
  173.                 abc.checkXP();
  174.             }
  175.             if (abc.shouldExamineEntity()) {
  176.                 abc.examineEntity();
  177.             }
  178.             if (abc.shouldMoveMouse()) {
  179.                 abc.moveMouse();
  180.             }
  181.             if (abc.shouldPickupMouse()) {
  182.                 abc.pickupMouse();
  183.             }
  184.             if (abc.shouldRightClick()) {
  185.                 abc.rightClick();
  186.             }
  187.             if (abc.shouldRotateCamera()) {
  188.                 abc.rotateCamera();
  189.             }
  190.             if (abc.shouldLeaveGame()) {
  191.                 abc.leaveGame();
  192.             }
  193.         }
  194.        
  195.     //START: Code generated using Enfilade's Easel
  196.     private Image getImage(String url) {
  197.         try {
  198.             return ImageIO.read(new URL(url));
  199.         } catch(IOException e) {
  200.             return null;
  201.         }
  202.     }
  203.  
  204.     private final Color color1 = new Color(255, 255, 255);
  205.     private final Font font1 = new Font("Arial", 0, 10);
  206.     private final Image img1 = getImage("http://i.imgur.com/zwBUJ0i.png");
  207.  
  208.     public void onPaint(Graphics g1) {
  209.         double multiplier = getRunningTime() / 3600000.0D;
  210.             int xpPerHour = (int) ((Skills.getXP(SKILLS.MAGIC) - startXp) / multiplier);              
  211.                 Graphics2D g = (Graphics2D)g1;
  212.         g.drawImage(img1, 277, 345, null);
  213.         g.setFont(font1);
  214.         g.setColor(color1);
  215.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  216.         g.drawString("Magic level: " + Skills.getActualLevel(SKILLS.MAGIC), 366, 421);
  217.         g.drawString("XP: "  + (Skills.getXP(SKILLS.MAGIC) - startXp) + " (" + xpPerHour + ")", 366, 433);
  218.     }
  219.     //END: Code generated using Enfilade's Easel
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement