Guest User

Untitled

a guest
May 7th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. package com.osroyale.content.skill.impl.magic;
  2.  
  3. import com.osroyale.game.world.entity.mob.player.Player;
  4. import com.osroyale.game.world.items.Item;
  5. import com.osroyale.game.world.position.Area;
  6. import com.osroyale.net.packet.out.SendItemOnInterface;
  7. import com.osroyale.util.Utility;
  8.  
  9. import java.util.LinkedList;
  10. import java.util.List;
  11.  
  12. /**
  13. * Handles the rune pouch.
  14. *
  15. * @author Daniel//edited by amen
  16. */
  17. public class RunePouch {
  18.  
  19. /** The maximum amount of total runes the player can carry in their rune pouch. */
  20. private static final int MAXIMUM_RUNE_CAPACITY = 16_000;
  21.  
  22. /** Array of all runes allowed to be inside the rune pouch. */
  23. private final Item[] ALLOWED_RUNES = {
  24. new Item(554), new Item(555), new Item(556), new Item(557), new Item(558),
  25. new Item(559), new Item(560), new Item(561), new Item(562), new Item(563),
  26. new Item(564), new Item(565), new Item(566), new Item(9075)
  27. };
  28.  
  29. /** The player instance. */
  30. private final Player player;
  31.  
  32. /** The runes stores in the rune pouch; */
  33. public List<Item> runes = new LinkedList<>();
  34.  
  35. /** Constructs a new <code>RunePouch</code>. */
  36. public RunePouch(Player player) {
  37. this.player = player;
  38. }
  39.  
  40. public void open() {
  41. refresh();
  42. player.interfaceManager.open(41700);
  43. }
  44.  
  45. public void clear() {
  46. runes.forEach(player.inventory::add);
  47. runes.clear();
  48. player.interfaceManager.open(41700);
  49. refresh();
  50. }
  51.  
  52. public void refresh() {
  53. player.send(new SendItemOnInterface(41710, runes.toArray(new Item[runes.size()])));
  54. player.send(new SendItemOnInterface(41711, player.inventory.getItems()));
  55. }
  56.  
  57. public void withdraw(int item, int amount) {
  58. for (Item rune : runes) {
  59. if (rune.getId() == item) {
  60. int current = player.inventory.computeAmountForId(item);
  61. if (rune.getAmount() - amount < 0) amount = rune.getAmount();
  62. player.inventory.add(item, amount);
  63. int newAm = player.inventory.computeAmountForId(item);
  64. if (newAm - current < amount) amount = newAm - current;
  65. rune.decrementAmountBy(amount);
  66. if (rune.getAmount() == 0)
  67. runes.remove(rune);
  68. refresh();
  69. return;
  70. }
  71. }
  72. }
  73.  
  74. public void deposit(Item item, int amount) {
  75. boolean allowed = false;
  76. for (Item rune : ALLOWED_RUNES) {
  77. if (rune.getId() == item.getId()) {
  78. allowed = true;
  79. break;
  80. }
  81. }
  82. if (!allowed) {
  83. player.message("You can only deposit runes into the rune pouch!");
  84. return;
  85. }
  86. int runeAmount = getRuneAmount();
  87. if (runeAmount >= MAXIMUM_RUNE_CAPACITY) {
  88. player.message("You can only have a total of " + Utility.formatDigits(MAXIMUM_RUNE_CAPACITY) + " runes in your rune pouch.");
  89. return;
  90. }
  91. if (amount > item.getAmount()) {
  92. amount = item.getAmount();
  93. }
  94. if (MAXIMUM_RUNE_CAPACITY - runeAmount < amount) {
  95. amount = MAXIMUM_RUNE_CAPACITY - runeAmount;
  96. }
  97.  
  98. for (Item rune : runes) {
  99. if (item.getId() == rune.getId()) {
  100. player.inventory.remove(item.getId(), amount);
  101. rune.incrementAmountBy(amount);
  102. refresh();
  103. return;
  104. }
  105. }
  106.  
  107. if (runes.size() >= 3) {
  108. player.message("Your rune pouch is currently full and can not hold any more runes!");
  109. return;
  110. }
  111.  
  112. player.inventory.remove(item.getId(), amount);
  113. runes.add(new Item(item.getId(), amount));
  114. refresh();
  115. }
  116.  
  117. public int getRuneAmount() {
  118. int amount = 0;
  119. for (Item rune : runes) {
  120. amount += rune.getAmount();
  121. }
  122. return amount;
  123. }
  124.  
  125. public int getRuneAmount(int id) {
  126. int amount = 0;
  127. for (Item rune : runes) {
  128. if (rune.getId() == id)
  129. amount += rune.getAmount();
  130. }
  131. return amount;
  132. }
  133.  
  134. public boolean contains(Item item) {
  135. for (Item rune : runes) {
  136. if (rune.getId() == item.getId() && rune.getAmount() >= item.getAmount())
  137. return true;
  138. }
  139. return false;
  140. }
  141.  
  142. public boolean containsId(int item) {
  143. for (Item rune : runes) {
  144. if (rune.getId() == item)
  145. return true;
  146. }
  147. return false;
  148. }
  149.  
  150. public void remove(Item item) {
  151. for (Item rune : runes) {
  152. if (rune.equalIds(item)) {
  153. rune.decrementAmountBy(item.getAmount());
  154. if (rune.getAmount() == 0)
  155. runes.remove(rune);
  156. return;
  157. }
  158. }
  159. }
  160.  
  161. public boolean death(Item item) {
  162. if (item.getId() == 12971 && Area.inWilderness(player)) {
  163. runes.clear();
  164. return true;
  165. }
  166.  
  167. return false;
  168. }
  169. }
Add Comment
Please, Sign In to add comment