package com.scripts; import com.kbot2.handlers.eventSystem.eventListeners.PaintListener; import com.kbot2.scriptable.Script; import com.kbot2.scriptable.methods.wrappers.*; import com.kbot2.scriptable.methods.Calculations; import com.kbot2.scriptable.methods.Methods; import static com.kbot2.scriptable.methods.Calculations.random; import com.kbot2.out.Console; import java.applet.Applet; import java.awt.event.KeyEvent; import java.awt.*; import java.util.*; public class TehEssMiner extends Script implements PaintListener { Tile bankTile = new Tile(3253,3421); Tile aubTile = new Tile(3253,3400); Tile[] portal = {new Tile(2885,4850), new Tile(2889,4813), new Tile(2932,4854), new Tile(2933,4815)}; Tile[] essLoc = {new Tile(2893,4849), new Tile(2895,4814), new Tile(2927,4850),new Tile(2929,4816)}; Tile center = new Tile(2910,4832); int[] essHeight = {70,140,140,140}; double[] essDevX = {.5,.9,.6,.6}; double[] essDevY = {.5,.2,.6,.4}; int[] pickaxes = {1265, 1267, 1269, 1296, 1273, 1271, 1275}; Calculations calc; Player me; Tile location; long lastIdle; Tile[] lastPath; public boolean onStart() { calc = getBot().getCalculations(); return true; } public void log(String s) { Console.writeLine(this,s); } public void setIdle(int time) { lastIdle = System.currentTimeMillis()+time+(time*random(1,4)/10); } public void setIdle() { lastIdle = System.currentTimeMillis()+1000; } public boolean active() { return true; } public void checkRotate() { if(random(0,10)!=9) return; int old = getCameraAngle(); sleep(50); if(old!=getCameraAngle()) { releaseKey(37); releaseKey(39); } } public int loop() { checkRotate(); me = getMyPlayer(); location = me.getLocation(); if(idle()) return random(50,100); me = getMyPlayer(); location = me.getLocation(); if(getClient().getPlane()!=0) return lost(); if(inventory.getCount()==28) return bank(); Item weapon = interfaces.getEquipmentItem(3); check: if(!inventory.contains(pickaxes)) { for(int pick:pickaxes) if(weapon==null || weapon.getID()==pick) break check; return bank(); } return mine(); } public int mine() { if(location.distanceTo(aubTile)>50) { int pos = getPos(); if(location.distanceTo(essLoc[pos])>11) { Tile[] toEss = fixPath2(essLoc[pos]); lastPath = toEss; walkPath2(toEss); setIdle(); return random(50,100); } Point p = circleTile(essLoc[pos].getPosX(),essLoc[pos].getPosY(),(Math.random()*.15)+1.7); if(p==null) { setCameraRotation(getAngleToCoordinates(essLoc[pos].getPosX(),essLoc[pos].getPosY())); p = circleTile(essLoc[pos].getPosX(),essLoc[pos].getPosY(),(Math.random()*.15)+1.7); if(p==null) return random(50,100); } moveMouse(p); atMenu("Mine"); setIdle(); return random(50,100); } NPC aubury = npcs.getClosestNPC(20,"Aubury"); if(location.distanceTo(aubTile)>7) { Tile aubTile2 = aubTile; if(aubury!=null) aubTile2=aubury.getLocation(); Tile[] toAub = fixPath2(aubTile2); lastPath=toAub; walkPath2(toAub); setIdle(); return random(50,100); } if(aubury==null) return random(50,100); if(aubury.doAction("Teleport")) setIdle(3000); else setCameraRotation(getAngleToCoordinates(aubury.getLocation().getPosX(),aubury.getLocation().getPosY())+random(-5,5)); return random(50,100); } public int bank() { if(location.distanceTo(aubTile)>50) { int pos = getPos(); if(location.distanceTo(portal[pos])>4) { Tile[] path = fixPath2(portal[pos]); lastPath=path; walkPath2(path); setIdle(); return random(50,100); } Point p = calc.tileToScreen(portal[pos]); if(p==null) { setCameraRotation(getAngleToCoordinates(portal[pos].getPosX(),portal[pos].getPosY())); p = calc.tileToScreen(portal[pos].getPosX(), portal[pos].getPosY(), random(4,7)/10, random(4,7)/10, random(0,10)); if(p==null) return random(50,100); } moveMouse(p,2,2); if(atMenu("Use")) setIdle(3000); return random(50,100); } if(bank.isOpen()) { check: if(!inventory.contains(pickaxes)) { Item weapon = interfaces.getEquipmentItem(3); for(int pick:pickaxes) if(weapon==null || weapon.getID()==pick) break check; int bestPick=-1; for(int pick:pickaxes) if(bank.contains(pick)) bestPick = pick; if(bestPick==-1) { Console.writeLine(this,"We don't have a pickaxe. Stopping Script"); stopAllScripts(); return 1000; } bank.withdrawItem(bestPick,1); log("Withdrawing Pick. index: "+bestPick); } if(inventory.contains(7936,1436)) bank.depositAll(7936,1436); return random(50,100); } Obj banker = objects.getClosestObject(20,11402); if(banker==null || location.distanceTo(bankTile) > 6) { Tile[] path = fixPath2(bankTile); lastPath=path; walkPath2(path); setIdle(); return random(50,100); } if(banker.getScreenPos()==null || banker.getScreenPos().getX()==-1 || banker.getScreenPos().getY()==-1) { setCameraRotation(getAngleToCoordinates(banker.getLocation().getPosX(),banker.getLocation().getPosY())); if(banker.getScreenPos()==null || banker.getScreenPos().getX()==-1 || banker.getScreenPos().getY()==-1) return random(50,100); } banker.doAction("Use-quickly"); setIdle(1500); return random(50,100); } public boolean idle() { if(me.isInCombat() && !me.isMoving()) return false; if(me.getAnimation()!=-1 || me.isMoving()) { setIdle(1500); } return lastIdle>System.currentTimeMillis(); } public int lost() { log("WTF we're lost. this sucks. stopping. . ."); return -1; } public String getName() { return "TehEssMiner"; } public String getAuthor() { return "Mike_"; } public String getDescription() { return "Mines ess."; } public void onRepaint(Graphics g) { g.setColor(Color.YELLOW); if (lastPath != null) { for(int i=0;i= 4832) return 0; //NW else return 1;//SW else if(myY >= 4832) return 2; //NE else return 3;//SE } public String[] getTags() { return new String[]{"Ess", "Essence", "Rune Ess", "Rune Essence", "Mike", "Mike_", "Mining"}; } public Tile[] fixPath2(Tile tile) { return fixPath2(getMyPlayer().getLocation().getPosX(),getMyPlayer().getLocation().getPosY(), tile.getPosX(), tile.getPosY()); } public Tile[] fixPath2(Tile tile, Tile tile2) { return fixPath2(tile.getPosX(), tile.getPosY(), tile2.getPosX(), tile2.getPosY()); } public Tile[] fixPath2(int startX, int startY, int destinationX, int destinationY) { //most credits to aftermath double dx, dy; ArrayList list = new ArrayList(); list.add(new Tile(startX, startY)); while(Math.hypot(destinationY - startY, destinationX - startX) > 8) { dx = destinationX - startX; dy = destinationY - startY; int gamble = random(14,16); while(Math.hypot(dx, dy) > gamble) { dx *= .95; dy *= .95; } startX += (int) dx; startY += (int) dy; list.add(new Tile(startX, startY)); } list.add(new Tile(destinationX, destinationY)); if(walking.getEnergy()>random(random(50,99),99)) walking.setRunning(true); return list.toArray(new Tile[list.size()]); } public Point circleTile(int x, int y, double distance) { int angle = getAngleToCoordinates(x,y)-180; if(angle<0) angle+=360; java.util.List possibleX = new ArrayList(); java.util.List possibleY = new ArrayList(); java.util.List possibleHeight = new ArrayList(); int rawX; int rawY; double xDev; double yDev; int height; for(int i=angle-20;i 0) angle = 180; if(x < 0 && y == 0) angle = 90; if(x == 0 && y < 0) angle = 0; if(x < 0 && y == 0) angle = 270; if(x < 0 && y > 0) angle+=270; if(x > 0 && y > 0) angle+=90; if(x < 0 && y < 0) angle=Math.abs(angle)-180; if(x > 0 && y < 0) angle=Math.abs(angle)+270; if(angle<0) angle=360+angle; if(angle>=360) angle-=360; return (int)angle; } public Tile[] randomizePath(Tile[] path, int randomX, int randomY){ for(Tile tile: path){ tile.setPosX(tile.getPosX()-randomX+random(0, randomX)*2); tile.setPosY(tile.getPosY()-randomY+random(0, randomY)*2); } return path; } public int getCameraAngle() { double mapAngle = getBot().getClient().getCameraCurveX(); mapAngle /= 2040; mapAngle *= 360; return (int) mapAngle; } public void setCameraRotation(int degrees) { char left = 37; char right = 39; char whichDir = left; int start = getCameraAngle(); /* Some of this shit could be simplified, but it's easier to wrap my mind around it this way*/ if(start < 180) start += 360; if(degrees < 180) degrees += 360; if(degrees > start) { if(degrees - 180 < start) whichDir = right; } else if(start > degrees) { if(start - 180 >= degrees) whichDir = right; } degrees %= 360; holdKey(whichDir); int timeWaited = 0; while (getCameraAngle() > degrees + 5 || getCameraAngle() < degrees - 5) { sleep(10); timeWaited += 10; if (timeWaited > 500) { int time = timeWaited - 500; if (time == 0) { holdKey(whichDir); } else if (time % 40 == 0) { holdKey(whichDir); } } } holdKey(whichDir); } public void holdKey(int keyCode) { com.kbot2.accessors.Keyboard keyboard = getClient().getKeyboard(); KeyEvent keyEvent; // Press key keyEvent = new KeyEvent(((Applet) getClient()), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, keyCode, (char) keyCode); keyboard.dispatchEvent(keyEvent); } public void releaseKey(int keyCode) { com.kbot2.accessors.Keyboard keyboard = getClient().getKeyboard(); KeyEvent keyEvent; // Press key keyEvent = new KeyEvent(((Applet) getClient()), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), 0, keyCode, (char) keyCode); keyboard.dispatchEvent(keyEvent); } public boolean onRandomActivate(Random random) { try { return true; // Debug script } catch(Exception e) { e.printStackTrace(); } return false; } public boolean walkPath2(Tile[] path){ final Player myPlayer = getMyPlayer(); if(path == null){ Console.writeLine(this, "The path was null."); return false; } if(path.length == 0){ Console.writeLine(this, "The path contains no tiles."); return false; } long lastClicked = 0; int index = 0; while(index ==0){//lol lazy if(myPlayer.isMoving()){ if(System.currentTimeMillis() - lastClicked < random(1500, 3000)){ sleep(300, 600); continue; } } Tile myPos = myPlayer.getLocation(); int maxDistance = random(7, 16); // Get the furthest possible tile double distance = 0; for(int i = index; i < path.length; i++){ double curDistance = myPos.distanceTo(path[i]); if(curDistance > maxDistance) continue; if(curDistance > distance){ distance = curDistance; index = i; } } if(path[index].equals(myPos)){ if(index == path.length-1){ return true; } continue; } walking.walkToMM(path[index]); lastClicked = System.currentTimeMillis(); } return false; } }