import { world, system, EntityDamageCause, EquipmentSlot} from "@minecraft/server";
import { launchPlayer } from "../../util/movements.js";
import { attackMobHumanoidMeikyu } from "../../util/attackMethods.js";

const animations =[
    [
        {
            animation: "minced.irongolem.attack_sprint",
            knockback: [-0.5,2],
            Player_Knockback: [2,0.25],
            type: "blunt",
            attack_speed: 8,
            stun_type: "short",
            hit_number: 1,
            range: 3,
            distance: 2,
            targetNum: 1,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "minced.irongolem.attack",
            knockback: [5,0.2],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 22,
            stun_type: "long",
            hit_number: 1,
            range: 5,
            distance: 0,
            targetNum: 20,
            damage_multiplier: 1.5,
            stun_damage_multiplier: 1,
            next_attack_time: 10,
            Unbreakable: true
        },
        {
            animation: "minced.irongolem.attack2",
            knockback: [7,0.2],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 24,
            stun_type: "long",
            hit_number: 1,
            range: 3,
            distance: 0,
            targetNum: 10,
            damage_multiplier: 1.25,
            stun_damage_multiplier: 2,
            next_attack_time: 10,
            Unbreakable: false
        },
        {
            animation: "minced.irongolem.attack3",
            knockback: [7,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 22,
            stun_type: "long",
            hit_number: 1,
            range: 3,
            distance: 1,
            targetNum: 10,
            damage_multiplier: 1.5,
            stun_damage_multiplier: 1.5,
            next_attack_time: 10,
            Unbreakable: false
        }
    ]
]

const mob = {
    name: 'iron_golem',
    display_name: "Iron Golem",
    can_block: true,
    distance: 1,
    range: 1,
    stun_meter_ticks: 40,
    block_damage: 5,
    block_power: 30,
    clash_power: 10,
    available_moves: [],
    cd: 20,
    execute(player, effect, mode) {
        const range = this.range
        const cd = this.cd
        const blckdmg = this.block_damage
        let atkspd
        let lavander = 12
        let critChance = Math.floor(Math.random()*9)
        let critDamage = 0
        critChance != 2 ? critDamage = 0 : critDamage = Math.floor(Math.random() * lavander)
        let animChecker = 0
        for(let i = (animations[0].length - 1); i > 0; i--) {
            if(player.getDynamicProperty("combo") % i == 0) {
                animChecker = i
                break;
            }
        }
        switch(mode) {
            case "sprint": {
                player.playAnimation(`animation.${animations[0][0]}`)
                let stundamage = 10
                let propCheck = {
                    animation: "minced.unarmed.attack",
                    knockback: [1,0.25],
                    Player_Knockback: [3,0],
                    type: "blunt",
                    attack_speed: 8,
                    stun_type: "short",
                    hit_number: 1,
                    range: 2,
                    distance: 1.5,
                    targetNum: 1,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    next_attack_time: 10,
                    Unbreakable: true
                }
                let knockback = propCheck.knockback
                player.playAnimation(`animation.${propCheck.animation}`)
                atkspd = propCheck.attack_speed
                let Pknockback = propCheck.Player_Knockback
                launchPlayer(player, Pknockback[0], Pknockback[1])
                let effects = propCheck.type
                let stun = propCheck.stun_type
                let ranger = propCheck.range
                let distil = propCheck.distance
                let tgtnm = propCheck.targetNum
                let NAT = propCheck.next_attack_time
                let breakable = propCheck.Unbreakable
                let hitNum = propCheck.hit_number
                attackMobHumanoidMeikyu(player, ranger, (lavander * propCheck.damage_multiplier), blckdmg, cd, atkspd, distil, tgtnm, "line_target", effect, knockback, stun, "knock_player", effects, 1, stundamage, NAT, breakable, "no_cooldown", "", hitNum)
            } break;
            default: {
                let stundamage = 35
                let propCheck = animations[0][animChecker]
                let knockback = propCheck.knockback
                player.playAnimation(`animation.${propCheck.animation}`)
                atkspd = propCheck.attack_speed
                let Pknockback = propCheck.Player_Knockback
                launchPlayer(player, Pknockback[0], Pknockback[1])
                let effects = propCheck.type
                let stun = propCheck.stun_type
                let ranger = propCheck.range
                let distil = propCheck.distance
                let tgtnm = propCheck.targetNum
                let NAT = propCheck.next_attack_time
                let breakable = propCheck.Unbreakable
                let hitNum = propCheck.hit_number
                attackMobHumanoidMeikyu(player, ranger, (lavander * propCheck.damage_multiplier), blckdmg, cd, atkspd, distil, tgtnm, "line_target", effect, knockback, stun, "", effects, (animations[0].length - 1), stundamage, NAT, breakable, "no_cooldown", "", hitNum)
            } break;
        }
    }
}

export default mob


