Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fly.api.objects;
- 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.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 Object {
- 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 List<Color> colors = new LinkedList<Color>();
- private List<DTM> dtms = new LinkedList<DTM>();
- private boolean useDTM = false;
- private boolean inBounds;
- private Rectangle bounds;
- public Object(final Color... colors) {
- for (final Color c : colors) {
- this.colors.add(c);
- }
- useDTM = false;
- }
- public Object(final Rectangle bounds, final Color... colors) {
- for (final Color c : colors) {
- this.colors.add(c);
- }
- this.bounds = bounds;
- useDTM = false;
- inBounds = true;
- }
- public Object(final Rectangle bounds, final DTM... dtms) {
- for (final DTM dtm : dtms) {
- this.dtms.add(dtm);
- }
- this.bounds = bounds;
- useDTM = true;
- inBounds = true;
- }
- public Object(final DTM... dtms) {
- for (final DTM dtm : dtms) {
- this.dtms.add(dtm);
- }
- useDTM = true;
- }
- public boolean interact(final String action) {
- final Point object = findObject();
- if (object != null) {
- Mouse.move(object);
- if (optionsValid(action)) {
- Mouse.click(object);
- 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() != null
- && OCR.getOptionsText().contains(option);
- }
- });
- }
- public Point findObject() {
- if (!useDTM) {
- for (final Color c : colors) {
- final Point target = ColorUtils.findClosestPoint(CENTER, c);
- if (target != null) {
- if (Game.VIEWPORT.contains(target)
- && !noflyzone.contains(target)
- && !charspace.contains(target)) {
- if (inBounds) {
- if (bounds.contains(target)) {
- return target;
- }
- } else if (!inBounds) {
- return target;
- }
- }
- }
- }
- } else if (useDTM) {
- for (final DTM dtm : dtms) {
- if (dtm != null) {
- if (inBounds) {
- if (dtm.findDTMS(20, bounds)) {
- 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());
- }
- } else if (!inBounds) {
- 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;
- }
- }
Add Comment
Please, Sign In to add comment