|
| 1 | +package pb.osrandoms.randoms; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.concurrent.Callable; |
| 5 | + |
| 6 | +import org.powerbot.script.Condition; |
| 7 | +import org.powerbot.script.Filter; |
| 8 | +import org.powerbot.script.Random; |
| 9 | +import org.powerbot.script.rt4.GameObject; |
| 10 | +import org.powerbot.script.rt4.Npc; |
| 11 | +import org.powerbot.script.rt4.Player; |
| 12 | +import org.powerbot.script.rt4.Widget; |
| 13 | + |
| 14 | +import com.logicail.DefinitionCache; |
| 15 | +import com.logicail.wrappers.ObjectDefinition; |
| 16 | + |
| 17 | +import pb.osrandoms.core.OSRandom; |
| 18 | +import pb.osrandoms.core.RandomContext; |
| 19 | + |
| 20 | +public class SurpriseExam extends OSRandom { |
| 21 | + |
| 22 | + private class ObjectRelations { |
| 23 | + private final String text; |
| 24 | + private final int[] items; |
| 25 | + |
| 26 | + private ObjectRelations(final String text, final int[] items) { |
| 27 | + this.text = text; |
| 28 | + this.items = items; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + private static final int WIDGET_NEXT = 103; |
| 33 | + private static final int WIDGET_RELATED = 559; |
| 34 | + private static final int WIDGET_CHAT = 242; |
| 35 | + private static final int WIDGET_CHAT_TEXT = 2; |
| 36 | + |
| 37 | + private static final int[] WIDGET_ITEM_RANGE = {11539, 11540, 11541, 11614, 11615, 11633}; |
| 38 | + private static final int[] WIDGET_ITEM_CULINARY = {11526, 11529, 11545, 11549, 11550, 11555, 11560, 11563, 11564, 11607, 11608, 11616, 11620, 11621, 11622, 11623, 11628, 11629, 11634, 11639, 11641, 11649, 11624}; |
| 39 | + private static final int[] WIDGET_ITEM_FISH = {11527, 11574, 11578, 11580, 11599, 11600, 11601, 11602, 11603, 11604, 11605, 11606, 11625}; |
| 40 | + private static final int[] WIDGET_ITEM_COMBAT = {11528, 11531, 11536, 11537, 11579, 11591, 11592, 11593, 11597, 11627, 11631, 11635, 11636, 11638, 11642, 11648, 11617}; |
| 41 | + private static final int[] WIDGET_ITEM_FARM = {11530, 11532, 11547, 11548, 11554, 11556, 11571, 11581, 11586, 11610, 11645}; |
| 42 | + private static final int[] WIDGET_ITEM_MAGIC = {11533, 11534, 11538, 11562, 11567, 11582}; |
| 43 | + private static final int[] WIDGET_ITEM_FIREMAKING = {11535, 11551, 11552, 11559, 11646}; |
| 44 | + private static final int[] WIDGET_ITEM_HATS = {11540, 11557, 11558, 11560, 11570, 11619, 11626, 11630, 11632, 11637, 11654}; |
| 45 | + private static final int[] WIDGET_ITEM_PIRATE = {11570, 11626, 11558}; |
| 46 | + private static final int[] WIDGET_ITEM_JEWELLERY = {11572, 11576, 11652}; |
| 47 | + private static final int[] WIDGET_ITEM_JEWELLERY_2 = {11572, 11576, 11652}; |
| 48 | + private static final int[] WIDGET_ITEM_DRINKS = {11542, 11543, 11544, 11644, 11647}; |
| 49 | + private static final int[] WIDGET_ITEM_LUMBER = {11573, 11595}; |
| 50 | + private static final int[] WIDGET_ITEM_BOOTS = {11561, 11618, 11650, 11651}; |
| 51 | + private static final int[] WIDGET_ITEM_CRAFT = {11546, 11553, 11565, 11566, 11568, 11569, 11572, 11575, 11576, 11577, 11581, 11583, 11584, 11585, 11643, 11652, 11653}; |
| 52 | + private static final int[] WIDGET_ITEM_MINING = {11587, 11588, 11594, 11596, 11598, 11609, 11610}; |
| 53 | + private static final int[] WIDGET_ITEM_SMITHING = {11611, 11612, 11613, 11553}; |
| 54 | + |
| 55 | + public static final int[][] WIDGET_ITEMS = { |
| 56 | + WIDGET_ITEM_RANGE, WIDGET_ITEM_CULINARY, |
| 57 | + WIDGET_ITEM_FISH, WIDGET_ITEM_COMBAT, |
| 58 | + WIDGET_ITEM_FARM, WIDGET_ITEM_MAGIC, |
| 59 | + WIDGET_ITEM_FIREMAKING, WIDGET_ITEM_HATS, |
| 60 | + WIDGET_ITEM_DRINKS, WIDGET_ITEM_LUMBER, |
| 61 | + WIDGET_ITEM_BOOTS, WIDGET_ITEM_CRAFT, |
| 62 | + WIDGET_ITEM_MINING, WIDGET_ITEM_SMITHING |
| 63 | + }; |
| 64 | + |
| 65 | + private static final String[] COLORS = {"red", "blue", "purple", "green"}; |
| 66 | + private static final int[][] OBJECT_MODELS_DOORS = { { 27078 }, { 27099 }, { 27083 }, { 27076 } }; |
| 67 | + |
| 68 | + private GameObject door = null; |
| 69 | + |
| 70 | + public DefinitionCache<ObjectDefinition> objectLoader; |
| 71 | + |
| 72 | + public final ObjectRelations[] WIDGET_ITEM_RELATIONS = { |
| 73 | + new ObjectRelations("I never leave the house without some sort of jewellery.", WIDGET_ITEM_JEWELLERY), |
| 74 | + new ObjectRelations("There is no better feeling than", WIDGET_ITEM_JEWELLERY_2), |
| 75 | + new ObjectRelations("I'm feeling dehydrated", WIDGET_ITEM_DRINKS), |
| 76 | + new ObjectRelations("All this work is making me thirsty", WIDGET_ITEM_DRINKS), |
| 77 | + new ObjectRelations("quenched my thirst", WIDGET_ITEM_DRINKS), |
| 78 | + new ObjectRelations("light my fire", WIDGET_ITEM_FIREMAKING), |
| 79 | + new ObjectRelations("fishy", WIDGET_ITEM_FISH), |
| 80 | + new ObjectRelations("fishing for answers", WIDGET_ITEM_FISH), |
| 81 | + new ObjectRelations("fish out of water", WIDGET_ITEM_DRINKS), |
| 82 | + new ObjectRelations("strange headgear", WIDGET_ITEM_HATS), |
| 83 | + new ObjectRelations("tip my hat", WIDGET_ITEM_HATS), |
| 84 | + new ObjectRelations("thinking cap", WIDGET_ITEM_HATS), |
| 85 | + new ObjectRelations("wizardry here", WIDGET_ITEM_MAGIC), |
| 86 | + new ObjectRelations("rather mystical", WIDGET_ITEM_MAGIC), |
| 87 | + new ObjectRelations("abracada", WIDGET_ITEM_MAGIC), |
| 88 | + new ObjectRelations("hide one's face", WIDGET_ITEM_HATS), |
| 89 | + new ObjectRelations("shall unmask", WIDGET_ITEM_HATS), |
| 90 | + new ObjectRelations("hand-to-hand", WIDGET_ITEM_COMBAT), |
| 91 | + new ObjectRelations("melee weapon", WIDGET_ITEM_COMBAT), |
| 92 | + new ObjectRelations("prefers melee", WIDGET_ITEM_COMBAT), |
| 93 | + new ObjectRelations("me hearties", WIDGET_ITEM_PIRATE), |
| 94 | + new ObjectRelations("puzzle for landlubbers", WIDGET_ITEM_PIRATE), |
| 95 | + new ObjectRelations("mighty pirate", WIDGET_ITEM_PIRATE), |
| 96 | + new ObjectRelations("mighty archer", WIDGET_ITEM_RANGE), |
| 97 | + new ObjectRelations("as an arrow", WIDGET_ITEM_RANGE), |
| 98 | + new ObjectRelations("Ranged attack", WIDGET_ITEM_RANGE), |
| 99 | + new ObjectRelations("shiny things", WIDGET_ITEM_CRAFT), |
| 100 | + new ObjectRelations("igniting", WIDGET_ITEM_FIREMAKING), |
| 101 | + new ObjectRelations("sparks from my synapses.", WIDGET_ITEM_FIREMAKING), |
| 102 | + new ObjectRelations("fire.", WIDGET_ITEM_FIREMAKING), |
| 103 | + new ObjectRelations("disguised", WIDGET_ITEM_HATS), |
| 104 | + new ObjectRelations("range", WIDGET_ITEM_RANGE), |
| 105 | + new ObjectRelations("arrow", WIDGET_ITEM_RANGE), |
| 106 | + new ObjectRelations("drink", WIDGET_ITEM_DRINKS), |
| 107 | + new ObjectRelations("logs", WIDGET_ITEM_FIREMAKING), |
| 108 | + new ObjectRelations("light", WIDGET_ITEM_FIREMAKING), |
| 109 | + new ObjectRelations("headgear", WIDGET_ITEM_HATS), |
| 110 | + new ObjectRelations("hat", WIDGET_ITEM_HATS), |
| 111 | + new ObjectRelations("cap", WIDGET_ITEM_HATS), |
| 112 | + new ObjectRelations("mine", WIDGET_ITEM_MINING), |
| 113 | + new ObjectRelations("mining", WIDGET_ITEM_MINING), |
| 114 | + new ObjectRelations("ore", WIDGET_ITEM_MINING), |
| 115 | + new ObjectRelations("fish", WIDGET_ITEM_FISH), |
| 116 | + new ObjectRelations("fishing", WIDGET_ITEM_FISH), |
| 117 | + new ObjectRelations("thinking cap", WIDGET_ITEM_HATS), |
| 118 | + new ObjectRelations("cooking", WIDGET_ITEM_CULINARY), |
| 119 | + new ObjectRelations("cook", WIDGET_ITEM_CULINARY), |
| 120 | + new ObjectRelations("bake", WIDGET_ITEM_CULINARY), |
| 121 | + new ObjectRelations("farm", WIDGET_ITEM_FARM), |
| 122 | + new ObjectRelations("farming", WIDGET_ITEM_FARM), |
| 123 | + new ObjectRelations("cast", WIDGET_ITEM_MAGIC), |
| 124 | + new ObjectRelations("magic", WIDGET_ITEM_MAGIC), |
| 125 | + new ObjectRelations("craft", WIDGET_ITEM_CRAFT), |
| 126 | + new ObjectRelations("boot", WIDGET_ITEM_BOOTS), |
| 127 | + new ObjectRelations("chop", WIDGET_ITEM_LUMBER), |
| 128 | + new ObjectRelations("cut", WIDGET_ITEM_LUMBER), |
| 129 | + new ObjectRelations("tree", WIDGET_ITEM_LUMBER) |
| 130 | + }; |
| 131 | + |
| 132 | + public SurpriseExam(RandomContext ctx) { |
| 133 | + super(ctx); |
| 134 | + this.objectLoader = ctx.definitions.getLoader(ObjectDefinition.class); |
| 135 | + } |
| 136 | + |
| 137 | + private int[] getItemArray(final int item) { |
| 138 | + for (final int[] items : SurpriseExam.WIDGET_ITEMS) { |
| 139 | + Arrays.sort(items); |
| 140 | + if (Arrays.binarySearch(items, item) >= 0) { |
| 141 | + return items; |
| 142 | + } |
| 143 | + } |
| 144 | + return null; |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public void run() { |
| 149 | + final Player local = ctx.players.local(); |
| 150 | + if (local.inMotion() || local.animation() != -1) { |
| 151 | + Condition.sleep(Random.getDelay()); |
| 152 | + return; |
| 153 | + } |
| 154 | + if (ctx.widgets.widget(WIDGET_CHAT).component(WIDGET_CHAT_TEXT).valid()) { |
| 155 | + final String text = ctx.widgets.widget(WIDGET_CHAT).component(WIDGET_CHAT_TEXT).text().toLowerCase(); |
| 156 | + for (int i = 0; i < COLORS.length; i++) { |
| 157 | + if (text.contains(COLORS[i])) { |
| 158 | + final int[] models = OBJECT_MODELS_DOORS[i]; |
| 159 | + door = ctx.objects.select().name("door").select(new Filter<GameObject>() { |
| 160 | + |
| 161 | + @Override |
| 162 | + public boolean accept(GameObject arg0) { |
| 163 | + final ObjectDefinition def = objectLoader.get(arg0.id()); |
| 164 | + return def != null && Arrays.equals(def.modelIds, models); |
| 165 | + } |
| 166 | + |
| 167 | + }).poll(); |
| 168 | + break; |
| 169 | + } |
| 170 | + } |
| 171 | + if (door != null && door.valid()) { |
| 172 | + if (!door.inViewport()) { |
| 173 | + ctx.movement.step(door); |
| 174 | + for (int i = 0; i < 200; i++) |
| 175 | + if (ctx.players.local().inMotion())i=0; |
| 176 | + Condition.sleep(150); |
| 177 | + } |
| 178 | + ctx.camera.turnTo(door); |
| 179 | + } |
| 180 | + if (door.inViewport() && door.interact("Open")) { |
| 181 | + Condition.wait(new Callable<Boolean>() { |
| 182 | + |
| 183 | + @Override |
| 184 | + public Boolean call() throws Exception { |
| 185 | + return !valid(); |
| 186 | + } |
| 187 | + |
| 188 | + }); |
| 189 | + } |
| 190 | + return; |
| 191 | + } |
| 192 | + if (ctx.randomMethods.clickContinue()) { |
| 193 | + status("Following conversation"); |
| 194 | + Condition.sleep(Random.nextInt(1200, 1800)); |
| 195 | + return; |
| 196 | + } |
| 197 | + final Widget next = ctx.widgets.widget(WIDGET_NEXT); |
| 198 | + if (next.component(8).valid()) { |
| 199 | + status("WIDGET_VALIDATED: Next item"); |
| 200 | + final int item_1 = next.component(8).modelId(); |
| 201 | + final int item_2 = next.component(9).modelId(); |
| 202 | + final int item_3 = next.component(10).modelId(); |
| 203 | + status("Items: " + item_1 + ", " + item_2 + ", " + item_3); |
| 204 | + final int[] item_arr_1 = getItemArray(item_1); |
| 205 | + final int[] item_arr_2 = getItemArray(item_2); |
| 206 | + final int[] item_arr_3 = getItemArray(item_3); |
| 207 | + final int[] item_arr; |
| 208 | + final int[] item_arr_o; |
| 209 | + if (Arrays.equals(item_arr_2, item_arr_3)) { |
| 210 | + item_arr = item_arr_2; |
| 211 | + item_arr_o = item_arr_1; |
| 212 | + } else { |
| 213 | + item_arr = item_arr_1; |
| 214 | + if (Arrays.equals(item_arr_1, item_arr_2)) { |
| 215 | + item_arr_o = item_arr_3; |
| 216 | + } else { |
| 217 | + item_arr_o = item_arr_2; |
| 218 | + } |
| 219 | + } |
| 220 | + status("Matched 1: " + Arrays.toString(item_arr_1)); |
| 221 | + status("Matched 2: " + Arrays.toString(item_arr_2)); |
| 222 | + status("Matched 3: " + Arrays.toString(item_arr_3)); |
| 223 | + if (item_arr_1 != null && item_arr_2 != null && item_arr_3 != null) { |
| 224 | + final int[] choices = { |
| 225 | + next.component(12).modelId(), |
| 226 | + next.component(13).modelId(), |
| 227 | + next.component(14).modelId(), |
| 228 | + next.component(15).modelId() |
| 229 | + }; |
| 230 | + status("Possible choices: " + Arrays.toString(choices)); |
| 231 | + int index = 12; |
| 232 | + for (final int choice : choices) { |
| 233 | + Arrays.sort(item_arr); |
| 234 | + if (Arrays.binarySearch(item_arr, choice) >= 0) { |
| 235 | + status("Found choice at index " + index + "."); |
| 236 | + next.component(index).click(); |
| 237 | + Condition.sleep(Random.nextInt(1500, 2000)); |
| 238 | + return; |
| 239 | + } |
| 240 | + ++index; |
| 241 | + } |
| 242 | + index = 12; |
| 243 | + status("Unknown, making an educated guess."); |
| 244 | + for (final int choice : choices) { |
| 245 | + Arrays.sort(item_arr_o); |
| 246 | + if (Arrays.binarySearch(item_arr_o, choice) >= 0) { |
| 247 | + status("Found choice at index " + index + "."); |
| 248 | + next.component(index).click(); |
| 249 | + Condition.sleep(Random.nextInt(1500, 2000)); |
| 250 | + return; |
| 251 | + } |
| 252 | + ++index; |
| 253 | + } |
| 254 | + status("Just going to guess..."); |
| 255 | + final int randomIndex = Random.nextInt(12, 16); |
| 256 | + next.component(randomIndex).click(); |
| 257 | + Condition.sleep(Random.nextInt(1500, 2000)); |
| 258 | + } |
| 259 | + return; |
| 260 | + } |
| 261 | + final Widget related = ctx.widgets.widget(WIDGET_RELATED); |
| 262 | + if (related.component(72).valid()) { |
| 263 | + status("WIDGET_VALIDATED: Related items"); |
| 264 | + final String text = related.component(72).text(); |
| 265 | + status("HINT: " + text); |
| 266 | + for (final ObjectRelations question : WIDGET_ITEM_RELATIONS) { |
| 267 | + if (text.toLowerCase().contains(question.text.toLowerCase())) { |
| 268 | + status("Relation validated: " + question.text); |
| 269 | + status("Searching children"); |
| 270 | + for (int childIndex = 24; childIndex <= 38; childIndex++) { |
| 271 | + status("[" + childIndex + "] Searching for " + related.component(childIndex).modelId() + " in " + Arrays.toString(question.items) + "."); |
| 272 | + Arrays.sort(question.items); |
| 273 | + if (Arrays.binarySearch(question.items, related.component(childIndex).modelId()) >= 0) { |
| 274 | + status("Found relation for this index (" + childIndex + "), selecting."); |
| 275 | + related.component(childIndex).click(); |
| 276 | + Condition.sleep(Random.nextInt(1200, 2000)); |
| 277 | + } |
| 278 | + } |
| 279 | + break; |
| 280 | + } |
| 281 | + } |
| 282 | + Condition.sleep(Random.nextInt(1200, 2000)); |
| 283 | + status("Confirming attempt"); |
| 284 | + if (related.component(70).click()) { |
| 285 | + Condition.sleep(Random.nextInt(1200, 2000)); |
| 286 | + } |
| 287 | + return; |
| 288 | + } |
| 289 | + status("Unknown position - talking"); |
| 290 | + final Npc dude = ctx.npcs.select().name("Mr. Mordaut").poll(); |
| 291 | + if (!dude.inViewport()) { |
| 292 | + ctx.camera.turnTo(dude); |
| 293 | + if (!dude.inViewport()) { |
| 294 | + ctx.movement.step(dude); |
| 295 | + Condition.sleep(1500); |
| 296 | + ctx.camera.turnTo(dude); |
| 297 | + } |
| 298 | + } |
| 299 | + if (dude.inViewport() && dude.interact("Talk-to")) { |
| 300 | + Condition.wait(new Callable<Boolean>() { |
| 301 | + |
| 302 | + @Override |
| 303 | + public Boolean call() throws Exception { |
| 304 | + return ctx.randomMethods.queryContinue(); |
| 305 | + } |
| 306 | + |
| 307 | + }); |
| 308 | + } |
| 309 | + } |
| 310 | + |
| 311 | + @Override |
| 312 | + public boolean valid() { |
| 313 | + if (!ctx.npcs.select().name("Mr. Mordaut").within(15).isEmpty()) { |
| 314 | + return true; |
| 315 | + } else { |
| 316 | + door = null; |
| 317 | + return false; |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | +} |
0 commit comments