From 4f764a4eb9d2c1b41b372cc166c03613ebe99384 Mon Sep 17 00:00:00 2001 From: Yuri Moens Date: Thu, 28 Oct 2021 00:00:11 +0200 Subject: [PATCH] Add support for non-stackable items --- .../io/reisub/dreambot/cshopper/CShopper.java | 17 ++++--- .../reisub/dreambot/cshopper/ItemWrapper.java | 18 +++++++- .../reisub/dreambot/cshopper/tasks/Buy.java | 4 +- .../dreambot/cshopper/tasks/Deposit.java | 45 +++++++++++++++++++ .../reisub/dreambot/cshopper/tasks/Hop.java | 4 ++ .../reisub/dreambot/cshopper/tasks/Open.java | 5 ++- 6 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 CShopper/src/io/reisub/dreambot/cshopper/tasks/Deposit.java diff --git a/CShopper/src/io/reisub/dreambot/cshopper/CShopper.java b/CShopper/src/io/reisub/dreambot/cshopper/CShopper.java index 6ce44e5..49c4a8e 100644 --- a/CShopper/src/io/reisub/dreambot/cshopper/CShopper.java +++ b/CShopper/src/io/reisub/dreambot/cshopper/CShopper.java @@ -1,9 +1,6 @@ package io.reisub.dreambot.cshopper; -import io.reisub.dreambot.cshopper.tasks.Buy; -import io.reisub.dreambot.cshopper.tasks.Hop; -import io.reisub.dreambot.cshopper.tasks.Open; -import io.reisub.dreambot.cshopper.tasks.Stop; +import io.reisub.dreambot.cshopper.tasks.*; import io.reisub.dreambot.util.CTaskScript; import io.reisub.dreambot.util.Constants; import io.reisub.dreambot.util.tasks.Run; @@ -18,9 +15,14 @@ import java.awt.*; @ScriptManifest(category = Category.MISC, name = "CShopper", description = "Shops like a woman with an unlimited Visa card", author = Constants.AUTHOR, version = 1.0) public class CShopper extends CTaskScript { private static final Configuration configuration = new Configuration( - Constants.LUNDAIL, - new ItemWrapper(Constants.COSMIC_RUNE, -1), - new ItemWrapper(Constants.NATURE_RUNE, 6000) + "Ordan", + new ItemWrapper("Gold ore", 2600, 73, false) + //new ItemWrapper("Hammerstone seed", -1), + //new ItemWrapper("Asgarnian seed", -1), + //new ItemWrapper("Jute seed", -1), + //new ItemWrapper("Yanillian seed", -1), + //new ItemWrapper("Krandorian seed", -1), + //new ItemWrapper("Barley seed", 2000) ); private Buy buyTask; @@ -36,6 +38,7 @@ public class CShopper extends CTaskScript { buyTask = new Buy(); addNodes( + new Deposit(), new Stop(), new Run(), new Open(), diff --git a/CShopper/src/io/reisub/dreambot/cshopper/ItemWrapper.java b/CShopper/src/io/reisub/dreambot/cshopper/ItemWrapper.java index 09cefa7..7bd8ded 100644 --- a/CShopper/src/io/reisub/dreambot/cshopper/ItemWrapper.java +++ b/CShopper/src/io/reisub/dreambot/cshopper/ItemWrapper.java @@ -3,15 +3,25 @@ package io.reisub.dreambot.cshopper; public class ItemWrapper { private final String name; private final int buyTotal, minimumInShop; + private final boolean stackable; - public ItemWrapper(String name, int buyTotal, int minimumInShop) { + public ItemWrapper(String name, int buyTotal, int minimumInShop, boolean stackable) { this.name = name; this.buyTotal = buyTotal; this.minimumInShop = minimumInShop; + this.stackable = stackable; + } + + public ItemWrapper(String name, int buyTotal, boolean stackable) { + this(name, buyTotal, 0, stackable); + } + + public ItemWrapper(String name, int buyTotal, int minimumInShop) { + this(name, buyTotal, minimumInShop, false); } public ItemWrapper(String name, int buyTotal) { - this(name, buyTotal, 0); + this(name, buyTotal, 0, false); } public String getName() { @@ -25,4 +35,8 @@ public class ItemWrapper { public int getMinimumInShop() { return minimumInShop; } + + public boolean isStackable() { + return stackable; + } } diff --git a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Buy.java b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Buy.java index 8cf7129..091c2ef 100644 --- a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Buy.java +++ b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Buy.java @@ -21,7 +21,7 @@ public class Buy extends TaskNode { @Override public boolean accept() { - if (!Shop.isOpen()) return false; + if (!Shop.isOpen() || Inventory.isFull() || Hop.shouldHop) return false; for (ItemWrapper iw : CShopper.getConfiguration().getItems()) { int shopCount = Shop.get(iw.getName()).getAmount(); @@ -54,7 +54,7 @@ public class Buy extends TaskNode { int toBuy = buyTotal - inventoryCount; int canBuy = iw.getMinimumInShop() == 0 ? 50 : shopCount - iw.getMinimumInShop(); - if (toBuy >= 50 && canBuy >= 50) { + if ((toBuy >= 50 && canBuy >= 50) || (toBuy >= 27 && canBuy >= 27 && !iw.isStackable())) { shopItem.interact("Buy 50"); } else if (toBuy >= 10 && canBuy >= 10) { shopItem.interact("Buy 10"); diff --git a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Deposit.java b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Deposit.java new file mode 100644 index 0000000..8ed8bfb --- /dev/null +++ b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Deposit.java @@ -0,0 +1,45 @@ +package io.reisub.dreambot.cshopper.tasks; + +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.Shop; +import org.dreambot.api.methods.container.impl.bank.Bank; +import org.dreambot.api.methods.interactive.GameObjects; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.GameObject; + +public class Deposit extends TaskNode { + @Override + public boolean accept() { + return Inventory.isFull(); + } + + @Override + public int execute() { + GameObject bank = GameObjects.closest("Bank chest"); + if (bank == null) return Calculations.random(250, 400); + + if (Shop.isOpen()) { + Shop.close(); + MethodProvider.sleepUntil(() -> !Shop.isOpen(), Calculations.random(2000, 2500)); + } + + bank.interact(); + if (!Util.sleepUntilMoving()) return Calculations.random(250, 400); + + if (!MethodProvider.sleepUntil(Bank::isOpen, Calculations.random(5000, 5500))) return Calculations.random(250, 400); + + MethodProvider.sleep(300, 500); + + Bank.depositAllExcept("Coins"); + MethodProvider.sleepUntil(() -> Inventory.onlyContains("Coins"), Calculations.random(5000, 5500)); + + Bank.close(); + MethodProvider.sleepUntil(() -> !Bank.isOpen(), Calculations.random(2000, 2500)); + Hop.shouldHop = true; + + return Calculations.random(250, 400); + } +} diff --git a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Hop.java b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Hop.java index 08188cc..4a926ed 100644 --- a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Hop.java +++ b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Hop.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Queue; public class Hop extends TaskNode { + public static boolean shouldHop; private final Queue worlds; public Hop(boolean members) { @@ -42,6 +43,8 @@ public class Hop extends TaskNode { @Override public boolean accept() { + if (Hop.shouldHop) return true; + if (!Shop.isOpen()) return false; for (ItemWrapper iw : CShopper.getConfiguration().getItems()) { @@ -60,6 +63,7 @@ public class Hop extends TaskNode { @Override public int execute() { + shouldHop = false; Shop.close(); MethodProvider.sleepUntil(() -> !Shop.isOpen(), Calculations.random(2000, 2500)); diff --git a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Open.java b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Open.java index e7f71b6..5e95fc4 100644 --- a/CShopper/src/io/reisub/dreambot/cshopper/tasks/Open.java +++ b/CShopper/src/io/reisub/dreambot/cshopper/tasks/Open.java @@ -4,6 +4,7 @@ import io.reisub.dreambot.cshopper.CShopper; import io.reisub.dreambot.util.Constants; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.MethodContext; +import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.container.impl.Shop; import org.dreambot.api.methods.interactive.NPCs; import org.dreambot.api.script.TaskNode; @@ -12,7 +13,9 @@ import org.dreambot.api.wrappers.interactive.NPC; public class Open extends TaskNode { @Override public boolean accept() { - return !Shop.isOpen(); + return !Shop.isOpen() + && !Inventory.isFull() + && !Hop.shouldHop; } @Override