Advertisement
NoiselessJoe

nCosmics

Jul 17th, 2014
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.36 KB | None | 0 0
  1. package PKHonorRuneCrafter;
  2.  
  3.  
  4. import java.awt.Color;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import java.awt.Image;
  9. import java.awt.Polygon;
  10. import java.awt.Toolkit;
  11. import java.io.IOException;
  12. import java.net.URL;
  13. import java.text.DecimalFormat;
  14. import java.util.ArrayList;
  15.  
  16.  
  17.  
  18.  
  19. import javax.imageio.ImageIO;
  20.  
  21. import org.parabot.environment.api.interfaces.Paintable;
  22. import org.parabot.environment.api.utils.Time;
  23. import org.parabot.environment.scripts.Category;
  24. import org.parabot.environment.scripts.Script;
  25. import org.parabot.environment.scripts.ScriptManifest;
  26. import org.parabot.environment.scripts.framework.SleepCondition;
  27. import org.parabot.environment.scripts.framework.Strategy;
  28. import org.rev317.min.Loader;
  29. import org.rev317.min.api.methods.Bank;
  30. import org.rev317.min.api.methods.Inventory;
  31. import org.rev317.min.api.methods.Menu;
  32. import org.rev317.min.api.methods.Npcs;
  33. import org.rev317.min.api.methods.Players;
  34. import org.rev317.min.api.methods.SceneObjects;
  35. import org.rev317.min.api.methods.Skill;
  36. import org.rev317.min.api.wrappers.Npc;
  37. import org.rev317.min.api.wrappers.SceneObject;
  38. import org.rev317.min.api.wrappers.Tile;
  39. import org.parabot.environment.api.utils.Timer;
  40. @ScriptManifest
  41. (author = "NoiselessJoe", category = Category.RUNECRAFTING, description = "Makes cosmic runes. Put essence in first bank slot, and start in cosmic alter rift. Now with Anti-Randoms (Thanks Minimal) & Paint.", name = "nCosmics", servers = {"PkHonor"}, version = 1.4)
  42. /**********************************************************************************************************************/
  43. public class nCosmics extends Script implements Paintable
  44. {
  45.     private final ArrayList<Strategy> strategies = new ArrayList<>();
  46.    
  47.     /*Variables*/
  48.    
  49.     /*Makes a new timer, used for getPerHour*/
  50.     private Timer timer = new Timer();
  51.     /*Sceneobjects to fins the nearest bank/alter*/
  52.     private final SceneObject[] Banks = SceneObjects.getNearest(2213);
  53.     private final SceneObject[] Altar = SceneObjects.getNearest(2484);
  54.     final SceneObject booth = Banks[0];
  55.     /*Essence and Cosmic Rune IDs*/
  56.     private static int ESSENCE = 1437;
  57.     private int COSMIC = 565;
  58.     /*Anti-Random vars*/
  59.     private int[] randoms = { 410, 1091, 3117, 3022, 3351, 409 };
  60.     private int rCount;
  61.     private final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
  62.     private static Image img1;
  63.     Area bobsIsland = new Area(new Tile(2511, 4765),
  64.     new Tile(2511, 4790),
  65.     new Tile(2542, 4790),
  66.     new Tile(2542, 4765));
  67.     /*Paint Vars*/
  68.     private final Color color1 = new Color(255, 255, 255); /*White*/
  69.     private final Font font1 = new Font("Verdana", 1, 11);/*Bold, Sized 11 Verdana Font*/
  70.     public int cosmicsMade = 0;
  71.     public int byhow;
  72.    
  73.     public boolean onExecute()
  74.    
  75.     {
  76.         if(Skill.RUNECRAFTING.getLevel() >= 59)
  77.         {
  78.             byhow = 56;
  79.         }
  80.         else
  81.         {
  82.             byhow = 28;
  83.         }
  84.         strategies.add(new Antis());
  85.         strategies.add(new makeRunes());
  86.         strategies.add(new Banking());
  87.        
  88.         provide(strategies);
  89.         return true;
  90.        
  91.     }
  92.     public void onFinish()
  93.     {
  94.         System.out.println("You have made " + cosmicsMade + " Cosmic Runes.");
  95.         System.out.println("Thanks for using my script! :) Any problems, let me know in the thread. ");
  96.     }
  97.     /**********************************************************************************************************************/
  98. //Thanks to Minimal for the Anti-Randoms
  99. //http://www.parabot.org/community/user/10775-minimal/
  100.     public class Antis implements Strategy
  101.     {
  102.         public boolean activate()
  103.         {
  104.             for (Npc n : Npcs.getNearest(randoms))
  105.             {
  106.                 if (n.getLocation().distanceTo() < 3)
  107.                     return true;
  108.             }
  109.  
  110.             return false;
  111.         }
  112.  
  113.         public void execute()
  114.         {
  115.             if (runnable != null)
  116.                 runnable.run();
  117.  
  118.             sleep(500);
  119.  
  120.             Npc[] n = Npcs.getNearest(randoms);
  121.  
  122.             System.out.println("There is a random nearby!");
  123.  
  124.             sleep(500);
  125.  
  126.             try
  127.             {
  128.                 if (n[0].getDef().getId() == 1091
  129.                 && bobsIsland.contains(Players.getMyPlayer().getLocation()))
  130.                 {
  131.                     // Bob anti-random
  132.  
  133.                     SceneObject[] portal = SceneObjects.getNearest(8987);
  134.  
  135.                     for (int i = 0; i < portal.length; i++)
  136.                     {
  137.                         if (bobsIsland.contains(Players.getMyPlayer().getLocation()))
  138.                         {
  139.                             final SceneObject portal2 = portal[i];
  140.  
  141.                             portal2.interact(0);
  142.  
  143.                             Time.sleep(new SleepCondition()
  144.                             {
  145.                                 @Override
  146.                                 public boolean isValid()
  147.                                 {
  148.                                     return portal2.getLocation().distanceTo() < 1;
  149.                                 }
  150.  
  151.                             }, 7500);
  152.  
  153.                             sleep(1000);
  154.                         }
  155.                         else
  156.                             break;
  157.                     }
  158.  
  159.                     System.out.println("Bob's Island has been completed");
  160.                 }
  161.                 else if (n[0].getDef().getId() == 3022)
  162.                 {
  163.                     System.out.println("A mod called a Genie random.\n" +
  164.                             "The client was closed to protect your account.");
  165.  
  166.                     System.exit(0);
  167.                 }
  168.                 else
  169.                 {
  170.                     n[0].interact(0);
  171.                     sleep(2000);
  172.  
  173.                     System.out.println("Sandwich lady/Old man random has been completed");
  174.                 }
  175.             }
  176.             catch (NullPointerException | ArrayIndexOutOfBoundsException e)
  177.             {
  178.                 System.out.println(e.getMessage());
  179.                 sleep(1500);
  180.             }
  181.  
  182.             rCount++;
  183.         }
  184.     }
  185.     /**********************************************************************************************************************/
  186.     //Interacts with Alter
  187.     public class makeRunes implements Strategy
  188. {
  189.     final SceneObject CosmicAlter = Altar[0];
  190.    
  191.     @Override
  192.     public boolean activate() {
  193.  
  194.         return Inventory.isFull()
  195.         && !Players.getMyPlayer().isInCombat()
  196.         && Inventory.getCount(ESSENCE) > 0;
  197.     }
  198.  
  199.     @Override
  200.     public void execute()
  201.     {
  202.        
  203.         if(CosmicAlter != null)
  204.         {
  205.             CosmicAlter.interact(0);
  206.             Time.sleep(420);
  207.             cosmicsMade = cosmicsMade + byhow;
  208.         }
  209.        
  210.     }
  211.    
  212. }
  213.     /**********************************************************************************************************************/
  214.    
  215.     /*Banks the Cosmic Runes, withdrawls Rune Essence*/
  216.    
  217.     public class Banking implements Strategy
  218. {
  219.    
  220.    
  221. @Override
  222.     public boolean activate()
  223.     {
  224.         return !Inventory.isFull()
  225.         && !Players.getMyPlayer().isInCombat();
  226.     }
  227.  
  228.     @Override
  229.     public void execute()
  230.     {
  231.         if(booth != null)
  232.         {
  233.             /*If there is a bank booth near you, it will interact with it.*/
  234.             booth.interact(0);
  235.             Time.sleep(new SleepCondition()
  236.             {
  237.                
  238.                 @Override
  239.                 public boolean isValid()
  240.                 {
  241.                     /*Check if bank interface is open*/
  242.                     return Loader.getClient().getOpenInterfaceId() == 23350;
  243.                 }
  244.             }, 3000);
  245.            
  246.             /*Deposists Everything into bank*/
  247.             Menu.clickButton(23412);
  248.             Time.sleep(new SleepCondition()
  249.             {
  250.                
  251.                 @Override
  252.                 public boolean isValid()
  253.                 {
  254.                    
  255.                     //When inventory is empty, it will withdrawl the essence.
  256.                     return Inventory.isEmpty();
  257.                 }
  258.             }, 3000);
  259.             Menu.sendAction(53, ESSENCE - 1, 0, 5382);
  260.             Time.sleep(new SleepCondition()
  261.             {
  262.                
  263.                 @Override
  264.                 public boolean isValid()
  265.                 {
  266.                     return Inventory.getCount(ESSENCE) > 0;
  267.                 }
  268.             }, 3000);
  269.             Time.sleep(300);
  270.         }
  271.     }
  272. }
  273.     /*********************************************************************************/
  274.     /*Formats numbers, so 1000000 will output as 1,000,000*/
  275.     public String addDecimals(int thing)
  276.     {
  277.         DecimalFormat form = new DecimalFormat("#,###");
  278.         return "" + form.format(thing);
  279.     }
  280.     //Method to get Image from online (ie. Imgur)
  281.     public static Image getImage(String url)
  282.     {
  283.         try {
  284.            
  285.             return ImageIO.read(new URL(url));
  286.         } catch (IOException e)
  287.         {
  288.             return null;
  289.         }
  290.     }
  291.     @Override
  292.     /*Makes the Paint*/
  293.     public void paint(Graphics arg0)
  294.    
  295.     {
  296. /*  Using xpos and ypos makes it easier to find the coords on the paint. I get the
  297.     coords of the paint themselves and add the xpos and ypos to get the location.
  298. */
  299.         int xpos = 545;
  300.         int ypos = 313;
  301.         img1=getImage("http://i.imgur.com/fBoKdBE.png");
  302.         Graphics2D g = (Graphics2D) arg0;
  303.         g.drawImage(img1, xpos,ypos,null);
  304.         g.setColor(color1);
  305.         g.setFont(font1);
  306.         g.drawString(timer.toString(), 70+xpos, 82+ypos);
  307.         g.drawString("" + addDecimals(cosmicsMade), 95+xpos,100+ypos );
  308.         g.drawString("" + addDecimals(timer.getPerHour((int)cosmicsMade)), 102+xpos,118+ypos );
  309.         g.drawString("" + rCount, 109 + xpos, 136 + ypos);
  310.     }
  311.     //Area for the Anti-Randoms (from Minimal)
  312.     public class Area
  313.     {
  314.     private Polygon p;
  315.  
  316.     /**
  317.      * Initializes a PolygonArea with the tiles given
  318.      *
  319.      * @param tiles
  320.      *            tiles to use in the area
  321.      */
  322.         public Area(Tile... tiles)
  323.         {
  324.             this.p = new Polygon();
  325.             for (int i = 0; i < tiles.length; i++)
  326.             {
  327.                 p.addPoint(tiles[i].getX(), tiles[i].getY());
  328.             }
  329.         }
  330.  
  331.     /**
  332.      * Checks if a tile is in the area
  333.      *
  334.      * @param tile
  335.      *            The tile to check
  336.      * @return <b>true</b> if area does contain the tile, otherwise <b>false</b>
  337.      */
  338.     public boolean contains(Tile tile)
  339.     {
  340.         return this.contains(tile.getX(), tile.getY());
  341.     }
  342.  
  343.     public boolean contains(int x, int y)
  344.     {
  345.         int i;
  346.         int j;
  347.         boolean result = false;
  348.         for (i = 0, j = p.npoints - 1; i < p.npoints; j = i++)
  349.         {
  350.             if ((p.ypoints[i] > y - 1) != (p.ypoints[j] > y - 1)
  351.                     && (x <= (p.xpoints[j] - p.xpoints[i]) * (y - p.ypoints[i])
  352.                     / (p.ypoints[j] - p.ypoints[i]) + p.xpoints[i])) {
  353.                 result = !result;
  354.             }
  355.         }
  356.         return result;
  357.     }
  358.     }
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement