package org.vinsert.script.randevent.impl; import java.util.ArrayList; import org.vinsert.script.ScriptManifest; import org.vinsert.script.api.Npc; import org.vinsert.script.randevent.RandomEvent; import org.vinsert.util.Utils; @ScriptManifest(name = "Exam", description = "Solve the exam random event", authors = {"tommo", "tholomew"}) public class Exam extends RandomEvent { //STILL NEEDS A LITTLE WORK /** * The 'What comes next' interface id */ private static final int WHAT_NEXT_INTERFACE_ID = 103; //the preset pattern child ids private static final int[] WHAT_NEXT_PRESET = new int[]{8, 9, 10}; //the pattern option child ids private static final int[] WHAT_NEXT_OPTIONS = new int[]{12, 13, 14, 15}; /** * The riddle/pattern interface id */ private static final int PATTERN_INTERFACE_ID = 559; //the description of the riddle private static final int PATTERN_DESCRIPTION_ID = 72; //the thumb up button private static final int PATTERN_ACCEPT_ID = 70; //the child ids for the options private static final int[] PATTERN_OPTION_IDS = new int[]{24, 25, 26, 27, 28, 29, 30, 31, 32, 32, 34, 35, 36, 37, 38}; private static final int EXAMINER_NPC_ID = 6117; private static final int PURPLE_CIRCLE_DOOR_ID = 2192; private static final int BLUE_MAYBE_CYAN_STAR_DOOR_ID = 2189; private static final int RED_CROSS_DOOR_ID = 2188; private static final int GREEN_SQUARE_DOOR_ID = 2193; private int completed = 0; //-------HOW IT WORKS----- //npcid: 6117 = mordaut, dragon in exam room //click continue, again, again, again //do puzzle //continue, continue //do puzzle //continue, continue //do puzzle //continue //parse the text: "To exit, use the #color# door in the #direction# of the school room." //continue @Override public boolean init() { Npc npc = npcs.getNearest(EXAMINER_NPC_ID); if (npc != null) { return true; } return false; } @Override public int pulse() { if (widgets.get(WHAT_NEXT_INTERFACE_ID) != null) { int[] preset = new int[]{widgets.get(WHAT_NEXT_INTERFACE_ID, 8).getModelId(), widgets.get(WHAT_NEXT_INTERFACE_ID, 9).getModelId(), widgets.get(WHAT_NEXT_INTERFACE_ID, 10).getModelId()}; ArrayList possibleAnswers = WhatComesNext.getPossibleAnswers(preset); if (possibleAnswers.size() > 0) { for (int a : WHAT_NEXT_OPTIONS) { for (int id : possibleAnswers) { if (widgets.get(WHAT_NEXT_INTERFACE_ID, a).getModelId() == id) { widgets.get(WHAT_NEXT_INTERFACE_ID, a).click(); Utils.sleep(1000, 1500); return 150; //get the fuck out } } } } else { //could not find any possible answers, guess? } } else if (widgets.get(PATTERN_INTERFACE_ID) != null) { String riddle = widgets.get(PATTERN_INTERFACE_ID, PATTERN_DESCRIPTION_ID).getText(); PatternEntry pe = PatternEntry.getPattern(riddle); if (pe != null) { int count = 0; for (int wid : PATTERN_OPTION_IDS) { for (int id : pe.ids) { if (widgets.get(PATTERN_INTERFACE_ID, wid).getModelId() == id) { widgets.get(PATTERN_INTERFACE_ID, wid).click(); count++; Utils.sleep(700, 900); } } } if (count == 3) { widgets.get(PATTERN_INTERFACE_ID, PATTERN_ACCEPT_ID).click(); } } } //CHECK IF YOU SUCCESSFULLY COMPLETED THE PUZZLE //completed++; //check for exit text, "go through this door" if (widgets.canContinue()) { //collect all data from continue widgets before this widgets.clickContinue(); Utils.sleep(1000, 1500); } if (npcs.getNearest(EXAMINER_NPC_ID) == null) { requestExit(); Utils.sleep(1000, 1500); } log("Random event solver not finished!"); return 1500; } @Override public void close() { } @Override public RandomEventPriority priority() { return RandomEventPriority.MEDIUM; } public enum PatternEntry { HANDTOHAND("hand-to-hand", new int[]{11597, 11528, 11591}), QUENCHED("quenched", new int[]{11542, 11543, 11647}), MELEE("melee", new int[]{11597, 11591, 11528}), SPARKS("sparks", new int[]{11559, 11551, 11552}); public String description; public int[] ids; PatternEntry(String description, int[] ids) { this.description = description; this.ids = ids; } public static PatternEntry getPattern(String desc) { for (PatternEntry pe : PatternEntry.values()) { if (desc.contains(pe.description)) { return pe; } } return null; } } public enum WhatComesNext { /* * store any unique modelid in a WhatComesNext object that has some * relation to the other ids does not have to be 4 */ MINING(new int[]{11596, 11588, 11553, 11612, 11648}), FARMING(new int[]{11554}), HERBLORE(new int[]{11653}), SHEILDS(new int[]{11537, 11635, 11636, 11638}), BOOTS(new int[]{11650}), BONESPRAYER(new int[]{11617}), DRINKS(new int[]{11542, 11543, 11644, 11544}), HATS(new int[]{11557, 11632, 11558, 11559}), COOKING(new int[]{11560, 11555, 11620, 11616}), ARCHERY(new int[]{11539, 11615, 11633, 11541}); public final int[] ids; WhatComesNext(int[] ids) { this.ids = ids; } public int[] getIds() { return ids; } /* * returns all possible answers with respect to the 'preset' pattern * will only return IDs if it finds 3 matches */ public static ArrayList getPossibleAnswers(int[] pattern) { ArrayList possibleAnswers = new ArrayList(); int found, notFound; for (WhatComesNext wcn : WhatComesNext.values()) { if (wcn.getIds().length > pattern.length) { found = 0; for (int wId : wcn.getIds()) { notFound = 0; for (int pId : pattern) { if (wId == pId) { notFound = 0; found++; break; } else { notFound++; if (notFound > 2) { possibleAnswers.add(wId); } } } } if (found > 2) { return possibleAnswers; } else { possibleAnswers.clear(); } } } return possibleAnswers; } } }