Compare commits

..

4 Commits

Author SHA1 Message Date
7536ae4db3 Add GUI support 2021-10-28 16:30:07 +02:00
03b882635e Fix unnecessary wait after banking 2021-10-28 09:37:11 +02:00
25844dad61 Add hover functionality 2021-10-28 09:33:53 +02:00
aaee43be4c Add hover functions 2021-10-28 09:33:35 +02:00
11 changed files with 493 additions and 4 deletions

View File

@ -4,19 +4,26 @@ 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(
"Ordan",
new ItemWrapper("Gold ore", 2600, 73, false)
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),
@ -26,6 +33,7 @@ public class CShopper extends CTaskScript {
);
private Buy buyTask;
private GUI gui;
public static Configuration getConfiguration() {
return configuration;
@ -34,11 +42,33 @@ public class CShopper extends CTaskScript {
@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 Deposit(),
new Stop(),
new Run(),
new Open(),

View File

@ -0,0 +1,16 @@
package io.reisub.dreambot.cshopper;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.ui.Option;
public class CShopperOptions {
public final static Option[] traders = new Option[]{
new Option("custom"),
new Option("Lundail", "mage arena rune shop")
};
public final static Option[] items = new Option[]{
new Option("custom"),
new Option("Nature rune")
};
}

View File

@ -0,0 +1,31 @@
package io.reisub.dreambot.cshopper;
public enum ShopperItem {
CUSTOM("custom..."),
NATURE_RUNE("Nature rune");
private final String name;
private String customName;
ShopperItem(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
public void setCustomName(String customName) {
this.customName = customName;
}
public String getCustomName() {
return customName;
}
}

View File

@ -0,0 +1,49 @@
package io.reisub.dreambot.cshopper;
public enum Trader {
CUSTOM("custom..."),
LUNDAIL("Lundail", "mage arena rune shop");
private final String name;
private final String info;
private String customName;
Trader(String name) {
this(name, "");
}
Trader(String name, String info) {
this.name = name;
this.info = info;
}
public String getName() {
if (customName == null || customName.equals("")) {
return name;
} else {
return customName;
}
}
public String getInfo() {
return info;
}
@Override
public String toString() {
if (info.equals("")) {
return name;
} else {
return name + " (" + info + ")";
}
}
public String getCustomName() {
return customName;
}
public void setCustomName(String customName) {
this.customName = customName;
}
}

View File

@ -2,11 +2,15 @@ package io.reisub.dreambot.csmelter.tasks;
import io.reisub.dreambot.csmelter.CSmelter;
import io.reisub.dreambot.csmelter.Ingredient;
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.bank.Bank;
import org.dreambot.api.methods.widget.Widgets;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.items.Item;
import org.dreambot.api.wrappers.widgets.WidgetChild;
public class DoBank extends TaskNode {
@Override
@ -17,6 +21,18 @@ public class DoBank extends TaskNode {
@Override
public int execute() {
if (Inventory.contains(CSmelter.smeltingOption.getEndProduct())) {
if (Util.getHoverEntry("deposit") == null) {
if (Inventory.contains(item -> item.getName().endsWith("mould"))) {
Item item = Inventory.get(CSmelter.smeltingOption.getEndProduct());
Util.addHoverEntry("deposit", item.getDestination().getBoundingBox());
} else {
WidgetChild depositAll = Widgets.getChildWidget(12, 42);
if (depositAll != null && depositAll.isVisible()) {
Util.addHoverEntry("deposit", depositAll.getRectangle());
}
}
}
Bank.depositAllExcept(item -> item.getName().endsWith("mould"));
if (!MethodProvider.sleepUntil(() -> Inventory.isEmpty() || Inventory.onlyContains(item -> item.getName().endsWith("mould")), Calculations.random(2000, 2500))) return Calculations.random(250, 400);
}
@ -46,6 +62,8 @@ public class DoBank extends TaskNode {
}
}
Util.hover("minimapToFurnace");
MethodProvider.sleepUntil(() -> Inventory.containsAll(names), Calculations.random(2000, 2500));
return Calculations.random(250, 400);

View File

@ -32,9 +32,12 @@ public class OpenBank extends TaskNode {
}
}
Util.addHoverEntry("bank", bank);
bank.interactForceLeft("Bank");
if (!Util.sleepUntilMoving()) return Calculations.random(250, 400);
Util.hover("deposit");
MethodProvider.sleepUntil(Bank::isOpen, Calculations.random(10000, 11000));
return Calculations.random(250, 400);

View File

@ -21,7 +21,7 @@ public class Smelt extends TaskNode {
@Override
public boolean accept() {
return Inventory.containsAll(CSmelter.smeltingOption.getIngredientsNames())
&& Util.playerIsIdle(1000);
&& (Bank.isOpen() || Util.playerIsIdle(1400));
}
@Override
@ -30,6 +30,7 @@ public class Smelt extends TaskNode {
if (furnace == null) return Calculations.random(250, 400);
if (Bank.isOpen()) {
Util.addHoverEntry("minimapToFurnace", furnace.getTile(), true);
Walking.walk(furnace);
MethodProvider.sleep(300, 600);
}
@ -39,6 +40,7 @@ public class Smelt extends TaskNode {
if (!Util.sleepUntilMoving()) return Calculations.random(250, 400);
}
Util.hover("smeltWidget");
MethodProvider.sleepWhile(() -> furnace.distance() > Calculations.random(2, 4), Calculations.random(10000, 11000));
if (CSmelter.smeltingOption.getMould().equals("")) {
@ -61,11 +63,14 @@ public class Smelt extends TaskNode {
}, Calculations.random(3000, 3500))) return Calculations.random(250, 400);
WidgetChild w = Widgets.getChildWidget(446, CSmelter.smeltingOption.getHotkey());
Util.addHoverEntry("smeltWidget", w.getRectangle());
w.interact();
Util.sleepUntilAnimating();
}
Util.hover("bank");
return Calculations.random(250, 400);
}
}

View File

@ -1,17 +1,26 @@
package io.reisub.dreambot.util;
import org.dreambot.api.input.Mouse;
import org.dreambot.api.input.mouse.destination.impl.MiniMapTileDestination;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.methods.map.Tile;
import org.dreambot.api.methods.skills.Skill;
import org.dreambot.api.methods.skills.Skills;
import org.dreambot.api.wrappers.interactive.Entity;
import org.dreambot.api.wrappers.interactive.GameObject;
import org.dreambot.api.wrappers.interactive.Player;
import org.w3c.dom.css.Rect;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("unused")
public class Util {
private static final String VERSION = "1.0.0";
private static final Map<String, Rectangle> hoverMap = new HashMap<>();
public static String getVersion() {
return VERSION;
@ -114,4 +123,40 @@ public class Util {
return false;
}
public static Rectangle getHoverEntry(String name) {
return hoverMap.get(name);
}
public static void addHoverEntry(String name, Rectangle dest) {
hoverMap.putIfAbsent(name, dest);
}
public static void addHoverEntry(String name, Tile dest, boolean minimap) {
Rectangle rect;
if (minimap) {
MiniMapTileDestination td = new MiniMapTileDestination(dest);
rect = td.getBoundingBox();
} else {
rect = dest.getTileReference().getBoundaryObject().getBoundingBox();
}
addHoverEntry(name, rect);
}
public static void addHoverEntry(String name, Tile dest) {
addHoverEntry(name, dest, false);
}
public static void addHoverEntry(String name, Entity dest) {
addHoverEntry(name, dest.getBoundingBox());
}
public static void hover(String name) {
Rectangle dest = getHoverEntry(name);
if (dest != null) {
Mouse.move(dest);
}
}
}

View File

@ -0,0 +1,208 @@
package io.reisub.dreambot.util.ui;
import org.dreambot.api.methods.MethodProvider;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class GUI extends JFrame {
private final GridBagLayout layout;
private final GridBagConstraints constraints;
private final Map<String, Component> componentMap;
private final Map<String, java.util.List<Option>> optionMap;
private volatile boolean ready;
public GUI(String title) {
super(title);
layout = new GridBagLayout();
constraints = new GridBagConstraints();
constraints.insets = new Insets(6, 6, 6, 6);
componentMap = new HashMap<>();
optionMap = new HashMap<>();
}
public void init() {
setUndecorated(true);
Container contentPane = getContentPane();
contentPane.setLayout(layout);
addStart();
pack();
setLocationRelativeTo(getOwner());
setVisible(true);
}
private void addStart() {
JButton start = new JButton("Start");
start.setPreferredSize(new Dimension(100, 40));
constraints.fill = GridBagConstraints.VERTICAL;
constraints.weighty = 2.0;
layout.setConstraints(start, constraints);
getContentPane().add(start);
start.addActionListener((e) -> {
for (String key : componentMap.keySet()) {
Component component = componentMap.get(key);
java.util.List<Option> options = new ArrayList<>();
if (component instanceof JComboBox) {
Option option = (Option) ((JComboBox<?>) component).getSelectedItem();
options.add(option);
} else if (component instanceof JList) {
DefaultListModel<Option> listModel = (DefaultListModel<Option>) ((JList<?>) component).getModel();
for (int i = 0; i < listModel.size(); i++) {
options.add(listModel.get(i));
}
}
optionMap.put(key, options);
}
ready = true;
setVisible(false);
dispose();
});
}
public void addComboBox(String name, Option[] options, Parameter... parameters) {
addComboBox(name, options, false, parameters);
}
public void addComboBox(String name, Option[] options, boolean multiple, Parameter... parameters) {
JComboBox<Option> comboBox = new JComboBox<>();
for (Option option : options) {
comboBox.addItem(option);
}
JLabel label = new JLabel(name);
label.setLabelFor(comboBox);
JPanel parametersPanel = new JPanel();
GridBagLayout parametersPanelLayout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(0, 6, 6, 6);
parametersPanel.setLayout(parametersPanelLayout);
DefaultListModel<Option> optionsList = new DefaultListModel<>();
JList<Option> optionsJList = new JList<>(optionsList);
for (Parameter parameter : parameters) {
JLabel pLabel = new JLabel(parameter.getName());
pLabel.setLabelFor(parameter.getComponent());
componentMap.put(name + "." + parameter.getName(), parameter.getComponent());
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
c.gridwidth = 1;
parametersPanelLayout.setConstraints(pLabel, c);
parametersPanel.add(pLabel);
c.gridwidth = GridBagConstraints.REMAINDER;
parametersPanelLayout.setConstraints(parameter.getComponent(), c);
parametersPanel.add(parameter.getComponent());
}
if (multiple) {
c.gridwidth = 2;
JButton button = new JButton("Add");
button.addActionListener((e) -> {
Option option = (Option) comboBox.getSelectedItem();
assert option != null;
option = option.clone();
if (option.getName().equals("custom")) {
JTextField customField = (JTextField) componentMap.get(name + ".Custom");
MethodProvider.log(customField);
if (customField != null) {
option.setCustomName(customField.getText());
}
}
for (Parameter parameter : parameters) {
Component component = parameter.getComponent();
String value = "";
if (component instanceof JTextField) {
value = ((JTextField) component).getText();
} else if (component instanceof JCheckBox) {
if (((JCheckBox) component).isSelected()) {
value = "true";
} else {
value = "false";
}
}
option.setParameter(parameter.getName(), value);
}
optionsList.addElement(option);
});
parametersPanelLayout.setConstraints(button, c);
parametersPanel.add(button);
}
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.anchor = GridBagConstraints.NORTH;
constraints.gridwidth = 1;
layout.setConstraints(label, constraints);
getContentPane().add(label);
if (multiple) {
JPanel panel = new JPanel();
GridBagLayout panelLayout = new GridBagLayout();
GridBagConstraints panelConstraints = new GridBagConstraints();
panel.setLayout(panelLayout);
panelConstraints.weightx = 1;
panelConstraints.fill = GridBagConstraints.HORIZONTAL;
panelConstraints.gridwidth = GridBagConstraints.REMAINDER;
panelLayout.setConstraints(comboBox, panelConstraints);
panel.add(comboBox);
panelConstraints.fill = GridBagConstraints.BOTH;
panelLayout.setConstraints(optionsJList, panelConstraints);
panel.add(optionsJList);
layout.setConstraints(panel, constraints);
getContentPane().add(panel);
} else {
layout.setConstraints(comboBox, constraints);
getContentPane().add(comboBox);
}
constraints.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(parametersPanel, constraints);
getContentPane().add(parametersPanel);
if (multiple) {
componentMap.put(name, optionsJList);
} else {
componentMap.put(name, comboBox);
}
}
public boolean isReady() {
return ready;
}
public Option getOption(String name) {
return optionMap.get(name).get(0);
}
public java.util.List<Option> getOptions(String name) {
return optionMap.get(name);
}
}

View File

@ -0,0 +1,55 @@
package io.reisub.dreambot.util.ui;
import java.util.HashMap;
import java.util.Map;
public class Option implements Cloneable {
private final String name, info;
private final Map<String, String> parameters;
private String customName = "";
public Option(String name) {
this(name, "");
}
public Option(String name, String info) {
this.name = name;
this.info = info;
parameters = new HashMap<>();
}
public String getName() {
return name;
}
@Override
public String toString() {
if (!customName.equals("")) {
return customName;
}
if (info.equals("")) {
return name;
} else {
return name + " (" + info + ")";
}
}
public void setCustomName(String customName) {
this.customName = customName;
}
public void setParameter(String key, String value) {
parameters.put(key, value);
}
@Override
public Option clone() {
try {
return (Option) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}

View File

@ -0,0 +1,29 @@
package io.reisub.dreambot.util.ui;
import javax.swing.*;
import java.awt.*;
public class Parameter {
private final String name;
private final Component component;
public Parameter(String name) {
JTextField textField = new JTextField(10);
this.name = name;
this.component = textField;
}
public Parameter(String name, Component component) {
this.name = name;
this.component = component;
}
public String getName() {
return name;
}
public Component getComponent() {
return component;
}
}