mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
Proper RandomHandler implementation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user