Advertisement
Guest User

XBLToothPik - Easy mPlanker #8

a guest
Aug 26th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.50 KB | None | 0 0
  1. package xtpMPlanker;
  2.  
  3.  
  4. import java.awt.Color;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.lang.reflect.Field;
  8. import java.util.ArrayList;
  9. import javax.swing.JOptionPane;
  10. import org.parabot.environment.api.interfaces.Paintable;
  11. import org.parabot.environment.scripts.Category;
  12. import org.parabot.environment.scripts.Script;
  13. import org.parabot.environment.scripts.ScriptManifest;
  14. import org.parabot.environment.scripts.framework.Strategy;
  15. import org.rev317.min.Loader;
  16. import org.parabot.environment.api.utils.Time;
  17. import org.parabot.environment.scripts.framework.SleepCondition;
  18. import org.rev317.min.api.methods.Npcs;
  19. import org.rev317.min.api.methods.Players;
  20. import org.rev317.min.api.methods.SceneObjects;
  21. import org.rev317.min.api.wrappers.Npc;
  22. import org.rev317.min.api.wrappers.SceneObject;
  23. import org.rev317.min.api.wrappers.Tile;
  24. import java.awt.event.KeyEvent;
  25. import org.parabot.environment.input.Keyboard;
  26. import org.rev317.min.api.methods.Inventory;
  27. import org.rev317.min.api.methods.Menu;
  28. import org.rev317.min.api.wrappers.Item;
  29.  
  30.  
  31. @ScriptManifest(author = "ToothPik, ",
  32. category = Category.OTHER,
  33. description = "Easy Planking",
  34. name = "Easy Planker",
  35. servers = { "PKHonor" },
  36. version = 1.)
  37. public class Main extends Script implements Paintable{
  38.     public ArrayList<Strategy> strategies = new ArrayList<Strategy>();
  39.     private boolean isPaintVisible;
  40.     public boolean onExecute()
  41.     {
  42.        
  43.         isPaintVisible = false;
  44.  
  45.         Globals.Status = Globals.BotStatus.BANKING;
  46.         strategies.add(new AntiRandom());
  47.         strategies.add(new Banker());
  48.         strategies.add(new Planker());
  49.         provide(strategies);
  50.        
  51.         showid();
  52.         isPaintVisible = true;
  53.         return true;
  54.     }
  55.     public void showid()
  56.     {
  57.         try{
  58.         Class<?>c = Loader.getClient().getClass();
  59.         Field f = c.getDeclaredField("h");
  60.         f.setAccessible(true);
  61.         f.setBoolean(Loader.getClient(), true);
  62.         }catch (Exception ex)
  63.         {
  64.            
  65.         }
  66.     }
  67.     public void paint(Graphics g)
  68.     {
  69.         if (!isPaintVisible)
  70.             return;
  71.         g.fillRect(2, 238, 108, 45);
  72.         g.setColor(Color.blue);
  73.         g.fillRect(2 , 224, 108, 14);
  74.        
  75.         g.setColor(Color.ORANGE);
  76.         g.setFont(new Font("News Gothic MT", Font.BOLD, 12));;
  77.         g.drawString("A ToothPik Bot", 12, 236);
  78.        
  79.         g.setColor(Color.white);
  80.         g.setFont(new Font("verdana", Font.BOLD, 12));;
  81.         g.drawString("Easy mPlanker", 4, 250);
  82.        
  83.         g.setColor(Color.cyan);
  84.         g.setFont(new Font("Verdana", Font.PLAIN, 10));
  85.         g.drawString("State: " + Globals.Status, 4, 260);
  86.        
  87.         g.drawString("Planks: " + Globals.PlanksMade, 4,  270);
  88.         g.drawString("Randoms: " + ((AntiRandom)strategies.get(0)).RandomsComplete, 4, 280);
  89.     }
  90.  
  91.     public class AntiRandom implements Strategy {
  92.     public int RandomsComplete;
  93.     //15814 = Preist (moderator must call this)
  94.     public int[] randoms = { 1091, 410, 3117 };
  95.    
  96.     public AntiRandom()
  97.     {
  98.         this.RandomsComplete = 0;
  99.     }
  100.     @Override
  101.     public boolean activate()
  102.     {
  103.        
  104.         Npc[] rnds = Npcs.getNearest(randoms);
  105.        
  106.         for (Npc n : rnds)
  107.             if (n != null && n.getLocation().distanceTo() < 3 && n.getInteractingCharacter().equals(Players.getMyPlayer()))
  108.                 return true;
  109.         return false;
  110.     }
  111.    
  112.     @Override
  113.     public void execute()
  114.     {
  115.         Globals.BotStatus lastStatus = Globals.Status;
  116.         Globals.Status = Globals.BotStatus.EVENT;
  117.        
  118.         Npc[] rnds = Npcs.getNearest(randoms);
  119.         System.out.println("Random Event Detected");
  120.        
  121.         for (Npc n : rnds)
  122.         {
  123.             if (n.getDef().getId() == 1091)
  124.             {
  125.                 System.out.println("Random Event: Bob's Island");
  126.                 //Bob's Island
  127.                 if (new Tile(2523, 4777).distanceTo() < 50)
  128.                 {
  129.                     SceneObject[] portals = SceneObjects.getNearest(8987);
  130.                     for (final SceneObject currentPortal : portals)
  131.                     {
  132.                         if (!(new Tile(2523, 4777).distanceTo() < 50))
  133.                             break;
  134.                         if (currentPortal != null)
  135.                         {
  136.                             currentPortal.interact(0);
  137.                             Time.sleep(new SleepCondition()
  138.                             {
  139.                                 @Override
  140.                                 public boolean isValid()
  141.                                 {
  142.                                     return currentPortal.getLocation().distanceTo() < 2;
  143.                                 }
  144.                             }, 6000);
  145.                             currentPortal.interact(0);
  146.                             Time.sleep(800);
  147.                            
  148.                         }
  149.                     }
  150.                 }
  151.                 RandomsComplete++;
  152.                 System.out.println("Bob's Island Complete");
  153.             }else if ((n.getDef().getId() == 3117 || n.getDef().getId() == 410) && n.getInteractingCharacter().equals(Players.getMyPlayer()))
  154.             {
  155.                 int npcID = n.getDef().getId();
  156.                 String eventName = npcID == 3117 ? "Sandwich Lady" : "Mysterious Old Man";
  157.                 System.out.println("Random Event: " + eventName);
  158.                 n.interact(0);
  159.                 Time.sleep(1000);
  160.                 System.out.println("Random Event: " + eventName + " Complete");
  161.                 RandomsComplete++;
  162.             }
  163.  
  164.         }
  165.         Globals.Status = lastStatus;
  166.     }
  167. }
  168.     public class Banker implements Strategy{
  169.     @Override
  170.     public boolean activate()
  171.     {
  172.         return Globals.Status == Globals.BotStatus.BANKING;
  173.     }
  174.     @Override
  175.     public void execute()
  176.     {
  177.         Npc[] npcs = Npcs.getNearest(4241);
  178.         for (final Npc n : npcs)
  179.         {
  180.             if (n != null)
  181.             {
  182.                 n.interact(0);
  183.                 Time.sleep(new SleepCondition(){
  184.                     @Override
  185.                     public boolean isValid()
  186.                     {
  187.                         return n.getLocation().distanceTo() < 2;
  188.                     }
  189.                 }, 15000);
  190.                 Time.sleep(new SleepCondition(){
  191.                     @Override
  192.                     public boolean isValid()
  193.                     {
  194.                         return Loader.getClient().getBackDialogId() == 2469;
  195.                     }
  196.                 }, 6000);
  197.                
  198.                 Menu.sendAction(315,20987904,49,2471);
  199.                 Time.sleep(new SleepCondition()
  200.                 {  
  201.                     @Override
  202.                     public boolean isValid()
  203.                     {
  204.                         return Loader.getClient().getOpenInterfaceId() == 23350;
  205.                     }
  206.                 }, 3500);
  207.                 Menu.sendAction(169, 558, 0, 23424);
  208.                
  209.                 if (Inventory.getCount(false, 8783) > 0)
  210.                 {
  211.                     Globals.PlanksMade += Inventory.getCount(false, 8783);
  212.                     Item[] invenItems = Inventory.getItems();
  213.                     boolean eBreak = false;                
  214.                     int looper = 0;
  215.                     while (looper < invenItems.length && !eBreak)
  216.                     {
  217.                         if (invenItems[looper].getId() == 8783)
  218.                         {
  219.                             int itemSlot = invenItems[looper].getSlot();
  220.                            
  221.                             Menu.sendAction(432, 8782,itemSlot,5064);
  222.                             Time.sleep(new SleepCondition()
  223.                             {
  224.                                 @Override
  225.                                 public boolean isValid()
  226.                                 {
  227.                                     return Inventory.getCount(false, 8783) == 0;
  228.                                 }
  229.                             }, 1000);
  230.                             eBreak = true;
  231.                         }
  232.                         looper++;
  233.                     }
  234.                 }
  235.                
  236.            
  237.                 if (Inventory.getCount(true, 8795) == 0)
  238.                 {
  239.                     if (!playerHasBankItem(8795))
  240.                     {
  241.                         System.out.println("Saw not found in bank or inventory.");
  242.                         Globals.Status = Globals.BotStatus.ERROR;
  243.                         return;
  244.                     }
  245.  
  246.                 }
  247.                 if (!(Inventory.getCount(true, 996) > 0))
  248.                 {
  249.                     if (!playerHasBankItem(996))
  250.                     {
  251.                         System.out.println("Money not found in invetory or bank.");
  252.                         Globals.Status = Globals.BotStatus.ERROR;
  253.                         return;
  254.                     }
  255.                 }
  256.  
  257.                 if (!playerHasBankItem(6332))
  258.                 {
  259.                     System.out.println("Mahogany Logs not found in bank.");
  260.                     Globals.Status = Globals.BotStatus.ERROR;
  261.                     return;
  262.                 }
  263.                
  264.                 if (!(Inventory.getCount(false, 8795) > 0))
  265.                 {
  266.                     int sawSlot = getBankSlot(8795);
  267.                     Menu.sendAction(632, 8794, sawSlot, 5382);
  268.                     Time.sleep(new SleepCondition()
  269.                     {
  270.                         @Override
  271.                         public boolean isValid()
  272.                         {
  273.                             return Inventory.getCount(false, 8795) > 0;
  274.                         }
  275.                     }, 6000);
  276.                 }
  277.                
  278.                 if (!(Inventory.getCount(true, 996) > 0))
  279.                 {
  280.  
  281.                     int moneySlot = getBankSlot(996);
  282.                     Menu.sendAction(432,995,moneySlot,5382);
  283.                     Time.sleep(new SleepCondition(){
  284.                         @Override
  285.                         public boolean isValid()
  286.                         {
  287.                             return Inventory.getCount(true, 996) > 0;
  288.                         }
  289.                     }, 6000);
  290.                 }
  291.                
  292.                 int logSlot = getBankSlot(6333);
  293.                
  294.                 Menu.sendAction(53, 6332, logSlot, 5382);
  295.                 Globals.Status = Globals.BotStatus.PLANKING;
  296.                 break;
  297.             }
  298.            
  299.         }
  300.        
  301.     }
  302.     public int getInputState(){
  303.         try{
  304.             Class<?> c = Loader.getClient().getClass();
  305.             Field f = c.getDeclaredField("aq");
  306.             f.setAccessible(true);
  307.             return f.getInt(Loader.getClient());
  308.         }catch(Exception e){
  309.             e.printStackTrace();
  310.             return -1;
  311.         }
  312.     }
  313.     private String getWithdrawValue()
  314.     {
  315.         try
  316.         {
  317.             Class<?> c = Loader.getClient().getClass();
  318.             Field f = c.getDeclaredField("eY");
  319.             f.setAccessible(true);
  320.             return (String)f.get(Loader.getClient());
  321.         }catch (Exception ex)
  322.         {
  323.             ex.printStackTrace();
  324.            
  325.         }
  326.         return null;
  327.     }
  328.     private void setWithdrawValue(int val)
  329.     {
  330.         try{
  331.             Class<?> c = Loader.getClient().getClass();
  332.             Field f = c.getDeclaredField("eY");
  333.             f.setAccessible(true);
  334.             f.set(Loader.getClient(), Integer.toString(val));
  335.         }catch(Exception e){
  336.             e.printStackTrace();
  337.         }
  338.     }
  339.     //Thanks to minecraftftw for these 3 bank functions!
  340.     private int getBankSlot(int id)
  341.     {
  342.         int[] bankIds = Loader.getClient().getInterfaceCache()[5382].getItems();
  343.         for (int i = 0; i < bankIds.length; i++)
  344.             if (bankIds[i] == id)
  345.                 return i;
  346.         return 0;
  347.     }
  348.     private int getBankStackSize(int id)
  349.     {
  350.         int[] stacks = Loader.getClient().getInterfaceCache()[5382].getStackSizes();
  351.         for (int i = 0; i < stacks.length; i++)
  352.             if (i == getBankSlot(id))
  353.                 return stacks[i];
  354.         return 0;
  355.     }
  356.     private boolean playerHasBankItem(int id)
  357.     {
  358.         return getBankStackSize(id) > 0;
  359.     }
  360. }
  361.     public static class Globals {
  362.     public static String UserName;
  363.     public static String Password;
  364.     public static BotStatus Status;
  365.     public static int PlanksMade;
  366.     public enum BotStatus
  367.     {
  368.         RELOGGING,
  369.         EVENT,
  370.         BANKING,
  371.         PLANKING,
  372.         ERROR
  373.     }
  374. }
  375.     public class Planker implements Strategy {
  376.  
  377.     @Override
  378.     public boolean activate()
  379.     {
  380.         return Globals.Status == Globals.BotStatus.PLANKING;
  381.     }
  382.     @Override
  383.     public void execute()
  384.     {
  385.         if (Inventory.getCount(false, 8783) > 0)
  386.         {
  387.             Globals.Status = Globals.BotStatus.BANKING;
  388.             return;
  389.         }
  390.         SceneObject[] workBenches = SceneObjects.getNearest(13708);
  391.         if (Inventory.getCount(true, 996) < 54000)
  392.         {
  393.             System.out.println("Not enough money to continue the bot.");
  394.             Globals.Status = Globals.BotStatus.ERROR;
  395.             return;
  396.         }
  397.         for (SceneObject wb : workBenches)
  398.         {
  399.             if (wb != null)
  400.             {
  401.                 wb.interact(0);
  402.                
  403.                 Time.sleep(new SleepCondition()
  404.                 {
  405.                     @Override
  406.                     public boolean isValid()
  407.                     {
  408.                         return Loader.getClient().getBackDialogId() == 2459;
  409.                     }
  410.                 }, 20000);
  411.                
  412.                 Menu.sendAction(315, 6332, 282, 2461);
  413.                
  414.                 Globals.Status = Globals.BotStatus.BANKING;
  415.                 break;
  416.             }
  417.         }
  418.        
  419.     }
  420. }
  421.  
  422. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement