Feat: Implement Field to Home portals - #533
Conversation
WalkthroughThe changes introduce an Changes
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
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
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
📒 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.indoorinteger to boolean using!= 0is 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
--blockflag 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 newIndoorPortalboolean was added alongside the existingObjectCubeIdfield—nothing was replaced or removed, so there is no breaking change.• Maple2.Model/Metadata/ItemMetadata.cs still declares
int ObjectCubeIdnext tobool IndoorPortal
• Maple2.File.Ingest/Mapper/ItemMapper.cs continues mappingObjectCubeId
• Maple2.Server.Game/Manager/HousingManager.cs still callsitemMetadata.Install.ObjectCubeIdYou can disregard the previous comment about replacing
ObjectCubeIdwithIndoorPortal.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
IndoorPortalboolean 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.Installprevents 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.
Summary by CodeRabbit
New Features
Bug Fixes
Other Changes