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

const mob = {
    name: 'ravager',
    display_name: "ravager",
    can_block: true,
    stun_meter_ticks: 40,
    block_damage: 5,
    block_power: 30,
    clash_power: 60,
    available_moves: [],
    cd: 20,
    execute(player, combo, effect, mode) {
        const cd = this.cd
        const blckdmg = this.block_damage
        const animations =[
            [
                {
                    animation: "minced.unarmed.attack_sprint",
                    knockback: [-0.5,2],
                    Player_Knockback: [2,0.25],
                    type: "blunt",
                    attack_speed: 8,
                    stun_type: "short",
                    range: 3,
                    distance: 2,
                    targetNum: 1,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    next_attack_time: 4,
                    Unbreakable: false
                },
                {
                    animation: "minced.ravager.attack_bite",
                    knockback: [1,0],
                    Player_Knockback: [1,0],
                    type: "pierce",
                    attack_speed: 10,
                    stun_type: "short",
                    range: 2,
                    distance: 1.5,
                    targetNum: 1,
                    damage_multiplier: 2,
                    stun_damage_multiplier: 0.4,
                    next_attack_time: 10,
                    Unbreakable: false
                },
                {
                    animation: "minced.ravager.attack_stomp_left",
                    knockback: [3,0],
                    Player_Knockback: [3,0.25],
                    type: "blunt",
                    attack_speed: 10,
                    stun_type: "long",
                    range: 5,
                    distance: 0,
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1.5,
                    next_attack_time: 8,
                    Unbreakable: false
                },
                {
                    animation: "minced.ravager.attack_stomp_right",
                    knockback: [3,0],
                    Player_Knockback: [3,0.25],
                    type: "blunt",
                    attack_speed: 10,
                    stun_type: "long",
                    range: 5,
                    distance: 0,
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1.5,
                    next_attack_time: 8,
                    Unbreakable: false
                },
                {
                    animation: "minced.ravager.attack_stomp",
                    knockback: [3,0],
                    Player_Knockback: [3,0.25],
                    type: "blunt",
                    attack_speed: 20,
                    stun_type: "long",
                    range: 5,
                    distance: 0,
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 2.5,
                    next_attack_time: 8,
                    Unbreakable: false
                },
                {
                    animation: "minced.ravager.attack_kick",
                    knockback: [7,0],
                    Player_Knockback: [1,0.25],
                    type: "blunt",
                    attack_speed: 14,
                    stun_type: "knockdown",
                    range: 5,
                    distance: 0,
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 2,
                    next_attack_time: 20,
                    Unbreakable: false
                }
            ]
        ]
        let atkspd
        let lavander = 5
        let ModeCheck = player.getProperty("aura:color")
        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;
            }
        }
        if(mode == "charge") {
            player.playAnimation(`animation.${animations[0][animChecker]}`)
            let stundamage = 12
            let propCheck = {
                    animation: "minced.ravager.run",
                    knockback: [0.5,0.25],
                    Player_Knockback: [2,0.25],
                    type: "blunt",
                    attack_speed: 2,
                    stun_type: "medium",
                    range: 3,
                    distance: 1,
                    targetNum: 1,
                    damage_multiplier: 1.7,
                    stun_damage_multiplier: 1,
                    next_attack_time: 30
                }
            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
            attackMobHumanoidMeikyu(player, ranger, (lavander * propCheck.damage_multiplier), blckdmg, cd, atkspd, distil, tgtnm, "line_target", effect, knockback, stun, "initial_knockback_to_target", effects, "", stundamage, NAT, true, "no_cooldown", "", 10)
        } else if(mode == "normal") {
            player.playAnimation(`animation.${animations[0][animChecker]}`)
            let stundamage = 12
            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
            if(ModeCheck == 1 && animChecker == 1) {
              let BlackHole = system.runInterval(()=>{
                player.runCommand("execute as @s run tp @e[type=!ravager,tag=!immune,r=5] ^^0.25^1")
              })
              system.runTimeout(()=>{
                system.clearRun(BlackHole)
              },atkspd)
            }
            attackMobHumanoidMeikyu(player, ranger, (lavander * propCheck.damage_multiplier), blckdmg, cd, atkspd, distil, tgtnm, "line_target", effect, knockback, stun, "", effects, 5, stundamage, NAT, true, "no_cooldown", "", 1)
        } else if(mode == "stunned") {
            let stundamage = 30
            let propCheck = {
                animation: "minced.ravager.stunned_roar",
                knockback: [5,0],
                Player_Knockback: [0,0],
                type: "blunt",
                attack_speed: 20,
                stun_type: "medium",
                range: 6,
                distance: 1,
                targetNum: 20,
                damage_multiplier: 1,
                stun_damage_multiplier: 1,
                next_attack_time: 60
            }
            let knockback = propCheck.knockback
            atkspd = propCheck.attack_speed
            let Pknockback = propCheck.Player_Knockback
            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
            system.runTimeout(()=>{
                attackMobHumanoidMeikyu(player, ranger, 20, 200, cd, atkspd, distil, tgtnm, "line_target", effect, knockback, stun, "", effects, 1, stundamage, NAT, true, "", 1)
                player.playAnimation(`animation.minced.ravager.stunned_roar`,{
                    blendOutTime: 0.5,
                    stopExpression: "query.all_animations_finished",
                    nextState: `animation.minced.ravager.base_idle`
                })
                system.runTimeout(()=>{
                    player.setProperty("aura:color",1)
                },(atkspd - 2))
            },20)
           
        }/* else if(mode == "offhand") {
            atkspd = 6
            player.playAnimation(`animation.${animationsOffhand[0][animChecker]}`)
            let knockback = [0,0]
            animChecker != comboNum ? knockback = [0,0] : knockback = [0.25,0.25]
            attackPlayerMeikyu(player, range, lavander, blckdmg, cd, atkspd, distance, targetNum, "line_target", effect, knockback)
        }  else if(mode == "jump") {
            
        } else if(mode == "assasinate") {
            assasinate(player, burn, (lavander * 200), 10, 61)
        }*/
    }
}

export default mob


