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

const animations =[
    [
        {
            animation: "minced.unarmed.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.unarmed.attack",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 6,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.25,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "minced.unarmed.attack2",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 6,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.25,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.attack_no_weapon",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 9,
            stun_type: "medium",
            hit_number: 1,
            range: 2,
            distance: 1.5,
            targetNum: 1,
            damage_multiplier: 2,
            stun_damage_multiplier: 1.5,
            next_attack_time: 4,
            Unbreakable: false
        },
    ],
    [
        {
            animation: "minced.unarmed.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: "zombie_paced.dagger_attack",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "pierce",
            attack_speed: 18,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 0.5,
            targetNum: 1,
            damage_multiplier: 1.5,
            stun_damage_multiplier: 0.25,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.dagger_attack2",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "slash",
            attack_speed: 10,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 10,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.dagger_attack3",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "slash",
            attack_speed: 9,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.75,
            stun_damage_multiplier: 0.75,
            next_attack_time: 4,
            Unbreakable: false
        }
    ],
    [
        {
            animation: "minced.unarmed.attack_sprint",
            knockback: [-0.5,2],
            Player_Knockback: [2,0.25],
            type: "blunt",
            attack_speed: 8,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.longsword_attack",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "slash",
            attack_speed: 17,
            stun_type: "short",
            hit_number: 1,
            range: 3,
            distance: 1.5,
            targetNum: 10,
            damage_multiplier: 1.5,
            stun_damage_multiplier: 0.75,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.longsword_attack2",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "pierce",
            attack_speed: 18,
            stun_type: "short",
            hit_number: 1,
            range: 3,
            distance: 1,
            targetNum: 3,
            damage_multiplier: 2,
            stun_damage_multiplier: 0.5,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.longsword_attack3",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "slash",
            attack_speed: 18,
            stun_type: "short",
            hit_number: 1,
            range: 3,
            distance: 1,
            targetNum: 10,
            damage_multiplier: 2,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        }
    ],
    [
        {
            animation: "minced.unarmed.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: "zombie_paced.mace_attack",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 17,
            stun_type: "long",
            hit_number: 1,
            range: 2,
            distance: 1.5,
            targetNum: 1,
            damage_multiplier: 1.5,
            stun_damage_multiplier: 1.5,
            next_attack_time: 10,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.mace_attack2",
            knockback: [3,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 21,
            stun_type: "long",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.25,
            stun_damage_multiplier: 1.75,
            next_attack_time: 10,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.mace_attack3",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 18,
            stun_type: "knockdown",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.25,
            stun_damage_multiplier: 2,
            next_attack_time: 10,
            Unbreakable: false
        }
    ],
    [
        {
            animation: "minced.unarmed.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: "zombie_paced.saber_attack",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "slash",
            attack_speed: 15,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1.5,
            targetNum: 1,
            damage_multiplier: 2,
            stun_damage_multiplier: 1,
            next_attack_time: 8,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.saber_attack2",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "pierce",
            attack_speed: 12,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.65,
            stun_damage_multiplier: 0.25,
            next_attack_time: 8,
            Unbreakable: false
        },
        {
            animation: "zombie_paced.saber_attack3",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "slash",
            attack_speed: 12,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1.25,
            stun_damage_multiplier: 1.25,
            next_attack_time: 8,
            Unbreakable: false
        }
    ],
    [
        {
            animation: "minced.drowned.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.drowned.attack",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 20,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1.5,
            targetNum: 1,
            damage_multiplier: 2,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "minced.drowned.attack2",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 20,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "minced.drowned.attack3",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 8,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "minced.drowned.attack_pierce",
            knockback: [1,0],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 8,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        },
        {
            animation: "minced.drowned.attack_pierce2",
            knockback: [3,0.25],
            Player_Knockback: [1,0],
            type: "blunt",
            attack_speed: 8,
            stun_type: "short",
            hit_number: 1,
            range: 2,
            distance: 1,
            targetNum: 1,
            damage_multiplier: 1,
            stun_damage_multiplier: 1,
            next_attack_time: 4,
            Unbreakable: false
        }
    ]
]

const mob = {
    name: 'zombie',
    display_name: "Zombie",
    can_block: true,
    stun_meter_ticks: 40,
    block_damage: 5,
    block_power: 30,
    clash_power: 10,
    available_moves: [],
    cd: 20,
    execute(player, effect, mode) {
        const cd = this.cd
        const blckdmg = this.block_damage
        let atkspd
        
        let animChecker = 0
        let weapons = player.getProperty("weapon:type")
        let lavander = weapons == 1 ? 4 : weapons == 2 ? 8 : weapons == 3 ? 6 : weapons == 4 ? 6 : weapons == 5 ? 7 : 3
        let critChance = Math.floor(Math.random()*9)
        let critDamage = 0
        critChance != 2 ? critDamage = 0 : critDamage = Math.floor(Math.random() * lavander)
        for(let i = (animations[weapons].length - 1); i > 0; i--) {
            if(player.getDynamicProperty("combo") % i == 0) {
                animChecker = i
                break;
            }
        }
        switch(mode) {
            case "sprint": {
                let stundamage = 10
                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, "knock_player", effects, animations[weapons].length - 1, stundamage, NAT, breakable, "no_cooldown", "", hitNum)
            } break;
            default: {
                let stundamage = 10
                let propCheck = animations[weapons][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[weapons].length - 1, stundamage, NAT, breakable, "no_cooldown", "", hitNum)
            } break;
        }
    }
}

export default mob


