58 private static final Logger logger = LogManager.getLogger(
DialogueFactory.class);
61 private final Queue<Chainable> CHAIN =
new ArrayDeque<>();
64 private static final int MAXIMUM_LENGTH = 100;
67 private final Player player;
70 private boolean active;
73 private Optional<Runnable> nextAction = Optional.empty();
74 private boolean locked;
91 player.dialogue = Optional.of(dialogue);
92 dialogue.sendDialogues(
this);
108 public void lock(
boolean lock) {
122 player.interfaceManager.close();
134 if (result.isPresent()) {
137 if (type < 0 || type >= optionDialogue.
getActions().size()) {
154 nextAction = Optional.empty();
155 player.dialogue = Optional.empty();
156 player.optionDialogue = Optional.empty();
158 player.interfaceManager.setDialogue(-1);
168 this.CHAIN.add(chain);
199 if (player.movement.isMoving()) {
200 player.movement.reset();
211 player.optionDialogue = Optional.of(option);
213 player.optionDialogue = Optional.empty();
216 player.interfaceManager.setDialogue(1);
229 player.optionDialogue = Optional.empty();
233 player.dialogueFactory.clear();
243 private final String appendKeywords(String line) {
244 if (line.contains(
"#username")) {
245 line = line.replace(
"#username",
Utility.formatName((player.
getName())));
247 if (line.contains(
"#name")) {
248 line = line.replace(
"#name",
Utility.formatName((player.
getName())));
281 Expression expression = dialogue.getExpression();
282 String[] lines = dialogue.getLines();
283 validateLength(lines);
284 switch (lines.length) {
288 player.send(
new SendString(appendKeywords(lines[0]), 971));
295 player.send(
new SendString(appendKeywords(lines[0]), 976));
296 player.send(
new SendString(appendKeywords(lines[1]), 977));
303 player.send(
new SendString(appendKeywords(lines[0]), 982));
304 player.send(
new SendString(appendKeywords(lines[1]), 983));
305 player.send(
new SendString(appendKeywords(lines[2]), 984));
312 player.send(
new SendString(appendKeywords(lines[0]), 989));
313 player.send(
new SendString(appendKeywords(lines[1]), 990));
314 player.send(
new SendString(appendKeywords(lines[2]), 991));
315 player.send(
new SendString(appendKeywords(lines[3]), 992));
320 logger.error(String.format(
"Invalid player dialogue line length: %s", lines.length));
346 return append(
new NpcDialogue(
id, expression, lines));
356 Expression expression = dialogue.getExpression();
357 String[] lines = dialogue.getLines();
358 validateLength(lines);
359 int id = dialogue.getId();
362 if (npcDef ==
null)
return this;
363 switch (lines.length) {
367 player.send(
new SendString(appendKeywords(lines[0]), 4885));
374 player.send(
new SendString(appendKeywords(lines[0]), 4890));
375 player.send(
new SendString(appendKeywords(lines[1]), 4891));
382 player.send(
new SendString(appendKeywords(lines[0]), 4896));
383 player.send(
new SendString(appendKeywords(lines[1]), 4897));
384 player.send(
new SendString(appendKeywords(lines[2]), 4898));
391 player.send(
new SendString(appendKeywords(lines[0]), 4903));
392 player.send(
new SendString(appendKeywords(lines[1]), 4904));
393 player.send(
new SendString(appendKeywords(lines[2]), 4905));
394 player.send(
new SendString(appendKeywords(lines[3]), 4906));
399 logger.error(String.format(
"Invalid npc dialogue line length: %s", lines.length));
414 return append(
new OptionDialogue(option1, action1, option2, action2));
427 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3) {
428 return append(
new OptionDialogue(option1, action1, option2, action2, option3, action3));
443 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4) {
444 return append(
new OptionDialogue(option1, action1, option2, action2, option3, action3, option4, action4));
461 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4, String option5, Runnable action5) {
462 return append(
new OptionDialogue(option1, action1, option2, action2, option3, action3, option4, action4, option5, action5));
472 String[] options = dialogue.getLines();
473 validateLength(options);
474 switch (options.length) {
476 player.send(
new SendString(
"Select an Option", 2460));
477 player.send(
new SendString(options[0], 2461));
478 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[0], 2461));
479 player.send(
new SendString(options[1], 2462));
480 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[1], 2461));
484 player.send(
new SendString(
"Select an Option", 2470));
485 player.send(
new SendString(options[0], 2471));
486 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[0], 2471));
487 player.send(
new SendString(options[1], 2472));
488 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[1], 2472));
489 player.send(
new SendString(options[2], 2473));
490 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[2], 2473));
494 player.send(
new SendString(
"Select an Option", 2481));
495 player.send(
new SendString(options[0], 2482));
496 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[0], 2482));
497 player.send(
new SendString(options[1], 2483));
498 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[1], 2483));
499 player.send(
new SendString(options[2], 2484));
500 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[2], 2484));
501 player.send(
new SendString(options[3], 2485));
502 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[3], 2485));
506 player.send(
new SendString(
"Select an Option", 2493));
507 player.send(
new SendString(options[0], 2494));
508 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[0], 2494));
509 player.send(
new SendString(options[1], 2495));
510 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[1], 2495));
511 player.send(
new SendString(options[2], 2496));
512 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[2], 2496));
513 player.send(
new SendString(options[3], 2497));
514 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[3], 2497));
515 player.send(
new SendString(options[4], 2498));
516 player.send(
new SendTooltip(
"</col>Select <col=A89590>" + options[4], 2498));
530 validateLength(lines);
541 validateLength(dialogue.getLines());
542 switch (dialogue.getLines().length) {
544 player.send(
new SendString(dialogue.getLines()[0], 357));
548 player.send(
new SendString(dialogue.getLines()[0], 360));
549 player.send(
new SendString(dialogue.getLines()[1], 361));
553 player.send(
new SendString(dialogue.getLines()[0], 364));
554 player.send(
new SendString(dialogue.getLines()[1], 365));
555 player.send(
new SendString(dialogue.getLines()[2], 366));
559 player.send(
new SendString(dialogue.getLines()[0], 369));
560 player.send(
new SendString(dialogue.getLines()[1], 370));
561 player.send(
new SendString(dialogue.getLines()[2], 371));
562 player.send(
new SendString(dialogue.getLines()[3], 372));
566 player.send(
new SendString(dialogue.getLines()[0], 375));
567 player.send(
new SendString(dialogue.getLines()[1], 376));
568 player.send(
new SendString(dialogue.getLines()[2], 377));
569 player.send(
new SendString(dialogue.getLines()[3], 378));
570 player.send(
new SendString(dialogue.getLines()[4], 379));
574 logger.error(String.format(
"Invalid statement dialogue line length: %s", dialogue.getLines().length));
580 public final DialogueFactory sendItem(String title, String text, Item item) {
581 validateLength(text);
582 append(
new ItemDialogue(title, text, item.getId()));
586 public final DialogueFactory sendItem(String title, String text,
int item) {
587 validateLength(text);
588 append(
new ItemDialogue(title, text, item));
593 validateLength(dialogue.getContext());
595 player.send(
new SendString(dialogue.getTitle(), 4884));
596 player.send(
new SendString(dialogue.getContext(), 4885));
597 player.send(
new SendString(
"Click here to continue.", 4886));
603 public final DialogueFactory sendInformationBox(String title, String...lines) {
604 validateLength(lines);
605 append(
new InformationDialogue(title, lines));
609 final DialogueFactory sendInformationBox(InformationDialogue dialogue) {
610 validateLength(dialogue.getLines());
611 switch (dialogue.getLines().length) {
613 player.send(
new SendString(dialogue.getTitle(), 6180));
614 player.send(
new SendString(
"", 6181));
615 player.send(
new SendString(dialogue.getLines()[0], 6182));
616 player.send(
new SendString(
"", 6183));
617 player.send(
new SendString(
"", 6184));
618 player.send(
new SendChatBoxInterface(6179));
621 player.send(
new SendString(dialogue.getTitle(), 6180));
622 player.send(
new SendString(
"", 6181));
623 player.send(
new SendString(dialogue.getLines()[0], 6182));
624 player.send(
new SendString(dialogue.getLines()[1], 6183));
625 player.send(
new SendString(
"", 6184));
626 player.send(
new SendChatBoxInterface(6179));
629 player.send(
new SendString(dialogue.getTitle(), 6180));
630 player.send(
new SendString(
"", 6181));
631 player.send(
new SendString(dialogue.getLines()[0], 6182));
632 player.send(
new SendString(dialogue.getLines()[1], 6183));
633 player.send(
new SendString(dialogue.getLines()[2], 6184));
634 player.send(
new SendChatBoxInterface(6179));
637 player.send(
new SendString(dialogue.getTitle(), 6180));
638 player.send(
new SendString(dialogue.getLines()[0], 6181));
639 player.send(
new SendString(dialogue.getLines()[1], 6182));
640 player.send(
new SendString(dialogue.getLines()[2], 6183));
641 player.send(
new SendString(dialogue.getLines()[3], 6184));
642 player.send(
new SendChatBoxInterface(6179));
645 logger.error(String.format(
"Invalid information dialogue line length: %s", dialogue.getLines().length));
657 private final void validateLength(String... text) {
658 if (Arrays.stream(text).filter(Objects::nonNull).anyMatch(s -> s.length() > MAXIMUM_LENGTH)) {
659 throw new IllegalStateException(
"Dialogue length too long, maximum length is: " + MAXIMUM_LENGTH);
688 this.nextAction = nextAction;
691 public boolean isActive() {
695 public void setActive(
boolean active) {
696 this.active = active;
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4, String option5, Runnable action5)
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4)
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3)