package zulFisher;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;
//import java.util.List;
//import org.osbot.rs07.api.NPCS;
//import org.osbot.rs07.api.Players;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.ui.Skill;
//import org.osbot.rs07.api.model.NPC;
//import org.osbot.rs07.api.model.Player;
//import org.osbot.rs07.api.ui.Option;
import org.osbot.rs07.api.ui.Tab;
//import org.osbot.rs07.input.mouse.EntityDestination;
//import org.osbot.rs07.input.mouse.MouseDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
@ScriptManifest(author = "S3R0", info = "A simple bot that fishes for Sacred Eels at Zul-Andra and cuts them for scales.", logo = "", name = "ZulFisher", version = 0.1)
public class ZulFisher extends Script {
//Enums
enum State {
CHECKINV, FISHSACREDEELS, GATHERSCALES;
}
//State
State state;
//Strings
String botStatus = "";
//Ints
int eelsCaught = 0;
//Time
long startTime;
//Code to be executed on start
public void onStart() {
log("Starting ZulFisher by S3R0");
log("Current version is 1.0");
startTime = System.currentTimeMillis();
state = State.CHECKINV;
}
//Code to be executed on exit
public void onExit() {
log("Thank you for using my script!");
}
//Stop Script
public void exitScript(Boolean StopScript) {
if(StopScript == true) {
try {
getBot().getScriptExecutor().stop();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//Code for Main Loop
@Override
public int onLoop() throws InterruptedException {
switch(state) {
case CHECKINV:
if(!inventory.isFull() & inventory.contains("Bait", "Fishing rod")) {
state = State.FISHSACREDEELS;
} else if (!inventory.contains("Bait")) {
log("Fishing bait missing from inventory. Script shutting down...");
exitScript(true);
} else if (!inventory.contains("Fishing rod")) {
log("Fishing rod missing from inventory. Script shutting down...");
exitScript(true);
} else if (inventory.isFull() & inventory.contains("Sacred eel")) {
if(inventory.contains("Knife")) {
state = State.GATHERSCALES;
} else if (!inventory.contains("Knife")) {
log("Knife missing from inventory. Script shutting down...");
exitScript(true);
}
} else {
log("Unable to continue due to not having enough inventory space (too many items!). Script shutting down...");
exitScript(true);
}
break;
case FISHSACREDEELS:
Entity fishSpot = objects.closest("Fishing spot");
if(fishSpot != null) {
if(fishSpot.isVisible()) {
if(!myPlayer().isAnimating()) {
fishSpot.interact("Fishing spot");
botStatus = "Fishing for Sacred Eels";
} else {
state = State.CHECKINV;
}
} else {
camera.toString().indexOf("Fishing spot");
botStatus = "Moving camera to fishing spot";
}
}
break;
case GATHERSCALES:
if(tabs.getOpen() != Tab.INVENTORY) {
tabs.open(Tab.INVENTORY);
botStatus = "Opening inventory tab";
}
while (inventory.contains("Sacred eel")) {
if(!myPlayer().isAnimating()) {
inventory.interact("Use", "Knife");
botStatus = "Using knife on Sacred Eel";
sleep(random(200, 400));
inventory.interact("Use", "Sacred eel");
botStatus = "Gathering Zulrah Scales";
}
}
state = State.CHECKINV;
break;
default:
log("Jet fuel can't melt Zulrah scales");
break;
}
return 100 * (random(50));
}
//Code for Paint
//Interface
private final Color fontColor = new Color(58, 57, 46);
private final Font fontInterface = new Font("Arial", 0, 9);
private final Image imgInterface = getImage("http://i.imgur.com/IPbEQiw.jpg");
//Mouse
private int mX, mY;
private long angle;
private BasicStroke cursorStroke = new BasicStroke(2);
private Color cursorColor = Color.getColor("#8F8F6B");
private AffineTransform oldTransform;
//Getting Interface Image
private Image getImage(String url) {
try {
return ImageIO.read(new URL(url));
} catch(IOException e) {
log("Error downloading image...");
return null;
}
}
public void onMessage(String message) {
if(message.contains("You catch a sacred eel")) {
eelsCaught++;
}
}
public void onPaint(Graphics grafix) {
long timeElapsed = System.currentTimeMillis() - startTime;
long sec = (timeElapsed / 1000) % 60;
long min = (timeElapsed / (1000 * 60)) % 60;
long hr = (timeElapsed / (1000 * 60 * 60)) % 24;
//Code for interface paint
Graphics2D g = (Graphics2D) grafix;
g.drawImage(imgInterface, 1, 335, null);
g.setFont(fontInterface);
g.setColor(fontColor);
g.drawString("Time Running: " + hr + ":" + min + ":" + sec, 301, 361);
g.drawString("Status: " + botStatus, 301, 373);
g.drawString("Current Fishing Level: " + getSkills().getStatic(Skill.FISHING), 301, 392);
g.drawString("Exp Gained: N/A", 301, 404);
g.drawString("Eels Collected: " + eelsCaught , 301, 416);
g.drawString("Current Cooking Level: " + getSkills().getStatic(Skill.COOKING), 301, 436);
g.drawString("Exp Gained: N/A", 301, 448);
g.drawString("Scales Collected: N/A", 301, 460);
//Code for mouse paint
Point mP = getMouse().getPosition();
g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5);
g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
//Mouse Rotation
oldTransform = g.getTransform();
mX = mouse.getPosition().x;
mY = mouse.getPosition().y;
LinkedList<MousePathPoint> mousePath = new LinkedList<>();
g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
//MOUSE TRAIL
while (!mousePath.isEmpty() && mousePath.peek().isUp())
mousePath.remove();
Point clientCursor = mouse.getPosition();
MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y, 300);
if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
mousePath.add(mpp);
MousePathPoint lastPoint = null;
for (MousePathPoint a : mousePath) {
if (lastPoint != null) {
g.setColor(new Color(160, 160, 120, a.getAlpha())); //trail color
g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
}
lastPoint = a;
}
if (mX != -1) {
g.setStroke(cursorStroke);
g.setColor(cursorColor);
g.drawLine(mX-3, mY-3, mX+2, mY+2);
g.drawLine(mX-3, mY+2, mX+2, mY-3);
g.rotate(Math.toRadians(angle+=6), mX, mY);
g.draw(new Arc2D.Double(mX-12, mY-12, 24, 24, 330, 60, Arc2D.OPEN));
g.draw(new Arc2D.Double(mX-12, mY-12, 24, 24, 151, 60, Arc2D.OPEN));
g.setTransform(oldTransform);
}
}
/*private boolean hoverEntityOption(Entity entity, String option) throws InterruptedException {
if(entity == null)
return false;
if(menu.isOpen()) {
List<Option> options = menu.getMenu();
if(options != null) {
Rectangle optionRec = null;
for(int index = 0; index < options.size(); index++) {
if(options.get(index).action.equals(option)) {
optionRec = menu.getOptionRectangle(index);
if(optionRec != null) {
if(!optionRec.contains(mouse.getPosition())) {
int x = menu.getX() + Script.random(10, 160);
int y = menu.getY() + 23 + index * 15;
Script.sleep(Script.random(200, 400));
return mouse.move(x, y);
}
}
}
}
}
} else {
EntityDestination ed = new EntityDestination(bot, entity);
mouse.click(ed, true);
}
return false;
}*/
//AntiBan
//@SuppressWarnings("unchecked")
/*public void AntiBan() throws InterruptedException{
int rand = random(0,random(5000,10000));
if(rand == random(0,random(0,100))){
log("Rotating camera.");
switch(random(0,4)%2){
case 0:
getCamera().moveYaw(random(0, 3000));
break;
case 1:
getCamera().movePitch(random(60,400));
break;
}
} else if(rand == random(random(0,300), random(300,400))){
log("Varied sleep.");
sleep(random(0,5000));
} else if(rand == 10000){
log("Idling to log out!");
sleep(random(310000,380000));
}
}*/
}
Sure thing.
Before you say anything, the code may be bad? Might be okay? I don't know. I don't plan on releasing this. It's just for my own personal use, since no one has created a Sacred Eels bot, other than part of an AIO Fishing. That, and I'm learning some parts of the API as I go.
Please be gentle...