Skip to content

[#6627] Fix getActorCurrencyUpdates not working in some instances#6707

Merged
Fyorl merged 2 commits into
5.3.xfrom
fix/6627
Feb 25, 2026
Merged

[#6627] Fix getActorCurrencyUpdates not working in some instances#6707
Fyorl merged 2 commits into
5.3.xfrom
fix/6627

Conversation

@arbron

@arbron arbron commented Feb 9, 2026

Copy link
Copy Markdown
Collaborator

Modifies how getActorCurrencyUpdates works to now perform additional passes in an attempt to find the correct currency to deduce without resulting in a remainder. Previously, if you had a character with 100 gp, 5 sp, and 20 cp, and you asked to deduce 100 cp, it would return a remainder of 30 despite having enough currency to complete the request. This is because the loop would start at the lowest currency (100 - 20 = 80), then go to the next currency up (80 - (5 * 10) = 30), and then continue up through the denominations not finding any more that would be able to be deducted.

This change causes it to instead perform several loops over the list of currencies. If on the first pass ends with a remainder, then it will move the first entry in the currencies list to the end and re-perform the calculation. It will continue until it ends up with a remainder of 0 or has used each currency denomination as its first entry.

Closed #6627

Modifies how `getActorCurrencyUpdates` works to now perform
additional passes in an attempt to find the correct currency to
deduce without resulting in a remainder. Previously, if you had a
character with 100 gp, 5 sp, and 20 cp, and you asked to deduce
100 cp, it would return a remainder of 30 despite having enough
currency to complete the request. This is because the loop would
start at the lowest currency (100 - 20 = 80), then go to the next
currency up (80 - (5 * 10) = 30), and then continue up through the
denominations not finding any more that would be able to be
deducted.

This change causes it to instead perform several loops over the
list of currencies. If on the first pass ends with a remainder,
then it will move the first entry in the currencies list to the end
and re-perform the calculation. It will continue until it ends up
with a remainder of `0` or has used each currency denomination as
its first entry.

Closes #6627
@arbron arbron added this to the D&D5E 5.3.0 milestone Feb 9, 2026
@arbron arbron self-assigned this Feb 9, 2026
@arbron arbron added the api label Feb 9, 2026
@arbron
arbron requested a review from Fyorl February 21, 2026 00:03

@Fyorl Fyorl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if this PR is intended to fix all or just some of the issues in #6627. It doesn't handle the the case of deducting 1gp from an actor with 1pp (Math.floor(1 * 0.1) = 0). We would need to generate change for that, and I'm not sure if this method is intending to do that.

Comment thread module/applications/currency-manager.mjs Outdated
Comment thread module/applications/currency-manager.mjs Outdated
Comment thread module/applications/currency-manager.mjs Outdated
@arbron

arbron commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator Author

Not sure if this PR is intended to fix all or just some of the issues in #6627. It doesn't handle the the case of deducting 1gp from an actor with 1pp (Math.floor(1 * 0.1) = 0). We would need to generate change for that, and I'm not sure if this method is intending to do that.

This fix is focused on fixing the behavior that broke at some point in the past. I added another issue (#6708) to add a makeChange option that would allow the system to go one step further.

@arbron
arbron requested a review from Fyorl February 25, 2026 17:44

@Fyorl Fyorl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fix is focused on fixing the behavior that broke at some point in the past. I added another issue (#6708) to add a makeChange option that would allow the system to go one step further.

Probably shouldn't be marked as closing #6627 then (and maybe #6627 should be a feature request, not bug), but otherwise this looks good, thank you.

@Fyorl
Fyorl merged commit e2c69ab into 5.3.x Feb 25, 2026
@arbron
arbron deleted the fix/6627 branch March 2, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deductActorCurrency doesn't look at higher currencies if lower currencies partially fulfill request

2 participants