// priority: 8
const main_attribute = [
    // 撼地斯拉
    'uranium_spurs',
    //转化
    "invert",
    //畸变
    'aberration',
    //核能熔炉
    "nuclear_furnace_component",
    //噬魂者
    "soul_eater"
]
NativeEvents.onEvent($LivingEquipmentChangeEvent, event => {
    if (!event.entity || !event.entity.isPlayer()) return;
    let player = event.entity;

    if (player.getMainHandItem().item instanceof $ModularItem) {
        let item = player.getMainHandItem()
        main_attribute.forEach(effectname => {
            let effectLevel = simpleGetTetraEffectLevel(item, effectname)
            let efficiency = item.item.getEffectEfficiency(item, effectname)
            let strategy = main_effect_attribute_strategies[effectname] || main_effect_attribute_strategies.default;
            strategy(event, player, effectLevel, item, effectname, efficiency);
        })
    } else {
        main_attribute.forEach(effectname => {
            let item = Item.of('tetra:modular_toolbelt')
            let strategy = main_effect_attribute_strategies[effectname] || main_effect_attribute_strategies.default;
            strategy(event, player, 0, item, effectname, 0);
        })
    }
})
const main_effect_attribute_strategies = {
    //核能熔炉
    'nuclear_furnace_component': function (event, player, effectLevel, item, effectname, efficiency) {

        if (simpleGetTetraEffectLevel(item, 'hellstone_ingot') > 0) return

        let radiation_level = simple_get_radiation(player).level
        let radiation_efficiency = simple_get_radiation(player).efficiency

        player.modifyAttribute('kubejs:fire_damage', effectname + 'addition', radiation_level * effectLevel / 100, 'addition')
        player.modifyAttribute('kubejs:fire_damage', effectname + 'multiply_base', radiation_efficiency * efficiency / 100, 'multiply_base')
    },
    //畸变
    'aberration': function (event, player, effectLevel, item, effectname, efficiency) {
        let radiation_level = simple_get_radiation(player).level
        player.modifyAttribute('minecraft:generic.max_health', effectname + 'multiply_total', radiation_level * effectLevel / 10000, 'multiply_total')
    },

    // 转化
    'invert': function (event, player, effectLevel, item, effectname, efficiency) {
        player.modifyAttribute('kubejs:fire_damage', effectname + 'multiply_base', 0, 'multiply_base')

        let fire_damage = player.getAttributeTotalValue('kubejs:fire_damage')
        let decrease = fire_damage * effectLevel / 100 * efficiency

        player.modifyAttribute('kubejs:fire_damage', effectname + 'multiply_base', - effectLevel / 100, 'multiply_base')
        player.persistentData.putDouble('fire_increased_damag', decrease)
    },
    // 撼地斯拉
    'uranium_spurs': function (event, player, effectLevel, item, effectname, efficiency) {
        let total_level = simple_get_radiation(player).level * effectLevel / 100

        let total_efficiency = simple_get_radiation(player).efficiency * efficiency / 100

        player.modifyAttribute('kubejs:pestilence', effectname + 'addition', total_level, 'addition')
        player.modifyAttribute('kubejs:pestilence', effectname + 'multiply_base', total_efficiency / 100, 'multiply_base')


    },
    'default': function (event, player, effectLevel, item, effectname, efficiency) {
        return
    }
};