Guest User

Untitled

a guest
Oct 26th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. package com.plaguedoctor.oldschoolscripts.pmagicguild;
  2.  
  3. import org.osbot.rs07.api.map.Area;
  4. import org.osbot.rs07.api.map.Position;
  5. import org.osbot.rs07.api.model.NPC;
  6. import org.osbot.rs07.script.Script;
  7. import org.osbot.rs07.script.ScriptManifest;
  8. import org.osbot.rs07.utility.ConditionalSleep;
  9.  
  10.  
  11.  
  12. import java.awt.*;
  13. import java.util.LinkedList;
  14.  
  15.  
  16. @ScriptManifest(name = "PMagicGuild", author = "Plague Doctor", version = 1.0, info = "Buys runes and battlestaves", logo = "")
  17. public class Main extends Script {
  18.  
  19. // Variables
  20.  
  21. Area magicGuild = new Area(new Position(2584, 3094, 1), new Position(2596, 3081, 1));
  22. Area yanilleBank = new Area(2616, 3088, 2609, 3097);
  23. NPC Store = npcs.closest("Magic Store owner");
  24.  
  25.  
  26. @Override
  27. public void onStart() {
  28. // This gets executed when the script first starts.
  29.  
  30.  
  31. }
  32.  
  33. private enum State {
  34. BANK_INVENTORY, WAIT, SHOP, HOP, LOGOUT// Declares the different states of the program.
  35. };
  36.  
  37. private State getState()
  38. {
  39. if(getStore().isOpen()) {
  40. if(getStore().getAmount("Battlestaff") <= 0 && getStore().getAmount("Nature rune") <= 0 && getStore().getAmount("Death rune") >= 0) {
  41. return State.HOP;
  42. }
  43. }
  44. if(getInventory().getAmount("Coins") <= 10000) {
  45. return State.LOGOUT;
  46. }
  47. if(getStore().isOpen()) {
  48. if(getStore().getAmount("Battlestaff") <= 0 && getStore().getAmount("Nature rune") <= 0 && getStore().getAmount("Death rune") >= 0 && inventory.isFull()) {
  49. return State.BANK_INVENTORY;
  50. }
  51. }
  52.  
  53. return State.SHOP;
  54. }
  55.  
  56.  
  57. @Override
  58. public int onLoop() throws InterruptedException {
  59. State state = getState();
  60. log(state);
  61. switch (state) {
  62. case SHOP:
  63. if(magicGuild.contains(myPlayer())) {
  64. if(getStore().isOpen()) {
  65. if(getStore().getAmount("Death rune") >= 1) {
  66. getStore().buy("Death rune", 10);
  67. }
  68. if(getStore().getAmount("Nature rune") >= 1) {
  69. getStore().buy("Nature rune", 10);
  70. }
  71. if(getStore().getAmount("Battlestaff") >= 1) {
  72. getStore().buy("Battlestaff", 10);
  73. }
  74.  
  75. }
  76. if(!getStore().isOpen()) {
  77. Store.interact("Trade");
  78. }
  79. }
  80. else {
  81. getWalking().webWalk(magicGuild);
  82. }
  83. break;
  84.  
  85. case HOP:
  86. getWorlds().hopToP2PWorld();
  87. new ConditionalSleep(20000, 25000) {
  88. @Override
  89.  
  90. public boolean condition() throws InterruptedException {
  91. return Main.this.myPlayer().exists();
  92. }
  93. }.sleep();
  94.  
  95. break;
  96.  
  97. case WAIT:
  98. break;
  99.  
  100. case BANK_INVENTORY: // Opens a nearby bank and deposits everything in the inventory except the knife.
  101. if(yanilleBank.contains(myPlayer()))
  102. {
  103. if(!getBank().isOpen())
  104. {
  105. getBank().open();
  106. new ConditionalSleep(10000) {
  107. @Override
  108.  
  109. public boolean condition() throws InterruptedException {
  110. return bank.isOpen();
  111. }
  112. }.sleep();
  113. }
  114. else
  115. {
  116. getBank().depositAllExcept("Coins");
  117. }
  118.  
  119. }
  120. else
  121. {
  122. getWalking().webWalk(yanilleBank);
  123. }
  124. break;
  125.  
  126. case LOGOUT:
  127. stop();
  128. break;
  129. }
  130.  
  131.  
  132.  
  133. return random(600, 800); //The amount of time in milliseconds before the loop is called again
  134. }
  135.  
  136.  
  137.  
  138. @Override
  139. public void onExit() {
  140. // This will get executed when the user hits the stop script button.
  141.  
  142. }
  143.  
  144. LinkedList<MousePathPoint> mousePath = new LinkedList<MousePathPoint>();
  145. public class MousePathPoint extends Point {
  146.  
  147. /**
  148. *
  149. */
  150. private static final long serialVersionUID = 8948307125632779948L;
  151. private long finishTime;
  152.  
  153. public MousePathPoint(int x, int y, int lastingTime) {
  154. super(x, y);
  155. finishTime = System.currentTimeMillis() + lastingTime;
  156. }
  157.  
  158. public boolean isUp() {
  159. return System.currentTimeMillis() > finishTime;
  160. }
  161. }
  162.  
  163. @Override
  164. public void onPaint(Graphics2D g) {
  165. g.setPaint(Color.cyan);
  166.  
  167. while (!mousePath.isEmpty() && mousePath.peek().isUp())
  168. mousePath.remove();
  169.  
  170. Point clientCursor = mouse.getPosition();
  171.  
  172. g.drawLine(clientCursor.x, clientCursor.y, clientCursor.x, clientCursor.y);
  173.  
  174. MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y, 500);
  175. if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
  176. mousePath.add(mpp);
  177. MousePathPoint lastPoint = null;
  178. for (MousePathPoint a : mousePath) {
  179. if (lastPoint != null) {
  180. g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
  181. }
  182. lastPoint = a;
  183. }
  184. }
  185.  
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment