Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.speljohan.rsbot.script.randoms;
- import java.awt.Point;
- import java.util.List;
- import com.speljohan.rsbot.script.Calculations;
- import com.speljohan.rsbot.script.Random;
- import com.speljohan.rsbot.script.ScriptManifest;
- import com.speljohan.rsbot.script.wrappers.RSCharacter;
- import com.speljohan.rsbot.script.wrappers.RSInterface;
- import com.speljohan.rsbot.script.wrappers.RSInterfaceChild;
- import com.speljohan.rsbot.script.wrappers.RSNPC;
- import com.speljohan.rsbot.script.wrappers.RSObject;
- import com.speljohan.rsbot.script.wrappers.RSTile;
- @ScriptManifest(authors = { "PwnZ", "Megaalgos", "Taha" }, name = "Exam", version = 1.0)
- public class Exam extends Random {
- public RSObject door;
- public RSNPC teacher;
- public RSTile teacherTile;
- public RSInterfaceChild exitColor;
- public RSInterface nextObjectInterface = getInterface(103);
- public RSInterface relatedCardsInterface = getInterface(559);
- public int[] Ranged = { 11539, 11540, 11541, 11614, 11615, 11633 };
- public int[] Cooking = { 11526, 11529, 11545, 11549, 11550, 11555, 11560,
- 11563, 11564, 11607, 11608, 11616, 11620, 11621, 11622, 11623,
- 11628, 11629, 11634, 11639, 11641, 11649, 11624 };
- public int[] Fishing = { 11527, 11574, 11578, 11580, 11599, 11600, 11601,
- 11602, 11603, 11604, 11605, 11606, 11625 };
- public int[] Combat = { 11528, 11531, 11536, 11537, 11579, 11591, 11592,
- 11593, 11597, 11627, 11631, 11635, 11636, 11638, 11642, 11648,
- 11617 };
- public int[] Farming = { 11530, 11532, 11547, 11548, 11554, 11556, 11571,
- 11581, 11586, 11610, 11645 };
- public int[] Magic = { 11533, 11534, 11538, 11562, 11567, 11582 };
- public int[] Firemaking = { 11535, 11551, 11552, 11559, 11646 };
- public int[] Hats = { 11540, 11557, 11558, 11560, 11570, 11619, 11626,
- 11630, 11632, 11637, 11654 };
- public int[] Jewellery = { 11572, 11576, 11652 };
- public int[] Jewellery2 = { 11572, 11576, 11652 };
- public int[] Drinks = { 11542, 11543, 11544, 11644, 11647 };
- public int[] Woodcutting = { 11573, 11595 };
- public int[] Boots = { 11561, 11618, 11650, 11651 };
- public int[] Crafting = { 11546, 11553, 11565, 11566, 11568, 11569, 11572,
- 11575, 11576, 11577, 11581, 11583, 11584, 11585, 11643, 11652,
- 11653 };
- public int[] Mining = { 11587, 11588, 11594, 11596, 11598, 11609, 11610 };
- public int[] Smithing = { 11611, 11612, 11613 };
- public int[][] items = { Ranged, Cooking, Fishing, Combat, Farming, Magic,
- Firemaking, Hats, Drinks, Woodcutting, Boots, Crafting, Mining,
- Smithing };
- public int Key = 11589;
- public int Book = 11590;
- public int Bones = 11617; // Combat?
- public int Feather = 11624; // Cooking?
- public int Hook = 11626; // Added to hats for pirate stuff.
- public int Cape = 11627; // Added to combat (legends cape)
- // Missing 11640
- public int Talisman = 11643; // Added to crafting
- public int Candle = 11646; // WTF? (Firemaking)
- public int Vial = 11653; // Crafting?
- public int firstObject = -1;
- public int secondObject = -1;
- public int thirdObject = -1;
- String[] color = { "red", "green", "blue", "purple" };
- int[] ids = { 2188, 2193, 2189, 2192 };
- public enum Stage {
- wait, findTeacher, clickDoor, findDoorColor, answerNextObject;
- }
- @Override
- public boolean activateCondition() {
- if (!isFullyLoggedIn())
- return false;
- return getNearestNPCByName("Mr. Mordaut") != null
- && distanceTo(teacherTile) <= 15;
- }
- public Stage getStage() {
- if (teacher == null)
- return Stage.findTeacher;
- if (door != null)
- return Stage.clickDoor;
- exitColor = searchInterfacesText("door");
- if (exitColor != null)
- return Stage.findDoorColor;
- if (nextObjectInterface.isValid()) {
- return Stage.answerNextObject;
- }
- return Stage.wait;
- }
- private int AnswerNextObject(){
- if (getObjects()) {
- if (clickAnswer()) {
- return random(800, 1200);
- } else {
- log.info("I failed to click the correct answer. " +
- "I am going to make an educated guess.");
- guess();
- return random(800, 1200);
- }
- } else {
- log.info("I was unable to find the objects. " +
- "I am going to make an educated guess.");
- guess();
- return random(800, 1200);
- }
- }
- private int FindCorrectDoor(){
- String text = exitColor.getText().toLowerCase();
- for(int i = 0; i < color.length; i++){
- if(text.contains(color[i]))
- door = findObject(ids[i]);
- }
- return random(200, 400);
- }
- private int ClickDoor(){
- if (distanceTo(door) > 3) {
- walkTileMM(door.getLocation());
- wait(random(1400, 2500));
- }
- char[] direction = { 'w', 'e', 'w', 'n' };
- int doorID = door.getID();
- for(int i = 0; i < ids.length; i++){
- if(doorID == ids[i])
- setCompass(direction[i]);
- }
- clickObject(door, "Open");
- return random(500, 1000);
- }
- private int FindMordaut(){
- if ((teacher = getNearestNPCByName("Mr. Mordaut")) == null
- || distanceTo(teacherTile) >= 15) {
- log("Error! Could not find Mr. Mordaut!");
- return -1;
- }
- return (random(200, 400));
- }
- @Override
- public int loop() {
- switch (getStage()) {
- case answerNextObject:
- log.info("Question Type: What comes next?");
- return AnswerNextObject();
- case findDoorColor:
- return FindCorrectDoor();
- case clickDoor:
- return ClickDoor();
- case findTeacher:
- return FindMordaut();
- case wait:
- return (random(200, 400));
- //Why? Would still return the same if you look two lines down /Sweed Raver
- }
- return random(200, 400);
- }
- /*
- * Don't use this with any other monster. I edited for this script only
- * because Mr. Mordaut doesn't move.
- */
- @Override
- public boolean clickCharacter(final RSCharacter c, final String action) {
- try {
- Point screenLoc = null;
- screenLoc = c.getScreenLocation();
- if (!c.isValid() || !pointOnScreen(screenLoc)) {
- System.out.println("Not on screen " + action);
- return false;
- }
- moveMouse(screenLoc);
- screenLoc = c.getScreenLocation();
- final List<String> items = getMenuItems();
- if (items.get(0).toLowerCase().contains(action.toLowerCase())) {
- clickMouse(screenLoc, true);
- return true;
- } else {
- clickMouse(screenLoc, false);
- return atMenu(action);
- }
- } catch (final NullPointerException e) {
- }
- return true;
- }
- // My clickObject, like clickCharacter, and faster than atObject.
- public boolean clickObject(final RSObject c, final String action) {
- try {
- Point screenLoc = Calculations.tileToScreen(c.getLocation());
- if (c == null || !pointOnScreen(screenLoc)) {
- log("Not on screen " + action);
- return false;
- }
- moveMouse(screenLoc);
- screenLoc = Calculations.tileToScreen(c.getLocation());
- if (!getMouseLocation().equals(screenLoc)) {
- return false;
- }
- final List<String> items = getMenuItems();
- if (items.size() <= 1) {
- return false;
- }
- if (items.get(0).toLowerCase().contains(action.toLowerCase())) {
- clickMouse(screenLoc, true);
- return true;
- } else {
- clickMouse(screenLoc, false);
- return atMenu(action);
- }
- } catch (final NullPointerException e) {
- }
- return true;
- }
- public RSInterfaceChild searchInterfacesText(final String string) {
- final RSInterface[] inters = RSInterface.getAllInterfaces();
- for (final RSInterface inter : inters) {
- for (final RSInterfaceChild interfaceChild : inter) {
- if (interfaceChild.getText().toLowerCase().contains(
- string.toLowerCase())) {
- return interfaceChild;
- }
- }
- }
- return null;
- }
- public boolean arrayContains(final int[] arr, final int i) {
- boolean returnt = false;
- for (final int num : arr) {
- if (num == i) {
- returnt = true;
- }
- }
- return returnt;
- }
- public boolean clickAnswer() {
- int[] Answers;
- if ((Answers = returnAnswer()) == null) {
- return false;
- }
- for (int i = 10; i <= 13; i++) {
- if (arrayContains(Answers, nextObjectInterface.getChild(i)
- .getComponentID())) {
- return atInterface(nextObjectInterface.getChild(i));
- }
- }
- return false;
- }
- public boolean getObjects() {
- firstObject = -1;
- secondObject = -1;
- thirdObject = -1;
- firstObject = nextObjectInterface.getChild(6).getComponentID();
- secondObject = nextObjectInterface.getChild(7).getComponentID();
- thirdObject = nextObjectInterface.getChild(8).getComponentID();
- return firstObject != -1 && secondObject != -1 && thirdObject != -1;
- }
- public void guess() {
- final int[] objects = new int[4];
- objects[0] = nextObjectInterface.getChild(10).getComponentID();
- objects[1] = nextObjectInterface.getChild(11).getComponentID();
- objects[2] = nextObjectInterface.getChild(12).getComponentID();
- objects[3] = nextObjectInterface.getChild(13).getComponentID();
- int lowest = 120;
- int click = 10;
- final int compare = returnAnswer()[0];
- if (compare <= 10) {
- atInterface(nextObjectInterface.getChild(random(10, 13)));
- return;
- }
- for (int i = 0; i < objects.length; i++) {
- if (Math.abs(objects[i] - compare) <= lowest) {
- lowest = Math.abs(objects[i] - compare);
- }
- click = 10 + i;
- }
- atInterface(nextObjectInterface.getChild(click));
- }
- public int[] returnAnswer() {
- final int[] count = new int[items.length];
- for (int i = 0; i < count.length; i++) {
- count[i] = 0;
- }
- for (int i = 0; i < items.length; i++) {
- for (int j = 0; j < items[i].length; j++) {
- if (items[i][j] == firstObject) {
- count[i]++;
- }
- if (items[i][j] == secondObject) {
- count[i]++;
- }
- if (items[i][j] == thirdObject) {
- count[i]++;
- }
- if (count[i] >= 2) {
- log.info("Answer Type Found!");
- return items[i];
- }
- }
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment