runelite-api: add distance methods to actor and tile queries

This commit is contained in:
Adam
2017-11-17 17:34:03 -05:00
parent ff78d2324d
commit fdb5193c3e
2 changed files with 40 additions and 0 deletions

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.api.queries;
import static java.lang.Math.abs;
import net.runelite.api.Actor;
import net.runelite.api.Point;
import net.runelite.api.Query;
@@ -93,4 +94,23 @@ public abstract class ActorQuery<EntityType extends Actor, QueryType> extends Qu
predicate = and(a -> a.getInteracting().equals(a));
return (QueryType) this;
}
@SuppressWarnings("unchecked")
public QueryType isWithinDistance(Point to, int distance)
{
predicate = and(a -> a.getLocalLocation().distanceTo(to) <= distance);
return (QueryType) this;
}
@SuppressWarnings("unchecked")
public QueryType isWithinArea(Point from, int area)
{
predicate = and(a ->
{
Point localLocation = a.getLocalLocation();
return abs(localLocation.getX() - from.getX()) < area
&& abs(localLocation.getY() - from.getY()) < area;
});
return (QueryType) this;
}
}

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.api.queries;
import static java.lang.Math.abs;
import net.runelite.api.Client;
import net.runelite.api.Point;
import net.runelite.api.Query;
@@ -89,4 +90,23 @@ public abstract class TileObjectQuery<EntityType extends TileObject, QueryType>
predicate = and(object -> object.getLocalLocation().equals(location));
return (QueryType) this;
}
@SuppressWarnings("unchecked")
public QueryType isWithinDistance(Point to, int distance)
{
predicate = and(a -> a.getLocalLocation().distanceTo(to) <= distance);
return (QueryType) this;
}
@SuppressWarnings("unchecked")
public QueryType isWithinArea(Point from, int area)
{
predicate = and(a ->
{
Point localLocation = a.getLocalLocation();
return abs(localLocation.getX() - from.getX()) < area
&& abs(localLocation.getY() - from.getY()) < area;
});
return (QueryType) this;
}
}