53public class Overrides {
55 private final Player player;
56 public Overrides(
Player player) {
60 public record OverridePreset(Item... items) {}
61 public Map<String, OverridePreset> presets =
new HashMap<>();
63 public List<Integer> allOverrides =
new ArrayList<>();
64 public Map<Integer, Item> currentOverrides =
new HashMap<>();
66 final Map<Integer, Integer> buttons =
new HashMap<>();
67 final Map<Integer, String> presetButtons =
new HashMap<>();
70 String filterName =
"All";
71 boolean managingOverrides =
false;
73 public void openInterface() {
74 if (
Area.inWilderness(player)) {
75 player.message(
"You can't do this in the wilderness.");
82 player.interfaceManager.open(OVERRIDE_INTERFACE);
85 private void drawText() {
87 player.send(
new SendString(filterName +
" Overrides", 60113));
89 if (filterName.equals(
"Preset")) {
95 for (
int i = 0; i < allOverrides.size(); i++) {
96 final var equipmentSlot =
new Item(allOverrides.get(i)).getDefinition().getEquipmentType().getNewItemDefName();
97 if (!Objects.equals(equipmentSlot, filter.getNewItemDefName()) && filter !=
EquipmentType.NOT_WIELDABLE) {
101 final var itemName =
new Item(allOverrides.get(i)).getName();
102 player.send(
new SendString(itemName, 60146 + (slot * 2)));
103 buttons.put(-5391 + (slot * 2), allOverrides.get(i));
108 private void drawPresets() {
109 for (
int i = 0; i < presets.size(); i++) {
110 final var presetName = presets.keySet().toArray()[i].toString();
111 player.send(
new SendString(presetName, 60146 + (i * 2)));
112 presetButtons.put(-5391 + (i * 2), presetName);
116 private void wipeInterface() {
117 for (
int i = 0; i < allOverrides.size() + 1; i++) {
118 player.send(
new SendString(
"", 60146 + (i * 2)));
121 presetButtons.clear();
124 public void addOverride(
int itemId) {
125 final var item =
new Item(itemId);
126 final var canEquipItem = item.isEquipable();
128 player.dialogueFactory.sendItem(
"Keepsake Overrides",
"You can only keepsake equipable items.", itemId).execute();
131 final var unallowedSlot = item.getEquipmentType() == EquipmentType.RING || item.getEquipmentType() ==
EquipmentType.ARROWS;
133 player.dialogueFactory.sendItem(
"Keepsake Overrides",
"You cannot keepsake this item.", itemId).execute();
136 if (allOverrides.contains(itemId)) {
137 player.dialogueFactory.sendItem(
"Keepsake Overrides",
"You already have this as an override.", itemId).execute();
140 if (allOverrides.size() > 44) {
141 player.dialogueFactory.sendItem(
"Keepsake Overrides",
"You can only have 45 overrides.", itemId).execute();
144 if (
Area.inWilderness(player)) {
145 player.message(
"You can't do this in the wilderness.");
149 player.dialogueFactory.sendStatement(
150 "Are you sure you want to keepsake the " + item.getName() +
"?",
"You will @red@not@bla@ be able to reclaim it.").sendOption(
151 "Yes, keepsake the " + item.getName(), () -> {
152 allOverrides.add(itemId);
153 player.inventory.remove(2399, 1);
154 player.inventory.remove(itemId, 1);
156 "Nevermind", () -> player.dialogueFactory.clear()).execute();
159 private void deleteOverride(Item item) {
160 if (!allOverrides.contains(item.getId())) {
161 player.message(
"Error deleting override.");
165 allOverrides.remove(Integer.valueOf(item.getId()));
168 if (currentOverrides.containsValue(item)) {
169 removeOverride(item.getId());
173 for (
int i = 0; i < presets.size(); i++) {
174 final var preset = presets.get(presets.keySet().toArray()[i].toString());
175 if (Arrays.stream(preset.items).anyMatch(presetItem -> presetItem !=
null && presetItem.getId() == item.getId())) {
176 presets.remove(presets.keySet().toArray()[i].toString());
177 player.message(
"A preset has been deleted as it contained a deleted override.");
184 public boolean hasOverride(
int slot) {
185 if (
Area.inWilderness(player)) {
188 if (
Area.inDuelArena(player)) {
191 if (!currentOverrides.containsKey(slot)) {
196 return hasWeaponOverride();
207 return hasShieldOverride();
224 return currentOverrides.containsKey(slot);
227 private boolean hasWeaponOverride() {
228 final var hasWeapon = player.equipment.get(
Equipment.WEAPON_SLOT) !=
null;
229 final var weaponIs2h = hasWeapon && player.equipment.get(
Equipment.WEAPON_SLOT).isTwoHanded();
230 final var weaponIsRanged = hasWeapon && player.equipment.get(
Equipment.WEAPON_SLOT).getRangedDefinition().isPresent();
232 final var hasOverride = currentOverrides.containsKey(
Equipment.WEAPON_SLOT);
233 final var overrideIs2h = hasOverride && currentOverrides.get(
Equipment.WEAPON_SLOT).isTwoHanded();
234 final var overrideIsRanged = hasOverride && currentOverrides.get(
Equipment.WEAPON_SLOT).getRangedDefinition().isPresent();
237 if (weaponIs2h && !overrideIs2h || overrideIs2h && !weaponIs2h) {
240 if (weaponIsRanged && !overrideIsRanged || overrideIsRanged && !weaponIsRanged) {
248 private boolean hasShieldOverride() {
249 final var hasWeapon = player.equipment.get(
Equipment.WEAPON_SLOT) !=
null;
250 final var weaponIs2h = hasWeapon && player.equipment.get(
Equipment.WEAPON_SLOT).isTwoHanded();
252 final var hasOverrideWeapon = currentOverrides.containsKey(
Equipment.WEAPON_SLOT);
253 final var overrideIs2h = hasOverrideWeapon && currentOverrides.get(
Equipment.WEAPON_SLOT).isTwoHanded();
262 return currentOverrides.containsKey(
Equipment.SHIELD_SLOT);
265 public Item
get(
int slot) {
266 return currentOverrides.get(slot);
269 private void createPreset(String presetName) {
270 if (presets.containsKey(presetName)) {
271 player.message(
"You already have a preset named " + presetName +
".");
274 Item[] presetItems =
new Item[11];
275 currentOverrides.forEach((k, v) -> presetItems[k] = v);
277 presets.put(presetName,
new OverridePreset(presetItems));
281 private void loadPreset(String presetName) {
282 if (!presets.containsKey(presetName)) {
283 player.message(
"Error loading preset: " + presetName);
287 removeAllOverrides();
289 for (Item item : presets.get(presetName).items) {
297 private void renamePreset(String currentName, String newName) {
298 if (!presets.containsKey(currentName)) {
299 player.message(
"Error renaming preset: " + currentName);
302 if (presets.containsKey(newName)) {
303 player.message(
"You already have a preset named " + newName +
".");
307 presets.put(newName, presets.get(currentName));
308 presets.remove(currentName);
309 player.message(
"Preset renamed to " + newName +
".");
313 private void deletePreset(String presetName) {
314 if (!presets.containsKey(presetName)) {
315 player.message(
"Error deleting preset: " + presetName);
319 presets.remove(presetName);
320 player.message(
"Preset deleted.");
324 public FightType getFightType(Item item) {
325 WeaponInterface weapon = item ==
null ? null : item.getWeaponInterface();
328 FightType[] oldTypes = player.getWeapon().getFightTypes();
332 for (
int index = 0; index < oldTypes.length; index++) {
333 if (newTypes.length == index) {
337 if (newTypes[index].getStyle().equals(
FightStyle.DEFENSIVE)
338 && player.getCombat().getFightType().getStyle().equals(
FightStyle.DEFENSIVE)) {
339 result = newTypes[index];
343 if (oldTypes[index] == player.getCombat().getFightType()) {
346 if (newControlled != oldControlled) {
349 result = newTypes[index];
354 if (result ==
null) {
355 if (player.getCombat().getFightType().getStyle().equals(
FightStyle.DEFENSIVE)) {
356 result = newTypes[newTypes.length - 1];
358 result = newTypes[1];
364 public boolean handleButtons(
int button) {
365 if (presetButtons.containsKey(button)) {
366 final var presetName = presetButtons.get(button);
367 if (managingOverrides) {
368 managePresetDialogue(presetName);
371 loadPreset(presetName);
374 if (buttons.containsKey(button)) {
375 final var item =
new Item(buttons.get(button));
376 if (managingOverrides) {
377 manageItemDialogue(item);
384 case INFO_BTN -> player.interfaceManager.open(INFO_INTERFACE);
385 case INFO_CLOSE_BTN -> player.interfaceManager.close();
386 case VIEW_ALL_BTN, INFO_GO_BACK_BTN, OPEN_OVERRIDE_BTN -> openInterface();
388 case AMULET_SLOT_BTN -> setFilter(
EquipmentType.AMULET,
"Amulet");
391 case BOOTS_SLOT_BTN -> setFilter(
EquipmentType.BOOTS,
"Boot");
393 case WEAPON_SLOT_BTN -> setFilter(
EquipmentType.WEAPON,
"Weapon");
394 case GLOVES_SLOT_BTN -> setFilter(
EquipmentType.GLOVES,
"Glove");
395 case SHIELD_SLOT_BTN -> setFilter(
EquipmentType.SHIELD,
"Shield");
396 case VIEW_PRESET_BTN -> setFilter(
EquipmentType.NOT_WIELDABLE,
"Preset");
397 case MANAGE_BTN -> manageModeDialogue();
399 case SAVE_PRESET_BTN -> {
400 if (presets.size() > 4) {
401 player.message(
"You already have the maximum amount of presets saved.");
404 player.send(
new SendInputMessage(
"Enter name for preset:", 30, this::createPreset));
411 private void manageModeDialogue() {
412 player.dialogueFactory.sendOption(
413 "Toggle manage mode to " + (managingOverrides ?
"@red@off@bla@" :
"@gre@on@bla@"), () -> managingOverrides = !managingOverrides,
415 "What is manage mode?", () -> player.dialogueFactory.sendStatement(
416 "Manage mode allows you to manage your overrides and presets.",
417 "When manage mode is on, clicking an override or preset will",
418 "open a menu allowing you to equip, delete, or rename it."),
420 "Nevermind", () -> player.dialogueFactory.clear()).execute();
423 private void manageItemDialogue(Item item) {
424 player.dialogueFactory.sendOption(
425 "Equip <col=255>" + item.getName()+
"</col>", () -> equipOverride(item),
427 "@red@Delete " + item.getName(), () -> player.dialogueFactory.sendStatement(
428 "Are you sure you want to delete this override?",
"The item will be @red@permanently lost@bla@.").sendOption(
429 "Yes, permanently delete " + item.getName(), () -> deleteOverride(item),
430 "Nevermind", () -> player.dialogueFactory.clear()),
432 "Nevermind", () -> player.dialogueFactory.clear()).execute();
435 private void managePresetDialogue(String presetName) {
436 player.dialogueFactory.sendOption(
437 "Equip <col=255>" + presetName +
"</col>", () -> loadPreset(presetName),
439 "Rename preset", () -> {
440 player.dialogueFactory.clear();
441 player.dialogueFactory.onAction(() -> player.send(
new SendInputMessage(
"Enter new preset name:", 30, input -> renamePreset(presetName, input))));
444 "@red@Delete " + presetName, () -> player.dialogueFactory.sendStatement(
445 "Are you sure you want to delete this preset?").sendOption(
446 "Yes, delete " + presetName, () -> deletePreset(presetName),
447 "Nevermind", () -> player.dialogueFactory.clear()),
449 "Nevermind", () -> player.dialogueFactory.clear()).execute();
452 private void setFilter(
EquipmentType equipmentType, String name) {
453 filter = equipmentType;
458 public void removeOverride(
int itemId) {
459 player.send(toggleConfig(itemId,
"on"));
462 final var equipmentType =
new Item(itemId).getDefinition().getEquipmentType();
463 currentOverrides.remove(equipmentType.getSlot());
464 player.updateFlags.add(
UpdateFlag.APPEARANCE);
465 player.equipment.updateAnimation();
468 private void removeAllOverrides() {
469 while (!currentOverrides.isEmpty()) {
470 removeOverride(currentOverrides.get(currentOverrides.keySet().iterator().next()).getId());
474 private void equipOverride(Item item) {
475 player.send(toggleConfig(item.getId(),
"off"));
478 final var equipmentType = item.getDefinition().getEquipmentType();
479 currentOverrides.remove(equipmentType.getSlot());
480 currentOverrides.put(equipmentType.getSlot(), item);
481 player.updateFlags.add(
UpdateFlag.APPEARANCE);
482 player.equipment.updateAnimation();
487 private void loadContainers() {
488 currentOverrides.forEach((slot, item) -> {
489 player.send(toggleConfig(item.getId(),
"off"));
494 private SendConfig toggleConfig(
int itemId, String toggle) {
495 final var configValue = toggle.equals(
"on") ? 0 : 1;
496 final var equipmentSlot =
new Item(itemId).getDefinition().getEquipmentType();
497 return switch (equipmentSlot) {
498 case HAT, HELM, MASK, FACE ->
new SendConfig(1300, configValue);
499 case CAPE ->
new SendConfig(1301, configValue);
500 case AMULET ->
new SendConfig(1302, configValue);
501 case WEAPON ->
new SendConfig(1303, configValue);
502 case BODY, TORSO ->
new SendConfig(1304, configValue);
503 case SHIELD ->
new SendConfig(1305, configValue);
504 case LEGS ->
new SendConfig(1306, configValue);
505 case BOOTS ->
new SendConfig(1307, configValue);
506 case GLOVES ->
new SendConfig(1308, configValue);
511 private int determineContainer(
int itemId) {
512 final var equipmentSlot =
new Item(itemId).getDefinition().getEquipmentType();
513 return switch (equipmentSlot) {
514 case HAT, HELM, MASK, FACE -> HEAD_CONTAINER;
515 case CAPE -> CAPE_CONTAINER;
516 case AMULET -> AMULET_CONTAINER;
517 case WEAPON -> WEAPON_CONTAINER;
518 case BODY, TORSO -> BODY_CONTAINER;
519 case SHIELD -> SHIELD_CONTAINER;
520 case LEGS -> LEGS_CONTAINER;
521 case GLOVES -> GLOVES_CONTAINER;
522 case BOOTS -> BOOTS_CONTAINER;
528 final int HEAD_CONTAINER = 60131;
529 final int BODY_CONTAINER = 60135;
530 final int LEGS_CONTAINER = 60137;
531 final int AMULET_CONTAINER = 60133;
532 final int CAPE_CONTAINER = 60132;
533 final int GLOVES_CONTAINER = 60138;
534 final int BOOTS_CONTAINER = 60139;
535 final int WEAPON_CONTAINER = 60134;
536 final int SHIELD_CONTAINER = 60136;
537 final int OVERRIDE_INTERFACE = 60106;
538 final int INFO_INTERFACE = 60260;
539 final int INFO_BTN = -5286;
540 final int INFO_CLOSE_BTN = -5270;
541 final int INFO_GO_BACK_BTN = -5267;
542 final int MANAGE_BTN = -5395;
543 final int HEAD_SLOT_BTN = -5415;
544 final int AMULET_SLOT_BTN = -5413;
545 final int BODY_SLOT_BTN = -5410;
546 final int LEGS_SLOT_BTN = -5408;
547 final int BOOTS_SLOT_BTN = -5407;
548 final int CAPE_SLOT_BTN = -5414;
549 final int WEAPON_SLOT_BTN = -5411;
550 final int GLOVES_SLOT_BTN = -5406;
551 final int SHIELD_SLOT_BTN = -5409;
552 final int VIEW_PRESET_BTN = -5417;
553 final int SAVE_PRESET_BTN = -5422;
554 final int VIEW_ALL_BTN = -5428;
555 final int OPEN_OVERRIDE_BTN = 27659;