Skip to content

如何新增伤害类型

在 v1.6.0 中,新增伤害类型只需要两步:

  1. 定义属性(声明 channel + channel-role)
  2. 定义显示(damage_types 文件)

不需要写新的 Stage,不需要改 Pipeline。


完整示例:新增"雷电伤害"

第一步:定义属性

attributes/ 目录下新建或编辑一个 yml 文件,注册雷电相关属性:

yml
# attributes/element.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

关键点:

  • channel: thunder -- 声明这个属性属于 thunder 通道
  • channel-role: damage -- 声明这是伤害来源
  • channel-role: resist -- 声明这是抗性

如果你还需要穿透属性,可以继续添加:

yml
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

第二步:定义显示

新建 damage_types/thunder.yml

yml
id: thunder
display-order: 20
display-name: "雷电伤害"
display: "{color}{value}"
color: "&e"
special-color: "&e&l"
description: "雷电伤害"

这就完成了。重载配置后,只要玩家身上有 thunder_damage > 0,近战攻击时 collect_channels 就会自动收集到 thunder 通道,per_channel 的 resist Stage 会自动用默认减伤公式结算。


可选:自定义减伤公式

默认情况下,所有通道共用 stages/resist.yml 中的减伤公式。如果你想让雷电伤害使用不同的减伤逻辑,可以在 DamageType 中配置 resist-formula

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 中可用的变量:

变量含义
channel_value当前通道的伤害值
channel_resist当前通道的抗性值
channel_penetration_flat当前通道的固定穿透
channel_penetration_rate当前通道的百分比穿透
self_* / target_*攻击者/受击者的任意属性

不需要做什么

  • 不需要写新的 Stage -- collect_channelsper_channel 已经能自动处理任意通道
  • 不需要改 Pipeline -- melee/ranged/spell/dot 管线对所有伤害通道通用
  • 不需要在 damage_types/*.yml 里额外绑定来源属性和抗性属性,系统会通过 channel + channel-role 自动关联

验证步骤

1. 确认属性注册成功

text
/hnattr reload
/hnattr trace thunder_damage
/hnattr trace thunder_resistance

2. 做一件测试装备

武器 Lore:

text
雷电伤害: 100

护甲 Lore:

text
雷电抗性: 30

3. 确认系统读到了

text
/hnattr inspect
/hnattr lookup

4. 打一下怪物

近战攻击时应该能看到雷电伤害的显示(黄色数字)。

5. 用技能指定雷电伤害

yml
- hna-damage{a=100;pp=true;dt=thunder;st=skill} @target

常见问题

装备上有雷电伤害,但攻击时没有雷伤显示

检查顺序:

  1. thunder_damage 属性是否配了 channel: thunderchannel-role: damage
  2. /hnattr trace thunder_damage 是否有值
  3. damage_types/thunder.yml 是否存在且格式正确

雷电伤害显示了但数值不对

检查 resist-formula 是否符合你的预期。如果没配 resist-formula,会使用 stages/resist.yml 的默认公式。

HN 系列插件文档