Skip to content

[script][cast] cap-aware cambrinth charges behind a new cambrinth_distribute_charges setting - #7561

Open
simtel12 wants to merge 2 commits into
elanthia-online:mainfrom
simtel12:feat/cambrinth-distribute-charges-setting
Open

[script][cast] cap-aware cambrinth charges behind a new cambrinth_distribute_charges setting#7561
simtel12 wants to merge 2 commits into
elanthia-online:mainfrom
simtel12:feat/cambrinth-distribute-charges-setting

Conversation

@simtel12

Copy link
Copy Markdown
Contributor

Problem

cast.lic splits the cambrinth mana into charges of one size, then fills each item up to its cap and never returns to an item once a charge has passed it by. Both halves of that hurt a character whose cambrinth_items have very different caps.

Take a cap-4 worn earcuff, a cap-4 worn anklet and a cap-48 stored urchin, with cambrinth_num_charges: 3:

  • The split does not know the caps. 20 mana becomes charges of 7, 7 and 6. Nothing sized 7 can enter a cap-4 item, so only the urchin is used.
  • The packer only moves forward. 13 mana becomes 5, 4 and 4. The 5 does not fit the earcuff, so the packer advances to the anklet, then to the urchin, and never comes back. The two 4s that would have fitted the small items perfectly end up behind it in the urchin.

The small worn items therefore sit idle at most discerns, and their mana goes into the base prep instead.

Change

Behind the new cambrinth_distribute_charges setting, cast.lic hands the split to DRCA.allocate_cambrinth_charges. Each item takes as much as its cap allows, in the order the profile lists them, so a small worn item fills before a large stored one. Each item then splits its own share into charges.

caps 4/4/48, cambrinth_num_charges: 3

  to charge   before                 after
  13          [[], [], [5, 4, 4]]    [[4], [4], [5]]
  20          [[], [], [7, 7, 6]]    [[4], [4], [12]]
  36          [[], [], [12, 12, 12]] [[4], [4], [28]]

Sharing DRCA's allocator is the point: ,cast, the waggle sets and magic-training then charge the same way instead of each carrying its own scheme. An older Lich has no such method, so cast.lic checks for it and falls back to its own split.

The setting is off by default, so nothing changes for anyone who does not opt in. A single cambrinth item is unaffected either way.

profiles/base.yaml gains the setting with its default and an explanation.

Also fixed

distribute_num_charges divides by zero when the charge count is 0 and the prep is fixed by a runestone, because the loop keeps going while mana is left but has no charges to put it in. Mana that the charges cannot take now goes back into the prep.

Testing

  • bundle exec rspec — 3025 examples, 0 failures, including 8 new ones in spec/cast_spec.rb. They cover both schemes, the leftover going back into the prep, the fallback when Lich has no allocator, and the divide-by-zero case.
  • The fallback example drives the real guard rather than a stub of it: the spec harness DRCA genuinely has no allocate_cambrinth_charges, exactly like an older Lich.
  • bundle exec rubocop — clean on both changed files.

Companion change

elanthia-online/lich-5#1549 adds DRCA.allocate_cambrinth_charges and fixes the same class of problem in DRCA itself, where a flat cambrinth: list is charged into every item in full. This PR does not depend on that one landing first — without it, cast.lic keeps its current behaviour.

Test plan

  • ,cast <spell> is unchanged for a profile with one cambrinth item.
  • ,cast <spell> is unchanged for any profile that does not set cambrinth_distribute_charges.
  • With the setting on and several cambrinth_items, small items are charged up to their cap before a larger item is used.
  • ,cast <spell> -yaml exports the new nested charge list correctly.
  • A charge-time budget (,cast <spell> -c10s) still picks a plan inside the budget.

Adds the default and an explanation for a new Lich setting that spreads a
spell's cambrinth charges over cambrinth_items instead of charging each
item in full.

It only matters when cambrinth_items lists more than one item. Without it,
"cambrinth: [4, 10]" charges 4 and then 10 into every item. The default
stays off, so no profile changes behaviour. An older Lich ignores the key.
…e_charges

cast.lic splits the cambrinth mana into charges of one size, then fills each
item up to its cap and never returns to an item once a charge has passed it
by. A character with a cap-4 earcuff, a cap-4 anklet and a cap-48 urchin
therefore charges only the urchin at most discerns, because a charge of 7
fits none of the small items.

With the new cambrinth_distribute_charges setting, cast.lic hands the split
to DRCA.allocate_cambrinth_charges. Each item takes as much as its cap
allows, in the order the profile lists them, so a small worn item fills
before a large stored one:

  caps 4/4/48, 3 charges, 20 mana to charge
    before: [[], [], [7, 7, 6]]
    after:  [[4], [4], [12]]

Sharing DRCA's allocator keeps ,cast and the waggle scripts on one scheme.
An older Lich has no such method, so cast.lic checks for it and falls back
to its own split.

The setting is off by default, so nothing changes for anyone who does not
opt in. A single cambrinth item is unaffected either way.

Also stops distribute_num_charges from dividing by zero when the charge
count is 0 and the prep is fixed by a runestone. Undistributed mana now
goes back into the prep.

The base profile documents the new setting and its default.
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e404fb85-a95b-4e66-b4d6-33ef417c05b2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

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.

1 participant