Advertisement
Guest User

Untitled

a guest
Mar 6th, 2018
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.FlowLayout;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JComboBox;
  11. import javax.swing.JDialog;
  12.  
  13. import xobot.client.callback.listeners.PaintListener;
  14. import xobot.script.ActiveScript;
  15. import xobot.script.Manifest;
  16. import xobot.script.methods.GameObjects;
  17. import xobot.script.methods.Players;
  18. import xobot.script.methods.Walking;
  19. import xobot.script.methods.tabs.Skills;
  20. import xobot.script.util.Time;
  21. import xobot.script.util.Timer;
  22. import xobot.script.wrappers.Tile;
  23. import xobot.script.wrappers.interactive.GameObject;
  24.  
  25. @Manifest(authors = { "pepsip77", "Sebo" }, name = "pAgility", version = 0.2, description = "Runs agility course laps.")
  26. public class pAgility extends ActiveScript implements PaintListener {
  27.  
  28. public Timer t = null;
  29.  
  30. Obstacle currObstacle;
  31.  
  32. int agilStart = 0;
  33.  
  34. String course = "null";
  35. String coursePicked = "null";
  36.  
  37. @Override
  38. public boolean onStart() {
  39. currObstacle = null;
  40. t = new Timer(System.currentTimeMillis());
  41. agilStart = Skills.getCurrentExp(Skills.AGILITY);
  42.  
  43. JDialog frame = new JDialog();
  44. frame.setPreferredSize(new Dimension(250, 90));
  45. frame.setLocationRelativeTo(null);
  46. frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  47. FlowLayout layout = new FlowLayout();
  48. layout.setHgap(5);
  49. layout.setVgap(5);
  50. frame.setLayout(layout);
  51.  
  52. JComboBox<String> combo = new JComboBox<String>();
  53. combo.setPreferredSize(new Dimension(150, 30));
  54. combo.setFocusable(false);
  55. combo.addItem("Gnome Agility");
  56. combo.addItem("Barbarian Agility");
  57. combo.addItem("Wilderness Agility");
  58.  
  59. JButton button = new JButton("Start");
  60. button.setFocusable(false);
  61. button.setPreferredSize(new Dimension(60, 32));
  62. button.addActionListener(new ActionListener() {
  63.  
  64. @Override
  65. public void actionPerformed(ActionEvent ae) {
  66. course = (String) combo.getSelectedItem();
  67. switch (course) {
  68. case "Gnome Agility":
  69. coursePicked = "Gnome";
  70. break;
  71. case "Barbarian Agility":
  72. coursePicked = "Barb";
  73. break;
  74. case "Wilderness Agility":
  75. coursePicked = "Wild";
  76. break;
  77. }
  78. frame.dispose();
  79. }
  80.  
  81. });
  82.  
  83. frame.add(combo);
  84. frame.add(button);
  85. frame.setTitle("XoBot - pAgility 0.2");
  86.  
  87. frame.pack();
  88. frame.setVisible(true);
  89. while (frame.isVisible()) {
  90. Time.sleep(100);
  91. }
  92. return true;
  93. }
  94.  
  95. @Override
  96. public void onStop() {
  97.  
  98. }
  99.  
  100. @Override
  101. public int loop() {
  102. if (isAtCourse()) {
  103. if (!Players.getMyPlayer().isMoving() && Players.getMyPlayer().getAnimation() == -1) {
  104. currObstacle = getNextObstacle();
  105. if (currObstacle != null) {
  106. if (Players.getMyPlayer().getLocation().getX() == currObstacle.beginTile.getX()
  107. && Players.getMyPlayer().getLocation().getY() == currObstacle.beginTile.getY()) {
  108. GameObject o = GameObjects.getNearest(currObstacle.getId());
  109. if (o != null && o.isReachable()) {
  110. o.interact(currObstacle.getAction());
  111. Time.sleep(950, 1050);
  112. }
  113. } else {
  114. Walking.walkTo(currObstacle.beginTile);
  115. Time.sleep(950, 1050);
  116. }
  117. }
  118. }
  119. }
  120. return 100;
  121. }
  122.  
  123. public String format(int i) {
  124. if (i > 1000000) {
  125. return (i / 1000000) + "M";
  126. } else if (i > 1000) {
  127. return (i / 1000) + "K";
  128. }
  129. return String.valueOf(i);
  130. }
  131.  
  132. @Override
  133. public void repaint(Graphics g1) {
  134. int agil = Skills.getCurrentExp(Skills.AGILITY) - agilStart;
  135. int agilTimer = (int) ((agil) * 3600000D / (t.getElapsed()));
  136.  
  137. Graphics2D g = (Graphics2D) g1;
  138.  
  139. g.setColor(Color.WHITE);
  140. g.drawString("Agility XP Gained: " + format(agil), 5, 175);
  141. g.drawString("Agility XP/HR: " + format(agilTimer), 5, 190);
  142. }
  143.  
  144. public boolean isAtCourse() {
  145. for (Obstacle o : Obstacle.values()) {
  146. GameObject ob = GameObjects.getNearest(o.getId());
  147. if (ob != null && ob.isReachable()) {
  148. return true;
  149. }
  150. }
  151. return false;
  152. }
  153.  
  154. public Obstacle getNextObstacle() {
  155. switch (coursePicked) {
  156. case "Gnome":
  157. if ((Players.getMyPlayer().getLocation().getY() >= Obstacle.LOG_GNOME.getBeginTile().getY()
  158. && Players.getMyPlayer().getLocation().getX() >= 2474)
  159. || Players.getMyPlayer().getLocation().getY() >= 3436)
  160. return Obstacle.LOG_GNOME;
  161. break;
  162. case "Barb":
  163. if ((Players.getMyPlayer().getLocation().getX() == Obstacle.WALL3_BARB.getEndTile().getX()
  164. && Players.getMyPlayer().getLocation().getY() == Obstacle.WALL3_BARB.getEndTile().getY())
  165. || Players.getMyPlayer().getLocation().getY() >= 3554)
  166. return Obstacle.ROPE_BARB;
  167. break;
  168. case "Wild":
  169. if ((Players.getMyPlayer().getLocation().getY() <= Obstacle.PIPE_WILD.getBeginTile().getY()
  170. && Players.getMyPlayer().getLocation().getX() >= 2997)
  171. || Players.getMyPlayer().getLocation().getY() <= Obstacle.WALL_WILD.getEndTile().getY())
  172. return Obstacle.PIPE_WILD;
  173. break;
  174. }
  175. boolean thisOne = false;
  176. for (Obstacle o : Obstacle.values()) {
  177. if (thisOne)
  178. return o;
  179. if (Players.getMyPlayer().getLocation().getX() == o.getEndTile().getX()
  180. && Players.getMyPlayer().getLocation().getY() == o.getEndTile().getY())
  181. thisOne = true;
  182. if (Players.getMyPlayer().getLocation().getX() == o.getBeginTile().getX()
  183. && Players.getMyPlayer().getLocation().getY() == o.getBeginTile().getY())
  184. return o;
  185. }
  186. return null;
  187. }
  188.  
  189. public enum Obstacle {
  190.  
  191. /* GNOME VILLAGE AGILITY OBSTACLES */
  192. LOG_GNOME(23145, new Tile(2474, 3436), new Tile(2474, 3429), "Walk-across"), NET_GNOME(23134,
  193. new Tile(2474, 3426), new Tile(2474, 3424),
  194. "Climb-over"), TREE_GNOME(23559, new Tile(2474, 3422), new Tile(2473, 3420), "Climb"), ROPE_GNOME(23557,
  195. new Tile(2477, 3420), new Tile(2483, 3420), "Walk-on"), TREE2_GNOME(23560, new Tile(2485, 3419),
  196. new Tile(2487, 3421), "Climb-down"), NET2_GNOME(23135, new Tile(2484, 3425),
  197. new Tile(2484, 3427), "Climb-over"), PIPE_GNOME(23138, new Tile(2484, 3430),
  198. new Tile(2484, 3437), "Squeeze-through"),
  199.  
  200. /* BARBARIAN VILLAGE AGILITY OBSTACLES */
  201. ROPE_BARB(23131, new Tile(2551, 3554), new Tile(2551, 3549), "Swing-on"), LOG_BARB(23144, new Tile(2551, 3546),
  202. new Tile(2541, 3546),
  203. "Walk-across"), NET_BARB(20211, new Tile(2539, 3546), new Tile(2537, 3546), "Climb-over"), LEDGE_BARB(
  204. 23547, new Tile(2536, 3547), new Tile(2532, 3546), "Walk-across"), WALL_BARB(1948,
  205. new Tile(2535, 3553), new Tile(2537, 3553), "Climb-over"), WALL2_BARB(1948,
  206. new Tile(2538, 3553), new Tile(2540, 3553), "Climb-over"), WALL3_BARB(1948,
  207. new Tile(2541, 3553), new Tile(2543, 3553), "Climb-over"),
  208. /* WILDERNESS AGILITY OBSTACLES */
  209. PIPE_WILD(23137, new Tile(3004, 3937), new Tile(3004, 3950), "Squeeze-through"), SWING_WILD(23132,
  210. new Tile(3005, 3953), new Tile(3005, 3958), "Swing-on"), STONES_WILD(23556, new Tile(3002, 3960),
  211. new Tile(2996, 3960), "Cross"), LOG_WILD(23542, new Tile(3002, 3945), new Tile(2994, 3945),
  212. "Walk-across"), WALL_WILD(23640, new Tile(2995, 3937), new Tile(2995, 3933), "Climb"),;
  213.  
  214. private int id;
  215. private Tile beginTile;
  216. private Tile endTile;
  217. private String action;
  218.  
  219. Obstacle(int id, Tile beginTile, Tile endTile, String action) {
  220. this.id = id;
  221. this.beginTile = beginTile;
  222. this.endTile = endTile;
  223. this.action = action;
  224. }
  225.  
  226. public int getId() {
  227. return id;
  228. }
  229.  
  230. public Tile getBeginTile() {
  231. return beginTile;
  232. }
  233.  
  234. public Tile getEndTile() {
  235. return endTile;
  236. }
  237.  
  238. public String getAction() {
  239. return action;
  240. }
  241. }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement