Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.77 KB | None | 0 0
  1.  
  2. package scripts;
  3.  
  4. import java.awt.Color;
  5. import java.awt.Graphics2D;
  6. import java.text.NumberFormat;
  7. import java.util.Locale;
  8. import org.osbot.rs07.api.model.Entity;
  9. import org.osbot.rs07.api.model.Item;
  10. import org.osbot.rs07.api.ui.Option;
  11. import org.osbot.rs07.api.ui.Skill;
  12. import org.osbot.rs07.api.ui.Spells;
  13. import org.osbot.rs07.api.ui.Tab;
  14. import org.osbot.rs07.script.Script;
  15. import org.osbot.rs07.script.ScriptManifest;
  16.  
  17.  
  18. @ScriptManifest(name = "Stun Alcher", author = "MegaManAlpha", logo = "", version = 0.0, info = "")
  19. public class StunAlcher extends Script {
  20.     String targetEnemyName = "Monk of Zamorak";
  21.     long scriptStartTime = 0;
  22.     int startMagicLevel = 0;
  23.     int startMagicExp = 0;
  24.     int currentMagicExp = 0;
  25.     int soulRunesStartAmount = 0;
  26.     int soulRunesCurrentAmount = 0;
  27.     int soulRunesUsed = 0;
  28.     int natureRunesStartAmount = 0;
  29.     int natureRunesCurrentAmount = 0;
  30.     int natureRunesUsed = 0;
  31.     boolean started = false;
  32.  
  33.     @Override
  34.     public void onStart() throws InterruptedException {
  35.         antiBan.unregisterAllBehaviors();
  36.         scriptStartTime = System.currentTimeMillis();
  37.         startMagicExp = skills.getExperience(Skill.MAGIC);
  38.         startMagicLevel = skills.getStatic(Skill.MAGIC);
  39.         soulRunesStartAmount = getNumberOfSoulRunes();
  40.         natureRunesStartAmount = getNumberOfNatureRunes();
  41.  
  42.         log("MegaManAlpha's Stun-Alcher script has now started!");
  43.         log("You will be splashing: " + targetEnemyName);
  44.         started = true;
  45.     }
  46.    
  47.     @Override
  48.     public int onLoop() throws InterruptedException {
  49.         if(started) getState();
  50.         return random(100, 200);
  51.     }
  52.  
  53.     private void getState() throws InterruptedException {
  54.         if(!client.isLoggedIn()) {
  55.             log("Not logged in.");
  56.             log("You need to be logged in for this script to work.");
  57.             return;
  58.         }
  59.        
  60.         if(!tabs.getOpen().equals(Tab.MAGIC)) {
  61.             if(tabs.open(Tab.MAGIC)) {
  62.                 sleepUntilMagicTabOpens();
  63.             }
  64.             return;
  65.         }
  66.        
  67.         Entity enemy = npcs.closest(targetEnemyName);
  68.         if(enemy == null) {
  69.             log("Target enemy not found");
  70.             return;
  71.         }
  72.        
  73.         soulRunesCurrentAmount = getNumberOfSoulRunes();
  74.         natureRunesCurrentAmount = getNumberOfNatureRunes();
  75.         soulRunesUsed = soulRunesStartAmount - soulRunesCurrentAmount;
  76.         natureRunesUsed = natureRunesStartAmount - natureRunesCurrentAmount;
  77.         currentMagicExp = skills.getExperience(Skill.MAGIC);
  78.  
  79.         if(magic.castSpellOnEntity(Spells.NormalSpells.STUN, enemy) && sleepUntilStunIsCast(soulRunesCurrentAmount)) {
  80.             sleep(random(25, 100));
  81.             if(moveMouseToAlchArea()) {
  82.                 leftClick();
  83.                 if(sleepUntilInventoryTabActive() && isHighAlchOption()) {
  84.                     sleep(random(25, 100));
  85.                     leftClick();
  86.                     sleepUntilMagicTabOpens();
  87.                 }
  88.             }
  89.         }
  90.     }
  91.    
  92.     private int getNumberOfSoulRunes() throws InterruptedException {
  93.         for(Item item : inventory.getItems()) {
  94.             if(item != null && item.getDefinition() != null && item.getName() != null) {
  95.                 if(item.getName().equals("Soul rune")) {
  96.                     return item.getAmount();
  97.                 }
  98.             }
  99.         }
  100.         return 0;
  101.     }
  102.    
  103.     private int getNumberOfNatureRunes() throws InterruptedException {
  104.         for(Item item : inventory.getItems()) {
  105.             if(item != null && item.getDefinition() != null && item.getName() != null) {
  106.                 if(item.getName().equals("Nature rune")) {
  107.                     return item.getAmount();
  108.                 }
  109.             }
  110.         }
  111.         return 0;
  112.     }
  113.    
  114.     private boolean moveMouseToAlchArea() throws InterruptedException {
  115.         //high alch area rectangle
  116.         //709, 322
  117.         //719, 336
  118.         mouse.move(random(709, 719), random(322, 336));
  119.         return isHighAlchOption();
  120.     }
  121.    
  122.     private boolean isHighAlchOption() {
  123.         for(Option option : menu.getMenu()) {
  124.             if(option != null) {
  125.                 if(option.action.equals("Cast")) {
  126.                     if(option.name.contains("High Level Alchemy")) {
  127.                         return true;
  128.                     }
  129.                 }
  130.             }
  131.         }
  132.  
  133.         return false;
  134.     }
  135.    
  136.     private void leftClick() {
  137.         mouse.click(false);
  138.     }
  139.    
  140.     private void rightClick() {
  141.         mouse.click(true);
  142.     }
  143.    
  144.     private void sleepUntilMagicTabOpens() throws InterruptedException {
  145.         long startTime = System.currentTimeMillis();
  146.         long timeout = 4000;
  147.        
  148.         while(!tabs.getOpen().equals(Tab.MAGIC)) {
  149.             long timeNow = System.currentTimeMillis();
  150.             if(timeNow > startTime + timeout) {
  151.                 break;
  152.             }
  153.             sleep(100);
  154.         }
  155.     }
  156.    
  157.     private boolean sleepUntilStunIsCast(int startNumOfSoulRunes) throws InterruptedException {
  158.         long startTime = System.currentTimeMillis();
  159.         long timeout = 4000;
  160.        
  161.         while(getNumberOfSoulRunes() == startNumOfSoulRunes) {
  162.             long timeNow = System.currentTimeMillis();
  163.             if(timeNow > startTime + timeout) {
  164.                 return false;
  165.             }
  166.             sleep(100);
  167.         }
  168.        
  169.         return true;
  170.     }
  171.    
  172.     private boolean sleepUntilInventoryTabActive() throws InterruptedException {
  173.         long startTime = System.currentTimeMillis();
  174.         long timeout = 4000;
  175.        
  176.         while(!tabs.getOpen().equals(Tab.INVENTORY)) {
  177.             long timeNow = System.currentTimeMillis();
  178.             if(timeNow > startTime + timeout) {
  179.                 return false;
  180.             }
  181.             sleep(100);
  182.         }
  183.        
  184.         return true;
  185.     }
  186.    
  187.     @Override
  188.     public void onPaint(Graphics2D g) {
  189.         int baseY = 10;
  190.         int baseX = 275;
  191.         int gapYAfterHeading = 20;
  192.         g.setColor(Color.LIGHT_GRAY);
  193.         g.fillRect(baseX, baseY, 290, 151);
  194.         g.setColor(Color.BLACK);
  195.         g.drawString("---: STUN-ALCHER :---", baseX+30, baseY+20);
  196.        
  197.         long totalRunTime = System.currentTimeMillis() - scriptStartTime;
  198.         long secondsRunTime = totalRunTime / 1000;
  199.         long minutesRunTime = 0;
  200.         if(secondsRunTime >= 60) {
  201.             minutesRunTime = secondsRunTime / 60;
  202.             secondsRunTime = secondsRunTime - (minutesRunTime * 60);
  203.         }
  204.         String strRunTime = "";
  205.         if(minutesRunTime > 0)
  206.             strRunTime += minutesRunTime + "min ";
  207.         strRunTime += secondsRunTime + "s";
  208.         g.drawString("Run Time: " + strRunTime, baseX+10, baseY+gapYAfterHeading+35);
  209.        
  210.         g.drawString("Total Stuns: " + soulRunesUsed, baseX+10, baseY+gapYAfterHeading+50);
  211.  
  212.         g.drawString("Total High Alchs: " + natureRunesUsed, baseX+10, baseY+gapYAfterHeading+65);
  213.        
  214.         g.drawString("Exp to next level: " + NumberFormat.getNumberInstance(Locale.ENGLISH).format(skills.experienceToLevel(Skill.MAGIC)), baseX+10, baseY+gapYAfterHeading+80);
  215.        
  216.         int totalMagicExp = currentMagicExp - startMagicExp;
  217.         String strMagicExp = NumberFormat.getNumberInstance(Locale.ENGLISH).format(totalMagicExp);
  218.         g.drawString("Total Exp gained: " + strMagicExp, baseX+10, baseY+gapYAfterHeading+95);
  219.        
  220.         int magicLevel = skills.getStatic(Skill.MAGIC);
  221.         g.drawString("Current level: " + magicLevel, baseX+10, baseY+gapYAfterHeading+110);
  222.        
  223.         g.drawString("Levels gained: " + (magicLevel - startMagicLevel), baseX+10, baseY+gapYAfterHeading+125);
  224.     }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement