import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import com.speljohan.rsbot.bot.*;
import com.speljohan.rsbot.event.events.*;
import com.speljohan.rsbot.event.listeners.*;
import com.speljohan.rsbot.script.*;
import com.speljohan.rsbot.script.wrappers.*;
import com.speljohan.rsbot.accessors.*;
public class TAIOWoodcutter extends Script implements PaintListener, ServerMessageListener {
/*Will currently text after 20 minutes!*/
int TEXT_ME_AFTER = 20 * 60 * 1000;
String myServer = "http://SERVER_HERE.com/mail.php";
double version = 1.2;
int[] treeID;
int[] bankID;
int[] neededIDs = {1359, 1357, 1355, 1353, 1361, 1351, 1349, 13661, 6739};
int[] nestIDs = {5070, 5071, 5072, 5073, 5074, 5075, 5076, 7413, 11966}; //Taken from Draggin's modded TAIO.
boolean bankerIsNPC = false;
boolean gotEXP = false;
boolean emailing = false;
int hours, minutes, seconds, time, startTime, EXP, startExp, lvl, cut;
RSTile[] Trees2Bank;
RSTile[] Bank2Trees;
RSObject tree = null;
RSObject bankBooth = null;
RSNPC banker = null;
String loc;
String email = null;
long lastCheck = System.currentTimeMillis();
//Easier way to declare all the stuff for RSBot to read in the script selector.
public TAIOWoodcutter() {
setParameter("author", "!@!@!");
setParameter("version", version);
setParameter("name", "TAIOWoodcutter");
setParameter("category", "!@!@!/Woodcutting");
setParameter("description", disc());
}
public String disc() {
/*Used profisher's and changed it a little. */
String html = "";
html += "
";
html += "";
html += "" + getName() + " v" + getVersion() + "
";
html += "By: !@!@!
";
html += "| ";
html += " |
";
html += "";
html += "";
return html;
}
//Called on start up.
public boolean onStart(Map args) {
loc = args.get("locAndTree");
gotEXP = false;
if(JOptionPane.showInputDialog("Want to use email/SMS proggies?").contains("y")) {
email = JOptionPane.showInputDialog("email?");
emailing = true;
}
if(args.get("locAndTree").equals("Trees - Draynor")) {
Trees2Bank = new RSTile[] {
new RSTile(3082,3269),new RSTile(3082,3263),
new RSTile(3081,3257),new RSTile(3081,3251),
new RSTile(3087,3249),new RSTile(3092,3245)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1276, 1278};
bankID = new int[] {2213};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Oaks - Draynor")) {
Trees2Bank = new RSTile[] {
new RSTile(3082,3299),new RSTile(3077,3295),
new RSTile(3079,3289),new RSTile(3079,3283),
new RSTile(3085,3279),new RSTile(3083,3273),
new RSTile(3083,3267),new RSTile(3082,3261),
new RSTile(3082,3255),new RSTile(3086,3250),
new RSTile(3092,3247)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1281};
bankID = new int[] {2213};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Oaks - East Varrock")) {
Trees2Bank = new RSTile[] {
new RSTile(3278,3428),new RSTile(3272,3428),
new RSTile(3266,3428),new RSTile(3259,3428),
new RSTile(3253,3426),new RSTile(3254,3420),
new RSTile(3253,3421)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1281};
bankID = new int[] {11402};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Willows - Port Sarim")) {
Trees2Bank = new RSTile[] {
new RSTile(3060,3254),new RSTile(3062,3260),
new RSTile(3066,3266),new RSTile(3067,3272),
new RSTile(3072,3267),new RSTile(3078,3264),
new RSTile(3080,3258),new RSTile(3084,3253),
new RSTile(3089,3249),new RSTile(3093,3244)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1308};
bankID = new int[] {2213};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Willows - Draynor")) {
Trees2Bank = new RSTile[] {
new RSTile(3087,3234),new RSTile(3087,3240),
new RSTile(3087,3246),new RSTile(3093,3243),
new RSTile(3093,3243)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {5551,5552,5553};
bankID = new int[] {2213};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Willows - Catherby")) {
Trees2Bank = new RSTile[] {
new RSTile(2784,3428),new RSTile(2790,3432),
new RSTile(2796,3433),new RSTile(2802,3433),
new RSTile(2808,3436)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {5551,5552,5553};
bankID = new int[] {2213};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Willows - Seers")) {
Bank2Trees = new RSTile[] {
new RSTile(2725,3492),new RSTile(2725,3486),
new RSTile(2720,3490),new RSTile(2718,3496),
new RSTile(2718,3502),new RSTile(2713,3506),
new RSTile(2711,3509)
};
Trees2Bank = reversePath(Bank2Trees);
treeID = new int[] {5551,5552,5553};
bankID = new int[] {25808};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Maples - Seers")) {
Bank2Trees = new RSTile[] {
new RSTile(2725,3492),new RSTile(2726,3486),
new RSTile(2731,3490),new RSTile(2732,3496),
new RSTile(2726,3500),new RSTile(2726,3501)
};
Trees2Bank = reversePath(Bank2Trees);
treeID = new int[] {1307};
bankID = new int[] {25808};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Yews - Rimmington")) {
Trees2Bank = new RSTile[] {
new RSTile(2936,3233),new RSTile(2942,3236),
new RSTile(2948,3239),new RSTile(2954,3243),
new RSTile(2959,3248),new RSTile(2963,3253),
new RSTile(2967,3258),new RSTile(2971,3264),
new RSTile(2976,3268),new RSTile(2980,3273),
new RSTile(2986,3277),new RSTile(2986,3283),
new RSTile(2987,3289),new RSTile(2991,3295),
new RSTile(2993,3301),new RSTile(2994,3307),
new RSTile(2999,3311),new RSTile(3000,3317),
new RSTile(3005,3322),new RSTile(3005,3328),
new RSTile(3006,3334),new RSTile(3007,3340),
new RSTile(3007,3346),new RSTile(3007,3352),
new RSTile(3007,3358),new RSTile(3013,3356)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1309};
bankID = new int[] {11758};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Yews - Seers Church")) {
Trees2Bank = new RSTile[] {
new RSTile(2710,3462),new RSTile(2716,3462),
new RSTile(2719,3468),new RSTile(2723,3474),
new RSTile(2726,3480),new RSTile(2726,3486),
new RSTile(2725,3490)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1309};
bankID = new int[] {25808};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Yews - Catherby")) {
Bank2Trees = new RSTile[] {
new RSTile(2809,3440),new RSTile(2805,3435),
new RSTile(2799,3433),new RSTile(2793,3433),
new RSTile(2787,3432),new RSTile(2780,3432),
new RSTile(2776,3427),new RSTile(2771,3431),
new RSTile(2759,3430)
};
Trees2Bank = reversePath(Bank2Trees);
treeID = new int[] {1309};
bankID = new int[] {2213};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Yews - Varrock (GE)")) {
Trees2Bank = new RSTile[] {
new RSTile(3212,3502),new RSTile(3206,3502),
new RSTile(3200,3502),new RSTile(3199,3496),
new RSTile(3194,3491),new RSTile(3188,3488),
new RSTile(3182,3488),new RSTile(3175,3488),
new RSTile(3169,3489),new RSTile(3169,3489)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1309};
bankID = new int[] {6533, 6534, 6535, 6532};
bankerIsNPC = true;
}
if(args.get("locAndTree").equals("Magics (South) - Seers")) {
Trees2Bank = new RSTile[] {
new RSTile(2702,3398),new RSTile(2704,3392),
new RSTile(2710,3396),new RSTile(2715,3401),
new RSTile(2715,3407),new RSTile(2715,3413),
new RSTile(2714,3419),new RSTile(2716,3425),
new RSTile(2717,3431),new RSTile(2713,3436),
new RSTile(2710,3442),new RSTile(2712,3450),
new RSTile(2717,3455),new RSTile(2718,3461),
new RSTile(2720,3467),new RSTile(2722,3473),
new RSTile(2725,3479),new RSTile(2727,3485),
new RSTile(2725,3491)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1306};
bankID = new int[] {25808};
bankerIsNPC = false;
}
if(args.get("locAndTree").equals("Magics (North) - Seers")) {
Trees2Bank = new RSTile[] {
new RSTile(2694,3425),new RSTile(2700,3425),
new RSTile(2702,3431),new RSTile(2706,3437),
new RSTile(2708,3443),new RSTile(2712,3448),
new RSTile(2716,3454),new RSTile(2721,3461),
new RSTile(2723,3467),new RSTile(2723,3473),
new RSTile(2725,3479),new RSTile(2726,3485),
new RSTile(2726,3491)
};
Bank2Trees = reversePath(Trees2Bank);
treeID = new int[] {1306};
bankID = new int[] {25808};
bankerIsNPC = false;
}
startTime = (int) System.currentTimeMillis();
startExp = (int) skills.getCurrentSkillExp(STAT_WOODCUTTING);
Bot.getEventManager().addListener(this);
return true;
}
//Called on shutdown.
public void onFinish() {
log("Stopping script...");
Bot.getEventManager().removeListener(this);
}
public String runTime() {
time = (int) System.currentTimeMillis() - startTime;
seconds = (time / 1000);
if (seconds >= 60) {
minutes = (seconds / 60);
seconds -= (minutes * 60);
}
if (minutes >= 60) {
hours = (minutes / 60);
minutes -= (hours * 60);
}
return hours + ":" + minutes + ":" + seconds;
}
public void onRepaint(Graphics x) {
time = (int) System.currentTimeMillis() - startTime;
seconds = (time / 1000);
if (seconds >= 60) {
minutes = (seconds / 60);
seconds -= (minutes * 60);
}
if (minutes >= 60) {
hours = (minutes / 60);
minutes -= (hours * 60);
}
x.setColor(Color.BLACK);
x.fill3DRect(315,350,150,105,true);
x.setColor(Color.RED);
x.drawString("TAIOWoodcutter v"+version, 325,370);
x.drawString(loc, 325,385);
x.drawString("Time Running:" + runTime(),325,400);
lvl = skills.getRealSkillLevel(STAT_WOODCUTTING);
EXP = skills.getCurrentSkillExp(STAT_WOODCUTTING);
x.drawString("Current wc lvl: "+ lvl,325,415);
x.drawString("Exp gained: " + (EXP - startExp), 325,430);
x.drawString("Logs cut: " + cut, 325,445);
}
//The loop obviously...
public int loop() {
tree = getNearestTreeByID(treeID);
RSItemTile nest = getGroundItemByID(10, nestIDs);
if(!bankerIsNPC) {
bankBooth = getNearestObjectByID(bankID);
}
if(bankerIsNPC) {
banker = getNearestNPCByID(bankID);
}
if(checkText() && emailing) {
try {
sendText(email, "Bot: "+Bot.getAccount().getUsername() +" || Ran for: " + runTime() +" || Logs cut: "+cut+" || Exp gained: " + (skills.getCurrentSkillExp(STAT_WOODCUTTING) - startExp) + " || WC lvl: " + skills.getRealSkillLevel(STAT_WOODCUTTING));
} catch (Exception e) {
e.printStackTrace();
return 100;
}
}
if(getMyPlayer().isInCombat()) {
runAway();
return random(1000, 2000);
}
if(getEnergy() > random(30, 90)) {
setRun(true);
}
if(isEnt()) {
handleEnt();
return random(1000, 2000);
}
if(getMyPlayer().isMoving()) {
return random(10, 200);
}
if(nest != null) {
if(tileOnScreen(nest)) {
atTile(nest, "Take");
waitWhileMoving();
return random(300, 500);
} else if(!tileOnScreen(nest)) {
walkTileMM(nest);
waitWhileMoving();
return random(1000, 2000);
}
}
if(getMyPlayer().getAnimation() != -1) {
antiBan();
return random(500, 900);
}
if(isLost()) {
stopAllScripts();
return -1;
}
if(interfaceCheck()) {
return random(1000, 2000);
}
if(tree == null && distanceTo(Trees2Bank[0]) <= 6) {
antiBan();
return random(100, 200);
}
if(tree == null && distanceTo(Trees2Bank[0]) > 7 && distanceTo(Trees2Bank[0]) < 18) {
try {
walkTileMM(Trees2Bank[0]);
waitWhileMoving();
return random(1200, 1700);
} catch (Exception e) {
log("Dirty fix called. :/");
return random(200, 800);
}
}
if(tree != null && !isInventoryFull() && tree.getLocation().isValid() && distanceTo(Trees2Bank[0]) < 15 && getMyPlayer().getAnimation() == -1) {
if(tileOnScreen(tree.getLocation())) {
if(!atTree(tree.getLocation(), "Chop down")) {
turnCamera();
}
waitWhileMoving();
return random(1000, 1200);
}
if(!tileOnScreen(tree.getLocation()) && distanceToTreeIsGood(tree)) {
try {
walkTileMM(nearClearTile(tree.getLocation()));
waitWhileMoving();
return random(200, 700);
} catch (Exception e) {
log("Dirty fix called. :/");
return random(200, 800);
}
}
}
if(isInventoryFull() && distanceTo(Bank2Trees[0]) <= 5) {
if(!RSInterface.getInterface(INTERFACE_BANK).isValid()) {
waitWhileMoving();
if(!bankerIsNPC) {
boolean failed = true;
for(int i = 0; i < 5; i++) {
while(failed) {
if(!tileOnScreen(bankBooth.getLocation())) {
break;
}
if(atObject(bankBooth, "Use-quickly")) {
failed = false;
}
waitWhileMoving();
}
}
if(failed) {
walkTileMM(nearClearTile(bankBooth.getLocation()));
waitWhileMoving();
}
}
if(bankerIsNPC) {
boolean failed = true;
for(int i = 0; i < 5; i++) {
while(failed) {
if(!tileOnScreen(banker.getLocation())) {
break;
}
if(atNPC(banker, "Bank Banker")) {
failed = false;
}
waitWhileMoving();
}
}
if(failed) {
walkTileMM(nearClearTile(banker.getLocation()));
waitWhileMoving();
}
}
}
if(RSInterface.getInterface(INTERFACE_BANK).isValid()) {
while(depositAllItems());
if(tree != null && tileOnScreen(tree.getLocation()) || random(0, 3) == 2) {
atInterface(INTERFACE_BANK, INTERFACE_BANK_BUTTON_CLOSE);
}
}
return random(500, 800);
}
while(isInventoryFull() && distanceTo(Bank2Trees[0]) > 3) {
walkPathMM(randomizePath(Trees2Bank, 2, 2), 15);
waitTilCloseToStop();
}
while(!isInventoryFull() && distanceTo(Trees2Bank[0]) > 7) {
walkPathMM(randomizePath(Bank2Trees, 2, 2), 15);
waitTilCloseToStop();
}
return random(200, 300);
}
public boolean checkText() {
if(lastCheck + TEXT_ME_AFTER < System.currentTimeMillis()) {
lastCheck = System.currentTimeMillis();
return true;
}
return false;
}
public void sendText(String email, String message) throws Exception {
email = encode(email);
message = encode(message);
URL mailScript = new URL(myServer+"?to="+email+"&m="+message);
URLConnection con = mailScript.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String src;
if((src = in.readLine()) != null) {
if(src.contains("Sent the email")) {
System.out.println("Sent the text successfully.");
}
}
}
public String encode(String src) {
src = src.replace(" ","%20");
src = src.replace("@", "%40");
src = src.replace("|","%7C");
src = src.replace(":", "%3A");
return src;
}
//Just my antiBan void.
public void antiBan() {
int x = random(0, 30);
switch(x) {
case 1:
turnCamera();
break;
case 2:
moveMouse(0, 0, random(0, 750), random(0, 500));
break;
case 3:
moveMouse(0, 0, random(0, 750), random(0, 500));
break;
case 4:
if(random(0, 3) == 0) {
tab(true);
break;
}
tab(false);
break;
}
}
public void tab(boolean stupid) {
int[] nonStupidTabs = {TAB_CLAN, TAB_FRIENDS, TAB_INVENTORY, TAB_MUSIC, TAB_OPTIONS, TAB_STATS};
if(stupid) {
int i = random(0, 14);
if(getCurrentTab() != i) {
openTab(i);
}
} else if(!stupid) {
int i = random(0, nonStupidTabs.length - 1);
if(getCurrentTab() != i) {
openTab(i);
}
}
}
public boolean isLost() {
for(RSTile tile : Trees2Bank) {
if(distanceTo(tile) <= 16) {
return false;
}
}
return true;
}
public boolean depositAllItems() {
if(!RSInterface.getInterface(INTERFACE_BANK).isValid()) {
return false;
}
int[] items = getInventoryArray();
for (int item : items) {
if(itemIsntNeeded(item) && item > 0) {
atInventoryItem(item, "Deposit-All");
wait(random(600, 900));
return true;
}
}
return false;
}
public boolean itemIsntNeeded(int id) {
for(int n : neededIDs) {
if(id == n) {
return false;
}
}
return true;
}
public boolean interfaceCheck() {
RSInterface collectionBox = RSInterface.getInterface(109);
RSInterfaceChild closeCollect = RSInterface.getChildInterface(109,13);
RSInterface depositBox = RSInterface.getInterface(11);
RSInterfaceChild closeDepos = RSInterface.getChildInterface(11,14);
if(collectionBox.isValid() && collectionBox.getLocation() != new Point(-1, -1)) {
atInterface(closeCollect);
return true;
}
if(depositBox.isValid() && depositBox.getLocation() != new Point(-1, -1)) {
atInterface(closeDepos);
return true;
}
return false;
}
public RSTile nearClearTile(RSTile tile) {
RSTile tile1 = new RSTile(tile.getX() - 1, tile.getY() + 1);
RSTile tile2 = new RSTile(tile.getX(), tile.getY() + 1);
RSTile tile3 = new RSTile(tile.getX() + 1, tile.getY() + 1);
RSTile tile4 = new RSTile(tile.getX() - 1, tile.getY());
RSTile tile5 = new RSTile(tile.getX() + 1, tile.getY());
RSTile tile6 = new RSTile(tile.getX() - 1, tile.getY() - 1);
RSTile tile7 = new RSTile(tile.getX(), tile.getY() - 1);
RSTile tile8 = new RSTile(tile.getX() + 1, tile.getY() - 1);
RSTile[] tiles = new RSTile[] {tile1, tile2, tile3, tile4, tile5, tile6, tile7, tile8};
int distance = 20;
RSTile nearest = tile;
for(int i = 0; i < tiles.length; i++) {
if(distanceTo(tiles[i]) < distance && tileIsGood(tiles[i])) {
distance = distanceTo(tiles[i]);
nearest = tiles[i];
}
}
return nearest;
}
public boolean tileIsGood(RSTile tile) {
if(getObjectAt(tile) == null && tile.isValid()) {
return true;
}
return false;
}
public boolean isEnt() {
if(getMyPlayer().getInteracting() != null) {
Object inter = getMyPlayer().getInteracting();
if(inter instanceof RSNPC) {
String name = ((RSNPC) inter).getName();
if(name.contains("Maple") || name.contains("Willow") || name.contains("Tree") || name.contains("Oak") || name.contains("Yew") || name.contains("Magic")) {
return true;
}
}
}
return false;
}
public void handleEnt() {
atTile(getMyPlayer().getLocation(), "Walk here");
}
//Simple camera turner, used by everyone. (like runAway())
public boolean turnCamera() {
try{
setCameraAltitude(true);
int newCamera = getCameraAngle()+random(0,270);
if(newCamera >= 360)
newCamera-=360;
setCameraRotation(newCamera);
}catch(Exception e) {
return false;
}
return true;
}
public boolean lightCameraTurn() {
try{
setCameraAltitude(true);
int newCamera = getCameraAngle()+random(-10,10);
if(newCamera >= 360) {
newCamera-=360;
setCameraRotation(newCamera);
}
} catch(Exception e) {
return false;
}
return true;
}
//Thanks whoever made this, it owns! XD
public void runAway() {
RSTile foo, bar, bar2;
foo = getMyPlayer().getLocation();
setRun(true);
bar = new RSTile(foo.getX() + random(8, 10), foo.getY() + random(8, 10));
bar2 = new RSTile(foo.getX() + random(-8, -10), foo.getY() + random(-8, -10));
if(bar.isValid()) {
walkTileMM(bar);
} else if(bar2.isValid()) {
walkTileMM(bar2);
}
waitWhileMoving();
wait(random(1000, 2000));
walkTileMM(foo);
}
//Excludes far away trees, anti-fuckup.
public RSObject getNearestTreeByID( int... ids ) {
RSObject cur = null;
double dist = -1;
for (int x = 0; x < 104; x++) {
for (int y = 0; y < 104; y++) {
RSObject o = getObjectAt(x + Bot.getClient().getBaseX(), y
+ Bot.getClient().getBaseY());
if (o != null) {
boolean isObject = false;
for (int id : ids) {
if (o.getID() == id && distanceToTreeIsGood(o)) {
isObject = true;
break;
}
}
if (isObject) {
double distTmp = calculateDistance(getMyPlayer( ).getLocation( ), o.getLocation( ));
if (cur == null) {
dist = distTmp;
cur = o;
} else if (distTmp < dist) {
cur = o;
dist = distTmp;
}
}
}
}
}
return cur;
}
public boolean distanceToTreeIsGood(RSObject o) {
if(o != null) {
int distance = distanceBetween(o.getLocation(), Trees2Bank[0]);
if(distance < 15) {
return true;
}
}
return false;
}
public void waitWhileMoving() {
wait(random(600, 800));
while(getMyPlayer().isMoving()) {
wait(random(100, 200));
}
}
public void waitTilCloseToStop() {
wait(random(600, 800));
while(getMyPlayer().isMoving() && getDestination() != null && distanceTo(getDestination()) > random(3, 6)) {
wait(random(100, 200));
}
}
//Modded atTile by Mike_. Makes a damn good atTree. ;)
public boolean atTree(RSTile tile, String action) {
try {
Point location = Calculations.tileToScreen(tile.getX(), tile.getY(), 1.2, 1.2, 0);
if (location.x == -1 || location.y == -1) return false;
moveMouse(location, 3, 3);
if (getMenuItems().get(0).toLowerCase().contains(action.toLowerCase())) {
clickMouse(true);
} else {
clickMouse(false);
return atMenu(action);
}
} catch (Exception e) {
return false;
}
return false;
}
public void serverMessageRecieved(ServerMessageEvent e) {
if(e.getMessage().contains("You get some") && !gotEXP) {
startExp = (int) skills.getCurrentSkillExp(STAT_WOODCUTTING);
gotEXP = true;
}
if(e.getMessage().contains("You get some")) {
cut++;
}
}
}