diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/kspflip/KSPFlipScript.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/kspflip/KSPFlipScript.java index 57cee41..aa866ae 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/kspflip/KSPFlipScript.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/kspflip/KSPFlipScript.java @@ -6,6 +6,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.ItemID; +import net.runelite.client.plugins.microbot.Microbot; import lombok.extern.slf4j.Slf4j; import net.runelite.api.ItemID; import net.runelite.client.plugins.microbot.Microbot; @@ -44,6 +48,16 @@ public boolean run() Microbot.enableAutoRunOn = true; startTime = Instant.now(); mainScheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> { + + try { + if (!super.run()) { + return; + } + + if (BreakHandlerScript.breakIn > 0 && BreakHandlerScript.breakIn < 60) { + status = "Preparing for break"; + Rs2GrandExchange.closeExchange(); + try { if (!super.run()) @@ -62,10 +76,17 @@ public boolean run() Rs2GrandExchange.closeExchange(); Rs2GrandExchange.close(); + sleep(2000); return; } + if (itemPool.isEmpty() || Rs2Random.betweenInclusive(0, 100) < 5) { + refreshItemPool(); + } + + if (!Rs2Bank.isOpen() && Rs2Inventory.hasItem(ItemID.COINS_995)) { + if (itemPool.isEmpty() || Rs2Random.betweenInclusive(0, 100) < 5) { refreshItemPool(); @@ -73,10 +94,18 @@ public boolean run() if (!Rs2Bank.isOpen() && Rs2Inventory.hasItem(ItemID.COINS_995)) { + flipLoop(); } overlay.updateOverlay(getProfit(), getStatus(), getRuntime()); + + } catch (Exception e) { + log.error("Error in flip loop", e); + status = "Error - retrying"; + } + }, 0, 600, TimeUnit.MILLISECONDS); + } catch (Exception e) { @@ -84,6 +113,7 @@ public boolean run() status = "Error - retrying"; } }, 0, 600, java.util.concurrent.TimeUnit.MILLISECONDS); + return true; } @@ -133,8 +163,10 @@ private void flipLoop() { if (Rs2GrandExchange.getAvailableSlot() == null) + if (!Rs2GrandExchange.hasFreeSlot()) + { break; } @@ -149,6 +181,7 @@ private void flipLoop() } + Rs2Mouse.setSpeed(50, 90); Rs2GrandExchange.buyItem(itemId, quantity, buyPrice); @@ -160,6 +193,7 @@ private void flipLoop() { collectProfit(); + sleepUntil(() -> Rs2GrandExchange.hasOffer(itemId), 3000); lastFlipped.put(itemId, System.currentTimeMillis()); } @@ -169,6 +203,7 @@ private void flipLoop() Rs2GrandExchange.collectToInventory(); calculateProfit(); + } } @@ -185,10 +220,12 @@ private void collectProfit() int coinsAfter = Rs2Inventory.count(ItemID.COINS_995); long profit = coinsAfter - coinsBefore; + private void calculateProfit() { long profit = Rs2GrandExchange.getLastProfit(); + if (profit > 0) { totalProfit += profit;