import { ItemStack, system, world } from "@minecraft/server";
import * as util from '../libs/serverUtils';
const Infinity_gems = new ItemStack('purerain_dino:infinity_gems', 1);
const OneConsume = new ItemStack('purerain_dino:decayed_pixie_powder', 1);
const TwoConsume = new ItemStack('purerain_dino:decayed_pixie_powder', 2);
const ThreeConsume = new ItemStack('purerain_dino:decayed_pixie_powder', 3);
function executeSkill(args, skillFunction, consumeItem, delayFunctions) {
    if (util.item.hasItem(args.source, Infinity_gems)) {
        args.source.runCommand(`function purerain_dino/purerain/skills/${skillFunction}`);
        delayFunctions.forEach(({ function: func, delay }) => {
            system.runTimeout(() => {
                args.source.runCommand(`function purerain_dino/purerain/skills/${func}`);
            }, delay);
        });
    }
    else if (consumeItem && util.item.hasItem(args.source, consumeItem)) {
        if (util.item.consumeItem(args.source, consumeItem)) {
            args.source.runCommand(`function purerain_dino/purerain/skills/${skillFunction}`);
            delayFunctions.forEach(({ function: func, delay }) => {
                system.runTimeout(() => {
                    args.source.runCommand(`function purerain_dino/purerain/skills/${func}`);
                }, delay);
            });
        }
    }
    else {
        let rawtext = { rawtext: [
                { translate: "accessibility.purerain_dino.message.decayed_pixie_powder" }
            ]
        };
        args.source.onScreenDisplay.setActionBar(rawtext);
    }
}
const death_card_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'death_card', OneConsume, [
            { function: 'death_card_f', delay: 20 }
        ]);
    }
};
const black_hole_staff_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'black_hole_staff', OneConsume, [
            { function: 'black_hole_staff_2', delay: 20 },
            { function: 'damage_entities', delay: 30 },
            { function: 'damage_entities', delay: 40 }
        ]);
    }
};
const black_hole_staff_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'black_hole_staff', TwoConsume, [
            { function: 'black_hole_staff_2', delay: 20 },
            { function: 'damage_entities', delay: 30 },
            { function: 'damage_entities', delay: 40 }
        ]);
    }
};
const black_hole_staff_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'black_hole_staff', ThreeConsume, [
            { function: 'black_hole_staff_2', delay: 20 },
            { function: 'damage_entities', delay: 30 },
            { function: 'damage_entities', delay: 40 }
        ]);
    }
};
const ender_clock_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'ender_clock', OneConsume, []);
    }
};
const ice_age_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'ice_age', OneConsume, [
            { function: 'ice_age', delay: 20 }
        ]);
    }
};
const ice_age_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'ice_age_lv2', TwoConsume, [
            { function: 'ice_age_lv2', delay: 20 },
            { function: 'ice_age_lv2', delay: 40 },
            { function: 'ice_age_lv2', delay: 60 }
        ]);
    }
};
const thunder_attack_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'thunder_attack', OneConsume, [
            { function: 'thunder_attack', delay: 20 },
            { function: 'thunder_attack', delay: 40 },
        ]);
    }
};
const thunder_attack_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'thunder_attack_lv2', TwoConsume, []);
    }
};
const thunder_attack_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'thunder_attack_lv3', ThreeConsume, []);
    }
};
const deadly_roar_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'deadly_roar', OneConsume, []);
    }
};
const buff_magic_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'buff_magic', OneConsume, []);
    }
};
const buff_magic_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'buff_magic_lv2', TwoConsume, []);
    }
};
const buff_magic_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'buff_magic_lv3', ThreeConsume, []);
    }
};
const ninja_headband_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'ninja_headband', OneConsume, []);
    }
};
const ninja_headband_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'ninja_headband', TwoConsume, [
            { function: 'ninja_headband', delay: 50 },
        ]);
    }
};
const ninja_headband_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'ninja_headband', TwoConsume, [
            { function: 'ninja_headband', delay: 50 },
            { function: 'ninja_headband', delay: 100 },
        ]);
    }
};
const dark_sword_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'dark_sword', OneConsume, [
            { function: 'dark_sword', delay: 10 },
            { function: 'dark_sword', delay: 20 },
            { function: 'dark_sword', delay: 30 },
            { function: 'dark_sword', delay: 40 },
            { function: 'dark_sword', delay: 50 },
            { function: 'remove_dark_attack', delay: 60 }
        ]);
    }
};
const sakura_slash_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sakura_slash', OneConsume, [
            { function: 'sakura_slash_attack', delay: 30 },
            { function: 'sakura_slash_attack', delay: 40 },
            { function: 'sakura_slash_attack', delay: 50 },
            { function: 'sakura_slash_attack', delay: 60 },
            { function: 'sakura_slash_attack', delay: 70 },
        ]);
    }
};
const sakura_slash_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sakura_slash_lv2', TwoConsume, [
            { function: 'sakura_slash_attack_sp', delay: 20 },
            { function: 'sakura_slash_attack', delay: 30 },
            { function: 'sakura_slash_attack', delay: 40 },
            { function: 'sakura_slash_attack', delay: 50 },
            { function: 'sakura_slash_attack', delay: 60 },
            { function: 'sakura_slash_attack_2', delay: 70 },
        ]);
    }
};
const sakura_slash_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sakura_slash_lv3', ThreeConsume, [
            { function: 'sakura_slash_attack_sp_2', delay: 20 },
            { function: 'sakura_slash_attack', delay: 30 },
            { function: 'sakura_slash_attack_sp_2', delay: 35 },
            { function: 'sakura_slash_attack', delay: 40 },
            { function: 'sakura_slash_attack_sp_2', delay: 45 },
            { function: 'sakura_slash_attack', delay: 50 },
            { function: 'sakura_slash_attack_sp_2', delay: 55 },
            { function: 'sakura_slash_attack', delay: 60 },
            { function: 'sakura_slash_attack_sp_2', delay: 65 },
            { function: 'sakura_slash_attack', delay: 70 },
            { function: 'sakura_slash_attack_2', delay: 80 },
        ]);
    }
};
const black_coffin_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'black_coffin', OneConsume, [
            { function: 'black_coffin_attack', delay: 10 },
            { function: 'black_coffin_attack', delay: 20 },
            { function: 'black_coffin_attack', delay: 30 },
            { function: 'black_coffin_attack', delay: 40 },
            { function: 'black_coffin_attack', delay: 50 },
            { function: 'black_coffin_attack', delay: 60 },
            { function: 'black_coffin_attack', delay: 70 },
            { function: 'black_coffin_attack', delay: 80 }
        ]);
    }
};
const black_coffin_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'black_coffin_lv2', TwoConsume, [
            { function: 'black_coffin_attack_lv2', delay: 10 },
            { function: 'black_coffin_attack_lv2', delay: 20 },
            { function: 'black_coffin_attack_lv2', delay: 30 },
            { function: 'black_coffin_attack_lv2', delay: 40 },
            { function: 'black_coffin_attack_lv2', delay: 50 },
            { function: 'black_coffin_attack_lv2', delay: 60 },
            { function: 'black_coffin_attack_lv2', delay: 70 },
            { function: 'black_coffin_attack_lv2', delay: 80 },
            { function: 'black_coffin_attack_lv2', delay: 90 }
        ]);
    }
};
const black_coffin_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'black_coffin_lv3', ThreeConsume, [
            { function: 'black_coffin_attack_lv3', delay: 10 },
            { function: 'black_coffin_attack_lv3', delay: 20 },
            { function: 'black_coffin_attack_lv3', delay: 30 },
            { function: 'black_coffin_attack_lv3', delay: 40 },
            { function: 'black_coffin_attack_lv3', delay: 50 },
            { function: 'black_coffin_attack_lv3', delay: 60 },
            { function: 'black_coffin_attack_lv3', delay: 70 },
            { function: 'black_coffin_attack_lv3', delay: 80 },
            { function: 'black_coffin_attack_lv3', delay: 90 }
        ]);
    }
};
const red_moon_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'red_moon', OneConsume, [
            { function: 'red_moon_attack', delay: 10 },
            { function: 'red_moon_attack', delay: 20 },
            { function: 'red_moon_attack', delay: 30 },
            { function: 'red_moon_attack', delay: 40 },
            { function: 'red_moon_attack', delay: 50 },
            { function: 'red_moon_attack', delay: 60 }
        ]);
    }
};
const sword_rain_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sword_rain_attack_1', OneConsume, [
            { function: 'sword_rain_attack_2', delay: 10 },
            { function: 'sword_rain_attack_2', delay: 40 },
            { function: 'sword_rain_attack_2', delay: 50 },
            { function: 'sword_rain_attack_2', delay: 60 },
            { function: 'sword_rain_attack_2', delay: 70 },
            { function: 'sword_rain_attack_2', delay: 80 },
            { function: 'sword_rain_attack_2', delay: 90 },
            { function: 'sword_rain_attack_2', delay: 100 }
        ]);
    }
};
const sword_rain_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sword_rain_attack_lv2_1', TwoConsume, [
            { function: 'sword_rain_attack_lv2_2', delay: 10 },
            { function: 'sword_rain_attack_lv2_2', delay: 40 },
            { function: 'sword_rain_attack_lv2_2', delay: 50 },
            { function: 'sword_rain_attack_lv2_2', delay: 60 },
            { function: 'sword_rain_attack_lv2_2', delay: 70 },
            { function: 'sword_rain_attack_lv2_2', delay: 80 },
            { function: 'sword_rain_attack_lv2_2', delay: 90 },
            { function: 'sword_rain_attack_lv2_2', delay: 100 }
        ]);
    }
};
const sword_rain_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sword_rain_attack_lv3_1', ThreeConsume, [
            { function: 'sword_rain_attack_lv3_2', delay: 10 },
            { function: 'sword_rain_attack_lv3_2', delay: 40 },
            { function: 'sword_rain_attack_lv3_2', delay: 50 },
            { function: 'sword_rain_attack_lv3_2', delay: 60 },
            { function: 'sword_rain_attack_lv3_2', delay: 70 },
            { function: 'sword_rain_attack_lv3_2', delay: 80 },
            { function: 'sword_rain_attack_lv3_2', delay: 90 },
            { function: 'sword_rain_attack_lv3_2', delay: 100 }
        ]);
    }
};
const red_moon_sword_lv1_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'red_moon_attack', OneConsume, [
            { function: 'sword_rain_attack_2', delay: 1 },
            { function: 'red_moon_attack', delay: 10 },
            { function: 'sword_rain_attack_2', delay: 11 },
            { function: 'red_moon_attack', delay: 20 },
            { function: 'sword_rain_attack_2', delay: 21 },
        ]);
    }
};
const red_moon_sword_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'red_moon_attack', TwoConsume, [
            { function: 'sword_rain_attack_lv2_2', delay: 1 },
            { function: 'red_moon_attack', delay: 10 },
            { function: 'sword_rain_attack_lv2_2', delay: 11 },
            { function: 'red_moon_attack', delay: 20 },
            { function: 'sword_rain_attack_lv2_2', delay: 21 },
        ]);
    }
};
const red_moon_sword_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'red_moon_attack', ThreeConsume, [
            { function: 'sword_rain_attack_lv3_2', delay: 1 },
            { function: 'red_moon_attack', delay: 10 },
            { function: 'sword_rain_attack_lv3_2', delay: 11 },
            { function: 'red_moon_attack', delay: 20 },
            { function: 'sword_rain_attack_lv3_2', delay: 21 },
        ]);
    }
};
const thunder_sword_lv1_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sword_rain_attack_1', OneConsume, [
            { function: 'thunder_attack', delay: 1 },
            { function: 'sword_rain_attack_2', delay: 10 },
            { function: 'thunder_attack', delay: 11 },
            { function: 'sword_rain_attack_2', delay: 20 },
            { function: 'thunder_attack', delay: 21 },
        ]);
    }
};
const thunder_sword_lv2_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sword_rain_attack_lv2_1', TwoConsume, [
            { function: 'thunder_attack_lv2', delay: 1 },
            { function: 'sword_rain_attack_lv2_2', delay: 10 },
            { function: 'thunder_attack_lv2', delay: 11 },
            { function: 'sword_rain_attack_lv2_2', delay: 20 },
            { function: 'thunder_attack_lv2', delay: 21 },
        ]);
    }
};
const thunder_sword_lv3_comp = {
    //使用物品事件
    onUse(args) {
        executeSkill(args, 'sword_rain_attack_lv3_1', ThreeConsume, [
            { function: 'thunder_attack_lv3', delay: 1 },
            { function: 'sword_rain_attack_lv3_2', delay: 10 },
            { function: 'thunder_attack_lv3', delay: 11 },
            { function: 'sword_rain_attack_lv3_2', delay: 20 },
            { function: 'thunder_attack_lv3', delay: 21 },
        ]);
    }
};
world.beforeEvents.worldInitialize.subscribe(args => {
    /*注册名为'purerain_dino:example'的自定义组件，该组件需要在对应item数据驱动文件下挂载
    数驱注册格式：
    "components": {
        ...
        "minecraft:custom_components": [
            "purerain_dino:example"
        ],
        //需要配合该组件达成使用的效果
        "minecraft:use_modifiers": {
                "use_duration": 999999, //可使用时长，按秒计算
                "movement_modifier": 0.4 //使用时移动速度倍率，0.4为原版食物效果，1.0为正常速度
        },
        ...
    }
    注：对应物品的格式版本需在1.21.10以上！建议直接使用1.21.50
    */
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:ender_clock', ender_clock_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:death_card', death_card_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:ice_age', ice_age_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:ice_age_lv2', ice_age_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:black_coffin', black_coffin_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:black_coffin_lv2', black_coffin_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:black_coffin_lv3', black_coffin_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:red_moon', red_moon_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:buff_magic', buff_magic_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:buff_magic_lv2', buff_magic_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:buff_magic_lv3', buff_magic_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:sword_rain', sword_rain_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:sword_rain_lv2', sword_rain_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:sword_rain_lv3', sword_rain_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:deadly_roar', deadly_roar_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:dark_sword', dark_sword_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:thunder_attack', thunder_attack_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:thunder_attack_lv2', thunder_attack_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:thunder_attack_lv3', thunder_attack_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:black_hole_staff', black_hole_staff_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:black_hole_staff_lv2', black_hole_staff_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:black_hole_staff_lv3', black_hole_staff_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:red_moon_sword_lv1', red_moon_sword_lv1_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:red_moon_sword_lv2', red_moon_sword_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:red_moon_sword_lv3', red_moon_sword_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:thunder_sword_lv1', thunder_sword_lv1_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:thunder_sword_lv2', thunder_sword_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:thunder_sword_lv3', thunder_sword_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:ninja_headband', ninja_headband_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:ninja_headband_lv2', ninja_headband_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:ninja_headband_lv3', ninja_headband_lv3_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:sakura_slash', sakura_slash_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:sakura_slash_lv2', sakura_slash_lv2_comp);
    args.itemComponentRegistry.registerCustomComponent('purerain_dino:sakura_slash_lv3', sakura_slash_lv3_comp);
});
