Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs.game.player.dialogues.impl;
- import java.util.ArrayList;
- import com.rs.game.item.Item;
- import com.rs.game.player.Equipment;
- import com.rs.game.player.content.CosmeticsHandler;
- import com.rs.game.player.dialogues.Dialogue;
- public class CosmeticsD extends Dialogue {
- private int slotId;
- private int[] costumes;
- private int[][] pages;
- private int currentPage;
- @Override
- public void start() {
- slotId = (int) this.parameters[0];
- costumes = slotId == Equipment.SLOT_HAT ? CosmeticsHandler.HATS
- : slotId == Equipment.SLOT_CAPE ? CosmeticsHandler.CAPES
- : slotId == Equipment.SLOT_AMULET ? CosmeticsHandler.AMULETS
- : slotId == Equipment.SLOT_CHEST ? CosmeticsHandler.CHESTS
- : slotId == Equipment.SLOT_LEGS ? CosmeticsHandler.LEGS
- : slotId == Equipment.SLOT_HANDS ? CosmeticsHandler.GLOVES
- : slotId == Equipment.SLOT_WEAPON ? CosmeticsHandler.WEAPONS
- : slotId == Equipment.SLOT_SHIELD
- ? CosmeticsHandler.SHIELDS
- : CosmeticsHandler.BOOTS;
- int maxPagesNeeded = ((int) Math.ceil((double) (costumes.length / 3.00)));
- maxPagesNeeded = maxPagesNeeded == 0 ? 1 : maxPagesNeeded;
- int index = 0;
- pages = new int[maxPagesNeeded][3];
- for (int i = 0; i < pages.length; i++) {
- for (int j = 0; j < pages[i].length; j++) {
- if (index > (costumes.length - 1))
- continue;
- pages[i][j] = costumes[index];
- index++;
- }
- }
- currentPage = 0;
- if (player.getEquipment().getCosmeticItems().get(slotId) != null) {
- sendOptionsDialogue(DEFAULT_OPTIONS_TITLE,
- (player.getEquipment().getHiddenSlots()[slotId] ? "Unhide" : "Hide"), "Remove current costume",
- "Nevermind");
- } else
- sendOptionsDialogue("CHOOSE THE COSTUME YOU WANT", getDialogueOptions());
- }
- private String[] getDialogueOptions() {
- ArrayList<String> dialogueOptions = new ArrayList<String>(5);
- int maxPagesNeeded = ((int) Math.ceil((double) (costumes.length / 3.00)));
- maxPagesNeeded = maxPagesNeeded == 0 ? 1 : maxPagesNeeded;
- dialogueOptions
- .add(currentPage == 0 ? (player.getEquipment().getHiddenSlots()[slotId] ? "Unhide" : "Hide") : "Back");
- int itemsCount = 0;
- for (int i = 0; i < pages[currentPage].length; i++) {
- Item item = new Item(pages[currentPage][i]);
- if (item.getId() != 0)
- itemsCount++;
- }
- for (int i = 0; i < itemsCount; i++) {
- Item item = new Item(pages[currentPage][i]);
- if (item.getId() != 0)
- dialogueOptions.add(CosmeticsHandler.getNameOnDialogue(item.getId()));
- }
- if (currentPage < (maxPagesNeeded - 1))
- dialogueOptions.add("More");
- else
- dialogueOptions.add("Cancel");
- String[] options = new String[dialogueOptions.size()];
- for (int i = 0; i < options.length; i++) {
- String option = dialogueOptions.get(i);
- if (option == null)
- continue;
- options[i] = option;
- }
- return options;
- }
- @Override
- public void run(int interfaceId, int componentId) {
- if (player.getEquipment().getCosmeticItems().get(slotId) != null) {
- if (componentId == OPTION_1)
- player.getEquipment().getHiddenSlots()[slotId] = !player.getEquipment().getHiddenSlots()[slotId];
- else if (componentId == OPTION_2)
- player.getEquipment().getCosmeticItems().set(slotId, null);
- player.getAppearence().generateAppearenceData();
- end();
- return;
- }
- int itemsCount = 0;
- for (int i = 0; i < pages[currentPage].length; i++) {
- Item item = new Item(pages[currentPage][i]);
- if (item.getId() != 0)
- itemsCount++;
- }
- switch (componentId) {
- case OPTION_1:
- if (currentPage == 0) {// hide
- player.getEquipment().getHiddenSlots()[slotId] = !player.getEquipment().getHiddenSlots()[slotId];
- player.getAppearence().generateAppearenceData();
- end();
- } else {// back
- currentPage--;
- sendOptionsDialogue("CHOOSE THE COSTUME YOU WANT", getDialogueOptions());
- }
- break;
- case OPTION_2:
- if (itemsCount > 0) {
- Item item = new Item(pages[currentPage][0]);
- setCostume(item);
- }
- end();
- break;
- case OPTION_3:
- if (itemsCount > 1) {
- Item item = new Item(pages[currentPage][1]);
- setCostume(item);
- }
- end();
- break;
- case OPTION_4:
- if (itemsCount > 2) {
- Item item = new Item(pages[currentPage][2]);
- setCostume(item);
- }
- end();
- break;
- case OPTION_5:
- if (itemsCount > 2) {
- int maxPagesNeeded = ((int) Math.ceil((double) (costumes.length / 3.00)));
- maxPagesNeeded = maxPagesNeeded == 0 ? 1 : maxPagesNeeded;
- if (currentPage < (maxPagesNeeded - 1)) {
- currentPage++;
- sendOptionsDialogue("CHOOSE THE COSTUME YOU WANT", getDialogueOptions());
- } else
- end();
- } else
- end();
- break;
- }
- }
- public void setCostume(Item item) {
- if (CosmeticsHandler.isRestrictedItem(player, item.getId())) {
- player.getPackets().sendGameMessage("Apparently you can't use that costume!");
- return;
- }
- if (slotId == Equipment.SLOT_WEAPON) {
- boolean twoHanded = Equipment.isTwoHandedWeapon(item);
- boolean hasShield = player.getEquipment().getCosmeticItems().get(Equipment.SLOT_SHIELD) != null
- || player.getEquipment().getShieldId() != -1;
- if (twoHanded && hasShield) {
- player.getPackets().sendGameMessage("You can't put on two handed weapon while having a shield.");
- return;
- }
- }
- player.getEquipment().getCosmeticItems().set(slotId, item);
- player.getAppearence().generateAppearenceData();
- }
- @Override
- public void finish() {
- }
- }
Add Comment
Please, Sign In to add comment