Advertisement
Guest User

Willow Chop'N'Sell - Shop.java

a guest
Nov 21st, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Point;
  4.  
  5. import org.tribot.api.General;
  6. import org.tribot.api.input.Mouse;
  7. import org.tribot.api2007.ChooseOption;
  8. import org.tribot.api2007.Interfaces;
  9. import org.tribot.api2007.Inventory;
  10. import org.tribot.api2007.types.RSItem;
  11.  
  12. public class Shop {
  13.  
  14. public static int getSlot(int itemId) {
  15. if (isShopOpen()) {
  16. RSItem[] items = getItems();
  17. for (int i = 0; i < getStockLength(); i++) {
  18. if (items[i] != null && itemId == items[i].getID())
  19. return i;
  20. }
  21. }
  22. return -1;
  23. }
  24.  
  25. public static boolean contains(int id) {
  26. if (isShopOpen()) {
  27. for (RSItem r : Interfaces.get(300, 75).getItems()) {
  28. if (r.getID() == id)
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34.  
  35. static public void buy(int id) {
  36. int index = -1;
  37. if (Shop.isShopOpen()) {
  38. for (int i = 0; i < Shop.getItems().length; i++) {
  39. if (Shop.getItems()[i].getID() == id) {
  40. index = i;
  41. }
  42. }
  43. if (index == -1)
  44. return;
  45. int itemX = (int) Math.ceil((index) % 8);
  46. int itemY = (int) ((Math.floor(index) / 8) % 5);
  47. int y = (itemY * 45) + 82;
  48. int x = (itemX * 46) + 97;
  49.  
  50. // from here it's terrible, but the main part is up above
  51. Mouse.move(new Point(x, y));
  52. General.sleep(200);
  53. Mouse.click(3);
  54. if (ChooseOption.isOpen() && ChooseOption.isOptionValid("Buy 10")) {
  55. ChooseOption.select("Buy 10");
  56. }
  57. }
  58. }
  59.  
  60. public static boolean isShopOpen() {
  61. return Interfaces.get(300, 75) != null;
  62. }
  63.  
  64. public String getShopName() {
  65. if (Interfaces.get(300, 76) != null)
  66. return Interfaces.get(300, 76).getText();
  67.  
  68. return null;
  69. }
  70.  
  71. public static boolean close() {
  72. if (Interfaces.get(300, 91) != null) {
  73. if (Interfaces.get(300, 91).click("Close")) {
  74. General.sleep(600);
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80.  
  81. static int getStockLength() {
  82. if (isShopOpen())
  83. return Interfaces.get(300, 75).getItems().length;
  84.  
  85. return 0;
  86. }
  87.  
  88. public static boolean sell(int id, int count) {
  89. if (isShopOpen()) {
  90. RSItem[] item = Inventory.find(id);
  91. if (item.length > 0) {
  92. if (count == 0 || count > 10) {
  93. if (item[0].click("Sell 10")) {
  94. General.sleep(750);
  95. return true;
  96. }
  97. } else {
  98. if (item[0].click("Sell " + count)) {
  99. General.sleep(750);
  100. return true;
  101. }
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107.  
  108. public static RSItem[] getItems() {
  109. if (Interfaces.get(300, 75) != null)
  110. return Interfaces.get(300, 75).getItems();
  111.  
  112. return null;
  113. }
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement