59 lines
2.0 KiB
Java
59 lines
2.0 KiB
Java
package io.reisub.dreambot.cplanker.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.input.Keyboard;
|
|
import org.dreambot.api.methods.interactive.NPCs;
|
|
import org.dreambot.api.methods.widget.Widgets;
|
|
import org.dreambot.api.script.TaskNode;
|
|
import org.dreambot.api.wrappers.interactive.NPC;
|
|
import org.dreambot.api.wrappers.widgets.WidgetChild;
|
|
|
|
public class BuyPlanks extends TaskNode {
|
|
private boolean madePlanks;
|
|
public static int planksMade = 0;
|
|
|
|
@Override
|
|
public boolean accept() {
|
|
return Inventory.isFull()
|
|
&& Inventory.contains("Oak logs");
|
|
}
|
|
|
|
@Override
|
|
public int execute() {
|
|
NPC operator = NPCs.closest("Sawmill operator");
|
|
if (operator == null) return Calculations.random(250, 400);
|
|
|
|
operator.interact("Buy-plank");
|
|
if (!Util.sleepUntilMoving()) return Calculations.random(250, 400);
|
|
|
|
MethodProvider.sleepUntil(() -> operator.distance() < Calculations.random(4, 7), Calculations.random(3000, 3500));
|
|
|
|
if (madePlanks) {
|
|
Keyboard.holdSpace(() -> {
|
|
WidgetChild w = Widgets.getChildWidget(270, 15);
|
|
return w != null && w.isVisible();
|
|
}, Calculations.random(3000, 3500));
|
|
} else {
|
|
MethodProvider.sleepUntil(() -> {
|
|
WidgetChild w = Widgets.getChildWidget(270, 15);
|
|
return w != null && w.isVisible();
|
|
}, Calculations.random(5000, 5500));
|
|
|
|
WidgetChild w = Widgets.getChildWidget(270, 15);
|
|
if (w != null && w.isVisible()) {
|
|
Keyboard.type("2", false);
|
|
}
|
|
}
|
|
|
|
if (MethodProvider.sleepUntil(() -> Inventory.contains("Oak plank"), Calculations.random(5000, 5500))) {
|
|
madePlanks = true;
|
|
planksMade += Inventory.count("Oak plank");
|
|
}
|
|
|
|
return Calculations.random(250, 400);
|
|
}
|
|
}
|