Skip to content

Feat: Implement Field to Home portals - #533

Merged
AngeloTadeucci merged 1 commit into
masterfrom
field-to-home-portal
Jul 9, 2025
Merged

Feat: Implement Field to Home portals#533
AngeloTadeucci merged 1 commit into
masterfrom
field-to-home-portal

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Jul 9, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for indoor portal cubes, allowing creation of portals between outdoor plots and indoor areas.
    • Portals are now automatically spawned or removed when placing or removing indoor portal cubes on outdoor plots.
  • Bug Fixes

    • Improved validation to prevent placing indoor portals on indoor plots and to restrict outdoor plots to a single indoor portal.
  • Other Changes

    • Enhanced cube placement and removal logic for better handling of indoor portal cubes and related portal management.

@coderabbitai

coderabbitai Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce an IndoorPortal boolean property to item metadata, replacing the previous ObjectCubeId integer. New logic is added to manage the placement, spawning, and removal of indoor portal cubes and their corresponding field portals, with updated validation and lifecycle management in housing and field managers.

Changes

File(s) Change Summary
Maple2.Model/Metadata/ItemMetadata.cs Replaced ObjectCubeId with IndoorPortal in ItemMetadataInstall record.
Maple2.File.Ingest/Mapper/ItemMapper.cs Set new IndoorPortal property in ItemMetadataInstall during mapping.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs Added SpawnFieldToHomePortal method for spawning portals for indoor portal cubes.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs Modified plot loading to process cubes (interactions and portals) per plot during initialization.
Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs Updated plot loading to handle portal spawning and interaction addition per plot, removing post-loop queries.
Maple2.Server.Game/Manager/HousingManager.cs Enhanced cube placement/removal to handle indoor portal cubes, enforce placement rules, and manage portals.
Maple2.Server.Game/Commands/CoordCommand.cs Adjusted coordinate parsing to apply block size scaling to absolute coordinates when asBlock is true.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HousingManager
    participant FieldManager
    participant Field

    User->>HousingManager: TryPlaceCube(cube, plot, metadata, ...)
    alt itemMetadata.Install is null
        HousingManager-->>User: Return false
    else if placing IndoorPortal on indoor plot
        HousingManager-->>User: Return false
    else if placing IndoorPortal on outdoor plot
        HousingManager->>FieldManager: SpawnFieldToHomePortal(plotCube, ownerId)
        alt Spawn fails
            HousingManager->>User: Send error, delete cube
        else
            FieldManager->>Field: Broadcast new portal
            HousingManager-->>User: Return true
        end
    else
        HousingManager-->>User: Proceed with normal placement
    end
Loading
sequenceDiagram
    participant User
    participant HousingManager
    participant FieldManager
    participant Field

    User->>HousingManager: TryRemoveCube(plot, position)
    alt Cube is IndoorPortal on outdoor plot
        HousingManager->>FieldManager: RemoveFieldPortal(ownerId)
        FieldManager->>Field: Remove portal from field
    end
    HousingManager-->>User: Return result
Loading

Suggested reviewers

  • Zintixx

Poem

In fields and homes where portals bloom,
A bunny hops from room to room.
With cubes and checks, the code grows neat—
Now indoor gates and plots can meet!
Through portals new, adventures start,
CodeRabbit’s joy in every part.
🐇✨

✨ 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: 1

🧹 Nitpick comments (1)
Maple2.Server.Game/Manager/HousingManager.cs (1)

699-705: Proper portal cleanup on cube removal.

The logic correctly removes the associated field portal when an indoor portal cube is removed from an outdoor plot, maintaining data consistency.

Consider using the null-conditional operator for cleaner code:

-if (plot.MapId is not Constant.DefaultHomeMapId && cube.Metadata.Install is { IndoorPortal: true }) {
-    FieldPortal? portal = session.Field?.GetPortals().FirstOrDefault(x => x.HomeId == plot.OwnerId);
-    if (portal is not null) {
-        session.Field?.RemovePortal(portal.ObjectId);
-    }
-}
+if (plot.MapId is not Constant.DefaultHomeMapId && cube.Metadata.Install is { IndoorPortal: true }) {
+    FieldPortal? portal = session.Field?.GetPortals().FirstOrDefault(x => x.HomeId == plot.OwnerId);
+    session.Field?.RemovePortal(portal?.ObjectId ?? 0);
+}

However, this is just a minor style preference - the current implementation is perfectly functional.

📜 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 503e701.

📒 Files selected for processing (7)
  • Maple2.File.Ingest/Mapper/ItemMapper.cs (1 hunks)
  • Maple2.Model/Metadata/ItemMetadata.cs (1 hunks)
  • Maple2.Server.Game/Commands/CoordCommand.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs (1 hunks)
  • Maple2.Server.Game/Manager/HousingManager.cs (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs (1)
Learnt from: AngeloTadeucci
PR: AngeloTadeucci/Maple2#236
File: Maple2.Server.Game/PacketHandlers/RequestCubeHandler.cs:375-422
Timestamp: 2024-09-16T07:50:30.281Z
Learning: In `RequestCubeHandler`, the `HandleLoadLayout` method is responsible for applying the layout to the plot after missing cubes are calculated in `HandleRequestLayout`.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (2)
Learnt from: AngeloTadeucci
PR: AngeloTadeucci/Maple2#236
File: Maple2.Server.Game/PacketHandlers/RequestCubeHandler.cs:375-422
Timestamp: 2024-09-16T07:50:30.281Z
Learning: In `RequestCubeHandler`, the `HandleLoadLayout` method is responsible for applying the layout to the plot after missing cubes are calculated in `HandleRequestLayout`.
Learnt from: Zintixx
PR: AngeloTadeucci/Maple2#279
File: Maple2.Database/Storage/Game/GameStorage.Wedding.cs:147-159
Timestamp: 2024-10-13T18:10:08.059Z
Learning: In the `GameStorage` class in `Maple2.Database/Storage/Game/GameStorage.Wedding.cs`, the `GetMarriage` method is necessary to properly convert the `Marriage` object and initialize `Partner1` and `Partner2`.
🧬 Code Graph Analysis (1)
Maple2.Server.Game/Commands/CoordCommand.cs (1)
Maple2.Model/Metadata/Constants.cs (1)
  • Constant (10-959)
⏰ 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 (9)
Maple2.File.Ingest/Mapper/ItemMapper.cs (1)

159-159: LGTM: Correct boolean conversion logic.

The conversion from data.install.indoor integer to boolean using != 0 is correct and follows standard conventions.

Maple2.Server.Game/Commands/CoordCommand.cs (1)

70-75: Verify that block scaling for absolute coordinates is intentional.

The change now applies block size scaling to absolute coordinates when the --block flag is used, making the behavior consistent with relative coordinates. This is a behavioral change that could affect existing usage.

Please confirm that this behavioral change is intentional and won't break existing coordinate commands that rely on absolute coordinates not being scaled.

Maple2.Model/Metadata/ItemMetadata.cs (1)

124-124: No removal of ObjectCubeId; only an addition of IndoorPortal
The new IndoorPortal boolean was added alongside the existing ObjectCubeId field—nothing was replaced or removed, so there is no breaking change.

• Maple2.Model/Metadata/ItemMetadata.cs still declares int ObjectCubeId next to bool IndoorPortal
• Maple2.File.Ingest/Mapper/ItemMapper.cs continues mapping ObjectCubeId
• Maple2.Server.Game/Manager/HousingManager.cs still calls itemMetadata.Install.ObjectCubeId

You can disregard the previous comment about replacing ObjectCubeId with IndoorPortal.

Likely an incorrect or invalid review comment.

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

141-150: LGTM: Correct implementation of inline plot processing.

The refactoring correctly processes cubes within each plot iteration and uses the new IndoorPortal boolean flag for portal filtering. This is consistent with the metadata model changes and should improve performance by avoiding multiple iterations over the same data.

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

219-238: LGTM! Well-implemented portal spawning logic.

The method correctly handles field-to-home portal creation with appropriate validation, positioning calculations, and portal configuration. The 75-unit offset positioning relative to the cube's front axis provides good spatial separation.

Maple2.Server.Game/Manager/HousingManager.cs (4)

532-532: Good defensive null check addition.

Adding the null check for itemMetadata.Install prevents potential null reference exceptions later in the method.


552-562: Well-structured outdoor plot validation.

The outdoor plot detection and ground tile verification logic is properly implemented. Using the acceleration structure to find sellable tiles ensures cubes are placed only on valid ground positions within the plot boundaries.


563-573: Appropriate portal placement restrictions.

The validation correctly enforces that indoor portals can only be placed on outdoor plots and limits each plot to a single portal, which prevents confusion and maintains a clean user experience.


671-680: Robust portal spawning with proper error handling.

The implementation correctly spawns field-to-home portals for indoor portal cubes on outdoor plots. The error handling ensures data consistency by deleting the cube if portal spawning fails, preventing orphaned cubes.

Comment thread Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs
@AngeloTadeucci
AngeloTadeucci merged commit 5b81b24 into master Jul 9, 2025
4 checks passed
@AngeloTadeucci
AngeloTadeucci deleted the field-to-home-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.

Home Entrances on Map Plots have no functionality

1 participant