实例

OTHER 类属性值仅提供 属性名 变量 可供其他属性获取

package org.serverct.ersha.nukkit.attribute.manager.attribute.sub.defense

import cn.nukkit.entity.Entity
import org.serverct.ersha.nukkit.attribute.api.enums.AttributeName
import org.serverct.ersha.nukkit.attribute.manager.attribute.data.enums.AttributeType
import org.serverct.ersha.nukkit.attribute.manager.attribute.SubAttribute

class Defense : SubAttribute(AttributeType.DEFENSE, AttributeName.DEFENSE.toDefaultName(), "defense", 0) {

    /*
    this.damage = 此次攻击事件伤害(受优先级影响)
    this.randomValue = 相当于 getRandomValue() 方法
    */

    override fun cast(attacker: Entity, entity: Entity) {
        var defense = 0.0
        //获取攻击者的 真实伤害 属性值
        val realDamage = this.attackerData.getAttributeRandomValue(AttributeName.REAL_DAMAGE.toServerName())
        //获取攻击者的 护甲穿透 属性值
        val see = this.attackerData.getAttributeRandomValue(AttributeName.SEE_THROUGH.toServerName())
        //获取被攻击者的 护甲值 属性值
        val armor = this.entityData.getAttributeRandomValue(AttributeName.ARMOR.toServerName())
        defense += this.damage * (armor-see).coerceAtLeast(0.0) / 100
        defense += this.randomValue
        defense -= realDamage
        this.attackData.attrData[attributeName] = defense
        this.takeDamage(defense)
    }

    class Armor : SubAttribute(AttributeType.OTHER, AttributeName.ARMOR.toDefaultName(), "armor", 0)
}

最后更新于