Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Polygon Area

Featured Replies

import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;

import java.awt.*;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 3/23/2014
 */

public class PolygonArea {

	private Polygon polygon;

	public PolygonArea(Position... positions) {
		polygon = new Polygon(retrieveXPoints(positions), retrieveYPoints(positions), positions.length);
	}

	public boolean contains(Entity entity) {
		return polygon.contains(entity.getX(), entity.getY());
	}

	public boolean contains(Position position) {
		return polygon.contains(position.getX(), position.getY());
	}

	private int[] retrieveXPoints(Position[] positions) {
		int[] xPoints = new int[positions.length];
		for (int i = 0; i < positions.length; i++)
			xPoints[i] = positions[i].getX();
		return xPoints;
	}

	private int[] retrieveYPoints(Position[] positions) {
		int[] yPoints = new int[positions.length];
		for (int i = 0; i < positions.length; i++)
			yPoints[i] = positions[i].getY();
		return yPoints;
	}

}

Probably could be improved as well as have had more methods implemented/overridden but here's a basic class for creating a polygon area instead of being stuck with just a simple square.

Edited by Swizzbeat

  • 3 weeks later...
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;
 
import java.awt.*;
 
/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 3/23/2014
 */
 
@SuppressWarnings("serial")
public class PolygonArea extends Polygon {
 
public PolygonArea(Position... positions) {
super(retrieveXPoints(positions), retrieveYPoints(positions), positions.length);
}
 
public boolean contains(Entity entity) {
return contains(entity.getX(), entity.getY());
}
 
public boolean contains(Position position) {
return contains(position.getX(), position.getY());
}
 
private static final int[] retrieveXPoints(Position[] positions) {
int[] xPoints = new int[positions.length];
for (int i = 0; i < positions.length; i++)
xPoints[i] = positions[i].getX();
return xPoints;
}
 
private static final int[] retrieveYPoints(Position[] positions) {
int[] yPoints = new int[positions.length];
for (int i = 0; i < positions.length; i++)
yPoints[i] = positions[i].getY();
return yPoints;
}
 
}

 

No idea why you extend polygon then use a local variable polygon.

Also no idea why the hell my indents were removed when I pasted this here...

Edited by Billy

  • Author
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;
 
import java.awt.*;
 
/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 3/23/2014
 */
 
@SuppressWarnings("serial")
public class PolygonArea extends Polygon {
 
public PolygonArea(Position... positions) {
super(retrieveXPoints(positions), retrieveYPoints(positions), positions.length);
}
 
public boolean contains(Entity entity) {
return contains(entity.getX(), entity.getY());
}
 
public boolean contains(Position position) {
return contains(position.getX(), position.getY());
}
 
private static final int[] retrieveXPoints(Position[] positions) {
int[] xPoints = new int[positions.length];
for (int i = 0; i < positions.length; i++)
xPoints[i] = positions[i].getX();
return xPoints;
}
 
private static final int[] retrieveYPoints(Position[] positions) {
int[] yPoints = new int[positions.length];
for (int i = 0; i < positions.length; i++)
yPoints[i] = positions[i].getY();
return yPoints;
}
 
}

No idea why you extend polygon then use a local variable polygon.

Also no idea why the hell my indents were removed when I pasted this here...

 

I was overriding some other methods when I made this and never saw that I didn't remove it. Oh well.

 

Also that code wouldn't even compile considering a call to the superclasses constructor has to be done before anything, including method calls.

This is what I use for my Polygon areas, it has some extra methods that prove to be useful at times.

    package tools;

import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;

import java.awt.*;


/**
 * Created with IntelliJ IDEA.
 * User: NotoriousPP
 * Date: 2/6/14
 * Time: 8:53 PM
 */
public class Area {

    private Polygon polyArea;

    public Area(Position... cords){
        polyArea = new Polygon();
        addPositions(cords);
    }

    public Area(int xL, int yL, int xH, int yH){
        polyArea = new Polygon();
        polyArea.addPoint(xL, yL);
        polyArea.addPoint(xH, yH);
    }

    public boolean contains(Entity e){
        return polyArea.contains(e.getX(), e.getY());
    }
    public boolean contains(Position p){
        return polyArea.contains(p.getX(), p.getY());
    }
    public Position getCenterTile(){
        int lowX = 0, lowY = 0;
        int highX = 0, highY = 0;
        for(int i : polyArea.xpoints){
            if(lowX == 0 || i < lowX){
                lowX = i;
            }
            if(highX == 0 || i > highX){
                highX = i;
            }
        }
        for(int i : polyArea.ypoints){
            if(lowY == 0 || i < lowY){
                lowY = i;
            }
            if(highY == 0 || i > highY){
                highY = i;
            }
        }
        int x = ((highX + lowX)/2), y = ((highY + lowY)/2);
        return new Position(x,y,0);
    }
    public int getLowestX(){
        int lowX = 0;
        for(int i : polyArea.xpoints){
            if(lowX == 0 || i < lowX){
                lowX = i;
            }
        }
        if(lowX != 0){
            return lowX;
        }
        return -1;
    }
    public int getLowestY(){
        int lowY = 0;
        for(int i : polyArea.ypoints){
            if(lowY == 0 || i < lowY){
                lowY = i;
            }
        }
        if(lowY != 0){
            return lowY;
        }
        return -1;
    }
    public int getHighestX(){
        int highX = 0;
        for(int i : polyArea.xpoints){
            if(highX == 0 || i > highX){
                highX = i;
            }
        }
        if(highX != 0){
            return highX;
        }
        return -1;
    }
    public org.osbot.script.rs2.utility.Area getOSArea(){
        return new org.osbot.script.rs2.utility.Area(getLowestX(), getLowestY(), getHighestX(), getHighestY());
    }
    public int getHighestY(){
        int highY = 0;
        for(int i : polyArea.ypoints){
            if(highY == 0 || i > highY){
                highY = i;
            }
        }
        if(highY != 0){
            return highY;
        }
        return -1;
    }

    private void addPositions(Position... positions){
        for (Position pos : positions){
            polyArea.addPoint(pos.getX(), pos.getY());
        }
    }
}

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.