daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.speljohan.rsbot.script.randoms;
  2.  
  3. import java.awt.Point;
  4. import java.util.List;
  5.  
  6. import com.speljohan.rsbot.script.Calculations;
  7. import com.speljohan.rsbot.script.Random;
  8. import com.speljohan.rsbot.script.ScriptManifest;
  9. import com.speljohan.rsbot.script.wrappers.RSCharacter;
  10. import com.speljohan.rsbot.script.wrappers.RSInterface;
  11. import com.speljohan.rsbot.script.wrappers.RSInterfaceChild;
  12. import com.speljohan.rsbot.script.wrappers.RSNPC;
  13. import com.speljohan.rsbot.script.wrappers.RSObject;
  14. import com.speljohan.rsbot.script.wrappers.RSTile;
  15.  
  16. @ScriptManifest(authors = { "PwnZ", "Megaalgos", "Taha" }, name = "Exam", version = 1.0)
  17. public class Exam extends Random {
  18.  
  19.     public RSObject door;
  20.     public RSNPC teacher;
  21.     public RSTile teacherTile;
  22.     public RSInterfaceChild exitColor;
  23.     public RSInterface nextObjectInterface = getInterface(103);
  24.     public RSInterface relatedCardsInterface = getInterface(559);
  25.     public int[] Ranged = { 11539, 11540, 11541, 11614, 11615, 11633 };
  26.     public int[] Cooking = { 11526, 11529, 11545, 11549, 11550, 11555, 11560,
  27.             11563, 11564, 11607, 11608, 11616, 11620, 11621, 11622, 11623,
  28.             11628, 11629, 11634, 11639, 11641, 11649, 11624 };
  29.     public int[] Fishing = { 11527, 11574, 11578, 11580, 11599, 11600, 11601,
  30.             11602, 11603, 11604, 11605, 11606, 11625 };
  31.     public int[] Combat = { 11528, 11531, 11536, 11537, 11579, 11591, 11592,
  32.             11593, 11597, 11627, 11631, 11635, 11636, 11638, 11642, 11648,
  33.             11617 };
  34.     public int[] Farming = { 11530, 11532, 11547, 11548, 11554, 11556, 11571,
  35.             11581, 11586, 11610, 11645 };
  36.     public int[] Magic = { 11533, 11534, 11538, 11562, 11567, 11582 };
  37.     public int[] Firemaking = { 11535, 11551, 11552, 11559, 11646 };
  38.     public int[] Hats = { 11540, 11557, 11558, 11560, 11570, 11619, 11626,
  39.             11630, 11632, 11637, 11654 };
  40.     public int[] Jewellery = { 11572, 11576, 11652 };
  41.     public int[] Jewellery2 = { 11572, 11576, 11652 };
  42.     public int[] Drinks = { 11542, 11543, 11544, 11644, 11647 };
  43.     public int[] Woodcutting = { 11573, 11595 };
  44.     public int[] Boots = { 11561, 11618, 11650, 11651 };
  45.     public int[] Crafting = { 11546, 11553, 11565, 11566, 11568, 11569, 11572,
  46.             11575, 11576, 11577, 11581, 11583, 11584, 11585, 11643, 11652,
  47.             11653 };
  48.     public int[] Mining = { 11587, 11588, 11594, 11596, 11598, 11609, 11610 };
  49.     public int[] Smithing = { 11611, 11612, 11613 };
  50.     public int[][] items = { Ranged, Cooking, Fishing, Combat, Farming, Magic,
  51.             Firemaking, Hats, Drinks, Woodcutting, Boots, Crafting, Mining,
  52.             Smithing };
  53.     public int Key = 11589;
  54.     public int Book = 11590;
  55.     public int Bones = 11617; // Combat?
  56.     public int Feather = 11624; // Cooking?
  57.     public int Hook = 11626; // Added to hats for pirate stuff.
  58.     public int Cape = 11627; // Added to combat (legends cape)
  59.     // Missing 11640
  60.     public int Talisman = 11643; // Added to crafting
  61.     public int Candle = 11646; // WTF? (Firemaking)
  62.     public int Vial = 11653; // Crafting?
  63.  
  64.     public int firstObject = -1;
  65.     public int secondObject = -1;
  66.     public int thirdObject = -1;
  67.    
  68.     String[] color = { "red", "green", "blue", "purple" };
  69.     int[] ids = { 2188, 2193, 2189, 2192 };
  70.  
  71.     public enum Stage {
  72.         wait, findTeacher, clickDoor, findDoorColor, answerNextObject;
  73.     }
  74.  
  75.     @Override
  76.     public boolean activateCondition() {
  77.         if (!isFullyLoggedIn())
  78.             return false;
  79.         return getNearestNPCByName("Mr. Mordaut") != null
  80.                 && distanceTo(teacherTile) <= 15;
  81.     }
  82.  
  83.     public Stage getStage() {
  84.         if (teacher == null)
  85.             return Stage.findTeacher;
  86.         if (door != null)
  87.             return Stage.clickDoor;
  88.         exitColor = searchInterfacesText("door");
  89.         if (exitColor != null)
  90.             return Stage.findDoorColor;
  91.         if (nextObjectInterface.isValid()) {
  92.             return Stage.answerNextObject;
  93.         }
  94.         return Stage.wait;
  95.     }
  96.    
  97.     private int AnswerNextObject(){
  98.         if (getObjects()) {
  99.             if (clickAnswer()) {
  100.                 return random(800, 1200);
  101.             } else {
  102.                 log.info("I failed to click the correct answer. " +
  103.                                 "I am going to make an educated guess.");
  104.                 guess();
  105.                 return random(800, 1200);
  106.             }
  107.         } else {
  108.             log.info("I was unable to find the objects. " +
  109.                             "I am going to make an educated guess.");
  110.             guess();
  111.             return random(800, 1200);
  112.         }
  113.     }
  114.  
  115.     private int FindCorrectDoor(){
  116.         String text = exitColor.getText().toLowerCase();
  117.         for(int i = 0; i < color.length; i++){
  118.             if(text.contains(color[i]))
  119.                 door = findObject(ids[i]);
  120.         }
  121.         return random(200, 400);
  122.     }
  123.    
  124.     private int ClickDoor(){
  125.         if (distanceTo(door) > 3) {
  126.             walkTileMM(door.getLocation());
  127.             wait(random(1400, 2500));
  128.         }
  129.         char[] direction = { 'w', 'e', 'w', 'n' };
  130.         int doorID = door.getID();
  131.         for(int i = 0; i < ids.length; i++){
  132.             if(doorID == ids[i])
  133.                 setCompass(direction[i]);
  134.         }
  135.  
  136.         clickObject(door, "Open");
  137.         return random(500, 1000);
  138.     }
  139.    
  140.     private int FindMordaut(){
  141.         if ((teacher = getNearestNPCByName("Mr. Mordaut")) == null
  142.                 || distanceTo(teacherTile) >= 15) {
  143.             log("Error! Could not find Mr. Mordaut!");
  144.             return -1;
  145.         }
  146.         return (random(200, 400));
  147.     }
  148.    
  149.     @Override
  150.     public int loop() {
  151.         switch (getStage()) {
  152.         case answerNextObject:
  153.             log.info("Question Type: What comes next?");
  154.             return AnswerNextObject();
  155.  
  156.         case findDoorColor:
  157.             return FindCorrectDoor();
  158.  
  159.  
  160.         case clickDoor:
  161.             return ClickDoor();
  162.  
  163.         case findTeacher:
  164.             return FindMordaut();
  165.  
  166.         case wait:
  167.             return (random(200, 400));
  168.             //Why? Would still return the same if you look two lines down /Sweed Raver
  169.         }
  170.         return random(200, 400);
  171.     }
  172.  
  173.     /*
  174.      * Don't use this with any other monster. I edited for this script only
  175.      * because Mr. Mordaut doesn't move.
  176.      */
  177.     @Override
  178.     public boolean clickCharacter(final RSCharacter c, final String action) {
  179.         try {
  180.             Point screenLoc = null;
  181.             screenLoc = c.getScreenLocation();
  182.  
  183.             if (!c.isValid() || !pointOnScreen(screenLoc)) {
  184.                 System.out.println("Not on screen " + action);
  185.                 return false;
  186.             }
  187.  
  188.             moveMouse(screenLoc);
  189.  
  190.             screenLoc = c.getScreenLocation();
  191.  
  192.             final List<String> items = getMenuItems();
  193.  
  194.             if (items.get(0).toLowerCase().contains(action.toLowerCase())) {
  195.                 clickMouse(screenLoc, true);
  196.                 return true;
  197.             } else {
  198.                 clickMouse(screenLoc, false);
  199.                 return atMenu(action);
  200.             }
  201.  
  202.         } catch (final NullPointerException e) {
  203.         }
  204.         return true;
  205.     }
  206.  
  207.     // My clickObject, like clickCharacter, and faster than atObject.
  208.     public boolean clickObject(final RSObject c, final String action) {
  209.         try {
  210.             Point screenLoc = Calculations.tileToScreen(c.getLocation());
  211.             if (c == null || !pointOnScreen(screenLoc)) {
  212.                 log("Not on screen " + action);
  213.                 return false;
  214.             }
  215.  
  216.             moveMouse(screenLoc);
  217.             screenLoc = Calculations.tileToScreen(c.getLocation());
  218.             if (!getMouseLocation().equals(screenLoc)) {
  219.                 return false;
  220.             }
  221.  
  222.             final List<String> items = getMenuItems();
  223.             if (items.size() <= 1) {
  224.                 return false;
  225.             }
  226.             if (items.get(0).toLowerCase().contains(action.toLowerCase())) {
  227.                 clickMouse(screenLoc, true);
  228.                 return true;
  229.             } else {
  230.                 clickMouse(screenLoc, false);
  231.                 return atMenu(action);
  232.             }
  233.         } catch (final NullPointerException e) {
  234.         }
  235.         return true;
  236.     }
  237.  
  238.     public RSInterfaceChild searchInterfacesText(final String string) {
  239.         final RSInterface[] inters = RSInterface.getAllInterfaces();
  240.         for (final RSInterface inter : inters) {
  241.             for (final RSInterfaceChild interfaceChild : inter) {
  242.                 if (interfaceChild.getText().toLowerCase().contains(
  243.                         string.toLowerCase())) {
  244.                     return interfaceChild;
  245.                 }
  246.             }
  247.         }
  248.  
  249.         return null;
  250.     }
  251.  
  252.     public boolean arrayContains(final int[] arr, final int i) {
  253.         boolean returnt = false;
  254.         for (final int num : arr) {
  255.             if (num == i) {
  256.                 returnt = true;
  257.             }
  258.         }
  259.  
  260.         return returnt;
  261.     }
  262.  
  263.     public boolean clickAnswer() {
  264.         int[] Answers;
  265.         if ((Answers = returnAnswer()) == null) {
  266.             return false;
  267.         }
  268.  
  269.         for (int i = 10; i <= 13; i++) {
  270.             if (arrayContains(Answers, nextObjectInterface.getChild(i)
  271.                     .getComponentID())) {
  272.                 return atInterface(nextObjectInterface.getChild(i));
  273.             }
  274.         }
  275.  
  276.         return false;
  277.     }
  278.  
  279.     public boolean getObjects() {
  280.         firstObject = -1;
  281.         secondObject = -1;
  282.         thirdObject = -1;
  283.         firstObject = nextObjectInterface.getChild(6).getComponentID();
  284.         secondObject = nextObjectInterface.getChild(7).getComponentID();
  285.         thirdObject = nextObjectInterface.getChild(8).getComponentID();
  286.         return firstObject != -1 && secondObject != -1 && thirdObject != -1;
  287.     }
  288.  
  289.     public void guess() {
  290.         final int[] objects = new int[4];
  291.         objects[0] = nextObjectInterface.getChild(10).getComponentID();
  292.         objects[1] = nextObjectInterface.getChild(11).getComponentID();
  293.         objects[2] = nextObjectInterface.getChild(12).getComponentID();
  294.         objects[3] = nextObjectInterface.getChild(13).getComponentID();
  295.  
  296.         int lowest = 120;
  297.         int click = 10;
  298.         final int compare = returnAnswer()[0];
  299.         if (compare <= 10) {
  300.             atInterface(nextObjectInterface.getChild(random(10, 13)));
  301.             return;
  302.         }
  303.  
  304.         for (int i = 0; i < objects.length; i++) {
  305.             if (Math.abs(objects[i] - compare) <= lowest) {
  306.                 lowest = Math.abs(objects[i] - compare);
  307.             }
  308.             click = 10 + i;
  309.         }
  310.  
  311.         atInterface(nextObjectInterface.getChild(click));
  312.     }
  313.  
  314.     public int[] returnAnswer() {
  315.         final int[] count = new int[items.length];
  316.         for (int i = 0; i < count.length; i++) {
  317.             count[i] = 0;
  318.         }
  319.  
  320.         for (int i = 0; i < items.length; i++) {
  321.             for (int j = 0; j < items[i].length; j++) {
  322.                 if (items[i][j] == firstObject) {
  323.                     count[i]++;
  324.                 }
  325.                 if (items[i][j] == secondObject) {
  326.                     count[i]++;
  327.                 }
  328.                 if (items[i][j] == thirdObject) {
  329.                     count[i]++;
  330.                 }
  331.  
  332.                 if (count[i] >= 2) {
  333.                     log.info("Answer Type Found!");
  334.                     return items[i];
  335.                 }
  336.             }
  337.         }
  338.  
  339.         return null;
  340.     }
  341. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top