Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
package rocks.gravili.notquests.paper.conversation;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

import rocks.gravili.notquests.paper.structs.actions.Action;
import rocks.gravili.notquests.paper.structs.conditions.Condition;

public class ConversationLine {
private final Speaker speaker;
private final String message; // minimessage
private final List<String> messages; // minimessage
private final ArrayList<ConversationLine> next;
private final ArrayList<Action> actions;
private final ArrayList<Condition> conditions;
Expand All @@ -36,10 +39,10 @@ public class ConversationLine {

private int delayInMS;

public ConversationLine(final Speaker speaker, final String identifier, final String message) {
public ConversationLine(final Speaker speaker, final String identifier, final List<String> messages) {
this.speaker = speaker;
this.identifier = identifier;
this.message = message;
this.messages = messages;
next = new ArrayList<>();
conditions = new ArrayList<>();
actions = new ArrayList<>();
Expand All @@ -64,11 +67,20 @@ public final String getIdentifier() {
return identifier;
}

public final String getMessage() {
public final List<String> getMessages() {
if (isShouting()) {
return this.messages.stream().map(s -> "<bold>" + s + "</bold>").toList();
} else {
return this.messages;
}
}

public final String getOneMessage() {
int random = ThreadLocalRandom.current().nextInt(this.messages.size());
if (isShouting()) {
return "<bold>" + message + "</bold>";
return "<bold>" + this.messages.get(random) + "</bold>";
} else {
return message;
return this.messages.get(random);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ public Conversation createTestConversation() {
testConversation.addSpeaker(playerSpeaker, false);

final ConversationLine gustav1 =
new ConversationLine(gustav, "gustav1", "Hello, I'm Gustav! What's your name?");
new ConversationLine(gustav, "gustav1", List.of("Hello, I'm Gustav! What's your name?"));

final ConversationLine player1 = new ConversationLine(playerSpeaker, "player1", "I'm player!");
final ConversationLine player1 = new ConversationLine(playerSpeaker, "player1", List.of("I'm player!"));
final ConversationLine player2 =
new ConversationLine(playerSpeaker, "player2", "None of your business!");
new ConversationLine(playerSpeaker, "player2", List.of("None of your business!"));

gustav1.addNext(player1);
gustav1.addNext(player2);

final ConversationLine gustav2 = new ConversationLine(gustav, "gustav2", "Nice to meet you!");
final ConversationLine gustav3 = new ConversationLine(gustav, "gustav3", "Yeah, fuck you!");
final ConversationLine gustav2 = new ConversationLine(gustav, "gustav2", List.of("Nice to meet you!"));
final ConversationLine gustav3 = new ConversationLine(gustav, "gustav3", List.of("Yeah, fuck you!"));

final ConversationLine player3 =
new ConversationLine(playerSpeaker, "player2", "That was mean...");
new ConversationLine(playerSpeaker, "player2", List.of("That was mean..."));
gustav3.addNext(player3);

final ConversationLine gustav4 = new ConversationLine(gustav, "gustav3", "You are mean too!");
final ConversationLine gustav4 = new ConversationLine(gustav, "gustav3", List.of("You are mean too!"));
player3.addNext(gustav4);

final ConversationLine gustav5 = new ConversationLine(gustav, "gustav3", "I don't like you!");
final ConversationLine gustav5 = new ConversationLine(gustav, "gustav3", List.of("I don't like you!"));

gustav4.addNext(gustav5);

Expand Down Expand Up @@ -324,6 +324,13 @@ public void loadConversationsFromConfig(final Category category) {
for (final String starterLine : starterLines.split(",")) {
final String initialLine = "Lines." + starterLine;
final String message = config.getString(initialLine + ".text", "/skip/");
final List<String> messages = new ArrayList<>();
if ((message.isBlank() || message.equals("/skip/")) && config.get(initialLine + ".texts") != null)
messages.addAll(config.getStringList(initialLine + ".texts"));
else if (message.isBlank())
messages.add("/skip/");
else
messages.add(message);
final ArrayList<Action> actions =
parseActionString(config.getStringList(initialLine + ".actions"));
final boolean shouting = config.getBoolean(initialLine + ".shout", false);
Expand All @@ -345,9 +352,9 @@ public void loadConversationsFromConfig(final Category category) {

// Construct the ConversationLine
final ConversationLine startLine =
new ConversationLine(foundSpeaker, starterLine.split("\\.")[1], message);
new ConversationLine(foundSpeaker, starterLine.split("\\.")[1], messages);

if(message.equals("/skip/")){
if(messages.get(0).equals("/skip/")){
startLine.setSkipMessage(true);
}

Expand Down Expand Up @@ -416,6 +423,13 @@ public void deepDiveAndConnectStarterLines(
final String initialLine = "Lines." + nextLineFullIdentifier;

final String message = config.getString(initialLine + ".text", "/next/");
final List<String> messages = new ArrayList<>();
if ((message.isBlank() || message.equals("/next/")) && config.get(initialLine + ".texts") != null)
messages.addAll(config.getStringList(initialLine + ".texts"));
else if (message.isBlank())
messages.add("/next/");
else
messages.add(message);
final String next = config.getString(initialLine + ".next", "");
final ArrayList<Action> actions =
parseActionString(config.getStringList(initialLine + ".actions"));
Expand Down Expand Up @@ -481,9 +495,9 @@ public void deepDiveAndConnectStarterLines(
}

ConversationLine newLine =
new ConversationLine(foundSpeaker, nextLineFullIdentifier.split("\\.")[1], message);
new ConversationLine(foundSpeaker, nextLineFullIdentifier.split("\\.")[1], messages);

if(message.equals("/skip/")){
if(messages.get(0).equals("/next/")){
newLine.setSkipMessage(true);
}

Expand Down Expand Up @@ -970,7 +984,7 @@ public String analyze(final ConversationLine conversationLine, String beginningS
toReturn
.append(beginningSpaces)
.append(" <unimportant>Message:</unimportant> <main>")
.append(conversationLine.getMessage())
.append(conversationLine.getMessages())
.append("<RESET>\n");

if (conversationLine.getNext().size() >= 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public ArrayList<ConversationLine> findConversationLinesWhichFulfillsCondition(
public void sendLine(final ConversationLine conversationLine, final boolean deletePrevious) {
if(!conversationLine.isSkipMessage()){
for(final ConversationInteractionHandler interactionHandler : main.getConversationManager().getInteractionHandlers()){
interactionHandler.sendText(conversationLine.getMessage(), conversationLine.getSpeaker(), player, questPlayer, conversation, conversationLine, deletePrevious, this);
interactionHandler.sendText(conversationLine.getOneMessage(), conversationLine.getSpeaker(), player, questPlayer, conversation, conversationLine, deletePrevious, this);
}
}

Expand All @@ -275,7 +275,7 @@ public void sendLine(final ConversationLine conversationLine, final boolean dele
*/
public void sendOptionLine(final ConversationLine conversationLine) {
for(final ConversationInteractionHandler interactionHandler : main.getConversationManager().getInteractionHandlers()){
interactionHandler.sendOption(conversationLine.getMessage(), conversationLine.getSpeaker(), player, questPlayer, conversation, conversationLine, this);
interactionHandler.sendOption(conversationLine.getOneMessage(), conversationLine.getSpeaker(), player, questPlayer, conversation, conversationLine, this);
}
}

Expand Down