Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Color;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.awt.Rectangle;
- import com.rarebot.script.ScriptManifest;
- import com.rarebot.script.Script;
- import ocom.rarebot.event.listeners.PaintListener;
- import com.rarebot.script.util.Timer;
- import com.rarebot.script.wrappers.RSTile;
- import com.rarebot.script.wrappers.RSObject;
- @ScriptManifest(authors = { "Beans_HD" }, keywords = { "agility" }, name = "BAgility", version = 0.4, description = "Does the 'Gnome Agility' course.")
- public class BAgility extends Script implements PaintListener, MouseListener, MouseMotionListener {
- private enum State {LogBalance, ObstacleNet1, TreeBranch1, BalancingRope, TreeBranch2, ObstacleNet2, ObstaclePipe, WalkStart, Unknown};
- private Timer runTime = new Timer(0);
- private int distX, distY, paintX = 20, paintY = 20;
- private boolean enableDrag;
- private Rectangle paintOutline = new Rectangle(20, 20, 150, 50);
- private int startExp;
- private final RSTile startTile = new RSTile(2474, 3437);
- private final int logBalanceId = 2295;
- private final int logBalanceAnim = 9908;
- private final RSTile logBalanceEnd = new RSTile(2474, 3429);
- private final int obstacleNet1Id = 2285;
- private final int obstacleNet1Anim = 828;
- private final RSTile obstacleNet1End = new RSTile(2473, 3423);
- private final int treeBranch1Id = 35970;
- private final int treeBranch1Anim = 828;
- private final RSTile treeBranch1End = new RSTile(2473, 3420);
- private final int balancingRopeId = 2312;
- private final int balancingRopeAnim = 9908;
- private final RSTile balancingRopeEnd = new RSTile(2483, 3420);
- private final int treeBranch2Id = 2314;
- private final int treeBranch2Anim = 828;
- private final RSTile treeBranch2End = new RSTile(2487, 3420);
- private final int obstacleNet2Id = 2286;
- private final int obstacleNet2Anim = 828;
- private final RSTile obstacleNet2End = new RSTile(2483, 3428);//upto 2488
- private final int[] obstaclePipeId = {43543, 43544};
- private final int obstaclePipeAnim = 10580;
- private final RSTile[] obstaclePipeEnd = {new RSTile(2487, 3437), new RSTile(2483, 3437)};
- public boolean onStart() {
- if(!game.isLoggedIn()){
- log.severe("Please login before starting this script.");
- return false;
- }
- if(!calc.tileOnScreen(startTile)){
- log.severe("Please start script at the start of the Gnome Agility course.");
- return false;
- }
- startExp = skills.getCurrentExp(skills.AGILITY);
- log("BAgility started!.");
- return true;
- }
- public int loop() {
- switch(getState()) {
- case LogBalance:
- RSObject logBalance = objects.getNearest(logBalanceId);
- if(logBalance != null){
- logBalance.doAction("Walk-across");
- for(int i=0; !getMyPlayer().getLocation().equals(logBalanceEnd); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == logBalanceAnim)
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case ObstacleNet1:
- RSObject obstacleNet1 = objects.getNearest(obstacleNet1Id);
- if(obstacleNet1 != null){
- obstacleNet1.doAction("Climb-over");
- for(int i=0; !getMyPlayer().getLocation().equals(obstacleNet1End); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == obstacleNet1Anim || getMyPlayer().isMoving())
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case TreeBranch1:
- RSObject treeBranch1 = objects.getNearest(treeBranch1Id);
- if(treeBranch1 != null){
- treeBranch1.doAction("Climb");
- for(int i=0; !getMyPlayer().getLocation().equals(treeBranch1End); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == treeBranch1Anim || getMyPlayer().isMoving())
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case BalancingRope:
- RSObject balancingRope = objects.getNearest(balancingRopeId);
- if(balancingRope != null){
- balancingRope.doAction("Walk-on");
- for(int i=0; !getMyPlayer().getLocation().equals(balancingRopeEnd); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == balancingRopeAnim || getMyPlayer().isMoving())
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case TreeBranch2:
- RSObject treeBranch2 = objects.getNearest(treeBranch2Id);
- if(treeBranch2 != null){
- treeBranch2.doAction("Climb-down");
- for(int i=0; !getMyPlayer().getLocation().equals(treeBranch2End); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == treeBranch2Anim || getMyPlayer().isMoving())
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case ObstacleNet2:
- RSObject obstacleNet2 = objects.getNearest(obstacleNet2Id);
- if(obstacleNet2 != null){
- obstacleNet2.doAction("Climb-over");
- for(int i=0; !hoppedObstacleNet2(); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == obstacleNet2Anim || getMyPlayer().isMoving())
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case ObstaclePipe:
- RSObject obstaclePipe = objects.getNearest(obstaclePipeId);
- if(obstaclePipe != null){
- obstaclePipe.doAction("Squeeze-through");
- for(int i=0; !throughPipes(); i++){
- sleep(100, 200);
- if(getMyPlayer().getAnimation() == obstaclePipeAnim || getMyPlayer().isMoving())
- i=0;
- if(i>10)
- return random(50, 100);
- }
- }
- break;
- case WalkStart:
- if(walking.getDestination() == null || calc.distanceTo(walking.getDestination()) < random(3, 5)){
- if(calc.distanceTo(startTile) > 4){
- walking.walkTo(startTile);
- sleep(400, 600);
- }
- }
- break;
- case Unknown:
- log.severe("Don't know what to do next, ending script.");
- stopScript(true);
- sleep(500, 1000);
- break;
- }
- return random(100, 200);
- }
- private State getState() {
- if(game.getPlane() == 0 && calc.tileOnScreen(startTile)){
- return State.LogBalance;
- }else if(game.getPlane() == 0 && calc.distanceTo(logBalanceEnd) <= 3){
- return State.ObstacleNet1;
- }else if(game.getPlane() == 1){
- return State.TreeBranch1;
- }else if(game.getPlane() == 2 && calc.distanceTo(treeBranch1End) <= 4){
- return State.BalancingRope;
- }else if(game.getPlane() == 2){
- return State.TreeBranch2;
- }else if(calc.distanceTo(treeBranch2End) <= 5){
- return State.ObstacleNet2;
- }else if(calc.distanceTo(new RSTile(2485, 3428)) <= 3){
- return State.ObstaclePipe;
- }else{
- return State.WalkStart;
- }
- }
- private boolean hoppedObstacleNet2(){
- RSTile t = getMyPlayer().getLocation();
- return t.getY() == 3428 && t.getX() >= 2483 && t.getX() <= 2488;
- }
- private boolean throughPipes(){
- RSTile t = getMyPlayer().getLocation();
- return t.getY() == 3437 && t.getX() >= 2483 && t.getX() <= 2487;
- }
- public void onRepaint(Graphics g) {
- g.setColor(new Color(255, 255, 255, 150));
- g.fillRect(paintX, paintY, 150, 50);
- g.setColor(Color.RED);
- g.drawString("BAgility", paintX+5, paintY+15);
- g.drawString("RunTime: "+runTime.toElapsedString(), paintX+5, paintY+30);
- g.drawString("Exp gained: "+ (skills.getCurrentExp(skills.AGILITY) - startExp), paintX+5, paintY+45);
- }
- public void onFinish() {
- log("Thanks for using BAgility.");
- }
- public void mousePressed(MouseEvent e) {
- if(paintOutline.contains(e.getPoint())){
- enableDrag = true;
- distX = e.getX() - (int) paintOutline.getX();
- distY = e.getY() - (int) paintOutline.getY();
- }
- }
- public void mouseMoved(MouseEvent e) {
- }
- public void mouseClicked(MouseEvent e) {
- }
- public void mouseReleased(MouseEvent e) {
- if(paintOutline.contains(e.getPoint())){
- enableDrag = false;
- }
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- public void mouseDragged(MouseEvent e) {
- if(enableDrag){
- paintX = e.getX() - distX;
- paintY = e.getY() - distY;
- paintOutline = new Rectangle(paintX, paintY, 150, 50);
- }
- }
- }
Add Comment
Please, Sign In to add comment