Jump to content

[OPEN SOURCE] Ankou killer. Loots and uses bones to peaches


Recommended Posts

Posted (edited)

Well I got lazy training at Ankous so I wrote a script to do it for me lol

Feedback on the code would be nice :) Anything I'm doing wrong or can be improved please let me know. Thanks in-advanced.

Seems to be working flawlessly :) 

Features:

Kills Ankous (Guess it would most likely be fine to kill them anywhere but I was using in the stronghold of security)

Loots: "Death rune", "Blood rune", "Law rune", "Mithril ore", "Pure essence", "Adamant arrow",
                "Ranarr seed", "Torstol seed", "Snapdragon seed", "Bones"

Uses bones to peaches tablets on bones for food

Eats peaches obtained from b2p

Uses dragon dagger(p++) special attack once 100% special energy

ankouBot.png

Jar file: AnkouKiller.jar

 

Source code:

Spoiler

Main.java


import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Crezzy", name = "Anokou Killer", info = "Kills Ankous", logo = "", version = 1)
public class Main extends Script {

	private final List<Node> nodes = new ArrayList<>();
	private final List<Node> cache = new ArrayList<>();
	private int startExp;
	private long startTime;
	private long timeRunning;

	@Override
	public void onStart() {
		startTime = System.currentTimeMillis();
		startExp = getSkills().getTotalExperience();
		cache.add(new BonesToPeaches(this));
		cache.add(new Attack(this));
		cache.add(new Loot(this));
		cache.add(new Eat(this));
		cache.add(new SpecialAttack(this));
		getCombat().toggleAutoRetaliate(true);
	}

	@Override
	public int onLoop() {
		int delay = 333;
		timeRunning = System.currentTimeMillis() - startTime;
		if (!cache.isEmpty()) {
			nodes.clear();
			nodes.addAll(cache.stream().filter(Node::validate).collect(Collectors.toList()));
			if (!nodes.isEmpty())
				delay = getSuitabletasksNode().execute();
		}
		return delay;
	}

	public Node getSuitabletasksNode() {
		Node node = null;
		if (!nodes.isEmpty()) {
			node = nodes.get(0);
			if (nodes.size() > 1) {
				for (Node possible : nodes) {
					if (node.priority() < possible.priority())
						node = possible;
				}
			}
		}
		return node;
	}

	@Override
	public void onPaint(Graphics2D g) {
		int runtimeExp = getSkills().getTotalExperience() - startExp;
		int expPerHour = (int) ((runtimeExp * 3600000.0D) / timeRunning);
		Graphics2D paint = (Graphics2D) g.create();

		paint.drawString("Time running: " + formatTime(timeRunning), 10, 300);
		paint.drawString("Experience gained: " + runtimeExp, 10, 315);
		paint.drawString("Experience an hour: " + expPerHour, 10, 330);
	}

	private String formatTime(final long ms) {
		long s = ms / 1000, m = s / 60, h = m / 60;
		s %= 60;
		m %= 60;
		h %= 24;
		return String.format("%02d:%02d:%02d", h, m, s);
	}
}

Node.java


import org.osbot.rs07.script.Script;

public abstract class Node {
	
	protected Script c;
	
	public Node(Script c) {
		this.c = c;
	}
	
	public abstract int priority();	
	public abstract boolean validate();
	public abstract int execute();

}

Loot.java


import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.script.Script;

public class Loot extends Node {

	GroundItem item;
	String[] itemsToLoot = { "Death rune", "Blood rune", "Law rune", "Mithril ore", "Pure essence", "Adamant arrow",
			"Ranarr seed", "Torstol seed", "Snapdragon seed", "Bones" };

	public Loot(Script c) {
		super(c);
	}

	@Override
	public boolean validate() {
		for (String i : itemsToLoot) {
			item = c.groundItems.closest(i);
			if (item != null) {
				if (item.getId() != 526 && c.getInventory().isFull())
					return true;
				if (!c.getInventory().isFull())
					return true;
			}
		}
		return false;
	}

	@Override
	public int execute() {
		c.log("Picking uo item: " + item.getName());
		item.interact("Take");
		return 1000;
	}

	@Override
	public int priority() {
		return 4;
	}

}

SpecialAttack.java


import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.ui.EquipmentSlot;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

public class SpecialAttack extends Node {

	public SpecialAttack(Script c) {
		super(c);
	}

	@Override
	public int priority() {
		return 3;
	}

	@Override
	public boolean validate() {
		return c.getCombat().getSpecialPercentage() == 100 && c.getInventory().contains("Dragon dagger(p++)")
				&& c.getCombat().isFighting();
	}

	@Override
	public int execute() {
		Item originalWeapon = c.getEquipment().getItemInSlot(EquipmentSlot.WEAPON.slot);
		while (c.getCombat().getSpecialPercentage() > 0) {
			if(!c.getEquipment().isWearingItem(EquipmentSlot.WEAPON, "Dragon dagger(p++)")) {
				c.getInventory().getItem("Dragon dagger(p++)").interact("Wield");
				c.log("Equiping dragon dagger");
			}
			if(!c.getCombat().isFighting()) {
				c.log("Ankou died exit special attack loop.");
				break;
			}
			c.log("Actiating special attack");
			c.getCombat().toggleSpecialAttack(true);
			try {
				MethodProvider.sleep(1200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		c.log("Special energy depleated - requiping original weapon.");
		c.getInventory().getItem(originalWeapon.getName()).interact("Wield");
		return 1200;
	}

}

Attack.java


import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;

public class Attack extends Node {

	public Attack(Script c) {
		super(c);
	}

	@Override
	public boolean validate() {
		return !c.getCombat().isFighting() && !c.myPlayer().isUnderAttack() && c.myPlayer().isAttackable();
	}

	@Override
	public int execute() {
		c.log("Attacking ankou");
		NPC ankou = c.getNpcs().closest("Ankou");
		if(ankou != null && ankou.isAttackable() && ankou.isVisible()) 
			ankou.interact("Attack");
		return 2000;
	}

	@Override
	public int priority() {
		return 4;
	}

}

BonesToPeaches.java


import org.osbot.rs07.script.Script;

public class BonesToPeaches extends Node {

	public BonesToPeaches(Script c) {
		super(c);
	}

	@Override
	public int priority() {
		return 1;
	}

	@Override
	public boolean validate() {
		if (c.getInventory().contains("Bones to peaches")) {
			if (c.getInventory().getAmount("Bones") >= 15)
				return true;
			if (c.getInventory().contains("Bones") && !c.getInventory().contains(6883)) 
				return true;
		}
		return false;
	}

	@Override
	public int execute() {
		c.getInventory().getItem("Bones to peaches").interact("Break");
		return 1000;
	}

}

Eat.java


import org.osbot.rs07.script.Script;

public class Eat extends Node {

	public Eat(Script c) {
		super(c);
	}

	@Override
	public int priority() {
		return 5;
	}

	@Override
	public boolean validate() {
		return (c.skills.myPlayer().getHealthPercent() <= 50 && c.getInventory().contains(6883));
	}

	@Override
	public int execute() {
		c.getInventory().getItem(6883).interact("Eat");
		return 100;
	}

}

 

 

Edited by crezzy
  • Like 5
Posted

Sweet, nicely done.

Just why do you reinitialize the loot array each time you run the validate method?

String[] itemsToLoot = { "Death rune", "Blood rune", "Law rune", "Mithril ore", "Pure essence", "Adamant arrow",
				"Ranarr seed", "Torstol seed", "Snapdragon seed", "Bones" };

Just make it a class variable 

  • Like 1
Posted (edited)
11 minutes ago, Butters said:

Sweet, nicely done.

Just why do you reinitialize the loot array each time you run the validate method?


String[] itemsToLoot = { "Death rune", "Blood rune", "Law rune", "Mithril ore", "Pure essence", "Adamant arrow",
				"Ranarr seed", "Torstol seed", "Snapdragon seed", "Bones" };

Just make it a class variable 

Good point.  Shall make it a global variable instead. Thanks :)

 

Edited by crezzy
Posted (edited)
14 hours ago, Chikan said:

You might want to hide your username a bit better in the first screenshot.

 

Haha didn't even notice. Thanks for letting me know :D 

 

Updated; added dragon dagger(p++) special attack. Can add more or even a text box or something for the user to input their special weapon if requested(it will automatically know your primary weapon and switch back to it).

Edited by crezzy
  • 4 weeks later...
Posted

been running for a while, came into a few problems

1) if inventory is full but not all drops collected yet will spam the floor 

2) the door thing from above

3) something else because i cant run it for more than like 4 hours without it shutting down , not exactly sure what happens for it to turn off

  • 4 weeks later...
Posted

Great script only 2 complaints

1) the DDS spec is programmed to fast causing the script to get confused.

2) the script attempts to pick up items whilst inventory is full and doesn't make room (god knows how many seeds i missed without knowing this!) best to start app with 1 of each item that gets looted!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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