Hi everyone,
I'm just getting started writing scripts for RS and wrote my first script to auto fish and deposit in bank. Would love to get some feedback on anything I could be doing better.
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
import java.util.Comparator;
import java.util.Optional;
import java.util.Random;
@ScriptManifest(name = "FirstScript", author = "ultraswagger", version = 1.0, info = "", logo = "")
public class FirstScript extends Script {
private static Random gaussianGenerator = new Random();
private Comparator closestCageFishingSpot = (Comparator<NPC>) (a, b) ->
getMap().distance(a.getPosition()) - getMap().distance(b.getPosition());
private ConditionalSleep bankConditionalSleep = new ConditionalSleep(5000) {
@Override
public boolean condition() throws InterruptedException {
return getBank().isOpen();
}
};
private ConditionalSleep fishingConditionalSleep = new ConditionalSleep(5000) {
@Override
public boolean condition() throws InterruptedException {
return getInventory().isFull();
}
};
private void depositFishToBank() {
if(!Banks.CATHERBY.contains(myPosition()))
getWalking().webWalk(Banks.CATHERBY);
else {
if(!getBank().isOpen())
bankConditionalSleep.sleep();
else
getBank().depositAllExcept("Lobster pot");
}
}
@Override
public void onStart() {
log("Starting Script");
}
@Override
public int onLoop() {
if (!this.myPlayer().isAnimating()) {
if (this.getInventory().isFull()) {
depositFishToBank();
} else {
Optional<NPC> cageFishingSpot = this.getNpcs().getAll().stream()
.filter(o -> o.hasAction("Cage")).min(closestCageFishingSpot);
if (cageFishingSpot.isPresent()) {
cageFishingSpot.get().interact("Cage");
fishingConditionalSleep.sleep();
}
}
}
return (int)((double)1000 * gaussianGenerator.nextGaussian());
}
@Override
public void onExit() {
log("Script has been stopped");
}
}
Thanks in advance!