Skip to content

feat(statcalc): apply a named datacron's stat affixes to characters - #266

Merged
MarTrepodi merged 3 commits into
developfrom
feat/datacron-statcalc
Nov 10, 2026
Merged

MarTrepodi merged 3 commits into
developfrom
feat/datacron-statcalc

Conversation

@MarTrepodi

Copy link
Copy Markdown
Collaborator

Description

Adds datacron support to StatCalc: given one of a player's datacrons, each character gains a datacron stat 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 own datacron collection and raises KeyError if it is not there.
  • calc_roster_stats(units, datacron) and calc_char_stats(unit, datacron) take the datacron object.
  • StatCalcAsync.acalc_player_stats, acalc_roster_stats and acalc_char_stats pass the same arguments through.

How the contribution is resolved:

  • The bucket sits beside final and is never summed into it. It is the last link of the percent-conversion chain, so final + datacron is correct for every stat, including non-linear percentage stats such as Armor and Resistance.
  • Affixes are gated on the unit's gear tier and relic tier. A unit with no relic still gets the affixes that need none. Ability affixes are skipped.
  • Percent affixes expand onto their target stats through the same mapping the mod path uses, now shared from StatCalc/_datacron.py. They resolve against base plus gear, without mods.
  • A stat's affix percentages are summed, then rounded to the two decimals the datacron card shows. That is what values read from the game match.
  • Ships get no bucket and their stats are unchanged.

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 async calc_datacron_stats.py examples and a section in docs/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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Performance improvement
  • Documentation
  • Tests
  • CI / build / dependencies

Checklist

  • This PR targets the develop branch (only release PRs target main)
  • My commits follow the Conventional Commits / Angular convention (feat:, fix:, refactor:, etc.) — they become the changelog
  • I have not edited CHANGELOG.md by hand (it is generated from commit messages)
  • I have added/updated docstrings with type hints for any new or changed public methods
  • I have updated the docs (README.md, docs/, examples/) if user-facing behavior changed
  • I have added unit tests that cover my changes (mocked, not requiring a live comlink service)
  • Tests pass (uv run pytest tests/)
  • Ruff linter and formatter pass (uv run ruff check src/ tests/ and uv run ruff format --check src/ tests/)
  • Type check passes (uv run ty check src/swgoh_comlink/)
  • I have not bundled unrelated changes in this PR

Testing

  • uv run pytest tests/: 2057 passed, 31 skipped. Includes the new tests/statcalc/test_datacron.py, the golden-fixture test and the acalc_* 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/ and uv run python .github/scripts/unasync.py --check: pass.
  • Ran both examples/*/calc_datacron_stats.py against 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 + datacron at the precision the game displays. If it fails, the implementation is what should change, not the fixture.

🤖 Generated with Claude Code

MarTrepodi and others added 3 commits November 9, 2026 13:58
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>
@github-actions github-actions Bot added documentation Improvements or additions to documentation code testing labels Nov 9, 2026
@MarTrepodi
MarTrepodi merged commit c9bd8bc into develop Nov 10, 2026
12 checks passed
@MarTrepodi
MarTrepodi deleted the feat/datacron-statcalc branch November 10, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code documentation Improvements or additions to documentation testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant