Guest User

Untitled

a guest
Jul 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. package com.fly.api.npcs;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8.  
  9. import org.runedream.api.methods.Calculations;
  10. import org.runedream.api.methods.Game;
  11. import org.runedream.api.methods.Mouse;
  12. import org.runedream.api.methods.Timing;
  13. import org.runedream.api.util.Random;
  14.  
  15. import com.fly.api.colors.ColorUtils;
  16. import com.fly.api.utils.DTM;
  17. import com.fly.api.utils.OCR;
  18.  
  19. public class Npc {
  20.  
  21. private final Rectangle noflyzone = new Rectangle(218, 0, 110, 65);
  22. private final Rectangle charspace = new Rectangle(236, 96, 49, 95);
  23. private final Point CENTER = new Point(261, 148);
  24. private boolean useDTM = false;
  25. private final List<Color> colors = new LinkedList<Color>();
  26. private final List<DTM> dtms = new LinkedList<DTM>();
  27. private Point points[];
  28.  
  29. public Npc(final Color... colors) {
  30. for (final Color c : colors) {
  31. this.colors.add(c);
  32. }
  33. useDTM = false;
  34. }
  35.  
  36. public Npc(final DTM... dtms) {
  37. for (final DTM dtm : dtms) {
  38. this.dtms.add(dtm);
  39. }
  40. useDTM = true;
  41. }
  42.  
  43. public boolean interact(final String action) {
  44. final Point npc = findNpc();
  45. if (npc != null) {
  46. Mouse.move(npc);
  47. if (optionsValid(action)) {
  48. Mouse.click(npc);
  49. return true;
  50. }
  51. }
  52. return false;
  53. }
  54.  
  55. public boolean optionsValid(final String option) {
  56. return Timing.waitFor(Random.random(150, 250), new Timing.Condition() {
  57. public boolean isMet() {
  58. return OCR.getOptionsText().contains(option);
  59. }
  60. });
  61. }
  62.  
  63. public Point findNpc() {
  64. if (!useDTM) {
  65. for (final Color c : colors) {
  66. points = ColorUtils.findColor(c);
  67. if (points != null) {
  68. final Point target = getClosestPoint(points, CENTER);
  69. if (target != null) {
  70. if (Game.VIEWPORT.contains(target)
  71. && !charspace.contains(target)
  72. && !noflyzone.contains(target)) {
  73. return target;
  74. }
  75. }
  76. }
  77. }
  78. } else if (useDTM) {
  79. for (final DTM dtm : dtms) {
  80. if (dtm != null) {
  81. if (dtm.findDTMS(20, Game.VIEWPORT)) {
  82. final int i = Random.random(0,
  83. dtm.dtmLocations.size() - 1);
  84. return new Point((int) dtm.dtmLocations.get(i)
  85. .getCenterX(), (int) dtm.dtmLocations.get(i)
  86. .getCenterY());
  87. }
  88. }
  89. }
  90. }
  91. return null;
  92. }
  93.  
  94. public static Point getClosestPoint(final Point[] points, final Point CENTER) {
  95. Point nearest = null;
  96. double dist = -1;
  97. for (final Point point : points) {
  98. final double distTmp = Calculations.getDistanceBetween(point,
  99. CENTER);
  100. if (nearest == null || nearest != null && distTmp < dist) {
  101. dist = distTmp;
  102. nearest = point;
  103. }
  104. }
  105. return nearest;
  106. }
  107.  
  108. }
Add Comment
Please, Sign In to add comment