Jump to content

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


crezzy

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

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...