feat:优化代码

This commit is contained in:
2026-06-04 11:03:35 +08:00
parent bb3ad71d21
commit 060de9494f
4 changed files with 262 additions and 60 deletions
+25 -15
View File
@@ -19,6 +19,18 @@ def _identity(value: Any) -> Any:
return value
@cache
def _load_custom_cn() -> list[dict[str, Any]]:
with (OPENAPI_DIR / 'custom_cn.json').open(encoding='utf-8') as f:
return json.load(f)
@cache
def _load_skill_detail(prefix: str) -> dict[str, Any]:
with (OPENAPI_DIR / 'data' / f'{prefix}.json').open(encoding='utf-8') as f:
return json.load(f)
@cache
def _get_skill_data_suffixes(skill_class: type) -> tuple[str, ...]:
return tuple(key.replace('data', '') for key in dir(skill_class) if key.startswith('data') and not key.startswith('plus'))
@@ -41,15 +53,9 @@ def get_data(prefix: str, key: int | str, func: Callable[[Any], Any] = _identity
jobGrow = prefix_parts[1]
skill = prefix_parts[-1]
def get_custom_cn():
with (OPENAPI_DIR / 'custom_cn.json').open(encoding='utf-8') as f:
custom_cn = json.load(f)
return custom_cn
def get_skill_info():
with (OPENAPI_DIR / 'data' / f'{prefix}.json').open(encoding='utf-8') as f:
skill_data = json.load(f)
custom_cn = get_redis_info(redis, 'dcalc:custom_cn', get_custom_cn, without_gzip=True)
skill_data = _load_skill_detail(prefix)
custom_cn = get_redis_info(redis, 'dcalc:custom_cn', _load_custom_cn, without_gzip=True)
try:
if isinstance(key, int):
data = [0] + [row["optionValue"].get("value" + str(key+1), 0) for row in skill_data["levelInfo"]["rows"]]
@@ -235,15 +241,19 @@ class Skill:
value = self.get_data_value(data, new) / ratio - self.get_data_value(data, old) / ratio
self.char.SetStatus(**{type[2:]: value})
else:
if skills == '*':
skills = self.char.GetSkillNames('all', True)
exceptSkills = set(exceptSkills)
for name in skills:
if name in exceptSkills:
continue
skill = self.char.GetSkillByName(name)
if skill is not None:
if skills == '*':
for skill in self.char.GetSkills('all', True):
if skill.name in exceptSkills:
continue
self.update_skill_attribute(skill, type, old, new, data, ratio, weapon, weapon_type, weapon_options)
else:
for name in skills:
if name in exceptSkills:
continue
skill = self.char.GetSkillByName(name)
if skill is not None:
self.update_skill_attribute(skill, type, old, new, data, ratio, weapon, weapon_type, weapon_options)
except Exception as e:
# print(f"Error applying association {type} for skill {self.name}: {e}")
raise e