mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 00:38:16 +00:00
Proper RandomHandler implementation
This commit is contained in:
@@ -9,6 +9,7 @@ import org.parabot.core.ui.components.GamePanel;
|
|||||||
import org.parabot.environment.api.interfaces.Paintable;
|
import org.parabot.environment.api.interfaces.Paintable;
|
||||||
import org.parabot.environment.input.Keyboard;
|
import org.parabot.environment.input.Keyboard;
|
||||||
import org.parabot.environment.input.Mouse;
|
import org.parabot.environment.input.Mouse;
|
||||||
|
import org.parabot.environment.randoms.RandomHandler;
|
||||||
import org.parabot.environment.scripts.Script;
|
import org.parabot.environment.scripts.Script;
|
||||||
import org.parabot.environment.servers.ServerProvider;
|
import org.parabot.environment.servers.ServerProvider;
|
||||||
|
|
||||||
@@ -23,35 +24,35 @@ import java.util.TimerTask;
|
|||||||
* @author Everel
|
* @author Everel
|
||||||
*/
|
*/
|
||||||
public class Context {
|
public class Context {
|
||||||
public static HashMap<ThreadGroup, Context> threadGroups = new HashMap<ThreadGroup, Context>();
|
public static final HashMap<ThreadGroup, Context> threadGroups = new HashMap<ThreadGroup, Context>();
|
||||||
|
private static ArrayList<Paintable> paintables = new ArrayList<Paintable>();
|
||||||
private static int id = 1;
|
private static int id = 1;
|
||||||
|
|
||||||
private ASMClassLoader classLoader = null;
|
public boolean added;
|
||||||
private ClassPath classPath = null;
|
private ASMClassLoader classLoader;
|
||||||
private ServerProvider serverProvider = null;
|
private ClassPath classPath;
|
||||||
private int tab = 0;
|
private ServerProvider serverProvider;
|
||||||
private Applet gameApplet = null;
|
private int tab;
|
||||||
private HookParser hookParser = null;
|
private Applet gameApplet;
|
||||||
private Script runningScript = null;
|
private HookParser hookParser;
|
||||||
|
private Script runningScript;
|
||||||
private Object clientInstance = null;
|
private RandomHandler randomHandler;
|
||||||
|
private Object clientInstance;
|
||||||
private static ArrayList<Paintable> paintables = new ArrayList<Paintable>();
|
private PaintDebugger paintDebugger;
|
||||||
|
private Mouse mouse;
|
||||||
private PaintDebugger paintDebugger = new PaintDebugger();
|
private Keyboard keyboard;
|
||||||
|
|
||||||
public boolean added = false;
|
|
||||||
|
|
||||||
private Mouse mouse = null;
|
|
||||||
private Keyboard keyboard = null;
|
|
||||||
|
|
||||||
public Context(final ServerProvider serverProvider) {
|
public Context(final ServerProvider serverProvider) {
|
||||||
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
||||||
tab = id;
|
|
||||||
this.serverProvider = serverProvider;
|
this.serverProvider = serverProvider;
|
||||||
id++;
|
this.paintDebugger = new PaintDebugger();
|
||||||
this.classPath = new ClassPath();
|
this.classPath = new ClassPath();
|
||||||
classLoader = new ASMClassLoader(classPath);
|
this.classLoader = new ASMClassLoader(classPath);
|
||||||
|
this.randomHandler = new RandomHandler();
|
||||||
|
this.tab = id;
|
||||||
|
|
||||||
|
id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,4 +299,12 @@ public class Context {
|
|||||||
return this.runningScript;
|
return this.runningScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the random handler
|
||||||
|
* @return random handler
|
||||||
|
*/
|
||||||
|
public RandomHandler getRandomHandler() {
|
||||||
|
return this.randomHandler;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package org.parabot.environment.randoms;
|
|
||||||
|
|
||||||
import org.parabot.environment.scripts.Script;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: Jeroen
|
|
||||||
* Date: 18/02/14
|
|
||||||
* Time: 19:37
|
|
||||||
*/
|
|
||||||
public class Handler {
|
|
||||||
|
|
||||||
|
|
||||||
public static class RandomChecker {
|
|
||||||
private ArrayList<Random> randoms;
|
|
||||||
|
|
||||||
public void addRandom(Random random) {
|
|
||||||
randoms.add(random);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAndRun() {
|
|
||||||
Script s = new Script();
|
|
||||||
for(Random r : randoms) {
|
|
||||||
if(r.shouldRun()) {
|
|
||||||
s.setState(1);
|
|
||||||
r.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Random {
|
|
||||||
public boolean shouldRun();
|
|
||||||
public void run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class RandomScript {
|
|
||||||
//private RandomChecker randomChecker = ServerProvider.getRandomChecker();
|
|
||||||
|
|
||||||
public void scriptLoop() {
|
|
||||||
while(true) {
|
|
||||||
// randomChecker.checkAndRun();
|
|
||||||
// framework.loop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.parabot.environment.randoms;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Everel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RandomHandler {
|
||||||
|
private ArrayList<Random> randoms;
|
||||||
|
|
||||||
|
public RandomHandler() {
|
||||||
|
randoms = new ArrayList<Random>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a random to the random list
|
||||||
|
* @param random
|
||||||
|
*/
|
||||||
|
public void addRandom(Random random) {
|
||||||
|
randoms.add(random);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if random occures and runs it
|
||||||
|
* @return returns <b>true</b> if a random has been executed, otherwise <b>false</b>
|
||||||
|
*/
|
||||||
|
public boolean checkAndRun() {
|
||||||
|
for(Random r : randoms) {
|
||||||
|
if(r.activate()) {
|
||||||
|
r.execute();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,19 +20,19 @@ import java.util.Collection;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Script implements Runnable {
|
public class Script implements Runnable {
|
||||||
private Collection<Strategy> strategies = null;
|
|
||||||
private int frameWorkType = 0;
|
|
||||||
private AbstractFramework frameWork = null;
|
|
||||||
|
|
||||||
public static final int TYPE_STRATEGY = 0;
|
public static final int TYPE_STRATEGY = 0;
|
||||||
public static final int TYPE_LOOP = 1;
|
public static final int TYPE_LOOP = 1;
|
||||||
public static final int TYPE_OTHER = 2;
|
public static final int TYPE_OTHER = 2;
|
||||||
|
|
||||||
private int state = 0;
|
|
||||||
public static final int STATE_RUNNING = 0;
|
public static final int STATE_RUNNING = 0;
|
||||||
public static final int STATE_PAUSE = 1;
|
public static final int STATE_PAUSE = 1;
|
||||||
public static final int STATE_STOPPED = 2;
|
public static final int STATE_STOPPED = 2;
|
||||||
|
|
||||||
|
private Collection<Strategy> strategies;
|
||||||
|
private AbstractFramework frameWork;
|
||||||
|
private int state;
|
||||||
|
private int frameWorkType;
|
||||||
|
|
||||||
public boolean onExecute() {
|
public boolean onExecute() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -62,8 +62,10 @@ public class Script implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void run() {
|
public final void run() {
|
||||||
|
Context context = Context.resolve();
|
||||||
|
|
||||||
Core.verbose("Initializing script...");
|
Core.verbose("Initializing script...");
|
||||||
Context.resolve().getServerProvider().initScript(this);
|
context.getServerProvider().initScript(this);
|
||||||
Core.verbose("Done.");
|
Core.verbose("Done.");
|
||||||
|
|
||||||
if(!onExecute()) {
|
if(!onExecute()) {
|
||||||
@@ -75,7 +77,7 @@ public class Script implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Core.verbose("Detecting script framework...");
|
Core.verbose("Detecting script framework...");
|
||||||
Context.resolve().setRunningScript(this);
|
context.setRunningScript(this);
|
||||||
BotToolbar.getInstance().toggleRun();
|
BotToolbar.getInstance().toggleRun();
|
||||||
if(this instanceof LoopTask) {
|
if(this instanceof LoopTask) {
|
||||||
Core.verbose("Script framework detected: LoopTask");
|
Core.verbose("Script framework detected: LoopTask");
|
||||||
@@ -93,6 +95,10 @@ public class Script implements Runnable {
|
|||||||
LogArea.log("Script started.");
|
LogArea.log("Script started.");
|
||||||
try {
|
try {
|
||||||
while(this.state != STATE_STOPPED) {
|
while(this.state != STATE_STOPPED) {
|
||||||
|
if(context.getRandomHandler().checkAndRun()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(this.state == STATE_PAUSE) {
|
if(this.state == STATE_PAUSE) {
|
||||||
sleep(500);
|
sleep(500);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user