Skip to content

feat(field): adjust player position when moving through touch portals - #531

Merged
AngeloTadeucci merged 1 commit into
masterfrom
portal
Jul 9, 2025
Merged

feat(field): adjust player position when moving through touch portals#531
AngeloTadeucci merged 1 commit into
masterfrom
portal

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Jul 9, 2025

Copy link
Copy Markdown
Collaborator

Modify portal teleportation logic to offset player position when the
portal's action type is Touch. This prevents players from spawning
exactly on the portal. The offset uses either a default block size
or a custom front offset if specified.

Summary by CodeRabbit

  • Bug Fixes
    • Improved portal movement accuracy within the same map, ensuring correct player positioning and orientation when using portals, especially for touch-activated portals.

Modify portal teleportation logic to offset player position when the
portal's action type is Touch. This prevents players from spawning
exactly on the portal. The offset uses either a default block size
or a custom front offset if specified.
@coderabbitai

coderabbitai Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The UsePortal method in the FieldManager class has been updated to adjust how portal movement is handled when the player moves within the same map. The code now explicitly calculates the destination position and rotation, applying an offset if the portal's action type is Touch, before sending the movement packet.

Changes

File(s) Change Summary
Maple2.Server.Game/Manager/Field/FieldManager.cs Refactored UsePortal to extract destination portal position/rotation and apply offset logic.

Sequence Diagram(s)

sequenceDiagram
    participant Player
    participant FieldManager
    participant Portal

    Player->>FieldManager: UsePortal(sourcePortal)
    FieldManager->>Portal: Get destination portal
    FieldManager->>FieldManager: Extract position and rotation
    alt Portal action type is Touch
        FieldManager->>FieldManager: Apply forward offset to position
    end
    FieldManager->>Player: Send portal move packet with adjusted position and rotation
Loading

Possibly related PRs

  • AngeloTadeucci/Maple2#397: Both PRs modify the UsePortal method in FieldManager.cs to change how player movement through portals is handled, shifting from direct position updates to sending movement packets with adjusted position data.

Suggested reviewers

  • Zintixx

Poem

Through portals we hop with a hop and a spin,
Now with offsets and vectors, our journeys begin.
Touch portals nudge us just a little ahead,
With code that’s precise, as the changelog has said.
🐇✨

✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)

554-568: Good improvement to portal positioning logic.

The implementation correctly applies an offset to prevent players from being placed exactly on Touch portals. The logic properly extracts position and rotation, applies the offset in the forward direction, and handles both default and custom offset values.

However, consider adding null safety checks and position validation:

 Vector3 position = dstPortal.Position;
 Vector3 rotation = dstPortal.Rotation;

-if (dstPortal.Value.ActionType is PortalActionType.Touch) {
+if (dstPortal.Value?.ActionType is PortalActionType.Touch) {
     // add one blocks or use offset in the direction of front axis
     float offset = Constant.BlockSize;
-    if (dstPortal.Value.FrontOffset != 0) {
+    if (dstPortal.Value.FrontOffset != 0) {
         offset = dstPortal.Value.FrontOffset;
     }

     Vector3 forward = dstPortal.Transform.FrontAxis;

     position += forward * offset;
+    
+    // Validate the final position is within valid navigation mesh
+    if (!ValidPosition(position)) {
+        logger.Warning("Portal offset resulted in invalid position {Position} for portal {PortalId}", position, dstPortal.Value.Id);
+        position = dstPortal.Position; // Fallback to original position
+    }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6874acd and fa61e79.

📒 Files selected for processing (1)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (2 hunks)
⏰ 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). (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (1)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)

30-30: LGTM: Required import for vector math operations.

The new using statement is necessary for the vector math operations introduced in the UsePortal method changes.

@AngeloTadeucci
AngeloTadeucci merged commit fa28c99 into master Jul 9, 2025
4 checks passed
@AngeloTadeucci
AngeloTadeucci deleted the portal branch July 9, 2025 09:59
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.

1 participant