feat:优化职业技能关联实现

This commit is contained in:
2026-10-13 15:57:28 +08:00
parent 15c3bff467
commit 7dc5f4cde5
20 changed files with 875 additions and 161 deletions
+71 -12
View File
@@ -8,6 +8,7 @@ from .formula import 武器冷却惩罚
from database.connect import get_redis_client
from api.core.Redis import get_redis_info
from api.utils.openapi_data import OPENAPI_CUSTOM_CN_PATH, logical_skill_detail_path
from .skill_effects import CHARACTER_ATTRIBUTES, INPUT_ATTRIBUTES
if TYPE_CHECKING:
from core.basic.character import Character
@@ -84,9 +85,21 @@ def get_data(prefix: str, key: int | str, func: Callable[[Any], Any] = _identity
class Skill:
def __setattr__(self, name, value):
char = self.__dict__.get('char')
engine = getattr(char, 'skill_effects', None)
if name != 'lv' and name in INPUT_ATTRIBUTES and engine is not None and engine.owns(self) and not engine.resolving:
engine.set_attribute(self, name, value)
else:
object.__setattr__(self, name, value)
name: str = ''
"""技能名称"""
_lv: int = 0
level_source: str | None = None
"""共享等级的源技能;目标不独立加级,也不使用自身 maxLv 截断。"""
association_source: bool | None = None
"""共享等级技能默认仅复用等级;需要独立提供关联效果时显式开启。"""
id: int = 0
"""技能ID"""
icon: str = '$char/$uuid'
@@ -131,15 +144,15 @@ class Skill:
cdRecover: float = 1
"""技能冷却恢复"""
associate: list = []
"""关联技能
type: 关联类型 *乘算 +加算 =直接赋值 $角色属性 默认'*skillDamage'
e.g.
*skillDamage 乘算技能伤害
*cdReduce 乘算技能冷却缩减
$*PATK 乘算角色物理攻击
~直接走type对应的函数名称 传参为old,new,data,skills,exceptSkills
skills: 关联技能 默认 '*'
exceptSkills: 例外技能 默认[]
"""关联声明;维护示例和扩展边界见 core/basic/skill_effects.py 文件顶部说明。
type 默认 '*skillDamage':*乘算、+加算、=覆盖;$*PAtkP 等作用于角色。
skills 默认 '*',表示所有伤害技能;显式列表使用技能名称,可指定被动技能。
exceptSkills 默认 [];weapon 默认职业武器选项;precondition() 控制前置条件。
data 按来源等级取值;ratio 是数据除数,默认 100,与技能的 ratio 属性不同。
+lv 的整数加级通常设置 ratio=1;=覆盖直接使用 data 值,不除以 ratio。
动态 effect 以 (0, 最终等级) 多次收集,只构造声明并调用 super().effect。
自定义 type 方法仍有兼容入口,但直接修改目标会绕过贡献收集,新增规则勿照搬。
"""
mode: list[str] = ['']
currentMode: str = ''
@@ -159,6 +172,10 @@ class Skill:
def __init__(self, char):
self.char = char
# Shared-level display skills override the setter with a no-op. They
# did not apply their own associations in the original calculation.
if self.association_source is None:
self.association_source = self.level_source is None and type(self).lv.fset is Skill.lv.fset
self.id = self._extract_id()
self.icon = self._generate_icon()
if self.line is None:
@@ -199,11 +216,22 @@ class Skill:
@property
def lv(self):
"""技能等级"""
engine = getattr(self.char, 'skill_effects', None)
if engine is not None and engine.owns(self):
engine.read_level(self)
elif self.level_source is not None:
return self.char.GetSkillByName(self.level_source).lv
return self._lv
@lv.setter
def lv(self, value):
value = int(min(self.maxLv, value))
if self.level_source is not None:
return
engine = getattr(self.char, 'skill_effects', None)
if engine is not None and engine.owns(self) and not engine.resolving:
engine.set_level(self, max(0, int(value)))
return
value = int(max(0, min(self.maxLv, value)))
if self._lv != value:
self.effect(self._lv, value)
self._lv = value
@@ -238,10 +266,20 @@ class Skill:
value = (1 - self.get_data_value(data, new) / ratio) / (1 - self.get_data_value(data, old) / ratio)
else:
value = (1 + self.get_data_value(data, new) / ratio) / (1 + self.get_data_value(data, old) / ratio)
self.char.SetStatus(**{type[2:]: value})
engine = getattr(self.char, 'skill_effects', None)
if engine is not None and engine.collecting is self:
if type[2:] in CHARACTER_ATTRIBUTES:
engine.record(self, self.char, type[2:], '*', value)
else:
self.char.SetStatus(**{type[2:]: value})
elif type.startswith('$+'):
value = self.get_data_value(data, new) / ratio - self.get_data_value(data, old) / ratio
self.char.SetStatus(**{type[2:]: value})
engine = getattr(self.char, 'skill_effects', None)
if engine is not None and engine.collecting is self:
if type[2:] in CHARACTER_ATTRIBUTES:
engine.record(self, self.char, type[2:], '+', value)
else:
self.char.SetStatus(**{type[2:]: value})
else:
exceptSkills = set(exceptSkills)
if skills == '*':
@@ -256,6 +294,10 @@ class Skill:
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)
else:
engine = getattr(self.char, 'skill_effects', None)
if engine is not None and engine.collecting is self:
engine.missing_target(self, name)
except Exception as e:
# print(f"Error applying association {type} for skill {self.name}: {e}")
raise e
@@ -265,6 +307,23 @@ class Skill:
return
old_value = self.get_data_value(data, old)
new_value = self.get_data_value(data, new)
engine = getattr(self.char, 'skill_effects', None)
if engine is not None and engine.collecting is self:
if type[1:] == 'lv' and skill.level_source is not None:
return
if type.startswith('*'):
if 'cdReduce' in type or 'cdRatio' in type:
value = (1 - new_value / ratio) / (1 - old_value / ratio)
else:
value = (1 + new_value / ratio) / (1 + old_value / ratio)
elif type.startswith('+'):
if type[1:] == 'lv' and not engine.is_learned(skill):
return
value = (new_value - old_value) / ratio
else:
value = new_value
engine.record(self, skill, type[1:], type[0], value)
return
if type.startswith('*'):
if 'cdReduce' in type or type == 'cd' or 'cdRatio' in type:
setattr(skill, type[1:], getattr(skill, type[1:]) * (1 - new_value / ratio) / (1 - old_value / ratio))