Jump to content

Ashe Catcher


JavaMadness

Recommended Posts

This is a pretty simple bot that goes to the GE and picks up all the ashes left behind and then banks them.

 

This is one of my first scripts so I would love to have some feedback.

 

Main

package madness.script;

import java.awt.Graphics2D;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import madness.task.BankTask;
import madness.task.PickupItemTask;
import madness.task.TaskManager;


@ScriptManifest(name = "AsheCatcher", author = "JavaMadness", version = 1.0, info = "", logo = "") 
public class Main extends Script {
	private TaskManager tasks;
    @Override
    public void onStart() {
        //Code here will execute before the loop is started
    	tasks = new TaskManager();
    	tasks.add(new BankTask(this,new Area(3159, 3493, 3170, 3485)));
    	tasks.add(new PickupItemTask(this,"Ashes", new Area(3144, 3470, 3186, 3510)));
    }
    
    @Override
    public void onExit() {
        //Code here will execute after the script ends
    }

    @Override
    public int onLoop() {
    	tasks.runTask();
        return 100; //The amount of time in milliseconds before the loop starts over
    }


    @Override
    public void onPaint(Graphics2D g) {
        //This is where you will put your code for paint(s)
    }


} 

 

Task

package madness.task;

import org.osbot.rs07.script.Script;

public abstract class Task {

	protected Script api;

	public Task(Script api) {
		this.api = api;
	}

	public abstract boolean canProcess();

	public abstract void process();

} 

 

TaskManager

package madness.task;

import java.util.ArrayList;

public class TaskManager {
	protected ArrayList<Task> tasks;
	protected Task currentTask;
	
	public TaskManager() {
		tasks = new ArrayList<Task>();
	}

	public TaskManager(ArrayList<Task> a) {
		tasks = a;
	}

	public void runTask(){
		currentTask = findTask();
		currentTask.process();
	}
	private Task findTask(){
		for(Task t : tasks){
			if(t.canProcess())
				return t;
		}
		return tasks.get(tasks.size()-1);
	}
	
	public Task getCurrentTask(){
		return currentTask;
	}
	public void add(Task t){
		tasks.add(t);
	}
	public void remove(Task t){
		tasks.remove(t);
	}
}
 

 

PickipItemTask

package madness.task;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.event.InteractionEvent;
import org.osbot.rs07.script.Script;

import madness.utill.AntiBan;

public class PickupItemTask extends Task {
	private String itemName;
	private Area pickupArea;
	public PickupItemTask(Script api, String itemName, Area pickupArea) {
		super(api);
		this.itemName = itemName;
		this.pickupArea = pickupArea;
	}

	@Override
	public boolean canProcess() {
		return true;
	}

	@Override
	public void process() {
		if (!pickupArea.contains(api.myPlayer())) {
			api.getWalking().webWalk(pickupArea);
			AntiBan.randomEvent(api);
		}else{
			GroundItem item = api.getGroundItems().closest(itemName);
			InteractionEvent pickup = new InteractionEvent(item, "Take");
			pickup.setOperateCamera(true);
			pickup.setWalkTo(true);
			api.execute(pickup);
			while(item.exists()){
				AntiBan.sleep(100, 400);
			}
		}
		
	}
}
 

 

BankTask

package madness.task;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.event.InteractionEvent;
import org.osbot.rs07.script.Script;

import madness.utill.AntiBan;

public class BankTask extends Task {
	private Area bankArea;

	public BankTask(Script api, Area bankArea) {
		super(api);
		this.bankArea = bankArea;
	}

	@Override
	public boolean canProcess() {
		return api.getInventory().isFull();
	}

	@Override
	public void process() {
		if (!bankArea.contains(api.myPlayer())) {
			api.getWalking().webWalk(bankArea);
			AntiBan.randomEvent(api);
		} else {
			NPC banker = api.getNpcs().closest("Banker");
			InteractionEvent bank = new InteractionEvent(banker, "Bank");
			bank.setOperateCamera(true);
			bank.setWalkTo(true);
			api.execute(bank);
			while (!api.getBank().isOpen())
				AntiBan.randomEvent(api);
			if (api.getInventory().isFull()) {
				api.getBank().depositAll();
			}
		}
	}

}
 

 

AntiBan - needs a lot of work 

package madness.utill;

import java.util.List;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.event.InteractionEvent;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

public class AntiBan {
	private static long lastMove = System.currentTimeMillis();
	private final static long MIN_LAST_TIME = 15000;

	public static void randomEvent(Script api) {
		if (lastMove + MIN_LAST_TIME <= System.currentTimeMillis()) {
			lastMove = System.currentTimeMillis();
			int num = MethodProvider.random(0, 1000);
			if (inRange(num, 0, 20)) {
				api.log("Anti-Ban: Moving mouse");
				api.getMouse().moveRandomly();
			}
			if (inRange(num, 20, 100)) {
				api.log("Anti-Ban: Moving mouse slightly");
				api.getMouse().moveSlightly();
			}
			if (inRange(num, 101, 200)) {
				api.log("Anti-Ban: Checking Website");
				api.getMouse().moveOutsideScreen();
				sleep(5000, 10000);
			}
			if (inRange(num, 201, 205)) {
				api.log("Anti-Ban: Going to bathroom");
				api.getMouse().moveSlightly();
				sleep(10000, 20000);
			}
			if (inRange(num, 206, 250)) {
				api.log("Anti-Ban: Moving Camera Yaw");
				api.getCamera().moveYaw(MethodProvider.random(-100, 100));
				api.getCamera().movePitch(MethodProvider.random(-10, 10));
			}
			if (inRange(num, 251, 300)) {
				api.log("Anti-Ban: Moving Camera Pitch");
				api.getCamera().moveYaw(MethodProvider.random(-10, 10));
				api.getCamera().movePitch(MethodProvider.random(-100, 100));
			}
			if (inRange(num, 301, 320)) {
				api.log("Anti-Ban: Moving Camera Dramaticly Yaw");
				api.getCamera().moveYaw(MethodProvider.random(-360, 360));
				api.getCamera().movePitch(MethodProvider.random(-10, 10));
			}
			if (inRange(num, 321, 330)) {
				api.log("Anti-Ban: Checking Settings");
				api.getTabs().open(Tab.SETTINGS);
				try {
					api.getMouse().moveRandomly(100);
					sleep(200, 500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
			if (inRange(num, 331, 340)) {
				api.log("Anti-Ban: Checking Skills");
				api.getTabs().open(Tab.SKILLS);
				try {
					api.getSkills().hoverSkill(Skill.WOODCUTTING);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				api.getMouse().moveVerySlightly();
			}
			if (inRange(num, 341, 350)) {
				api.log("Anti-Ban: Checking Inventory");
				api.getTabs().open(Tab.INVENTORY);
				try {
					api.getMouse().moveRandomly(10);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (inRange(num, 351, 360)) {
				api.log("Anti-Ban: Hovering over object");
				List<RS2Object> lst = api.getObjects().getAll();
				RS2Object o = lst.get(MethodProvider.random(0, lst.size() - 1));
				InteractionEvent o2 = new InteractionEvent(o, "examine");
				o2.setOperateCamera(true);
				o2.setHover(true);
			}
			if (inRange(num, 361, 365)) {
				api.log("Anti-Ban: Checking random skill");
				api.getTabs().open(Tab.SKILLS);
				try {
					api.getSkills().hoverSkill(randomSkill());
					sleep(100,600);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				api.getTabs().open(Tab.INVENTORY);
			}

		}
	}

	private static Skill randomSkill() {
		Skill[] s = Skill.values();
		int i = MethodProvider.random(0, s.length);
		return s[i];
	}

	public static void sleep(int a, int b) {
		sleep(MethodProvider.random(a, b));
	}

	public static void sleep(int a) {
		try {
			MethodProvider.sleep(a);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static boolean inRange(int value, int low, int high) {
		return low <= value && value <= high;
	}

}
 

 

Wish I could upload a jar file to try, but its probably against the rules.

Edited by JavaMadness
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...