TheScrub Posted August 30, 2013 Posted August 30, 2013 (edited) 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 September 2, 2013 by TheScrub
bfir3 Posted September 1, 2013 Posted September 1, 2013 (edited) 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 September 2, 2013 by bfir3
TheScrub Posted September 2, 2013 Author Posted September 2, 2013 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!
liverare Posted February 7, 2014 Posted February 7, 2014 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.
TheScrub Posted February 7, 2014 Author Posted February 7, 2014 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