Add support for non-stackable items
This commit is contained in:
parent
75ab1e7fe8
commit
4f764a4eb9
@ -1,9 +1,6 @@
|
|||||||
package io.reisub.dreambot.cshopper;
|
package io.reisub.dreambot.cshopper;
|
||||||
|
|
||||||
import io.reisub.dreambot.cshopper.tasks.Buy;
|
import io.reisub.dreambot.cshopper.tasks.*;
|
||||||
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.util.CTaskScript;
|
import io.reisub.dreambot.util.CTaskScript;
|
||||||
import io.reisub.dreambot.util.Constants;
|
import io.reisub.dreambot.util.Constants;
|
||||||
import io.reisub.dreambot.util.tasks.Run;
|
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)
|
@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 {
|
public class CShopper extends CTaskScript {
|
||||||
private static final Configuration configuration = new Configuration(
|
private static final Configuration configuration = new Configuration(
|
||||||
Constants.LUNDAIL,
|
"Ordan",
|
||||||
new ItemWrapper(Constants.COSMIC_RUNE, -1),
|
new ItemWrapper("Gold ore", 2600, 73, false)
|
||||||
new ItemWrapper(Constants.NATURE_RUNE, 6000)
|
//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;
|
private Buy buyTask;
|
||||||
@ -36,6 +38,7 @@ public class CShopper extends CTaskScript {
|
|||||||
buyTask = new Buy();
|
buyTask = new Buy();
|
||||||
|
|
||||||
addNodes(
|
addNodes(
|
||||||
|
new Deposit(),
|
||||||
new Stop(),
|
new Stop(),
|
||||||
new Run(),
|
new Run(),
|
||||||
new Open(),
|
new Open(),
|
||||||
|
@ -3,15 +3,25 @@ package io.reisub.dreambot.cshopper;
|
|||||||
public class ItemWrapper {
|
public class ItemWrapper {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int buyTotal, minimumInShop;
|
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.name = name;
|
||||||
this.buyTotal = buyTotal;
|
this.buyTotal = buyTotal;
|
||||||
this.minimumInShop = minimumInShop;
|
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) {
|
public ItemWrapper(String name, int buyTotal) {
|
||||||
this(name, buyTotal, 0);
|
this(name, buyTotal, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -25,4 +35,8 @@ public class ItemWrapper {
|
|||||||
public int getMinimumInShop() {
|
public int getMinimumInShop() {
|
||||||
return minimumInShop;
|
return minimumInShop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStackable() {
|
||||||
|
return stackable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class Buy extends TaskNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
if (!Shop.isOpen()) return false;
|
if (!Shop.isOpen() || Inventory.isFull() || Hop.shouldHop) return false;
|
||||||
|
|
||||||
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
||||||
int shopCount = Shop.get(iw.getName()).getAmount();
|
int shopCount = Shop.get(iw.getName()).getAmount();
|
||||||
@ -54,7 +54,7 @@ public class Buy extends TaskNode {
|
|||||||
int toBuy = buyTotal - inventoryCount;
|
int toBuy = buyTotal - inventoryCount;
|
||||||
int canBuy = iw.getMinimumInShop() == 0 ? 50 : shopCount - iw.getMinimumInShop();
|
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");
|
shopItem.interact("Buy 50");
|
||||||
} else if (toBuy >= 10 && canBuy >= 10) {
|
} else if (toBuy >= 10 && canBuy >= 10) {
|
||||||
shopItem.interact("Buy 10");
|
shopItem.interact("Buy 10");
|
||||||
|
45
CShopper/src/io/reisub/dreambot/cshopper/tasks/Deposit.java
Normal file
45
CShopper/src/io/reisub/dreambot/cshopper/tasks/Deposit.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ import java.util.List;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public class Hop extends TaskNode {
|
public class Hop extends TaskNode {
|
||||||
|
public static boolean shouldHop;
|
||||||
private final Queue<World> worlds;
|
private final Queue<World> worlds;
|
||||||
|
|
||||||
public Hop(boolean members) {
|
public Hop(boolean members) {
|
||||||
@ -42,6 +43,8 @@ public class Hop extends TaskNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
|
if (Hop.shouldHop) return true;
|
||||||
|
|
||||||
if (!Shop.isOpen()) return false;
|
if (!Shop.isOpen()) return false;
|
||||||
|
|
||||||
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
||||||
@ -60,6 +63,7 @@ public class Hop extends TaskNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int execute() {
|
public int execute() {
|
||||||
|
shouldHop = false;
|
||||||
Shop.close();
|
Shop.close();
|
||||||
MethodProvider.sleepUntil(() -> !Shop.isOpen(), Calculations.random(2000, 2500));
|
MethodProvider.sleepUntil(() -> !Shop.isOpen(), Calculations.random(2000, 2500));
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import io.reisub.dreambot.cshopper.CShopper;
|
|||||||
import io.reisub.dreambot.util.Constants;
|
import io.reisub.dreambot.util.Constants;
|
||||||
import org.dreambot.api.methods.Calculations;
|
import org.dreambot.api.methods.Calculations;
|
||||||
import org.dreambot.api.methods.MethodContext;
|
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.container.impl.Shop;
|
||||||
import org.dreambot.api.methods.interactive.NPCs;
|
import org.dreambot.api.methods.interactive.NPCs;
|
||||||
import org.dreambot.api.script.TaskNode;
|
import org.dreambot.api.script.TaskNode;
|
||||||
@ -12,7 +13,9 @@ import org.dreambot.api.wrappers.interactive.NPC;
|
|||||||
public class Open extends TaskNode {
|
public class Open extends TaskNode {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return !Shop.isOpen();
|
return !Shop.isOpen()
|
||||||
|
&& !Inventory.isFull()
|
||||||
|
&& !Hop.shouldHop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user