Skip to content

Instantly share code, notes, and snippets.

@JeroenMerks
Created June 5, 2011 15:35
Show Gist options
  • Save JeroenMerks/1009057 to your computer and use it in GitHub Desktop.
Save JeroenMerks/1009057 to your computer and use it in GitHub Desktop.
//Version with no walking involved
private boolean sleepWhile(final Condition condition, final int Threshold) {
final int Irritations = Threshold / 25;
for (int i = 0; i < Irritations && condition.isTrue(); i++) {
if (game.getClientState() != 11) {
i = 0;
}
Methods.sleep(Methods.random(20, 30));
}
return condition.isTrue();
}
//RSNPC version
private boolean sleepWhile(final Condition condition,
final RSNPC targetNPC, final int Threshold) {
final int Irritations = Threshold / 25;
if (!players.getMyPlayer().isMoving()
&& calc.distanceTo(targetNPC) >= 2) {
final long endTime = System.currentTimeMillis()
+ random(1500, 2000);
while (System.currentTimeMillis() < endTime) {
if (getMyPlayer().isMoving()) {
break;
}
Methods.sleep(Methods.random(20, 30));
}
if (!players.getMyPlayer().isMoving()) {
return false;
}
}
for (int i = 0; i < Irritations && condition.isTrue(); i++) {
if (players.getMyPlayer().isMoving() || game.getClientState() != 11) {
i = 0;
}
Methods.sleep(Methods.random(20, 30));
}
return condition.isTrue();
}
//RSObject version
private boolean sleepWhile(final Condition condition,
final RSObject targetObject, final int Threshold) {
final int Irritations = Threshold / 25;
final int minimalSleepTillMove = 1500;
final int MaximalSleepTillMove = 2000;
if (!players.getMyPlayer().isMoving()
&& Threshold < (minimalSleepTillMove + MaximalSleepTillMove) / 2) {
if (targetObject != null) {
if (calc.distanceTo(targetObject) >= calc
.distanceTo(targetObject) + 1) {
final long endTime = System.currentTimeMillis()
+ random(minimalSleepTillMove, MaximalSleepTillMove);
while (System.currentTimeMillis() < endTime) {
if (getMyPlayer().isMoving()) {
break;
}
Methods.sleep(Methods.random(20, 30));
}
if (!players.getMyPlayer().isMoving()) {
return false;
}
}
} else {
return false;
}
}
for (int i = 0; i < Irritations && condition.isTrue(); i++) {
if (players.getMyPlayer().isMoving() || game.getClientState() != 11) {
i = 0;
}
Methods.sleep(Methods.random(20, 30));
}
return condition.isTrue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment