import { world, system, ItemStack} from "@minecraft/server";
import { cooldowns } from "./../../util/utils.js";
import { launchPlayer } from "./../../util/movements.js";
import { attackPlayerMeikyu } from "./../../util/attackMethods.js";
import { attackFramerMeikyu } from "./../../util/cameraMoves.js";

const weaponBoost = new Map([
        ["hand_cannon", 3.5],
        ["pistol", 5.5],
        ["grand_cross", 2.5],
    ])

const ability = {
    name: 'R2',
    display_name: "Ram",
    button_icon: "textures/items/diamond",
    registry_name: "ram",
    description: 'Rams Enemies',
    level: "advanced",
    cooldown: 30,
    damages: 15,
    charge_type: "continuous",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["grand_cross"],
    slots: ["ability","charge"],
    execute(player, weaponType, mode, weapon) {
        switch(mode) {
            case "charge": {
                system.runTimeout(()=>{
                    let playerScore = world.scoreboard.getObjective("exhaust").getScore(player)
                    world.scoreboard.getObjective("exhaust").addScore(player, -5)
                    if(playerScore < 5) {
                        return;
                    }
                    player.runCommand("scoreboard players remove @s exhaust 5")
                    player.playAnimation(`animation.minced.${weaponType}.ability_ram`, {
                        stopExpression : "!query.is_using_item"
                    })
                    launchPlayer(player, 1, 0)
                    attackPlayerMeikyu(player, 3, 5, 10, 20, 3, 2, 10, "line_target", [], [5,0.5], "long", "", "blunt", 0, 10, 1, true, "no_cooldown", new ItemStack("pixel:wooden_grand_cross", 1), 1, true)
                },3)
            } break;
            default: {
                const multiplier = weaponBoost.get(weaponType)
                player.runCommand("scoreboard players remove @s exhaust 25")
                player.playAnimation(`animation.minced.${weaponType}.ability_ram`, {
                    stopExpression : "query.all_animations_finished"
                })
                let counter = 0
                let leChocolat = system.runInterval(()=>{
                    if(counter == 10) {
                        system.clearRun(leChocolat)
                    }
                    counter = counter + 1
                    launchPlayer(player, 1, 0.15)
                },3)
                
                let propCheck =  {
                    attackTime: 32,
                    ShowFrames: false,
                    next_attack_time: 10,
                    attackFrameNumber: 10,
                    frames: [
                        {
                            timeStamp: "checkParry",
                            FrameMode: "normal",
                            knockback: [0,1.5],
                            attack_timeFrame: 1
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 3,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 3,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 6,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 9,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 12,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 15,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 18,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 21,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 24,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 27,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "add_frame",
                            FrameMode: "normal",
                            knockback: [0,0.5],
                            Player_Knockback: [1,2],
                            type: "blunt",
                            attack_timeFrame: 30,
                            hit_number: 1,
                            stun_type: "long",
                            knockCheck: "mp",
                            range: 2.5,
                            distanceOffset: {x:0, y: 1, z: 1},
                            targetNum: 10,
                            damage_multiplier: 1,
                            stun_damage_multiplier: 1,
                            Unbreakable: true
                        },
                        {
                            timeStamp: "restore_movement",
                            FrameMode: "normal",
                            attack_timeFrame: 31
                        }
                    ] 
                }
                attackFramerMeikyu(player, propCheck, 10, 20, 10, [], 1, 10, 10, weaponType, true)
                cooldowns(player,this.name,this.cooldown,this.cooldown)
            } break;
        }
        
    }, 
    resetStats(player) {
        let statuser = JSON.parse(player.getDynamicProperty("resetingStatus"))
        statuser["Boost"] = statuser.Boost - 0.2
        player.setDynamicProperty("resetingStatus", JSON.stringify(statuser))
        player.setProperty("aura:color", 0)
    }
}

export default ability