Fix UGC Templates stacking - #421
Conversation
## Walkthrough
This set of changes updates the handling of cubes and item storage in the game server's furnishing and inventory systems. The `FurnishingManager` now supports adding cubes directly from `HeldCube` objects and distinguishes stored items by both item ID and template. The `AddStorage` method is refactored to accept an optional template parameter, and related method calls throughout the codebase are updated accordingly. Additionally, obsolete item creation methods are removed from the `ItemManager`, streamlining item instantiation and color assignment logic. A new packet handler for furnishing storage commands is added, and the item update packet now explicitly includes the item UID.
## Changes
| File(s) | Change Summary |
|------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| Maple2.Server.Game/Manager/HousingManager.cs | Modified `TryPlaceCube` to call `AddCube` with a `HeldCube` object instead of just the cube's item ID. |
| Maple2.Server.Game/Manager/Items/FurnishingManager.cs | Added `AddCube(HeldCube cube)` and refactored `AddStorage` to accept `Item item, UgcItemLook? template`. Updated storage logic to handle templates and direct `HeldCube` addition. Added `RemoveItem(long itemUid)` method. |
| Maple2.Server.Game/Manager/Items/InventoryManager.cs | Updated call to `AddStorage` to pass both the item and its template. |
| Maple2.Server.Game/Manager/Items/ItemManager.cs | Removed obsolete `CreateItem` and `GetColor` methods, eliminating legacy item creation and color assignment logic. |
| Maple2.Server.Core/Packets/UgcPacket.cs | Updated `UpdateItem` method signature to include explicit `uid` parameter and use it when writing item UID in the packet. |
| Maple2.Server.Game/PacketHandlers/FurnishingStorageHandler.cs | Added new packet handler class to process furnishing storage commands, currently supporting item deletion by UID. |
| Maple2.Server.Game/PacketHandlers/UgcHandler.cs | Modified `ConfirmItem` method to use `AddCube` return UID for furniture items and create items via DB for others, updating packet calls accordingly. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant HousingManager
participant FurnishingManager
participant InventoryManager
participant Database
participant UgcHandler
HousingManager->>FurnishingManager: AddCube(HeldCube cube)
FurnishingManager->>FurnishingManager: AddStorage(Item from cube, cube.Template)
FurnishingManager->>InventoryManager: Return item UID
UgcHandler->>FurnishingManager: AddCube(HeldCube cube) [if Furniture]
UgcHandler->>Database: CreateItem(characterId, item) [if not Furniture]
Database-->>UgcHandler: new item UID
UgcHandler->>InventoryManager: Add(item, notifyNew=true)
UgcHandler->>UgcPacket: UpdateItem(objectId, uid, item, createPrice, ugcType)Possibly related PRs
Suggested reviewers
Poem
|
feat: delete extra cubes
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
Maple2.Server.Core/Packets/UgcPacket.cs(2 hunks)Maple2.Server.Game/Manager/Items/FurnishingManager.cs(5 hunks)Maple2.Server.Game/PacketHandlers/FurnishingStorageHandler.cs(1 hunks)Maple2.Server.Game/PacketHandlers/UgcHandler.cs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- Maple2.Server.Game/Manager/Items/FurnishingManager.cs
🧰 Additional context used
🧬 Code Graph Analysis (1)
Maple2.Server.Game/PacketHandlers/UgcHandler.cs (4)
Maple2.Server.Game/Manager/Items/FurnishingManager.cs (5)
Item(67-71)Item(73-77)AddCube(155-170)AddCube(173-188)AddCube(190-205)Maple2.Server.Game/Manager/Items/InventoryManager.cs (2)
Item(560-568)Add(149-254)Maple2.Database/Storage/Game/GameStorage.Item.cs (7)
Item(13-20)Item(22-32)Item(50-57)Item(184-190)GameStorage(11-192)Request(12-191)UpdateItem(142-147)Maple2.Server.Core/Packets/UgcPacket.cs (1)
UgcPacket(12-231)
🪛 GitHub Actions: Format
Maple2.Server.Game/PacketHandlers/FurnishingStorageHandler.cs
[error] 8-8: dotnet format whitespace error: Fix whitespace formatting. Insert '\s'.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build
- GitHub Check: build
🔇 Additional comments (9)
Maple2.Server.Core/Packets/UgcPacket.cs (2)
79-79: Good improvement in parameter clarity.The explicit
uidparameter makes the method signature clearer and more flexible compared to implicitly accessingitem.Uidinside the method.
97-97: Correctly using the explicit UID parameter.This change ensures the packet contains the UID provided by the caller rather than implicitly relying on
item.Uid, which aligns with the method signature update.Maple2.Server.Game/PacketHandlers/UgcHandler.cs (4)
451-452: Good practice: tracking UID explicitly.Introducing a dedicated variable for tracking the item UID improves code clarity and makes the flow easier to follow.
454-456: Clean implementation of furniture-specific logic.The code now correctly delegates to the specialized
AddCubemethod in the furnishing manager for furniture items, addressing the UGC templates stacking issue mentioned in the PR title.
457-466: Robust database item creation with error handling.The implementation properly:
- Creates a database context with
using- Creates the item in the database for the character
- Checks for null (failure) and logs an error
- Extracts the UID from the new item
- Adds the item to inventory with notification
This is a significant improvement over previous code.
468-468: Consistent with the packet API update.This line correctly uses the explicit UID parameter when calling
UgcPacket.UpdateItem, matching the method signature change inUgcPacket.cs.Maple2.Server.Game/PacketHandlers/FurnishingStorageHandler.cs (3)
11-13: Appropriately defines the command enum.The enum definition follows the standard pattern in the codebase, with the
Deletecommand properly defined with value 6.
15-22: Standard packet handler implementation.The
Handlemethod correctly follows the established pattern for packet handlers by reading the command and dispatching to the appropriate handler method.
24-27: Clean and focused delete handler.The
HandleDeletemethod is properly implemented to:
- Read the item UID from the packet
- Call the appropriate method on the furnishing manager
This complements the changes in the UGC handler and provides a clean way to remove items from furnishing storage.
Summary by CodeRabbit
New Features
Bug Fixes
Chores