Finish CShopper
This commit is contained in:
parent
7a12e2d60a
commit
a9ef578e50
@ -1,24 +1,59 @@
|
|||||||
package io.reisub.dreambot.cshopper;
|
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.util.CTaskScript;
|
||||||
import io.reisub.dreambot.util.Constants;
|
import io.reisub.dreambot.util.Constants;
|
||||||
|
import org.dreambot.api.methods.container.impl.Inventory;
|
||||||
import org.dreambot.api.script.Category;
|
import org.dreambot.api.script.Category;
|
||||||
import org.dreambot.api.script.ScriptManifest;
|
import org.dreambot.api.script.ScriptManifest;
|
||||||
import org.dreambot.api.script.impl.TaskScript;
|
import org.dreambot.api.script.impl.TaskScript;
|
||||||
|
import org.dreambot.api.wrappers.items.Item;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@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 TaskScript {
|
public class CShopper extends CTaskScript {
|
||||||
private static final Configuration configuration = new Configuration(
|
private static final Configuration configuration = new Configuration(
|
||||||
Constants.LUNDAIL,
|
Constants.LUNDAIL,
|
||||||
new ItemWrapper(Constants.NATURE_RUNE, 6000),
|
new ItemWrapper(Constants.COSMIC_RUNE, -1),
|
||||||
new ItemWrapper(Constants.COSMIC_RUNE, -1)
|
new ItemWrapper(Constants.NATURE_RUNE, 6000)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private Buy buyTask;
|
||||||
|
|
||||||
public static Configuration getConfiguration() {
|
public static Configuration getConfiguration() {
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
|
getUI().setCustomLines(configuration.getItems().length);
|
||||||
|
|
||||||
|
buyTask = new Buy();
|
||||||
|
|
||||||
|
addNodes(
|
||||||
|
new Open(),
|
||||||
|
buyTask,
|
||||||
|
new Hop(),
|
||||||
|
new Stop()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPaint(Graphics g) {
|
||||||
|
super.onPaint(g);
|
||||||
|
|
||||||
|
if (buyTask == null) return;
|
||||||
|
|
||||||
|
for (ItemWrapper iw : configuration.getItems()) {
|
||||||
|
String name = iw.getName();
|
||||||
|
Item item = Inventory.get(iw.getName());
|
||||||
|
int current = item == null ? 0 : item.getAmount();
|
||||||
|
getUI().drawString("Bought " + buyTask.getBought(name) + " " + name + " (" + current + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,23 @@ package io.reisub.dreambot.cshopper.tasks;
|
|||||||
|
|
||||||
import io.reisub.dreambot.cshopper.CShopper;
|
import io.reisub.dreambot.cshopper.CShopper;
|
||||||
import io.reisub.dreambot.cshopper.ItemWrapper;
|
import io.reisub.dreambot.cshopper.ItemWrapper;
|
||||||
|
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.Inventory;
|
||||||
import org.dreambot.api.methods.container.impl.Shop;
|
import org.dreambot.api.methods.container.impl.Shop;
|
||||||
import org.dreambot.api.script.TaskNode;
|
import org.dreambot.api.script.TaskNode;
|
||||||
|
import org.dreambot.api.wrappers.items.Item;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Buy extends TaskNode {
|
public class Buy extends TaskNode {
|
||||||
|
private final Map<String, Integer> boughtMap;
|
||||||
|
|
||||||
|
public Buy() {
|
||||||
|
this.boughtMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
if (!Shop.isOpen()) return false;
|
if (!Shop.isOpen()) return false;
|
||||||
@ -28,19 +40,53 @@ public class Buy extends TaskNode {
|
|||||||
@Override
|
@Override
|
||||||
public int execute() {
|
public int execute() {
|
||||||
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
||||||
int shopCount = Shop.get(iw.getName()).getAmount();
|
Item shopItem = Shop.get(iw.getName());
|
||||||
|
int shopCount = shopItem.getAmount();
|
||||||
|
|
||||||
int inventoryCount = 0;
|
int inventoryCount = 0;
|
||||||
if (Inventory.get(iw.getName()) != null) {
|
if (Inventory.get(iw.getName()) != null) {
|
||||||
inventoryCount = Inventory.get(iw.getName()).getAmount();
|
inventoryCount = Inventory.get(iw.getName()).getAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shopCount > iw.getMinimumInShop() && inventoryCount < iw.getBuyTotal()) {
|
int buyTotal = iw.getBuyTotal() == -1 ? Integer.MAX_VALUE : iw.getBuyTotal();
|
||||||
int toBuy = shopCount - iw.getMinimumInShop();
|
|
||||||
// TODO finish while testing at shop
|
if (shopCount > iw.getMinimumInShop() && inventoryCount < buyTotal) {
|
||||||
|
int toBuy = buyTotal - inventoryCount;
|
||||||
|
int canBuy = iw.getMinimumInShop() == 0 ? 50 : shopCount - iw.getMinimumInShop();
|
||||||
|
|
||||||
|
if (toBuy >= 50 && canBuy >= 50) {
|
||||||
|
shopItem.interact("Buy 50");
|
||||||
|
} else if (toBuy >= 10 && canBuy >= 10) {
|
||||||
|
shopItem.interact("Buy 10");
|
||||||
|
} else if (toBuy >= 5 && canBuy >= 5) {
|
||||||
|
shopItem.interact("Buy 5");
|
||||||
|
} else {
|
||||||
|
shopItem.interact("Buy 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
int finalInventoryCount = inventoryCount;
|
||||||
|
if (MethodProvider.sleepUntil(() -> {
|
||||||
|
Item inventoryItem = Inventory.get(iw.getName());
|
||||||
|
return inventoryItem != null && inventoryItem.getAmount() > finalInventoryCount;
|
||||||
|
}, Calculations.random(2000, 2500))) {
|
||||||
|
int count = Inventory.get(iw.getName()).getAmount();
|
||||||
|
bought(iw.getName(), count - inventoryCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bought(String item, int amount) {
|
||||||
|
int old = getBought(item);
|
||||||
|
boughtMap.put(item, old + amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBought(String item) {
|
||||||
|
Integer i = boughtMap.get(item);
|
||||||
|
if (i == null) return 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,20 @@ package io.reisub.dreambot.cshopper.tasks;
|
|||||||
|
|
||||||
import io.reisub.dreambot.cshopper.CShopper;
|
import io.reisub.dreambot.cshopper.CShopper;
|
||||||
import io.reisub.dreambot.cshopper.ItemWrapper;
|
import io.reisub.dreambot.cshopper.ItemWrapper;
|
||||||
|
import org.dreambot.api.Client;
|
||||||
|
import org.dreambot.api.data.GameState;
|
||||||
import org.dreambot.api.methods.Calculations;
|
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.Inventory;
|
||||||
import org.dreambot.api.methods.container.impl.Shop;
|
import org.dreambot.api.methods.container.impl.Shop;
|
||||||
|
import org.dreambot.api.methods.interactive.Players;
|
||||||
|
import org.dreambot.api.methods.skills.Skills;
|
||||||
import org.dreambot.api.methods.world.World;
|
import org.dreambot.api.methods.world.World;
|
||||||
import org.dreambot.api.methods.world.Worlds;
|
import org.dreambot.api.methods.world.Worlds;
|
||||||
import org.dreambot.api.methods.worldhopper.WorldHopper;
|
import org.dreambot.api.methods.worldhopper.WorldHopper;
|
||||||
import org.dreambot.api.script.TaskNode;
|
import org.dreambot.api.script.TaskNode;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -18,9 +24,17 @@ public class Hop extends TaskNode {
|
|||||||
private final Queue<World> worlds;
|
private final Queue<World> worlds;
|
||||||
|
|
||||||
public Hop(boolean members) {
|
public Hop(boolean members) {
|
||||||
List<World> worldsList = Worlds.all(world -> world.isMembers() == members && world.isNormal() && !world.isHighRisk() && !world.isPVP());
|
List<World> worldsList = Worlds.all(world -> world.isMembers() == members && world.isNormal() && !world.isHighRisk() && !world.isPVP() && world.getMinimumLevel() <= Skills.getTotalLevel());
|
||||||
|
worldsList.sort(Comparator.comparingInt(World::getWorld));
|
||||||
|
|
||||||
worlds = new LinkedList<>(worldsList);
|
worlds = new LinkedList<>(worldsList);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
World w = worlds.poll();
|
||||||
|
worlds.add(w);
|
||||||
|
|
||||||
|
if (w == null || w.getWorld() == Worlds.getCurrentWorld()) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hop() {
|
public Hop() {
|
||||||
@ -47,13 +61,18 @@ public class Hop extends TaskNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int execute() {
|
public int execute() {
|
||||||
|
Shop.close();
|
||||||
|
MethodProvider.sleepUntil(() -> !Shop.isOpen(), Calculations.random(2000, 2500));
|
||||||
|
|
||||||
World world = worlds.poll();
|
World world = worlds.poll();
|
||||||
worlds.add(world);
|
worlds.add(world);
|
||||||
|
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
WorldHopper.hopWorld(world);
|
WorldHopper.hopWorld(world);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MethodProvider.sleepUntil(() -> Client.getGameState() == GameState.LOGGED_IN, Calculations.random(10000, 11000));
|
||||||
|
|
||||||
return Calculations.random(200, 400);
|
return Calculations.random(200, 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
CShopper/src/io/reisub/dreambot/cshopper/tasks/Stop.java
Normal file
32
CShopper/src/io/reisub/dreambot/cshopper/tasks/Stop.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package io.reisub.dreambot.cshopper.tasks;
|
||||||
|
|
||||||
|
import io.reisub.dreambot.cshopper.CShopper;
|
||||||
|
import io.reisub.dreambot.cshopper.ItemWrapper;
|
||||||
|
import org.dreambot.api.methods.MethodProvider;
|
||||||
|
import org.dreambot.api.methods.container.impl.Inventory;
|
||||||
|
import org.dreambot.api.script.ScriptManager;
|
||||||
|
import org.dreambot.api.script.TaskNode;
|
||||||
|
|
||||||
|
public class Stop extends TaskNode {
|
||||||
|
@Override
|
||||||
|
public boolean accept() {
|
||||||
|
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
|
||||||
|
int inventoryCount = 0;
|
||||||
|
if (Inventory.get(iw.getName()) != null) {
|
||||||
|
inventoryCount = Inventory.get(iw.getName()).getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inventoryCount < iw.getBuyTotal()) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int execute() {
|
||||||
|
MethodProvider.log("Finished buying");
|
||||||
|
ScriptManager.getScriptManager().stop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user