import { system, EntityComponentTypes } from '@minecraft/server';
import * as utils from "./utils";

export const weapons = [
    "goe_bos:spider_blade",
    "goe_bos:boss_bone_blade",
    "goe_bos:boss_hoglin_warrior_axe",
    "goe_bos:necromancer_dagger",
    "goe_bos:necromancers_staff",
    "goe_bos:frostblizzard_scepter",
    "goe_bos:wraith_reaper",
    "goe_bos:wand_of_void"
]

export async function onEntityHurt(event, weapon) {
    const attacker = event.damageSource.damagingEntity;
    let animationIndex = attacker.getDynamicProperty("goe_bos_attack_combo_index");
    if (animationIndex === undefined) {
        animationIndex = -1;
    }
    animationIndex = (animationIndex + 1) % 3;

    attacker.runCommandAsync(`playanimation @s animation.goe_bos.player.fp_attack_v${animationIndex + 1} animation.goe_bos.player.tp_attack_v${animationIndex + 1} 0 "!v.is_first_person"`);
    attacker.runCommandAsync(`playanimation @s animation.goe_bos.player.tp_attack_v${animationIndex + 1} animation.goe_bos.player.fp_attack_v${animationIndex + 1} 0 "v.is_first_person"`);
    attacker.runCommandAsync(`playanimation @s animation.goe_bos.player.tp_attack_v${animationIndex + 1} animation.goe_bos.player.empty 0.15 "q.all_animations_finished"`);
    attacker.runCommandAsync(`playanimation @s animation.goe_bos.player.fp_attack_v${animationIndex + 1} animation.goe_bos.player.empty 0.15 "q.all_animations_finished"`);
    
    attacker.setDynamicProperty("goe_bos_attack_combo_index", animationIndex);

    utils.runPlayerCommand(attacker, "playsound goe_bos:sword_use @s ~ ~ ~ 100 3");
}