diff --git a/docs/api/helpers.md b/docs/api/helpers.md index 7b48679..9fe80b4 100644 --- a/docs/api/helpers.md +++ b/docs/api/helpers.md @@ -64,12 +64,14 @@ in about 2.4 seconds, versus about 147 MB in about 12.5 seconds for `ABILITY_DECISION_TREE`. Bitwise OR (`|`) is always safe. !!! note - Comlink accepts any `items` bitmask from 1 to 252 − 1, or `-1` + Comlink accepts any `items` bitmask from 1 to 253 − 1, or `-1` (`DataItems.ALL`) for everything, and rejects values outside that range with an - HTTP 400. Older Comlink releases had a bug in how CDN URLs were built that could + HTTP 400. `DataItems.OVERCHARGE` (252) and `DataItems.SEGMENT4`, which + includes it, need Comlink 4.6.0 or later; earlier releases accept only up to + 252 − 1. Older Comlink releases had a bug in how CDN URLs were built that could make some single-collection requests fail; upgrade Comlink if you see that. - On Python 3.15 and later, `int(DataItems.ALL)` is 252 − 1 rather than + On Python 3.15 and later, `int(DataItems.ALL)` is 253 − 1 rather than `-1`, because `enum` now turns a negative flag value into the union of every defined bit. The client still sends `-1` for `DataItems.ALL` and `items="ALL"`. diff --git a/docs/migration.md b/docs/migration.md index f059e87..888700a 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -284,7 +284,7 @@ in your own code (rather than referencing the constants by name), update them: | Constant | Old value | New value | |----------|-----------|-----------| | `DataItems.SEGMENT2` / `Constants.Segment2` | `68717379584` | `1125968624222208` | -| `DataItems.SEGMENT4` / `Constants.Segment4` | `281200098803712` | `3377424842620928` | +| `DataItems.SEGMENT4` / `Constants.Segment4` | `281200098803712` | `7881024469991424` | `SEGMENT1` (`2097151`) and `SEGMENT3` (`206158430208`) are unchanged. @@ -292,8 +292,8 @@ Code that references the constant by name (`DataItems.SEGMENT2`, `Constants.Segm `Constants.get("Segment2")`) picks up the new values automatically. **`get_game_data(items=...)` accepts any in-range bitmask.** Comlink accepts any -`items` value from 1 to 252 − 1, or `-1` (`DataItems.ALL`; the client sends -`-1` for it even on Python 3.15+, where `int(DataItems.ALL)` is 252 − 1) for everything, +`items` value from 1 to 253 − 1, or `-1` (`DataItems.ALL`; the client sends +`-1` for it even on Python 3.15+, where `int(DataItems.ALL)` is 253 − 1) for everything, so single collections (e.g. `DataItems.UNITS`), custom combinations and the `SEGMENT1`–`SEGMENT4` aggregates all work. Out-of-range values are rejected with an HTTP 400. Earlier versions of this guide advised against single-collection values; @@ -362,6 +362,14 @@ Upgrading from v2.8 to v2.9. rebuilt table is a copy: call `set_game_data` again after changing it. The same applies to a unit's `skills` list, which `set_game_data` indexes by skill id, and to `gpTables["modRarityLevelTierGP"]`, which it indexes by pips, level and tier. +- **`DataItems.OVERCHARGE` and a wider `SEGMENT4` need Comlink 4.6.0 or later.** Game + client 0.41 added the `Overcharge` bit (252). `DataItems.OVERCHARGE` requests + `overchargeDefinition`, `overchargeStatGroup` and `overchargePointMissionLookup` (each also + available under its own alias, e.g. `DataItems.OVERCHARGE_STAT_GROUP`), and + `Constants.get("Overcharge")` resolves it. The game folded the bit into segment 4, so + `DataItems.SEGMENT4` / `Constants.Segment4` changes from `3377424842620928` to + `7881024469991424`, and `items` accepts 1 to 253 − 1. A Comlink release + older than 4.6.0 rejects both values with an HTTP 400. ## Summary of changes @@ -382,5 +390,5 @@ Upgrading from v2.8 to v2.9. | GAC bracket scanning | Linear O(n) | Exponential probe + binary search O(log n) | | Migration checker | Not available | `swgoh-migrate` CLI / `python -m swgoh_comlink.migrate` | | `DataItems.SEGMENT2` value | `68717379584` | `1125968624222208` (server-aligned) | -| `DataItems.SEGMENT4` value | `281200098803712` | `3377424842620928` (server-aligned) | -| `get_game_data(items=)` values | Any bitmask | Any bitmask from 1 to 252 − 1, or `-1`; out of range → HTTP 400 | +| `DataItems.SEGMENT4` value | `281200098803712` | `7881024469991424` (server-aligned) | +| `get_game_data(items=)` values | Any bitmask | Any bitmask from 1 to 253 − 1, or `-1` | diff --git a/src/swgoh_comlink/helpers/_constants.py b/src/swgoh_comlink/helpers/_constants.py index 4f5b0af..0dd6453 100644 --- a/src/swgoh_comlink/helpers/_constants.py +++ b/src/swgoh_comlink/helpers/_constants.py @@ -84,6 +84,7 @@ "EpisodeDefinition": "EPISODE_DEFINITION", "EpisodeDefinitions": "EPISODE_DEFINITION", "EraDefinitions": "ERA_DEFINITION", + "Overcharge": "OVERCHARGE", "LinkingReward": "LINKING_REWARD", "AccountLinking": "LINKING_REWARD", } @@ -141,7 +142,7 @@ class Constants: Segment1 = 2097151 Segment2 = 1125968624222208 Segment3 = 206158430208 - Segment4 = 3377424842620928 + Segment4 = 7881024469991424 # Proxied stat data from _stat_data (backward compat) STAT_ENUMS = STAT_ENUMS diff --git a/src/swgoh_comlink/helpers/_data_items.py b/src/swgoh_comlink/helpers/_data_items.py index ec0bbb6..05eb9e2 100644 --- a/src/swgoh_comlink/helpers/_data_items.py +++ b/src/swgoh_comlink/helpers/_data_items.py @@ -27,10 +27,10 @@ class DataItems(IntFlag): `DataItems.CONQUEST_DEFINITION + DataItems.ARTIFACT_DEFINITION` requests `ABILITY_DECISION_TREE`, while `DataItems.CONQUEST_DEFINITION | DataItems.ARTIFACT_DEFINITION` correctly requests `CONQUEST`. - Comlink accepts any bitmask from 1 to 2**52 - 1, or -1 (`DataItems.ALL`) for everything. Values outside - that range are rejected with an HTTP 400. + Every collection bit lies below 2**53, so any combination of members is a bitmask from 1 to 2**53 - 1. + Use -1 (`DataItems.ALL`) for everything. - On Python 3.15 and later, `int(DataItems.ALL)` is 2**52 - 1 rather than -1, because `enum` now turns a + On Python 3.15 and later, `int(DataItems.ALL)` is 2**53 - 1 rather than -1, because `enum` now turns a negative flag value into the union of every defined bit. The client still sends -1 for `DataItems.ALL`. Some of the DataItems members are actually aliases for other members. For example, the `TABLE` member is an @@ -133,11 +133,15 @@ class DataItems(IntFlag): LINKING_REWARD = 562949953421312 LIGHTSPEED_TOKEN = 1125899906842624 ERA_DEFINITION = 2251799813685248 + OVERCHARGE = 4503599627370496 + OVERCHARGE_DEFINITION = OVERCHARGE + OVERCHARGE_STAT_GROUP = OVERCHARGE + OVERCHARGE_POINT_MISSION_LOOKUP = OVERCHARGE SEGMENT1 = 2097151 SEGMENT2 = 1125968624222208 SEGMENT3 = RELIC_TIER_DEFINITION + UNITS - SEGMENT4 = 3377424842620928 + SEGMENT4 = 7881024469991424 @classmethod def members(cls) -> KeysView[str]: diff --git a/src/swgoh_comlink/helpers/_stat_data.py b/src/swgoh_comlink/helpers/_stat_data.py index 46f4b3f..d54fcc3 100644 --- a/src/swgoh_comlink/helpers/_stat_data.py +++ b/src/swgoh_comlink/helpers/_stat_data.py @@ -637,6 +637,16 @@ "enum": "UNITSTATMASTERY", "tableKey": "MASTERY", }, + "62": { + "statId": 62, + "nameKey": "UNIT_STAT_CRITICAL_DAMAGE_NEGATE", + "descKey": "UNIT_STAT_DESCRIPTION_CRITICAL_DAMAGE_NEGATE", + "isDecimal": True, + "name": "Critical Defense", + "detailedName": "Critical Damage Negate", + "enum": "UNITSTATCRITICALDAMAGENEGATE", + "tableKey": "CRITICAL_DAMAGE_NEGATE", + }, } # --------------------------------------------------------------------------- @@ -756,10 +766,11 @@ 33: "EPISODE_PASS_PLUS", 34: "LIGHTSPEED_TOKEN", 35: "LOANED_UNIT_ERA_LEVEL_INCREASE", + 36: "OVERCHARGE_POINT", } """``ItemType`` number to enum member name: the ``type`` of a reward, preview or inventory item. -A snapshot of ``get_enums()["ItemType"]`` at game data 0.40.6, without ``ItemType_DEFAULT``. The game adds +A snapshot of ``get_enums()["ItemType"]`` at client schema 0.41.2115745, without ``ItemType_DEFAULT``. The game adds members over time: pass the live ``get_enums()`` response to :class:`ItemNames` to read the current table. """ @@ -811,13 +822,14 @@ 48: "EPISODE_CURRENCY", 49: "ERA_CURRENCY", 50: "ERA_UPGRADE_CURRENCY", + 51: "ARENA_CURRENCY", } """``CurrencyType`` number to enum member name. An inventory's ``currencyItem[].currency`` carries the number; a reward of ``ItemType`` ``CURRENCY`` carries the member name as its ``id``. -A snapshot of ``get_enums()["CurrencyType"]`` at game data 0.40.6, without ``CurrencyType_DEFAULT``. The +A snapshot of ``get_enums()["CurrencyType"]`` at client schema 0.41.2115745, without ``CurrencyType_DEFAULT``. The game adds currencies over time: pass the live ``get_enums()`` response to :class:`ItemNames` to read the current table. """ @@ -875,6 +887,7 @@ "EPISODE_CURRENCY": "Episode Currency", "ERA_CURRENCY": "Era Currency", "ERA_UPGRADE_CURRENCY": "Era Level Currency", + "ARENA_CURRENCY": "Arena Tokens", } """``CurrencyType`` member name to its English display name (see ``CURRENCY_TYPES``). diff --git a/tests/resources/enums-item-currency.json b/tests/resources/enums-item-currency.json index 744d1bf..29d0f15 100644 --- a/tests/resources/enums-item-currency.json +++ b/tests/resources/enums-item-currency.json @@ -1,5 +1,5 @@ { - "_comment": "Excerpt of get_enums() at game data 0.40.6: the groups ITEM_TYPES and CURRENCY_TYPES snapshot.", + "_comment": "Excerpt of get_enums() at client schema 0.41.2115745: the groups ITEM_TYPES and CURRENCY_TYPES snapshot.", "ItemType": { "ItemType_DEFAULT": 0, "EMPTY": 1, @@ -33,7 +33,8 @@ "EPISODE_PASS": 32, "EPISODE_PASS_PLUS": 33, "LIGHTSPEED_TOKEN": 34, - "LOANED_UNIT_ERA_LEVEL_INCREASE": 35 + "LOANED_UNIT_ERA_LEVEL_INCREASE": 35, + "OVERCHARGE_POINT": 36 }, "CurrencyType": { "CurrencyType_DEFAULT": 0, @@ -83,6 +84,7 @@ "GL_EVENT_CURRENCY": 47, "EPISODE_CURRENCY": 48, "ERA_CURRENCY": 49, - "ERA_UPGRADE_CURRENCY": 50 + "ERA_UPGRADE_CURRENCY": 50, + "ARENA_CURRENCY": 51 } } diff --git a/tests/unit/test_helpers.py b/tests/unit/test_helpers.py index 552e899..24dd570 100644 --- a/tests/unit/test_helpers.py +++ b/tests/unit/test_helpers.py @@ -2261,7 +2261,7 @@ def test_invalid_input_raises(self, args: tuple[Any, ...], match: str): def _recorded_enums() -> dict[str, Any]: - """The ItemType and CurrencyType groups of a real get_enums() response (game data 0.40.6).""" + """The ItemType and CurrencyType groups of a real get_enums() response (client schema 0.41.2115745).""" return json.loads((_RESOURCES / "enums-item-currency.json").read_text()) @@ -3321,13 +3321,15 @@ class TestConstants: ("name", "expected"), [ pytest.param("Segment1", str(Constants.Segment1), id="own-attribute"), - # Sent as -1 even on Python 3.15+, where int(DataItems.ALL) is 2**52 - 1. + # Sent as -1 even on Python 3.15+, where int(DataItems.ALL) is 2**53 - 1. pytest.param("ALL", "-1", id="all"), pytest.param("UnitDefinitions", "137438953472", id="legacy-name"), # 2**37, DataItems.UNITS pytest.param("UNITS", "137438953472", id="data-items-name"), # Aligned with the live GameDataItemsEnum from get_enums(). pytest.param("AbilityDecisionTrees", "1099511627776", id="ability-decision-trees"), pytest.param("EraDefinitions", "2251799813685248", id="era-definitions"), + pytest.param("Overcharge", "4503599627370496", id="overcharge"), # 2**52, client 0.41.2115745 + pytest.param("Segment4", "7881024469991424", id="segment4-includes-overcharge"), pytest.param("UBSUpdate", "2150109456", id="ubs-update"), pytest.param("EpisodeDefinitions", "281474976710656", id="episode-definitions-plural"), pytest.param("AccountLinking", "562949953421312", id="account-linking-alias"), @@ -3351,13 +3353,30 @@ def test_segment_values_match_server(self): 2097151, 1125968624222208, 206158430208, - 3377424842620928, + 7881024469991424, ) + assert DataItems.SEGMENT4 == 3377424842620928 | DataItems.OVERCHARGE def test_dataitems_members_present(self): assert DataItems.ABILITY_DECISION_TREE.value == 1099511627776 assert DataItems.ERA_DEFINITION.value == 2251799813685248 assert DataItems.UBS_UPDATE.value == 2150109456 + assert DataItems.OVERCHARGE.value == 4503599627370496 + + @pytest.mark.parametrize( + "alias", ["OVERCHARGE_DEFINITION", "OVERCHARGE_STAT_GROUP", "OVERCHARGE_POINT_MISSION_LOOKUP"] + ) + def test_overcharge_collections_share_one_bit(self, alias): + assert DataItems[alias] is DataItems.OVERCHARGE + + def test_critical_damage_negate_stat(self): + # UnitStat 62 arrived with client schema 0.41.2115745; the keys are the localization bundle's. + assert Constants.UNIT_STAT_ENUMS_MAP["62"] == { + "enum": "UNITSTATCRITICALDAMAGENEGATE", + "nameKey": "UNIT_STAT_CRITICAL_DAMAGE_NEGATE", + "tableKey": "CRITICAL_DAMAGE_NEGATE", + } + assert Constants.STATS["62"]["name"] == "Critical Defense" # ── _decorators ─────────────────────────────────────────────────────────