Thanks for some feedback, wondering what you would do different without implementing a lot more to this script.
I'm still relative new to writing methods and so i'm not sure if they are written correct, and are usefull the way they are.
This is also my first script after reading through the tutorial.
Edit: There's also some useless imports im pretty sure since this was also the class i made to fool around ;/
package core;
import java.awt.*;
import Utils.MouseCursor;
import org.osbot.rs07.input.mouse.InventorySlotDestination;
import org.osbot.rs07.input.mouse.MouseDestination;
import org.osbot.rs07.api.Mouse;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.input.mouse.MouseDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.api.Camera;
import java.util.function.BooleanSupplier;
import javax.imageio.ImageIO;
@ScriptManifest(author = "You", info = "My first script", name = "WoodcuttingV2", version = 2, logo = "")
public class WoodcuttingV2 extends Script {
private MouseCursor cursor = new MouseCursor(255, 1, Color.white, this);
int invValue = 28;
int i = 0;
boolean canChop = false;
@Override
public int onLoop() throws InterruptedException {
if (inventoryFull()) {
drop(getRs2ObjectTree());
} else {
chop();
}
return random(150, 200);
}
private void chop() throws InterruptedException {
RS2Object tree = getRs2ObjectTree();
moveMouseOutsideScreen();
Sleep.sleepUntil(this::isPlayerAnimating,3000);
if (areaHasTree(tree) && !isPlayerAnimating()) {
sleep(random(1000, 5000));
if (!isVisible(tree)) {
panCameraToObject(tree);
hoverObject(tree);
interactWithObject();
Sleep.sleepUntil(this::isPlayerAnimating,3000);
} else if (hoverObject(tree)) {
interactWithObject();
Sleep.sleepUntil(this::isPlayerAnimating,3000);
}
moveMouseOutsideScreen();
}
}
private void drop(RS2Object tree) throws InterruptedException {
sleep(random(1000,11000));
dropRowInventory1();
dropRowInventory2();
dropRowInventory3();
dropRowInventory4();
hoverObject(tree);
interactWithObject();
}
private void interactWithObject() {
Sleep.sleepUntil(this::isChopDownVisible, random(73,192));
clickLeftButton();
}
private boolean isChopDownVisible() {
return getWidgets().getWidgetContainingText("Chop down") != null;
}
private boolean isPlayerAnimating() {
return myPlayer().isAnimating();
}
private boolean moveMouseOutsideScreen() {
return mouse.moveOutsideScreen();
}
private boolean clickLeftButton() {
return mouse.click(false);
}
private boolean hoverObject(RS2Object tree) {
return tree.hover();
}
private void panCameraToObject(RS2Object tree) {
getCamera().toEntity(tree);
}
private boolean isVisible(RS2Object tree) {
return tree.isVisible();
}
private boolean areaHasTree(RS2Object tree) {
return (getRadius().contains(tree));
}
private boolean inventoryFull() {
return getInventory().isFull();
}
private Area getRadius() {
Area radius = myPlayer().getArea(10);
return radius;
}
private RS2Object getRs2ObjectTree() {
RS2Object tree = getObjects().closest("Oak");
return tree;
}
@Override
public void onPaint(Graphics2D g) {
cursor.paint(g);
}
private void dropRowInventory1() {
keyboard.pressKey(16);
for (i = 3; i < 28; i += 4) {
if (mouse.move(new InventorySlotDestination(getBot(), i))) {
new ConditionalSleep(24, 191) {
@Override
public boolean condition() {
return !mouse.move(new InventorySlotDestination(getBot(), i));
}
}.sleep();
mouse.click(false);
}
}
}
private void dropRowInventory2() {
for (i = 26; i > 1; i -= 4) {
if (mouse.move(new InventorySlotDestination(getBot(), i))) {
new ConditionalSleep(12, 241) {
@Override
public boolean condition() {
return !mouse.move(new InventorySlotDestination(getBot(), i));
}
}.sleep();
mouse.click(false);
}
}
}
private void dropRowInventory3() {
for (i = 1; i <= 25; i += 4) {
if (mouse.move(new InventorySlotDestination(getBot(), i))) {
new ConditionalSleep(2, 112) {
@Override
public boolean condition() {
return !mouse.move(new InventorySlotDestination(getBot(), i));
}
}.sleep();
mouse.click(false);
}
}
}
private void dropRowInventory4() {
for (i = 24; i >= 4; i -= 4) {
if (mouse.move(new InventorySlotDestination(getBot(), i))) {
new ConditionalSleep(7, 192) {
@Override
public boolean condition() {
return !mouse.move(new InventorySlotDestination(getBot(), i));
}
}.sleep();
mouse.click(false);
}
}
keyboard.releaseKey(16);
}
}
class Sleep extends ConditionalSleep {
private final BooleanSupplier condition;
public Sleep(final BooleanSupplier condition, final int timeout) {
super(timeout);
this.condition = condition;
}
@Override
public final boolean condition() throws InterruptedException {
return condition.getAsBoolean();
}
public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) {
return new Sleep(condition, timeout).sleep();
}
}