Guest User

Untitled

a guest
Jul 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.24 KB | None | 0 0
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.RenderingHints;
  7.  
  8. import org.powerbot.concurrent.Task;
  9. import org.powerbot.concurrent.strategy.Condition;
  10. import org.powerbot.concurrent.strategy.Strategy;
  11. import org.powerbot.game.api.ActiveScript;
  12. import org.powerbot.game.api.Manifest;
  13. import org.powerbot.game.api.methods.Tabs;
  14. import org.powerbot.game.api.methods.Widgets;
  15. import org.powerbot.game.api.methods.input.Mouse;
  16. import org.powerbot.game.api.methods.interactive.Players;
  17. import org.powerbot.game.api.methods.node.Locations;
  18. import org.powerbot.game.api.methods.node.Menu;
  19. import org.powerbot.game.api.methods.tab.Inventory;
  20. import org.powerbot.game.api.methods.tab.Skills;
  21. import org.powerbot.game.api.methods.widget.Camera;
  22. import org.powerbot.game.api.util.Random;
  23. import org.powerbot.game.api.util.Time;
  24. import org.powerbot.game.api.wrappers.interactive.Player;
  25. import org.powerbot.game.api.wrappers.node.Item;
  26. import org.powerbot.game.api.wrappers.node.Location;
  27. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  28. import org.powerbot.game.bot.event.MessageEvent;
  29. import org.powerbot.game.bot.event.listener.MessageListener;
  30. import org.powerbot.game.bot.event.listener.PaintListener;
  31.  
  32.  
  33.  
  34. @Manifest(
  35.         name = "xScott's Lunar Planks",
  36.         version = 2.01,
  37.         description = "Makes planks with the PLank Make Spell",
  38.         authors = {     "xScott"    }
  39.         )
  40. public class xScottsLunarPlanker extends ActiveScript implements PaintListener, MessageListener
  41. {
  42.     //private final static int[] BankIDsNpcs =
  43.     //  {
  44.     //3293, /*GE(SW/NE)*/               3416,   /*GE(NE/SW)*/
  45.     //3418, /*GE(NW/SW)*/               553,    /*VarrockWest/East/Edgevile*/  
  46.     //2718, /*GE(NW)*/                  494,    /*Catherby/Lumbridge/Yanille/Ardy(S/N)*/
  47.     //6200, /*Falador(W/E)*/            7605,   /*Fist of guthix*/
  48.     //14924,    /*Burthrope(S)*/            497,    /*Al-Kharid Banker*/
  49.     //4457, /*Drayer banker*/           2759,   /*Edgevile*/
  50.     //4519  /*Moonclan*/
  51.     //};   
  52.  
  53.     private final static int[] BankIDsLocs =
  54.         {
  55.         2738,   /*Soulwars chest*/          25808/*Seers village bank booths*/
  56.         2213,   /*Catherby/Yanille*/        782,    /*Varrock west/east bankbooth*/
  57.         36786/*Lumb bankbooth*/          11758/*Falador booth (W/E)*/
  58.         4483,   /*Castle wars chest*/       27663/*Duel areana chest*/
  59.         42192/*Burthope(N) Chest*/       66665/*Burthrope(S) Table*/
  60.         35647/*Al-Kharid Booth*/         2012,   /*Draynor booth*/
  61.         42373/*Edgevile booth*/          34752/*Ardy(N/S)*/  
  62.         16700, /*Moonclan booth*/           2738    /*soulwars*/
  63.         };
  64.  
  65.  
  66.     //Variables
  67.     private static int BankID;
  68.     private static String Status = "Starting up";
  69.     private static int startExp;
  70.     private static long startTime;
  71.  
  72.     //Widgets
  73.     private static WidgetChild PlankMakeSpell;
  74.     private static WidgetChild[] InventoryItems;
  75.     private static WidgetChild CloseBank;
  76.     private static WidgetChild MagicStats;
  77.  
  78.     private final RenderingHints antialiasing = new RenderingHints(
  79.             RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  80.  
  81.     //private final Color color2 = new Color(0, 102, 51);
  82.     private final Color color3 = new Color(255, 255, 255);
  83.  
  84.     private final BasicStroke stroke1 = new BasicStroke(1);
  85.  
  86.     private final Font font1 = new Font("Arial", 0, 12);
  87.     private final Font font2 = new Font("Arial", 1, 16);
  88.  
  89.     @Override
  90.     protected void setup()
  91.     {
  92.         InventoryItems = Widgets.get(679,0).getChildren();
  93.         PlankMakeSpell = Widgets.get(430, 33);
  94.         CloseBank = Widgets.get(762, 45);
  95.         MagicStats = Widgets.get(320, 66);
  96.  
  97.         startExp = Skills.getExperiences()[6];
  98.         startTime = System.currentTimeMillis();
  99.  
  100.         LocateNearestBanker();
  101.         Tabs.INVENTORY.open();
  102.  
  103.  
  104.         provide(new MakePlanks());
  105.         provide(new Bank());
  106.         provide(new AntiBan());
  107.  
  108.     }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.     private class Bank extends Strategy implements Task, Condition
  115.     {
  116.  
  117.  
  118.         public boolean withdraw(int id) {
  119.             WidgetChild[] bank = Widgets.get(762, 95).getChildren();
  120.             for (WidgetChild child : bank) {
  121.                 if (child.getChildId() == id) {
  122.                     Mouse.click(child.getRelativeX() + 40,
  123.                             child.getRelativeY() + 105, false);
  124.                     return Menu.select("Withdraw-All");
  125.                 }
  126.             }
  127.             return false;
  128.         }
  129.  
  130.  
  131.         private void Deposit()
  132.         {
  133.             if(InventoryItems[24] != null && InventoryItems[24].getChildName().contains("plank"))
  134.             {
  135.                 InventoryItems[24].interact("Deposit-All");
  136.             }
  137.             else
  138.             {
  139.                 for(Item I : Inventory.getItems())
  140.                 {
  141.                     if(I.getName().contains("plank"))
  142.                     {
  143.                         I.getWidgetChild().interact("Deposit-All");
  144.                         break;
  145.                     }
  146.                 }
  147.             }
  148.         }
  149.         @Override
  150.         public void run()
  151.         {
  152.  
  153.             Location bank_ = Locations.getNearest(BankID);
  154.  
  155.             Status = "Interacting with bank...";
  156.  
  157.             if(!bank_.interact("Use")) { bank_.interact("Bank"); }
  158.             Time.sleep(500);
  159.  
  160.             Status = "Depositing";
  161.             Deposit();
  162.             //InventoryItems[Random.nextInt(2, 27)].interact("Deposit-All");
  163.             Time.sleep(600);
  164.  
  165.             Status = "Withdrawing";
  166.             withdraw(6332);//Mahogany log ID.
  167.             Time.sleep(Random.nextInt(100,200));
  168.  
  169.             CloseBank.click(true);
  170.             Tabs.INVENTORY.open();
  171.  
  172.  
  173.         }
  174.  
  175.         @Override
  176.         public boolean validate()
  177.         {
  178.             for(Item I : Inventory.getItems())
  179.             {
  180.                 if(I.getName().contains("logs"))
  181.                 {
  182.                     return false;
  183.                 }
  184.             }
  185.             return true;
  186.  
  187.         }
  188.  
  189.     }
  190.  
  191.     private class MakePlanks extends Strategy implements Task, Condition
  192.     {
  193.         //checks if magic tab is open, if not open it.
  194.         private void CheckMagicTabIsOpen()
  195.         {
  196.             if(!Tabs.MAGIC.open())  {   Tabs.MAGIC.open();  }
  197.         }
  198.  
  199.  
  200.         @Override
  201.         public void run()
  202.         {
  203.             Status = "Checking...";
  204.             CheckMagicTabIsOpen();//checks
  205.             Status = "Casting spell";
  206.             for(Item I : Inventory.getItems())
  207.             {
  208.                 if(I.getName().contains("logs"))
  209.                 {
  210.                     PlankMakeSpell.click(true);
  211.                     I.getWidgetChild().click(true);
  212.                     Time.sleep(Random.nextInt(1100, 1300));
  213.                     break;
  214.                     //CheckMagicTabIsOpen();
  215.                 }
  216.             }
  217.  
  218.         }
  219.  
  220.         @Override
  221.         public boolean validate()
  222.         {
  223.             for(Item I : Inventory.getItems())
  224.             {
  225.                 if(I.getName().contains("logs"))
  226.                 {
  227.                     return true;
  228.                 }
  229.             }
  230.             return false;
  231.         }
  232.  
  233.     }
  234.  
  235.     private class AntiBan extends Strategy implements Task, Condition
  236.     {
  237.  
  238.         @Override
  239.         public void run()
  240.         {
  241.             Antiban(Random.nextInt(0,160));
  242.  
  243.         }
  244.  
  245.         @Override
  246.         public boolean validate()
  247.         {
  248.             return true;
  249.         }
  250.  
  251.         void Antiban(int randomNumber)
  252.         {
  253.             if(randomNumber % 2 == 0)
  254.             {
  255.                 Status = "Anti-ban";
  256.                 switch(randomNumber)
  257.                 {
  258.                 case 0:
  259.                 case 2:
  260.                 case 4:
  261.                 case 6:
  262.                 case 8:
  263.                 {
  264.                     Camera.setAngle(Random.nextInt(43, 311));
  265.                     break;
  266.                 }
  267.                 case 10:
  268.                 {
  269.                     for(Player P : Players.getLoaded())
  270.                     {
  271.                         if(P.isOnScreen())
  272.                         {
  273.                             P.click(false);
  274.                             Time.sleep(Random.nextInt(400,700));
  275.                             break;
  276.                         }
  277.                     }
  278.                 }
  279.                 case 14:
  280.                 {
  281.                     Tabs.STATS.open();
  282.                     MagicStats.hover();
  283.                     Time.sleep(700);
  284.                     break;
  285.                 }
  286.                 case 16:
  287.                 {
  288.                     Time.sleep(Random.nextInt(500, 2100));
  289.                     break;
  290.                 }
  291.                 }
  292.             }
  293.  
  294.         }
  295.  
  296.     }
  297.  
  298.     private boolean LocateNearestBanker()
  299.     {
  300.         Status = "Locating nearest banker...";
  301.  
  302.         for(Location Loc : Locations.getLoaded())
  303.         {
  304.             for(final int I : BankIDsLocs)
  305.             {
  306.                 if(Loc.getId() == I)
  307.                 {
  308.                     if(Loc.isOnScreen())
  309.                     {
  310.                         BankID = I;
  311.                         return true;
  312.                     }
  313.                 }
  314.             }
  315.  
  316.         }
  317.         return false;
  318.     }
  319.  
  320.     private String formatTime(final long milliseconds)
  321.     {
  322.         final long t_seconds = milliseconds / 1000;
  323.         final long t_minutes = t_seconds / 60;
  324.         final long t_hours = t_minutes / 60;
  325.         final long seconds = t_seconds % 60;
  326.         final long minutes = t_minutes % 60;
  327.         final long hours = t_hours % 500;
  328.         return hours + ":" + minutes + ":" + seconds;
  329.     }
  330.  
  331.     @Override
  332.     public void onRepaint(Graphics g1)
  333.     {
  334.  
  335.         int ExpGained = (Skills.getExperiences()[6] - startExp);
  336.         int ExpPerHour = (int)Math.floor((ExpGained * 3600000D) / (System.currentTimeMillis() - startTime) / 1000);
  337.         String exphr = ExpPerHour + "k";
  338.         String timeElapsed = formatTime(System.currentTimeMillis() - startTime);
  339.  
  340.  
  341.  
  342.  
  343.  
  344.         //Mouse
  345.         //g1.setColor(Color.DARK_GRAY);
  346.         //g1.drawLine(mLoc.x, 0, mLoc.x, 505);
  347.         //g1.drawLine(0, mLoc.y, 765, mLoc.y);
  348.  
  349.         Graphics2D g = (Graphics2D)g1;
  350.         g.setRenderingHints(antialiasing);
  351.  
  352.         g.setColor(new Color(0,0,0,120));
  353.         g.fillRoundRect(4, 227, 229, 109, 16, 16);
  354.         g.setColor(Color.BLACK);
  355.         g.setStroke(stroke1);
  356.         g.drawRoundRect(4, 227, 229, 109, 16, 16);
  357.         g.setFont(font1);
  358.         g.setColor(color3);
  359.         g.drawString("Time elapsed: " + timeElapsed, 22, 266);
  360.         g.drawString("Experience gained: " + ExpGained, 22, 283);
  361.         g.drawString("Exp/hr: " + exphr, 22, 301);
  362.         g.drawString("Status: " + Status, 22, 319);
  363.         g.setFont(font2);
  364.         g.setColor(Color.GRAY);
  365.         g.drawString("xScotts Lunar Planker ", 37, 248);
  366.  
  367.  
  368.         g.setColor(new Color(0, 0, 0));
  369.         g.fillOval(Mouse.getX(), Mouse.getY(), 7, 7);
  370.         g.setColor(new Color(153, 153, 153));
  371.         g.fillOval(Mouse.getX() + 1, Mouse.getY() + 1, 5, 5);
  372.  
  373.     }
  374.  
  375.     @Override
  376.     public void messageReceived(MessageEvent arg0)
  377.     {
  378.         if(arg0.getMessage().contains("You do not have enough astral")) {       stop();     }
  379.         else if(arg0.getMessage().contains("You do not have enough nature")) {  stop();     }
  380.         else if(arg0.getMessage().contains("You do not have enough earth")) {   stop();     }
  381.         else if(arg0.getMessage().contains("You need")) {   stop();     }
  382.  
  383.     }
  384. }
Add Comment
Please, Sign In to add comment