feat:完善技能代码匹配逻辑

This commit is contained in:
2026-06-28 01:09:00 +08:00
parent 8199275181
commit 879d765d51
+38 -22
View File
@@ -84,8 +84,7 @@ def decode_skill_hash(encoded: str) -> dict:
'skill_index': high[i],
'level': high[i + 1],
'skill_flag': low[i],
# 0 被动 1 主动
'skill_type': low[i + 1],
'level_flag': low[i + 1],
}
)
@@ -191,6 +190,25 @@ def _parse_section2(sec2: bytes):
return evolutions, enhancements, keybinds, remaining
def _resolve_openapi_skill_id(skill_index: int, level_flag: int, skill_name_map: dict[str, str]) -> int | None:
if level_flag:
high_skill_id = skill_index + 0x100
if str(high_skill_id) in skill_name_map:
return high_skill_id
if str(skill_index) in skill_name_map:
return skill_index
return None
def _resolve_section_skill_id(skill_index: int, skill_name_map: dict[str, str]) -> int | None:
high_skill_id = skill_index + 0x100
if str(high_skill_id) in skill_name_map:
return high_skill_id
if str(skill_index) in skill_name_map:
return skill_index
return None
def get_skill_tree_info(encoded: str) -> dict:
r = decode_skill_hash(encoded)
header = r['header']
@@ -219,20 +237,18 @@ def get_skill_tree_info(encoded: str) -> dict:
get_skill_name_map,
)
def get_skill_name(skill):
return skill_name_map.get(str(skill.id), skill.name)
character = createCharacter(className)
skillMap = {}
for index, i in enumerate(r['skills']):
skillIndex = i['skill_index']
skillUuids = skill_map.get(str(skillIndex), [None])
skills = []
for uuid in skillUuids:
skill = next((s for s in character.skills if s.uuid == uuid), None)
if skill is not None:
skills.append(skill)
skillMap[skillIndex] = skills
actualSkillId = _resolve_openapi_skill_id(skillIndex, i.get('level_flag'), skill_name_map)
skillName = skill_name_map.get(str(actualSkillId)) if actualSkillId is not None else None
skills = [skill for skill in character.skills if skill.name == skillName] if skillName else []
i['actual_skill_id'] = actualSkillId
i['skill_name'] = skillName
i['candidates'] = skills[0] if skills else None
if actualSkillId is not None:
skillMap[actualSkillId] = skills
if len(skills) == 0:
r['skills'][index] = None
for k, v in skillMap.items():
@@ -243,29 +259,29 @@ def get_skill_tree_info(encoded: str) -> dict:
for skill in r['skills']:
if skill is None:
continue
skillIndex = skill['skill_index']
candidates = skillMap.get(skillIndex, [])
candidates = skill.get('candidates', [])
skillName = skill.get('skill_name')
chosen = None
if len(candidates) == 1:
chosen = candidates[0]
elif len(candidates) > 1:
chosen = next((x for x in candidates if x.type == ('active' if skill['skill_type'] == 1 else 'passive')), None)
if candidates:
chosen = candidates
if chosen and skillLearn.get(str(chosen.id), {'lv': 0})['lv'] < skill['level']:
skillLearn[str(chosen.id)] = {
'lv': skill['level'],
'up': 0,
'vp': 0,
'name': get_skill_name(chosen),
'name': skillName or chosen.name,
}
# 处理进化
for evo in r['evolutions']:
for s in skillMap.get(evo['skill_index'], []):
actualSkillId = _resolve_section_skill_id(evo['skill_index'], skill_name_map)
for s in skillMap.get(actualSkillId, []):
if getattr(s, 'hasVP', False) and str(s.id) in skillLearn:
skillLearn[str(s.id)]['vp'] = evo['type']
# 处理强化
for enh in r['enhancements']:
for s in skillMap.get(enh['skill_index'], []):
actualSkillId = _resolve_section_skill_id(enh['skill_index'], skill_name_map)
for s in skillMap.get(actualSkillId, []):
if getattr(s, 'hasUP', False) and str(s.id) in skillLearn:
skillLearn[str(s.id)]['up'] = enh['type']
for i in character.skills:
@@ -274,7 +290,7 @@ def get_skill_tree_info(encoded: str) -> dict:
'lv': i.calculate_lv() if (i.learnLv in [50,85] or i.name == '基础精通') and str(i.id) else 0,
'up': 0,
'vp': 0,
'name': get_skill_name(i),
'name': i.name,
}
return {
"name": header['name'],