Files
dcalc/backend/api/utils/skill_tree.py
T
2026-06-12 13:41:55 +08:00

43 lines
1.5 KiB
Python

import json
from pathlib import Path
from database.connect import BACKEND_DIR
SKILL_TREE_WITH_DESC_SPECIAL_VERSION = 'skillTreeWithDescSpecial:v1'
def load_skill_tree_with_desc_special(job_id: str, job_grow_id: str) -> list[dict]:
skill_tree_path = BACKEND_DIR / 'openapi' / 'data' / job_id / job_grow_id / 'cn' / '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 []))
]