Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.63 KB | None | 0 0
  1. package scripts.sophherblore.nodes;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api.input.Keyboard;
  6. import org.tribot.api.types.generic.Condition;
  7. import org.tribot.api2007.Banking;
  8. import org.tribot.api2007.Interfaces;
  9. import org.tribot.api2007.Inventory;
  10. import org.tribot.api2007.types.RSInterface;
  11. import org.tribot.api2007.types.RSItem;
  12.  
  13. import scripts.sophchaos.api.Node;
  14.  
  15. public class MakePotions extends Node
  16. {
  17.     private String ingredient = "Guam leaf";
  18.     private String vial = "Vial of water";
  19.     private int ingredientToClick;
  20.     private int vialToClick;
  21.  
  22.     private int startMakingPotsRandom = 420;
  23.     private int ingredientToClickRandom = 20;
  24.     private int changeClickOrderRandom = 180;
  25.     private int makeXRandom = 4;
  26.     private int makeOptionRandom = 220;
  27.  
  28.     @Override
  29.     public void execute()
  30.     {
  31.         if (!Banking.isBankScreenOpen())
  32.         {
  33.             General.sleep(100, startMakingPotsRandom);
  34.             useIngredientsOnEachOther();
  35.         }
  36.         if (Banking.isBankScreenOpen())
  37.         {
  38.             Banking.close();
  39.         }
  40.     }
  41.  
  42.     @Override
  43.     public boolean validate()
  44.     {
  45.         return WithdrawBankIngredients.gotIngredientsInInventory(ingredient, vial);
  46.     }
  47.  
  48.     // Calls different methods in order to get to the interface.
  49.     private void useIngredientsOnEachOther()
  50.     {
  51.         chooseIngredientsToClick();
  52.         RSItem[] ingredients = Inventory.find(WithdrawBankIngredients.ingredient);
  53.         RSItem[] vials = Inventory.find(WithdrawBankIngredients.vial);
  54.  
  55.         int random = General.random(0, changeClickOrderRandom);
  56.         if (random == 0)
  57.         {
  58.             changeClickOrder(ingredients, vials);
  59.             General.println("Changed click order!");
  60.         }
  61.         else if (WithdrawBankIngredients.withdrawOrder == 0)
  62.         {
  63.             ingredients[ingredientToClick].click();
  64.             vials[vialToClick].click();
  65.         }
  66.         else
  67.         {
  68.             General.println("We clicked on the vials first");
  69.             vials[vialToClick].click();
  70.             ingredients[ingredientToClick].click();
  71.         }
  72.         General.sleep(150, 250);
  73.         getInterface();
  74.  
  75.     }
  76.  
  77.     // Get's the interface.
  78.     private void getInterface()
  79.     {
  80.         RSInterface target = Interfaces.get(309, 3);
  81.         if (Timing.waitCondition(new Condition()
  82.         {
  83.             @Override
  84.             public boolean active()
  85.             {
  86.                 General.sleep(50, 150);
  87.                 return target != null && !target.isHidden();
  88.             }
  89.         }, General.random(2500, 3500)))
  90.         {
  91.             General.println("Calling chooseMakeOption!");
  92.             chooseMakeOption(target);
  93.         }
  94.         else
  95.         {
  96.             General.println("We are running getInterface() again.");
  97.             getInterface();
  98.         }
  99.     }
  100.  
  101.     // Changes the click order and also uses the items on each other.
  102.     private void changeClickOrder(RSItem[] ingredients, RSItem[] vials)
  103.     {
  104.         int vialToClick = 0;
  105.         int ingredientToClick = 0;
  106.         if (WithdrawBankIngredients.withdrawOrder == 0)
  107.         {
  108.             vialToClick = General.random(8, 13);
  109.             ingredientToClick = General.random(0, 5);
  110.  
  111.             vials[vialToClick].click();
  112.             General.sleep(50, 150);
  113.             ingredients[ingredientToClick].click();
  114.         }
  115.         else
  116.         {
  117.             vialToClick = General.random(0, 5);
  118.             ingredientToClick = General.random(8, 13);
  119.  
  120.             ingredients[ingredientToClick].click();
  121.             General.sleep(50, 150);
  122.             vials[vialToClick].click();
  123.         }
  124.     }
  125.  
  126.     // Chooses which ingredients to click.
  127.     private void chooseIngredientsToClick()
  128.     {
  129.         int random = General.random(0, ingredientToClickRandom);
  130.         int firstItem;
  131.         int secondItem;
  132.         if (random > 20)
  133.         {
  134.             firstItem = 10;
  135.             secondItem = 0;
  136.         }
  137.         else if (random > 10)
  138.         {
  139.             firstItem = 13;
  140.             secondItem = 0;
  141.         }
  142.         else if (random > 4)
  143.         {
  144.             firstItem = 11;
  145.             secondItem = 0;
  146.         }
  147.         else
  148.         {
  149.             firstItem = General.random(4, 13);
  150.             secondItem = General.random(0, 5);
  151.         }
  152.         if (WithdrawBankIngredients.withdrawOrder == 0)
  153.         {
  154.             ingredientToClick = firstItem;
  155.             vialToClick = secondItem;
  156.         }
  157.         else
  158.         {
  159.             vialToClick = secondItem;
  160.             ingredientToClick = firstItem;
  161.         }
  162.     }
  163.  
  164.     // Chooses one of the three make options.
  165.     private void chooseMakeOption(RSInterface target)
  166.     {
  167.         int random = General.random(0, makeOptionRandom);
  168.         if (random > 3)
  169.         {
  170.             General.println("Standard method called!");
  171.             makeAll(target);
  172.         }
  173.         else if (random != 0)
  174.         {
  175.             General.println("Make X called!");
  176.             makeX(target);
  177.         }
  178.         else
  179.         {
  180.             General.println("Cancel missclick called!");
  181.             cancelMissclick(target);
  182.         }
  183.     }
  184.  
  185.     // Uses the make all option.
  186.     private void makeAll(RSInterface target)
  187.     {
  188.         target.click("Make All");
  189.         Timing.waitCondition(new Condition()
  190.         {
  191.             @Override
  192.             public boolean active()
  193.             {
  194.                 General.sleep(50, 150);
  195.                 return potsAreMade(WithdrawBankIngredients.finishedProduct);
  196.             }
  197.         }, General.randomLong(8800, 11500));
  198.     }
  199.  
  200.     // Uses the "x" amount of potions.
  201.     private void makeX(RSInterface target)
  202.     {
  203.         target.click("Make X");
  204.         int random = General.random(0, makeXRandom);
  205.         if (random != 0)
  206.         {
  207.             Keyboard.typeSend("55");
  208.             General.sleep(100, 250);
  209.             Keyboard.pressEnter();
  210.         }
  211.         else
  212.         {
  213.             Keyboard.typeSend("33");
  214.             General.sleep(100, 250);
  215.             Keyboard.pressEnter();
  216.         }
  217.         Timing.waitCondition(new Condition()
  218.         {
  219.             @Override
  220.             public boolean active()
  221.             {
  222.                 General.sleep(50, 150);
  223.                 return potsAreMade(WithdrawBankIngredients.finishedProduct);
  224.             }
  225.         }, General.randomLong(8800, 11500));
  226.     }
  227.  
  228.     // Instead of choosing makeAll or makeX, we click on cancel.
  229.     private void cancelMissclick(RSInterface target)
  230.     {
  231.         target.click("Cancel");
  232.         General.sleep(50, 120);
  233.         int random = General.random(0, 10);
  234.         if (random != 0)
  235.         {
  236.             makeAll(target);
  237.         }
  238.         else
  239.         {
  240.             makeX(target);
  241.         }
  242.     }
  243.  
  244.     // Returns true if the pots are made.
  245.     private boolean potsAreMade(String finishedProduct)
  246.     {
  247.         return Inventory.getCount(finishedProduct) == 14;
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement