// priority: 8
const all_attribute = [
    // 加速
    'jia_su',
    // 台阶高度
    'tai_jie_gao_du',
    // 沉重
    'chen_zhong',
    // 防护
    'fang_hu',
    // 韧性
    'ren_xing',
    // 幸运
    'xing_yun',
    // 攻击加成
    'gong_ji_jia_cheng',
    // 经验
    'jing_yan',
    // 距离
    'ju_li',
    // 生命流失
    'decrease_maxhealth',
    // 生命增幅
    'attribute_maxhealth',
    //攻速增加
    'attack_speed_addition',
    //攻速减少
    'attack_speed_decrease',
    //防护减少
    'fang_hu_decrease',
    //鞘翅飞行
    'elytra',
    //游泳速度
    'swim_attribute',
    //瘟疫
    'pestilence_attribute',
    //击退抗性
    'attack_knockback_addition',
    //治疗
    'healing_received',
    //挖掘速度
    'gravhastighet',
    //火焰增幅
    'attribute_fire',
    //韧性减少
    'ren_xing_decrease',
    //宙斯盾
    'aegis',
]
PlayerEvents.inventoryClosed(event => {
    let player = event.entity
    if (!player) return;
    all_tetra_attribute(player)
})
//玩家登录事件
PlayerEvents.loggedIn(event => {
    let player = event.player;
    if (!player) return;
    all_tetra_attribute(player)
})
//玩家重生事件
PlayerEvents.respawned(event => {
    let player = event.player;
    if (!player) return;
    all_tetra_attribute(player)
})
function all_tetra_attribute(player) {
    all_attribute.forEach(effectname => {
        let effect = get_specific_effect(player, effectname)
        let level = effect.level||0
        let efficiency = effect.efficiency || 0
        let strategy = all_effect_attribute_strategies[effectname] || all_effect_attribute_strategies.default;
        strategy( player, level, effectname, efficiency)
    })
}
const all_effect_attribute_strategies = {
    // 宙斯盾
    'aegis': function ( player, effectLevel, effectname, efficiency) {
        //获取未使用的应力     
        let stress_level = get_specific_effect(player, 'stress').level - get_occupation_stress(player)

        player.modifyAttribute('minecraft:generic.armor', effectname + 'armor', stress_level * effectLevel / 100, 'addition')
        player.modifyAttribute('minecraft:generic.armor_toughness', effectname + 'armor_toughness', stress_level * efficiency / 1000, 'addition')
    },
    // 火焰增幅
    'attribute_fire': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('kubejs:fire_damage', effectname + 'addition', effectLevel, 'addition')
        player.modifyAttribute('kubejs:fire_damage', effectname + 'multiply_base', efficiency / 100, 'multiply_base')
    },
    // 挖掘速度
    'gravhastighet': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('attributeslib:mining_speed', effectname, effectLevel / 100, 'multiply_base')
    },
    // 治疗
    'healing_received': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('attributeslib:healing_received', effectname, effectLevel / 100, 'addition')
    },
    // 鞘翅飞行
    'elytra': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('caelus:fall_flying', effectname, effectLevel, 'addition')
    },
    // 台阶高度
    'tai_jie_gao_du': function ( player, effectLevel, effectname, efficiency) {
        let isEnabled = player.persistentData.getInt(effectname) ?? 0;
        // 清除当前加成
        player.modifyAttribute('forge:step_height_addition', effectname, 0, 'addition');

        // 根据开关状态设置加成
        if (isEnabled === 1) {
            player.modifyAttribute('forge:step_height_addition', effectname, effectLevel / 5, 'addition');
        } 
    },

    // 击退抗性
    'attack_knockback_addition': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.knockback_resistance', effectname, effectLevel / 100, 'addition')
    },
    // 瘟疫增幅
    'pestilence_attribute': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('kubejs:pestilence', effectname + 'addition', effectLevel, 'addition')
        player.modifyAttribute('kubejs:pestilence', effectname + 'multiply_base', efficiency / 100, 'multiply_base')
    },
    // 游泳速度
    'swim_attribute': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('forge:swim_speed', effectname, effectLevel / 100, 'addition')
    },
    // 攻速增加
    'attack_speed_addition': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.attack_speed', effectname, effectLevel / 100, 'multiply_base')
    },
    // 攻速减少
    'attack_speed_decrease': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.attack_speed', effectname, -effectLevel / 100, 'multiply_base')
    },
    // 生命流失
    'decrease_maxhealth': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.max_health', effectname + 'addition', -effectLevel, 'addition')
        player.modifyAttribute('minecraft:generic.max_health', effectname + 'multiply_base', -efficiency / 100, 'multiply_base')
    },
    // 生命增幅
    'attribute_maxhealth': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.max_health', effectname + 'addition', effectLevel, 'addition')
        player.modifyAttribute('minecraft:generic.max_health', effectname + 'multiply_base', efficiency / 100, 'multiply_base')
    },
    // 加速
    'jia_su': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.movement_speed', effectname, effectLevel / 100, 'multiply_base')
    },
    // 沉重
    'chen_zhong': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.movement_speed', effectname, -effectLevel / 100, 'multiply_base')
    },
    // 防护减少
    'fang_hu_decrease': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.armor', effectname, -effectLevel / 100, 'multiply_base')
    },
    // 防护
    'fang_hu': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.armor', effectname + 'addition', effectLevel, 'addition')
        player.modifyAttribute('minecraft:generic.armor', effectname + 'multiply_base', efficiency / 100, 'multiply_base')
    },
    // 韧性
    'ren_xing_decrease': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.armor_toughness', effectname + 'addition', -effectLevel, 'addition')
        player.modifyAttribute('minecraft:generic.armor_toughness', effectname + 'multiply_base', -efficiency / 100, 'multiply_base')
    },
    // 韧性
    'ren_xing': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.armor_toughness', effectname + 'addition', effectLevel, 'addition')
        player.modifyAttribute('minecraft:generic.armor_toughness', effectname + 'multiply_base', efficiency / 100, 'multiply_base')
    },
    // 幸运
    'xing_yun': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.luck', effectname + 'minecraft', effectLevel, 'addition')
        player.modifyAttribute('pasterdream:luck', effectname + 'pasterdream', effectLevel, 'addition')
    },
    // 攻击加成
    'gong_ji_jia_cheng': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('minecraft:generic.attack_damage', effectname + 'addition', effectLevel, 'addition')
        player.modifyAttribute('minecraft:generic.attack_damage', effectname + 'multiply_base', efficiency / 100, 'multiply_base')
    },
    // 经验
    'jing_yan': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('attributeslib:experience_gained', effectname, effectLevel / 100, 'addition')
    },
    // 距离
    'ju_li': function ( player, effectLevel, effectname, efficiency) {
        player.modifyAttribute('forge:block_reach', effectname, effectLevel / 2, 'addition')
    },
    'default': function ( player, effectLevel, effectname, efficiency) {
        return
    }
};