import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.util.Map;
import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.events.ServerMessageEvent;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.event.listeners.ServerMessageListener;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.RSInterface;
import com.speljohan.rsbot.script.wrappers.RSObject;
import com.speljohan.rsbot.script.wrappers.RSTile;
public class AllSmelter extends Script implements ServerMessageListener,
PaintListener {
private char type;
private RSTile[] falador = new RSTile[] { new RSTile(2946, 3370),
new RSTile(2953, 3380), new RSTile(2967, 3378),
new RSTile(2974, 3370) }, alKharid = new RSTile[] {
new RSTile(3271, 3169), new RSTile(3277, 3176),
new RSTile(3276, 3186) }, path;
private int amount, tries = 0, smelted = 0, oreOne, oreTwo, busy = 0,
bankID = 35647;
private RSTile furnaceClick;
private final int wait1 = 350, wait2 = 500, ringID = 2568, barID = 2353,
cannonMould = 4;
private final long startTime = System.currentTimeMillis();
private boolean smelting = false, ring = false;
private String bar, doing;
public String getName() {
return "All Smelter";
}
public String getAuthor() {
return "Fusion89k";
}
public double getVersion() {
return 1.5;
}
public String getScriptCategory() {
return "Smelting";
}
public String getScriptDescription() {
return "<html>\n"
+ "<head></head>\n"
+ "<body>\n"
+ "<center>"
+ "<h2>"
+ getName()
+ "</h2>"
+ "</center>\n"
+ "<b>Author:</b> "
+ getAuthor()
+ "<br />"
+ "<b>Version:</b> "
+ getVersion()
+ "<br><form>"
+ "Bar Type: <select name='bar'>"
+ "<option>Bronze<option>Iron<option>Silver<option>Steel<option>Gold<option>Mithril<option>Adamant<option>Rune<option>CannonBall"
+ "</select>"
+ "<br>How many ores you have:<input type='text' name='amount' size='8'>"
+ "<br>Al Kharid: <input type='radio' name='city' value='0' checked='checked'>    Falador: <input type='radio' name='city' value='1'>"
+ "<br>Ring of Forging: <input type='checkbox' name='ring' value='1'>"
+ "</form></body>\n" + "</html>";
}
public boolean onStart(Map<String, String> args) {
doing = "Starting";
bar = args.get("bar");
type = bar.toLowerCase().charAt(0);
if (type == 's') {
if (bar.toLowerCase().charAt(1) == 'i')
type = 'e';
}
try {
log(args.get("amount"));
amount = Integer.parseInt(args.get("amount"));
} catch (Exception e) {
log("Invalid Amount");
return false;
}
if (args.get("ring") != null)
ring = true;
if (Integer.parseInt(args.get("city")) == 0) {
path = alKharid;
furnaceClick = new RSTile(3273, 3186);
log("In Al Kharid");
} else {
bankID = 11758;
path = falador;
furnaceClick = new RSTile(2976, 3369);
log("In Falador");
}
Bot.getEventManager().addListener(PaintListener.class, this);
doing = "Started";
return true;
}
public void onFinish() {
Bot.getEventManager().removeListener(PaintListener.class, this);
}
public int loop() {
setCameraAltitude(true);
setCompass('w');
if (amount <= 0) {
log("Out of Ore");
stopAllScripts();
}
if (isMoving())
return random(0, 150);
if (smelting && getMyPlayer().getAnimation() == -1) {
if (distanceTo(furnaceClick) > 2)
walkTileMM(path[path.length - 1]);
busy++;
if (busy > 3)
smelting = false;
return random(wait1, wait2);
} else
busy = 0;
if (!canMakeBar()) {
busy = 5;
smelting = false;
if (distanceTo(path[0]) > 4) {
doing = "Walking to Bank";
walk(true);
return random(wait1, wait2);
}
if (!RSInterface.getInterface(INTERFACE_BANK).isValid()) {
doing = "Finding Bank";
RSObject booth = findObject(bankID);
if (booth == null)
return random(wait1, wait2);
atObject(booth, "Use-Quickly");
return random(wait1, wait2);
}
if (RSInterface.getInterface(INTERFACE_BANK).isValid()) {
doing = "Depositing";
bank.depositAllExcept(453, cannonMould);
doing = "Withdrawing";
withdrawOre();
pause();
if (!canMakeBar()) {
tries++;
return random(wait1, wait2);
}
tries = 0;
doing = "Closing Bank";
bank.close();
}
return random(wait1, wait2);
} else {
if (smelting) {
busy = 0;
return random(wait1, wait2);
}
if (distanceTo(path[path.length - 1]) > 4) {
doing = "Walking to Furnace";
walk(false);
return random(wait1, wait2);
}
if (!RSInterface.getInterface(INTERFACE_SMELTINGSCREEN).isValid()) {
if (getMyPlayer().getAnimation() != -1) {
busy = 0;
smelting = true;
return random(wait1, wait2);
}
doing = "Finding Furnace";
if (type == 'c') {
useItemCustom(barID, furnaceClick);
wait(random(wait1, wait2));
smeltOre();
} else
atTile(furnaceClick, "Smelt");
return random(wait1, wait2);
}
if (RSInterface.getInterface(INTERFACE_SMELTINGSCREEN).isValid())
smeltOre();
return random(wait1, wait2);
}
}
private void smeltOre() {
doing = "Smelting";
int minX = 28, maxX = 78;
int minY = 390, maxY = 457;
switch (type) {
case 'i':// Iron
minX = 130;
maxX = 178;
break;
case 'e':
minX = 182;
maxX = 229;
break;
case 's':// Steel
minX = 234;
maxX = 279;
break;
case 'g':
minX = 286;
maxX = 333;
break;
case 'm':// Mithril
minX = 338;
maxX = 387;
break;
case 'a':// Adamant
minX = 390;
maxX = 441;
break;
case 'r':// Rune
minX = 442;
maxX = 496;
break;
case 'c':
minX = 88;
maxX = 429;
clickMouse(new Point(random(minX, maxX), random(minY, maxY)), false);
wait(random(100, 200));
atMenu("All");
smelting = true;
return;
}
clickMouse(new Point(random(minX, maxX), random(minY, maxY)), false);
int ore1 = getInventoryArray()[1];
int temp = getInventoryCount(ore1);
if (getInventoryCount(ore1) > 10)
temp = random(getInventoryCount(ore1), getInventoryCount(ore1) + 5);
if (temp == 1)
atMenu("1");
else if (temp <= 10)
atMenu("10");
else {
atMenu("Smelt x");
pause();
pause();
if (!sendTextCustom("" + temp)) {
smeltOre();
}
}
smelting = true;
}
private void withdrawOre() {
int x = random(38, 73), y = random(92, 123);
int x2 = random(82, 117), y2 = random(92, 123);
switch (type) {
case 'b':
if (getInventoryCount(oreOne) < 1) {
clickMouse(x, y, false);
if (getMenuIndex("14") < 0 || amount < 14) {
atMenu("X");
pause();
pause();
if (!sendTextCustom(amount < 14 ? "" + amount : "14"))
withdrawOre();
} else
atMenu("14");
pause();
if (getInventoryCount(oreOne) < 1) {
pause();
withdrawOre();
}
}
if (amount <= 14)
clickMouse(x, y, false);
else
clickMouse(x2, y2, false);
atMenu("All");
break;
case 'e':
case 'g':
case 'i':
if (ring && !isCarryingItem(ringID) && type == 'i') {
clickMouse(x2, y2, false);
atMenu("1");
bank.close();
atInventoryItem(ringID, "Wear");
break;
}
clickMouse(x, y, false);
atMenu("All");
break;
case 's':
if (getInventoryCount(oreOne) < 1) {
clickMouse(x, y, false);
if (getMenuIndex("9") < 0 || amount < 9) {
atMenu("X");
pause();
pause();
if (!sendTextCustom(amount < 9 ? "" + amount : "9"))
withdrawOre();
} else
atMenu("9");
pause();
if (getInventoryCount(oreOne) < 1) {
pause();
withdrawOre();
}
}
if (amount <= 9)
clickMouse(x, y, false);
else
clickMouse(x2, y2, false);
atMenu("All");
break;
case 'm':
if (getInventoryCount(oreOne) < 1) {
clickMouse(x, y, false);
if (getMenuIndex("5") < 0 || amount < 5) {
atMenu("X");
pause();
pause();
if (!sendTextCustom(amount < 5 ? "" + amount : "5"))
withdrawOre();
} else
atMenu("5");
pause();
if (getInventoryCount(oreOne) < 1) {
pause();
withdrawOre();
}
}
if (amount <= 5)
clickMouse(x, y, false);
else
clickMouse(x2, y2, false);
atMenu("All");
break;
case 'a':
if (getInventoryCount(oreOne) < 1) {
clickMouse(x, y, false);
if (getMenuIndex("4") < 0 || amount < 4) {
atMenu("X");
pause();
pause();
if (!sendTextCustom(amount < 4 ? "" + amount : "4"))
withdrawOre();
} else
atMenu("4");
pause();
if (getInventoryCount(oreOne) < 1) {
pause();
withdrawOre();
}
}
if (amount <= 4)
clickMouse(x, y, false);
else
clickMouse(x2, y2, false);
atMenu("All");
break;
case 'r':
if (getInventoryCount(oreOne) < 1) {
clickMouse(x, y, false);
if (getMenuIndex("3") < 0 || amount < 3) {
atMenu("X");
pause();
pause();
if (!sendTextCustom(amount < 3 ? "" + amount : "3"))
withdrawOre();
} else
atMenu("3");
pause();
if (getInventoryCount(oreOne) < 1) {
pause();
withdrawOre();
}
}
if (amount <= 3)
clickMouse(x, y, false);
else
clickMouse(x2, y2, false);
atMenu("All");
break;
case 'c':
if (getInventoryCount(4) < 1) {
clickMouse(x2, y2, true);
pause();
withdrawOre();
} else {
clickMouse(x, y, false);
atMenu("All");
}
break;
}
pause();
}
private boolean canMakeBar() {
oreTwo = 453;
int coal = getInventoryCount(oreTwo);
switch (type) {
case 'b':
oreOne = 436;
oreTwo = 438;
int copper = getInventoryCount(oreOne),
tin = getInventoryCount(oreTwo);
if (copper == 0 || tin == 0)
return false;
break;
case 'i':
oreOne = 440;
int iron = getInventoryCount(oreOne);
if (iron <= 0)
return false;
break;
case 'e':
oreOne = 442;
int silver = getInventoryCount(oreOne);
if (silver <= 0)
return false;
break;
case 's':
oreOne = 440;
int steel = getInventoryCount(oreOne);
if (coal < steel * 2 || steel == 0)
return false;
break;
case 'g':
oreOne = 444;
int gold = getInventoryCount(oreOne);
if (gold <= 0)
return false;
break;
case 'm':
oreOne = 447;
int mith = getInventoryCount(oreOne);
if (coal < mith * 4 || mith == 0)
return false;
break;
case 'a':
oreOne = 449;
int addy = getInventoryCount(oreOne);
if (coal < addy * 6 || addy == 0)
return false;
break;
case 'r':
oreOne = 451;
int rune = getInventoryCount(oreOne);
if (coal < rune * 8 || rune == 0)
return false;
break;
case 'c':
if (!inventoryContains(barID) || !inventoryContains(cannonMould))
return false;
break;
}
return true;
}
private void walk(boolean toBank) {
if (getEnergy() > random(60, 100))
setRun(true);
RSTile start = locate();
int loc = 0;
for (int i = 0; i < path.length; i++) {
if (start.equals(path[i])) {
loc = i;
break;
}
}
if (toBank) {
if (loc == 0) {
walkTileMM(randomTile(path[0]));
return;
}
walkTileMM(randomTile(path[loc - 1]));
} else {
if (loc == path.length - 1) {
walkTileMM(randomTile(path[path.length - 1]));
return;
}
walkTileMM(randomTile(path[loc + 1]));
}
}
private RSTile locate() {
RSTile min = path[0];
for (int i = 1; i < path.length; i++) {
if (distanceTo(path[i]) < distanceTo(min))
min = path[i];
}
return min;
}
private RSTile randomTile(RSTile location) {
return randomTile(location, 2);
}
private RSTile randomTile(RSTile location, int diff) {
int x = location.getX(), y = location.getY();
return new RSTile(random(x - diff, x + diff),
random(y - diff, y + diff));
}
private void pause() {
wait(random(500, 800));
}
private void useItemCustom(int item, RSTile tile) {
if (getCurrentTab() != TAB_INVENTORY) {
openTab(TAB_INVENTORY);
}
atInventoryItem(item, "Use");
atTile(tile, "furnace");
}
private boolean sendTextCustom(String text) {
sendText(text, false);
String sent = RSInterface.getChildInterface(137, 51).getText();
if (sent.length() > 2
&& Character.toString(sent.charAt(sent.length() - 2)).equals(
">")) {
sendKey((char) KeyEvent.VK_ENTER);
return true;
}
for (int i = 0; i < text.length() + 1; i++) {
sendKey((char) KeyEvent.VK_BACK_SPACE);
}
return false;
}
private boolean isMoving() {
if (!getMyPlayer().isMoving())
return false;
RSTile here = locate();
int index = 0;
for (int i = 0; i < path.length; i++) {
if (here.equals(path[i]))
index = i;
}
if ((index != 0 && index != path.length - 1)
&& distanceTo(getDestination()) < 5)
return false;
return true;
}
public void serverMessageRecieved(ServerMessageEvent e) {
String word = e.getMessage().toLowerCase();
if (word.contains("advanced")) {
smelting = false;
} else if (word.contains("retrieve")) {
smelted++;
amount--;
} else if (word.contains("fail")) {
amount--;
} else if (word.contains("cannon")) {
amount--;
smelted += 4;
} else if (word.contains("space")) {
int full = getInventoryCount(getInventoryArray()[getInventoryArray().length - 1]);
switch (type) {
case 'b':
if (full <= 14)
return;
case 's':
if (full <= 19)
return;
case 'm':
if (full <= 23)
return;
case 'a':
if (full <= 24)
return;
case 'r':
if (full <= 25)
return;
}
bank.depositAll();
}
}
public void onRepaint(Graphics g) {
if (isLoggedIn()) {
long millis = System.currentTimeMillis() - startTime;
long hours = millis / (1000 * 60 * 60);
millis -= hours * (1000 * 60 * 60);
long minutes = millis / (1000 * 60);
millis -= minutes * (1000 * 60);
long seconds = millis / 1000;
int topX = 515 - 173, topY = 337 - 80, x = topX + 5, y = topY + 5;
g.setColor(new Color(0, 100, 0, 100));
g.fill3DRect(topX, topY, 515 - topX, 337 - topY, true);
g.setColor(Color.green);
g.drawString("Runtime: " + hours + "h " + minutes + "min "
+ seconds + "sec.", x, y += 15);
g.drawString("Ore Left: " + Integer.toString(amount), x, y += 15);
g.drawString("Bars: " + Integer.toString(smelted) + " " + bar
+ " Bars.", x, y += 15);
g.drawString("Status: " + doing, x, y += 15);
}
}
}