条件系统
Attribute 条件文件位于 conditions/*.yml。条件组可用于装备限制、配方限制、技能限制和其他模块的业务判断。默认条件示例中部分可能是 enabled: false,需要根据服务器需求手动开启。
条件组字段
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | boolean | true | 是否启用该条件组。 |
source_id | string | — | 条件来源或业务标识。 |
condition.type | string | all_of | 条件组合方式。 |
condition.required_count | integer | 1 | 当 condition.type 为 at_least 或 exactly 时,需要满足的条件数量。 |
condition.invalid_as_failure | boolean | true | 条件配置异常或解析失败时是否视为不通过。 |
condition.entries | list | [] | 条件条目列表。 |
condition.type 完整枚举
| 值 | 说明 |
|---|---|
all_of | 全部条件满足才通过。 |
any_of | 任意一个条件满足即通过。 |
at_least | 满足至少 required_count 个条件。 |
exactly | 恰好满足 required_count 个条件。 |
none_of | 全部条件不满足才通过。 |
条件条目类型
| 类型 | 说明 |
|---|---|
pdc_meta | 检查 payload 中 meta 字段的值。 |
lore_regex | 通过正则匹配物品 Lore。 |
pdc_attribute | 检查 payload 中某个属性的数值。 |
source_id | 检查 payload 的 source_id 是否匹配。 |
pdc_meta 条目字段
| 字段 | 说明 |
|---|---|
type | pdc_meta |
key | 要检查的 meta key。 |
condition | 比较表达式,支持占位符和运算符。 |
lore_regex 条目字段
| 字段 | 说明 |
|---|---|
type | lore_regex |
pattern | 正则表达式。 |
require_match | 是否要求匹配成功(true 表示必须匹配到)。 |
pdc_attribute 条目字段
| 字段 | 说明 |
|---|---|
type | pdc_attribute |
key | 属性 ID。 |
condition | 比较表达式。 |
source_id 条目字段
| 字段 | 说明 |
|---|---|
type | source_id |
condition | 比较表达式,检查 payload 的 source_id。 |
条件表达式内置变量
在 condition 字段中可以使用以下变量:
| 变量 | 说明 |
|---|---|
%value% | 当前字段值(pdc_meta 的 key 对应值,或 pdc_attribute 的属性值)。 |
$0、$1、$2... | 正则捕获组(lore_regex 类型中可用)。 |
%source_meta_<key>% | payload meta 中指定 key 的值。 |
%source_attribute_<key>% | payload attributes 中指定属性的值。 |
%source_id% | payload 的 source_id。 |
%player_name% | 玩家名称。 |
%player_level% | 玩家经验等级。 |
如果安装了 PlaceholderAPI,所有 PAPI 占位符也可在条件表达式中使用。
示例:PDC meta 条件
yaml
enabled: true
source_id: forge
condition:
type: all_of
invalid_as_failure: true
entries:
- type: pdc_meta
key: required_level
condition: '%value% <= %player_level%'示例:属性值条件
yaml
enabled: true
source_id: equipment_check
condition:
type: all_of
entries:
- type: pdc_attribute
key: physical_attack
condition: '%value% >= 50'示例:来源匹配条件
yaml
enabled: true
source_id: strengthen
condition:
type: all_of
entries:
- type: source_id
condition: '%source_id% == "strengthen"'示例:Lore 正则条件
yaml
enabled: true
source_id: legacy_weapon
condition:
type: any_of
invalid_as_failure: true
entries:
- type: lore_regex
pattern: '.*武器等级: (\d+).*'
require_match: true
condition: '$1 >= 20'示例:至少满足 N 个条件
yaml
enabled: true
source_id: multi_check
condition:
type: at_least
required_count: 2
entries:
- type: pdc_meta
key: enchant_level
condition: '%value% >= 3'
- type: pdc_meta
key: quality
condition: '%value% == "epic"'
- type: pdc_attribute
key: physical_attack
condition: '%value% >= 100'内置条件文件
默认生成的条件文件:
| 文件 | source_id | 说明 |
|---|---|---|
strengthen.yml | strengthen | 强化来源,entries 为空,无条件通过。 |
forge.yml | forge | 锻造来源,检查 required_level <= %player_level%。 |
emakiitem.yml | emakiitem | 物品来源,把 condition_expressions 的值当作表达式执行;require_match: false 表示该 key 不存在时跳过而非失败。 |
default_bind.yml | gem_bind | 绑定检查 bound_player == %player_name%。默认禁用。 |
default_equipment_level.yml | gem_equipment_level | 用 lore_regex 匹配装备等级需求并与 %player_level% 比较。默认禁用。 |
改完条件文件后先执行 /ea lint,可在重载前发现 schema 问题(缺少 source_id、不支持的 checks 字段、非法条件类型、缺少 key / pattern、无效正则等)。