Hey guys I just wrote my first script, it's a very simple script for anglerfish on my main. I'd appreciate any feedback!
public final class Angler extends Script {
private final MouseTrail trail = new MouseTrail(0, 255, 255, 2000, this);
private final MouseCursor cursor = new MouseCursor(52, 4, Color.white, this);
private final Area fishingArea = new Area(1819,3765, 1840, 3780);
@Override
public final int onLoop() throws InterruptedException {
if(!doingSomething()) {
if(inventoryFull()) {
if(Banks.PISCARILIUS_HOUSE.contains(myPosition())) {
bank();
} else {
getWalking().webWalk(Banks.PISCARILIUS_HOUSE);
}
} else {
if(hasCorrectEquipment()) {
if(fishingArea.contains(myPosition())) {
fish();
} else {
getWalking().webWalk(fishingArea);
}
} else {
throw new InterruptedException("Please retry with bait and rod in inventory."); //Better exception?
}
}
}
return random(250,600);
}
@Override
public void onPaint(Graphics2D g) {
trail.paint(g);
cursor.paint(g);
}
private void bank() throws InterruptedException {
Bank bank = getBank();
if (bank != null && bank.open()) {
bank.depositAll("Raw anglerfish");
if(getInventory().contains("Open fish barrel"))
{
getInventory().getItem("Open fish barrel").interact("Empty");
}
bank.close();
}
}
private void fish() {
Entity fishingSpot = getNpcs().singleFilter(getNpcs().getAll(), e -> e.getName().startsWith("Rod"));
if (fishingSpot != null)
{
fishingSpot.interact("Bait");
}
}
private boolean doingSomething() {
return myPlayer().isAnimating() || myPlayer().isMoving();
}
private boolean inventoryFull() {
return getInventory().getEmptySlots() == 0;
}
private boolean hasCorrectEquipment() {
return getInventory().contains("Sandworms") && getInventory().contains("Fishing rod");
}
}
I did have a couple of basic questions as well if you still have time after reviewing the code.
Why is anglerfish spot an NPC?
What is more 'human-like', always interacting with the closest fishing spot? Or doing what I did in fish() and just getting one that matches?
What exception to throw when user starts without correct inventory?
Cleaner onLoop() implementation ideas? This bot is very simple but I already hate the amount of if..else... nested everywhere, Maybe a list of objects with "shouldRun()" and "run()"?