Skip to content

Enter Stage simplified & Ensemble condition - #310

Merged
AngeloTadeucci merged 2 commits into
masterfrom
dev
Feb 20, 2025
Merged

Enter Stage simplified & Ensemble condition#310
AngeloTadeucci merged 2 commits into
masterfrom
dev

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Feb 17, 2025

Copy link
Copy Markdown
Collaborator

Added music_play_ensemble condition
Simplified enter stage with proper trigger box

Summary by CodeRabbit

  • New Features

    • Enhanced ensemble performance tracking, ensuring your play status updates in real-time when joining an ensemble.
    • Improved stage transitions with dynamic area detection for smoother entry and exit.
    • Introduced a new manager for handling performance stage interactions.
  • Refactor

    • Streamlined underlying behavior for consistent performance during ensemble play and stage movement.

@coderabbitai

coderabbitai Bot commented Feb 17, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce enhancements to the InstrumentHandler class, including a new using directive for collision tools and an update to the HandleJoinEnsemble method, which now triggers a condition update for ensemble music playing. Several null-conditional operators have been removed to enforce direct property access. The logic for entering and exiting the stage has been streamlined to utilize trigger box checks instead of hardcoded coordinates. Additionally, a new case for ConditionType.music_play_ensemble has been added to the ConditionUtil class, and a new PerformanceStageManager class has been introduced to manage performance stages.

Changes

File Change Summary
Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs • Added using directive for collision tools
• Updated HandleJoinEnsemble to call memberSession.ConditionUpdate(music_play_ensemble)
• Removed null-conditional operators in HandleStartPerform, HandleEndPerform, HandleFireworks, HandleEnterExitStage
• Modified HandleEnterExitStage logic to use trigger box checks
Maple2.Server.Game/Util/ConditionUtil.cs • Introduced new case ConditionType.music_play_ensemble in CheckCode and CheckTarget methods
Maple2.Server.Game/Manager/Field/FieldManager.cs • Added public readonly field PerformanceStage initialized based on MapId in FieldManager constructor
Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs • Introduced new class PerformanceStageManager with method EnterExitStage(GameSession session) to manage player interactions with performance stages

Possibly related PRs

Suggested reviewers

  • Zintixx

Poem

Oh, how I hop through lines of code with glee,
New tunes of logic set my circuits free.
A melody of conditions now doth play,
Trigger boxes guide the stage by day.
With every hop and every clever tweak,
This rabbit celebrates changes unique!
🐇🎶 Happy coding!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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: 1

🧹 Nitpick comments (2)
Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs (2)

154-154: Address TODO comment about Prestige exp.

The TODO comment indicates that Prestige exp functionality is missing. Would you like me to help implement this feature or create an issue to track this task?


284-291: LGTM! Improved stage boundary detection with TriggerBox.

The change from hardcoded coordinates to TriggerBox is a good improvement. However, consider documenting or defining the magic numbers as constants:

  • TriggerBox ID: 101
  • Portal IDs: 802, 803
+private const int STAGE_TRIGGER_BOX_ID = 101;
+private const int STAGE_ENTRY_PORTAL_ID = 802;
+private const int STAGE_EXIT_PORTAL_ID = 803;

-session.Field.TriggerObjects.Boxes.TryGetValue(101, out TriggerBox? triggerBox);
+session.Field.TriggerObjects.Boxes.TryGetValue(STAGE_TRIGGER_BOX_ID, out TriggerBox? triggerBox);

-session.Field.MoveToPortal(session, insideStage ? 802 : 803);
+session.Field.MoveToPortal(session, insideStage ? STAGE_ENTRY_PORTAL_ID : STAGE_EXIT_PORTAL_ID);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2469923 and a2d08c5.

📒 Files selected for processing (2)
  • Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs (3 hunks)
  • Maple2.Server.Game/Util/ConditionUtil.cs (2 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • Maple2.Server.Game/Util/ConditionUtil.cs
  • Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: format
  • GitHub Check: build
🔇 Additional comments (10)
Maple2.Server.Game/Util/ConditionUtil.cs (3)

129-129: LGTM! Addition of music_play_ensemble condition.

The new condition follows the established pattern for music-related conditions and is consistently implemented in both CheckCode and CheckTarget methods.

Also applies to: 226-226


129-129: LGTM! Consistent implementation of the new ensemble condition.

The new music_play_ensemble condition is correctly implemented and follows the established pattern for similar condition types.

Also applies to: 226-226


129-129: LGTM! Addition of music_play_ensemble condition.

The new condition follows the established pattern for music-related conditions and is consistently implemented in both CheckCode and CheckTarget methods.

Also applies to: 226-226

Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs (7)

284-290: LGTM! Improved stage entry/exit implementation.

The change from hardcoded coordinates to TriggerBox is a significant improvement:

  • Uses proper collision detection
  • Adds proper null safety checks
  • Makes the code more maintainable

216-216: LGTM! Well-placed condition update.

The condition update is correctly placed after all validation checks pass and the ensemble successfully starts, ensuring accurate state tracking.


268-268:

Details

❓ Verification inconclusive

Consider maintaining defensive null checks.

The removal of null-conditional operators (?.) when accessing session.Field.MapId assumes Field is never null. While this might be true in the current implementation, maintaining defensive null checks could prevent potential NullReferenceException if the contract changes in the future.

Also applies to: 274-274, 280-280, 294-294


🏁 Script executed:

#!/bin/bash
# Search for other Field.MapId usages to verify the pattern
rg -A 2 "Field\.MapId" --type cs

Length of output: 183


I'll need to gather more context on how the Field.MapId pattern is used in this file before finalizing a recommendation. The previous rg command didn’t return results due to a file filtering issue. To get a complete picture, please run the following script which searches directly in the intended file:

Once we have the output from this script, we can confidently assess whether the removal of defensive null checks is safe or if they should be reinstated.


🏁 Script executed:

#!/bin/bash
# Searching for Field.MapId occurrences in InstrumentHandler.cs to verify null-safety assumptions.
rg "Field\.MapId" Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs -n

Length of output: 172


I'll need to verify the location of the file to ensure we are examining the proper code. Since the previous lookup for Field.MapId used an explicit file path that returned "No such file or directory," let's search for the InstrumentHandler.cs file across the repository.

Once we have the correct location, we can verify the usage of Field.MapId within the file. Please provide the output so we can proceed with a confident assessment of the null-safety changes.


🏁 Script executed:

#!/bin/bash
# Searching for InstrumentHandler.cs to confirm its correct location
find . -type f -name "InstrumentHandler.cs"

Length of output: 43


I'll need to verify the location and content of the file before providing a final recommendation on the null-safety changes. The previous search for InstrumentHandler.cs didn't return any file, which suggests that the file might be located elsewhere or renamed. Please run this script to search for any C# file containing "InstrumentHandler" in its name:

Once you provide the output, we can confirm the file's existence and verify its usage of Field.MapId to properly assess whether defensive null checks are needed.


🏁 Script executed:

#!/bin/bash
# Searching for any C# file with "InstrumentHandler" in the filename in the repository
find . -type f -iname "*InstrumentHandler*.cs"

Length of output: 48


Action Required: Confirm File Location & Reassess Defensive Null Checks

It appears that our searches did not locate the expected file (InstrumentHandler.cs). Please verify that the file exists under its expected path (or has been renamed/moved) so we can accurately assess the removal of null-conditional operators. As noted, removing the null-conditional operators on session.Field.MapId assumes that Field is always non-null. Given potential future changes to this contract, please double-check:

  • The existence and correct location of the InstrumentHandler file.
  • That Field is indeed guaranteed non-null across all usages (including lines 274, 280, and 294) before this safeguard is permanently removed.

16-16: LGTM! Proper integration of ensemble condition update.

The condition update is correctly placed after successfully starting the ensemble score.

Also applies to: 216-216


284-290: LGTM! Improved stage entry logic using TriggerBox.

The change from hardcoded coordinates to TriggerBox is a significant improvement:

  • More maintainable by removing hardcoded values
  • More robust using proper collision detection
  • Properly handles the case when TriggerBox is not found

268-268:

Details

❓ Verification inconclusive

Verify Field non-null assumption.

The removal of null-conditional operators (?.) when accessing session.Field.MapId assumes that Field is guaranteed to be non-null. While there are null checks at the beginning of these methods, please verify this assumption holds true throughout the execution path.

Also applies to: 274-274, 280-280, 294-294


🏁 Script executed:

#!/bin/bash
# Search for places where Field might be set to null
ast-grep --pattern 'session.Field = null'

# Search for other methods that might modify Field
rg -A 5 'Field\s*=' 

Length of output: 214


Verify Field Non-Null Guarantee

The direct access to session.Field.MapId (line 268) assumes that Field is guaranteed to be non-null, which is why the null-conditional operator (?.) was removed. Although the method contains initial null checks, it’s crucial to confirm that no execution path reassigns Field to null and that its initialization is robust.

Please verify the following:

  • Ensure that there are no cases where session.Field gets set to null or unexpectedly reassigned.
  • Double-check that all code paths accessing session.Field (including those on lines 274, 280, and 294) are protected by sufficient checks prior to this usage.

The above shell script attempts should help, but manual verification may still be warranted to ensure overall safety.


🏁 Script executed:

#!/bin/bash
# Re-run search for assignments setting session.Field to null,
# ensuring all files are scanned by removing ignore patterns.
rg --no-ignore --hidden -A 5 'session\.Field\s*=\s*null'
rg --no-ignore --hidden -A 5 'session\.Field\s*='

Length of output: 110


Verify Field Non-Null Guarantee

The earlier searches returned no output, but it appears that ripgrep might have skipped files. To be certain that no execution path inadvertently sets session.Field to null (or modifies it unexpectedly), please run the above script. Once you've confirmed that no assignments to session.Field occur—including null assignments—across the entire codebase, you can confidently assume that the direct access to session.Field.MapId is safe.

If the results confirm no modifications to session.Field, then the removal of the null-conditional operator is justified. Otherwise, please update the checks accordingly.


🏁 Script executed:

#!/bin/bash
# Search all C# files for any assignments to session.Field (including potential null assignments)
fd -e cs | xargs rg --no-ignore -n 'session\.Field\s*='

Length of output: 206


Action Required: Verify Non-Null Assumption of session.Field

The removal of the null-conditional operator (?.) when accessing session.Field.MapId assumes that Field will always be non-null. Our automated searches for assignments (including possible null assignments) to session.Field across the codebase did not return results. However, since the search did not actually process any files (as indicated by the output), this result remains inconclusive.

Please manually verify the following in the codebase:

  • Confirm that all execution paths initializing or modifying session.Field guarantee a non-null value.
  • Check that no code (especially within the methods surrounding lines 268, 274, 280, and 294 in Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs) reassigns session.Field to null or otherwise invalidates its assumption of being non-null.

Once these checks are confirmed, you can be confident that directly accessing session.Field.MapId is safe. Otherwise, consider reintroducing the null-conditional operator or additional safeguards where necessary.


216-216: LGTM! Condition update for ensemble music.

The condition update is well-placed after successful instrument usage and score broadcast, ensuring proper state tracking.

Comment thread Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs Outdated

@Zintixx Zintixx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

imo instead of having a constant for this, we put this all in a PerformanceStageManager that is in field.
When the field is instructed, we check if the map is queenstown and if so, we init a stage manager.
I say this all because there's a queue and time limit that needs to be handled for the stage

@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 (2)
Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs (2)

18-24: Extract magic numbers into constants.

The trigger box ID (101) and portal IDs (802, 803) should be defined as constants to improve maintainability and readability.

+    private const int STAGE_TRIGGER_BOX_ID = 101;
+    private const int STAGE_ENTRY_PORTAL_ID = 802;
+    private const int STAGE_EXIT_PORTAL_ID = 803;
+
     public void EnterExitStage(GameSession session) {
-        Field.TriggerObjects.Boxes.TryGetValue(101, out TriggerBox? triggerBox);
+        Field.TriggerObjects.Boxes.TryGetValue(STAGE_TRIGGER_BOX_ID, out TriggerBox? triggerBox);
         if (triggerBox is null) {
             return;
         }

         bool insideStage = triggerBox.Contains(session.Player.Position);
-        Field.MoveToPortal(session, insideStage ? 802 : 803);
+        Field.MoveToPortal(session, insideStage ? STAGE_ENTRY_PORTAL_ID : STAGE_EXIT_PORTAL_ID);
     }

7-7: Consider implementing queue management and time limit.

The TODO comment indicates important features that should be implemented for better stage management:

  1. Queue system to handle multiple players wanting to enter the stage
  2. Time limit to prevent a single player from monopolizing the stage

Would you like me to help design and implement these features or create an issue to track this work?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a2d08c5 and 0db216a.

📒 Files selected for processing (3)
  • Maple2.Server.Game/Manager/Field/FieldManager.cs (2 hunks)
  • Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs (1 hunks)
  • Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Maple2.Server.Game/PacketHandlers/InstrumentHandler.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: format
  • GitHub Check: build
🔇 Additional comments (2)
Maple2.Server.Game/Manager/Field/PerformanceStageManager.cs (1)

17-25: LGTM! Clean implementation of stage entry/exit logic.

The implementation effectively uses trigger boxes to determine player position relative to the stage and moves them to appropriate portals. This is a clean and maintainable solution.

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

57-57: LGTM! Clean integration of PerformanceStageManager.

The PerformanceStageManager is properly integrated:

  • Declared as nullable readonly field
  • Initialized only for the specific performance map
  • Uses proper null safety patterns

Also applies to: 99-101

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