Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fly.api.npcs;
- import java.awt.Color;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.util.LinkedList;
- import java.util.List;
- import org.runedream.api.methods.Calculations;
- import org.runedream.api.methods.Game;
- import org.runedream.api.methods.Mouse;
- import org.runedream.api.methods.Timing;
- import org.runedream.api.util.Random;
- import com.fly.api.colors.ColorUtils;
- import com.fly.api.utils.DTM;
- import com.fly.api.utils.OCR;
- public class Npc {
- private final Rectangle noflyzone = new Rectangle(218, 0, 110, 65);
- private final Rectangle charspace = new Rectangle(236, 96, 49, 95);
- private final Point CENTER = new Point(261, 148);
- private boolean useDTM = false;
- private final List<Color> colors = new LinkedList<Color>();
- private final List<DTM> dtms = new LinkedList<DTM>();
- private Point points[];
- public Npc(final Color... colors) {
- for (final Color c : colors) {
- this.colors.add(c);
- }
- useDTM = false;
- }
- public Npc(final DTM... dtms) {
- for (final DTM dtm : dtms) {
- this.dtms.add(dtm);
- }
- useDTM = true;
- }
- public boolean interact(final String action) {
- final Point npc = findNpc();
- if (npc != null) {
- Mouse.move(npc);
- if (optionsValid(action)) {
- Mouse.click(npc);
- return true;
- }
- }
- return false;
- }
- public boolean optionsValid(final String option) {
- return Timing.waitFor(Random.random(150, 250), new Timing.Condition() {
- public boolean isMet() {
- return OCR.getOptionsText().contains(option);
- }
- });
- }
- public Point findNpc() {
- if (!useDTM) {
- for (final Color c : colors) {
- points = ColorUtils.findColor(c);
- if (points != null) {
- final Point target = getClosestPoint(points, CENTER);
- if (target != null) {
- if (Game.VIEWPORT.contains(target)
- && !charspace.contains(target)
- && !noflyzone.contains(target)) {
- return target;
- }
- }
- }
- }
- } else if (useDTM) {
- for (final DTM dtm : dtms) {
- if (dtm != null) {
- if (dtm.findDTMS(20, Game.VIEWPORT)) {
- final int i = Random.random(0,
- dtm.dtmLocations.size() - 1);
- return new Point((int) dtm.dtmLocations.get(i)
- .getCenterX(), (int) dtm.dtmLocations.get(i)
- .getCenterY());
- }
- }
- }
- }
- return null;
- }
- public static Point getClosestPoint(final Point[] points, final Point CENTER) {
- Point nearest = null;
- double dist = -1;
- for (final Point point : points) {
- final double distTmp = Calculations.getDistanceBetween(point,
- CENTER);
- if (nearest == null || nearest != null && distTmp < dist) {
- dist = distTmp;
- nearest = point;
- }
- }
- return nearest;
- }
- }
Add Comment
Please, Sign In to add comment