Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,4 @@ private static Widget getSlotChild(GrandExchangeSlots slot, int childIndex)
{
return getWidgetChild(getSlot(slot), childIndex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.IntSupplier;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -587,25 +588,32 @@ private static void confirm() {
* @param quantity the number of items to set for the offer
*/
private static boolean setQuantity(int quantity) {
int tries = 0;
while (quantity != getOfferQuantity()) {
boolean success = retryQuantity(quantity, Rs2GrandExchange::getOfferQuantity, () -> {
Widget quantityButtonX = GrandExchangeWidget.getQuantityButton_X();
if (quantityButtonX == null) { log.warn("Quantity button not found"); tries++; continue; }
if (quantityButtonX == null) {
log.warn("Quantity button not found");
return;
}
Microbot.getMouse().click(quantityButtonX.getBounds());
sleepUntil(() -> Rs2Widget.getWidget(InterfaceID.Chatbox.MES_TEXT2) != null); //GE Enter Price/Quantity
sleep(600, 1000);
setChatboxValue(quantity);
sleep(500, 750);
Rs2Keyboard.enter();
sleep(1000);
tries++;
if (tries > 3) {
log.error("Failed to set quantity after 3 tries, breaking out to avoid infinite loop.");
Rs2GrandExchange.closeExchange();
break;
}
});
if (!success) {
log.error("Failed to set quantity after 3 tries, breaking out to avoid infinite loop.");
Rs2GrandExchange.closeExchange();
}
return success;
}

static boolean retryQuantity(int quantity, IntSupplier currentQuantity, Runnable attempt) {
for (int tries = 0; quantity != currentQuantity.getAsInt() && tries < 3; tries++) {
attempt.run();
}
return tries <= 3;
return quantity == currentQuantity.getAsInt();
}

/**
Expand Down