Skip to content

Feat: Patrols with AirWaypoint - #434

Merged
AngeloTadeucci merged 4 commits into
masterfrom
air-waypoint
May 30, 2025
Merged

Feat: Patrols with AirWaypoint#434
AngeloTadeucci merged 4 commits into
masterfrom
air-waypoint

Conversation

@AngeloTadeucci

@AngeloTadeucciAngeloTadeucci commented Apr 28, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Introduced flying movement for NPCs, enabling navigation through air waypoints with dedicated flying animations and logic.
    • Added support for air waypoints, allowing NPCs to distinguish between ground and air patrol paths.
    • Added new flying movement tasks and methods to manage flying behavior and navigation.
  • Bug Fixes

    • Improved waypoint navigation error handling with better warnings and fallback behavior when paths or animations are unavailable.
  • Enhancements

    • NPCs now utilize specific flying sequences when approaching or arriving at air waypoints.
    • Increased update tick delta limit to improve movement responsiveness.

@coderabbitai

coderabbitaiBot commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce support for air waypoints and flying movement in the game server's NPC navigation system. The waypoint data structure (MS2WayPoint) is extended with a boolean flag indicating air waypoints. The mapping logic is updated to propagate this flag from patrol data. On the server side, new methods and classes are added to enable NPCs to fly to waypoints, including logic for flying movement, animation handling, and task management. The NPC behavior is updated to select flying or walking movement based on the waypoint type, and appropriate animation sequences are used for flying.

Changes

File(s)Change Summary
Maple2.Model/Metadata/MapEntity/PatrolData.csAdded a new boolean property AirWayPoint to the MS2WayPoint record, updating its constructor signature.
Maple2.File.Ingest/Mapper/MapEntityMapper.csModified the construction of MS2WayPoint to include the IsAirWayPoint flag from patrol data when parsing map entities.
Maple2.Server.Game/Manager/Field/AgentNavigation.csAdded a new public method FlyAdvance for linear, unconstrained movement between two positions, returning the new position and a completion flag.
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.csAdded a public method TryFlyTo to initiate flying movement tasks for NPCs, similar to existing walking movement initiation.
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateStates/MovementState.Walk.csAdded private boolean field isFlying to track flying state. Updated StateWalkUpdate to process flying movement using FlyAdvance, updating position, velocity, and rotation accordingly, and completing the flying task when the target is reached.
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.WalkTask.csAdded a nested class NpcFlyToTask for flying movement with properties and lifecycle methods. Added a private FlyTo method to handle flying movement logic and animation initiation.
Maple2.Server.Game/Model/Field/Actor/FieldNpc.csAdded a readonly field FlySequence for flying animation. Updated NextWaypoint method to handle air waypoints by invoking flying movement and animations, and improved path and animation error handling for walking waypoints.

Sequence Diagram(s)

sequenceDiagram
participant GameServer
participant FieldNpc
participant MovementState
participant AgentNavigation
GameServer->>FieldNpc: NextWaypoint()
alt AirWayPoint
FieldNpc->>MovementState: TryFlyTo(position, isBattle, sequence, speed, lookAt)
MovementState->>MovementState: Create NpcFlyToTask
MovementState->>MovementState: FlyTo(task, position, sequence, speed, lookAt)
MovementState->>AgentNavigation: FlyAdvance(start, target, speed, deltaTime)
AgentNavigation-->>MovementState: (newPosition, reachedTarget)
else Ground WayPoint
FieldNpc->>MovementState: TryMoveTo(...)
MovementState->>...: (existing walking logic)
end
Loading

Suggested reviewers

  • Zintixx

Poem

🐇
Air waypoints now dot the sky,
NPCs spread wings and fly!
With flying tasks and new advance,
They twirl and soar, they leap and dance.
Animation flows, no need to walk—
The code now lets our rabbits flock!
Upward and onward, let’s give it a try!


📜 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 54e9850 and f23b6fd.

📒 Files selected for processing (1)
  • Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
✨ 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.

@coderabbitaicoderabbitaiBot 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: 1

🧹 Nitpick comments (3)
Maple2.Model/Metadata/MapEntity/PatrolData.cs (1)

22-23: Added air waypoint support to the data model

The new AirWayPoint parameter enables waypoints to be flagged for flying movement, which is essential for the air waypoint feature.

For better naming consistency, consider aligning the parameter name with MS2PatrolData.IsAirWayPoint to either bool IsAirWayPoint or rename the IsAirWayPoint field in MS2PatrolData to AirWayPoint.

Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (1)

276-284: Improve error message for air waypoints.

When no flying animation is found, the error message refers to "walk sequence" which is confusing for air waypoints.

- Logger.Warning("No walk sequence found for npc {NpcId} in patrol {PatrolId}", Value.Metadata.Id, Patrol.Uuid);+ Logger.Warning("No fly sequence found for npc {NpcId} in patrol {PatrolId}", Value.Metadata.Id, Patrol.Uuid);
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateStates/MovementState.Walk.cs (1)

118-136: Flying movement implementation is clear and effective.

The flying advance logic correctly uses direct linear movement for flying NPCs, with appropriate handling of velocity, rotation, and task completion. Consider adding collision detection for flying NPCs in a future update to prevent them from flying through obstacles.

In the future, you might want to implement collision detection for flying NPCs to prevent them from flying through solid objects, similar to how walking NPCs navigate around obstacles.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a9f8f82 and 04ced14.

📒 Files selected for processing (7)
  • Maple2.File.Ingest/Mapper/MapEntityMapper.cs (1 hunks)
  • Maple2.Model/Metadata/MapEntity/PatrolData.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/AgentNavigation.cs (2 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (1 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateStates/MovementState.Walk.cs (4 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.WalkTask.cs (3 hunks)
  • Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
Maple2.Server.Game/Manager/Field/AgentNavigation.cs (1)
Maple2.Tools/DotRecast/DotRecastHelper.cs (1)
  • Vector3 (46-49)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (8)
Maple2.File.Ingest/Mapper/MapEntityMapper.cs (1)

228-228: Implementation correctly propagates air waypoint flag

The change correctly passes the patrolData.IsAirWayPoint flag to the MS2WayPoint constructor, ensuring that waypoints are appropriately marked for air navigation.

Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (1)

75-86: Well-structured implementation for flying movement

The new TryFlyTo method follows the same pattern as other movement methods, providing a clean interface for initiating flying movement with appropriate task priority handling and parameter propagation.

Maple2.Server.Game/Manager/Field/AgentNavigation.cs (1)

224-243: Well-implemented linear movement for flying

The FlyAdvance method provides a clean implementation for linear flying movement, correctly handling edge cases and providing a straightforward calculation for position updates. The documentation is clear about the method's purpose and parameters.

Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.WalkTask.cs (2)

79-103: Well-implemented flying task pattern!

The NpcFlyToTask class correctly follows the established pattern for NPC movement tasks, maintaining consistency with the existing codebase. Good job using the "Fly_A" animation for idle states when paused or finished.


137-158: The FlyTo implementation looks good.

This follows the same pattern as MoveTo but correctly calls StartFlying instead of StartWalking. The implementation appropriately handles validation checks before initiating flying movement.

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

78-78: Good addition of FlySequence field.

The FlySequence field properly matches the pattern established for other animation sequences.


284-296: Good ground movement validation.

The implementation correctly checks if a path exists before creating a movement task, which prevents NPCs from attempting to move to unreachable locations. The warning message is appropriately descriptive.

Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateStates/MovementState.Walk.cs (1)

60-82: StartFlying method matches established patterns.

The implementation mirrors the existing StartWalking method with appropriate adaptations for flying. Consider potential refactoring in the future to reduce code duplication between these two similar methods.

Comment threadMaple2.Server.Game/Model/Field/Actor/FieldNpc.cs
@AngeloTadeucci
AngeloTadeucciforce-pushed the air-waypoint branch 2 times, most recently from 131f5ba to f40fb4eCompareApril 29, 2025 12:38

@coderabbitaicoderabbitaiBot 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: 1

♻️ Duplicate comments (1)
Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (1)

262-268: Handle potential null reference in patrol waypoint access.

The code correctly gets the previous waypoint, but there's a risk of a null reference if the patrol data is unexpectedly null.

- MS2WayPoint currentWaypoint = Patrol!.WayPoints[currentWaypointIndex];+ if (Patrol == null || Patrol.WayPoints.Count == 0) {+ return MovementState.TryStandby(null, true);+ }++ MS2WayPoint currentWaypoint = Patrol.WayPoints[currentWaypointIndex];
🧹 Nitpick comments (2)
Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (2)

278-298: Consider refactoring to reduce code duplication in animation handling.

The approach animation handling logic is duplicated between air and ground waypoints. Consider extracting this common logic to reduce duplication.

 NpcTask? approachTask = null;
+ AnimationSequenceMetadata? sequenceToUse = null;++ // Try to get approach animation from waypoint+ if (!string.IsNullOrEmpty(currentWaypoint.ApproachAnimation) && + Value.Animations.TryGetValue(currentWaypoint.ApproachAnimation, out sequenceToUse)) {+ // Use the approach animation defined in the waypoint+ } else if (currentWaypoint.AirWayPoint && FlySequence is not null) {+ sequenceToUse = FlySequence;+ } else if (!currentWaypoint.AirWayPoint && WalkSequence is not null) {+ sequenceToUse = WalkSequence;+ }++ if (sequenceToUse is null) {+ Logger.Warning("No {Type} sequence found for npc {NpcId} in patrol {PatrolId}", + currentWaypoint.AirWayPoint ? "fly" : "walk", Value.Metadata.Id, Patrol.Uuid);+ }
if (currentWaypoint.AirWayPoint) {
- if (Value.Animations.TryGetValue(currentWaypoint.ApproachAnimation, out AnimationSequenceMetadata? patrolSequence)) {- approachTask = MovementState.TryFlyTo(currentWaypoint.Position, false, sequence: patrolSequence.Name, speed: Patrol.PatrolSpeed, lookAt: true);- } else if (FlySequence is not null) {- approachTask = MovementState.TryFlyTo(currentWaypoint.Position, false, sequence: FlySequence.Name, speed: Patrol.PatrolSpeed, lookAt: true);- } else {- Logger.Warning("No walk sequence found for npc {NpcId} in patrol {PatrolId}", Value.Metadata.Id, Patrol.Uuid);- }+ if (sequenceToUse is not null) {+ approachTask = MovementState.TryFlyTo(currentWaypoint.Position, false, sequence: sequenceToUse.Name, speed: Patrol.PatrolSpeed, lookAt: true);+ }
} else {
if (Navigation is not null && Navigation.PathTo(currentWaypoint.Position)) {
- if (Value.Animations.TryGetValue(currentWaypoint.ApproachAnimation, out AnimationSequenceMetadata? patrolSequence)) {- approachTask = MovementState.TryMoveTo(currentWaypoint.Position, false, sequence: patrolSequence.Name, speed: Patrol.PatrolSpeed);- } else if (WalkSequence is not null) {- approachTask = MovementState.TryMoveTo(currentWaypoint.Position, false, sequence: WalkSequence.Name, speed: Patrol.PatrolSpeed);- } else {- Logger.Warning("No walk sequence found for npc {NpcId} in patrol {PatrolId}", Value.Metadata.Id, Patrol.Uuid);- }+ if (sequenceToUse is not null) {+ approachTask = MovementState.TryMoveTo(currentWaypoint.Position, false, sequence: sequenceToUse.Name, speed: Patrol.PatrolSpeed);+ }
} else {
Logger.Warning("Failed to path to waypoint id({Id}) coord {Coord} for npc {NpcName} - {NpcId} in patrol {PatrolId}", currentWaypoint.Id, currentWaypoint.Position, Value.Metadata.Name, Value.Metadata.Id, Patrol.Uuid);
}
}

280-280: Consider making lookAt parameter consistent for both movement modes.

The TryFlyTo method uses lookAt: true but the TryMoveTo method doesn't include this parameter. For consistency, consider either adding it to ground movement or documenting why the behaviors differ.

- approachTask = MovementState.TryMoveTo(currentWaypoint.Position, false, sequence: patrolSequence.Name, speed: Patrol.PatrolSpeed);+ approachTask = MovementState.TryMoveTo(currentWaypoint.Position, false, sequence: patrolSequence.Name, speed: Patrol.PatrolSpeed, lookAt: true);

Also applies to: 289-289

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 131f5ba and f40fb4e.

📒 Files selected for processing (7)
  • Maple2.File.Ingest/Mapper/MapEntityMapper.cs (1 hunks)
  • Maple2.Model/Metadata/MapEntity/PatrolData.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/AgentNavigation.cs (2 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (1 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateStates/MovementState.Walk.cs (4 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.WalkTask.cs (3 hunks)
  • Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • Maple2.File.Ingest/Mapper/MapEntityMapper.cs
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs
  • Maple2.Server.Game/Manager/Field/AgentNavigation.cs
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateStates/MovementState.Walk.cs
  • Maple2.Model/Metadata/MapEntity/PatrolData.cs
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.WalkTask.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (3)
Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (3)

78-78: LGTM: Flying animation support properly added.

The implementation adds a nullable FlySequence field and initializes it from the NPC's animation dictionary, following the same pattern as other animation types.

Also applies to: 102-102


270-274: LGTM: Improved arrival animation handling.

The code now correctly checks the previous waypoint's ArriveAnimation and ensures the idle task isn't an emote task or null before playing the animation.


278-283: LGTM: Well-implemented air waypoint movement logic.

The implementation correctly handles air waypoints by using the new TryFlyTo method with appropriate fallback to the general FlySequence if no specific approach animation is defined.

Comment threadMaple2.Server.Game/Model/Field/Actor/FieldNpc.cs
@AngeloTadeucci
AngeloTadeucci marked this pull request as ready for review May 29, 2025 22:20
@AngeloTadeucci
AngeloTadeucci merged commit 0e5c339 into masterMay 30, 2025
@AngeloTadeucci
AngeloTadeucci deleted the air-waypoint branch May 30, 2025 05:50
Luca-LSEG added a commit to Luca-LSEG/Maple2 that referenced this pull request May 30, 2025
@coderabbitaicoderabbitaiBot mentioned this pull request Jul 9, 2025
Sign up for freeto 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

@AngeloTadeucci