Skip to content

Conversation

@CrimsonMage
Copy link
Contributor

@CrimsonMage CrimsonMage commented Jul 11, 2025

Utilizes MoveToManager to reduce server impact while improving MoveHome when stuck.

Fails gracefully if ever it does fail.

Built on the commits to ACE from Vanguish:
ACEmulator/ACE#4306

Summary by CodeRabbit

  • New Features

    • Improved detection and handling of stuck monsters during movement, allowing for more responsive recovery and smarter AI behavior.
    • Monsters returning home can now respond to distress calls from nearby allies in combat.
    • Enhanced monster AI with adaptive thresholds for movement progress and fail-safe mechanisms to prevent prolonged stuck states.
  • Bug Fixes

    • Added additional safeguards to prevent errors when updating monster positions.
  • Refactor

    • Optimized internal logic for movement and target distance calculations.

Mobstuck code - Successfully teleports mobs home
Logic in place to prevent monsters from getting stuck, resets their AI properly.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

The changes introduce adaptive stuck detection logic for both player and monster movement. In the movement manager, stuck detection thresholds are now dynamic and movement is canceled after repeated failures. For monsters, a new stuck detection and recovery system is added, along with cooperative AI behaviors, null safety improvements, and placeholder logic for fast healing.

Changes

File(s) Change Summary
.../Physics/Managers/MoveToManager.cs Enhanced stuck detection with adaptive thresholds and explicit fail count; movement is canceled after repeated failures.
.../WorldObjects/Monster_Navigation.cs Added monster stuck detection/recovery, cooperative AI (distress calls), null checks, and fast healing placeholder.

Sequence Diagram(s)

sequenceDiagram
    participant Creature
    participant MoveToManager
    participant Target

    Creature->>MoveToManager: Initiate movement
    loop Movement update
        MoveToManager->>MoveToManager: CheckProgressMade()
        alt Progress insufficient
            MoveToManager->>MoveToManager: Increment FailProgressCount
            alt FailProgressCount >= 5
                MoveToManager->>Creature: CancelMoveTo(ActionCancelled)
                Creature->>Creature: HandleStuck()
                alt Can find new target
                    Creature->>Target: Switch to new target
                else
                    Creature->>Creature: ForceHome()
                end
            end
        end
    end
Loading

Poem

Hopping along, the monsters now know,
When stuck in a rut, it's time to let go.
With clever checks and friendly calls,
They help each other within the halls.
Adaptive, alert, and ready to roam,
Even when lost, they find their way home!
🐾

✨ 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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)
Source/ACE.Server/Physics/Managers/MoveToManager.cs (2)

462-466: Consider making the stuck threshold configurable.

The hard-coded value of 5 for the maximum fail count works well, but consider extracting it to a constant or configurable property for better maintainability and flexibility across different movement scenarios.

+private const int MaxFailProgressCount = 5;
+
 // Enhanced stuck detection with better thresholds
-if (FailProgressCount >= 5)
+if (FailProgressCount >= MaxFailProgressCount)
 {
     CancelMoveTo(WeenieError.ActionCancelled);
     return;
 }

683-696: Good implementation of adaptive stuck detection thresholds.

The dynamic progress rate thresholds based on movement type and distance are well-designed. This prevents false positives when monsters move longer distances where progress naturally appears slower.

Consider adding a comment explaining the rationale behind the specific threshold values (0.15f, 0.20f, 0.25f) for future maintainers.

Source/ACE.Server/WorldObjects/Monster_Navigation.cs (2)

290-301: Document the placeholder implementation.

The ApplyFastHealing method is currently a placeholder. Consider adding a TODO comment or tracking this in an issue for future implementation.

 public void ApplyFastHealing()
 {
     if (MonsterState == State.Return)
     {
+        // TODO: Implement fast healing for monsters returning home
         // Increase vital regen when returning home
         // This is handled by the existing vital regen system
         // The actual implementation would be in the vital regen logic
     }
 }

303-347: Excellent implementation of cooperative AI behavior.

The distress call system is well-designed with proper faction/type checking and uses the existing aural awareness range. The use of WakeUp(false) to prevent chain reactions is particularly clever.

Consider caching objMaint.GetVisibleTargetsValuesOfTypeCreature() if this method is called frequently to avoid repeated visibility calculations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77f81f1 and 845ebfb.

📒 Files selected for processing (2)
  • Source/ACE.Server/Physics/Managers/MoveToManager.cs (2 hunks)
  • Source/ACE.Server/WorldObjects/Monster_Navigation.cs (8 hunks)
🔇 Additional comments (8)
Source/ACE.Server/Physics/Managers/MoveToManager.cs (1)

704-704: Correct calculation of original progress rate.

Using PhysicsTimer.CurrentTime directly provides a more accurate measurement of overall movement progress since the start.

Source/ACE.Server/WorldObjects/Monster_Navigation.cs (7)

68-74: Well-structured stuck detection properties.

The stuck detection constants are reasonable and well-documented. The 2-second check interval and 3-attempt threshold provide a good balance between responsiveness and avoiding false positives.


111-112: Proper initialization of stuck detection timer.

The stuck check timer is correctly initialized when movement begins, ensuring accurate tracking from the start.


183-187: Excellent null safety improvements and performance optimization.

Caching the physics object references and adding null checks prevents potential crashes. Returning float.MaxValue for invalid physics objects is the correct approach.


222-231: Well-integrated movement failure detection and recovery methods.

The null-safe access to MoveToManager and the integration of stuck detection with the existing cancel mechanism work well together. The three new method calls are appropriately placed.


233-281: Robust stuck detection and recovery implementation.

The stuck detection system is well-designed with appropriate guard clauses, interval checks, and state-based recovery logic. The bypass for immobile monsters is a crucial detail that prevents false positives.


351-352: Comprehensive null safety improvements.

The added null checks throughout the navigation methods prevent potential crashes. The warning log in ForceHome is particularly helpful for debugging physics object issues.

Also applies to: 384-385, 627-631


612-613: Proper reset of stuck detection state.

Resetting StuckAttempts when movement is cancelled ensures clean state for the next movement operation.

@rkroska rkroska merged commit da0c196 into rkroska:master Jul 19, 2025
1 check passed
@CrimsonMage CrimsonMage deleted the MobStuck_AI_Fix branch July 22, 2025 19:29
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