Skip to content

概述

hna-attribute 是通用的属性值判断条件,可以用于任何属性的值比较。

基本语法

yaml
- hna-attribute{参数} true/false

参数列表

参数别名类型默认值说明
attributeattr, a字符串-属性 ID(必填)
valueamount, v数值-比较的目标值(必填)
operatorop, o字符串>=比较操作符

比较操作符

操作符别名说明
>=ge大于等于
>gt大于
<=le小于等于
<lt小于
==eq, =等于
!=ne不等于

基本示例

yaml
# 检查攻击力是否 >= 50
- hna-attribute{attribute=attack_damage;value=50;operator=>=} true

# 短写形式
- hna-attribute{attr=attack_damage;v=50;op=>=} true

常见使用场景

场景 1:法力值判断

yaml
FireballSkill:
  Skills:
  # 检查是否有至少 30 点法力值
  - hna-attribute{attribute=current_mana;value=30;operator=>=} true
  
  # 法力值足够,释放火球术
  - hna-damage{amount=100;damage-type=fire;source-type=skill} @target
  
  # 消耗 30 点法力值
  - hna-attribute{attribute=current_mana;amount=-30;source=fireball_cost} @self

场景 2:攻击力判断

yaml
PowerStrike:
  Skills:
  # 检查攻击力是否达到 50
  - hna-attribute{attribute=attack_damage;value=50;operator=>=} true
  - hna-damage{multiplier=2.0;source-type=skill} @target
  
  # 攻击力不足
  - hna-attribute{attribute=attack_damage;value=50;operator=<} true
  - message{m="&c攻击力不足!"} @Self

场景 3:生命值判断

yaml
ExecuteSkill:
  Skills:
  # 检查目标生命值是否低于 30%
  - hna-attribute{attribute=current_health;value=30;operator=<} true
  - hna-damage{amount=500;source-type=skill} @target
  - message{m="&c斩杀!"} @Self

场景 4:抗性判断

yaml
FireSpell:
  Skills:
  # 检查目标火焰抗性是否低于 20
  - hna-attribute{attribute=fire_resistance;value=20;operator=<} true
  - hna-damage{amount=200;damage-type=fire} @target
  
  # 抗性太高
  - hna-attribute{attribute=fire_resistance;value=20;operator=>=} true
  - message{m="&e目标火焰抗性太高!"} @Self

场景 5:多条件判断

yaml
ComplexSkill:
  Skills:
  # 检查法力值 >= 50
  - hna-attribute{attribute=current_mana;value=50;operator=>=} true
  
  # 检查攻击力 >= 100
  - hna-attribute{attribute=attack_damage;value=100;operator=>=} true
  
  # 条件满足,释放技能
  - hna-damage{multiplier=3.0;source-type=skill} @target
  - message{m="&a强力一击!"} @Self

完整技能示例

yaml
ManaShield:
  Cooldown: 30
  Skills:
  # 检查当前法力值是否 >= 100
  - hna-attribute{attribute=current_mana;value=100;operator=>=} true
  
  # 法力值足够,激活护盾
  - hna-buff{key="法力护盾";time=200;level=1} @Self
  - effect:particles{p=ENCHANTMENT_TABLE;a=50} @Self
  - message{m="&b法力护盾已激活!"} @Self
  
  # 消耗 100 点法力值
  - hna-attribute{attribute=current_mana;amount=-100;source=mana_shield_cost} @self
  
  # 法力值不足
  - hna-attribute{attribute=current_mana;value=100;operator=<} true
  - message{m="&c法力值不足!需要 100 点法力值。"} @Self

适用属性

可以用于任何在 attributes.yml 中定义的属性:

  • max_health:最大生命值
  • current_health:当前生命值
  • max_mana:最大法力值
  • current_mana:当前法力值
  • mana_deficit:法力值缺失量
  • attack_damage:攻击力
  • fire_damage:火焰伤害
  • ice_damage:冰霜伤害
  • fire_resistance:火焰抗性
  • physical_resistance:物理抗性
  • crit_chance:暴击率
  • crit_damage:暴击伤害
  • ... 以及所有自定义属性

与其他条件的区别

条件用途
hna-attribute判断任意属性的值(通用)
hna-hasbuff判断是否有某个 Buff
hna-hasot判断是否有某个周期效果

注意事项

  1. attribute 必须是 attributes.yml 中定义的属性 ID
  2. 属性名区分大小写
  3. 默认操作符是 >=
  4. 可以用于任何实体(玩家、怪物等)
  5. 需要明确的目标选择器

调试方法

text
/hnattr inspect
/hnattr source
/hnattr trace <属性ID>

相关文档

HN 系列插件文档