Guest User

Untitled

a guest
Jan 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. package org.rsbot.script.methods;
  2.  
  3. import org.rsbot.script.methods.Game.Tab;
  4. import org.rsbot.script.wrappers.RSComponent;
  5. import org.rsbot.script.wrappers.RSItem;
  6.  
  7. public class RuneCrafting extends MethodProvider {
  8.  
  9. public static final int POUCH_SETTING = 720;
  10. public static final int MEDIUM_POUCH = 5510;
  11. public static final int DEGRADED_MEDIUM_POUCH = 5511;
  12. public static final int LARGE_POUCH = 5512;
  13. public static final int DEGRADED_LARGE_POUCH = 5513;
  14. public static final int GIANT_POUCH = 5514;
  15. public static final int DEGRADED_GIANT_POUCH = 5515;
  16. public static final int RUNE_POUCH_REPAIR_SPELL = 68;
  17. public static final int NPC_CONTACT_SPELL = 26;
  18.  
  19. public RuneCrafting(MethodContext ctx) {
  20. super(ctx);
  21. }
  22.  
  23. public int getSetting() {
  24. return methods.settings.getSetting(POUCH_SETTING);
  25. }
  26.  
  27. /**
  28. * Checks if small runecrafting pouch is full.
  29. *
  30. * @author Robert G
  31. *
  32. * @return <tt>true</tt> if the pouch is full, else false.
  33. */
  34. public boolean smallPouchFull() {
  35. return getSetting() == 2;
  36. }
  37.  
  38. /**
  39. * Checks if medium runecrafting pouch is full.
  40. *
  41. * @author Robert G
  42. *
  43. * @return <tt>true</tt> if the pouch is full, else false.
  44. */
  45. public boolean mediumPouchFull() {
  46. return getSetting() == 8 || getSetting() == 40;
  47. }
  48.  
  49. /**
  50. * Checks if large runecrafting pouch is full.
  51. *
  52. * @author Robert G
  53. *
  54. * @return <tt>true</tt> if the pouch is full, else false.
  55. */
  56. public boolean giantPouchFull() {
  57. return getSetting() == 32 || getSetting() == 40;
  58. }
  59.  
  60. /**
  61. * Checks if large runecrafting pouch is full.
  62. *
  63. * @author Robert G
  64. *
  65. * @return <tt>true</tt> if the pouch is full, else false.
  66. */
  67. public boolean largePouchFull() {
  68. return getSetting() == 32 || getSetting() == 40;
  69. }
  70.  
  71. /**
  72. * Interacts with a runecrafting pouch.
  73. *
  74. * @author Robert G
  75. *
  76. * @param arg0
  77. * the pouch id
  78. *
  79. * @param action
  80. * the action to perform
  81. */
  82. public void pouch(int arg0, String action) {
  83. RSItem item = methods.inventory.getItem(arg0);
  84. if (item != null) {
  85. item.interact(action);
  86. sleep(random(1100, 1200));
  87. }
  88. }
  89.  
  90. /**
  91. * Repairs a degraded runecrafting pouches using the lunar spell
  92. * rune pouch repair.
  93. *
  94. * @author Robert G
  95. */
  96. public void runePouchRepair() {
  97. if (methods.game.getTab() != Tab.MAGIC) {
  98. methods.game.openTab(Tab.MAGIC);
  99. waitForTab(Tab.MAGIC);
  100. }
  101. if (methods.magic.canCastSpell(Magic.Spell.REPAIR_RUNE_POUCH)) {
  102. methods.magic.castSpell(Magic.Spell.REPAIR_RUNE_POUCH);
  103. methods.game.openTab(Tab.INVENTORY);
  104. waitForTab(Tab.INVENTORY);
  105. if (methods.game.getTab() == Tab.INVENTORY) {
  106. if (methods.inventory.contains(DEGRADED_MEDIUM_POUCH)) {
  107. pouch(DEGRADED_MEDIUM_POUCH, "Repair");
  108. sleep(random(1000, 1200));
  109. }
  110. if (methods.inventory.contains(DEGRADED_LARGE_POUCH)) {
  111. pouch(DEGRADED_LARGE_POUCH, "Repair");
  112. sleep(random(1000, 1200));
  113. }
  114. if (methods.inventory.contains(DEGRADED_GIANT_POUCH)) {
  115. pouch(DEGRADED_GIANT_POUCH, "Repair");
  116. sleep(random(1000, 1200));
  117. }
  118. }
  119. }
  120. }
  121.  
  122. /**
  123. * Repairs degraded runecrafting pouches.
  124. *
  125. * @author Robert G
  126. */
  127. public void npcRepair() {
  128. if (!getInt(88, 1).isValid()) {
  129. if (methods.game.getTab() != Tab.MAGIC) {
  130. methods.game.openTab(Tab.MAGIC);
  131. waitForTab(Tab.MAGIC);
  132. }
  133. methods.magic.castSpell(Magic.Spell.NPC_CONTACT);
  134. waitForInterface(88, 1);
  135. }
  136. if (getInt(88, 1).isValid()) {
  137. RSComponent scrollBar = getInt(88, 20).getComponent(1);
  138. methods.mouse.move(scrollBar.getCenter());
  139. methods.mouse.drag(460, 250);
  140. if (getInt(88, 22).getComponent(14).isValid()) {
  141. getInt(88, 22).getComponent(14).doClick();
  142. sleep(random(800, 1000));
  143. while (methods.players.getMyPlayer().getAnimation() != -1) {
  144. sleep(50);
  145. }
  146. waitForInterface(64, 5);
  147. }
  148. }
  149. if (getInt(64, 5).isValid()) {
  150. getInt(64, 5).doClick();
  151. waitForInterface(242, 6);
  152. }
  153. if (getInt(242, 6).isValid()) {
  154. getInt(242, 6).doClick();
  155. waitForInterface(65, 6);
  156. }
  157. if (getInt(65, 6).isValid()) {
  158. getInt(65, 6).doClick();
  159. waitForInterface(242, 6);
  160. }
  161. if (getInt(242, 6).isValid()) {
  162. getInt(242, 6).doClick();
  163. waitForInterface(65, 6);
  164. }
  165. if (getInt(65, 6).isValid()) {
  166. getInt(65, 6).doClick();
  167. waitForInterface(243, 7);
  168. }
  169. if (getInt(243, 7).isValid()) {
  170. getInt(243, 7).doClick();
  171. waitForInterface(228, 2);
  172. }
  173. if (getInt(228, 2).isValid()) {
  174. getInt(228, 2).doClick();
  175. waitForInterface(65, 6);
  176. }
  177. if (getInt(65, 6).isValid()) {
  178. getInt(65, 6).doClick();
  179. waitForInterface(243, 7);
  180. }
  181. if (getInt(243, 7).isValid()) {
  182. getInt(243, 7).doClick();
  183. sleep(random(500, 600));
  184. }
  185. }
  186.  
  187. /**
  188. * Waits till a tab is open
  189. *
  190. * @param tab
  191. * the tab to wait for
  192. */
  193. public void waitForTab(Tab tab) {
  194. long start = System.currentTimeMillis();
  195. while (methods.game.getTab() != tab && System.currentTimeMillis() - start < 1000) {
  196. sleep(50);
  197. }
  198. }
  199.  
  200. /**
  201. * Returns the RSComponent with the specified ids
  202. *
  203. * @author Robert G
  204. *
  205. * @param parent
  206. * The parent id
  207. *
  208. * @param child
  209. * The child id
  210. */
  211. public RSComponent getInt(int parent, int child) {
  212. return methods.interfaces.getComponent(parent, child);
  213. }
  214.  
  215. /**
  216. * Waits till the specified interface is valid
  217. *
  218. * @author Robert G
  219. *
  220. * @param parent
  221. * The parent id
  222. *
  223. * @param child
  224. * The child id
  225. */
  226. public void waitForInterface(int parent, int child) {
  227. final long start = System.currentTimeMillis();
  228. while (System.currentTimeMillis() - start < 4000) {
  229. sleep(50);
  230. if (getInt(parent, child).isValid()) {
  231. break;
  232. }
  233. }
  234. }
  235.  
  236. }
Add Comment
Please, Sign In to add comment