主题
实战:让自定义元素真正参与战斗
这篇教程从零开始,完整演示如何新增一个"雷电"元素并让它参与战斗结算。
这篇重点是新增伤害通道与显示定义,不涉及自定义 Stage 或自定义 Pipeline 顺序。
目标
- 玩家装备带有"雷电伤害"的武器
- 近战攻击时自动产出雷电伤害通道
- 雷电伤害使用百分比减伤公式
- 支持雷电穿透
- 技能也能打出雷电伤害
第一步:注册属性
在 attributes/element.yml 中追加:
yml
thunder_damage:
display: "&e雷电伤害"
names:
- "雷电伤害"
- "雷伤"
read-pattern: default
default: 0.0
min: 0.0
max: 99999.0
channel: thunder
channel-role: damage
thunder_resistance:
display: "&e雷电抗性"
names:
- "雷电抗性"
- "雷抗"
read-pattern: default
default: 0.0
min: 0.0
max: 99999.0
channel: thunder
channel-role: resist
thunder_penetration_flat:
display: "&e雷电固定穿透"
names:
- "雷电固定穿透"
- "雷穿值"
read-pattern: default
default: 0.0
min: 0.0
max: 99999.0
channel: thunder
channel-role: penetration_flat
thunder_penetration_rate:
display: "&e雷电百分比穿透"
names:
- "雷电百分比穿透"
- "雷穿率"
read-pattern: default
default: 0.0
min: 0.0
max: 100.0
channel: thunder
channel-role: penetration_rate关键点:每个属性都声明了 channel: thunder 和对应的 channel-role。这样 collect_channels Stage 就能自动发现 thunder 通道。
第二步:定义伤害类型
新建 damage_types/thunder.yml:
yml
id: thunder
display-order: 20
display-name: "雷电伤害"
display: "{color}{value}"
color: "&e"
special-color: "&e&l"
description: "雷电伤害"
# 雷电使用百分比减伤(不同于物理的固定减伤)
resist-formula: |-
effective_resist = max(0, channel_resist - channel_penetration_flat) * (1 - channel_penetration_rate / 100)
return max(0, channel_value * (1 - min(effective_resist, 100) / 100))这里 resist-formula 是可选的。如果不配,会使用 stages/resist.yml 的默认公式。配了之后,thunder 通道在 per_channel 减伤时会优先使用这个公式。
第三步:重载并验证
text
/hnattr reload确认没有报错后,开始验证。
验证属性注册
text
/hnattr trace thunder_damage
/hnattr trace thunder_resistance应该能看到属性已注册,默认值为 0。
做测试装备
武器 Lore:
text
攻击力: 100
雷电伤害: 80
雷电固定穿透: 10护甲 Lore:
text
防御力: 30
雷电抗性: 40确认读取
text
/hnattr inspect
/hnattr lookup确认 thunder_damage、thunder_resistance、thunder_penetration_flat 都有正确的值。
第四步:实际攻击测试
装备好武器后,近战攻击一个穿了护甲的目标。
预期结果:
- 物理通道:
100 - 30 = 70(固定减伤) - 雷电通道:有效抗性 =
40 - 10 = 30,伤害 =80 * (1 - 30/100) = 56(百分比减伤) - 总伤害:
70 + 56 = 126 - 显示层:白色数字(物理)+ 黄色数字(雷电)
如果你的 display.yml 配置了 separate 模式,会分别看到两个跳字。
第五步:技能调用
MythicMobs 示例
yml
# 雷电技能,走 spell 管线
ThunderBolt:
Skills:
- hna-damage{a=200;pp=spell;dt=thunder;st=skill} @target
# 雷电附魔平A,走默认管线
ThunderStrike:
Skills:
- hna-damage{a=50;pp=true;dt=thunder;st=basic} @target参数说明
pp=spell-- 使用 spell 管线(无格挡)pp=true-- 使用默认管线dt=thunder-- 指定伤害类型为 thunderst=skill/st=basic-- 来源类型
完整文件清单
做完以上步骤后,你的配置目录应该包含:
text
plugins/HNAttribute/
├── attributes/
│ └── element.yml # 追加了 thunder 相关属性
├── damage_types/
│ ├── physical.yml # 已有
│ ├── magic.yml # 已有
│ └── thunder.yml # 新增
├── stages/ # 不需要改动
│ └── ...
└── pipelines/ # 不需要改动
└── ...排查清单
如果雷电伤害没有生效,按这个顺序检查:
| 步骤 | 命令 | 检查什么 |
|---|---|---|
| 1 | /hnattr trace thunder_damage | 属性是否有值 |
| 2 | /hnattr inspect | 装备是否被正确读取 |
| 3 | 查看控制台 | reload 时是否有报错 |
| 4 | 检查属性定义 | channel 和 channel-role 是否正确 |
| 5 | 检查 damage_types/thunder.yml | 文件是否存在,id 是否为 thunder |
扩展:更多元素
按同样的模式,你可以继续添加任意元素:
yml
# 毒属性
poison_damage:
channel: poison
channel-role: damage
poison_resistance:
channel: poison
channel-role: resist
# 风属性
wind_damage:
channel: wind
channel-role: damage
wind_resistance:
channel: wind
channel-role: resist每种元素只需要:属性定义 + damage_types 文件。管线和 Stage 完全复用。
