Advertisement
OSRSMargins

Untitled

Sep 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public class FruityGrandExchange extends API {
  2.  
  3. private final GrandExchange ge;
  4.  
  5. public FruityGrandExchange(FruityZulrah script) {
  6. this.ge = script.getGrandExchange();
  7. exchangeContext(script.getBot());
  8. }
  9.  
  10. public boolean sell(Exchange exchange) {
  11. SellItemEvent event = new SellItemEvent(exchange);
  12. return execute(event).hasFinished();
  13. }
  14.  
  15. public boolean buy(Exchange exchange) {
  16. BuyItemEvent event = new BuyItemEvent(exchange);
  17. return execute(event).hasFinished();
  18. }
  19.  
  20. public boolean open() {
  21. Entity booth = getBooth();
  22. if (booth != null && booth.interact("Exchange")) {
  23. Time.sleep(ge::isOpen);
  24. return true;
  25. }
  26. return false;
  27. }
  28.  
  29. public boolean close() {
  30. if (ge.close()) {
  31. Time.sleep(() -> !ge.isOpen());
  32. return true;
  33. }
  34. return false;
  35. }
  36.  
  37. public Entity getBooth() {
  38. return getObjects().closest(i -> i.getName().contains("Grand Exchange booth") && i.hasAction("Exchange"));
  39. }
  40.  
  41. public List<GrandExchange.Box> getBoxes() {
  42. return Arrays.asList(GrandExchange.Box.values());
  43. }
  44.  
  45. public GrandExchange.Box getBox(Predicate<GrandExchange.Box> predicate) {
  46. return getBoxes().stream().filter(predicate).findFirst().orElse(null);
  47. }
  48.  
  49. public List<GrandExchange.Box> getBoxes(Predicate<GrandExchange.Box> predicate) {
  50. return getBoxes().stream().filter(predicate).collect(Collectors.toList());
  51. }
  52.  
  53. public List<GrandExchange.Box> getCompletedBoxes() {
  54. return getBoxes(box -> {
  55. GrandExchange.Status status = ge.getStatus(box);
  56. return status == GrandExchange.Status.FINISHED_BUY || status == GrandExchange.Status.FINISHED_SALE;
  57. });
  58. }
  59.  
  60. public List<GrandExchange.Box> getEmptyBoxes() {
  61. return getBoxes(box -> ge.getStatus(box) == GrandExchange.Status.EMPTY);
  62. }
  63.  
  64. public List<GrandExchange.Box> getOffers() {
  65. return getBoxes(box -> ge.getStatus(box) != GrandExchange.Status.EMPTY);
  66. }
  67.  
  68. public List<Integer> getItems() {
  69. List<Integer> items = new ArrayList<>();
  70. getOffers().forEach(box -> items.add(ge.getItemId(box)));
  71. return items;
  72. }
  73.  
  74. public GrandExchange.Box getBoxForID(int id) {
  75. return getBox(box -> ge.getItemId(box) == id);
  76. }
  77.  
  78. @Override
  79. public void initializeModule() {
  80.  
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement