Skip to content

Instantly share code, notes, and snippets.

@CalebWhiting
Created May 27, 2012 13:01
Show Gist options
  • Save CalebWhiting/1ccca84c33d8ce1240a1 to your computer and use it in GitHub Desktop.
Save CalebWhiting/1ccca84c33d8ce1240a1 to your computer and use it in GitHub Desktop.
import cspro.com.api.util.paint.swing.UI;
import cspro.com.clues.executables.WidgetCloser.Closable;
import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Condition;
import org.powerbot.concurrent.strategy.Strategy;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.NPCs;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.node.SceneEntities;
import org.powerbot.game.api.methods.widget.Camera;
import org.powerbot.game.api.util.Filter;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.Entity;
import org.powerbot.game.api.wrappers.interactive.NPC;
import org.powerbot.game.api.wrappers.interactive.Player;
import org.powerbot.game.api.wrappers.node.SceneObject;
import static org.powerbot.game.api.util.Time.sleep;
/**
* @author Caleb Date: 21/05/12 Time: 13:24
*/
public class Antiban extends Strategy implements Task {
public static final int[] TIMES = { 15 * 1000, 2 * 60000 };
public static final Timer TIMER = new Timer(Random.nextInt(TIMES[0], TIMES[1]));
public static final Methods[] METHODS = Methods.values();
public void run() {
setReset(false);
final int times = Random.nextBoolean() ? 1 : Random.nextInt(1, 6);
for (int time = 0; time <= times; ) {
final Methods method = METHODS[Random.nextInt(0, METHODS.length)];
final boolean valid = method.condition.validate();
if (valid) {
method.task.run();
sleep(100, 1000);
time += 1;
}
}
TIMER.setEndIn(Random.nextInt(TIMES[0], TIMES[1]));
}
public boolean validate() {
final boolean result = ! TIMER.isRunning();
if(result) {
if(UI.current.chckbxAntiban.isSelected()) {
return true;
} else {
TIMER.reset();
return false;
}
}
return false;
}
public enum Methods {
MOUSE(new Condition() {
public boolean validate() {
return true;
}
}, new Task() {
public void run() {
switch (Random.nextInt(0, 3)) {
case 0:
Mouse.move(Random.nextInt(0, Game.getDimensions().width), Random.nextInt(0, Game.getDimensions().height));
break;
case 1:
Mouse.click(false);
break;
case 2:
Mouse.putSide(Random.nextInt(0, 4));
break;
}
}
}
),
CAMERA(new Condition() {
public boolean validate() {
return true;
}
}, new Task() {
public void run() {
switch (Random.nextInt(0, 4)) {
case 0:
Camera.setAngle(Random.nextInt(0, 360));
break;
case 1:
Camera.setPitch(Random.nextInt(3, 92));
break;
case 2:
new Thread(new Runnable() {
public void run() {
Camera.setAngle(Random.nextInt(0, 360));
}
}).start();
break;
case 3:
new Thread(new Runnable() {
public void run() {
Camera.setPitch(Random.nextInt(3, 92));
}
}).start();
break;
}
}
}
),
INTERACT(new Condition() {
public boolean validate() {
for (final Closable closable : WidgetCloser.widgets) {
if (closable.valid()) {
return false;
}
}
return true;
}
}, new Task() {
public void run() {
Entity[] entities = null;
switch (Random.nextInt(0, 3)) {
case 0:
entities = SceneEntities.getLoaded(new Filter<SceneObject>() {
public boolean accept(final SceneObject sceneObject) {
return sceneObject.isOnScreen() && sceneObject.getType() == SceneEntities.TYPE_INTERACTIVE;
}
});
break;
case 1:
entities = NPCs.getLoaded(new Filter<NPC>() {
public boolean accept(final NPC npc) {
return npc.isOnScreen();
}
});
break;
case 2:
entities = Players.getLoaded(new Filter<Player>() {
public boolean accept(final Player player) {
return !player.equals(Players.getLocal()) && player.isOnScreen();
}
});
break;
}
if (entities != null && entities.length > 0) {
final Entity entity = entities[Random.nextInt(0, entities.length)];
if (entity.validate() && entity.isOnScreen()) {
if (entity instanceof Player) {
entity.click(false);
} else {
switch (Random.nextInt(0, 2)) {
case 0:
entity.click(false);
break;
case 1:
entity.interact("Examine");
break;
}
}
}
}
}
}
);
private Condition condition;
private Task task;
Methods(final Condition condition, final Task task) {
this.condition = condition;
this.task = task;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment