RuneHive-Game
Loading...
Searching...
No Matches
DialogueFactory.java
Go to the documentation of this file.
1package com.runehive.content.dialogue;
2
3import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.items.Item;
6import com.runehive.net.packet.out.*;
7import com.runehive.util.Utility;
8import org.apache.logging.log4j.LogManager;
9import org.apache.logging.log4j.Logger;
10
11import java.util.*;
12
13/**
14 * Represents a factory class that contains important functions for building
15 * dialogues.
16 *
17 * @author nshusa
18 */
19public final class DialogueFactory {
20
21 private static final Logger logger = LogManager.getLogger(DialogueFactory.class);
22
23 /** The queue of dialogues in this factory. */
24 private final Queue<Chainable> CHAIN = new ArrayDeque<>();
25
26 /** The maximum length of a single line of dialogue. */
27 private static final int MAXIMUM_LENGTH = 500;
28
29 /** The player who owns this factory. */
30 private final Player player;
31
32 /** The flag that denotes dialogue is active. */
33 private boolean active;
34
35 /** The next action in the dialogue chain. */
36 private Optional<Runnable> nextAction = Optional.empty();
37 private boolean locked;
38
39 /**
40 * Creates a new {@link DialogueFactory}.
41 *
42 * @param player The player who owns this factory.
43 */
45 this.player = player;
46 }
47
48 /**
49 * Sends a player a dialogue.
50 *
51 * @param dialogue The dialogue to sent.
52 */
54 player.dialogue = Optional.of(dialogue);
55 dialogue.sendDialogues(this);
56 return this;
57 }
58
59 /**
60 * Sets an {@code action} so this action can be executed after dialogues are
61 * done.
62 *
63 * @param action The action to set.
64 * @return The instance of this factory.
65 */
66 public final DialogueFactory onAction(Runnable action) {
67 setNextAction(Optional.of(action));
68 return this;
69 }
70
71 public void lock(boolean lock) {
72 this.locked = lock;
73 }
74
75 /**
76 * Accepts the next dialogue in the chain.
77 *
78 * @return The instance of this factory.
79 */
81 if (getChain().peek() != null) {
82 Chainable chain = getChain().poll();
83 chain.accept(this);
84 } else {
85 player.interfaceManager.close();
86 }
87 return this;
88 }
89
90 /**
91 * Executes an {@code result} for a {@code player}.
92 *
93 * @param type The type of option.
94 * @param result The option to execute.
95 */
96 public final DialogueFactory executeOption(int type, Optional<OptionDialogue> result) {
97 if (result.isPresent()) {
98 OptionDialogue optionDialogue = result.get();
99
100 if (type < 0 || type >= optionDialogue.getActions().size()) {
101 return this;
102 }
103
104 optionDialogue.getActions().get(type).run();
105 }
106 execute();
107 return this;
108 }
109
110 /**
111 * Clears the current dialogue {@code chain}.
112 *
113 * @return The instance of this factory.
114 */
115 public void clear() {
116 CHAIN.clear();
117 nextAction = Optional.empty();
118 player.dialogue = Optional.empty();
119 player.optionDialogue = Optional.empty();
120 setActive(false);
121 player.interfaceManager.setDialogue(-1);
122 player.send(new SendRemoveInterface(false));
123 // Clear cached interface strings so dialogue can be replayed
124 player.playerAssistant.clearSendStrings();
125 }
126
127 /**
128 * Appends a {@code chain} to this factory.
129 *
130 * @return The instance of this factory.
131 */
132 private final DialogueFactory append(Chainable chain) {
133 this.CHAIN.add(chain);
134 return this;
135 }
136
137 /**
138 * Gets the current chain.
139 *
140 * @return The queue of dialogues.
141 */
142 public final Queue<Chainable> getChain() {
143 return CHAIN;
144 }
145
146 /**
147 * Gets if the dialogue is option.
148 *
149 * @return The option dialogue.
150 */
151 public boolean isOption() {
152 Chainable next = getChain().peek();
153 return next instanceof OptionDialogue;
154 }
155
156 /**
157 * Retrieves the next dialogue in the chain and executes it.
158 *
159 * @return The instance of this factory.
160 */
161 public final DialogueFactory execute() {
162 if (locked)
163 return this;
164 if (player.movement.isMoving()) {
165 player.movement.reset();
166 }
167 // check to see if there are anymore dialogues.
168 if (getChain().peek() != null) {
169
170 // there is so, grab the next dialogue.
171 Chainable entry = getChain().poll();
172
173 // is this an option dialogue?
174 if (entry instanceof OptionDialogue) {
175 OptionDialogue option = (OptionDialogue) entry;
176 player.optionDialogue = Optional.of(option);
177 } else {
178 player.optionDialogue = Optional.empty();
179 }
180
181 player.interfaceManager.setDialogue(1);
182 setActive(true);
183 // whatever dialogue it is, accept it.
184 entry.accept(this);
185 } else {
186 // there are no dialogues in this chain.
187 // is there an action?
188 if (getNextAction().isPresent()) {
189 // there is so, execute it.
190 getNextAction().ifPresent($it -> $it.run());
191 // we just used this action so empty it so it can't be used
192 // again.
193 setNextAction(Optional.empty());
194 player.optionDialogue = Optional.empty();
195 return this;
196 }
197 // there are no more dialogues, so clear the screen.
198 player.dialogueFactory.clear();
199 }
200 return this;
201 }
202
203 /**
204 * Appends keywords to an existing dialogue text.
205 *
206 * @param line The line to check for a keyword.
207 */
208 private final String appendKeywords(String line) {
209 if (line.contains("#username")) {
210 line = line.replace("#username", Utility.formatName((player.getName())));
211 }
212 if (line.contains("#name")) {
213 line = line.replace("#name", Utility.formatName((player.getName())));
214 }
215 return line;
216 }
217
218 /**
219 * Appends a {@link PlayerDialogue} to the current dialogue chain.
220 *
221 * @param lines The dialogue of the player talking.
222 * @return The instance of this factory.
223 */
224 public final DialogueFactory sendPlayerChat(String... lines) {
225 return append(new PlayerDialogue(lines));
226 }
227
228 /**
229 * Appends a {@link PlayerDialogue} to the current dialogue chain.
230 *
231 * @param lines The dialogue of the player talking.
232 * @param expression The expression of this dialogue.
233 * @return The instance of this factory.
234 */
235 public final DialogueFactory sendPlayerChat(Expression expression, String... lines) {
236 return append(new PlayerDialogue(expression, lines));
237 }
238
239 /**
240 * Sends a dialogue with a player talking.
241 *
242 * @param dialogue The player dialogue.
243 * @return The instance of this factory.
244 */
246 Expression expression = dialogue.getExpression();
247 String[] lines = dialogue.getLines();
248 validateLength(lines);
249 // Player speaking → camera behind player, looking at NPC (+slightly faster turn)
250 player.dialogueCamMode = com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode.BEHIND_PLAYER;
251 com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.boostSwap(player, 8);
252 switch (lines.length) {
253 case 1:
254 player.send(new SendInterfaceAnimation(969, expression.getId()));
255 player.send(new SendString(Utility.formatName(player.getName()), 970));
256 player.send(new SendString(appendKeywords(lines[0]), 971));
257 player.send(new SendPlayerDialogueHead(969));
258 player.send(new SendChatBoxInterface(968));
259 break;
260 case 2:
261 player.send(new SendInterfaceAnimation(974, expression.getId()));
262 player.send(new SendString(Utility.formatName(player.getName()), 975));
263 player.send(new SendString(appendKeywords(lines[0]), 976));
264 player.send(new SendString(appendKeywords(lines[1]), 977));
265 player.send(new SendPlayerDialogueHead(974));
266 player.send(new SendChatBoxInterface(973));
267 break;
268 case 3:
269 player.send(new SendInterfaceAnimation(980, expression.getId()));
270 player.send(new SendString(Utility.formatName(player.getName()), 981));
271 player.send(new SendString(appendKeywords(lines[0]), 982));
272 player.send(new SendString(appendKeywords(lines[1]), 983));
273 player.send(new SendString(appendKeywords(lines[2]), 984));
274 player.send(new SendPlayerDialogueHead(980));
275 player.send(new SendChatBoxInterface(979));
276 break;
277 case 4:
278 player.send(new SendInterfaceAnimation(987, expression.getId()));
279 player.send(new SendString(Utility.formatName(player.getName()), 988));
280 player.send(new SendString(appendKeywords(lines[0]), 989));
281 player.send(new SendString(appendKeywords(lines[1]), 990));
282 player.send(new SendString(appendKeywords(lines[2]), 991));
283 player.send(new SendString(appendKeywords(lines[3]), 992));
284 player.send(new SendPlayerDialogueHead(987));
285 player.send(new SendChatBoxInterface(986));
286 break;
287 default:
288 logger.error(String.format("Invalid player dialogue line length: %s", lines.length));
289 break;
290 }
291 return this;
292 }
293
294 /**
295 * Appends an {@link NpcDialogue} to the current dialogue chain.
296 *
297 * @param id The id of this npc.
298 * @param lines The text of this dialogue.
299 * @return The instance of this factory.
300 */
301 public final DialogueFactory sendNpcChat(int id, String... lines) {
302 return append(new NpcDialogue(id, Expression.DEFAULT, lines));
303 }
304
305 /**
306 * Appends an {@link NpcDialogue} to the current dialogue chain.
307 *
308 * @param id The id of this npc.
309 * @param expression The expression of this npc.
310 * @param lines The text of this dialogue.
311 * @return The instance of this factory.
312 */
313 public final DialogueFactory sendNpcChat(int id, Expression expression, String... lines) {
314 return append(new NpcDialogue(id, expression, lines));
315 }
316
317 /**
318 * Sends a dialogue with a npc talking.
319 *
320 * @param dialogue The dialogue.
321 * @return The instance of this factory.
322 */
324 Expression expression = dialogue.getExpression();
325 String[] lines = dialogue.getLines();
326 validateLength(lines);
327 // NPC speaking → camera behind NPC, looking at player (+slightly faster turn)
328 player.dialogueCamMode = com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode.BEHIND_NPC;
329 com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.boostSwap(player, 8);
330 int id = dialogue.getId();
331 final NpcDefinition npcDef = NpcDefinition.get(id);
332
333 if (npcDef == null) return this;
334 switch (lines.length) {
335 case 1:
336 player.send(new SendInterfaceAnimation(4883, expression.getId()));
337 player.send(new SendString(npcDef.getName(), 4884));
338 player.send(new SendString(appendKeywords(lines[0]), 4885));
339 player.send(new SendNpcHead(npcDef.getId(), 4883));
340 player.send(new SendChatBoxInterface(4882));
341 break;
342 case 2:
343 player.send(new SendInterfaceAnimation(4888, expression.getId()));
344 player.send(new SendString(npcDef.getName(), 4889));
345 player.send(new SendString(appendKeywords(lines[0]), 4890));
346 player.send(new SendString(appendKeywords(lines[1]), 4891));
347 player.send(new SendNpcHead(npcDef.getId(), 4888));
348 player.send(new SendChatBoxInterface(4887));
349 break;
350 case 3:
351 player.send(new SendInterfaceAnimation(4894, expression.getId()));
352 player.send(new SendString(npcDef.getName(), 4895));
353 player.send(new SendString(appendKeywords(lines[0]), 4896));
354 player.send(new SendString(appendKeywords(lines[1]), 4897));
355 player.send(new SendString(appendKeywords(lines[2]), 4898));
356 player.send(new SendNpcHead(npcDef.getId(), 4894));
357 player.send(new SendChatBoxInterface(4893));
358 break;
359 case 4:
360 player.send(new SendInterfaceAnimation(4901, expression.getId()));
361 player.send(new SendString(npcDef.getName(), 4902));
362 player.send(new SendString(appendKeywords(lines[0]), 4903));
363 player.send(new SendString(appendKeywords(lines[1]), 4904));
364 player.send(new SendString(appendKeywords(lines[2]), 4905));
365 player.send(new SendString(appendKeywords(lines[3]), 4906));
366 player.send(new SendNpcHead(npcDef.getId(), 4901));
367 player.send(new SendChatBoxInterface(4900));
368 break;
369 default:
370 logger.error(String.format("Invalid npc dialogue line length: %s", lines.length));
371 break;
372 }
373 return this;
374 }
375
376 /**
377 * Appends the {@link OptionDialogue} onto the current dialogue chain.
378 *
379 * @param option1 The text for the first option.
380 * @param action1 The action for the first action.
381 * @param option2 The text for the second option.
382 * @param action2 The action for the second action.
383 */
384 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2) {
385 return append(new OptionDialogue(option1, action1, option2, action2));
386 }
387
388 /**
389 * Appends the {@link OptionDialogue} onto the current dialogue chain.
390 *
391 * @param option1 The text for the first option.
392 * @param action1 The action for the first action.
393 * @param option2 The text for the second option.
394 * @param action2 The action for the second action.
395 * @param option3 The text for the third option.
396 * @param action3 The action for the third action.
397 */
398 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3) {
399 return append(new OptionDialogue(option1, action1, option2, action2, option3, action3));
400 }
401
402 /**
403 * Appends the {@link OptionDialogue} onto the current dialogue chain.
404 *
405 * @param option1 The text for the first option.
406 * @param action1 The action for the first action.
407 * @param option2 The text for the second option.
408 * @param action2 The action for the second action.
409 * @param option3 The text for the third option.
410 * @param action3 The action for the third action.
411 * @param option4 The text for the four option.
412 * @param action4 The action for the four action.
413 */
414 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4) {
415 return append(new OptionDialogue(option1, action1, option2, action2, option3, action3, option4, action4));
416 }
417
418 /**
419 * Appends the {@link OptionDialogue} onto the current dialogue chain.
420 *
421 * @param option1 The text for the first option.
422 * @param action1 The action for the first action.
423 * @param option2 The text for the second option.
424 * @param action2 The action for the second action.
425 * @param option3 The text for the third option.
426 * @param action3 The action for the third action.
427 * @param option4 The text for the four option.
428 * @param action4 The action for the four action.
429 * @param option5 The text for the fifth option.
430 * @param action5 The action for the fifth action.
431 */
432 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4, String option5, Runnable action5) {
433 return append(new OptionDialogue(option1, action1, option2, action2, option3, action3, option4, action4, option5, action5));
434 }
435
436 /**
437 * Sends a dialogue with options.
438 *
439 * @param dialogue The dialogue.
440 * @return The instance of this factory.
441 */
443 String[] options = dialogue.getLines();
444 validateLength(options);
445 switch (options.length) {
446 case 2:
447 player.send(new SendString("Select an Option", 2460));
448 player.send(new SendString(options[0], 2461));
449 player.send(new SendTooltip("</col>Select <col=A89590>" + options[0], 2461));
450 player.send(new SendString(options[1], 2462));
451 player.send(new SendTooltip("</col>Select <col=A89590>" + options[1], 2461));
452 player.send(new SendChatBoxInterface(2459));
453 return this;
454 case 3:
455 player.send(new SendString("Select an Option", 2470));
456 player.send(new SendString(options[0], 2471));
457 player.send(new SendTooltip("</col>Select <col=A89590>" + options[0], 2471));
458 player.send(new SendString(options[1], 2472));
459 player.send(new SendTooltip("</col>Select <col=A89590>" + options[1], 2472));
460 player.send(new SendString(options[2], 2473));
461 player.send(new SendTooltip("</col>Select <col=A89590>" + options[2], 2473));
462 player.send(new SendChatBoxInterface(2469));
463 return this;
464 case 4:
465 player.send(new SendString("Select an Option", 2481));
466 player.send(new SendString(options[0], 2482));
467 player.send(new SendTooltip("</col>Select <col=A89590>" + options[0], 2482));
468 player.send(new SendString(options[1], 2483));
469 player.send(new SendTooltip("</col>Select <col=A89590>" + options[1], 2483));
470 player.send(new SendString(options[2], 2484));
471 player.send(new SendTooltip("</col>Select <col=A89590>" + options[2], 2484));
472 player.send(new SendString(options[3], 2485));
473 player.send(new SendTooltip("</col>Select <col=A89590>" + options[3], 2485));
474 player.send(new SendChatBoxInterface(2480));
475 return this;
476 case 5:
477 player.send(new SendString("Select an Option", 2493));
478 player.send(new SendString(options[0], 2494));
479 player.send(new SendTooltip("</col>Select <col=A89590>" + options[0], 2494));
480 player.send(new SendString(options[1], 2495));
481 player.send(new SendTooltip("</col>Select <col=A89590>" + options[1], 2495));
482 player.send(new SendString(options[2], 2496));
483 player.send(new SendTooltip("</col>Select <col=A89590>" + options[2], 2496));
484 player.send(new SendString(options[3], 2497));
485 player.send(new SendTooltip("</col>Select <col=A89590>" + options[3], 2497));
486 player.send(new SendString(options[4], 2498));
487 player.send(new SendTooltip("</col>Select <col=A89590>" + options[4], 2498));
488 player.send(new SendChatBoxInterface(2492));
489 return this;
490 }
491 return this;
492 }
493
494 /**
495 * Appends a {@link StatementDialogue} to the current dialogue chain.
496 *
497 * @param lines The text for this statement.
498 * @return The instance of this factory.
499 */
500 public final DialogueFactory sendStatement(String... lines) {
501 validateLength(lines);
502 append(new StatementDialogue(lines));
503 return this;
504 }
505
506 /**
507 * Sends a player a statement dialogue.
508 *
509 * @param dialogue The statement dialogue.
510 */
512 validateLength(dialogue.getLines());
513 switch (dialogue.getLines().length) {
514 case 1:
515 player.send(new SendString(dialogue.getLines()[0], 357));
516 player.send(new SendChatBoxInterface(356));
517 break;
518 case 2:
519 player.send(new SendString(dialogue.getLines()[0], 360));
520 player.send(new SendString(dialogue.getLines()[1], 361));
521 player.send(new SendChatBoxInterface(359));
522 break;
523 case 3:
524 player.send(new SendString(dialogue.getLines()[0], 364));
525 player.send(new SendString(dialogue.getLines()[1], 365));
526 player.send(new SendString(dialogue.getLines()[2], 366));
527 player.send(new SendChatBoxInterface(363));
528 break;
529 case 4:
530 player.send(new SendString(dialogue.getLines()[0], 369));
531 player.send(new SendString(dialogue.getLines()[1], 370));
532 player.send(new SendString(dialogue.getLines()[2], 371));
533 player.send(new SendString(dialogue.getLines()[3], 372));
534 player.send(new SendChatBoxInterface(368));
535 break;
536 case 5:
537 player.send(new SendString(dialogue.getLines()[0], 375));
538 player.send(new SendString(dialogue.getLines()[1], 376));
539 player.send(new SendString(dialogue.getLines()[2], 377));
540 player.send(new SendString(dialogue.getLines()[3], 378));
541 player.send(new SendString(dialogue.getLines()[4], 379));
542 player.send(new SendChatBoxInterface(374));
543 break;
544 default:
545 logger.error(String.format("Invalid statement dialogue line length: %s", dialogue.getLines().length));
546 break;
547 }
548 return this;
549 }
550
551 public final DialogueFactory sendItem(String title, String text, Item item) {
552 validateLength(text);
553 append(new ItemDialogue(title, text, item.getId()));
554 return this;
555 }
556
557 public final DialogueFactory sendItem(String title, String text, int item) {
558 validateLength(text);
559 append(new ItemDialogue(title, text, item));
560 return this;
561 }
562
564 validateLength(dialogue.getContext());
565 player.send(new SendInterfaceAnimation(4883, 591));
566 player.send(new SendString(dialogue.getTitle(), 4884));
567 player.send(new SendString(dialogue.getContext(), 4885));
568 player.send(new SendString("Click here to continue.", 4886));
569 player.send(new SendItemModelOnInterface(4883, 250, dialogue.getItem()));
570 player.send(new SendChatBoxInterface(4882));
571 return this;
572 }
573
574 public final DialogueFactory sendInformationBox(String title, String...lines) {
575 validateLength(lines);
576 append(new InformationDialogue(title, lines));
577 return this;
578 }
579
581 validateLength(dialogue.getLines());
582 switch (dialogue.getLines().length) {
583 case 1:
584 player.send(new SendString(dialogue.getTitle(), 6180));
585 player.send(new SendString("", 6181));
586 player.send(new SendString(dialogue.getLines()[0], 6182));
587 player.send(new SendString("", 6183));
588 player.send(new SendString("", 6184));
589 player.send(new SendChatBoxInterface(6179));
590 break;
591 case 2:
592 player.send(new SendString(dialogue.getTitle(), 6180));
593 player.send(new SendString("", 6181));
594 player.send(new SendString(dialogue.getLines()[0], 6182));
595 player.send(new SendString(dialogue.getLines()[1], 6183));
596 player.send(new SendString("", 6184));
597 player.send(new SendChatBoxInterface(6179));
598 break;
599 case 3:
600 player.send(new SendString(dialogue.getTitle(), 6180));
601 player.send(new SendString("", 6181));
602 player.send(new SendString(dialogue.getLines()[0], 6182));
603 player.send(new SendString(dialogue.getLines()[1], 6183));
604 player.send(new SendString(dialogue.getLines()[2], 6184));
605 player.send(new SendChatBoxInterface(6179));
606 break;
607 case 4:
608 player.send(new SendString(dialogue.getTitle(), 6180));
609 player.send(new SendString(dialogue.getLines()[0], 6181));
610 player.send(new SendString(dialogue.getLines()[1], 6182));
611 player.send(new SendString(dialogue.getLines()[2], 6183));
612 player.send(new SendString(dialogue.getLines()[3], 6184));
613 player.send(new SendChatBoxInterface(6179));
614 break;
615 default:
616 logger.error(String.format("Invalid information dialogue line length: %s", dialogue.getLines().length));
617 break;
618 }
619 return this;
620 }
621
622 /**
623 * The method that validates the length of {@code text}.
624 *
625 * @param text the text that will be validated.
626 * @throws IllegalStateException if any lines of the text exceed a certain length.
627 */
628 private final void validateLength(String... text) {
629 if (Arrays.stream(text).filter(Objects::nonNull).anyMatch(s -> s.length() > MAXIMUM_LENGTH)) {
630 throw new IllegalStateException("Dialogue length too long, maximum length is: " + MAXIMUM_LENGTH);
631 }
632 }
633
634 /**
635 * The player that owns this factory.
636 *
637 * @return The player.
638 */
639 public Player getPlayer() {
640 return player;
641 }
642
643 /**
644 * Gets the {@link Optional} describing the next action in the dialogue
645 * chain.
646 *
647 * @return The optional describing the next action.
648 */
649 public Optional<Runnable> getNextAction() {
650 return nextAction;
651 }
652
653 /**
654 * Sets the next action in the dialogue chain.
655 *
656 * @param nextAction The action to set.
657 */
658 public void setNextAction(Optional<Runnable> nextAction) {
659 this.nextAction = nextAction;
660 }
661
662 public boolean isActive() {
663 return active;
664 }
665
666 public void setActive(boolean active) {
667 this.active = active;
668 }
669
670}
final DialogueFactory sendStatement(StatementDialogue dialogue)
Sends a player a statement dialogue.
void setNextAction(Optional< Runnable > nextAction)
Sets the next action in the dialogue chain.
static final int MAXIMUM_LENGTH
The maximum length of a single line of dialogue.
final DialogueFactory sendDialogue(Dialogue dialogue)
Sends a player a dialogue.
DialogueFactory onNext()
Accepts the next dialogue in the chain.
final DialogueFactory sendOption(OptionDialogue dialogue)
Sends a dialogue with options.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4)
Appends the OptionDialogue onto the current dialogue chain.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory sendPlayerChat(String... lines)
Appends a PlayerDialogue to the current dialogue chain.
boolean isOption()
Gets if the dialogue is option.
final DialogueFactory sendItem(ItemDialogue dialogue)
final DialogueFactory sendItem(String title, String text, int item)
final Queue< Chainable > getChain()
Gets the current chain.
final DialogueFactory sendNpcChat(NpcDialogue dialogue)
Sends a dialogue with a npc talking.
final DialogueFactory sendPlayerChat(PlayerDialogue dialogue)
Sends a dialogue with a player talking.
final DialogueFactory sendNpcChat(int id, Expression expression, String... lines)
Appends an NpcDialogue to the current dialogue chain.
final DialogueFactory onAction(Runnable action)
Sets an action so this action can be executed after dialogues are done.
Optional< Runnable > getNextAction()
Gets the Optional describing the next action in the dialogue chain.
final Player player
The player who owns this factory.
final DialogueFactory append(Chainable chain)
Appends a chain to this factory.
final Queue< Chainable > CHAIN
The queue of dialogues in this factory.
boolean active
The flag that denotes dialogue is active.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3, String option4, Runnable action4, String option5, Runnable action5)
Appends the OptionDialogue onto the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3)
Appends the OptionDialogue onto the current dialogue chain.
final void validateLength(String... text)
The method that validates the length of text.
final DialogueFactory sendItem(String title, String text, Item item)
Player getPlayer()
The player that owns this factory.
final DialogueFactory sendInformationBox(String title, String...lines)
final String appendKeywords(String line)
Appends keywords to an existing dialogue text.
Optional< Runnable > nextAction
The next action in the dialogue chain.
final DialogueFactory sendPlayerChat(Expression expression, String... lines)
Appends a PlayerDialogue to the current dialogue chain.
final DialogueFactory executeOption(int type, Optional< OptionDialogue > result)
Executes an result for a player.
DialogueFactory(Player player)
Creates a new DialogueFactory.
final DialogueFactory sendInformationBox(InformationDialogue dialogue)
final DialogueFactory sendNpcChat(int id, String... lines)
Appends an NpcDialogue to the current dialogue chain.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
Represents an abstract dialogue, in which extending classes will be able to construct and send dialog...
Definition Dialogue.java:11
The Chainable implementation that represents dialogue in which an NPC is talking.
The Chainable implementation that represents a dialogue in which options are given to the player.
List< Runnable > getActions()
Gets the list of actions for this dialogue.
A Chainable implementation that represents a player talking.
The Chainable implementation that represents a dialogue with a single statement; which has no models ...
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatName(final String input)
Definition Utility.java:645
Represents the expressions of entities for dialogue.
final int getId()
Gets the id for this expression.
The chain-able itemcontainer that allows implementing dialogue factories the ability to chain togethe...