Commit 646c2131 by Jonathan Thomas

When entity conversations switch players, a message is added for clarity (so the…

When entity conversations switch players, a message is added for clarity (so the entity knows a new player entered the conversation). Entity's now keep their entire message history in a single stack, but have more context when player's change in the conversation.
parent f1d3b14e
Pipeline #13201 passed with stages
in 2 minutes 45 seconds
......@@ -15,7 +15,8 @@ All notable changes to **CreatureChat** are documented in this file. The format
- New sounds and particles when max friendship with EnderDragon (plus XP drop)
### Changed
- Entity chat data now separates messages and friendship by player and includes timestamps
- Entity chat data now separates friendship by player and includes timestamps
- When entity conversations switch players, a message is added for clarity (so the entity knows a new player entered the conversation)
- Data is no longer deleted on entity death, and instead a "death" timestamp is recorded
- Removed "pirate" speaking style and a few <non-response> outputs
- Passive entities no longer emit damage particles when attacking, they emit custom attack particles
......
......@@ -141,14 +141,6 @@ public class EntityChatData {
}
}
// Get a filtered list of ChatMessages by a particular name (plus any messages with null or empty names)
// For example, if chat data is migrated before 'name' was stored, we want those message to be visible by everyone.
public ArrayList<ChatMessage> getMessagesByName(String playerName) {
return this.previousMessages.stream()
.filter(message -> message.name == null || message.name.isEmpty() || message.name.equals(playerName))
.collect(Collectors.toCollection(ArrayList::new));
}
// Generate light version of chat data (no previous messages)
public EntityChatDataLight toLightVersion(String playerName) {
return new EntityChatDataLight(this, playerName);
......@@ -269,19 +261,16 @@ public class EntityChatData {
ConfigurationHandler.Config config = new ConfigurationHandler(ServerPackets.serverInstance).loadConfig();
String promptText = ChatPrompt.loadPromptFromResource(ServerPackets.serverInstance.getResourceManager(), systemPrompt);
// Get all message (filtered by player)
List<ChatMessage> playerMessages = getMessagesByName(player.getDisplayName().getString());
// Get messages for player
PlayerData playerData = this.getPlayerData(player.getDisplayName().getString());
if (playerMessages.size() == 1 && systemPrompt.equals("system-chat")) {
if (previousMessages.size() == 1 && systemPrompt.equals("system-chat")) {
// No messages exist yet for this player (start with normal greeting)
String shortGreeting = Optional.ofNullable(getCharacterProp("short greeting")).filter(s -> !s.isEmpty()).orElse(Randomizer.getRandomMessage(Randomizer.RandomType.NO_RESPONSE)).replace("\n", " ");
previousMessages.add(0, new ChatMessage(shortGreeting, ChatDataManager.ChatSender.ASSISTANT, player.getDisplayName().getString()));
}
// fetch HTTP response from ChatGPT
ChatGPTRequest.fetchMessageFromChatGPT(config, promptText, contextData, playerMessages, false).thenAccept(output_message -> {
ChatGPTRequest.fetchMessageFromChatGPT(config, promptText, contextData, previousMessages, false).thenAccept(output_message -> {
if (output_message != null && systemPrompt.equals("system-character")) {
// Character Sheet: Remove system-character message from previous messages
previousMessages.clear();
......@@ -520,24 +509,36 @@ public class EntityChatData {
}
// Add a message to the history and update the current message
public void addMessage(String message, ChatDataManager.ChatSender messageSender, String playerName) {
public void addMessage(String message, ChatDataManager.ChatSender sender, String playerName) {
// Truncate message (prevent crazy long messages... just in case)
String truncatedMessage = message.substring(0, Math.min(message.length(), ChatDataManager.MAX_CHAR_IN_USER_MESSAGE));
// Add context-switching logic for USER messages only
if (sender == ChatDataManager.ChatSender.USER && previousMessages.size() > 1) {
ChatMessage lastMessage = previousMessages.get(previousMessages.size() - 1);
if (!lastMessage.name.equals(playerName)) {
boolean isReturningPlayer = previousMessages.stream().anyMatch(msg -> msg.name.equals(playerName));
String note = isReturningPlayer
? "<returning player: " + playerName + " resumes the conversation>"
: "<a new player has joined the conversation: " + playerName + ">";
previousMessages.add(new ChatMessage(note, sender, playerName));
}
}
// Add message to history
previousMessages.add(new ChatMessage(truncatedMessage, messageSender, playerName));
previousMessages.add(new ChatMessage(truncatedMessage, sender, playerName));
// Set new message and reset line number of displayed text
currentMessage = truncatedMessage;
currentLineNumber = 0;
if (messageSender == ChatDataManager.ChatSender.ASSISTANT) {
// Update current message and reset line number of displayed text
this.currentMessage = truncatedMessage;
this.currentLineNumber = 0;
if (sender == ChatDataManager.ChatSender.ASSISTANT) {
// Show new generated message
status = ChatDataManager.ChatStatus.DISPLAY;
} else if (messageSender == ChatDataManager.ChatSender.USER) {
} else if (sender == ChatDataManager.ChatSender.USER) {
// Show pending icon
status = ChatDataManager.ChatStatus.PENDING;
}
sender = messageSender;
this.sender = sender;
// Broadcast to all players
ServerPackets.BroadcastPacketMessage(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment