Created
April 9, 2012 00:21
-
-
Save CalebWhiting/68b64a6bc022801492ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.powerbot.concurrent.Task; | |
import org.powerbot.concurrent.strategy.Condition; | |
import org.powerbot.game.api.methods.Widgets; | |
import org.powerbot.game.api.util.Random; | |
import org.powerbot.game.api.util.Time; | |
import org.powerbot.game.api.util.Timer; | |
import org.powerbot.game.api.wrappers.widget.WidgetChild; | |
public class PIN implements Task, Condition { | |
private static final int WIDGET = 13; | |
private static final int[] CHILD_STAGE = {1, 2, 3, 4}; | |
private static final int[] CHILD_BUTTONS = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; | |
private static String pin = null; | |
public void setPin(final String to) { | |
pin = to; | |
} | |
@Override public boolean validate() { | |
return pin != null && isValid(); | |
} | |
@Override public void run() { | |
final int stage = getStage(); | |
final WidgetChild child = Widgets.get(WIDGET, CHILD_BUTTONS[toArray(pin)[stage]]); | |
if(child.validate()) { | |
child.click(true); | |
final Timer timer = new Timer(Random.nextInt(4000, 5000)); | |
while(timer.isRunning() && stage == getStage()) { | |
Time.sleep(Random.nextInt(1000, 2000)); | |
} | |
} | |
} | |
public boolean isValid() { | |
return Widgets.get(WIDGET).validate(); | |
} | |
public int getStage() { | |
int stage = 0; | |
for(final int CHILD_ID : CHILD_STAGE) { | |
final WidgetChild child = Widgets.get(WIDGET, CHILD_ID); | |
if(child.validate() && !child.getText().contains("?")) { | |
stage++; | |
} | |
} | |
return stage; | |
} | |
public int[] toArray(final String PIN) { | |
int[] array = new int[4]; | |
int index = 0; | |
for(final char c : PIN.toCharArray()) { | |
array[index] = Integer.parseInt(Character.toString(c)); | |
index++; | |
} | |
return array; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment