Jump to content

Polygon Area (not finished yet!)


TheScrub

Recommended Posts

so i'm making a script with a combat location in an odd shapped room and a rectangle won't work so i deiced to make a little class to for a polygon area

 

 

-edit was rewritten by guy below me.

import java.awt.Polygon;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;

public class PolygonArea 
{
    Polygon polygon;

PolygonArea(Position... positions)
{
polygon = new Polygon();
addPositions(positions);
}

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

    public static void addPositions(Position... positions) 
{
for (Position pos : positions)
{
polygon.addPoint(pos.getX(), pos.getY());
}
    }
}

How to use

PolygonArea polygonArea = new PolygonArea(positionsArray);
Check for entities in the area with this (NPC, Player, GroundItems, etc):
if (polygonArea.containsEntity(entity))
{
//do method
}

i still need to make a method to return the center of the polygon but i will touch on that later

 

Edited by TheScrub
Link to comment
Share on other sites

This is very useful, great work! I think you could probably simplify it a bit, and remove some of the dependencies like this:

import java.awt.Polygon;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;

public class PolygonArea 
{
    Polygon polygon;

    PolygonArea(Position... positions)
    {
        polygon = new Polygon();
        addPositions(positions);
    }

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

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

How to use

PolygonArea polygonArea = new PolygonArea(positionsArray);

Check for entities in the area with this (NPC, Player, GroundItems, etc):

if (polygonArea.containsEntity(entity))
{
//do method
}
Edited by bfir3
Link to comment
Share on other sites

 

This is very useful, great work! I think you could probably simplify it a bit, and remove some of the dependencies like this:

import java.awt.Polygon;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;

public class PolygonArea 
{
    Polygon polygon;

    PolygonArea(Position... positions)
    {
        polygon = new Polygon();
        addPositions(positions);
    }

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

    public static void addPositions(Position... positions) 
    {
        for (Position pos : positions)
        {
            polygon.addPoint(pos.getX(), pos.getY());
        }
    }
}

How to use

PolygonArea polygonArea = new PolygonArea(positionsArray);

Check for entities in the area with this (NPC, Player, GroundItems, etc):

if (polygonArea.containsEntity(entity))
{
//do method
}

 

thanks i just wrote it for a single thing only used it once or twice thanks i will update the thread with ur revision of the code!

 

Link to comment
Share on other sites

  • 5 months later...

You should inherit the Area class and override most/all of its methods to make it functional for a polygon-based region. This will ensure your PolygonArea instances can be applied to methods within the MethodProvider class that accept Area parameters.

 

this snippet is pretty old and is only used by me in osbot 2 related stuff as the api doesn't contain an AREA class

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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