2021-10-28 16:30:07 +02:00

94 lines
3.2 KiB
Java

package io.reisub.dreambot.cshopper;
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;
import io.reisub.dreambot.util.ui.GUI;
import io.reisub.dreambot.util.ui.Parameter;
import org.dreambot.api.methods.MethodProvider;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.randoms.RandomEvent;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.wrappers.items.Item;
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
@SuppressWarnings("unused")
@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("Nature rune", 5000)
//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;
private GUI gui;
public static Configuration getConfiguration() {
return configuration;
}
@Override
public void onStart() {
getUI().setCustomLines(configuration.getItems().length);
getRandomManager().disableSolver(RandomEvent.BREAK);
getRandomManager().disableSolver(RandomEvent.LOGIN);
buyTask = new Buy();
try {
SwingUtilities.invokeAndWait(() -> {
gui = new GUI(getSDNName());
gui.addComboBox("Trader", CShopperOptions.traders, new Parameter("Custom"));
gui.addComboBox("Items",
CShopperOptions.items,
true,
new Parameter("Custom"),
new Parameter("Buy total"),
new Parameter("Minimum in shop"),
new Parameter("Stackable", new JCheckBox()));
gui.init();
});
} catch (Exception ignored) {}
while (gui == null || !gui.isReady()) {
MethodProvider.sleep(500);
}
MethodProvider.log(gui.getOption("Trader").getName());
addNodes(
new Stop(),
new Run(),
new Open(),
buyTask,
new Hop()
);
}
@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 + ")");
}
}
}