import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Map;
import org.rsbot.bot.Bot;
import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.script.Constants;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.Skills;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSInterfaceChild;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSTile;
@ScriptManifest(authors = { "Pyratepig" }, category = "Crafting", name = "Pyratepig's Crafter", version = 1.0, description =
"<html><head>"
+ "</head><body>"
+ "<center>"
+ "<b><font size=\"5\" color=\"green\">"
+ "Pyratepig's Crafter"
+ "Version 1.0"
+ "</font></b>"
+ "<br></br>"
+ "<i><font size=\"4\" color=\"black\">Makes pots, bowls, pie dishes, or plantpots in Barbarian Village.</font></i>"
+ "<br></br>"
+ "<i><font size=\"4\" color=\"blue\">Please start in the West Varrock bank with soft clay visible in your bank.</font></i>"
+ "<br></br>"
+ "<b><font size=\"4\" color=\"black\">Which type of pottery would you like to make?</font></b>"
+ "<br></br>"
+ "<select name='pottery'>"
+ "<option>Pot"
+ "<option>Pie Dish"
+ "<option>Bowl"
+ "<option>Plantpot"
+ "<br></br>"
+ "</body></html>")
public class PyratepigCrafter extends Script implements PaintListener, ServerMessageListener {
public enum Action {
BANK, DO_WORK, WALK_TO_FURNACE, WALK_TO_BANK, OPENBANK, WAIT, ANTIBAN, CLICK
}
public int wheelAnimation = 883;
public int furnaceAnimation = 899;
public int furnace = 11601;
public int wheel = 2642;
public int clay = 1761;
public int potsMade = 0;
public int toChoose;
PyratepigCrafterAntiBan antiban;
Thread t;
Action action;
public int toMake;
public boolean neededClay;
String pottery = "";
String Pottery = "";
private String status = "";
public int thePot;
public int x2 = getInventoryCount(clay);
public int x4 = 28 * 3910;
public int x5 = x4 * 1;
public int compPot;
public int levelsGained = 0;
public int bankID = 11402;
public int energy = random(11, 70);
public final int levelUp = 740;
public final int potInterface = 513;
//Paint Variables
public static final int CRAFTING_STAT = Skills.getStatIndex("CRAFTING");
public long startTime = System.currentTimeMillis();
int startLVL = skills.getCurrentSkillLevel(Constants.STAT_CRAFTING);
int nextLVL = skills.getXPToNextLevel(Constants.STAT_CRAFTING);
//Paths
RSTile[] bankToFurnace = { new RSTile(3183, 3436),
new RSTile(3176, 3429), new RSTile(3165, 3424),
new RSTile(3153, 3421), //MUSIC
new RSTile(3146, 3417), new RSTile(3136, 3416),
new RSTile(3122, 3416), new RSTile(3110, 3421), //Gate
new RSTile(3097, 3420), new RSTile(3084, 3417),
new RSTile(3085, 3409) };
RSTile[] furnaceToBank = reversePath(bankToFurnace);
RSTile bankTile = new RSTile(3185, 3435);
RSTile furnaceTile = new RSTile(3085, 3409);
//Other Variables
final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean shouldRun() {
return runEnergy() > energy + random(-10, 10);
}
public boolean clickcontinue() {
if (getContinueChildInterface() != null) {
if (getContinueChildInterface().getText().contains("to continue")) {
return atInterface(getContinueChildInterface());
}
}
return false;
}
public boolean openBank() {
final RSObject bank = getNearestObjectByID(bankID);
if (bank == null) {
return false;
}
if (!tileOnScreen(bank.getLocation())) {
turnToTile(bank.getLocation(), 15);
}
return atTile(bank.getLocation(), "Use-quickly");
}
public int runEnergy() {
int a;
try {
a = Integer.parseInt(RSInterface.getChildInterface(750, 5)
.getText());
} catch (final Exception e) {
a = 0;
}
return a;
}
public boolean atInventoryItem(final int itemID, final String option) {
if (getCurrentTab() != Constants.TAB_INVENTORY
&& !RSInterface.getInterface(Constants.INTERFACE_BANK)
.isValid()
&& !RSInterface.getInterface(Constants.INTERFACE_STORE)
.isValid()) {
openTab(Constants.TAB_INVENTORY);
}
final int[] items = getInventoryArray();
final java.util.List<Integer> possible = new ArrayList<Integer>();
for (int i = 0; i < items.length; i++) {
if (items[i] == itemID) {
possible.add(i);
}
}
if (possible.size() == 0) {
return false;
}
final int idx = possible.get(random(0, possible.size()));
final Point t = getInventoryItemPoint(idx);
moveMouse(t, 5, 5);
getMenuItems();
final long waitTime = System.currentTimeMillis() + random(50, 250);
boolean found = false;
while (!found && System.currentTimeMillis() < waitTime) {
wait(15);
if (getMenuItems().get(0).toLowerCase().contains(
option.toLowerCase())) {
found = true;
}
}
if (found) {
clickMouse(true);
wait(random(150, 250));
return true;
}
clickMouse(false);
wait(random(150, 250));
return atMenu(option);
}
public boolean onStart(Map<String, String> args) {
antiban = new pyratepigCrafterAntiBan();
t = new Thread(antiban);
potsMade = 0;
levelsGained = 0;
final String FCP = args.get("pottery");
if(FCP.equals("Pot")) {
Pottery = "Pot";
toChoose = 3;
toMake = random(28, 51);
thePot = 1787;
compPot = 1931;
} else if(FCP.equals("Bowl")) {
Pottery = "Bowl";
toChoose = 5;
toMake = random(28, 51);
thePot = 1791;
compPot = 1923;
} else if(FCP.equals("Pie Dish")) {
Pottery = "Pie Dish";
toChoose = 4;
toMake = random(28, 51);
thePot = 1789;
compPot = 2313;
} else if(FCP.equals("Plantpot")) {
Pottery = "Plantpot";
toChoose = 6;
toMake = random(28, 51);
thePot = 5352;
compPot = 5350;
}
if (getCurrentTab() != Constants.TAB_INVENTORY) {
wait(random(2000, 4000));
openTab(Constants.TAB_INVENTORY);
wait(random(200, 400));
}
return true;
}
public Action getAction() {
try {
if (!inventoryContains(clay)) {
if (bank.isOpen()) {
return Action.BANK;
} else if (distanceTo(bankTile) <= 6) {
return Action.OPENBANK;
} else {
if(distanceTo(bankTile) >=12 && getInventoryCount(compPot) >=28)
return Action.WALK_TO_BANK;
}
} else {
if (getMyPlayer().getAnimation() == wheelAnimation || (getMyPlayer().getAnimation() == furnaceAnimation) || !
getInterface(752).isValid()) {
return Action.WAIT;
} else if (getInterface(levelUp).isValid()) {
atInterface(levelUp, 3);
return Action.CLICK;
} else if (distanceTo(furnaceTile) <= 6) {
return Action.DO_WORK;
} else {
if (inventoryContains(clay))
return Action.WALK_TO_FURNACE;
}
}
} catch (final Exception e) {
e.printStackTrace();
}
return Action.ANTIBAN;
}
public int loop() {
if (!t.isAlive()) {
t.start();
status = "Doing AntiBan";
}
try {
switch (getAction()) {
case BANK:
status = "Banking";
if (RSInterface.getInterface(Constants.INTERFACE_BANK).isValid()) {
bank.depositAllExcept(clay);
status = "Withdrawing";
if(!isInventoryFull()){
bank.withdraw(clay, 0);
wait(random(2000, 2130));
if(bank.getItemByID(clay) == null){
log("Not enough clay left! Stopping Script.");
stopScript();
}
}
if(inventoryContains(clay)){
status = "Closing Bank";
bank.close();
}
}
action = Action.WALK_TO_FURNACE;
break;
case OPENBANK:
status = "Opening Bank";
openBank();
break;
case WALK_TO_BANK:
status = "Walking to Bank";
walkPath(furnaceToBank);
break;
case WAIT:
status = "Waiting";
break;
case CLICK:
status = "Clicking Continue";
atInterface(levelUp, 3);
break;
case WALK_TO_FURNACE:
status = "Walking to Furnace";
walkPath(bankToFurnace);
break;
case DO_WORK:
status = "Forming Pots";
final RSInterfaceChild potMaker = getInterface(513, toChoose);
final RSObject whl = getNearestObjectByID(wheel);
final RSObject frn = getNearestObjectByID(furnace);
if (frn == null) {
log("Furnace not found. Please contact Pyratepig.");
wait(random(1200, 2000));
}
if (whl == null) {
log("Pottery wheel not found. Please contact Pyratepig.");
wait(random(1200, 2000));
}
if(canContinue()){
log("Attempting to click Continue.");
clickcontinue();
}
if (RSInterface.getInterface(740).isValid()) {
atInterface(RSInterface.getInterface(740).getChild(3));
}
if (!getInterface(potInterface).isValid()) {
atInventoryItem(clay, "Use");
wait(random(1800, 2000));
atObject(whl, "Use");
wait(random(2000, 2500));
atInterface(potMaker, "Make X");
wait(random(800, 2000));
sendText("28", true);
wait(random(36000, 40000));
if (getInventoryCount(thePot) == 28) {
status = "Firing Pots";
atObject(frn, "Fire");
wait(random(2000, 2500));
atInterface(potMaker, "Make X");
wait(random(1700, 2200));
sendText("28", true);
wait(random(x4, x5));
}
}
break;
}
} catch (final Exception e) {
e.printStackTrace();
}
return random(300, 400);
}
public void serverMessageRecieved(final ServerMessageEvent arg0) {
final String serverString = arg0.getMessage();
if (serverString.contains("You've just advanced")) {
levelsGained++;
log("Level Up! Attempting to click Continue");
clickcontinue();
}
if (serverString.contains("You remove the")) {
potsMade++;
}
if (serverString.contains("You need to play on a members world")) {
log("You need to be a member to make a plantpot. Stopping Script.");
stopScript();
}
if (serverString.contains("wishes to trade with you")) {
sendText("No thanks", true);
}
}
public void onRepaint(Graphics g) {
if(!isLoggedIn() || isLoginScreen()) {
return;
}
long millis = System.currentTimeMillis() - startTime;
final long hours = millis / (1000 * 60 * 60);
millis -= hours * 1000 * 60 * 60;
final long minutes = millis / (1000 * 60);
millis -= minutes * 1000 * 60;
final long seconds = millis / 1000;
final int x = 561;
final int y = 225;
g.setColor(new Color(0, 0, 0, 175));
g.fillRoundRect(555, 210, 175, 250, 10, 10);
g.setColor(Color.black);
g.drawString("Pyratepig's Crafter", x + 1, y + 1);
g.setColor(Color.white);
g.drawString("Pyratepig's Crafter", x, y);
g.setColor(Color.white);
g.drawString("Crafting Level: "+ skills.getCurrentSkillLevel(Constants.STAT_CRAFTING) + "", 561,255);
g.drawString("Pottery Made: " + Integer.toString(potsMade) + "", 561,275);
g.drawString("Levels Gained: " + Integer.toString(levelsGained) + "",561, 295);
g.drawString("EXP Till Next Level: "+ skills.getXPToNextLevel(Constants.STAT_CRAFTING) + "",561, 315);
g.drawString("Percent Till Next Level: "+ skills.getPercentToNextLevel(Constants.STAT_CRAFTING) + "%",561, 365);
g.drawString("Time Running:", 561, 335);
g.drawString("" + hours + ":" + minutes + ":" + seconds + "", 561, 345);
g.drawString("Status: " + status, 561, 395);
}
public void onFinish() {
Bot.getEventManager().removeListener(PaintListener.class, this);
Bot.getEventManager().removeListener(ServerMessageListener.class, this);
antiban.stopThread = true;
log("Thank You for using Pyratepig's Crafter!");
log("Pottery Made: " + potsMade);
log("Levels Gained: " + levelsGained);
}
private int start(final RSTile[] path) {
int start = 0;
for (int a = path.length - 1; a > 0; a--) {
if (tileOnMinimap(path[a])) {
start = a;
break;
}
}
return start;
}
private boolean tileOnMinimap(final RSTile tile) {
final Point p = tileToMinimap(tile);
return Math.sqrt(Math.pow(627 - p.x, 2) + Math.pow(85 - p.y, 2)) < random(
60, 74);
}
private RSTile checkTile(final RSTile tile) {
if (tileOnMap(tile)) {
return tile;
}
final RSTile loc = getMyPlayer().getLocation();
final RSTile walk = new RSTile((loc.getX() + tile.getX()) / 2, (loc
.getY() + tile.getY()) / 2);
return tileOnMap(walk) ? walk : checkTile(walk);
}
private boolean walkPath(final RSTile[] path) {
for (int i = start(path); i < path.length; i++) {
if (!isRunning() && getEnergy() > random(40, 60)) {
clickMouse(random(707, 762), random(90, 121), true);
}
walkTo(randomizeTile(path[i], 1, 1));
waitToMove(2000);
if (path[i] == path[path.length - 1]) {
break;
}
while (!tileOnMinimap(path[i + 1])) {
if (!getMyPlayer().isMoving()) {
walkTo(checkTile(randomizeTile(path[i + 1], 1, 1)));
}
}
}
return distanceTo(path[path.length - 1]) <= 4;
}
private class PyratepigCrafterAntiBan implements Runnable {
public boolean stopThread;
public void run() {
while (!stopThread) {
try {
if (random(0, 15) == 0) {
final char[] LR = new char[] { KeyEvent.VK_LEFT,
KeyEvent.VK_RIGHT };
final char[] UD = new char[] { KeyEvent.VK_DOWN,
KeyEvent.VK_UP };
final char[] LRUD = new char[] { KeyEvent.VK_LEFT,
KeyEvent.VK_RIGHT, KeyEvent.VK_UP,
KeyEvent.VK_UP };
final int random2 = random(0, 2);
final int random1 = random(0, 2);
final int random4 = random(0, 4);
if (random(0, 3) == 0) {
Bot.getInputManager().pressKey(LR[random1]);
Thread.sleep(random(100, 400));
Bot.getInputManager().pressKey(UD[random2]);
Thread.sleep(random(300, 600));
Bot.getInputManager().releaseKey(UD[random2]);
Thread.sleep(random(100, 400));
Bot.getInputManager().releaseKey(LR[random1]);
} else {
Bot.getInputManager().pressKey(LRUD[random4]);
if (random4 > 1) {
Thread.sleep(random(300, 600));
} else {
Thread.sleep(random(500, 900));
}
Bot.getInputManager().releaseKey(LRUD[random4]);
}
} else {
Thread.sleep(random(200, 2000));
}
} catch (final Exception e) {
e.printStackTrace();
}
}
}
}
}