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

const weaponBoost = new Map([
        ["greatsword", 7],
        ["katana", 2.5],
        ["wakizashi", 2.25],
        ["dagger", 1],
        ["glaive", 1.65],
        ["odachi", 3.5],
        ["halberd", 1.75],
        ["longsword", 2],
        ["saber", 2.5],
        ["rapier", 2.5],
    ])

const smasher = new Map([
        ["warhammer",  {
            attackTime: 20,
            animation: "minced.warhammer.ability_smash",
            ShowFrames: false,
            next_attack_time: 10,
            attackFrameNumber: 5,
            frames: [
                {
                    timeStamp: "checkParry",
                    FrameMode: "normal",
                    knockback: [0,0],
                    attack_timeFrame: 1
                },
                {
                    timeStamp: "add_frame",
                    FrameMode: "normal",
                    knockback: [0.25,0],
                    Player_Knockback: [1,0],
                    type: "blunt",
                    attack_timeFrame: 12,
                    hit_number: 1,
                    stun_type: "long",
                    knockCheck: "mp",
                    range: 3.5,
                    distanceOffset: {x:0, y: 1, z: 0.5},
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    Unbreakable: true
                },
               {
                    timeStamp: "add_frame",
                    FrameMode: "normal",
                    knockback: [0.25,0],
                    Player_Knockback: [1,0],
                    type: "blunt",
                    attack_timeFrame: 13,
                    hit_number: 1,
                    stun_type: "long",
                    knockCheck: "mp",
                    range: 3.5,
                    distanceOffset: {x:0, y: 1, z: 1},
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    Unbreakable: true
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 14,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smash_hit_debris"
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 15,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smoker"
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 16,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smash_pushback"
                },
                {
                    timeStamp: "restore_movement",
                    FrameMode: "normal",
                    attack_timeFrame: 20
                },
            ] 
        },],
        ["mace", {
            attackTime: 20,
            animation: "minced.mace.ability_smash",
            ShowFrames: false,
            next_attack_time: 10,
            attackFrameNumber: 5,
            frames: [
                {
                    timeStamp: "checkParry",
                    FrameMode: "normal",
                    knockback: [0,0],
                    attack_timeFrame: 1
                },
                {
                    timeStamp: "add_frame",
                    FrameMode: "normal",
                    knockback: [0.25,0],
                    Player_Knockback: [1,0],
                    type: "blunt",
                    attack_timeFrame: 12,
                    hit_number: 1,
                    stun_type: "long",
                    knockCheck: "mp",
                    range: 3.5,
                    distanceOffset: {x:0, y: 1, z: 0.5},
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    Unbreakable: true
                },
               {
                    timeStamp: "add_frame",
                    FrameMode: "normal",
                    knockback: [0.25,0],
                    Player_Knockback: [1,0],
                    type: "blunt",
                    attack_timeFrame: 13,
                    hit_number: 1,
                    stun_type: "long",
                    knockCheck: "mp",
                    range: 3.5,
                    distanceOffset: {x:0, y: 1, z: 1},
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    Unbreakable: true
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 14,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smash_hit_debris"
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 15,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smoker"
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 16,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smash_pushback"
                },
                {
                    timeStamp: "restore_movement",
                    FrameMode: "normal",
                    attack_timeFrame: 20
                },
            ] 
        }],
        ["gauntlet", {
            attackTime: 20,
            animation: "minced.gauntlet.ability_smash",
            ShowFrames: false,
            next_attack_time: 10,
            attackFrameNumber: 5,
            frames: [
                {
                    timeStamp: "checkParry",
                    FrameMode: "normal",
                    knockback: [0,0],
                    attack_timeFrame: 1
                },
                {
                    timeStamp: "add_frame",
                    FrameMode: "normal",
                    knockback: [0.25,0],
                    Player_Knockback: [1,0],
                    type: "blunt",
                    attack_timeFrame: 8,
                    hit_number: 1,
                    stun_type: "long",
                    knockCheck: "mp",
                    range: 3.5,
                    distanceOffset: {x:0, y: 1, z: 0.5},
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    Unbreakable: true
                },
               {
                    timeStamp: "add_frame",
                    FrameMode: "normal",
                    knockback: [0.25,0],
                    Player_Knockback: [1,0],
                    type: "blunt",
                    attack_timeFrame: 9,
                    hit_number: 1,
                    stun_type: "long",
                    knockCheck: "mp",
                    range: 3.5,
                    distanceOffset: {x:0, y: 1, z: 1},
                    targetNum: 10,
                    damage_multiplier: 1,
                    stun_damage_multiplier: 1,
                    Unbreakable: true
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 10,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smash_hit_debris"
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 11,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smoker"
                },
                {
                    timeStamp: "add_particle_effect",
                    FrameMode: "normal",
                    attack_timeFrame: 12,
                    distanceOffset: {x:0, y: 0, z: 1},
                    particle: "minced:smash_pushback"
                },
                {
                    timeStamp: "restore_movement",
                    FrameMode: "normal",
                    attack_timeFrame: 20
                },
            ] 
        }],
])
const ability = {
    name: 'S8',
    display_name: "Smash Attack",
    button_icon: "textures/items/diamond",
    registry_name: "smash",
    description: 'Smash in front of you to damage enemies deals bleed',
    level: "intermediate",
    cooldown: 10,
    damages: 7,
    charge_type: "charge_till_end",
    charge_count: 3,
    charge_interval: 10,
    canSwitch : false,
    filters: ["warhammer", "mace", "gauntlet"],
    slots: ["ability"],
    horizontal: 0.5,
    vertical: 0,
    execute(player, weaponType, mode, weapon) {
        const cooldown = this.cooldown
        const launch_power = this.horizontal
        const upwards = this.vertical
        let lavander = this.damages
        let blckdmg = 10
        player.runCommand("scoreboard players remove @s exhaust 10")
        let checker = player.isOnGround;
        let equipment = player.getComponent("minecraft:equippable");
        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
        switch(mode) {
          case ("ultimate"): {
            let newChecks = smasher.get(weaponType)
            launchPlayer(player, launch_power, upwards)
            player.playAnimation(`animation.minced.${weaponType}.ability_smash`)
            attackFramerMeikyu(player, newChecks, lavander, blckdmg, 10, [], 0, 20, NAT, weapon, true)
            cooldowns(player,this.name,cooldown,cooldown)
            cooldowns(player,this.name,cooldown,cooldown)
          } break;
          case ("charge"): {
            let newChecks = smasher.get(weaponType)
            launchPlayer(player, launch_power, upwards)
            player.playAnimation(`animation.minced.${weaponType}.ability_smash`)
            attackFramerMeikyu(player, newChecks, lavander, blckdmg, 10, [], 0, 20, NAT, weapon, true)
            cooldowns(player,this.name,cooldown,cooldown)
            cooldowns(player,this.name,cooldown,cooldown)
          } break;
          default: {
            let newChecks = smasher.get(weaponType)
            launchPlayer(player, launch_power, upwards)
            player.playAnimation(`animation.minced.${weaponType}.ability_smash`)
            attackFramerMeikyu(player, newChecks, lavander, blckdmg, 10, [], 0, 20, 10, weapon, true)
            cooldowns(player,this.name,cooldown,cooldown)
          } break;
        }
    }, 
    resetStats(player) {
        
    }
}

export default ability