Skip to content

Comments

Refactor Rs2Prayer#1463

Merged
chsami merged 1 commit intochsami:developmentfrom
gmason0:feat/rs2prayer-refactor
Sep 3, 2025
Merged

Refactor Rs2Prayer#1463
chsami merged 1 commit intochsami:developmentfrom
gmason0:feat/rs2prayer-refactor

Conversation

@gmason0
Copy link
Contributor

@gmason0 gmason0 commented Sep 3, 2025

This pull request aims to refactor the Rs2Prayer class, with optional support for using the natural mouse by passing realistic rectangles into Microbot#doInvoke.

We still default to not using this feature via overloaded parameters to ensure we prevent breaking previous implementations.

I want to say shoutout to Being for assisting with this idea, I just took it the extra mile to get this more polished around the edges.

Features

  • Provide optional usage of natural mouse when using prayers from prayer tab OR quick prayers

Chores

  • Migrate to api.gameval constants

@gmason0 gmason0 requested a review from chsami September 3, 2025 04:03
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Walkthrough

Rs2Prayer was refactored to a state-driven, UI-aware system. New methods toggle individual prayers (optionally via mouse), handle tab switching, and click within prayer widget bounds. Legacy varbit checks were replaced with VarbitID-based unlock predicates (e.g., Augury, Rigour). Quick prayer handling was expanded: detection, state checks, toggling (with/without mouse), and helpers for bulk enable/disable. Added helpers for quick-prayer orb interaction and bounds retrieval. Logging via @slf4j warns on missing widgets/bounds. Public API grew with toggle variants, bulk management methods, and unlock checks. Internal helpers structure UI interactions and verification via sleepUntil.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/prayer/Rs2Prayer.java (4)

67-75: Ensure tab switch completes before using natural mouse bounds

After switching to the PRAYER tab you immediately fetch/click bounds. Add a short wait so the widgets are present; otherwise withMouse often degrades to the default rectangle and defeats the “natural mouse” goal.

-        if (withMouse && Rs2Tab.getCurrentTab() != InterfaceTab.PRAYER)
-        {
-            Rs2Tab.switchTo(InterfaceTab.PRAYER);
-        }
+        if (withMouse && Rs2Tab.getCurrentTab() != InterfaceTab.PRAYER)
+        {
+            Rs2Tab.switchTo(InterfaceTab.PRAYER);
+            // Wait briefly for prayer widgets to materialize before computing bounds
+            sleepUntil(() -> Rs2Tab.getCurrentTab() == InterfaceTab.PRAYER
+                && Rs2Widget.getWidget(prayer.getIndex()) != null
+                && Rs2Widget.getWidget(prayer.getIndex()).getBounds() != null, 1_500);
+        }

302-306: Avoid rebuilding a list in the stream; precompute a Set

You recreate Arrays.asList(...) per element and do O(n) contains. Precompute an EnumSet for O(1) membership and fewer allocations.

-        Arrays.stream(Rs2PrayerEnum.values())
-            .filter(Rs2Prayer::isPrayerActive)
-            .filter(prayer -> !Arrays.asList(prayersToKeep).contains(prayer))
-            .forEach(prayer -> Rs2Prayer.toggle(prayer, false, withMouse));
+        final java.util.Set<Rs2PrayerEnum> keep = java.util.EnumSet.noneOf(Rs2PrayerEnum.class);
+        keep.addAll(Arrays.asList(prayersToKeep));
+        Arrays.stream(Rs2PrayerEnum.values())
+            .filter(Rs2Prayer::isPrayerActive)
+            .filter(prayer -> !keep.contains(prayer))
+            .forEach(prayer -> Rs2Prayer.toggle(prayer, false, withMouse));

109-116: Demote noisy widget-bound warnings to debug

Missing/invalid bounds during tab transitions are normal and will spam logs. Prefer debug to keep warnings meaningful.

-            log.warn("Prayer widget not found: {}", prayer.getName());
+            log.debug("Prayer widget not found: {}", prayer.getName());
...
-            log.warn("Invalid prayer bounds for: {}", prayer.getName());
+            log.debug("Invalid prayer bounds for: {}", prayer.getName());
...
-            log.warn("Quick prayer orb widget not found");
+            log.debug("Quick prayer orb widget not found");
...
-            log.warn("Invalid quick prayer orb bounds");
+            log.debug("Invalid quick prayer orb bounds");

Also applies to: 248-255


32-41: Fix Javadoc to reflect behavior

This overload always toggles (inverts state) unless out of prayer; it doesn’t check a “desired state.”

-    /**
-     * Toggles a prayer on or off. If the prayer is already in the desired state, no action is taken.
-     *
-     * @param prayer the prayer to toggle
-     */
+    /**
+     * Toggles a prayer (inverts its current state).
+     * No-op only when out of prayer points.
+     *
+     * @param prayer the prayer to toggle
+     */
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2877ef4 and 95cfb06.

📒 Files selected for processing (1)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/prayer/Rs2Prayer.java (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/prayer/Rs2Prayer.java (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/menu/NewMenuEntry.java (1)
  • NewMenuEntry (11-317)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/prayer/Rs2Prayer.java (1)

85-93: Verify CC_OP identifier/opcode for all prayer/quick-prayer actions

Both invokePrayer and invokeQuickPrayer assume identifier 1 with MenuAction.CC_OP. If any prayer widget exposes “Activate/Deactivate” on a different op index (or the orb’s option index varies), these calls will no-op.

Please sanity-check in-game (or via widget inspector) that:

  • Prayer buttons: CC_OP with identifier 1 toggles in both active and inactive states.
  • Quick-prayer orb: CC_OP with identifier 1 toggles; “Setup” uses identifier 2 as used in setQuickPrayers.

If discrepancies exist, compute the correct identifier from widget actions at runtime, or switch to NewMenuEntry helpers that resolve identifiers. I can draft that if needed.

Also applies to: 226-234, 166-176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants