package scripts;
import com.sun.corba.se.spi.orbutil.fsm.State;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.rsbot.bot.Bot;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Calculations;
import org.rsbot.script.Constants;
import org.rsbot.script.Methods;
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.RSItem;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;
@ScriptManifest(authors = { "Author" }, category = "Tutorial",
name = "Skeleton Script", version = 1.0,
description = "Description Box.")
public class skeleton extends Script implements PaintListener {
// Type values here...
public State state;
//Runs at beginning of script.
public boolean onStart(final Map<String, String> args) {
return true;
}
// States of Script
public enum State {
WALKING, POOPING, FARTING, SELLING;
}
// The actually function.
public int loop() {
return 0;
}
// Finish
public void onFinish() {
}
// Paint
public void onRepaint(final Graphics g) {
}
// Old functions.
// Asking for four variables, lowest possible place you could be,
// highest, most left, and most right.
public boolean amIThere(int lowX, int highX, int lowY, int highY){
// Checks if I am between or on the most left place and the most right
// place.
if(getLocation().getX() < highX + 1 && getLocation().getX() > lowX - 1){
// Checks if I am between or on the highest place and the lowest
// place.
if(getLocation().getY() < highY + 1 && getLocation().getY() > lowY - 1){
return true;
}
}
// If I am not within the plane of the four points, then
// return false and say I am not there!
return false;
}
public boolean walkGoodPath(final RSTile[] tilearray, final boolean forward) {
int i;
final int arrl = tilearray.length - 1;
if (forward) {
for (i = 0; i <= arrl; i++) {
if (distanceTo(tilearray[i]) < random(6, 8)) {
i++;
break;
}
}
if (i > arrl) {
i = arrl;
}
if (distanceTo(tilearray[arrl]) < random(8, 10)) {
walkTileMM(tilearray[arrl]);
return true;
}
if (distanceTo(getDestination()) < random(6, 8)) {
walkTileMM(tilearray[i]);
}
} else {
for (i = arrl; i >= 0; i--) {
if (distanceTo(tilearray[i]) < random(6, 8)) {
i--;
break;
}
}
if (i < 0) {
i = 0;
}
if (distanceTo(tilearray[0]) < random(8, 10)) {
walkTileMM(tilearray[0]);
return true;
}
if (distanceTo(getDestination()) < random(6, 8)) {
walkTileMM(tilearray[i]);
}
}
return false;
}
public boolean atBankItem(final int itemID, final String txt) {
if (!isLoggedIn() || !bank.isOpen()) {
return false;
}
final int[] itemArray = bank.getItemArray();
for (int off = 0; off < itemArray.length; off++) {
if (itemArray[off] == itemID) {
final Point p = bank.getItemPoint(off);
if (p.y < 87 || p.y > 291) {
while (bank.isOpen()) {
bank.close();
}
while (isLoggedIn()) {
logout();
}
log("Item not on bank screen. Logging out!");
stopScript();
return false;
}
moveMouse(p, 5, 5);
final long waitTime = System.currentTimeMillis()
+ random(50, 250);
boolean found = false;
while (!found && System.currentTimeMillis() < waitTime) {
wait(15);
if (getMenuItems().get(0).toLowerCase().contains(
txt.toLowerCase())) {
found = true;
}
}
if (found) {
clickMouse(true);
wait(random(150, 250));
return true;
}
clickMouse(false);
wait(random(150, 250));
return atMenu(txt);
}
}
return false;
}
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 atMenuItem(final int i) {
if (!isMenuOpen()) {
return false;
}
try {
final RSTile menu = getMenuLocation();
final List<String> items = getMenuItems();
int longest = 0;
for (final String s : items) {
if (s.length() > longest) {
longest = s.length();
}
}
final int xOff = random(4, longest * 4);
final int yOff = random(21, 29) + 15 * i;
clickMouse(menu.getX() + xOff, menu.getY() + yOff, 2, 2, true);
return true;
} catch (final Exception e) {
e.printStackTrace();
return false;
}
}
public boolean atTile(final RSTile tile, final String option) {
final Point p = Calculations.tileToScreen(tile);
p.x += random(-5, 6);
p.y += random(-5, 6);
if (p.x < 0 || p.y < 0) {
return false;
}
moveMouse(p);
// wait(random(100,150));
getMenuItems();
final long waitTime = System.currentTimeMillis() + random(50, 250);
boolean found = false;
while (System.currentTimeMillis() < waitTime && !found) {
wait(15);
found = getMenuItems().get(0).toLowerCase().contains(
option.toLowerCase());
}
if (found) {
clickMouse(true);
wait(random(150, 300));
return true;
}
clickMouse(false);
wait(random(150, 300));
return atMenu(option);
}
public int bankCount(final int itemID) {
final int[] itemArray = bank.getItemArray();
int count = 0;
for (final int element : itemArray) {
if (element == itemID) {
count++;
}
}
return count;
}
}