mirror of
https://github.com/2006-Scape/Parabot-Randoms.git
synced 2026-07-03 00:38:07 +00:00
Merge pull request #13 from Parabot/feature/dreamscape
[FEATURE] Added randoms for Dreamscape
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ env:
|
||||
- secure: UG+b1tEgc8xv9x4r//2OAIK1RrYv6n209KTTFMMwcnAa7DI8HaP8nljRa5/VhDhuKHdlVrYH/tI90v7UVBs0GDVNwK5V17Io0fMm3FUGZekSthTCqqno5wAGa9r6a6mMLtSaSmIFeIKi0+0d2ZwplRuhj/dtEYjjBBj+kK8g4nE=
|
||||
- secure: St/fecUDInFBCRriYqgp2F8PU9/SooorgxD9Mrs+b0EsC7AbtSsQXvdIv2Lp6xzdQ0VSXPcLIhULPOYrmBKnGQ/NjXTIZXxnroyQxxnI6xyEWIZwiHRY/bKRJDRbQTxD9NL32szKiDSwnw7pu6llF4D64UqQvziq4Gm6VohU75M=
|
||||
- secure: bD15GVZWowiknbfLavh8CxSh0GsnF5kT4kZ6ggCuUDGyj0mzqf7dNRnchQIKkCG0WRYyTrFN4pEiygeywWsipEeAVv9Xhx3cuUZmzeQaR5KCWabSwJ8gK6jZd1YhcWmM9vrdPHobZr65MP0y/8mu/Fovgky9dY7KDf4G3SebNrM=
|
||||
- RANDOMS_VERSION=0.1
|
||||
- RANDOMS_VERSION=0.2
|
||||
|
||||
cache:
|
||||
directories:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#! /bin/bash
|
||||
|
||||
sleep 15
|
||||
curl -sS "http://v3.bdn.parabot.org/api/bot/create/random?build_id=$TRAVIS_BUILD_ID&version=$RANDOMS_VERSION" >/dev/null
|
||||
sleep 1
|
||||
curl --data "build_id=$TRAVIS_BUILD_ID&version=$RANDOMS_VERSION" "http://v3.bdn.parabot.org/api/bot/create/randoms"
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.parabot</groupId>
|
||||
<artifactId>randoms</artifactId>
|
||||
<version>0.1</version>
|
||||
<version>0.2</version>
|
||||
|
||||
<properties>
|
||||
<jdk.version>1.7</jdk.version>
|
||||
|
||||
@@ -2,10 +2,7 @@ package org.parabot.randoms;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
import org.parabot.randoms.ikov.LogoutDisabler;
|
||||
import org.parabot.randoms.ikov.PacketFail;
|
||||
import org.parabot.randoms.ikov.Login;
|
||||
import org.parabot.randoms.ikov.QuestionSolver;
|
||||
import org.parabot.randoms.dreamscape.SerialBanAvoider;
|
||||
import org.parabot.randoms.pkhonor.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -17,19 +14,19 @@ public class Core {
|
||||
private ArrayList<Random> randoms = new ArrayList<>();
|
||||
|
||||
public void init(String server) {
|
||||
// PkHonor
|
||||
randoms.add(new Jail());
|
||||
randoms.add(new TriangleSandwich());
|
||||
randoms.add(new SandwichLady());
|
||||
randoms.add(new MysteriousOldMan());
|
||||
randoms.add(new QuestionSolver());
|
||||
randoms.add(new BobsIsland());
|
||||
randoms.add(new LogoutDisabler());
|
||||
randoms.add(new Login());
|
||||
randoms.add(new PacketFail());
|
||||
|
||||
// Dreamscape
|
||||
randoms.add(new SerialBanAvoider());
|
||||
|
||||
org.parabot.core.Core.verbose("Possible randoms:");
|
||||
for (Random random : randoms) {
|
||||
if (random.getServer().toLowerCase().equalsIgnoreCase(server.toLowerCase())) {
|
||||
if (random.getServer().equalsIgnoreCase(server)) {
|
||||
org.parabot.core.Core.verbose("-> " + random.getName());
|
||||
Context.getInstance().getRandomHandler().addRandom(random);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.parabot.randoms.dreamscape;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.reflect.RefClass;
|
||||
import org.parabot.core.reflect.RefField;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class SerialBanAvoider implements Random {
|
||||
|
||||
private static final String serialAddressField = "SERIAL_ADDRESS";
|
||||
private static final String serialAddressValue = "empty_or_unknown";
|
||||
|
||||
private boolean done;
|
||||
|
||||
@Override
|
||||
public boolean activate() {
|
||||
return !done;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
RefClass client = new RefClass(Context.getInstance().getClient());
|
||||
RefField serial = client.getField(serialAddressField);
|
||||
if (serial != null) {
|
||||
serial.set(serialAddressValue);
|
||||
} else {
|
||||
Core.verbose(String.format("Oh oh... Couldn't find field: %s", serialAddressField));
|
||||
}
|
||||
|
||||
done = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Serial ban avoider";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return "dreamscape";
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package org.parabot.randoms.ikov;
|
||||
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.input.Mouse;
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
import org.rev317.min.api.methods.Game;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class Login implements Random {
|
||||
|
||||
private static int timer = 0;
|
||||
|
||||
@Override
|
||||
public boolean activate() {
|
||||
return System.currentTimeMillis() - timer > 0 && !Game.isLoggedIn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
timer = 0;
|
||||
|
||||
// Move and click mouse on the login button
|
||||
Mouse.getInstance().moveMouse(380, 320);
|
||||
Mouse.getInstance().click(380, 320, true);
|
||||
|
||||
Time.sleep(new SleepCondition() {
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return Game.isLoggedIn();
|
||||
}
|
||||
}, 4500);
|
||||
if (Game.isLoggedIn()) {
|
||||
/* Sleep to let the client load their objects and players */
|
||||
Time.sleep(5000);
|
||||
}else{
|
||||
// Move and click mouse on the close button
|
||||
Mouse.getInstance().moveMouse(515, 130);
|
||||
Mouse.getInstance().click(515, 130, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Login";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return "Ikov";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeOut seconds
|
||||
*/
|
||||
public static void setTimer(int timeOut){
|
||||
timer = ((int) System.currentTimeMillis() + (timeOut * 1000));
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.parabot.randoms.ikov;
|
||||
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.input.Keyboard;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
import org.rev317.min.api.methods.Game;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class LogoutDisabler implements Random {
|
||||
|
||||
private final int[] keys = {KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT};
|
||||
private final java.util.Random random = new java.util.Random();
|
||||
|
||||
private long ms = System.currentTimeMillis();
|
||||
|
||||
@Override
|
||||
public boolean activate() {
|
||||
return Game.isLoggedIn() && (System.currentTimeMillis() - ms) / 1000 > random.nextInt((50 - 30) + 1) + 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
int keyCode = keys[random.nextInt(keys.length)];
|
||||
Keyboard.getInstance().pressKey(keyCode);
|
||||
Time.sleep(random.nextInt((20 - 5) + 1) + 5);
|
||||
Keyboard.getInstance().releaseKey(keyCode);
|
||||
|
||||
ms = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Logout disabler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return "Ikov";
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package org.parabot.randoms.ikov;
|
||||
|
||||
import org.parabot.core.ui.Logger;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
import org.rev317.min.api.events.MessageEvent;
|
||||
import org.rev317.min.api.events.listeners.MessageListener;
|
||||
import org.rev317.min.api.methods.Game;
|
||||
import org.rev317.min.script.ScriptEngine;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class PacketFail implements Random, MessageListener {
|
||||
|
||||
private int fails = 0;
|
||||
private long lastFail = 0;
|
||||
|
||||
public PacketFail(){
|
||||
ScriptEngine.getInstance().addMessageListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate() {
|
||||
if (fails >= 3 && System.currentTimeMillis() - lastFail <= 25 * 1000){
|
||||
return true;
|
||||
}else if (System.currentTimeMillis() - lastFail > 25 * 1000){
|
||||
lastFail = 0;
|
||||
fails = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
// if (!Game.dropClient()){
|
||||
Logger.addMessage("Couldn't drop the client, please restart if required", true);
|
||||
// }
|
||||
fails = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Client restarter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return "Ikov";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(MessageEvent messageEvent) {
|
||||
if (messageEvent.getType() == 0){
|
||||
String message = messageEvent.getMessage().toLowerCase();
|
||||
switch (message){
|
||||
case "unable to receive input":
|
||||
case "command does not exist":
|
||||
case "too far away from this object":
|
||||
case "that object does not exist":
|
||||
case "party room is currently disabled":
|
||||
fails++;
|
||||
lastFail = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package org.parabot.randoms.ikov;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.ui.Logger;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.input.Keyboard;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
import org.rev317.min.Loader;
|
||||
import org.rev317.min.api.methods.Game;
|
||||
import org.rev317.min.api.methods.Menu;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class QuestionSolver implements Random {
|
||||
|
||||
private final int backlogID = 368, cacheID = 372;
|
||||
|
||||
@Override
|
||||
public boolean activate() {
|
||||
return Game.isLoggedIn() && Game.getOpenBackDialogId() == backlogID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
String message = Loader.getClient().getInterfaceCache()[cacheID].getMessage();
|
||||
if (!message.contains("lose items on death, beware")) {
|
||||
message = message.replace("@dre@ ", "");
|
||||
|
||||
Logger.addMessage("Contacting server to get an answer", false);
|
||||
String answer = getAnswer(message);
|
||||
|
||||
if (answer == null) {
|
||||
Logger.addMessage("Could not solve the question, please report this question (and the possible answer) on the forums", true);
|
||||
Logger.addMessage("Question: " + message, true);
|
||||
forceRelog();
|
||||
Logger.addMessage("Logged account out for security measures", true);
|
||||
Context.getInstance().getRunningScript().setState(Script.STATE_STOPPED);
|
||||
} else {
|
||||
Logger.addMessage("Answer found, now trying: " + answer, false);
|
||||
Menu.sendAction(679, -1, -1, 373);
|
||||
Time.sleep(1000);
|
||||
Keyboard.getInstance().sendKeys(answer);
|
||||
}
|
||||
}
|
||||
Time.sleep(1000);
|
||||
}
|
||||
|
||||
public String getAnswer(String question){
|
||||
try {
|
||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(WebUtil.getContents("http://bdn.parabot.org/api/v2/data/questions/get",
|
||||
"server=ikov&question=" + URLEncoder.encode(question, "UTF-8")));
|
||||
JSONObject result;
|
||||
if ((result = (JSONObject) object.get("result")) != null){
|
||||
Object answer;
|
||||
if ((answer = result.get("answer")) != null){
|
||||
return (String) answer;
|
||||
}
|
||||
}
|
||||
} catch (ParseException | MalformedURLException | UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}catch (Exception ignored){
|
||||
// Catching for old bots
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void forceRelog() {
|
||||
try {
|
||||
Logger.addMessage("Logging out...", false);
|
||||
Class<?> c = Loader.getClient().getClass();
|
||||
|
||||
Method m = c.getDeclaredMethod("am");
|
||||
m.setAccessible(true);
|
||||
|
||||
m.invoke(Loader.getClient());
|
||||
Time.sleep(new SleepCondition() {
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return !Game.isLoggedIn();
|
||||
}
|
||||
}, 5000);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Login.setTimer(5 * 60);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Question solver";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return "Ikov";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user