Repository navigation
feat(statcalc): apply a named datacron's stat affixes to characters - #266
Merged
Merged
Conversation
A player owns many datacrons and picks one per squad, so stats are asked for "with this datacron" rather than "with datacrons". calc_player_stats takes a datacron_id from the player's own collection; calc_roster_stats and calc_char_stats take the datacron object. The acalc_* wrappers on StatCalcAsync pass the same arguments through. Each character gains a `datacron` bucket beside `final`, never summed into it. The bucket is the last link of the percent-conversion chain, so `final + datacron` is correct for every stat, including the non-linear percentage stats such as Armor and Resistance. Ships get no bucket. Affixes are gated on the unit's gear tier and encoded relic tier; a unit with no relic sits at the locked tier rather than 0, so it still gets the affixes that require no relic. Ability affixes are skipped. Percent affixes expand onto their target stats through the mapping the mod path already uses, now shared from the new _datacron module, and resolve against base plus gear, excluding mods. A stat's affix percentages are summed and then rounded to the two decimals the datacron card shows, which is what in-game readings match. Without a datacron argument nothing changes: no bucket appears and the output is identical to before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No reference calculator implements datacrons, so the parity suite cannot check them. The fixture records stat values read off the live game for a hand-authored unit under three datacrons and none, and the test asserts `final + datacron` against them at the precision the game displays. The readings are the measurement: when the implementation disagrees, the implementation changes. The fixture carries no account-identifying fields and the datacron ids are placeholders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Walks through applying a datacron, combining it with `final`, affix requirements across units, comparing datacrons, ships being unaffected, and applying one of a real player's datacrons fetched from Comlink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds datacron support to
StatCalc: given one of a player's datacrons, each character gains adatacronstat bucket holding what that datacron adds to it.A player owns many datacrons and picks one per squad, so the caller names the datacron rather than the library choosing one:
calc_player_stats(player, datacron_id=...)looks the id up in the player's owndatacroncollection and raisesKeyErrorif it is not there.calc_roster_stats(units, datacron)andcalc_char_stats(unit, datacron)take the datacron object.StatCalcAsync.acalc_player_stats,acalc_roster_statsandacalc_char_statspass the same arguments through.How the contribution is resolved:
finaland is never summed into it. It is the last link of the percent-conversion chain, sofinal + datacronis correct for every stat, including non-linear percentage stats such as Armor and Resistance.StatCalc/_datacron.py. They resolve against base plus gear, without mods.With no datacron argument nothing changes: no bucket appears and the output is identical to before.
Also adds
tests/resources/datacron-golden.json, stat values read from the game for a hand-authored unit under three datacrons and none. No reference calculator implements datacrons, so the parity suite cannot cover them. Adds sync and asynccalc_datacron_stats.pyexamples and a section indocs/api/statcalc.md.Left out on purpose, as candidates for a separate PR: renaming ship stats to display names, and raising an error on stat display-name collisions during renaming.
Related Issues
None.
Type of Change
Checklist
developbranch (only release PRs targetmain)feat:,fix:,refactor:, etc.) — they become the changelogCHANGELOG.mdby hand (it is generated from commit messages)README.md,docs/,examples/) if user-facing behavior changeduv run pytest tests/)uv run ruff check src/ tests/anduv run ruff format --check src/ tests/)uv run ty check src/swgoh_comlink/)Testing
uv run pytest tests/: 2057 passed, 31 skipped. Includes the newtests/statcalc/test_datacron.py, the golden-fixture test and theacalc_*datacron tests.RUN_PARITY_TESTS=1 uv run pytest tests/statcalc/test_parity.py: passes, so output without a datacron still matches the JS reference.uv run ruff check,uv run ruff format --check,uv run ty check src/swgoh_comlink/anduv run python .github/scripts/unasync.py --check: pass.examples/*/calc_datacron_stats.pyagainst the public Comlink release (spec 0.40.5). Sync and async output match, and the live section applied a real player's datacron.Worth checking: the golden fixture asserts
final + datacronat the precision the game displays. If it fails, the implementation is what should change, not the fixture.🤖 Generated with Claude Code