Jump to content

Walk case enabled after every kill.


BotSquad

Recommended Posts

Currently developing a plugin; and I'm fairly new to Java. My character walks back to the same coordinates after every kill. Any way to stop this? Kind of annoying but if it cannot be changed then I'd rather know now. Thanks!

Spoiler

 


import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.event.Event;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.api.util.GraphicUtilities;


import java.awt.*;
import java.util.EnumSet;

@ScriptManifest(author = "BotSquad", info = "Kills Thugs for money and exp.", name = "Thugger", version = 1.0, logo = "")
public class Main extends Script {
	private Area thugs = new Area(
	    new int[][]{
	        { 3132, 9929 },
	        { 3132, 9930 },
	        { 3132, 9931 },
	        { 3131, 9929 },
	        { 3131, 9930 },
	        { 3131, 9931 },
	        { 3130, 9929 },
	        { 3130, 9930 },
	        { 3130, 9931 },
	    }
	);
	private NPC target;
	private enum State {
		WAIT,
		WALK,
		ATTACK,
		BANK
	};
	private EnumSet<Skill> skillToTrain = EnumSet.of(Skill.ATTACK, Skill.STRENGTH, Skill.DEFENCE, Skill.HITPOINTS);
	private long startTime;
	private int thugsKilled = 0;
	
	@Override
	public void onStart() {
		log("Welcome to Thugger.");
		log("version: " + getVersion());
		startTime = System.currentTimeMillis();
		
		for (Skill skill : skillToTrain) {
			getExperienceTracker().start(skill);
		}
	}
	private State getState() {
		NPC thug = getNpcs().closest("Thug");
		
		if (target != null && myPlayer().isInteracting(target))
			return State.WAIT;
		
		if (!thugs.contains(myPlayer()))
			return State.WALK;
		
		if (
			thug != null &&
			!thug.isUnderAttack() &&
			!thug.isHitBarVisible()
		)
			return State.ATTACK;
		
		return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case ATTACK:
			target = getNpcs().closest("Thug");
			if (target != null) {
				if (target.interact("Attack")) {
					new ConditionalSleep(random(3000, 5000)) {
						@Override
						public boolean condition() throws InterruptedException {
							return target != null &&
								   target.getHealthPercent() > 0;
						}
					}.sleep();
				}
			}
			break;
		case WALK:
			getWalking().webWalk(thugs);
			break;
		case WAIT:
			
			if (target != null && target.getHealthPercent() == 0) {
				this.thugsKilled++;
				this.target = null;
			}
			
			if (this.getDialogues().isPendingContinuation()) {
				this.getDialogues().clickContinue();
			}
			
			sleep(random(500, 700));
			break;
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Bye!");
	}

	@Override
	public void onPaint(Graphics2D g) {
		final long runTime = System.currentTimeMillis() - startTime;
		drawMouse(g);
		g.setColor(Color.RED);
		g.drawString("Thugger Alpha" + this.getVersion(), 10, 40);
		g.drawString("Status:  " + getState().toString().toLowerCase() + "ing", 10, 55);
		g.drawString("Time Running: " + formatTime(runTime), 10, 70);
		g.drawString("Thugs Killed: " + this.thugsKilled, 10, 85);
		int trainingPaintMargin = 0;
		
		for (Skill skill : skillToTrain) {
			if (getExperienceTracker().getGainedXP(skill) > 0) {
				g.drawString(skill.toString().toUpperCase() + " xp: " + getExperienceTracker().getGainedXP(skill), 10, 100 + trainingPaintMargin);
				trainingPaintMargin += 15;
			}
		}
		
	}
	
	public final 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);
    }
    
    private void drawMouse(Graphics graphics) {
		((Graphics2D) graphics).setRenderingHints(
			new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
		Point pointer = mouse.getPosition();
		Graphics2D spinG = (Graphics2D) graphics.create();
		Graphics2D spinGRev = (Graphics2D) graphics.create();
		spinG.setColor(new Color(255, 255, 255));
		spinGRev.setColor(Color.cyan);
		spinG.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
		spinGRev.rotate(System.currentTimeMillis() % 2000d / 2000d * (-360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
		final int outerSize = 20;
		final int innerSize = 12;
		spinG.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		spinGRev.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, 100, 75);
		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, -100, 75);
		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, 100, 75);
		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, -100, 75);
	}

}
Quote

[INFO][Bot #1][12/08 10:12:56 PM]: WebWalkingEvent; We have reached the final destination!
[INFO][Bot #1][12/08 10:12:59 PM]: WebWalkingEvent; We have reached the final destination!
[INFO][Bot #1][12/08 10:13:09 PM]: WebWalkingEvent; We have reached the final destination!
[INFO][Bot #1][12/08 10:13:22 PM]: WebWalkingEvent; We have reached the final destination!
[INFO][Bot #1][12/08 10:13:24 PM]: WebWalkingEvent; We have reached the final destination!
[INFO][Bot #1][12/08 10:13:30 PM]: WebWalkingEvent; We have reached the final destination!

 

Link to comment
Share on other sites

12 hours ago, d0zza said:

I can't see anything wrong with your code from a quick glance (other than formatting which makes it pretty hard to read) but maybe your character goes outside of the thugs area whenever it tries to attack a thug causing the WALK case to run again? This is definitely something that can be fixed.

So I need to list every tile that the thugs are attacked it? Because currently I only listed 9, and some thugs wander out that area.

12 hours ago, Alek said:

Your "random" code is not random either, with enough time we can track the normally distributed mean and variance. Also "this" is for context disambiguity, no need to use it!

So I don't actually need to use "this," and can remove it from the code?

 

And thank you both for you input, greatly appreciated!

Link to comment
Share on other sites

30 minutes ago, BotSquad said:

So I need to list every tile that the thugs are attacked it? Because currently I only listed 9, and some thugs wander out that area.

 

13 hours ago, BotSquad said:

if (!thugs.contains(myPlayer()))

return State.WALK;

This part of your code will trigger every time you are outside of the thugs area, so if you attack a thug outside of this area your script will make you walk back to inside this area. Increase the area so that all of the spots thugs can walk to are also included.

  • Like 1
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...