armark1ng

Untitled

Sep 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. package com.rs.game.player.dialogues.impl;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import com.rs.game.item.Item;
  6. import com.rs.game.player.Equipment;
  7. import com.rs.game.player.content.CosmeticsHandler;
  8. import com.rs.game.player.dialogues.Dialogue;
  9.  
  10. public class CosmeticsD extends Dialogue {
  11.  
  12. private int slotId;
  13. private int[] costumes;
  14. private int[][] pages;
  15. private int currentPage;
  16.  
  17. @Override
  18. public void start() {
  19. slotId = (int) this.parameters[0];
  20. costumes = slotId == Equipment.SLOT_HAT ? CosmeticsHandler.HATS
  21. : slotId == Equipment.SLOT_CAPE ? CosmeticsHandler.CAPES
  22. : slotId == Equipment.SLOT_AMULET ? CosmeticsHandler.AMULETS
  23. : slotId == Equipment.SLOT_CHEST ? CosmeticsHandler.CHESTS
  24. : slotId == Equipment.SLOT_LEGS ? CosmeticsHandler.LEGS
  25. : slotId == Equipment.SLOT_HANDS ? CosmeticsHandler.GLOVES
  26. : slotId == Equipment.SLOT_WEAPON ? CosmeticsHandler.WEAPONS
  27. : slotId == Equipment.SLOT_SHIELD
  28. ? CosmeticsHandler.SHIELDS
  29. : CosmeticsHandler.BOOTS;
  30. int maxPagesNeeded = ((int) Math.ceil((double) (costumes.length / 3.00)));
  31. maxPagesNeeded = maxPagesNeeded == 0 ? 1 : maxPagesNeeded;
  32. int index = 0;
  33. pages = new int[maxPagesNeeded][3];
  34. for (int i = 0; i < pages.length; i++) {
  35. for (int j = 0; j < pages[i].length; j++) {
  36. if (index > (costumes.length - 1))
  37. continue;
  38. pages[i][j] = costumes[index];
  39. index++;
  40. }
  41. }
  42. currentPage = 0;
  43. if (player.getEquipment().getCosmeticItems().get(slotId) != null) {
  44. sendOptionsDialogue(DEFAULT_OPTIONS_TITLE,
  45. (player.getEquipment().getHiddenSlots()[slotId] ? "Unhide" : "Hide"), "Remove current costume",
  46. "Nevermind");
  47. } else
  48. sendOptionsDialogue("CHOOSE THE COSTUME YOU WANT", getDialogueOptions());
  49. }
  50.  
  51. private String[] getDialogueOptions() {
  52. ArrayList<String> dialogueOptions = new ArrayList<String>(5);
  53.  
  54. int maxPagesNeeded = ((int) Math.ceil((double) (costumes.length / 3.00)));
  55.  
  56. maxPagesNeeded = maxPagesNeeded == 0 ? 1 : maxPagesNeeded;
  57.  
  58. dialogueOptions
  59. .add(currentPage == 0 ? (player.getEquipment().getHiddenSlots()[slotId] ? "Unhide" : "Hide") : "Back");
  60. int itemsCount = 0;
  61. for (int i = 0; i < pages[currentPage].length; i++) {
  62. Item item = new Item(pages[currentPage][i]);
  63. if (item.getId() != 0)
  64. itemsCount++;
  65. }
  66. for (int i = 0; i < itemsCount; i++) {
  67. Item item = new Item(pages[currentPage][i]);
  68. if (item.getId() != 0)
  69. dialogueOptions.add(CosmeticsHandler.getNameOnDialogue(item.getId()));
  70. }
  71. if (currentPage < (maxPagesNeeded - 1))
  72. dialogueOptions.add("More");
  73. else
  74. dialogueOptions.add("Cancel");
  75.  
  76. String[] options = new String[dialogueOptions.size()];
  77. for (int i = 0; i < options.length; i++) {
  78. String option = dialogueOptions.get(i);
  79. if (option == null)
  80. continue;
  81. options[i] = option;
  82. }
  83. return options;
  84. }
  85.  
  86. @Override
  87. public void run(int interfaceId, int componentId) {
  88. if (player.getEquipment().getCosmeticItems().get(slotId) != null) {
  89. if (componentId == OPTION_1)
  90. player.getEquipment().getHiddenSlots()[slotId] = !player.getEquipment().getHiddenSlots()[slotId];
  91. else if (componentId == OPTION_2)
  92. player.getEquipment().getCosmeticItems().set(slotId, null);
  93. player.getAppearence().generateAppearenceData();
  94. end();
  95. return;
  96. }
  97. int itemsCount = 0;
  98. for (int i = 0; i < pages[currentPage].length; i++) {
  99. Item item = new Item(pages[currentPage][i]);
  100. if (item.getId() != 0)
  101. itemsCount++;
  102. }
  103. switch (componentId) {
  104. case OPTION_1:
  105. if (currentPage == 0) {// hide
  106. player.getEquipment().getHiddenSlots()[slotId] = !player.getEquipment().getHiddenSlots()[slotId];
  107. player.getAppearence().generateAppearenceData();
  108. end();
  109. } else {// back
  110. currentPage--;
  111. sendOptionsDialogue("CHOOSE THE COSTUME YOU WANT", getDialogueOptions());
  112. }
  113. break;
  114. case OPTION_2:
  115. if (itemsCount > 0) {
  116. Item item = new Item(pages[currentPage][0]);
  117. setCostume(item);
  118. }
  119. end();
  120. break;
  121. case OPTION_3:
  122. if (itemsCount > 1) {
  123. Item item = new Item(pages[currentPage][1]);
  124. setCostume(item);
  125. }
  126. end();
  127. break;
  128. case OPTION_4:
  129. if (itemsCount > 2) {
  130. Item item = new Item(pages[currentPage][2]);
  131. setCostume(item);
  132. }
  133. end();
  134. break;
  135. case OPTION_5:
  136. if (itemsCount > 2) {
  137. int maxPagesNeeded = ((int) Math.ceil((double) (costumes.length / 3.00)));
  138.  
  139. maxPagesNeeded = maxPagesNeeded == 0 ? 1 : maxPagesNeeded;
  140. if (currentPage < (maxPagesNeeded - 1)) {
  141. currentPage++;
  142. sendOptionsDialogue("CHOOSE THE COSTUME YOU WANT", getDialogueOptions());
  143. } else
  144. end();
  145. } else
  146. end();
  147. break;
  148. }
  149. }
  150.  
  151. public void setCostume(Item item) {
  152. if (CosmeticsHandler.isRestrictedItem(player, item.getId())) {
  153. player.getPackets().sendGameMessage("Apparently you can't use that costume!");
  154. return;
  155. }
  156. if (slotId == Equipment.SLOT_WEAPON) {
  157. boolean twoHanded = Equipment.isTwoHandedWeapon(item);
  158. boolean hasShield = player.getEquipment().getCosmeticItems().get(Equipment.SLOT_SHIELD) != null
  159. || player.getEquipment().getShieldId() != -1;
  160. if (twoHanded && hasShield) {
  161. player.getPackets().sendGameMessage("You can't put on two handed weapon while having a shield.");
  162. return;
  163. }
  164. }
  165. player.getEquipment().getCosmeticItems().set(slotId, item);
  166. player.getAppearence().generateAppearenceData();
  167. }
  168.  
  169. @Override
  170. public void finish() {
  171. }
  172.  
  173. }
Add Comment
Please, Sign In to add comment