Guest User

Untitled

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