1package com.runehive.content.dialogue;
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;
24 private final Queue<Chainable>
CHAIN =
new ArrayDeque<>();
36 private Optional<Runnable>
nextAction = Optional.empty();
54 player.dialogue = Optional.of(
dialogue);
85 player.interfaceManager.close();
97 if (result.isPresent()) {
100 if (type < 0 || type >= optionDialogue.
getActions().size()) {
118 player.dialogue = Optional.empty();
119 player.optionDialogue = Optional.empty();
121 player.interfaceManager.setDialogue(-1);
124 player.playerAssistant.clearSendStrings();
133 this.CHAIN.add(chain);
164 if (
player.movement.isMoving()) {
176 player.optionDialogue = Optional.of(option);
178 player.optionDialogue = Optional.empty();
181 player.interfaceManager.setDialogue(1);
194 player.optionDialogue = Optional.empty();
198 player.dialogueFactory.clear();
209 if (line.contains(
"#username")) {
212 if (line.contains(
"#name")) {
247 String[] lines =
dialogue.getLines();
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) {
288 logger.error(String.format(
"Invalid player dialogue line length: %s", lines.length));
325 String[] lines =
dialogue.getLines();
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);
333 if (npcDef ==
null)
return this;
334 switch (lines.length) {
370 logger.error(String.format(
"Invalid npc dialogue line length: %s", lines.length));
398 public final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2, String option3, Runnable action3) {
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));
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));
443 String[] options =
dialogue.getLines();
445 switch (options.length) {
513 switch (
dialogue.getLines().length) {
545 logger.error(String.format(
"Invalid statement dialogue line length: %s",
dialogue.getLines().length));
582 switch (
dialogue.getLines().length) {
616 logger.error(String.format(
"Invalid information dialogue line length: %s",
dialogue.getLines().length));
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);
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.
static final Logger logger
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.
void setActive(boolean active)
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...
Handles the information box dialogue.
Handles the item on dialogue.
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 ...
Contains the npc definitions.
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
This class represents a character controlled by a player.
The container class that represents an item that can be interacted with.
final int getId()
Gets the identification of this item.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
static String formatName(final String input)
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...