Skip to content

Check if position is valid on trigger MoveUser - #390

Merged
AngeloTadeucci merged 2 commits into
masterfrom
trigger
Mar 28, 2025
Merged

Check if position is valid on trigger MoveUser#390
AngeloTadeucci merged 2 commits into
masterfrom
trigger

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Mar 28, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added a new option to bypass coordinate validation, enabling direct movement commands.
    • Introduced additional checks for valid portal positions during user transitions.
    • Enhanced player movement methods to streamline transitions to portals and specified positions.
  • Refactor

    • Streamlined navigation logic for determining movement paths, reducing redundancy and enhancing reliability.
    • Simplified the logic for portal transitions, improving error handling and robustness.

@coderabbitai

coderabbitai Bot commented Mar 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes extend command and navigation functionality in the game server. The CoordCommand now accepts a --force option to bypass coordinate validation. The navigation logic in AgentNavigation has been refactored to use a centralized FieldManager via a new property, removing redundant methods. Three new public methods in FieldManager provide position validation and nearest polygon lookup. Additionally, the player movement methods have been streamlined across various classes to directly invoke movement functions instead of sending packets.

Changes

File(s) Change Summary
Maple2.Server.Game/Commands/CoordCommand.cs Updated command to include a --force (-f) option; modified the Handle method signature and logic to optionally skip coordinate validation.
Maple2.Server.Game/Manager/Field/AgentNavigation.cs
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs
Refactored navigation logic: Removed direct calls to local FindNearestPoly in favor of field.FindNearestPoly via a new property; added public methods (ValidPosition and two FindNearestPoly overloads) in FieldManager for centralized position validation and navigation mesh queries.
Maple2.Server.Game/Manager/Field/FieldManager/IField.cs Removed the MoveToPortal method declaration from the IField interface.
Maple2.Server.Game/Trigger/TriggerContext.Player.cs Updated movement methods to directly call player.MoveToPortal and player.MoveToPosition, removing packet transmission for player movement.
Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs Simplified portal ID determination and player movement logic in the EnterExitStage method.
Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs Added MoveToPortal(FieldPortal portal) method; updated MoveToPosition method to include validation checks for positions.
Maple2.Server.Game/PacketHandlers/RideHandler.cs Modified HandleLeave method to use session.Player.MoveToPosition instead of sending a packet.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant C as CoordCommand
  U->>C: Invoke command with coordinates and force flag
  alt force flag is true
    C->>C: Bypass coordinate validation
    C->>U: Proceed with move operation
  else force flag is false
    C->>C: Perform normal coordinate validation
    alt Coordinates valid
      C->>U: Proceed with move operation
    else Coordinates invalid
      C->>U: Return error
    end
  end
Loading
sequenceDiagram
  participant U as User
  participant TC as TriggerContext
  participant F as Field
  U->>TC: Initiate MoveUser(portalId)
  TC->>F: TryGetPortal(portalId)
  alt Portal found
    TC->>F: ValidPosition(portal.Position)
    alt Portal position valid
      TC->>U: Move user through portal
    else Portal position invalid
      TC->>U: Abort move operation
    end
  else Portal not found
    TC->>U: Abort move operation (portal not found)
  end
Loading

Suggested reviewers

  • Zintixx

Poem

I'm a coding bunny with joyful feet,
Hopping through changes both nimble and neat,
Carrots of logic in every line,
Skipping validations when force aligns,
In fields of code where adventures unite,
I celebrate these changes with a bunny delight!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bafa742 and da5d407.

📒 Files selected for processing (8)
  • Maple2.Server.Game/Commands/CoordCommand.cs (2 hunks)
  • Maple2.Server.Game/Manager/Field/AgentNavigation.cs (8 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (3 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/IField.cs (0 hunks)
  • Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs (2 hunks)
  • Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (1 hunks)
  • Maple2.Server.Game/PacketHandlers/RideHandler.cs (1 hunks)
  • Maple2.Server.Game/Trigger/TriggerContext.Player.cs (5 hunks)
💤 Files with no reviewable changes (1)
  • Maple2.Server.Game/Manager/Field/FieldManager/IField.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • Maple2.Server.Game/Trigger/TriggerContext.Player.cs
  • Maple2.Server.Game/Manager/Field/AgentNavigation.cs
🧰 Additional context used
🧬 Code Definitions (2)
Maple2.Server.Game/PacketHandlers/RideHandler.cs (3)
Maple2.Database/Storage/Game/GameStorage.User.cs (1)
  • Player (196-264)
Maple2.Model/Game/User/Player.cs (2)
  • Player (8-22)
  • Player (17-21)
Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (1)
  • MoveToPosition (386-392)
Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (5)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)
  • ValidPosition (297-299)
Maple2.Server.Core/Network/Session.cs (5)
  • Session (23-283)
  • Session (53-76)
  • Session (78-78)
  • Send (129-129)
  • Send (131-131)
Maple2.Server.Game/Packets/PortalPacket.cs (1)
  • PortalPacket (11-96)
Maple2.Server.Game/Trigger/TriggerContext.Player.cs (1)
  • MoveToPortal (68-79)
Maple2.Server.Game/Model/Field/Entity/FieldPortal.cs (2)
  • FieldPortal (6-28)
  • FieldPortal (17-21)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (13)
Maple2.Server.Game/Commands/CoordCommand.cs (3)

28-28: Good addition of the force option for bypassing position validation.

The addition of the --force (or -f) option is well-implemented, providing a clear way to bypass position validation when needed. This gives users more flexibility when working with coordinates.


33-34: LGTM: Command handling properly updated for the new force option.

The option is correctly added to the command and the handler method signature is properly updated to include the new force parameter.


42-47: Good implementation of position validation logic.

The validation check using session.Field.ValidPosition(position) is well-implemented. The code correctly blocks invalid positions unless the force flag is set, providing useful feedback to the user.

Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (2)

387-389: Good addition of position validation before moving the player.

Adding the validation check ensures that players cannot be moved to invalid positions, preventing potential issues with player teleportation. This improves the robustness of the movement system.


394-400: Well-structured new method for moving players to portals.

The new MoveToPortal method follows the same pattern as MoveToPosition, validating the position before movement. This ensures consistent validation across different movement methods and follows the DRY principle.

Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (4)

294-294: Good refactoring to use direct method call instead of sending a packet.

Replacing the packet transmission with a direct call to the MoveToPosition method streamlines the player movement process and ensures that the position validation is applied.


297-299: Well-implemented position validation method.

The ValidPosition method provides a clean interface for checking if a position is valid, using the FindNearestPoly method to determine if there's a valid polygon at the position. This creates a robust foundation for position validation across the codebase.


301-304: Excellent overload for Vector3 to RcVec3f conversion.

This overload provides a convenient way to validate positions represented as Vector3, converting them to navigation mesh space before checking for the nearest polygon. This simplifies usage across the codebase.


306-314: Comprehensive implementation of polygon finding logic.

The method correctly interacts with the navigation system to find the nearest polygon, includes error logging, and returns a boolean result indicating success or failure. This provides all the necessary functionality for position validation.

Maple2.Server.Game/PacketHandlers/RideHandler.cs (1)

171-171: Good refactoring to use direct method call instead of packet transmission.

Using session.Player.MoveToPosition directly aligns with the changes in other parts of the codebase, ensuring that position validation is consistently applied when a player leaves a ride. This also streamlines the code by removing the need for packet transmission.

Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs (3)

2-2: Added necessary import for Player model classes.

Adding the Maple2.Server.Game.Model namespace is appropriate as it's needed for the refactored player movement logic.


27-30: Improved code clarity and error handling.

The refactored code is clearer and more robust:

  1. Directly assigning the portal ID based on position check simplifies the logic
  2. Adding portal existence validation with TryGetPortal prevents attempts to move to non-existent portals

This is a good defensive programming practice that will prevent potential runtime errors.


32-32: Streamlined player movement with dedicated method.

Using session.Player.MoveToPortal(portal) encapsulates the movement logic within the Player class, which is a better design than having the field manager handle movement directly. This change aligns with the PR objective of improving position validation on user movement.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Comment thread Maple2.Server.Game/Trigger/TriggerContext.Player.cs Outdated
@AngeloTadeucci
AngeloTadeucci merged commit 376c244 into master Mar 28, 2025
@AngeloTadeucci
AngeloTadeucci deleted the trigger branch March 28, 2025 06:38
This was referenced Apr 1, 2025
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