SHARE
TWEET

Untitled

a guest Jan 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class RunePouch {
  2.  
  3.     /** The maximum amount of total runes the player can carry in their rune pouch. */
  4.     private static final int MAXIMUM_RUNE_CAPACITY = 16_000;
  5.  
  6.     /** Array of all runes allowed to be inside the rune pouch. */
  7.     private final Item[] ALLOWED_RUNES = {
  8.             new Item(554), new Item(555), new Item(556), new Item(557), new Item(558),
  9.             new Item(559), new Item(560), new Item(561), new Item(562), new Item(563),
  10.             new Item(564), new Item(565), new Item(566), new Item(9075)
  11.     };
  12.  
  13.     /** The player instance. */
  14.     private final Player player;
  15.  
  16.     /** The runes stores in the rune pouch; */
  17.     public List<Item> runes = new LinkedList<>();
  18.  
  19.     /** Constructs a new <code>RunePouch</code>. */
  20.     public RunePouch(Player player) {
  21.         this.player = player;
  22.     }
  23.  
  24.     public void open() {
  25.         refresh();
  26.         player.interfaceManager.open(41700);
  27.     }
  28.  
  29.     public void clear() {
  30.         runes.forEach(player.inventory::add);
  31.         runes.clear();
  32.         player.interfaceManager.open(41700);
  33.         refresh();
  34.     }
  35.  
  36.     public void refresh() {
  37.         player.send(new SendItemOnInterface(41710, runes.toArray(new Item[runes.size()])));
  38.         player.send(new SendItemOnInterface(41711, player.inventory.getItems()));
  39.     }
  40.  
  41.     public void withdraw(int item, int amount) {
  42.         for (Item rune : runes) {
  43.             if (rune.getId() == item) {
  44.                 int current = player.inventory.computeAmountForId(item);
  45.                 if (rune.getAmount() - amount < 0) amount = rune.getAmount();
  46.                 player.inventory.add(item, amount);
  47.                 int newAm = player.inventory.computeAmountForId(item);
  48.                 if (newAm - current < amount) amount = newAm - current;
  49.                 rune.decrementAmountBy(amount);
  50.                 if (rune.getAmount() == 0)
  51.                     runes.remove(rune);
  52.                 refresh();
  53.                 return;
  54.             }
  55.         }
  56.     }
  57.  
  58.     public void deposit(Item item, int amount) {
  59.         boolean allowed = false;
  60.         for (Item rune : ALLOWED_RUNES) {
  61.             if (rune.getId() == item.getId()) {
  62.                 allowed = true;
  63.                 break;
  64.             }
  65.         }
  66.         if (!allowed) {
  67.             player.message("You can only deposit runes into the rune pouch!");
  68.             return;
  69.         }
  70.         int runeAmount = getRuneAmount();
  71.         if (runeAmount >= MAXIMUM_RUNE_CAPACITY) {
  72.             player.message("You can only have a total of " + Utility.formatDigits(MAXIMUM_RUNE_CAPACITY) + " runes in your rune pouch.");
  73.             return;
  74.         }
  75.         if (amount > item.getAmount()) {
  76.             amount = item.getAmount();
  77.         }
  78.         if (MAXIMUM_RUNE_CAPACITY - runeAmount < amount) {
  79.             amount = MAXIMUM_RUNE_CAPACITY - runeAmount;
  80.         }
  81.  
  82.         for (Item rune : runes) {
  83.             if (item.getId() == rune.getId()) {
  84.                 player.inventory.remove(item.getId(), amount);
  85.                 rune.incrementAmountBy(amount);
  86.                 refresh();
  87.                 return;
  88.             }
  89.         }
  90.  
  91.         if (runes.size() >= 3) {
  92.             player.message("Your rune pouch is currently full and can not hold any more runes!");
  93.             return;
  94.         }
  95.  
  96.         player.inventory.remove(item.getId(), amount);
  97.         runes.add(new Item(item.getId(), amount));
  98.         refresh();
  99.     }
  100.  
  101.     public int getRuneAmount() {
  102.         int amount = 0;
  103.         for (Item rune : runes) {
  104.             amount += rune.getAmount();
  105.         }
  106.         return amount;
  107.     }
  108.  
  109.     public int getRuneAmount(int id) {
  110.         int amount = 0;
  111.         for (Item rune : runes) {
  112.             if (rune.getId() == id)
  113.                 amount += rune.getAmount();
  114.         }
  115.         return amount;
  116.     }
  117.  
  118.     public boolean contains(Item item) {
  119.         for (Item rune : runes) {
  120.             if (rune.getId() == item.getId() && rune.getAmount() >= item.getAmount())
  121.                 return true;
  122.         }
  123.         return false;
  124.     }
  125.  
  126.     public boolean containsId(int item) {
  127.         for (Item rune : runes) {
  128.             if (rune.getId() == item)
  129.                 return true;
  130.         }
  131.         return false;
  132.     }
  133.  
  134.     public void remove(Item item) {
  135.         for (Item rune : runes) {
  136.             if (rune.equalIds(item)) {
  137.                 rune.decrementAmountBy(item.getAmount());
  138.                 if (rune.getAmount() == 0)
  139.                     runes.remove(rune);
  140.                 return;
  141.             }
  142.         }
  143.     }
  144.  
  145.     public boolean death(Item item) {
  146.         if (item.getId() == 12971 && Area.inWilderness(player)) {
  147.             runes.clear();
  148.             return true;
  149.         }
  150.  
  151.         return false;
  152.     }
  153. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top