akef 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- akef/__init__.py +19 -0
- akef/cache.py +36 -0
- akef/client.py +578 -0
- akef/constants.py +17 -0
- akef/enka/__init__.py +13 -0
- akef/enka/build.py +175 -0
- akef/enka/client.py +60 -0
- akef/enka/gamedata.py +196 -0
- akef/enka/player.py +61 -0
- akef/enka/profile.py +337 -0
- akef/enka/skport.py +259 -0
- akef/enka/stats.py +307 -0
- akef/errors.py +54 -0
- akef/models/__init__.py +99 -0
- akef/models/account.py +78 -0
- akef/models/base.py +40 -0
- akef/models/card.py +664 -0
- akef/models/extra.py +207 -0
- akef/models/game.py +113 -0
- akef/models/pulls.py +149 -0
- akef/py.typed +0 -0
- akef/signing.py +20 -0
- akef/wiki.py +193 -0
- akef-0.3.0.dist-info/METADATA +289 -0
- akef-0.3.0.dist-info/RECORD +28 -0
- akef-0.3.0.dist-info/WHEEL +5 -0
- akef-0.3.0.dist-info/licenses/LICENSE +21 -0
- akef-0.3.0.dist-info/top_level.txt +1 -0
akef/enka/profile.py
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import re
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
|
|
8
|
+
import aiohttp
|
|
9
|
+
|
|
10
|
+
from akef.enka.build import (
|
|
11
|
+
ELEMENT,
|
|
12
|
+
PROFESSION,
|
|
13
|
+
PROMOTION,
|
|
14
|
+
SKILL_TYPE,
|
|
15
|
+
SLOT,
|
|
16
|
+
WEAPON_TYPE,
|
|
17
|
+
Build,
|
|
18
|
+
Essence,
|
|
19
|
+
EssenceTerm,
|
|
20
|
+
Gear,
|
|
21
|
+
Owner,
|
|
22
|
+
Skill,
|
|
23
|
+
Talent,
|
|
24
|
+
Weapon,
|
|
25
|
+
WeaponSkill,
|
|
26
|
+
amount,
|
|
27
|
+
element_icon,
|
|
28
|
+
)
|
|
29
|
+
from akef.errors import NetworkError, PlayerNotFound, ShowcaseEmpty
|
|
30
|
+
from akef.models.card import tier_unlocked
|
|
31
|
+
from akef.enka.gamedata import GameData, slot_of
|
|
32
|
+
from akef.enka.player import Badge, Player, Rostered
|
|
33
|
+
from akef.enka.stats import Loadout, calculate, gear_stats, require, skill_effect, weapon_skill_levels
|
|
34
|
+
|
|
35
|
+
ENKA = "https://enka.network"
|
|
36
|
+
API = ENKA + "/api/ef/uid/{}/"
|
|
37
|
+
ATTR_ICON = {39: "Str", 40: "Agi", 41: "Wisd", 42: "Will"}
|
|
38
|
+
ATTR_NAME = {39: "Strength", 40: "Agility", 41: "Intellect", 42: "Will"}
|
|
39
|
+
SKILL_ORDER = ("dispNormalAttackSkill", "normalSkill", "comboSkill", "ultimateSkill")
|
|
40
|
+
SLOT_ORDER = {"body": 0, "hand": 1, "edc": 2}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass
|
|
44
|
+
class EnkaProfile:
|
|
45
|
+
owner: Owner
|
|
46
|
+
builds: list[Build] = field(default_factory=list)
|
|
47
|
+
signature: str = ""
|
|
48
|
+
ttl: int = 0
|
|
49
|
+
raw: dict = field(default_factory=dict, repr=False)
|
|
50
|
+
player: Player | None = None
|
|
51
|
+
|
|
52
|
+
def build(self, name: str) -> Build | None:
|
|
53
|
+
wanted = name.lower()
|
|
54
|
+
return next((b for b in self.builds if b.name.lower() == wanted or b.id == name), None)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def asset(path: str) -> str:
|
|
58
|
+
if not path:
|
|
59
|
+
return ""
|
|
60
|
+
if path.startswith("http"):
|
|
61
|
+
return path
|
|
62
|
+
if not path.startswith("/"):
|
|
63
|
+
path = "/ui/ef/" + path + ("" if path.endswith((".png", ".webp")) else ".png")
|
|
64
|
+
return ENKA + path
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def talent_icon(path: str) -> str:
|
|
68
|
+
# enka's table says /ui/ef/icon_talent_x.png but the file is served from skillicon/
|
|
69
|
+
if path.startswith("/ui/ef/icon_talent_"):
|
|
70
|
+
path = path.replace("/ui/ef/", "/ui/ef/skillicon/", 1)
|
|
71
|
+
return asset(path)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def item_icon(path: str) -> str:
|
|
75
|
+
# weapon and essence art lives under itemicon/ on enka's cdn
|
|
76
|
+
if "/itemicon/" not in path:
|
|
77
|
+
path = path.replace("/ui/ef/", "/ui/ef/itemicon/", 1)
|
|
78
|
+
return asset(path)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
async def fetch_player(uid: int | str, *, session: aiohttp.ClientSession | None = None, timeout: float = 20) -> dict:
|
|
82
|
+
own = session is None
|
|
83
|
+
session = session or aiohttp.ClientSession(
|
|
84
|
+
timeout=aiohttp.ClientTimeout(total=timeout), headers={"User-Agent": "akef"}
|
|
85
|
+
)
|
|
86
|
+
try:
|
|
87
|
+
async with session.get(API.format(uid)) as resp:
|
|
88
|
+
if resp.status in (400, 404):
|
|
89
|
+
raise PlayerNotFound(f"Enka doesn't know UID {uid}")
|
|
90
|
+
if resp.status == 424:
|
|
91
|
+
raise NetworkError("Endfield's servers are under maintenance, try again later")
|
|
92
|
+
if resp.status == 429:
|
|
93
|
+
raise NetworkError("Enka is rate limiting us, slow down a little")
|
|
94
|
+
if resp.status != 200:
|
|
95
|
+
raise NetworkError(f"Enka returned http {resp.status}")
|
|
96
|
+
return await resp.json(content_type=None)
|
|
97
|
+
except (aiohttp.ClientError, asyncio.TimeoutError) as exc:
|
|
98
|
+
raise NetworkError(f"couldn't reach Enka: {exc.__class__.__name__}") from exc
|
|
99
|
+
finally:
|
|
100
|
+
if own:
|
|
101
|
+
await session.close()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _skill_name(name: str) -> str:
|
|
105
|
+
return re.sub(r"\s*\[[A-Z]\]$", "", name.split(":")[0]).strip()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
async def _weapon(data: GameData, raw: dict, avatar: dict) -> tuple[Weapon, dict, list[int]]:
|
|
109
|
+
key = str(raw["templateId"])
|
|
110
|
+
excel = require(data.weapons.get(key), "weapon", key)
|
|
111
|
+
tip = await data.tooltip("Weapons", key) or {}
|
|
112
|
+
gem = raw.get("attachedGem") or {}
|
|
113
|
+
terms = [(t["termNumId"], t["cost"]) for t in gem.get("terms") or []]
|
|
114
|
+
levels = weapon_skill_levels(data, excel, raw.get("refineLv", 0), raw.get("breakthroughLv", 0), terms)
|
|
115
|
+
|
|
116
|
+
essence = None
|
|
117
|
+
if gem:
|
|
118
|
+
skill_names = {}
|
|
119
|
+
for skill_id, skill in (tip.get("SkillMap") or {}).items():
|
|
120
|
+
skill_names[skill.get("TagId") or data.skills.get(skill_id, {}).get("TagId")] = _skill_name(skill["Name"])
|
|
121
|
+
names, title, badge = [], "", ""
|
|
122
|
+
for term_id, cost in terms:
|
|
123
|
+
term = data.gem_terms.get(str(term_id), {})
|
|
124
|
+
name = skill_names.get(term.get("TagId")) or term.get("TagId", "").replace("attr_", "").title()
|
|
125
|
+
names.append(EssenceTerm(name, cost))
|
|
126
|
+
if term.get("TermType") == 3:
|
|
127
|
+
title, badge = name, term.get("TagIcon", "")
|
|
128
|
+
badge = badge or term.get("TagIcon", "")
|
|
129
|
+
icon = data.gem_items.get(str(gem.get("templateId")), {}).get("Icon", "")
|
|
130
|
+
essence = Essence(title or "Essence", item_icon(icon) if icon else "", names, asset(badge) if badge else "")
|
|
131
|
+
|
|
132
|
+
skills = []
|
|
133
|
+
for skill_id, level in zip(excel["SkillList"], levels):
|
|
134
|
+
name = ((tip.get("SkillMap") or {}).get(str(skill_id)) or {}).get("Name", "")
|
|
135
|
+
stat, value = skill_effect(data, skill_id, level, avatar)
|
|
136
|
+
skills.append(WeaponSkill(_skill_name(name) or stat, level, stat, value))
|
|
137
|
+
|
|
138
|
+
weapon = Weapon(
|
|
139
|
+
name=tip.get("Name") or data.name(excel["NameHash"]),
|
|
140
|
+
rarity=excel["Rarity"],
|
|
141
|
+
icon=item_icon(excel["Icon"]),
|
|
142
|
+
level=raw.get("weaponLv", 1),
|
|
143
|
+
refine=raw.get("refineLv", 0),
|
|
144
|
+
breakthrough=raw.get("breakthroughLv", 0),
|
|
145
|
+
essence=essence,
|
|
146
|
+
skills=skills,
|
|
147
|
+
)
|
|
148
|
+
return weapon, excel, levels
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
async def _build(data: GameData, raw: dict, owner: Owner) -> Build:
|
|
152
|
+
key = str(raw["templateId"])
|
|
153
|
+
avatar = require(data.avatars.get(key), "operator", key)
|
|
154
|
+
tip = await data.tooltip("Avatars", key) or {}
|
|
155
|
+
sid = avatar["StrId"]
|
|
156
|
+
talent = raw.get("talent") or {}
|
|
157
|
+
attr_nodes = talent.get("attrNodes") or []
|
|
158
|
+
latest = (talent.get("latestPassiveSkillNodes") or []) + (talent.get("latestFactorySkillNodes") or [])
|
|
159
|
+
|
|
160
|
+
info = raw.get("skillInfo") or {}
|
|
161
|
+
levels = {s["skillId"]: s.get("skillLevel", 0) for s in info.get("levelInfo") or []}
|
|
162
|
+
skills = []
|
|
163
|
+
for slot in SKILL_ORDER:
|
|
164
|
+
skill_id = info.get(slot)
|
|
165
|
+
if not skill_id:
|
|
166
|
+
continue
|
|
167
|
+
excel_skill = avatar["SkillInfoMap"].get(skill_id, {})
|
|
168
|
+
tip_skill = (tip.get("SkillInfoMap") or {}).get(skill_id, {})
|
|
169
|
+
kind = SKILL_TYPE.get(skill_id.rsplit("_", 1)[-1], "")
|
|
170
|
+
skills.append(Skill(tip_skill.get("Name") or kind, kind, asset(excel_skill.get("Icon", "")), levels.get(skill_id, 0)))
|
|
171
|
+
|
|
172
|
+
talents = []
|
|
173
|
+
tip_nodes = tip.get("NodeSkillMap") or {}
|
|
174
|
+
nodes = avatar["AttributeNodes"]
|
|
175
|
+
if nodes:
|
|
176
|
+
key = next(iter(next(iter(nodes.values()))))
|
|
177
|
+
attr = int(key)
|
|
178
|
+
# some operators raise two stats per node by the same amount, the first one stands for both
|
|
179
|
+
total = sum((nodes.get(node) or {}).get(key, 0) for node in attr_nodes)
|
|
180
|
+
talents.append(Talent(ATTR_NAME.get(attr, ""), asset(f"/ui/ef/attributeicon/{ATTR_ICON.get(attr, 'Str')}.png"),
|
|
181
|
+
sum(node in nodes for node in attr_nodes), len(nodes), "attribute", value=amount(total)))
|
|
182
|
+
lines: dict[int, list[tuple[str, dict]]] = {}
|
|
183
|
+
for node, info_ in avatar["NodeSkillMap"].items():
|
|
184
|
+
lines.setdefault(info_["Index"], []).append((node, info_))
|
|
185
|
+
for index in sorted(lines):
|
|
186
|
+
tiers = sorted(lines[index], key=lambda kv: kv[1]["Level"])
|
|
187
|
+
level = max((info_["Level"] for node, info_ in tiers if tier_unlocked(node, latest)), default=0)
|
|
188
|
+
shown = tiers[max(level, 1) - 1]
|
|
189
|
+
name = (tip_nodes.get(shown[0]) or {}).get("Name", shown[0])
|
|
190
|
+
kind = "base" if shown[1].get("Type") == 5 else "combat"
|
|
191
|
+
talents.append(Talent(name, talent_icon(shown[1]["Icon"]), level, len(tiers), kind))
|
|
192
|
+
|
|
193
|
+
weapon = weapon_excel = None
|
|
194
|
+
weapon_levels: list[int] = []
|
|
195
|
+
if raw.get("weapon"):
|
|
196
|
+
weapon, weapon_excel, weapon_levels = await _weapon(data, raw["weapon"], avatar)
|
|
197
|
+
|
|
198
|
+
gear, loadout_gear = [], []
|
|
199
|
+
for entry in raw.get("equip") or []:
|
|
200
|
+
value = entry["value"]
|
|
201
|
+
item = require(data.items.get(str(value["templateid"])), "gear", value["templateid"])
|
|
202
|
+
enhance = {str(e["key"]): e["value"] for e in value.get("enhance") or []}
|
|
203
|
+
loadout_gear.append((item, enhance))
|
|
204
|
+
loadout_gear.sort(key=lambda pair: SLOT_ORDER.get(slot_of(pair[0]["Icon"]), 3))
|
|
205
|
+
|
|
206
|
+
loadout = Loadout(
|
|
207
|
+
avatar=avatar,
|
|
208
|
+
level=raw.get("level", 1),
|
|
209
|
+
potential=raw.get("potentialLevel", 0),
|
|
210
|
+
attr_nodes=attr_nodes,
|
|
211
|
+
passive_nodes=talent.get("latestPassiveSkillNodes") or [],
|
|
212
|
+
weapon=weapon_excel,
|
|
213
|
+
weapon_level=weapon.level if weapon else 1,
|
|
214
|
+
weapon_skill_levels=weapon_levels,
|
|
215
|
+
gear=loadout_gear,
|
|
216
|
+
)
|
|
217
|
+
for (item, _), stats in zip(loadout_gear, gear_stats(loadout)):
|
|
218
|
+
set_name = ""
|
|
219
|
+
if item["SuitId"]:
|
|
220
|
+
suit_tip = await data.tooltip("Suits", item["SuitId"]) or {}
|
|
221
|
+
set_name = suit_tip.get("Name") or data.name(data.suits.get(item["SuitId"], {}).get("NameHash"))
|
|
222
|
+
gear.append(Gear(SLOT.get(stats.slot, stats.slot), asset(item["Icon"]), item["Rarity"], set_name, stats.defense,
|
|
223
|
+
stats.lines))
|
|
224
|
+
|
|
225
|
+
return Build(
|
|
226
|
+
id=sid,
|
|
227
|
+
name=tip.get("Name") or data.name(avatar["NameHash"]),
|
|
228
|
+
rarity=avatar["Rarity"],
|
|
229
|
+
element=ELEMENT.get(avatar["Element"], avatar["Element"]),
|
|
230
|
+
profession=PROFESSION.get(avatar["Profession"], avatar["Profession"].title()),
|
|
231
|
+
weapon_type=WEAPON_TYPE.get(avatar["WeaponType"], avatar["WeaponType"]),
|
|
232
|
+
level=raw.get("level", 1),
|
|
233
|
+
promotion=PROMOTION.get(talent.get("latestBreakNode", ""), 0),
|
|
234
|
+
potential=raw.get("potentialLevel", 0),
|
|
235
|
+
art=asset(f"/ui/ef/splash/{raw.get('variantId') or sid}.webp"),
|
|
236
|
+
owner=owner,
|
|
237
|
+
skills=skills,
|
|
238
|
+
talents=talents,
|
|
239
|
+
weapon=weapon,
|
|
240
|
+
gear=gear,
|
|
241
|
+
stats=calculate(data, loadout),
|
|
242
|
+
source="enka",
|
|
243
|
+
element_icon=element_icon(avatar["Element"]),
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
async def profile_from_enka(data: GameData, raw: dict) -> EnkaProfile:
|
|
248
|
+
card = (raw.get("playerInfo") or {}).get("businessCard") or {}
|
|
249
|
+
owner = Owner(
|
|
250
|
+
name=card.get("name", "?"),
|
|
251
|
+
uid=str(raw.get("uid") or card.get("platformRoleId", "")),
|
|
252
|
+
level=card.get("adventureLevel", 0),
|
|
253
|
+
world_level=card.get("worldLevel", 0),
|
|
254
|
+
region=str(raw.get("region", "")).title(),
|
|
255
|
+
)
|
|
256
|
+
chars = (raw.get("playerInfo") or {}).get("charData") or []
|
|
257
|
+
if not chars and not card.get("charList"):
|
|
258
|
+
raise ShowcaseEmpty(f"{owner.name} has no operators in their showcase, or hid them")
|
|
259
|
+
builds = [await _build(data, c, owner) for c in chars]
|
|
260
|
+
player = await player_from_enka(data, raw, builds)
|
|
261
|
+
return EnkaProfile(owner, builds, card.get("signature", ""), raw.get("ttl", 0), raw, player)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
REGIONS = {"domain_1": "Valley IV", "domain_2": "Wuling"}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _medal(data: GameData, medal_id, level: int, plated: bool, slot: int = 0) -> Badge | None:
|
|
268
|
+
medal = data.medals.get(str(medal_id))
|
|
269
|
+
if not medal:
|
|
270
|
+
return None
|
|
271
|
+
icons = medal.get("IconByLevel") or {}
|
|
272
|
+
usable = sorted((int(k) for k in icons), reverse=True)
|
|
273
|
+
pick = next((k for k in usable if k <= level), usable[-1] if usable else None)
|
|
274
|
+
icon = icons[str(pick)] if pick else ""
|
|
275
|
+
if icon and plated:
|
|
276
|
+
icon = icon.replace(".png", "_plating.png")
|
|
277
|
+
return Badge(data.name(medal.get("NameHash")), asset(icon) if icon else "", level, plated, slot)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
async def player_from_enka(data: GameData, raw: dict, builds: list[Build]) -> Player:
|
|
281
|
+
card = (raw.get("playerInfo") or {}).get("businessCard") or {}
|
|
282
|
+
achieve = card.get("achievement") or {}
|
|
283
|
+
info = {m["achieveNumId"]: m for m in achieve.get("infoList") or []}
|
|
284
|
+
medals = []
|
|
285
|
+
for slot in sorted(achieve.get("display") or [], key=lambda s: s["key"]):
|
|
286
|
+
got = info.get(slot["value"], {})
|
|
287
|
+
badge = _medal(data, slot["value"], got.get("level", 1), got.get("isPlated", False), slot["key"])
|
|
288
|
+
if badge:
|
|
289
|
+
medals.append(badge)
|
|
290
|
+
|
|
291
|
+
by_id = {b.id: b for b in builds}
|
|
292
|
+
roster = []
|
|
293
|
+
for entry in card.get("charList") or []:
|
|
294
|
+
found = data.avatar_by_str.get(entry["templateId"])
|
|
295
|
+
if not found:
|
|
296
|
+
continue
|
|
297
|
+
key, avatar = found
|
|
298
|
+
tip = await data.tooltip("Avatars", key) or {}
|
|
299
|
+
build = by_id.get(entry["templateId"])
|
|
300
|
+
weapon = build.weapon if build else None
|
|
301
|
+
roster.append(Rostered(
|
|
302
|
+
name=tip.get("Name") or data.name(avatar["NameHash"]),
|
|
303
|
+
rarity=avatar["Rarity"],
|
|
304
|
+
element=ELEMENT.get(avatar["Element"], avatar["Element"]),
|
|
305
|
+
element_icon=element_icon(avatar["Element"]),
|
|
306
|
+
portrait=build.art if build else asset(f"/ui/ef/splash/{entry['templateId']}.webp"),
|
|
307
|
+
id=entry["templateId"],
|
|
308
|
+
level=entry.get("level", 0),
|
|
309
|
+
potential=entry.get("potentialLevel", 0),
|
|
310
|
+
promotion=build.promotion if build else None,
|
|
311
|
+
profession=PROFESSION.get(avatar["Profession"], avatar["Profession"].title()),
|
|
312
|
+
weapon_icon=weapon.icon if weapon else "",
|
|
313
|
+
weapon_rarity=weapon.rarity if weapon else 0,
|
|
314
|
+
))
|
|
315
|
+
|
|
316
|
+
stats = card.get("statistic") or {}
|
|
317
|
+
regions = [(REGIONS.get(d["domainId"], d["domainId"]), d.get("level", 0))
|
|
318
|
+
for d in (card.get("domainDev") or {}).get("domains") or []]
|
|
319
|
+
created = card.get("createTime")
|
|
320
|
+
return Player(
|
|
321
|
+
name=card.get("name", "?"),
|
|
322
|
+
uid=str(raw.get("uid") or card.get("platformRoleId", "")),
|
|
323
|
+
level=card.get("adventureLevel", 0),
|
|
324
|
+
world_level=card.get("worldLevel", 0),
|
|
325
|
+
region=str(raw.get("region", "")).title(),
|
|
326
|
+
avatar=asset((data.pfps.get(str(card.get("userAvatarId"))) or {}).get("Icon", "")),
|
|
327
|
+
namecard=asset((data.namecards.get(str(card.get("businessCardTopicId"))) or {}).get("Icon", "")),
|
|
328
|
+
signature=card.get("signature", ""),
|
|
329
|
+
created=datetime.fromtimestamp(created, tz=timezone.utc) if created else None,
|
|
330
|
+
operators_owned=stats.get("charNum", 0),
|
|
331
|
+
weapons_owned=stats.get("weaponNum", 0),
|
|
332
|
+
files=stats.get("docNum", 0),
|
|
333
|
+
medals=medals,
|
|
334
|
+
regions=regions,
|
|
335
|
+
roster=roster,
|
|
336
|
+
source="enka",
|
|
337
|
+
)
|
akef/enka/skport.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from akef.enka.build import (
|
|
6
|
+
ELEMENT,
|
|
7
|
+
PROFESSION,
|
|
8
|
+
WEAPON_TYPE,
|
|
9
|
+
Build,
|
|
10
|
+
Essence,
|
|
11
|
+
EssenceTerm,
|
|
12
|
+
Gear,
|
|
13
|
+
Owner,
|
|
14
|
+
Skill,
|
|
15
|
+
Tactical,
|
|
16
|
+
Talent,
|
|
17
|
+
Weapon,
|
|
18
|
+
WeaponSkill,
|
|
19
|
+
amount,
|
|
20
|
+
element_icon,
|
|
21
|
+
essence_base,
|
|
22
|
+
)
|
|
23
|
+
from akef.errors import MissingGameData
|
|
24
|
+
from akef.enka.gamedata import GameData
|
|
25
|
+
from akef.enka.player import Badge, Player, Rostered
|
|
26
|
+
from akef.enka.stats import DEF, MAIN, SUB, Loadout, calculate, gear_stats, skill_effect
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
GEAR_PROPS = {
|
|
30
|
+
"equip_attr_str": (39,),
|
|
31
|
+
"equip_attr_agi": (40,),
|
|
32
|
+
"equip_attr_wisd": (41,),
|
|
33
|
+
"equip_attr_will": (42,),
|
|
34
|
+
"equip_attr_max_hp": (1,),
|
|
35
|
+
"equip_attr_atk": (2,),
|
|
36
|
+
"equip_attr_critical_rate": (9,),
|
|
37
|
+
"equip_attr_normal_attack_damage_increase": (17,),
|
|
38
|
+
"equip_attr_ultimate_skill_damage_increase": (28,),
|
|
39
|
+
"equip_attr_heal_output_increase": (29,),
|
|
40
|
+
"equip_attr_normal_skill_damage_increase": (32,),
|
|
41
|
+
"equip_attr_combo_skill_damage_increase": (33,),
|
|
42
|
+
"equip_attr_ultimate_sp_gain_scalar": (44,),
|
|
43
|
+
"equip_attr_physical_damage_increase": (50,),
|
|
44
|
+
"equip_attr_damage_to_broken_unit_increase": (61,),
|
|
45
|
+
"equip_attr_physical_and_spellInfliction_enhance": (87,),
|
|
46
|
+
"equip_attr_cryst_and_pulse_damage_increase": (52, 53),
|
|
47
|
+
"equip_fire_and_natural_damage_increase": (51, 54),
|
|
48
|
+
"equip_spell_damage_increase": (51, 52, 53, 54),
|
|
49
|
+
"equip_all_skill_damage_increase": (28, 32, 33),
|
|
50
|
+
"equip_attr_all_damage_taken_scalar": (4, 5, 6, 7, 48, 60),
|
|
51
|
+
"equip_main": (MAIN,),
|
|
52
|
+
"equip_sub": (SUB,),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def avatar_entry(data: GameData, op) -> dict:
|
|
57
|
+
nodes = [t.id for t in op.char_data.ability_talents] + (op.talent.attr_nodes if op.talent else [])
|
|
58
|
+
for node in nodes:
|
|
59
|
+
found = data.avatar_by_str.get(node.rsplit("_", 1)[0])
|
|
60
|
+
if found:
|
|
61
|
+
return found[1]
|
|
62
|
+
raise MissingGameData("operator", op.name)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _gear_item(data: GameData, equip) -> dict:
|
|
66
|
+
d = equip.equip_data
|
|
67
|
+
suit = ""
|
|
68
|
+
if d.suit:
|
|
69
|
+
suit = data.suit_by_name.get(d.suit.name)
|
|
70
|
+
if suit is None:
|
|
71
|
+
raise MissingGameData("gear set", d.suit.name)
|
|
72
|
+
slot = d.type.key.replace("equip_type_", "")
|
|
73
|
+
rarity = int(d.rarity.key.rsplit("_", 1)[-1] or 0)
|
|
74
|
+
groups = [set(GEAR_PROPS.get(p, ())) for p in d.properties if p]
|
|
75
|
+
loose = None
|
|
76
|
+
for item in data.items_by_group.get((suit, slot, rarity), []):
|
|
77
|
+
mods = item["AttrModifiers"]
|
|
78
|
+
if mods[0]["AttrType"] != DEF or round(mods[0]["Values"][0]) != round(d.base_attr_value):
|
|
79
|
+
continue
|
|
80
|
+
ids = [m["AttrType"] for m in mods[1:]]
|
|
81
|
+
if sorted(ids) != sorted(i for g in groups for i in g):
|
|
82
|
+
continue
|
|
83
|
+
# pieces can share the same stats in a different order (int-heavy vs will-heavy gloves),
|
|
84
|
+
# skport keeps the game's order so walk both lists side by side
|
|
85
|
+
at, ordered = 0, True
|
|
86
|
+
for group in groups:
|
|
87
|
+
if set(ids[at:at + len(group)]) != group:
|
|
88
|
+
ordered = False
|
|
89
|
+
break
|
|
90
|
+
at += len(group)
|
|
91
|
+
if ordered:
|
|
92
|
+
return item
|
|
93
|
+
loose = loose or item
|
|
94
|
+
if loose is not None:
|
|
95
|
+
return loose
|
|
96
|
+
raise MissingGameData("gear", d.name)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _talents(op) -> list[Talent]:
|
|
100
|
+
d = op.char_data
|
|
101
|
+
out = []
|
|
102
|
+
nodes = sorted(d.ability_talents, key=lambda t: t.id)
|
|
103
|
+
if nodes:
|
|
104
|
+
got = [t for t in nodes if op.talent_unlocked(t.id)]
|
|
105
|
+
total = sum(float(m.group(1)) for t in got if (m := re.search(r"\+(\d+(?:\.\d+)?)", t.desc)))
|
|
106
|
+
out.append(Talent(nodes[0].name, nodes[0].icon_url, len(got), len(nodes), "attribute", nodes[0].locked_icon_url,
|
|
107
|
+
amount(total)))
|
|
108
|
+
for kind, group in (("combat", d.combat_talents), ("base", d.cultivation_talents)):
|
|
109
|
+
lines: dict[str, list] = {}
|
|
110
|
+
for t in sorted(group, key=lambda t: t.id):
|
|
111
|
+
lines.setdefault(t.id.rpartition("_")[0], []).append(t)
|
|
112
|
+
for tiers in lines.values():
|
|
113
|
+
level = sum(op.talent_unlocked(t.id) for t in tiers)
|
|
114
|
+
shown = tiers[max(level, 1) - 1]
|
|
115
|
+
out.append(Talent(shown.name, shown.icon_url, level, len(tiers), kind, shown.locked_icon_url))
|
|
116
|
+
return out
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def build_from_skport(data: GameData, card, op, *, stats: bool = True) -> Build:
|
|
120
|
+
base = card.base
|
|
121
|
+
owner = Owner(base.name, base.uid, base.level, base.world_level, base.server_name)
|
|
122
|
+
d = op.char_data
|
|
123
|
+
|
|
124
|
+
skills = [Skill(s.name, s.type.value, s.icon_url, op.skill_level(s.id)) for s in d.skills]
|
|
125
|
+
talents = _talents(op)
|
|
126
|
+
|
|
127
|
+
weapon = None
|
|
128
|
+
if op.weapon:
|
|
129
|
+
w = op.weapon
|
|
130
|
+
essence = None
|
|
131
|
+
if w.gem and w.gem.gem_data:
|
|
132
|
+
kind, _, effect = w.gem.name.replace("Â", "").partition("·")
|
|
133
|
+
gem = w.gem.gem_data
|
|
134
|
+
base = essence_base(gem.template_id)
|
|
135
|
+
# skport only sends the badge, the capsule under it comes from enka
|
|
136
|
+
terms = [EssenceTerm(t.name, t.cost) for t in w.gem.terms]
|
|
137
|
+
essence = Essence(effect or kind, base or gem.icon, terms, gem.icon if base else "")
|
|
138
|
+
weapon_skills = [WeaponSkill(_skill_name(s.name), s.level) for s in w.skills]
|
|
139
|
+
weapon = Weapon(w.name, w.rarity, w.weapon_data.icon_url, w.level, w.refine_level, w.breakthrough_level, essence,
|
|
140
|
+
weapon_skills)
|
|
141
|
+
|
|
142
|
+
tactical = None
|
|
143
|
+
if op.tactical_item:
|
|
144
|
+
tactical = Tactical(op.tactical_item.name, op.tactical_item.tactical_item_data.icon_url)
|
|
145
|
+
|
|
146
|
+
build = Build(
|
|
147
|
+
id=op.id,
|
|
148
|
+
name=op.name,
|
|
149
|
+
rarity=op.rarity,
|
|
150
|
+
element=element_of(d),
|
|
151
|
+
profession=english(d.profession, PROFESSION, str.upper),
|
|
152
|
+
weapon_type=english(d.weapon_type, WEAPON_TYPE, str.title),
|
|
153
|
+
level=op.level,
|
|
154
|
+
promotion=op.evolve_phase,
|
|
155
|
+
potential=op.potential_level,
|
|
156
|
+
art=d.illustration_url,
|
|
157
|
+
owner=owner,
|
|
158
|
+
skills=skills,
|
|
159
|
+
talents=talents,
|
|
160
|
+
weapon=weapon,
|
|
161
|
+
tactical=tactical,
|
|
162
|
+
source="skport",
|
|
163
|
+
element_icon=element_icon(element_of(d)),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if not stats:
|
|
167
|
+
build.gear = [Gear(e.equip_data.type.value, e.equip_data.icon_url, rarity_of(e),
|
|
168
|
+
e.equip_data.suit.name if e.equip_data.suit else "", e.equip_data.base_attr_value)
|
|
169
|
+
for e in op.equips]
|
|
170
|
+
return build
|
|
171
|
+
|
|
172
|
+
avatar = avatar_entry(data, op)
|
|
173
|
+
weapon_excel = None
|
|
174
|
+
if op.weapon:
|
|
175
|
+
found = data.weapon_by_name.get(op.weapon.name)
|
|
176
|
+
if found is None:
|
|
177
|
+
raise MissingGameData("weapon", op.weapon.name)
|
|
178
|
+
weapon_excel = found[1]
|
|
179
|
+
for skill, skill_id in zip(build.weapon.skills, weapon_excel["SkillList"]):
|
|
180
|
+
skill.stat, skill.value = skill_effect(data, skill_id, skill.level, avatar)
|
|
181
|
+
items = [(_gear_item(data, e), e.enhance) for e in op.equips]
|
|
182
|
+
loadout = Loadout(
|
|
183
|
+
avatar=avatar,
|
|
184
|
+
level=op.level,
|
|
185
|
+
potential=op.potential_level,
|
|
186
|
+
attr_nodes=op.talent.attr_nodes if op.talent else [],
|
|
187
|
+
passive_nodes=op.talent.latest_passive_skill_nodes if op.talent else [],
|
|
188
|
+
weapon=weapon_excel,
|
|
189
|
+
weapon_level=op.weapon.level if op.weapon else 1,
|
|
190
|
+
weapon_skill_levels=[s.level for s in op.weapon.skills] if op.weapon else [],
|
|
191
|
+
gear=items,
|
|
192
|
+
)
|
|
193
|
+
build.stats = calculate(data, loadout)
|
|
194
|
+
build.gear = [
|
|
195
|
+
Gear(e.equip_data.type.value, e.equip_data.icon_url, rarity_of(e),
|
|
196
|
+
e.equip_data.suit.name if e.equip_data.suit else "", g.defense, g.lines)
|
|
197
|
+
for e, g in zip(op.equips, gear_stats(loadout))
|
|
198
|
+
]
|
|
199
|
+
return build
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _skill_name(name: str) -> str:
|
|
203
|
+
return re.sub(r"\s*\[[A-Z]\]$", "", name.split(":")[0]).strip()
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def english(tag, table, case) -> str:
|
|
207
|
+
return table.get(case(tag.key.rsplit("_", 1)[-1]), tag.value)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def element_of(char_data) -> str:
|
|
211
|
+
return english(char_data.element, ELEMENT, str.title)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def rarity_of(equip) -> int:
|
|
215
|
+
return int(equip.equip_data.rarity.key.rsplit("_", 1)[-1] or 0)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def player_from_skport(card) -> Player:
|
|
219
|
+
base = card.base
|
|
220
|
+
picked = [c.id for c in card.showcased]
|
|
221
|
+
rest = sorted((c for c in card.chars if c.id not in picked),
|
|
222
|
+
key=lambda c: (-c.rarity, -c.level, -c.evolve_phase, -c.potential_level, c.name))
|
|
223
|
+
roster = []
|
|
224
|
+
for op in [*card.showcased, *rest]:
|
|
225
|
+
weapon = op.weapon
|
|
226
|
+
roster.append(Rostered(
|
|
227
|
+
name=op.name,
|
|
228
|
+
rarity=op.rarity,
|
|
229
|
+
element=element_of(op.char_data),
|
|
230
|
+
element_icon=element_icon(element_of(op.char_data)),
|
|
231
|
+
portrait=op.char_data.avatar_rt_url or op.char_data.avatar_sq_url,
|
|
232
|
+
level=op.level,
|
|
233
|
+
potential=op.potential_level,
|
|
234
|
+
promotion=op.evolve_phase,
|
|
235
|
+
profession=english(op.char_data.profession, PROFESSION, str.upper),
|
|
236
|
+
weapon_icon=weapon.weapon_data.icon_url if weapon else "",
|
|
237
|
+
weapon_rarity=weapon.rarity if weapon else 0,
|
|
238
|
+
))
|
|
239
|
+
by_id = {m.achievement_data.id: m for m in card.achieve.medals}
|
|
240
|
+
medals = [Badge(m.name, m.icon, m.level, m.is_plated, int(slot))
|
|
241
|
+
for slot, medal_id in card.achieve.display.items() if (m := by_id.get(medal_id))]
|
|
242
|
+
medals.sort(key=lambda b: b.slot)
|
|
243
|
+
return Player(
|
|
244
|
+
name=base.name,
|
|
245
|
+
uid=base.uid,
|
|
246
|
+
level=base.level,
|
|
247
|
+
world_level=base.world_level,
|
|
248
|
+
region=base.server_name,
|
|
249
|
+
avatar=base.avatar_url,
|
|
250
|
+
mission=base.main_mission.description,
|
|
251
|
+
created=base.create_time,
|
|
252
|
+
operators_owned=base.char_num,
|
|
253
|
+
weapons_owned=base.weapon_num,
|
|
254
|
+
files=base.doc_num,
|
|
255
|
+
medals=medals,
|
|
256
|
+
regions=[(d.name, d.level) for d in card.domain],
|
|
257
|
+
roster=roster,
|
|
258
|
+
source="skport",
|
|
259
|
+
)
|