Class DialogueService


  • public class DialogueService
    extends java.lang.Object
    A service class intended for managing and interacting with various types of dialogues in the game client.

    The DialogueService class provides utility methods for detecting dialogues, selecting options, resuming dialogues, handling text inputs, and extracting dialogue properties such as options, headers, and message content.

    Using this service, developers can interface with different dialogue widgets within the game client, enabling automated interaction, data extraction, and execution of player actions. The methods in this class operate on the client thread and ensure safe synchronization with the game's UI components.

    Features of this class include:

    • Detection of active dialogues.
    • Selection of dialogue options based on index or text.
    • Handling of object-based and numeric-based dialogues.
    • Support for "Make X" quantity-based operations.
    • Retrieval of dialogue options, text content, and headers.
    • Synchronization with game's client thread for secure widget interaction.

    Fields:

    • ctx: Context or environment within which the service operates.
    • widgetPackets: Utility responsible for interfacing with widget packets for actions.
    • log: Logging utility for debugging and information output.

    Methods:

    • Detection and validation of dialogues through isDialoguePresent().
    • Option selection by index or text with selectOption(int option) and selectOption(String option).
    • Progression of specific dialogues with continueObjectDialogue(int id) and continueNumericDialogue(int value).
    • Management of "Make X" operations via makeX(int quantity).
    • Extraction of dialogue options through getDialogueOptions().
    • Fetching header and text content with getDialogueHeader() and retrieving widget text methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      DialogueService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean continueDialogue()
      Attempts to continue an active dialogue in the game by interacting with various dialogue widgets.
      void continueNumericDialogue​(int value)
      Resumes a numeric dialogue in the game by interacting with the appropriate widgets and invoking client-side scripts to continue the process.
      void continueObjectDialogue​(int id)
      Resumes an object-based dialogue in the game by interacting with relevant widgets and invoking a client-side script to continue the process.
      java.lang.String getDialogueHeader()
      Retrieves the dialogue header text currently displayed in the widget interface.
      java.util.List<java.lang.String> getDialogueOptions()
      Retrieves a list of dialogue options currently available in the dialogue interface.
      java.lang.String getDialogueText()
      Retrieves the text from the currently active dialogue widget if available.
      boolean isDialoguePresent()
      Checks if any type of dialogue is currently present in the game client.
      boolean isOptionPresent​(java.lang.String option)
      Checks if a specific dialogue option is present in the list of available options.
      void makeX​(int quantity)
      Executes the "Make X" operation for a specified quantity.
      void selectOption​(int option)
      Selects a specific option in a dialog option group.
      boolean selectOption​(java.lang.String option)
      Attempts to select an option from a dialog interface based on the provided option text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DialogueService

        public DialogueService()
    • Method Detail

      • isDialoguePresent

        public boolean isDialoguePresent()
        Checks if any type of dialogue is currently present in the game client.

        This method scans various widget IDs associated with different dialogue types such as NPC dialogue, player dialogue, level-up messages, notifications, and more, to determine if a relevant dialogue is displayed.

        • Includes checks for NPC and player dialogues.
        • Handles level-up and notification dialogues.
        • Supports minigame-related and chatbox dialogues.
        • Accounts for "Click here to continue" prompts.
        • Detects option dialogues for user decisions.
        Returns:
        true if any dialogue or clickable interaction is active, false otherwise.
      • selectOption

        public void selectOption​(int option)
        Selects a specific option in a dialog option group.

        This method is executed on the client thread to select the desired option in the user interface dialog by sending the appropriate packet to the server.

        Parameters:
        option - the index of the option to select, typically starting from 0 for the first option.
      • selectOption

        public boolean selectOption​(java.lang.String option)
        Attempts to select an option from a dialog interface based on the provided option text. This method works on a client thread to interact with widget components and identify the dialog options available.

        This method checks if the dialog interface exists and contains child widgets, iterates over them to match the provided option text (case-insensitive), and selects the desired option if found.

        Parameters:
        option - the text of the option to be selected from the dialog. This is case-insensitive and matched against the text of the dialog options.
        Returns:
        true if the option was successfully found and selected; false if the dialog interface does not exist, the dialog options are unavailable or empty, or if the desired option cannot be found.
      • continueObjectDialogue

        public void continueObjectDialogue​(int id)
        Resumes an object-based dialogue in the game by interacting with relevant widgets and invoking a client-side script to continue the process.

        This method is specifically designed to handle dialogues involving object IDs and ensures that the appropriate actions are executed to progress through the dialogue. It queues a RESUME_OBJDIALOG packet with the given object ID and checks for specific chatbox input widgets to determine whether a client script needs to be executed. If either of the relevant widgets is detected, a predefined client script is invoked.

        The execution occurs on the client thread to ensure proper synchronization with the game's UI and safe interaction with client methods and widgets.

        • Queues the RESUME_OBJDIALOG packet using ctx.widgetPackets.queueResumeObj.
        • Checks WidgetInfo.CHATBOX_INPUT and WidgetInfo.CHATBOX_FULL_INPUT for presence.
        • Executes a client script (138) if either widget is detected.
        Parameters:
        id - The ID of the object used in the dialogue. This ID represents the object or item referenced by the dialogue option and ensures its selection and continuation.
      • continueNumericDialogue

        public void continueNumericDialogue​(int value)
        Resumes a numeric dialogue in the game by interacting with the appropriate widgets and invoking client-side scripts to continue the process.

        This method is designed to handle numeric input dialogues and ensure the correct actions are executed in response. It queues a RESUME_COUNTDIALOG packet with the provided value and checks for specific chatbox input widgets to determine if a client script needs to be executed. If the relevant widgets are found, it invokes a client script to resume the numeric dialogue.

        The execution occurs on the client thread to maintain proper synchronization with the game's UI and ensure safe interaction with client methods and widgets.

        • Queues the RESUME_COUNTDIALOG packet using ctx.widgetPackets.queueResumeCount.
        • Checks WidgetInfo.CHATBOX_INPUT and WidgetInfo.CHATBOX_FULL_INPUT for presence.
        • Executes a client script (138) if either widget is detected.
        Parameters:
        value - The numeric input to resume the dialogue with. This value is typically entered by the player in a dialogue box and represents the amount or quantity the player has specified.
      • makeX

        public void makeX​(int quantity)
        Executes the "Make X" operation for a specified quantity.

        This method interacts with the game's client thread to queue a resume/pause packet for completing a quantity-based action, such as creating multiple items in a crafting or production interface.

        The operation is carried out by sending a specific widget interaction request using widgetPackets.queueResumePause. The widget ID used is hardcoded in the method and corresponds to a predefined interface element within the game.

        Parameters:
        quantity - The number of items or actions to perform. Must be a positive integer representing the desired quantity for the "Make X" operation.
      • getDialogueOptions

        public java.util.List<java.lang.String> getDialogueOptions()
        Retrieves a list of dialogue options currently available in the dialogue interface.

        This method interacts with the client thread to extract options from the appropriate dialogue widget. It filters and returns only the non-blank options.

        The options are extracted from a pre-defined widget group and are returned as a list of strings. If no options are available or if there is an issue accessing the widget, an empty list is returned.

        Returns:
        A List of String containing the text of available dialogue options. If no options are available, the list will be empty.
      • getDialogueHeader

        public java.lang.String getDialogueHeader()
        Retrieves the dialogue header text currently displayed in the widget interface. This method determines the source of the dialogue and provides an appropriate header.

        The header may represent:

        • The NPC's name if an NPC dialogue is active.
        • "Player" if a player dialogue is active.
        • "Select an Option" if a dialogue option selection is active.
        • "unknown" if no known dialogue state is detected.
        Returns:
        The dialogue header text as a @String, which identifies the current dialogue source.
      • getDialogueText

        public java.lang.String getDialogueText()
        Retrieves the text from the currently active dialogue widget if available. This method checks multiple possible widgets for dialogue text, including NPC text, player text, sprite-based text, and other specific dialogue-related interfaces.

        The method will return the first non-null and non-empty text identified from the following widgets:

        • WidgetInfo.DIALOG_NPC_TEXT
        • WidgetInfo.DIALOG_PLAYER_TEXT
        • WidgetInfo.DIALOG_SPRITE_TEXT
        • ctx.widgets().get(11, 2)
        • ctx.widgets().get(229, MinigameDialog.TEXT)
        • ctx.widgets().get(229, DialogNotification.TEXT)
        • ctx.widgets().get(InterfaceID.Messagebox.TEXT)

        If no dialogue text is found across any of these widgets, an empty string will be returned.

        Returns:
        A String containing the dialogue text from the active widget, or an empty string if no text is available.
      • continueDialogue

        public boolean continueDialogue()
        Attempts to continue an active dialogue in the game by interacting with various dialogue widgets.

        This method works by checking for the presence of specific dialogue widgets representing NPC dialogues, player dialogues, notifications, level-up screens, chatbox dialogues, and other message boxes. If any such widget is found and recognized, the method sends a resume or pause command to the appropriate widget to continue the dialogue. The logic prioritizes widgets in a specific order to handle varying dialogue types.

        The method is executed on the client thread to ensure proper interaction with the game's UI. It returns true if a valid dialogue widget was found and the "continue" action was successfully triggered.

        • If an NPC dialogue widget is detected in the WidgetID.DIALOG_NPC_GROUP_ID group, it triggers the "continue" action.
        • Handles player dialogues, sprite dialogues, level-up dialogues, and other known specific IDs.
        • Checks text values, such as "Click here to continue," in certain widgets to verify the necessity of sending a command.
        Returns:
        true if a valid dialogue widget was interacted with to continue the dialogue, false if no applicable dialogue widget was found or interacted with.
      • isOptionPresent

        public boolean isOptionPresent​(java.lang.String option)
        Checks if a specific dialogue option is present in the list of available options.

        The search is case-insensitive and supports partial matches. If the provided option text matches any part of any dialogue option, the method will return true.

        Parameters:
        option - The text of the dialogue option to search for. This parameter is case-insensitive and partial matches are supported.
        Returns:
        true if the option is found in the list of available dialogue options, false otherwise.