Rework of NPC conversation system#4211
Draft
Henrybk wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR reworks OpenKore's NPC conversation handling so that NPC dialog is treated as a first-class runtime state instead of a loosely shared pair of globals.
A new central module,
NPC::Conversation, is now the single source of truth for NPC conversation state and interaction flow. Packet receive code, command code,Task::TalkNPC, and eventMacro state checks now go through that module instead of directly reading or mutating%talkor$ai_v{'npc_talk'}.Problem
NPC conversations were previously coordinated through shared global state, mainly:
%talk$ai_v{'npc_talk'}That made the conversation flow fragile and hard to reason about:
What this PR changes
1. Add a central NPC conversation module
Introduces:
src/NPC/Conversation.pmThis module owns the normalized NPC conversation state, including:
It also provides send-side helpers such as:
startcontinueselect_responseselect_response_textselect_response_regexsend_numbersend_textchoose_buy_or_sellclosecancelresetdebug_string2. Migrate packet receive handling
Updated receive-side NPC packet handling to route through
NPC::Conversationinstead of mutating%talk/$ai_v{'npc_talk'}directly.Main areas updated:
src/Network/Receive.pm3. Migrate command/task interaction
Updated command and task logic to consume the centralized state instead of reading legacy globals directly.
Main areas updated:
src/Commands.pmsrc/Task/TalkNPC.pmsrc/Actor/NPC.pmsrc/Misc.pmsrc/AI/CoreLogic.pmsrc/Task/MapRoute.pmsrc/functions.plsrc/Network/Send.pmThis preserves existing behavior while moving orchestration into the conversation module.
4. Add direct NPC conversation commands
Adds direct state-based commands:
npcTalkContinuenpcTalkSelectnpcTalkSelectRegexnpcTalkNumbernpcTalkTextnpcTalkClosenpcTalkCancelnpcTalkResetnpcTalkDebugThese commands now use
NPC::Conversationand do not touch%talkdirectly.5. Add eventMacro state support
Adds state-style NPC conditions for eventMacro so macros can inspect the currently open NPC dialog instead of relying only on
NpcMsgevent hooks.New condition modules include:
npcTalkActivenpcTalkStatenpcTalkTextnpcTalkTextRegexnpcTalkHasResponsesnpcTalkResponseCountnpcTalkResponsenpcTalkResponseRegexnpcTalkExpectsContinuenpcTalkExpectsResponsenpcTalkExpectsNumbernpcTalkExpectsTextnpcTalkNpcNamenpcTalkNpcIdExisting
NpcMsg*behavior is preserved for compatibility.6. Add tests and guardrails
Adds:
src/test/NPCConversationTest.pmsrc/test/NPCConversationStaticTest.pmThe static test enforces the new rule that production code outside
NPC::Conversationmust not directly access:%talk$talk{...}$ai_v{'npc_talk'}7. Add docs and rAthena test script
Adds:
docs/NPCConversation.mddocs/rathena-npc-conversation-test.txtThe docs describe the new state model, API, hooks, commands, eventMacro usage, and migration guidance for plugin authors.
Compatibility notes
%talkand$ai_v{'npc_talk'}still exist as compatibility mirrors, but they are now synchronized only insideNPC::Conversation.npc_talk/npc_talk_donestyle hook flows remain available.talk/talknpcbehavior is preserved while using the new module internally.Testing
Verified:
NPCConversationStaticTestgit diff --checkpassesNot fully verified in this environment:
XSTools.dllloading/runtime issuesdocs/rathena-npc-conversation-test.txtbut not executed in this sessionFollow-up
Potential follow-up work after this lands:
%talk/$ai_v{'npc_talk'}mirrors entirely once downstream compatibility risk is goneNPC::Conversation