Skip to content

可用变量

periodic/*.ymlconditionactions 中,公式可以使用以下变量:

target_ 前缀(目标实体)

规则target_ + 任何属性ID = 目标的该属性值

变量示例含义
target_health目标当前生命值
target_max_health目标最大生命值
target_health_regen目标生命恢复属性
target_attack_damage目标攻击力属性
target_defense目标防御力属性
target_max_mana目标最大法力值
target_<任意属性ID>目标的任意属性值

source_ 前缀(来源实体)

规则source_ + 任何属性ID = 来源的该属性值

变量示例含义
source_health来源当前生命值
source_attack_damage来源攻击力属性
source_magic_damage来源魔法伤害属性
source_max_mana来源最大法力值
source_<任意属性ID>来源的任意属性值

使用场景

这些变量用于周期效果配置文件中的条件判断和动作公式。

配置文件位置plugins/HNAttribute/periodic/*.yml


示例 1:基于目标属性的回复

yml
简单回血:
  enabled: true
  selector: players
  interval: 20
  condition: "target_health < target_max_health"  # 未满血
  actions:
    - type: heal
      amount: "target_health_regen"  # 回复量 = 目标的生命恢复属性

示例 2:基于来源属性的伤害

yml
流血:
  enabled: true
  mode: instance
  selector: mobs
  interval: 20
  instance:
    source: nearest-player
    interval: 20
    duration: 100
  actions:
    - type: damage
      amount: "source_attack_damage * 0.1"  # 伤害 = 施法者攻击力的 10%

示例 3:基于双方属性的计算

yml
魔法反噬:
  enabled: true
  mode: instance
  selector: mobs
  interval: 40
  instance:
    source: nearest-player
    interval: 20
    duration: 100
  actions:
    - type: damage
      amount: "Math.max(1, source_magic_damage - target_magic_resistance)"
      # 伤害 = 施法者魔法伤害 - 目标魔法抗性
      # 最少造成 1 点伤害

示例 4:血量百分比判断

yml
背水一战:
  enabled: true
  selector: players
  interval: 20
  condition: "target_health < target_max_health * 0.3"  # 血量低于 30%
  actions:
    - type: buff
      buff-key: "背水Buff"
      duration: 40
      level: "Math.ceil((1 - target_health / target_max_health) * 5)"
      # 血量 70%:1级
      # 血量 50%:2级
      # 血量 30%:3级
      # 血量 10%:4级

示例 5:基于目标防御的伤害

yml
破甲流血:
  enabled: true
  mode: instance
  selector: mobs
  interval: 20
  instance:
    source: nearest-player
    interval: 20
    duration: 100
  condition: "target_defense < 50"  # 目标防御低于 50
  actions:
    - type: damage
      amount: "source_attack_damage * 0.2"  # 造成 20% 攻击力的伤害

示例 6:基于来源法力值的治疗

yml
法力回复:
  enabled: true
  selector: players
  interval: 20
  condition: "target_max_mana > 0 && target_current_mana < target_max_mana"
  actions:
    - type: attribute
      attribute: current_mana
      amount: "target_max_mana * 0.01"  # 回复最大法力值的 1%

示例 7:复杂条件判断

yml
生命链接:
  enabled: true
  mode: instance
  selector: players
  interval: 20
  instance:
    source: nearest-player
    interval: 20
    duration: 100
  condition: |-
    target_health < target_max_health * 0.5 && 
    source_health > source_max_health * 0.5
  actions:
    - type: heal
      amount: "source_max_health * 0.05"  # 治疗目标
    - type: damage
      amount: "source_max_health * 0.05"  # 伤害来源
      target: source

注意事项

1. 属性 ID 必须存在

使用 target_<属性ID>source_<属性ID> 时,该属性必须已注册。

如果属性不存在,变量值为 0。

2. 除零保护

当使用最大值做除数时,注意保护:

yml
# ❌ 危险
condition: "target_health / target_max_health < 0.5"

# ✅ 安全
condition: "target_max_health > 0 && target_health / target_max_health < 0.5"

3. source 和 target 的区别

  • target:周期效果作用的目标(selector 选中的实体)
  • source:周期效果的来源(instance 模式下的 source 实体)

在非 instance 模式下,source 变量不可用。


调试方法

使用命令查看属性值:

text
/hnattr lookup          # 查看最终属性值
/hnattr trace <属性ID>  # 查看属性计算过程
/hnattr source          # 查看属性来源

相关文档

HN 系列插件文档