Skip to content

Fix enchant scroll applying single-level stats instead of cumulative#674

Merged
Zintixx merged 2 commits intomasterfrom
fix/enchant-scroll-cumulative
Apr 3, 2026
Merged

Fix enchant scroll applying single-level stats instead of cumulative#674
Zintixx merged 2 commits intomasterfrom
fix/enchant-scroll-cumulative

Conversation

@AngeloTadeucci
Copy link
Copy Markdown
Collaborator

@AngeloTadeucci AngeloTadeucci commented Mar 29, 2026

EnchantScrollHandler.HandleEnchant only called GetEnchant for the target level, giving e.g. only level 11's bonus instead of the sum of levels 1 through 11. HandlePreview also computed deltas from current enchant level instead of absolute cumulative values, showing wrong stats when using a scroll on an already-enchanted item.

Both now use GetCumulativeEnchant which sums per-level rates from 1 through the target level, matching manual Ophelia/Peachy enchanting.

Summary by CodeRabbit

  • Bug Fixes
    • Enchant scroll preview now accurately computes and displays option ranges across enchant levels using cumulative accumulation.
    • Corrected handling of random vs. standard enchant types so previews reflect true min/max options.
    • Fixed enchant application so upgraded items properly accumulate enchant properties and repopulate option lists after an upgrade.

EnchantScrollHandler.HandleEnchant only called GetEnchant for the target
level, giving e.g. only level 11's bonus instead of the sum of levels
1 through 11. HandlePreview also computed deltas from current enchant
level instead of absolute cumulative values, showing wrong stats when
using a scroll on an already-enchanted item.

Both now use GetCumulativeEnchant which sums per-level rates from 1
through the target level, matching manual Ophelia/Peachy enchanting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 271493c6-0743-4cb9-8d61-29e21cf3b787

📥 Commits

Reviewing files that changed from the base of the PR and between 1a8a18f and 6a9fb6e.

📒 Files selected for processing (1)
  • Maple2.Server.Game/PacketHandlers/EnchantScrollHandler.cs

📝 Walkthrough

Walkthrough

Preview and apply logic for enchant scrolls changed to compute cumulative BasicOptions across levels using a new GetCumulativeEnchant helper; preview selects min/max from cumulative results, and application updates item.Enchant fields by accumulating and replacing basic options rather than assigning a single-level enchant directly.

Changes

Cohort / File(s) Summary
Enchant Scroll Handler
Maple2.Server.Game/PacketHandlers/EnchantScrollHandler.cs
Reworked preview and apply flows to use a new GetCumulativeEnchant(session, item, targetLevel) helper that accumulates BasicOptions across levels 1..targetLevel. Preview for Random scrolls uses cumulative values at min/max metadata enchants; non-random uses cumulative at max. Runtime apply logic now computes cumulative enchant for the final level, sets item.Enchant.Enchants = targetLevel, clears item.Enchant.BasicOptions, and repopulates from the computed cumulative result instead of directly assigning item.Enchant from a single-level lookup. Added private static helper to produce cumulative enchant results.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Possibly related PRs

  • Fix: Add enchant stats to character #453 — Modifies consumption of item.Enchant.BasicOptions when applying enchant stats to characters; related to how BasicOptions are produced/used.
  • fix enchanting #631 — Adjusts merging and update logic for enchant BasicOptions and enchant counters; overlaps with cumulative accumulation changes.

Suggested reviewers

  • Zintixx

Poem

🐰
Whiskers twitch, I count each hop,
From one to target, options pop,
Cumulative bits stitched level by level,
Random or steady, none left dishevel,
I nibble code and bless this drop. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main bug fix: enchant scrolls now apply cumulative stats instead of single-level stats.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/enchant-scroll-cumulative

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Maple2.Server.Game/PacketHandlers/EnchantScrollHandler.cs`:
- Line 110: The current assignment item.Enchant = GetCumulativeEnchant(session,
item, enchantLevel) replaces the existing ItemEnchant object and wipes persisted
fields (EnchantExp, EnchantCharges, Charges, Tradeable) — instead, update the
existing Item.Enchant in-place: call GetCumulativeEnchant to obtain the computed
BasicOptions/Enchants and then copy only those specific properties onto the
existing item.Enchant instance (or create it if null) so EnchantExp,
EnchantCharges, Charges and Tradeable remain unchanged; apply the same in-place
merge fix for the other similar block referenced around lines 138-151.
- Around line 67-69: The preview for Random scrolls uses metadata.Enchants.Min()
directly which can show a lower floor than the item's current enchant; change
the min preview calculation in the EnchantScrollType.Random branch of
HandleEnchant to clamp the minimum roll to the item's current enchant (e.g.,
compute minRoll = Math.Max(metadata.Enchants.Min(), currentEnchant) or
equivalent using the item's current enchant level) before calling
GetCumulativeEnchant(session, item, ...). Leave the max preview as
metadata.Enchants.Max() but ensure both calls use the clamped value for the
lower bound so minOptions reflects the true non-decreasing floor.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17ba1ebe-0ea3-451f-b707-165b486f42de

📥 Commits

Reviewing files that changed from the base of the PR and between edabcd9 and 1a8a18f.

📒 Files selected for processing (1)
  • Maple2.Server.Game/PacketHandlers/EnchantScrollHandler.cs

Clamp preview minimum to item's current enchant level (Math.Max) since
enchant scrolls never decrease enchant level. Update enchant properties
in-place instead of replacing the ItemEnchant object to preserve
persisted fields (EnchantExp, EnchantCharges, Charges, Tradeable).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Zintixx Zintixx merged commit ee532da into master Apr 3, 2026
3 checks passed
@AngeloTadeucci AngeloTadeucci deleted the fix/enchant-scroll-cumulative branch April 3, 2026 22:16
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