Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve chat screen handling for game messages #2139

Merged
merged 2 commits into from
Sep 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ classes/
.gradle/
.architectury-transformer/

# Data generated while running Minecraft
# Data generated while running Minecraft or tests
run/
.devauth/microsoft_accounts.json
*/logs/*

# IDEs
.idea/
Expand Down
22 changes: 19 additions & 3 deletions common/src/main/java/com/wynntils/handlers/chat/ChatHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.wynntils.core.components.Handler;
import com.wynntils.core.components.Managers;
import com.wynntils.core.consumers.features.Feature;
import com.wynntils.core.mod.event.WynncraftConnectionEvent;
import com.wynntils.core.text.StyledText;
import com.wynntils.handlers.chat.event.ChatMessageReceivedEvent;
import com.wynntils.handlers.chat.event.NpcDialogEvent;
Expand Down Expand Up @@ -104,6 +105,18 @@ public void removeNpcDialogExtractionDependent(Feature feature) {
dialogExtractionDependents.remove(feature);
}

@SubscribeEvent
public void onConnectionChange(WynncraftConnectionEvent event) {
// Reset chat handler
collectedLines = new ArrayList<>();
chatScreenTicks = 0;
lastRealChat = null;
lastSlowdownApplied = 0;
lastScreenNpcDialog = List.of();
delayedDialogue = null;
delayedType = NpcDialogueType.NONE;
}

@SubscribeEvent
public void onTick(TickEvent event) {
if (collectedLines.isEmpty()) return;
Expand Down Expand Up @@ -349,9 +362,12 @@ private void handleScreenNpcDialog(List<Component> dialog, boolean isSelection)
private void handleFakeChatLine(Component message) {
// This is a normal, single line chat, sent in the background
StyledText styledText = StyledText.fromComponent(message);
if (styledText.isEmpty()) return;

// But it can weirdly enough actually also be a foreground NPC chat message...
if (getRecipientType(styledText, MessageType.FOREGROUND) == RecipientType.NPC) {
// But it can weirdly enough actually also be a foreground NPC chat message, or
// a game message; similar to a dialogue but not uttered by an NPC.
RecipientType recipientType = getRecipientType(styledText, MessageType.FOREGROUND);
if (recipientType == RecipientType.NPC || recipientType == RecipientType.GAME_MESSAGE) {
// In this case, do *not* save this as last chat, since it will soon disappear
// from history!
postNpcDialogue(List.of(message), NpcDialogueType.CONFIRMATIONLESS, false);
Expand Down Expand Up @@ -383,7 +399,7 @@ private Component postChatLine(Component message, StyledText styledText, Message
WynntilsMod.info("[CHAT] " + styledText.getString().replace("§", "&"));
RecipientType recipientType = getRecipientType(styledText, messageType);

if (recipientType == RecipientType.NPC) {
if (recipientType == RecipientType.NPC || recipientType == RecipientType.GAME_MESSAGE) {
if (shouldSeparateNPC()) {
postNpcDialogue(List.of(message), NpcDialogueType.CONFIRMATIONLESS, false);
// We need to cancel the original chat event, if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public enum RecipientType {
PARTY("^§7\\[§e[^➤]*§7\\] §f.*$", "^(§8)?\\[§7[^➤]*§8\\] §7[^§]*$", "Party"),
PRIVATE("^§7\\[.* ➤ .*\\] §f.*$", "^(§8)?\\[.* ➤ .*\\] §7.*$", "Private"),
SHOUT("^§5.* \\[[A-Z0-9]+\\] shouts: §d.*$", "^(§8)?.* \\[[A-Z0-9]+\\] shouts: §7.*$", "Shout"),
PETS("^§2(.*): §a(.*)$", "^§8(.*): §7(.*)$", "Pets");
PETS("^§2(.*): §a(.*)$", "^§8(.*): §7(.*)$", "Pets"),
GAME_MESSAGE("^§7[A-Z0-9].*$", null, "Game Message"); // Like dialogues but not uttered by an NPC

private final Pattern foregroundPattern;
private final Pattern backgroundPattern;
Expand Down