96 lines
3.1 KiB
Java
96 lines
3.1 KiB
Java
package io.reisub.dreambot.cminer.tasks;
|
|
|
|
import io.reisub.dreambot.util.Constants;
|
|
import io.reisub.dreambot.util.Util;
|
|
import org.dreambot.api.input.Mouse;
|
|
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.interactive.GameObjects;
|
|
import org.dreambot.api.methods.interactive.Players;
|
|
import org.dreambot.api.methods.tabs.Tab;
|
|
import org.dreambot.api.methods.tabs.Tabs;
|
|
import org.dreambot.api.methods.widget.Widgets;
|
|
import org.dreambot.api.script.TaskNode;
|
|
import org.dreambot.api.wrappers.interactive.GameObject;
|
|
import org.dreambot.api.wrappers.widgets.WidgetChild;
|
|
|
|
import java.util.List;
|
|
|
|
public class Mine extends TaskNode {
|
|
private final boolean superheat;
|
|
private boolean depleted = false;
|
|
|
|
public Mine(boolean superheat) {
|
|
this.superheat = superheat;
|
|
}
|
|
|
|
public Mine() {
|
|
this(false);
|
|
}
|
|
|
|
@Override
|
|
public boolean accept() {
|
|
return !Inventory.isFull() &&
|
|
(Util.playerIsIdle() || Players.localPlayer().getAnimation() == Constants.SUPERHEAT || depleted) &&
|
|
!getRocks(Constants.IRON_ROCKS_COLOR).isEmpty();
|
|
}
|
|
|
|
@Override
|
|
public int execute() {
|
|
depleted = false;
|
|
|
|
List<GameObject> rocks = getRocks(Constants.IRON_ROCKS_COLOR);
|
|
if (rocks.isEmpty()) return Calculations.random(250, 400);
|
|
|
|
int count = Inventory.count(Constants.IRON_ORE);
|
|
|
|
final GameObject rock = rocks.get(0);
|
|
rock.interactForceLeft(Constants.MINE);
|
|
|
|
if (!MethodProvider.sleepUntil(() -> Players.localPlayer().isAnimating(), Calculations.random(1500, 2000))) {
|
|
return Calculations.random(250, 400);
|
|
}
|
|
|
|
if (superheat) {
|
|
selectSuperheat();
|
|
}
|
|
|
|
MethodProvider.sleepUntil(() -> {
|
|
short[] colors = GameObjects.getTopObjectOnTile(rock.getTile()).getModelColors();
|
|
if (colors == null || colors.length == 0) {
|
|
depleted = true;
|
|
return true;
|
|
}
|
|
|
|
return count < Inventory.count(Constants.IRON_ORE);
|
|
}, Calculations.random(10000, 11000));
|
|
|
|
return Calculations.random(250, 400);
|
|
}
|
|
|
|
public static List<GameObject> getRocks(int colorID) {
|
|
return GameObjects.all(gameObject -> {
|
|
if (gameObject.getModelColors() == null || gameObject.getModelColors().length == 0) return false;
|
|
|
|
return gameObject.getModelColors()[0] == colorID &&
|
|
gameObject.hasAction(Constants.MINE) &&
|
|
gameObject.getInteractableFrom().contains(Players.localPlayer().getTile());
|
|
});
|
|
}
|
|
|
|
private void selectSuperheat() {
|
|
if (!Tabs.isOpen(Tab.MAGIC)) {
|
|
Tabs.open(Tab.MAGIC);
|
|
}
|
|
|
|
WidgetChild superheat = Widgets.getChildWidget(218, 30);
|
|
if (superheat == null) return;
|
|
|
|
superheat.interact();
|
|
MethodProvider.sleepUntil(() -> Tabs.isOpen(Tab.INVENTORY), Calculations.random(1200, 1500));
|
|
|
|
Mouse.move(Inventory.slotBounds(Inventory.getFirstEmptySlot()));
|
|
}
|
|
}
|