import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.*;
import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.*;
import com.speljohan.rsbot.accessors.NPC;
public class DPVarockYewChopper extends Script implements PaintListener {
public double getVersion() {
return(1.2);
}
public String getName() {
return("Dontpanic's Varock Yew Chopper");
}
public String getAuthor() {
return("Dontpanic - [email protected]");
}
public String getScriptCategory() {
return("Dontpanic Scripts");
}
public String getScriptDescription( ) {
String html = "";
html += "<html>\n";
html += "<body>\n";
html += "<h2>" + getName() + " v" + getVersion() + "</h2><br>\n";
html += "Author: " + getAuthor() + "<br><br>\n";
html += "This script chops yews north of the Varrock castle and banks them at the Grand Exchange.<br><br>Start anywhere with an axe in your inventory or equipped. This script may take up to 15 seconds to start if it's not already at the bank or trees, as it has to verify that it's not in a random event before teleporting to Lumbridge and walking back.";
//html += "<center>\n";
//html += "Arguments:<input type=\"text\" name=\"args\">\n";
//html += "</center>\n";
html += "</body>\n";
html += "</html\n";
return(html);
}
public boolean onStart(String[] args) {
Bot.getEventManager( ).addListener(PaintListener.class, this);
return(true);
}
public void onFinish() {
Bot.getEventManager().removeListener(PaintListener.class, this);
}
int waitAfterMoving = -1;
int failCount = 0;
public int loop() {
if(!isLoggedIn()) {
return random(100,200);
}
if(checkSpinningView()) {
return random(200, 300);
}
if(checkCamera()) {
return random(500, 800);
}
if(getMyPlayer().isMoving()) {
return random(150, 200);
}
if(waitAfterMoving != -1) {
int toReturn = waitAfterMoving;
waitAfterMoving = -1;
return toReturn;
}
if(checkAttack()) {
return random(800, 1000);
}
if(checkEnt()) {
return random(800, 1000);
}
if(getMyPlayer().getAnimation() != -1) {
return random(150, 200);
}
int result = work();
if(result != -1) {
failCount = 0;
return result;
}
if(walkBack()) {
failCount = 0;
return random(500, 800);
}
failCount ++;
if(failCount >= 10) {
failCount = 0;
homeTele();
return random(2000, 3000);
}
return random(1000, 2000);
}
public boolean checkEnt() {
if(getMyPlayer().getInteracting() != null) {
int count = Bot.getClient().getNPCCount();
NPC[] npcs = Bot.getClient().getNPCArray();
int[] ints = Bot.getClient().getNPCIndexArray();
for (int i = 0; i < count; i++)
{
RSNPC npc = new RSNPC(npcs[ints[i]]);
if(getMyPlayer().getInteracting().equals(npc) && Arrays.asList(treeNames).contains(npc.getName())) {
if(clickTree() > 0) {
walkTileMM(tree1Tile);
}
return true;
}
}
}
return false;
}
boolean cameraMoving = false;
public boolean checkCamera() {
if(cameraMoving) {
if(Bot.getClient().getCameraCurveY() >= 380) {
Bot.getInputManager().releaseKey((char) KeyEvent.VK_UP);
cameraMoving = false;
}
return true;
} else if (Bot.getClient().getCameraCurveY() < 380) {
Bot.getInputManager().pressKey((char) KeyEvent.VK_UP);
cameraMoving = true;
return true;
}
return false;
}
public boolean checkAttack() {
if(getMyPlayer().isInCombat()) {
return runFromCombat();
} else {
return false;
}
}
public boolean runFromCombat() {
if(atBank()) {
bankToTrees();
return true;
}
if(atTrees()) {
treesToBank();
return true;
}
return false;
}
int loads = 0;
public void onRepaint(Graphics g) {
g.setColor(Color.YELLOW);
g.drawString("Dontpanic's Varrock Yew Chopper", 260, 20);
g.drawString("Loads: " + loads, 260, 38);
}
public int work() {
if(getInventoryCount() != 28) {
return chop();
} else {
return bank();
}
}
public int chop() {
if(atTrees()) {
int result = clickTree();
if(result > 0) {
if(result == 1) {
waitAfterMoving = random(500, 800);
}
return random(500, 800);
} else {
if(result == -1) {
spinView();
} else {
if(distanceTo(centerTile) > 2) {
RSTile rCenterTile = new RSTile(centerTile.getX() + random(-1, 1), centerTile.getY() + random(-1, 1));
dpWalkTile(rCenterTile);
}
}
return random(500, 800);
}
} else {
if(bankToTrees()) {
return random(500, 800);
} else {
return -1;
}
}
}
public int bank() {
if(atBank()) {
if(RSInterface.getInterface(INTERFACE_BANK).isValid()) {
bank.depositAllExcept(1349, 1351, 1353, 1355, 1357, 1359, 6739);
loads ++;
return random(500, 800);
} else {
runOn();
if(distanceTo(bankTile) > 0) {
if(dpWalkTile(bankTile)) {
waitAfterMoving = random(200, 300);
return random(500, 800);
} else {
return -1;
}
} else {
if(useBanker()) {
return random(500, 800);
} else {
return -1;
}
}
}
} else {
if(treesToBank()) {
return random(500, 800);
} else {
return -1;
}
}
}
public boolean useBanker() {
RSNPC npc = getNearestNPCByID(bankerID);
return atNPC(npc, "Bank Banker");
}
public boolean atBank() {
return distanceTo(bankTile) < 15;
}
public boolean bankToTrees() {
return dpWalkPath(bankToTreesPath);
}
public boolean treesToBank() {
return dpWalkPath(treesToBankPath);
}
public boolean atTrees() {
return distanceTo(tree1Tile) < 10 || distanceTo(tree2Tile) < 10;
}
public int clickTree() {
RSObject object = findObject(treeID);
if(object == null || distanceTo(object.getLocation()) > 16) {
return -2;
}
if(atObject(object, "Chop")) {
return 1;
}
if(distanceTo(object.getLocation()) > 3) {
if(dpWalkTile(object.getLocation())) {
return 2;
}
}
return -1;
}
public boolean dpWalkPath(RSTile[] path) {
for(int i = path.length - 1; i >= 0; i--) {
if(dpWalkTile(path[i])) {
return true;
}
}
return false;
}
public boolean dpWalkTile(RSTile tile) {
if(distanceTo(tile) <= 16) {
walkTileMM(tile);
return true;
} else {
return false;
}
}
public void homeTele() {
openTab(Script.TAB_MAGIC);
castSpell(1);
}
public boolean walkBack() {
return dpWalkPath(walkBackPath);
}
public void runOn() {
setRun(true);
}
public void spinView() {
Bot.getInputManager().pressKey((char) KeyEvent.VK_RIGHT);
spinningView = true;
}
boolean spinningView = false;
public boolean checkSpinningView() {
if(spinningView) {
Bot.getInputManager().releaseKey((char) KeyEvent.VK_RIGHT);
spinningView = false;
return true;
} else {
return false;
}
}
public int treeID = 1309;
public RSTile[] treesToBankPath = {new RSTile(3220,3501),new RSTile(3214,3501),new RSTile(3208,3501),new RSTile(3202,3501),new RSTile(3199,3495),new RSTile(3194,3491),new RSTile(3188,3489),new RSTile(3182,3489),new RSTile(3176,3489),new RSTile(3170,3489),new RSTile(3167,3490),};
public RSTile[] bankToTreesPath = {new RSTile(3167,3490),new RSTile(3173,3490),new RSTile(3179,3490),new RSTile(3185,3490),new RSTile(3191,3489),new RSTile(3193,3495),new RSTile(3198,3499),new RSTile(3204,3501),new RSTile(3208,3502),};
public RSTile tree1Tile = new RSTile(3208, 3502);
public RSTile tree2Tile = new RSTile(3220, 3502);
public int bankerID = 6534;
public RSTile bankTile = new RSTile(3167, 3490);
public RSTile centerTile = new RSTile(3215, 3501);
public final String[] treeNames = {"Yew"};
public RSTile[] walkBackPath = {new RSTile(3222,3216),new RSTile(3228,3217),new RSTile(3234,3221),new RSTile(3239,3225),new RSTile(3245,3225),new RSTile(3251,3225),new RSTile(3257,3229),new RSTile(3259,3235),new RSTile(3259,3241),new RSTile(3258,3247),new RSTile(3253,3252),new RSTile(3251,3258),new RSTile(3251,3264),new RSTile(3247,3269),new RSTile(3243,3274),new RSTile(3240,3280),new RSTile(3239,3286),new RSTile(3239,3292),new RSTile(3239,3298),new RSTile(3239,3304),new RSTile(3243,3309),new RSTile(3246,3315),new RSTile(3250,3320),new RSTile(3256,3322),new RSTile(3262,3323),new RSTile(3267,3328),new RSTile(3261,3330),new RSTile(3255,3330),new RSTile(3250,3334),new RSTile(3244,3335),new RSTile(3238,3335),new RSTile(3232,3336),new RSTile(3228,3341),new RSTile(3227,3347),new RSTile(3227,3353),new RSTile(3222,3357),new RSTile(3218,3362),new RSTile(3215,3368),new RSTile(3214,3374),new RSTile(3213,3380),new RSTile(3213,3386),new RSTile(3213,3392),new RSTile(3212,3398),new RSTile(3212,3404),new RSTile(3212,3410),new RSTile(3212,3416),new RSTile(3211,3422),new RSTile(3207,3427),new RSTile(3201,3429),new RSTile(3200,3435),new RSTile(3197,3441),new RSTile(3195,3447),new RSTile(3189,3450),new RSTile(3185,3455),new RSTile(3181,3460),new RSTile(3175,3462),new RSTile(3169,3464),new RSTile(3165,3469),new RSTile(3165,3475),new RSTile(3165,3481),new RSTile(3167,3487),new RSTile(3167,3490)};
}