fix(ChangeAttributes): Fix wrong bonus value gen by Value Re-roller - #569
Conversation
…f two-handed weapons # Changes ## `Maple2.Server.Game\PacketHandlers\ChangeAttributesScrollHandler.cs` - Modified the handling logic for the in-game item "Bonus Value Re-roller" (e.g., ID 31001985) to align with the structure of "Bonus Re-roller" - Implemented calls to the new processing interface `UpdateFixedOption` (as counterpart to `UpdateRandomOption`) ## `Maple2.Server.Game\Util\ItemStatsCalculator.cs` - Created the `UpdateFixedOption` function following a similar structure to `UpdateRandomOption` - The updated Option directly uses the Basic and Special values from the original Option, along with the `multiplyFactor` from the metadata's RandomTable # Reason for Changes Bug Symptom: When using the "Bonus Value Re-roller" item (e.g., ID 31001985), two-handed weapons would receive abnormal values that were lower than the minimum expected range. Root Cause: The original logic failed to transfer the `multiplyFactor` between old and new Options, causing two-handed weapons to use the default `multiplyFactor = 1` and generate new values within **the same random range as one-handed weapons**. Change 1: > ``` > Maple2.Server.Game\PacketHandlers\ChangeAttributesScrollHandler.cs > ``` Standardized the abstraction level by unifying attribute modification logic into the `ItemStatsCalculator.cs` Change 2: > ``` > Maple2.Server.Game\Util\ItemStatsCalculator.cs > ``` Correctly implemented the transfer of `multiplyFactor` between Options
WalkthroughReplaces metadata-driven attribute randomization with a fixed-option update flow: ChangeAttributesScrollHandler now calls ItemStatsCalculator.UpdateFixedOption (optionally with LockOption presets) and signals failures via ChangeAttributesPacket.Error; item option metadata lookups were removed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant H as ChangeAttributesScrollHandler
participant ISC as ItemStatsCalculator
participant P as ChangeAttributesPacket
C->>H: Request change attributes (roll/fixed, optional lock item)
H->>ISC: UpdateFixedOption(ref item, [LockOption...])
alt ISC returns true
ISC-->>H: success
H->>P: Success (send updated item)
P-->>C: OK
else ISC returns false
ISC-->>H: failure
H->>P: Error(s_itemremake_error_server_default)
P-->>C: Error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Maple2.Server.Game/PacketHandlers/ChangeAttributesScrollHandler.cs (1)
119-132: Replace incorrect packet type in ChangeAttributesScrollHandler error paths
ChangeAttributesScrollHandler.cs (lines 120, 125, 131, 140, 145): currently callsChangeAttributesPacket.Error(ChangeAttributesError…), but should callChangeAttributesScrollPacket.Error(ChangeAttributesScrollError…)to match this handler’s other error paths.
🧹 Nitpick comments (1)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (1)
187-187: Fix dotnet-format whitespace error.Add a space before the opening brace.
-public bool UpdateFixedOption(ref Item item, params LockOption[] presets){ +public bool UpdateFixedOption(ref Item item, params LockOption[] presets) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
Maple2.Server.Game/PacketHandlers/ChangeAttributesScrollHandler.cs(1 hunks)Maple2.Server.Game/Util/ItemStatsCalculator.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (4)
Maple2.Model/Game/Item/Item.cs (4)
Item(9-269)Item(50-90)Item(92-117)Item(119-144)Maple2.Model/Game/Item/ItemOption.cs (4)
LockOption(35-38)LockOption(40-43)TryGet(45-54)TryGet(56-65)Maple2.Model/Game/Item/ItemStats.cs (6)
Option(98-124)Option(106-110)ItemStats(9-125)ItemStats(28-33)ItemStats(35-43)ItemStats(45-53)Maple2.Tools/Extensions/EnumerableExtensions.cs (1)
TryGetValue(74-82)
Maple2.Server.Game/PacketHandlers/ChangeAttributesScrollHandler.cs (3)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (1)
UpdateFixedOption(187-223)Maple2.Model/Game/Item/ItemOption.cs (2)
LockOption(35-38)LockOption(40-43)Maple2.Server.Game/Packets/ChangeAttributesPacket.cs (1)
ChangeAttributesPacket(10-43)
🪛 GitHub Actions: Format
Maple2.Server.Game/Util/ItemStatsCalculator.cs
[error] 187-187: dotnet format whitespace check failed for step: dotnet format whitespace --verify-no-changes --exclude 'Maple2.Server.World/Migrations/*.cs'. Issue found in Maple2.Server.Game/Util/ItemStatsCalculator.cs:187: WHITESPACE: Fix whitespace formatting. Insert '\s'.
⏰ 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
fix bug of Special Attribute fix format to pass format check fix reuses original dictionaries to avoid potential issues add assert of attribute in option
…f two-handed weapons
Changes
Maple2.Server.Game\PacketHandlers\ChangeAttributesScrollHandler.csUpdateFixedOption(as counterpart toUpdateRandomOption)Maple2.Server.Game\Util\ItemStatsCalculator.csUpdateFixedOptionfunction following a similar structure toUpdateRandomOptionmultiplyFactorfrom the metadata's RandomTableReason for Changes
Bug Symptom: When using the "Bonus Value Re-roller" item (e.g., ID 31001985), two-handed weapons would receive abnormal values that were lower than the minimum expected range.
Root Cause: The original logic failed to transfer the
multiplyFactorbetween old and new Options, causing two-handed weapons to use the defaultmultiplyFactor = 1and generate new values within the same random range as one-handed weapons.Change 1:
Standardized the abstraction level by unifying attribute modification logic into the
ItemStatsCalculator.csChange 2:
Correctly implemented the transfer of
multiplyFactorbetween OptionsSummary by CodeRabbit
New Features
Bug Fixes