71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
import json
|
|
from functools import cache
|
|
|
|
from api.utils.openapi_data import openapi_locale_path
|
|
|
|
|
|
SKILL_TREE_WITH_DESC_SPECIAL_VERSION = 'skillTreeWithDescSpecial:v1'
|
|
SKILL_TREE_NAME_MAP_VERSION = 'skillTreeNameMap:v1'
|
|
SKILL_TREE_MAP_VERSION = 'skillTreeMap:v1'
|
|
|
|
|
|
@cache
|
|
def load_skill_tree_map(job_id: str, job_grow_id: str) -> dict[str, dict]:
|
|
"""按 OpenAPI 数字 ID 索引技能树,保留 autoLevel 等元数据。调用方只读。"""
|
|
skill_tree_path = openapi_locale_path('cn', job_id, job_grow_id, 'skill_tree.json')
|
|
with skill_tree_path.open(encoding='utf-8') as file:
|
|
skills_data = json.load(file)
|
|
return {
|
|
str(skill['id']): skill
|
|
for skill in skills_data
|
|
if skill.get('id') is not None and skill.get('name') is not None
|
|
}
|
|
|
|
|
|
@cache
|
|
def load_skill_tree_name_map(job_id: str, job_grow_id: str) -> dict[str, str]:
|
|
skill_tree_path = openapi_locale_path('cn', job_id, job_grow_id, 'skill_tree.json')
|
|
with skill_tree_path.open(encoding='utf-8') as file:
|
|
skills_data = json.load(file)
|
|
|
|
return {
|
|
str(skill['id']): skill['name']
|
|
for skill in skills_data
|
|
if skill.get('id') is not None and skill.get('name') is not None
|
|
}
|
|
|
|
|
|
def load_skill_tree_with_desc_special(job_id: str, job_grow_id: str) -> list[dict]:
|
|
skill_tree_path = openapi_locale_path('cn', job_id, job_grow_id, 'skill_tree.json')
|
|
detail_dir = skill_tree_path.parent / 'skillDetail'
|
|
|
|
with skill_tree_path.open(encoding='utf-8') as file:
|
|
skills_data = json.load(file)
|
|
|
|
for skill in skills_data:
|
|
skill_id = skill.get('skillId')
|
|
desc_special = None
|
|
if skill_id:
|
|
detail_path = detail_dir / f'{skill_id}.json'
|
|
if detail_path.exists():
|
|
with detail_path.open(encoding='utf-8') as file:
|
|
skill_data = json.load(file)
|
|
desc_special = skill_data.get('descSpecial')
|
|
optionDesc = skill_data.get('levelInfo', {}).get('optionDesc','')
|
|
if optionDesc and '压制力' in optionDesc and not any(desc in (desc_special or []) for desc in ['压制', '压制力']):
|
|
desc_special = (desc_special or []) + ['压制']
|
|
|
|
skill['descSpecial'] = desc_special
|
|
|
|
return skills_data
|
|
|
|
|
|
def filter_skill_tree_by_desc_special(skills_data: list[dict], desc_special: str) -> list[dict]:
|
|
if not desc_special:
|
|
return skills_data
|
|
return [
|
|
skill
|
|
for skill in skills_data
|
|
if any(desc_special in item for item in (skill.get('descSpecial') or []))
|
|
]
|