import { world, EntityDamageCause, system, EntityComponentTypes, MolangVariableMap } from "@minecraft/server";
import { launchPlayer } from "./movements.js";
import weapons from './../weaponTypes/import.js';
import mobs from './../mob_attacks/import.js';
import effects from './../combatEffects/import.js';
import { Vector3, Director } from "./vector3.js";
import { stunLock, coordExtractor, distanceInEnts, getDistance, weaponTypeSplicer ,EnemyClashPower, backShotCheck, calculateDamageTaken} from "./utils.js";
import {JsonDatabase} from "./con-database.js";

let perf = new JsonDatabase("perf")
let comboCounter = new JsonDatabase("comboCounter")
let blockRecovery = new JsonDatabase("blockRecovery")

let knockMap = new Map([
    ["shortest",[2,"staggered_0.1"]],
    ["short",[10,"staggered_0.5"]],
    ["medium",[20,"staggered_1"]],
    ["long",[30,"staggered_1.5"]],
    ["knockdown",[60,"knocked_ground"]],
    ["on_air",[600,"knocked_wall"]]
])

let knockStrength = new Map([
    ["shortest",1],
    ["short",2],
    ["medium",3],
    ["long",4],
    ["knockdown",7],
    ["on_air",12]
])

let blockKnock = new Map([
    ["minecraft:black_wool",0.5],
    ["minecraft:blue_wool",0.5],
    ["minecraft:brown_wool",0.5],
    ["minecraft:cyan_wool",0.5],
    ["minecraft:gray_wool",0.5],
    ["minecraft:green_wool",0.5],
    ["minecraft:light_blue_wool",0.5],
    ["minecraft:light_gray_wool",0.5],
    ["minecraft:lime_wool",0.5],
    ["minecraft:magenta_wool",0.5],
    ["minecraft:orange_wool",0.5],
    ["minecraft:pink_wool",0.5],
    ["minecraft:purple_wool",0.5],
    ["minecraft:red_wool",0.5],
    ["minecraft:white_wool",0.5],
    ["minecraft:yellow_wool",0.5],
    ["minecraft:dirt",0.75],
    ["minecraft:grass_block",1],
    ["minecraft:gravel",0.75],
    ["minecraft:sand",0.75],
    ["minecraft:red_sand",1],
    ["minecraft:air",1],
    ["minecraft:acacia_planks",2],
    ["minecraft:bamboo_planks",2],
    ["minecraft:birch_planks",2],
    ["minecraft:cherry_planks",2],
    ["minecraft:crimson_planks",2],
    ["minecraft:dark_oak_planks",2],
    ["minecraft:jungle_planks",2],
    ["minecraft:mangrove_planks",2],
    ["minecraft:oak_planks",2],
    ["minecraft:pale_oak_planks",2],
    ["minecraft:spruce_planks",2],
    ["minecraft:warped_planks",2],
    ["minecraft:acacia_log",3],
    ["minecraft:bamboo_log",3],
    ["minecraft:birch_log",3],
    ["minecraft:cherry_log",3],
    ["minecraft:crimson_log",3],
    ["minecraft:dark_oak_log",3],
    ["minecraft:jungle_log",3],
    ["minecraft:mangrove_log",3],
    ["minecraft:oak_log",3],
    ["minecraft:pale_oak_log",3],
    ["minecraft:spruce_log",3],
    ["minecraft:warped_log",3],
    ["minecraft:netherrack",3],
    ["minecraft:bricks",3],
    ["minecraft:sandstone",3],
    ["minecraft:red_sandstone",3],
    ["minecraft:cut_sandstone",3],
    ["minecraft:cut_red_sandstone",3],
    ["minecraft:stone",3],
    ["minecraft:smooth_stone",3],
    ["minecraft:stone_bricks",3],
    ["minecraft:cobblestone",3],
    ["minecraft:chiseled_sandstone",4],
    ["minecraft:chiseled_red_sandstone",3],
    ["minecraft:obsidian",7],
    ["minecraft:bedrock",100]
])

let particleMap = new Map([
    ["slash","slashes2"],
    ["blunt","blunt_hit"],
    ["pierce","pierce"],
])

const potionTypes = new Map([
        ["P1", "poison"],
        ["P2", "slowness"],
        ["P3", "wither"],
        ["P4", "weakness"],
        ["P5", "night_vision"],
    ])



let checkInAir = new JsonDatabase("airCheck")

export function getKnockMap(id) {
    return knockMap.get(id)
}

let generalis = world.scoreboard

function calculateAngle(v1, v2) {
    const dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
    const mag1 =  Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
    const mag2 =  Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
    return Math.acos(dot / (mag1 * mag2)) * (180 / Math.PI);
}

async function outsideLooper(player, hell, mode, power) {
    return new Promise((resolve,reject)=>{
        let again
        switch(mode) {
            case "y": {
                again = system.runInterval(()=>{
                    let knocked
                    let loc
                    try {
                        hell != undefined ? knocked = world.scoreboard.getObjective("knocked").getScore(hell) : knocked = 0 
                        loc = coordExtractor(hell, 0.5)
                    }
                    catch(err) {
                        try {
                            player.runCommand("tag @s remove attack")
                        }
                        catch(err) {
                            reject("Entityが死んだ")
                            system.clearRun(again)
                        }
                    }
                    let onGrounds
                    try {
                        onGrounds = hell.isOnGround
                    }
                    catch(err) {
                        try {
                            player.runCommand("tag @s remove attack")
                        }
                        catch(err) {
                            reject("Entityが死んだ")
                            system.clearRun(again)
                        }
                    }
                    try{
                        let lof = Vector3.Add(loc, new Vector3(0,-1,0))
                        let block = hell.dimension.getBlock(lof)
                        if(block != undefined && block.typeId != "minecraft:air") {
                            hell.runCommand(`execute as @s run tp @s ^^^`)
                            resolve({mode: "knockedy", blocker: block})
                            system.clearRun(again)
                        }
                    } catch(err) {
                        reject("Entityが死んだ")
                        system.clearRun(again) 
                    }
                })
            }break;
            case "x": {
                again = system.runInterval(()=>{
                    let knocked
                    let loc0
                    let loc1
                    let loc2
                    try {
                        loc2 = coordExtractor(hell, 2)
                        loc1 = coordExtractor(hell, 1)
                        loc0 = coordExtractor(hell, 0.5)
                    }
                    catch(err) {
                        try {
                            player.runCommand("tag @s remove attack")
                        }
                        catch(err) {
                            reject("Entityが死んだ")
                            system.clearRun(again)
                        }
                    }
                    let onGrounds
                    try {
                        onGrounds = hell.isOnGround
                    }
                    catch(err) {
                        try {
                            player.runCommand("tag @s remove attack")
                        }
                        catch(err) {
                            reject("Entityが死んだ")
                            system.clearRun(again)
                        }
                    }
                    try{
                        let block = hell.dimension.getBlock(Vector3.Add(loc0, Vector3.Scale(hell.getViewDirection(), -1)))
                        let block1 = hell.dimension.getBlock(Vector3.Add(loc1, Vector3.Scale(hell.getViewDirection(), -1)))
                        let block2 = hell.dimension.getBlock(Vector3.Add(loc2, Vector3.Scale(hell.getViewDirection(), -1)))
                        let blocksForSocks
                        block.typeId != "minecraft:air" ? blocksForSocks = block : block.typeId != "minecraft:air" ? blocksForSocks = block1 : block2.typeId != "minecraft:air" ? blocksForSocks = block2 : blocksForSocks = ""
                        if(blocksForSocks != "minecraft:air" && block != undefined && block.typeId != "minecraft:air"||blocksForSocks != "minecraft:air" && block1 != undefined && block1.typeId != "minecraft:air"||blocksForSocks != "minecraft:air" && block2 != undefined && block2.typeId != "minecraft:air") {
                            //hell.runCommand(`execute as @s run tp @s ^^^`)
                            resolve({mode: "knockedx", blocker: blocksForSocks})
                            system.clearRun(again)
                        } else {
                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, Math.max(1, power - 3), 0)
                        }
                    } catch(err) {
                        reject("Entityが死んだ")
                        system.clearRun(again) 
                    }
                })
            } break;
        }
        system.runTimeout(()=>{
            reject("Timed Out")
            system.clearRun(again) 
        },30)
         
    })
   
}

async function outsideLoop(player, hell, power, mode, repeat) {
    let dx = player.location.x - hell.location.x;
    let dy = player.location.y - hell.location.y;
    let dz = player.location.z - hell.location.z;

    let yaw = Math.atan2(dz, dx) * (180 / Math.PI)-90;
    let distanceXZ = Math.sqrt(dx * dx + dz * dz);
    let pitch = -Math.atan2(dy, distanceXZ) * (180 / Math.PI);
    hell.setRotation({x:pitch, y:yaw})
    hell.playAnimation(`animation.zombie_paced.fly_knocked`)
    let wawit = await outsideLooper(player, hell, mode, power)
    let typee 
    let typer = blockKnock.get(wawit.blocker.typeId)
    try{
        if(typer == undefined) {
            typer = 1
        }
        typee = (2 * typer)
    } catch(err) {
        typee = 2
        typer = 1
    }
    let newPower = power - typer
    let distro
    Math.max((newPower - 3 ),1) > 1 || world.gameRules.mobGriefing != false || world.gameRules.tntExplodes != false? distro = true : distro = false
    console.warn(`this is ${wawit.blocker.typeId}`)
    let stuckBro = system.runInterval(()=>{
        try{
            hell.runCommand(`execute as @s run tp @s ^^^`)
        } catch(err) {
            system.clearRun(stuckBro)
        }
        
    })
    switch(wawit.mode) {
        case "knockedx": {
            player.addTag("attack")
            system.runTimeout(()=>{
                hell.playAnimation(`animation.zombie_paced.knocked_wall`, {
                    blendOutTime: 0.5
                })
                hell.dimension.spawnParticle('combat:impact_wall',coordExtractor(hell, 1));
                hell.dimension.spawnParticle('minced:wall_smoke',coordExtractor(hell, 1));
                player.runCommand("tag @s add attack")
                hell.applyDamage((typee), {damagingEntity: player, cause: EntityDamageCause.override })
                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                world.scoreboard.getObjective("combatCooldown").setScore(hell, 20)
                world.scoreboard.getObjective("combatCheck").setScore(hell, 0)
                hell.dimension.createExplosion(hell.location,Math.max((newPower - 3 ),1),{ breaksBlocks: distro})
                player.removeTag("attack")
            },3)
            system.runTimeout(()=>{
                system.clearRun(stuckBro)
                if(newPower > 1 && wawit != "Entityが死んだ") {
                    console.warn(`this is ${newPower}`)
                    hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, newPower, 0)
                    outsideLoop(player, hell, newPower, mode, true)
                }
            },5)
        } break;
        case "knockedy": {
            player.addTag("attack")
            system.runTimeout(()=>{
                hell.playAnimation(`animation.zombie_paced.knocked_ground`)
                hell.dimension.spawnParticle('combat:ground_knock_smoke',hell.location);
                hell.dimension.spawnParticle('combat:ground_knock_smoke_upward',hell.location);
                hell.dimension.spawnParticle('combat:ground_hit_lines',hell.location);
                player.runCommand("tag @s add attack")
                hell.applyDamage(10, {damagingEntity: player, cause: EntityDamageCause.override })
                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                world.scoreboard.getObjective("combatCooldown").setScore(hell, 20)
                world.scoreboard.getObjective("combatCheck").setScore(hell, 0)
                player.removeTag("attack")
                system.clearRun(stuckBro)
            },3)
        } break;
    }
}

async function outsideCounter(player, target, atkspd, dmg, weapon, ability, knockType, stunDamage) {
    player.playAnimation(`animation.minced.${weapon}.ability_${ability}`, {
        stopExpression: "query.all_animations_finished",
    })
    let stun_meter =  target.getProperty("stat:stun_meter")
    let stunThreshold
    let knoks = knockMap.get(knockType)
    let hellPower = JSON.parse(player.getDynamicProperty("resetingStatus"))
    hellPower["counter"] = 0
    player.setDynamicProperty("resetingStatus", JSON.stringify(hellPower))
    target?.typeId == "minecraft:player" ? stunThreshold = 1 : stunThreshold = target.getProperty("stat:stun_threshold")
    system.runTimeout(()=>{
        target.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.override })
        target.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, -2, player.getViewDirection().y + 0.1)
        world.scoreboard.getObjective("stunbreak").setScore(target, 1)
        system.runTimeout(()=>{
            world.scoreboard.getObjective("stunbreak").setScore(target, 0)
        },3)
        if((stun_meter - stunDamage) <= 0 && knockType != "knockdown") {
            player?.triggerEvent("stun:remove")
            target?.triggerEvent(`combat:remove_attack`)
            target?.triggerEvent(`stun:remove`)
            target?.setDynamicProperty("attacking", 1)
            if(target?.typeId == "minecraft:player") {
                target.inputPermissions.movementEnabled = false
                system.runTimeout(()=>{
                    hell.setDynamicProperty("attacking",0)
                    hell.inputPermissions.movementEnabled = true
                },100)
            } else {
                target?.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                target?.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
            }
            world.scoreboard.getObjective("stunTimer")?.setScore(target, 100)
            world.scoreboard.getObjective("stunned")?.setScore(target, 1)
            world.scoreboard.getObjective("stunCheck")?.setScore(target, 1)
            world.scoreboard.getObjective("stunbreak")?.setScore(target, 1)
            hell?.playAnimation(`animation.zombie_paced.stun_broken`)
        } else if((stun_meter - stunDamage) > 0) {
            if(player.getProperty("stat:stun_meter") < 30) {
                player.setProperty("stat:stun_meter",(player.getProperty("stat:stun_meter") + 3))
            }
            if(stunThreshold <= stunDamage) {
                world.scoreboard.getObjective("stunTimer")?.setScore(target, 40)
                world.scoreboard.getObjective("stunCheck")?.setScore(target, 1)
                world.scoreboard.getObjective("stunned")?.setScore(target, 1)
            }
            target?.setProperty("stat:stun_meter", (stun_meter - stunDamage))
            if(stunThreshold <= stunDamage) {
                target?.triggerEvent(`combat:cooldown_${knockType}`)
                if(target?.typeId == "minecraft:player") {
                    target.inputPermissions.movementEnabled = false
                    hell?.setDynamicProperty("attacking", 1)
                    system.runTimeout(()=>{
                        target.inputPermissions.movementEnabled = true
                        hell?.setDynamicProperty("attacking", 0)
                    },knoks[0])
                } else {
                    target?.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                    target?.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                }
                if(!target?.hasTag("Unbreakable")) {
                    target.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                    world.scoreboard.getObjective("stunned").setScore(target, 1)
                }     
            } 
        }
    },atkspd)
    system.runTimeout(()=>{
        player.removeTag("attack")
    },atkspd + 2)
}

function onAirEntity(player,hell) {
    world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
    world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
    world.scoreboard.getObjective("stunned").setScore(hell, 1)
    world.scoreboard.getObjective("combatCooldown").setScore(hell, 20)
    world.scoreboard.getObjective("combatCheck").setScore(hell, 0)
    let klein = system.runInterval(()=>{
        let checksAir = checkInAir.get(hell.id)
        let town
        
        if(checksAir == 0 || checksAir == undefined||hell == undefined) {
            checkInAir.delete(hell.id)
            system.clearRun(klein);
        }
        town = checksAir - 1
        checkInAir.set(hell.id,town)
        let onGrounds
        try{
            hell.runCommand(`execute as @s run tp @s ^^^`)
            onGrounds = hell.isOnGround
        } catch(err){
            system.clearRun(klein)
            checkInAir.delete(hell.id)
        }
        
        if(onGrounds){
            checkInAir.delete(hell.id)
            player.addEffect("slow_falling", 100, { amplifier: 3, showParticles: false })
            launchPlayer(player, 0, 0.75)
            system.clearRun(klein)
            
        }
        player.runCommand(`execute as @s run tp @s ^^^`)
        if(checkInAir <= 0) {
            system.clearRun(klein)
        }
    },20)
}

function targetPickerMeikyu(player, Hitbox, range, notargs) {
    let polter
    let geist = []
    let playerTargetMod = 0
    if(player.typeId == "minecraft:player") {
        playerTargetMod = JSON.parse(player.getDynamicProperty("resetingStatus")).targetNumMod
    }
    let targetBumer = notargs - playerTargetMod
    targetBumer <= 0 ? targetBumer = 1 : targetBumer = targetBumer
    const viewDir = player.getViewDirection();
    const pLoc = player.location;
    if(player.typeId == "minecraft:player") {
        polter = Hitbox.dimension.getEntities({ location: Hitbox.location, excludeNames: [player.name], excludeTypes: ["minecraft:item", "pixel:hit_box", "minecraft:arrow", "minecraft:xp_orb", "pixel:aura", "minced:middle_entity", "minced:ability_table", "minced:ability_writing_table"], excludeFamilies: ["inanimate", "projectiles"],excludeTags:[`${player.name}`, "hit"], maxDistance: 3, closest : targetBumer}).forEach(e => {
        const eLoc = e.location;
        let distancing = Math.abs(distanceInEnts(e.location,Hitbox.location))
            if(distancing <= range) {
                const toEntityVec = {
                    x: eLoc.x - pLoc.x,
                    y: eLoc.y - pLoc.y,
                    z: eLoc.z - pLoc.z
                };
                const angle = calculateAngle(viewDir, toEntityVec);
                if (angle >= -90 && angle <= 90) {
                    geist.push(e)
                }
            }
        })
    } else {
        polter = Hitbox.dimension.getEntities({ location: Hitbox.location, excludeTypes: ["minecraft:item", "pixel:hit_box", "minecraft:arrow", "minecraft:xp_orb", "pixel:aura", "minced:middle_entity", "minced:ability_table", "minced:ability_writing_table", `${player.typeId}`], excludeFamilies: ["inanimate", "projectiles"],excludeTags:[`${player.typeId}`, "hit"], maxDistance: 3, closest : targetBumer}).forEach(e => {
          let distancing = Math.abs(distanceInEnts(e.location,Hitbox.location))
          if(distancing <= range) {
            geist.push(e)
          }
       })
    }
 	
    /*for(let polt of polter) {
        if(polt.typeId == "pixel:hit_box") {
            let array = [polt]
            return array
            break;
        }
    }*/
    return geist
}

function distancedTargetPicker(player, dist) {
    let targetsList = []
    let tgt = player.getEntitiesFromViewDirection({maxDistance:dist,}).filter((hit) => hit?.entity?.typeId != ("minecraft:item"|| "pixel:hit_box"|| "minecraft:arrow"|| "pixel:aura"));
    for(let i = 0; i < (tgt.length - 1); i++) {
         if(!targetsList.includes(tgt[i])) {
            targetsList.push(tgt[i])      
        }
    }
    return targetsList;
}


export function spawnProjectile(player, entity, y, distance, power, mode, bloc, damage, range, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, damageType, hitNumber ) {
    const { x, z } = player.getVelocity();
    const speed = (Math.sqrt(x ** 2 +  z ** 2) * 20).toFixed(1);
    let velocity = parseInt(speed)
    let loc = coordExtractor(player, y)
    let frontLoc = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), distance));
    let strongLoc = Vector3.Scale(player.getViewDirection(), power);
    let NewProjectile = {
        damage: damage,
        range: range,
        blck_damage: block_damage,
        stunDamage: stunDamage,
        atkspd: atkspd,
        distance: dist,
        numberOfTargets: targetNum,
        target_type: targetType,
        effect: effect,
        knockback: launch_power,
        knockType: knockType,
        knockCheck: knockCheck,
        particle: particle,
        damageType: damageType,
        hitNumber: hitNumber
    }
    if(mode == "normal") {
        let proj = player.dimension.spawnEntity(entity, frontLoc)
        const projectileComp = proj?.getComponent('minecraft:projectile');
        system.runTimeout(()=>{
            proj.setDynamicProperty("properties", JSON.stringify(NewProjectile))
            projectileComp?.shoot(strongLoc);
        },1)
        projectileComp.owner = player
        let dx = player.location.x - proj.location.x;
        let dy = player.location.y - proj.location.y;
        let dz = player.location.z - proj.location.z;

        let yaw = Math.atan2(dz, dx) * (180 / Math.PI)-90;
        let distanceXZ = Math.sqrt(dx * dx + dz * dz);
        let pitch = -Math.atan2(dy, distanceXZ) * (180 / Math.PI);
        proj.setRotation({x:pitch, y:yaw})
        
    } else if(mode == "block") {
        let proj = player.dimension.spawnEntity(entity, bloc)
        const projectileComp = proj?.getComponent('minecraft:projectile');
        proj.setDynamicProperty("properties", JSON.stringify(NewProjectile))
        projectileComp?.shoot(strongLoc);
    }
    player.setDynamicProperty("attacking", 0)
    world.scoreboard.getObjective("combatCooldown").setScore(player, 10)
    world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    player.removeTag("attack")
}

async function attackTeleportChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, playerKnock) {
    return new Promise((resolve) => {
        let stunned = world.scoreboard.getObjective("stunned").getScore(player)
        system.runTimeout(() => {
            if (stunned == 1) {
                player.setDynamicProperty("attacking",0)
                player.removeTag("attack")
                player.inputPermissions.movementEnabled = true
                resolve("attack_finished")
            } else if (stunned == 0 && player.getDynamicProperty("attacking")) {
                let loc = coordExtractor(player, 0)
                let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
                let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:${targetType}>`, lof);
                Hit.runCommand(`tag @s add ${player.name}`)
                let target = targetPickerMeikyu(player, Hit, range, targetNum)
                for(let hell of target) {
                    if(hell == undefined){
                        resolve("attack_finished")
                        return
                    }
                    let blocking = hell.hasTag("blocking")
                    let theBag = backShotCheck(player, hell)
                    if(hell.hasTag("attack") && !theBag) {
                        player.triggerEvent("Iframe")
                        player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, -2, player.getViewDirection().y + 0.1)
                        hell.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, -2, player.getViewDirection().y + 0.1)
                        let clash = system.runTimeout(() => {
                            player.triggerEvent("Iframe_remove")
                            
                        },3)
                        
                    } else if(blocking && !theBag) {
                        let equipment = hell.getComponent("minecraft:equippable");
                        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                        let weaponType = weaponTypeSplicer(mainhand)
                        let blocking_reduction = block_damage -  weapons[weaponType].block_power
                        blocking_reduction <= 0 ? blocking_reduction = 0 : blocking_reduction = blocking_reduction
                        hell.runCommand(`execute as @s run scoreboard players remove @s posture ${blocking_reduction}`)
                        hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                        
                    } else {
                        hell.applyDamage(damage, {damagingEntity: player, cause: EntityDamageCause.override })
                        hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                        if(knockCheck == "knock_player") {
                            player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, playerKnock[0], playerKnock[1])
                        }
                        let Hhis = player.dimension.spawnEntity(`pixel:aura`, player.location);
                        Hhis.runCommandAsync(`tp @s ~~~ facing @e[r=5,c=1,type=!pixel:aura,name=!${player.id}]`)
                        switch(particle) {
                            case "blunt": {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                hell.dimension.spawnParticle(`combat:blunt_impact`,hell.location);
                            } break;
                            case "slash": {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                            } break;
                            case "pierce": {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                let lite = hell.dimension.spawnEntity(`minced:pierce_trail`, coordExtractor(hell, 1));
                                lite.setRotation(player.getRotation())
                            } break;
                            default : {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                            } break;
                        }
                        
                        let knoks = knockMap.get(knockType)
                        try{
                            hell.triggerEvent(`combat:cooldown_${knockType}`)
                            hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                        } catch(err) {
                            hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                        }
                        if(launch_power[1] > 0.5){
                            checkInAir.set(hell.id,200)
                            onAirEntity(player, hell)
                            hell.playAnimation('animation.zombie_paced.on_air')
                            hell.triggerEvent("combat:cooldown_on_air")
                        }
                        if(launch_power[0] >= 3 && launch_power[1] < 1.1) {
                            let newLauncher = Math.max((launch_power[0] + (generalis.getObjective("Strength").getScore(player)/10)),0)
                            hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                            outsideLoop(player, hell,newLauncher, "x", false)
                        } else if(launch_power[1] < 0) {
                            let newLauncher = Math.max((launch_power[1] + (generalis.getObjective("Strength").getScore(player)/100)),0)
                            hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                            outsideLoop(player, hell, newLauncher, "y", false)
                        }
                        if(effect !='00' && effect != undefined) {
                            for(let i of effect) {
                                hell.addEffect(`${potionTypes.get(i)}`, 200, { amplifier: 2, showParticles: false })
                                
                            }
                        }
                    }
                }
                resolve("attack_finished")
            }
        },atkspd);
    })
    
}

export async function attackTeleport(player, range, damage, block_damage, cooldown, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle,playerKnock, combo_length) {
    player.addEffect("weakness", atkspd + cooldown, { amplifier: 100, showParticles: false })
    player.inputPermissions.movementEnabled = false
    const waiter = await attackTeleportChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle,playerKnock)
    if(player.getDynamicProperty("combo") >= combo_length && combo_length != "") {
        player.setDynamicProperty("combo",1)
    } else {
        player.setDynamicProperty("combo",(player.getDynamicProperty("combo") + 1))
    }
    system.runTimeout(()=>{
        player.setDynamicProperty("attacking",0)
        player.runCommandAsync(`tp @s ~~~ facing @e[r=5,c=1,type=!pixel:aura,name=!${player.id}]`)
        player.inputPermissions.movementEnabled = true
        player.removeTag("attack")
    },cooldown)
}

export async function assasinate(player, burn, damage, stunTime, atkspd) {
    let timer = 60
    burn.addEffect("slowness", atkspd, { amplifier: 10, showParticles: false })
    if(burn.typeId == "minecraft:player"){
        player.inputPermissions.movementEnabled = false
    }
    player.inputPermissions.movementEnabled = false
    let tisse = system.runInterval(()=>{
        timer = timer - 1
        if(timer == 59) {
            burn.runCommand(`execute as @p at @s anchored eyes rotated ~ 0 positioned ^^0.5^2.5 run camera @s set minecraft:free ease 0.1 linear pos ~~~ facing @s`)
            player.runCommand(`execute as @s run tag @s add attack`)
        }
        if(timer == 45) {
            burn.runCommand(`execute as @s run teleport ${player.name} ^^^-1`)
            player.runCommand(`execute as @p at @s anchored eyes rotated ~ 0 positioned ^^0.5^2.5 run camera @s set minecraft:free ease 0.1 linear pos ~~~ facing @s`)
            burn.applyDamage(damage, {damagingEntity: player, cause: EntityDamageCause.override })
        }
        if(timer == 30) {
            player.runCommand(`execute as @s run camera @s clear`)
            player.runCommand(`execute as @s run tag @s remove attack`)
            if(burn.typeId == "minecraft:player"){
                burn.inputPermissions.movementEnabled = true
            }
            player.setDynamicProperty("combo",1)
            player.setDynamicProperty("attacking",0)
            world.scoreboard.getObjective("combatCooldown").setScore(player, 20)
            world.scoreboard.getObjective("combatCheck").setScore(player, 0)
            player.inputPermissions.movementEnabled = true
            system.clearRun(tisse)
        }
    })
}

export async function executer(player, burn, damage, weaponType, time) {
    let timer = time
    burn.addEffect("slowness", time + 20, { amplifier: 10, showParticles: false })
    if(burn.typeId == "minecraft:player"){
        burn.inputPermissions.movementEnabled = false
    }
    burn?.setDynamicProperty("attacking", 1)
    world.scoreboard.getObjective("stunTimer").setScore(burn, time)
    world.scoreboard.getObjective("stunCheck").setScore(burn, 1)
    world.scoreboard.getObjective("stunned").setScore(burn, 1)
    if(burn.typeId != "minecrat:player") {
        burn.addEffect("weakness", time + 20, { amplifier: 100, showParticles: false })
        burn.addEffect("slowness", time + 20, { amplifier: 100, showParticles: false })
    }
    player.playAnimation(`animation.minced.${weaponType}.attack_execute`)
    burn.playAnimation(`animation.zombie_paced.stun_broken_${weaponType}_execute`,{
        blendOutTime: 0.1,
        stopExpression: "query.all_animations_finished",
        nextState: `animation.zombie_paced.stun_broken`
    })
    player.inputPermissions.movementEnabled = false
    player.runCommand(`execute as @s as @e[c=1,r=10,scores={stunbreak=1}] run teleport @s ^^^0.25`)
    system.runTimeout(()=>{
        system.runTimeout(()=>{
            player.inputPermissions.movementEnabled = true
            player.runCommand(`execute as @s run camera @s clear`)
            player.runCommand(`execute as @s run tag @s remove attack`)
            if(burn.typeId == "minecraft:player"){
                burn.inputPermissions.movementEnabled = true
            }
        },timer)
        system.runTimeout(()=>{
            player.runCommand(`execute as @p at @s anchored eyes rotated ~ 0 positioned ^1^0^ run camera @s set minecraft:free ease 0.1 linear pos ~~~ facing @s`)  
        },Math.floor(timer * 0.9))
        system.runTimeout(()=>{
            player.setDynamicProperty("combo",1)
            player.setDynamicProperty("attacking",0)
            world.scoreboard.getObjective("combatCooldown").setScore(player, 20)
            world.scoreboard.getObjective("combatCheck").setScore(player, 0)
            player.runCommand(`execute as @p at @s anchored eyes rotated ~ 0 positioned ^3.5^-0.7^ run camera @s set minecraft:free ease 0.1 linear pos ~~~ facing @s`)  
        },Math.floor(timer * 0.7))
        system.runTimeout(()=>{
            burn.applyDamage(damage, {damagingEntity: player, cause: EntityDamageCause.override })
            player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
        },Math.floor(timer * 0.6))
        system.runTimeout(()=>{
            player.runCommand(`execute as @s run tag @s add attack`)
        },Math.floor(timer * 0.3))
        system.runTimeout(()=>{
            burn.runCommand(`execute as @p at @s anchored eyes rotated ~ 0 positioned ^5.5^-0.5^ run camera @s set minecraft:free ease 0.1 linear pos ~~~ facing @s`)
        },Math.floor(timer * 0.1))
    })
}


async function doDogdeBack(player, atkspd, dist, knockCheck) {
    return new Promise((resolve) => {
        if(knockCheck == "initial_knockback_to_target") {
            let loc = coordExtractor(player, 0)
            let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
            let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
            Hit.runCommand(`tag @s add ${player.nameTag.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
            try{
                let target = targetPickerMeikyu(player, Hit, 16, 1)
                let entity = target[0] 
                let distance = getDistance(player, entity)
                system.runTimeout(()=>{
                    player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, (distance * 0.5), 0.3)
                },(Math.floor(atkspd * 0.1)))
            } catch(err) {
    
            }
            system.runTimeout(()=>{
                player.addTag("attack")
                resolve("done")
            },(Math.floor(atkspd * 0.5)))
            
        }
    })
    
}

async function DodgeChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item) {
    await doDogdeBack(player, atkspd, dist, knockCheck)
    return new Promise((resolve) => {
        system.runTimeout(() => {
            let stunned = world.scoreboard.getObjective("stunned").getScore(player)
            let clashed = world.scoreboard.getObjective("clash").getScore(player)
            if(clashed == 1) {
                resolve("clashed")
            } else if (stunned == 1 && Unbreakable == false) {
                
                resolve("countered")
            } else if (stunned == 0 && player.getDynamicProperty("attacking")||Unbreakable == true) {
                let loc = coordExtractor(player, 0)
                let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), 0));
                let target
                if(targetType == "line_target") {
                    let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
                    Hit.runCommand(`tag @s add ${player.nameTag.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
                    target = targetPickerMeikyu(player, Hit, range, targetNum)
                } else if(targetType == "distanced") {
                    target = distancedTargetPicker(player, dist)
                }
               
                for(let hell of target) {
                    if(hell == undefined){
                        resolve("attack_finished")
                    }
                    world.scoreboard.getObjective("stunbreak").addScore(hell, 0)
                    let stun_meter =  hell.getProperty("stat:stun_meter") 
                    let blocking = hell.hasTag("blocking")
                    let posture = world.scoreboard.getObjective("posture").getScore(hell)
                    let dmg = calculateDamageTaken(player, damage, particle, hell, item)
                    let theBag = backShotCheck(player, hell)
                    if(hell.hasTag("attack") && !theBag) {
                        player.triggerEvent("Iframe")
                        player.addTag("Immune")
                        world.scoreboard.getObjective("clash").setScore(hell, 1)
                        player.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                        hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 2, 0.2)
                        hell.removeTag("attack")
                        if(hell.typeId == "minecraft:player") {
                            hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                        }
                        player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                        system.runTimeout(() => {
                            player.triggerEvent("Iframe_remove")
                            player.removeTag("Immune")
                            
                        },3)
                        world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                        resolve("clashed")
                    } else if(hell.hasTag("Immune")) {
                        player.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                        if(hell.typeId == "minecraft:player") {
                            hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                        }
                        world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                        resolve("attack_finished")
                    } else if(blocking && !theBag) {
                        let equipment = hell.getComponent("minecraft:equippable");
                        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                        let offhand = equipment?.getEquipmentSlot(`Offhand`)?.getItem()
                        let weaponType = weaponTypeSplicer(mainhand)
                        let weaponTyper = weapons[weaponType]
                        let offhandType = weaponTypeSplicer(offhand)
                        let blockChecker
                        offhandType != "unarmed" && weaponTyper.dual_wield.includes(offhandType) ? blockChecker = `${offhandType}_` : blockChecker = ""
                        let animpref = weaponTyper?.stylePrefixes[hell.getProperty("fighting:style")]
                        animpref == undefined || animpref == "" ? animpref = weaponTyper?.stylePrefixes[0] : animpref = animpref
                        hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                        let blocking_reduction = block_damage -  weapons[weaponType].block_power
                        blocking_reduction <= 0 ? blocking_reduction = 10 : blocking_reduction = blocking_reduction
                        player.runCommand(`execute as @s run camerashake add @s 0.3 0.1`)
                        if((posture - blocking_reduction) <= 0) {
                            world.scoreboard.getObjective("stunned").setScore(hell, 1)
                            stunLock(hell, 20)
                            hell.removeTag("blocking")
                            hell.removeTag("attack")
                            hell.runCommand(`reload`)
                            blockRecovery.set(hell.id,30)
                            hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                            world.scoreboard.getObjective("posture").setScore(hell, 0)
                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                            system.runTimeout(()=>{
                                hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                try{
                                    hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                } catch(err){
                                    console.warn("no entity")
                                }
                            },1)
                        } else {
                            system.runTimeout(()=>{
                                hell.playAnimation(`animation.${animpref}.${blockChecker}block`, 
                                {
                                    blendOutTime: 0.5,
                                    stopExpression: "!query.is_using_item",
                                    nextState: `animation.${animpref}.combat_stance`
                                })
                            },12)
                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                            if(perf.get(hell.id) == 1) {
                                player.triggerEvent(`combat:cooldown_${knockType}`)
                                player.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                player.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                hell.playAnimation(`animation.${animpref}.${blockChecker}parry`,
                                {
                                    blendOutTime: 0.2,
                                    stopExpression: "query.all_animations_finished",
                                    nextState: `animation.${animpref}.${blockChecker}blocking`
                                })
                                world.scoreboard.getObjective("posture").setScore(hell, (posture - Math.floor(blocking_reduction * 0.5)))
                                blockRecovery.set(hell.id,5)
                                resolve("parried")
                            } else {
                                player.triggerEvent(`combat:cooldown_shortest`)
                                player.addEffect("slowness", 2, { amplifier: 100, showParticles: false })
                                player.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                hell.playAnimation(`animation.${animpref}.${blockChecker}hit_on_block`,
                                {
                                    blendOutTime: 0.2,
                                    stopExpression: "query.all_animations_finished",
                                    nextState: `animation.${animpref}.${blockChecker}blocking`
                                })
                                world.scoreboard.getObjective("posture").setScore(hell, (posture - blocking_reduction))
                                blockRecovery.set(hell.id,10)
                                resolve("blocked")
                            }
                        } 
                    } else if(blocking && theBag) {
                        hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                        hell.removeTag("blocking")
                        hell.removeTag("attack")
                        hell.runCommand(`reload`)
                        system.runTimeout(()=>{
                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                            try{
                                hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                            } catch(err){
                                console.warn("no entity")
                            }
                        },1)
                        resolve("attack_finished")
                    } else {
                        if(damageType == "normal") {
                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                        } else if(damageType == "no cooldown") {
                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.override })
                        }  else if(damageType == "true") {
                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.void })
                        }
                       
                        try{
                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                        } catch(err){
                            console.warn("no entity")
                        }
                        
                        if(damage >= 8) {
                            player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                        } else {
                            player.runCommand(`execute as @s run camerashake add @s 0.1 0.1`)
                        }
                        let che4ck = world.scoreboard.getObjective("stunbreak").getScore(hell)
                        let knoks = knockMap.get(knockType)
                        if(knockType == "knockdown" && (stun_meter - stunDamage) <= 0 && che4ck == 0) {
                            try{
                                hell.triggerEvent(`combat:cooldown_${knockType}`)
                                if(hell.typeId == "minecraft:player") {
                                    hell.setDynamicProperty("attacking",1)
                                    hell.inputPermissions.movementEnabled = false
                                    system.runTimeout(()=>{
                                        hell.setDynamicProperty("attacking",0)
                                        hell.inputPermissions.movementEnabled = true
                                    },knoks[0])
                                } else {
                                    hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                    hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                }
                                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                            } catch(err) {
                                hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                            }
                        } else if((stun_meter - stunDamage) <= 0 && knockType != "knockdown" && che4ck == 0) {
                            try{
                                hell.triggerEvent(`combat:remove_attack`)
                                hell.triggerEvent(`stun:remove`)
                                if(hell.typeId == "minecraft:player") {
                                    hell.setDynamicProperty("attacking",1)
                                    hell.inputPermissions.movementEnabled = false
                                    system.runTimeout(()=>{
                                        hell.setDynamicProperty("attacking",0)
                                        hell.inputPermissions.movementEnabled = true
                                    },100)
                                } else {
                                    hell.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                                    hell.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
                                }
                                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                hell.playAnimation(`animation.zombie_paced.stun_broken`)
                                console.warn("broke")
                            } catch(err) {
                                if(hell.typeId == "minecraft:player") {
                                    hell.setDynamicProperty("attacking",1)
                                    hell.inputPermissions.movementEnabled = false
                                    system.runTimeout(()=>{
                                        hell.setDynamicProperty("attacking",0)
                                        hell.inputPermissions.movementEnabled = true
                                    },100)
                                } else {
                                    hell.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                                    hell.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
                                }
                                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                hell.playAnimation(`animation.zombie_paced.stun_broken`)
                            }
                        } else if((stun_meter - stunDamage) > 0 && che4ck == 0) {
                            try{
                                if(che4ck != 1||che4ck == undefined) {
                                    world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                    world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                    hell.setProperty("stat:stun_meter", (stun_meter - stunDamage))
                                }
                            } catch(err) {
                                console.warn("no entity")
                            }
                            try{
                                hell.triggerEvent(`combat:cooldown_${knockType}`)
                                if(hell.typeId == "minecraft:player") {
                                    hell.inputPermissions.movementEnabled = false
                                    hell.setDynamicProperty("attacking",1)
                                    system.runTimeout(()=>{
                                        hell.inputPermissions.movementEnabled = true
                                        hell.setDynamicProperty("attacking",0)
                                    },knoks[0])
                                } else {
                                    hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                    hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                }
                            } catch(err) {
                                if(hell.typeId == "minecraft:player") {
                                    hell.inputPermissions.movementEnabled = false
                                    system.runTimeout(()=>{
                                        hell.inputPermissions.movementEnabled = true
                                    },knoks[0])
                                } else {
                                    hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                    hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                }
                            }
                            hell.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                            
                        }
                        
                        if(knockCheck == "knock_player") {
                            player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                        } else if(knockCheck == "initial_knockback_to_target") {
                            player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, ((launch_power[0] * 0.25) * -1 ), launch_power[1])
                            player.playAnimation(`animation.minced.halberd.attack_backdodge_knockback`)
                        }
                        switch(particle) {
                            case "blunt": {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                hell.dimension.spawnParticle(`combat:blunt_impact`,hell.location);
                            } break;
                            case "slash": {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                            } break;
                            case "pierce": {
                                let lite = hell.dimension.spawnEntity(`minced:pierce_trail`, coordExtractor(hell, 1));
                                lite.setRotation(player.getRotation())
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                hell.dimension.spawnParticle(`combat:impact_accumilate_small`,hell.location);
                            } break;
                            default : {
                                hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                            } break;
                        }
                        
                        if(launch_power[1] > 0.5 && !hell.isOnGround){
                            checkInAir.set(hell.id,200)
                            onAirEntity(player, hell)
                            hell.playAnimation('animation.zombie_paced.on_air')
                            try{
                                hell.triggerEvent("combat:cooldown_on_air")
                            } catch(err) {
                                console.warn("hit entity has no event")
                            }
                           
                        }
                        if(launch_power[0] >= 3 && launch_power[1] < 1.1) {
                            let newLauncher = Math.max((launch_power[0] + (generalis.getObjective("Strength").getScore(player)/10)),0)
                            hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                            outsideLoop(player, hell,newLauncher, "x", false)
                        } else if(launch_power[1] < 0) {
                            let newLauncher = Math.max((launch_power[1] + (generalis.getObjective("Strength").getScore(player)/100)),0)
                            hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                            outsideLoop(player, hell, newLauncher, "y", false)
                        }
                        if(effect !='00' && effect != undefined) {
                            for(let i of effect) {
                                hell.addEffect(`${potionTypes.get(i)}`, 200, { amplifier: 2, showParticles: false })
                                
                            }
                        }
                        resolve("attack_finished")
                    }
                }
                resolve("nothing")
            }
        });
    })
    
}

export async function dodgedAttackPolearm(player, range, damage, block_damage, cooldown, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, combo_length, stunDamage, NAT, Unbreakable, damageType, item) {
    player.addEffect("weakness", atkspd + cooldown, { amplifier: 100, showParticles: false })
    player.inputPermissions.movementEnabled = false
    let comboGet = player.getDynamicProperty("combo")
    world.scoreboard.getObjective("clash").addScore(player, 0)
    if(Unbreakable == true) {
        player.addTag("Unbreakable")
    }
    world.scoreboard.getObjective("stunned").setScore(player, 0)
    const waiter = await DodgeChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item)
    let comboed = false
    let che4ck = world.scoreboard.getObjective("stunbreak").getScore(player)
    player.setProperty("mode:combat", 1)
    player.runCommand("execute as @s run tag @s remove Unbreakable")
    player.removeTag("attack")
    world.scoreboard.getObjective("clash").setScore(player, 0)
    if(comboGet >= combo_length || waiter != ("attack_finished"||"countered"||"clashed"||"blocked")) {
        player.setDynamicProperty("combo",1)
        comboed = true
        system.runTimeout(()=>{
            if(comboed == true || player.getDynamicProperty("attacking") && waiter != "attack_finished" && waiter == "nothing") {
                player.setDynamicProperty("combo",1)
                player.setDynamicProperty("attacking",0)
                if(che4ck != 1) {
                    player.inputPermissions.movementEnabled = true
                }
               
            }
           
        },(cooldown + NAT))
    } else if(player.getDynamicProperty("attacking") && waiter == ("attack_finished"||"blocked") && comboGet <= combo_length) {
        let newCombo = comboGet + 1
        player.setDynamicProperty("combo", newCombo)
        system.runTimeout(()=>{
            player.setDynamicProperty("attacking",0)
            if(che4ck != 1) {
                player.inputPermissions.movementEnabled = true
            }
        },NAT)
        world.scoreboard.getObjective("combatCooldown").setScore(player, (cooldown + NAT))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    } else if(waiter == ("parried")) {
        player.setDynamicProperty("combo",1)
        system.runTimeout(()=>{
            player.setDynamicProperty("attacking",0)
            if(che4ck != 1) {
                player.inputPermissions.movementEnabled = true
            }
        },(NAT + cooldown + 10))
        world.scoreboard.getObjective("combatCooldown").setScore(player, (NAT + cooldown + 10))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    } else if(waiter == ("countered")) {
        world.scoreboard.getObjective("combatCooldown").setScore(player, cooldown)
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    } else if(waiter == ("clashed")) {
        world.scoreboard.getObjective("combatCooldown").setScore(player, Math.floor(cooldown * 0.5))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    }
}

function attackPlayerRepeater(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber) {
    if (Unbreakable == false) {
        EnemyClashPower(player,"start",atkspd)
    }
    system.runTimeout(()=>{  
        player.addTag("attacking")
    },(Math.floor(atkspd * 0.3)))
    system.runTimeout(()=>{
        player.removeTag("parriable")
        player.removeTag("attacking")
        player.addTag("attack")
    },(Math.floor(atkspd * 0.99)))
    return new Promise((resolve) => {
        try{
            system.runTimeout(()=>{ 
                let stunned = world.scoreboard.getObjective("stunned").getScore(player)
                let clashed = world.scoreboard.getObjective("clash").getScore(player)
                let blocker = player.hasTag("blocking")
                let mover = JSON.parse(player.getDynamicProperty("resetingStatus"))
                let trigga = "attack"
                stunned == 1 && Unbreakable == false || blocker|| (mover.inputs[mover.inputs.length - 1] == "back_dodge"||mover.inputs[mover.inputs.length - 1] == "front_dodge")|| (mover.inputs[mover.inputs.length - 1] == "S") ? trigga = "countered" : clashed == 1 ? trigga = "clashed" : trigga = "attack"
                switch(trigga) {
                    case "attack": {
                        let loc = coordExtractor(player, 0)
                        let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
                        let target
                        if(targetType == "line_target") {
                            let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
                            Hit.runCommand(`tag @s add ${player.name?.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
                            target = targetPickerMeikyu(player, Hit, range, targetNum)
                        } else if(targetType == "distanced") {
                            target = distancedTargetPicker(player, dist)
                        }
                        let knoks = knockMap.get(knockType)
                        for(let hell of target) {
                            if(hell == undefined){
                                resolve("attack_finished")
                            }
                            world.scoreboard.getObjective("stunbreak").addScore(hell, 0)
                            let stun_meter =  hell.getProperty("stat:stun_meter") 
                            let blocking = hell.hasTag("blocking")
                            let posture = world.scoreboard.getObjective("posture").getScore(hell)
                            let dmg = calculateDamageTaken(player, damage, particle, hell, item)
                            let theBag = backShotCheck(player, hell)
                            let stunThreshold
                            let statusses = JSON.parse(hell?.getDynamicProperty("resetingStatus"))
                            let PlayerweaponType = weaponTypeSplicer(item)
                            let modem = "attack"
                            hell?.addTag("hit")
                            system.runTimeout(()=>{
                                hell?.removeTag("hit")
                            },7)
                            hell?.typeId == "minecraft:player" ? stunThreshold = 1 : stunThreshold = hell.getProperty("stat:stun_threshold")
                            hell.hasTag("parriable") == true ? modem = "parried" : hell.hasTag("Immune") ? modem = "immune": blocking && !theBag ? modem = "blocked" : blocking && theBag ? modem = "remove_block": modem = modem
                            switch(modem) { 
                                case "parried": {
                                    let ClashWinner
                                    if(hell.typeId == "minecraft:player") {
                                        let equipment = hell.getComponent("minecraft:equippable");
                                        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                                        let weaponType = weaponTypeSplicer(mainhand)
                                        let clashers = weapons[weaponType].clash_power - weapons[PlayerweaponType].clash_power
                                        clashers > 0 ? ClashWinner = "hell" : clashers < 0 ? ClashWinner = "player" : ClashWinner = "both"
                                    } else {
                                        let Typer = hell.getProperty("mob:type")
                                        let clashers = mobs[Typer].clash_power - weapons[PlayerweaponType].clash_power
                                        clashers > 0 ? ClashWinner = "hell" : clashers < 0 ? ClashWinner = "player" : ClashWinner = "both"
                                    }
                                    let Center = new Vector3(((hell.location.x + player.location.x)/2),(((hell.location.y + player.location.y)/2) + 1.25),((hell.location.z + player.location.z)/2))
                                    switch(ClashWinner) {
                                        case "hell": {
                                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                                            player.applyKnockback(player.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                                            hell.applyKnockback(player.getViewDirection().x, hell.getViewDirection().z, -0.7, 0.2)
                                            player.removeTag("attack")
                                            player.removeTag("parriable")
                                            if(player.typeId == "minecraft:player") {
                                                player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            hell.dimension.spawnParticle(`combat:clash_sparkle`,Center);      
                                            player.playAnimation(`animation.minced.${PlayerweaponType}.clash_lost`)
                                            player.runCommand(`execute as @s run camerashake add @s 0.5 0.3`)
                                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                            resolve("attack_finished")
                                        } break;
                                        case "player": {
                                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 2, 0.2)
                                            player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, -0.7, 0.2)
                                            hell.removeTag("attack")
                                            hell.removeTag("parriable")
                                            if(hell.typeId == "minecraft:player") {
                                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            hell.dimension.spawnParticle(`combat:clash_sparkle`,Center);
                                            hell.playAnimation(`animation.zombie_paced.parried`)
                                            player.runCommand(`execute as @s run camerashake add @s 0.5 0.3`)
                                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                            resolve("attack_finished")
                                        } break;
                                        default: {
                                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 2, 0.2)
                                            player.applyKnockback(player.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                                            hell.removeTag("attack")
                                            hell.removeTag("parriable")
                                            player.removeTag("attack")
                                            player.removeTag("parriable")
                                            if(hell.typeId == "minecraft:player") {
                                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            if(player.typeId == "minecraft:player") {
                                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            hell.dimension.spawnParticle(`combat:clash_sparkle`,Center);
                                            hell.playAnimation(`animation.zombie_paced.parried`)
                                            player.playAnimation(`animation.zombie_paced.parried`)
                                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                            resolve("attack_finished")
                                        } break;
                                    }
                                } break;
                                case "immune": {
                                    player.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                                    if(hell.typeId == "minecraft:player") {
                                        hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                    }
                                    world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                    resolve("attack_finished")
                                } break;
                                case "remove_block": {
                                    hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                    hell.removeTag("blocking")
                                    hell.removeTag("attack")
                                    hell.runCommand(`reload`)
                                    system.runTimeout(()=>{
                                        hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                        try{
                                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                        } catch(err){
                                            console.warn("no entity")
                                        }
                                    },1)
                                } break;
                                case "blocked": {
                                    let equipment = hell.getComponent("minecraft:equippable");
                                    let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                                    let weaponType = weaponTypeSplicer(mainhand)
                                    let offhand = equipment?.getEquipmentSlot(`Offhand`)?.getItem()
                                    let weaponTyper = weapons[weaponType]
                                    let offhandType = weaponTypeSplicer(offhand)
                                    let blockChecker
                                    offhandType != "unarmed" && weaponTyper.dual_wield.includes(offhandType) ? blockChecker = `${offhandType}_` : blockChecker = ""
                                    let animpref = weaponTyper?.stylePrefixes[hell.getProperty("fighting:style")]
                                    animpref == undefined || animpref == "" ? animpref = weaponTyper?.stylePrefixes[0] : animpref = animpref
                                    statusses["blockRecovery"] = 10
                                    hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                    let blocking_reduction = block_damage -  weapons[weaponType].block_power
                                    blocking_reduction <= 0 ? blocking_reduction = 10 : blocking_reduction = blocking_reduction
                                    player.runCommand(`execute as @s run camerashake add @s 0.3 0.1`)
                                    if((posture - blocking_reduction) <= 0 && statusses.counter == 0) {
                                        world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                        stunLock(hell, 20)
                                        hell.removeTag("blocking")
                                        hell.removeTag("attack")
                                        hell.runCommand(`reload`)
                                        statusses["blockRecovery"] = 30
                                        if (hell.typeId == "minecraft:player") {
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}guard_break`)
                                        } else  {  
                                            hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                        }
                                        statusses["bide"] = 0
                                        world.scoreboard.getObjective("posture").setScore(hell, 0)
                                        world.getDimension(hell.dimension.id).playSound(`random.${damageType}_small_blocked`,hell.location) 
                                        offhandType == "shield" ? world.getDimension(hell.dimension.id).playSound(`item.shield.block`,hell.location) : world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                        system.runTimeout(()=>{
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                            try{
                                                hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                            } catch(err){
                                                console.warn("no entity")
                                            }
                                        },1)
                                    } else if (statusses.counter >= 1) {
                                        hell.addTag("attack")
                                        outsideCounter(hell, player, atkspd, dmg, animpref, "counter", knockType, stunDamage)
                                    } else {
                                        system.runTimeout(()=>{
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}block`, 
                                            {
                                                blendOutTime: 0.5,
                                                stopExpression: "!query.is_using_item",
                                                nextState: `animation.${animpref}.combat_stance`
                                            })
                                        },12)
                                        offhandType == "shield" ? world.getDimension(hell.dimension.id).playSound(`item.shield.block`,hell.location) : world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                        hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                        if(perf.get(hell.id) == 1) {
                                            player.triggerEvent(`combat:cooldown_${knockType}`)
                                            player.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                            player.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}parry`,
                                            {
                                                blendOutTime: 0.2,
                                                stopExpression: "query.all_animations_finished",
                                                nextState: `animation.${animpref}.${blockChecker}blocking`
                                            })
                                            world.scoreboard.getObjective("posture").setScore(hell, (posture - Math.floor(blocking_reduction * 0.5)))
                                            statusses["blockRecovery"] = 5
                                            tatusses["bide"] = statusses.bide + 6
                                            resolve("parried")
                                        } else {
                                            player.triggerEvent(`combat:cooldown_shortest`)
                                            player.addEffect("slowness", 2, { amplifier: 100, showParticles: false })
                                            player.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}hit_on_block`,
                                            {
                                                blendOutTime: 0.2,
                                                stopExpression: "query.all_animations_finished",
                                                nextState: `animation.${animpref}.${blockChecker}blocking`
                                            })
                                            world.scoreboard.getObjective("posture").setScore(hell, (posture - blocking_reduction))
                                            statusses["blockRecovery"] = 10
                                            statusses["bide"] = statusses.bide + 3
                                            resolve("blocked")
                                        }
                                    }   
                                } break;
                                default: {
                                    switch(damageType) {
                                        case "no cooldown": {
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.override })
                                        } break;
                                        case "true": {
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.void })
                                        } break;
                                        default: {
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                        } break;
                                    }
                        
                                  
                                    hell?.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                    
                                    if(dmg >= 8) {
                                        player.runCommand(`execute as @s run camerashake add @s 0.5 0.5`)
                                    } else  {
                                        player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                    }
                                    world.getDimension(hell.dimension.id).playSound(`random.${particle}_${weapons[PlayerweaponType].weaponSize}_hit`,player.location) 
                                    let che4ck = world.scoreboard.getObjective("stunbreak").getScore(hell)
                                    if(che4ck == 0) {
                                        if(knockType == "knockdown" && (stun_meter - stunDamage) <= 0) {
                                            try{
                                                hell.triggerEvent("stun:remove")
                                                hell.triggerEvent(`combat:cooldown_${knockType}`)
                                                if(hell.typeId == "minecraft:player") {
                                                    hell.setDynamicProperty("attacking",1)
                                                    hell.inputPermissions.movementEnabled = false
                                                    system.runTimeout(()=>{
                                                        hell.setDynamicProperty("attacking",0)
                                                        hell.inputPermissions.movementEnabled = true
                                                    },knoks[0])
                                                } else {
                                                    hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                                    hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                                }
                                                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                                world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                            } catch(err) {
                                                hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                                hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                            }
                                        } else if((stun_meter - stunDamage) <= 0 && knockType != "knockdown") {
                                            player?.triggerEvent("stun:remove")
                                            hell?.triggerEvent(`combat:remove_attack`)
                                            hell?.triggerEvent(`stun:remove`)
                                            hell?.setDynamicProperty("attacking", 1)
                                            if(hell?.typeId == "minecraft:player") {
                                                hell.inputPermissions.movementEnabled = false
                                                system.runTimeout(()=>{
                                                    hell.setDynamicProperty("attacking",0)
                                                    hell.inputPermissions.movementEnabled = true
                                                },100)
                                            } else {
                                                hell?.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                                                hell?.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
                                            }
                                            world.scoreboard.getObjective("stunTimer")?.setScore(hell, 100)
                                            world.scoreboard.getObjective("stunned")?.setScore(hell, 1)
                                            world.scoreboard.getObjective("stunCheck")?.setScore(hell, 1)
                                            world.scoreboard.getObjective("stunbreak")?.setScore(hell, 1)
                                            hell?.playAnimation(`animation.zombie_paced.stun_broken`)
                                        } else if((stun_meter - stunDamage) > 0) {
                                            if(player.getProperty("stat:stun_meter") < 30) {
                                                player.setProperty("stat:stun_meter",(player.getProperty("stat:stun_meter") + 3))
                                            }
                                            if(stunThreshold <= stunDamage) {
                                                world.scoreboard.getObjective("stunTimer")?.setScore(hell, 40)
                                                world.scoreboard.getObjective("stunCheck")?.setScore(hell, 1)
                                                world.scoreboard.getObjective("stunned")?.setScore(hell, 1)
                                            }
                                            hell?.setProperty("stat:stun_meter", (stun_meter - stunDamage))
                                            if(stunThreshold <= stunDamage) {
                                                hell?.triggerEvent(`combat:cooldown_${knockType}`)
                                                if(hell?.typeId == "minecraft:player") {
                                                    hell.inputPermissions.movementEnabled = false
                                                    hell?.setDynamicProperty("attacking", 1)
                                                    system.runTimeout(()=>{
                                                        hell.inputPermissions.movementEnabled = true
                                                        hell?.setDynamicProperty("attacking", 0)
                                                    },knoks[0])
                                                } else {
                                                    hell?.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                                    hell?.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                                }
                                                if(!hell?.hasTag("Unbreakable")) {
                                                    hell.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                                    world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                                }     
                                            } 
                                        }
                                    }
                                    
            
                                    if(knockCheck == "knock_player") {
                                        player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                    } else if(knockCheck == "initial_knockback_to_target") {
                                        player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, ((launch_power[0] * 0.5) * -1 ), launch_power[1])
                                    }
                                    switch(particle) {
                                        case "blunt": {
                                            let Loa = coordExtractor(hell,1)
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                            hell.dimension.spawnParticle(`combat:blunt_impact`,Loa);
                                        } break;
                                        case "slash": {
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                        } break;
                                        case "pierce": {
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                            hell.dimension.spawnParticle(`combat:impact_accumilate_small`,hell.location);
                                            let Mapper = new MolangVariableMap()
                                            let lite = hell.dimension.spawnEntity(`minced:pierce_trail`, coordExtractor(hell, 1));
                                            lite.setRotation(player.getRotation())
                                            Mapper.setSpeedAndDirection("actor", 0, player.getViewDirection())
                                            hell.dimension.spawnParticle(`combat:rapier_piercer`,hell.location, Mapper);
                                        } break;
                                        default : {
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                        } break;
                                    }
                                    
                                    if(launch_power[1] > 0.5){
                                        checkInAir.set(hell.id,200)
                                        onAirEntity(player, hell)
                                        hell.playAnimation('animation.zombie_paced.on_air')
                                        try{
                                            hell.triggerEvent("combat:cooldown_on_air")
                                        } catch(err) {
                                            console.warn("hit entity has no event")
                                        }  
                                    }
                                    if(launch_power[0] >= 3 && launch_power[1] < 1.1) {
                                        let newLauncher = Math.max((launch_power[0] + (generalis.getObjective("Strength").getScore(player)/10)),0)
                                        hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                                        outsideLoop(player, hell,newLauncher, "x", false)
                                    } else if(launch_power[1] < 0) {
                                        let newLauncher = Math.max((launch_power[1] + (generalis.getObjective("Strength").getScore(player)/100)),0)
                                        hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                                        outsideLoop(player, hell, newLauncher, "y", false)
                                    }
                                    for(let ce of effect) {
                                        if(ce != "00" && ce != "" && ce != undefined)
                                            
                                        try{
                                           effects[ce].execute(player, hell, "", dmg) 
                                        } catch(err) {
                                            console.warn(err)
                                        }
                                       
                                    /*switch(ce) {
                                        default: {
                                            if(ce !='00' && ce != undefined && ce != '') {
                                                for(let i of effect) {
                                                    hell.addEffect(`${potionTypes.get(i)}`, 200, { amplifier: 2, showParticles: false })
                                                        
                                                }
                                            }
                                        } break;
                                    }*/
                                    }  
                                    resolve("attack_finished")
                                } break;
                            }
                            hell.setDynamicProperty("resetingStatus", JSON.stringify(statusses))
                        }
                        resolve("attack_finished")
                    } break; 
                    default: {
                        resolve(trigga)
                    } break;
                }
            },atkspd)
        } catch(err) {
            resolve("attack_nothing")
        }
    })
    
}

async function attackPlayerChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber) {
    let comboers
    let hits = 0
    if(knockCheck == "initial_knockback_to_target") {
        let loc = coordExtractor(player, 0)
        let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
        let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
        Hit.runCommand(`tag @s add ${player.nameTag.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
        try{
            let target = targetPickerMeikyu(player, Hit, 16, 1)
            let entity = target[0] 
            let distance = getDistance(player, entity)
            const dista = (distance * 2)
            let rover = system.runInterval(()=>{
                player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, dista, 1)
            },(Math.floor(atkspd * 0.1)))
            system.runTimeout(()=>{
                system.clearRun(rover)
            },atkspd)
        } catch(err) {
            console.warn(`${err}`)
        }
    }
    if(knockCheck == "jump_attack"){
        let loc = coordExtractor(player, 0)
        let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
        let target = distancedTargetPicker(player, (dist + 5))
        for(let Jk of target){
            let distance = getDistance(player,Jk)
            launchPlayer(player, distance, 0.6)
        }
    }
    while (hits < hitNumber && comboers != "clashed" && comboers != "countered") {
        player.removeTag("attack")
        world.scoreboard.getObjective("clash").setScore(player, 0)
        let comboer = await attackPlayerRepeater(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber)
        comboers = comboer
        hits = hits + 1;
        player.removeTag("parriable")
    };
    return new Promise((resolve) => {
        if(hits >= hitNumber||comboers == "clashed"||comboers == "countered") {
            resolve(comboers)
        }
    })
    
}

export async function attackPlayerMeikyu(player, range, damage, block_damage, cooldown, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, combo_length, stunDamage, NAT, Unbreakable, damageType, item, hitNumber, inputDisabled) {
    player.addEffect("weakness", atkspd + cooldown, { amplifier: 100, showParticles: false })
    
    if(inputDisabled == true) {
        try{
            player.inputPermissions.movementEnabled = false
        } catch (e) {
            player.addEffect("slowness", atkspd , { amplifier: 100, showParticles: false })
        }
    }
    let comboGet = player.getDynamicProperty("combo")
    world.scoreboard.getObjective("clash").addScore(player, 0)
    if(Unbreakable == true) {
        player.addTag("Unbreakable")
    }
    world.scoreboard.getObjective("stunned").setScore(player, 0)
    const waiter = await attackPlayerChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber)
    let statusUpdate = JSON.parse(player.getDynamicProperty("resetingStatus"))
    let comboed = false
    let che4ck = world.scoreboard.getObjective("stunbreak").getScore(player)
    player.setProperty("mode:combat", 1)
    player.removeTag("Unbrekable")
    player.removeTag("attack")
    world.scoreboard.getObjective("clash").setScore(player, 0)
    if(comboGet >= combo_length && ( waiter != "countered" && waiter != "clashed")) {
        player.setDynamicProperty("combo",1)
        comboed = true
        statusUpdate["powerBar"] = statusUpdate.powerBar + Math.floor((damage/3))
        statusUpdate.powerBar >= 100 ? statusUpdate["powerBarTrigger"] = 1 : statusUpdate["powerBarTrigger"] = 0
        player.setDynamicProperty("resetingStatus", JSON.stringify(statusUpdate))
        system.runTimeout(()=>{
            if(comboed == true || player.getDynamicProperty("attacking") == 1 && waiter != "attack_finished" && waiter == "nothing") {
                player.setDynamicProperty("combo",1)
                player.setDynamicProperty("attacking",0)
                if(che4ck != 1 && inputDisabled == true) {
                    try{
                        player.inputPermissions.movementEnabled = true
                    } catch (e) {
                        
                    }
                }
               
            }
           
        },(cooldown + NAT))
        if(comboGet >= combo_length) {
            if(comboCounter.get(player.id) == 1){
                comboCounter.set(player.id,2)
            } else {
                comboCounter.set(player.id,1)
            }
           
        }
    } else if(waiter == "attack_finished" && comboGet <= combo_length) {
        let newCombo = comboGet + 1
        player.setDynamicProperty("combo", newCombo)
        statusUpdate["powerBar"] = statusUpdate.powerBar + Math.floor((damage/3))
        statusUpdate.powerBar >= 100 ? statusUpdate["powerBarTrigger"] = 1 : statusUpdate["powerBarTrigger"] = 0
        player.setDynamicProperty("resetingStatus", JSON.stringify(statusUpdate))
        system.runTimeout(()=>{
            player.setDynamicProperty("attacking",0)
            if(che4ck != 1 && inputDisabled == true) {
                try{
                    player.inputPermissions.movementEnabled = true
                } catch (e) {
                        
                }
            }
        },NAT)
        if(knockCheck == "after_attack" && waiter == "attack_finished") {
            system.runTimeout(()=>{
                player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
            },3)
            
        }
        world.scoreboard.getObjective("combatCooldown").setScore(player, (cooldown + NAT))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    } else if(waiter == ("parried")) {
        player.setDynamicProperty("combo",1)
        system.runTimeout(()=>{
            player.setDynamicProperty("attacking",0)
            if(che4ck != 1 && inputDisabled == true) {
                try{
                    player.inputPermissions.movementEnabled = true
                } catch (e) {
                        
                }
            }
        },(NAT + cooldown + (20 + (20 * (weapons[weaponTypeSplicer(item)].block_power) / 100))))
        if(player.getProperty("stat:stun_meter") <= 30) {
            player.setProperty("stat:stun_meter",(player.getProperty("stat:stun_meter") - 3))
        }
        world.scoreboard.getObjective("combatCooldown").setScore(player, (NAT + cooldown + (20 * (weapons[weaponTypeSplicer(item)].block_power) / 100)))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    } else if(waiter == ("blocked")) {
        let newCombo = comboGet + 1
        player.setDynamicProperty("combo", newCombo)
        system.runTimeout(()=>{
            player.setDynamicProperty("attacking",0)
            if(che4ck != 1 && inputDisabled == true) {
                try{
                    player.inputPermissions.movementEnabled = true
                } catch (e) {
                        
                }
            }
        },(NAT + cooldown + 10))
        world.scoreboard.getObjective("combatCooldown").setScore(player, (NAT + cooldown + 10))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
    } else if(waiter == ("countered")) {
        world.scoreboard.getObjective("combatCooldown").setScore(player, cooldown)
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
        if(inputDisabled == true) {
            try{
                player.inputPermissions.movementEnabled = true
            } catch (e) {
                        
            }
        }
    } else if(waiter == ("clashed")) {
        world.scoreboard.getObjective("combatCooldown").setScore(player, Math.floor(cooldown + 20))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
        if(inputDisabled == true) {
            try{
                player.inputPermissions.movementEnabled = true
            } catch (e) {
                        
            }
        }
        statusUpdate["powerBar"] = statusUpdate.powerBar + Math.floor((damage/3))
        statusUpdate.powerBar >= 100 ? statusUpdate["powerBarTrigger"] = 1 : statusUpdate["powerBarTrigger"] = 0
        player.setDynamicProperty("resetingStatus", JSON.stringify(statusUpdate))
    } else {
        world.scoreboard.getObjective("combatCooldown").setScore(player, Math.floor(cooldown * 0.5))
        world.scoreboard.getObjective("combatCheck").setScore(player, 0)
        if(inputDisabled == true) {
            try{
                player.inputPermissions.movementEnabled = true
            } catch (e) {
                        
            }
        }
    }
}



export async function attackFrameDated(player, atkspd, range, damage, block_damage, distanceOffset, targetNum, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item) {
    player.removeTag("parriable")
    player.removeTag("attacking")
    player.addTag("attack")
    return new Promise((resolve) => {
        try{
            system.runTimeout(()=>{ 
                let stunned = world.scoreboard.getObjective("stunned").getScore(player)
                let clashed = world.scoreboard.getObjective("clash").getScore(player)
                let blocker = player.hasTag("blocking")
                let mover = JSON.parse(player.getDynamicProperty("resetingStatus"))
                let trigga = "attack"
                stunned == 1 && Unbreakable == false || blocker|| (mover.inputs[mover.inputs.length - 1] == "back_dodge"||mover.inputs[mover.inputs.length - 1] == "front_dodge")|| (mover.inputs[mover.inputs.length - 1] == "S") ? trigga = "countered" : clashed == 1 ? trigga = "clashed" : trigga = "attack"
                switch(trigga) {
                    case "attack": {
                        let lof = Director(player.getViewDirection(), player.location, distanceOffset)
                        let target
                        let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
                        Hit.runCommand(`tag @s add ${player.nameTag.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
                        target = targetPickerMeikyu(player, Hit, range, targetNum)
                        let knoks = knockMap.get(knockType)
                        for(let hell of target) {
                            if(hell == undefined){
                                resolve("attack_finished")
                            }
                            world.scoreboard.getObjective("stunbreak").addScore(hell, 0)
                            let stun_meter =  hell.getProperty("stat:stun_meter") 
                            let blocking = hell.hasTag("blocking")
                            let posture = world.scoreboard.getObjective("posture").getScore(hell)
                            let dmg = calculateDamageTaken(player, damage, particle, hell, item)
                            let theBag = backShotCheck(player, hell)
                            let stunThreshold
                            let statusses = JSON.parse(hell?.getDynamicProperty("resetingStatus"))
                            let PlayerweaponType = weaponTypeSplicer(item)
                            let modem = "attack"
                            hell?.addTag("hit")
                            system.runTimeout(()=>{
                                hell?.removeTag("hit")
                            },7)
                            hell?.typeId == "minecraft:player" ? stunThreshold = 1 : stunThreshold = hell.getProperty("stat:stun_threshold")
                            hell.hasTag("parriable") == true ? modem = "parried" : hell.hasTag("Immune") ? modem = "immune": blocking && !theBag ? modem = "blocked" : blocking && theBag ? modem = "remove_block": modem = modem
                            switch(modem) { 
                                case "parried": {
                                    let ClashWinner
                                    if(hell.typeId == "minecraft:player") {
                                        let equipment = hell.getComponent("minecraft:equippable");
                                        let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                                        let weaponType = weaponTypeSplicer(mainhand)
                                        let clashers = weapons[weaponType].clash_power - weapons[PlayerweaponType].clash_power
                                        clashers > 0 ? ClashWinner = "hell" : clashers < 0 ? ClashWinner = "player" : ClashWinner = "both"
                                    } else {
                                        let Typer = hell.getProperty("mob:type")
                                        let clashers = mobs[Typer].clash_power - weapons[PlayerweaponType].clash_power
                                        clashers > 0 ? ClashWinner = "hell" : clashers < 0 ? ClashWinner = "player" : ClashWinner = "both"
                                    }
                                    let Center = new Vector3(((hell.location.x + player.location.x)/2),(((hell.location.y + player.location.y)/2) + 1.25),((hell.location.z + player.location.z)/2))
                                    switch(ClashWinner) {
                                        case "hell": {
                                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                                            player.applyKnockback(player.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                                            hell.applyKnockback(player.getViewDirection().x, hell.getViewDirection().z, -0.7, 0.2)
                                            player.removeTag("attack")
                                            player.removeTag("parriable")
                                            if(player.typeId == "minecraft:player") {
                                                player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            hell.dimension.spawnParticle(`combat:clash_sparkle`,Center);      
                                            player.playAnimation(`animation.minced.${PlayerweaponType}.clash_lost`)
                                            player.runCommand(`execute as @s run camerashake add @s 0.5 0.3`)
                                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                            resolve("attack_finished")
                                        } break;
                                        case "player": {
                                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 2, 0.2)
                                            player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, -0.7, 0.2)
                                            hell.removeTag("attack")
                                            hell.removeTag("parriable")
                                            if(hell.typeId == "minecraft:player") {
                                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            hell.dimension.spawnParticle(`combat:clash_sparkle`,Center);
                                            hell.playAnimation(`animation.zombie_paced.parried`)
                                            player.runCommand(`execute as @s run camerashake add @s 0.5 0.3`)
                                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                            resolve("attack_finished")
                                        } break;
                                        default: {
                                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 2, 0.2)
                                            player.applyKnockback(player.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                                            hell.removeTag("attack")
                                            hell.removeTag("parriable")
                                            player.removeTag("attack")
                                            player.removeTag("parriable")
                                            if(hell.typeId == "minecraft:player") {
                                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            if(player.typeId == "minecraft:player") {
                                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                            }
                                            hell.dimension.spawnParticle(`combat:clash_sparkle`,Center);
                                            hell.playAnimation(`animation.zombie_paced.parried`)
                                            player.playAnimation(`animation.zombie_paced.parried`)
                                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                            resolve("attack_finished")
                                        } break;
                                    }
                                } break;
                                case "immune": {
                                    player.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                                    if(hell.typeId == "minecraft:player") {
                                        hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                    }
                                    world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                    resolve("attack_finished")
                                } break;
                                case "remove_block": {
                                    hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                    hell.removeTag("blocking")
                                    hell.removeTag("attack")
                                    hell.runCommand(`reload`)
                                    system.runTimeout(()=>{
                                        hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                        try{
                                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                        } catch(err){
                                            console.warn("no entity")
                                        }
                                    },1)
                                } break;
                                case "blocked": {
                                    let equipment = hell.getComponent("minecraft:equippable");
                                    let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                                    let weaponType = weaponTypeSplicer(mainhand)
                                    let offhand = equipment?.getEquipmentSlot(`Offhand`)?.getItem()
                                    let weaponTyper = weapons[weaponType]
                                    let offhandType = weaponTypeSplicer(offhand)
                                    let blockChecker
                                    offhandType != "unarmed" && weaponTyper.dual_wield.includes(offhandType) ? blockChecker = `${offhandType}_` : blockChecker = ""
                                    let animpref = weaponTyper?.stylePrefixes[hell.getProperty("fighting:style")]
                                    animpref == undefined || animpref == "" ? animpref = weaponTyper?.stylePrefixes[0] : animpref = animpref
                                    statusses["blockRecovery"] = 10
                                    hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                    let blocking_reduction = block_damage -  weapons[weaponType].block_power
                                    blocking_reduction <= 0 ? blocking_reduction = 10 : blocking_reduction = blocking_reduction
                                    player.runCommand(`execute as @s run camerashake add @s 0.3 0.1`)
                                    if((posture - blocking_reduction) <= 0 && statusses.counter == 0) {
                                        world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                        stunLock(hell, 20)
                                        hell.removeTag("blocking")
                                        hell.removeTag("attack")
                                        hell.runCommand(`reload`)
                                        statusses["blockRecovery"] = 30
                                        statusses["bide"] = 0
                                        if (hell.typeId == "minecraft:player") {
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}guard_break`)
                                        } else  {  
                                            hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                        }
                                        world.scoreboard.getObjective("posture").setScore(hell, 0)
                                        world.getDimension(hell.dimension.id).playSound(`random.${damageType}_small_blocked`,hell.location) 
                                        offhandType == "shield" ? world.getDimension(hell.dimension.id).playSound(`item.shield.block`,hell.location) : world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                        system.runTimeout(()=>{
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                            try{
                                                hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                            } catch(err){
                                                console.warn("no entity")
                                            }
                                        },1)
                                    } else if (statusses.counter >= 1) {
                                        hell.addTag("attack")
                                        outsideCounter(hell, player, atkspd, dmg, animpref, "full_counter", knockType, stunDamage)
                                    } else {
                                        system.runTimeout(()=>{
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}block`, 
                                            {
                                                blendOutTime: 0.5,
                                                stopExpression: "!query.is_using_item",
                                                nextState: `animation.${animpref}.combat_stance`
                                            })
                                        },12)
                                        offhandType == "shield" ? world.getDimension(hell.dimension.id).playSound(`item.shield.block`,hell.location) : world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                        hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                        if(perf.get(hell.id) == 1) {
                                            player.triggerEvent(`combat:cooldown_${knockType}`)
                                            player.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                            player.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}parry`,
                                            {
                                                blendOutTime: 0.2,
                                                stopExpression: "query.all_animations_finished",
                                                nextState: `animation.${animpref}.${blockChecker}blocking`
                                            })
                                            world.scoreboard.getObjective("posture").setScore(hell, (posture - Math.floor(blocking_reduction * 0.5)))
                                            statusses["blockRecovery"] = 5
                                            statusses["bide"] = statusses.bide + 6
                                            resolve("parried")
                                        } else {
                                            player.triggerEvent(`combat:cooldown_shortest`)
                                            player.addEffect("slowness", 2, { amplifier: 100, showParticles: false })
                                            player.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                            hell.playAnimation(`animation.${animpref}.${blockChecker}hit_on_block`,
                                            {
                                                blendOutTime: 0.2,
                                                stopExpression: "query.all_animations_finished",
                                                nextState: `animation.${animpref}.${blockChecker}blocking`
                                            })
                                            world.scoreboard.getObjective("posture").setScore(hell, (posture - blocking_reduction))
                                            statusses["blockRecovery"] = 10
                                            statusses["bide"] = statusses.bide + 3
                                            resolve("blocked")
                                        }
                                    }   
                                } break;
                                default: {
                                    switch(damageType) {
                                        case "no cooldown": {
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.override })
                                        } break;
                                        case "true": {
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.void })
                                        } break;
                                        default: {
                                            hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                        } break;
                                    }
                        
                                  
                                    hell?.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                    
                                    if(dmg >= 8) {
                                        player.runCommand(`execute as @s run camerashake add @s 0.5 0.5`)
                                    } else  {
                                        player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                                    }
                                    world.getDimension(hell.dimension.id).playSound(`random.${particle}_${weapons[PlayerweaponType].weaponSize}_hit`,player.location) 
                                    let che4ck = world.scoreboard.getObjective("stunbreak").getScore(hell)
                                    if(che4ck == 0) {
                                        if(knockType == "knockdown" && (stun_meter - stunDamage) <= 0) {
                                            try{
                                                hell.triggerEvent("stun:remove")
                                                hell.triggerEvent(`combat:cooldown_${knockType}`)
                                                if(hell.typeId == "minecraft:player") {
                                                    hell.setDynamicProperty("attacking",1)
                                                    hell.inputPermissions.movementEnabled = false
                                                    system.runTimeout(()=>{
                                                        hell.setDynamicProperty("attacking",0)
                                                        hell.inputPermissions.movementEnabled = true
                                                    },knoks[0])
                                                } else {
                                                    hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                                    hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                                }
                                                world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                                world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                                world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                            } catch(err) {
                                                hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                                hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                            }
                                        } else if((stun_meter - stunDamage) <= 0 && knockType != "knockdown") {
                                            player?.triggerEvent("stun:remove")
                                            hell?.triggerEvent(`combat:remove_attack`)
                                            hell?.triggerEvent(`stun:remove`)
                                            hell?.setDynamicProperty("attacking",1)
                                            if(hell?.typeId == "minecraft:player") {
                                                hell.inputPermissions.movementEnabled = false
                                                system.runTimeout(()=>{
                                                    hell?.setDynamicProperty("attacking",0)
                                                    hell.inputPermissions.movementEnabled = true
                                                },100)
                                            } else {
                                                hell?.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                                                hell?.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
                                            }
                                            world.scoreboard.getObjective("stunTimer")?.setScore(hell, 100)
                                            world.scoreboard.getObjective("stunned")?.setScore(hell, 1)
                                            world.scoreboard.getObjective("stunCheck")?.setScore(hell, 1)
                                            world.scoreboard.getObjective("stunbreak")?.setScore(hell, 1)
                                            hell?.playAnimation(`animation.zombie_paced.stun_broken`)
                                        } else if((stun_meter - stunDamage) > 0) {
                                            if(player.getProperty("stat:stun_meter") < 30) {
                                                player.setProperty("stat:stun_meter",(player.getProperty("stat:stun_meter") + 3))
                                            }
                                            if(stunThreshold <= stunDamage) {
                                                world.scoreboard.getObjective("stunTimer")?.setScore(hell, 40)
                                                world.scoreboard.getObjective("stunCheck")?.setScore(hell, 1)
                                                world.scoreboard.getObjective("stunned")?.setScore(hell, 1)
                                            }
                                            hell?.setProperty("stat:stun_meter", (stun_meter - stunDamage))
                                            if(stunThreshold <= stunDamage) {
                                                hell?.triggerEvent(`combat:cooldown_${knockType}`)
                                                if(hell?.typeId == "minecraft:player") {
                                                    hell.inputPermissions.movementEnabled = false
                                                    hell?.setDynamicProperty("attacking", 1)
                                                    system.runTimeout(()=>{
                                                        hell.inputPermissions.movementEnabled = true
                                                        hell?.setDynamicProperty("attacking", 0)
                                                    },knoks[0])
                                                } else {
                                                    hell?.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                                    hell?.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                                }
                                                if(!hell?.hasTag("Unbreakable")) {
                                                    hell.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                                    world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                                }     
                                            } 
                                        }
                                    }
                                    
            
                                    if(knockCheck == "knock_player") {
                                        player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                    } else if(knockCheck == "initial_knockback_to_target") {
                                        player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, ((launch_power[0] * 0.5) * -1 ), launch_power[1])
                                    }
                                    switch(particle) {
                                        case "blunt": {
                                            let Loa = coordExtractor(hell,1)
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                            hell.dimension.spawnParticle(`combat:blunt_impact`,Loa);
                                        } break;
                                        case "slash": {
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                        } break;
                                        case "pierce": {
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                            hell.dimension.spawnParticle(`combat:impact_accumilate_small`,hell.location);
                                        } break;
                                        default : {
                                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                                        } break;
                                    }
                                    
                                    if(launch_power[1] > 0.5){
                                        checkInAir.set(hell.id,200)
                                        onAirEntity(player, hell)
                                        hell.playAnimation('animation.zombie_paced.on_air')
                                        try{
                                            hell.triggerEvent("combat:cooldown_on_air")
                                        } catch(err) {
                                            console.warn("hit entity has no event")
                                        }  
                                    }
                                    if(launch_power[0] >= 3 && launch_power[1] < 1.1) {
                                        let newLauncher = Math.max((launch_power[0] + (generalis.getObjective("Strength").getScore(player)/10)),0)
                                        hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                                        outsideLoop(player, hell,newLauncher, "x", false)
                                    } else if(launch_power[1] < 0) {
                                        let newLauncher = Math.max((launch_power[1] + (generalis.getObjective("Strength").getScore(player)/100)),0)
                                        hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                                        outsideLoop(player, hell, newLauncher, "y", false)
                                    }
                                    for(let ce of effect) {
                                        if(ce != "00" && ce != "" && ce != undefined)
                                            
                                        try{
                                           effects[ce].execute(player, hell, "", dmg)
                                        } catch(err) {
                                            console.warn(err)
                                        }
                                       
                                    /*switch(ce) {
                                        default: {
                                            if(ce !='00' && ce != undefined && ce != '') {
                                                for(let i of effect) {
                                                    hell.addEffect(`${potionTypes.get(i)}`, 200, { amplifier: 2, showParticles: false })
                                                        
                                                }
                                            }
                                        } break;
                                    }*/
                                    }  
                                    resolve("attack_finished")
                                } break;
                            }
                            hell.setDynamicProperty("resetingStatus", JSON.stringify(statusses))
                        }
                        resolve("attack_finished")
                    } break; 
                    default: {
                        resolve(trigga)
                    } break;
                }
            },atkspd)
        } catch(err) {
            resolve("attack_nothing")
        }
    })
}




async function attackMobRepeater(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item) {
    if (Unbreakable == false) {
        EnemyClashPower(player,"start",atkspd)
    }
    system.runTimeout(()=>{
        player.addTag("attacking")
    },(Math.floor(atkspd * 0.3)))
   
   
    system.runTimeout(()=>{
        player.removeTag("parriable")
        player.removeTag("attacking")
        player.addTag("attack")
    },(Math.floor(atkspd * 0.99)))
    return new Promise((resolve) => { 
        try{
            system.runTimeout(() => {
                let stunned = world.scoreboard.getObjective("stunned").getScore(player)
                let clashed = world.scoreboard.getObjective("clash").getScore(player)
                let blocker
                try {
                    blocker = player.hasTag("blocking")
                }
                catch(err) {
                    blocker = false
                }
                if(clashed == 1) {
                    resolve("clashed")
                } else if (stunned == 1 && Unbreakable == false || blocker) {
                    resolve("countered")
                } else if (stunned == 0 && player.getDynamicProperty("attacking") == 1||Unbreakable == true) {
                    let loc = coordExtractor(player, 0)
                    let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
                    let target
                    if(targetType == "line_target") {
                        let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
                        target = targetPickerMeikyu(player, Hit, range, targetNum)
                    } else if(targetType == "distanced") {
                        target = distancedTargetPicker(player, dist)
                    }
                   
                    for(let hell of target) {
                        if(hell == undefined){
                            resolve("attack_finished")
                        }
                        world.scoreboard.getObjective("stunbreak").addScore(hell, 0)
                        let stun_meter =  hell.getProperty("stat:stun_meter") 
                        let blocking = hell.hasTag("blocking")
                        let posture = world.scoreboard.getObjective("posture").getScore(hell)
                        let dmg = calculateDamageTaken(player, damage, particle, hell, item)
                        let theBag = backShotCheck(player, hell)
                        let stunThreshold
                        let knoks = knockMap.get(knockType)
                        hell.typeID == "minecraft:player" ? stunThreshold = 5 : stunThreshold = hell.getProperty("stat:stun_threshold")
                        if(hell.hasTag("parriable") && !theBag && Unbreakable == false) {
                            world.scoreboard.getObjective("clash").setScore(hell, 1)
                            hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 2, 0.2)
                            hell.removeTag("attack")
                            hell.removeTag("parriable")
                            if(hell.typeId == "minecraft:player") {
                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                            }
                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                            resolve("attack_finished")
                        } else if(hell.hasTag("Immune")) {
                            player.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, 2, 0.2)
                            if(hell.typeId == "minecraft:player") {
                                hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                            }
                            world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                            resolve("attack_finished")
                        } else if(blocking && !theBag) {
                            let equipment = hell.getComponent("minecraft:equippable");
                            let mainhand = equipment?.getEquipmentSlot(`Mainhand`)?.getItem()
                            let offhand = equipment?.getEquipmentSlot(`Offhand`)?.getItem()
                            let weaponType = weaponTypeSplicer(mainhand)
                            let weaponTyper = weapons[weaponType]
                            let offhandType = weaponTypeSplicer(offhand)
                            let blockChecker
                            offhandType != "unarmed" && weaponTyper.dual_wield.includes(offhandType) ? blockChecker = `${offhandType}_` : blockChecker = ""
                            let animpref = weaponTyper?.stylePrefixes[hell.getProperty("fighting:style")]
                            animpref == undefined || animpref == "" ? animpref = weaponTyper?.stylePrefixes[0] : animpref = animpref
                            blockRecovery.set(hell.id,10)
                            hell.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                            let blocking_reduction = block_damage -  weapons[weaponType].block_power
                            blocking_reduction <= 0 ? blocking_reduction = 10 : blocking_reduction = blocking_reduction
                            player.runCommand(`execute as @s run camerashake add @s 0.3 0.1`)
                            let hellPower = JSON.parse(hell.getDynamicProperty("resetingStatus"))
                            if((posture - blocking_reduction) <= 0 && hellPower.counter == 0) {
                                world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                stunLock(hell, 20)
                                hell.removeTag("blocking")
                                hell.removeTag("attack")
                                hell.runCommand(`reload`)
                                blockRecovery.set(hell.id,30)
                                if (hell.typeId == "minecraft:player") {
                                    hell.playAnimation(`animation.${animpref}.${blockChecker}guard_break`)
                                } else  {
                                   
                                    hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                }
                                world.scoreboard.getObjective("posture").setScore(hell, 0)
                                offhandType == "shield" ? world.getDimension(hell.dimension.id).playSound(`item.shield.block`,hell.location) : world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                system.runTimeout(()=>{
                                    hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                    try{
                                        hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, (launch_power[0] * 0.25), launch_power[1])
                                    } catch(err){
                                        console.warn("no entity")
                                    }
                                },1)
                            } else if (hellPower.counter >= 1) {
                                hell.addTag("attack")
                                outsideCounter(hell, player, atkspd, dmg, animpref, "counter", knockType, stunDamage)
                            } else {
                                system.runTimeout(()=>{
                                    hell.playAnimation(`animation.${animpref}.${blockChecker}block`, 
                                    {
                                            blendOutTime: 0.5,
                                            stopExpression: "!query.is_using_item",
                                            nextState: `animation.${animpref}.combat_stance`
                                    })
                                },12)
                                offhandType == "shield" ? world.getDimension(hell.dimension.id).playSound(`item.shield.block`,hell.location) : world.getDimension(hell.dimension.id).playSound(`random.anvil_land`,hell.location)
                                hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, (launch_power[0] * 0.25), launch_power[1])
                                if(perf.get(hell.id) == 1) {
                                    player.triggerEvent(`combat:cooldown_${knockType}`)
                                    player.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                    player.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                    hell.playAnimation(`animation.${animpref}.${blockChecker}parry`,
                                    {
                                        blendOutTime: 0.2,
                                        stopExpression: "query.all_animations_finished",
                                        nextState: `animation.${animpref}.${blockChecker}blocking`
                                    })
                                    world.scoreboard.getObjective("posture").setScore(hell, (posture - Math.floor(blocking_reduction * 0.5)))
                                    blockRecovery.set(hell.id,5)
                                    resolve("parried")
                                } else {
                                    player.triggerEvent(`combat:cooldown_shortest`)
                                    player.addEffect("slowness", 2, { amplifier: 100, showParticles: false })
                                    player.playAnimation(`animation.zombie_paced.staggered_0.1`)
                                    hell.playAnimation(`animation.${animpref}.${blockChecker}hit_on_block`,
                                    {
                                        blendOutTime: 0.2,
                                        stopExpression: "query.all_animations_finished",
                                        nextState: `animation.${animpref}.${blockChecker}blocking`
                                    })
                                    world.scoreboard.getObjective("posture").setScore(hell, (posture - blocking_reduction))
                                    blockRecovery.set(hell.id,10)
                                    resolve("blocked")
                                }
                            }
                            
                        } else if(blocking && theBag) {
                            hell.playAnimation(`animation.zombie_paced.staggered_0.1`)
                            hell.removeTag("blocking")
                            hell.removeTag("attack")
                            hell.runCommand(`reload`)
                            system.runTimeout(()=>{
                                hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                                try{
                                    hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                                } catch(err){
                                    console.warn("no entity")
                                }
                            },1)
                            resolve("attack_finished")
                        } else {
                            if(damageType == "no cooldown") {
                                hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.override })
                            }  else if(damageType == "true") {
                                hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.void })
                            } else {
                                hell.applyDamage(dmg, {damagingEntity: player, cause: EntityDamageCause.entityAttack })
                            }
                           
                            try{
                                hell.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                            } catch(err){
                                console.warn("no entity")
                            }
                            
                            if(damage >= 8) {
                                player.runCommand(`execute as @s run camerashake add @s 0.3 0.3`)
                            } else {
                                player.runCommand(`execute as @s run camerashake add @s 0.1 0.1`)
                            }
                            let che4ck = world.scoreboard.getObjective("stunbreak").getScore(hell)
                            let knoks = knockMap.get(knockType)
                            if(knockType == "knockdown" && (stun_meter - stunDamage) <= 0 && che4ck == 0) {
                                try{
                                    hell.triggerEvent("stun:remove")
                                    hell.triggerEvent(`combat:cooldown_${knockType}`)
                                    if(hell.typeId == "minecraft:player") {
                                        hell.setDynamicProperty("attacking",1)
                                        hell.inputPermissions.movementEnabled = false
                                        system.runTimeout(()=>{
                                            hell.setDynamicProperty("attacking",0)
                                            hell.inputPermissions.movementEnabled = true
                                        },knoks[0])
                                    } else {
                                        hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                        hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                    }
                                    world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                    world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                } catch(err) {
                                    hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                    hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                }
                            } else if((stun_meter - stunDamage) <= 0 && knockType != "knockdown" && che4ck == 0) {
                                try{
                                    player.triggerEvent("stun:remove")
                                    hell.triggerEvent(`combat:remove_attack`)
                                    hell.triggerEvent(`stun:remove`)
                                    if(hell.typeId == "minecraft:player") {
                                        hell.setDynamicProperty("attacking",1)
                                        hell.inputPermissions.movementEnabled = false
                                        system.runTimeout(()=>{
                                            hell.setDynamicProperty("attacking",0)
                                            hell.inputPermissions.movementEnabled = true
                                        },100)
                                    } else {
                                        hell.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                                        hell.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
                                    }
                                    world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                    world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                    hell.playAnimation(`animation.zombie_paced.stun_broken`)
                                } catch(err) {
                                    if(hell.typeId == "minecraft:player") {
                                        hell.setDynamicProperty("attacking",1)
                                        hell.inputPermissions.movementEnabled = false
                                        system.runTimeout(()=>{
                                            hell.setDynamicProperty("attacking",0)
                                            hell.inputPermissions.movementEnabled = true
                                        },100)
                                    } else {
                                        hell.addEffect("weakness", 100, { amplifier: 100, showParticles: false })
                                        hell.addEffect("slowness", 100, { amplifier: 100, showParticles: false })
                                    }
                                    world.scoreboard.getObjective("stunTimer").setScore(hell, 100)
                                    world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunbreak").setScore(hell, 1)
                                    world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                    hell.playAnimation(`animation.zombie_paced.stun_broken`)
                                }
                            } else if((stun_meter - stunDamage) > 0 && che4ck == 0) {
                                if(player.getProperty("stat:stun_meter") < 30) {
                                    player.setProperty("stat:stun_meter",(player.getProperty("stat:stun_meter") + 3))
                                }
                                try{
                                    if(che4ck != 1||che4ck == undefined) {
                                        if(stunThreshold <= stunDamage) {
                                            world.scoreboard.getObjective("stunTimer").setScore(hell, 40)
                                            world.scoreboard.getObjective("stunCheck").setScore(hell, 1)
                                            world.scoreboard.getObjective("stunned").setScore(hell, 1)
                                        }
                                        hell.setProperty("stat:stun_meter", (stun_meter - stunDamage))
                                    }
                                } catch(err) {
                                    console.warn("no entity")
                                }
                                try{
                                    if(stunThreshold <= stunDamage) {
                                        hell.triggerEvent(`combat:cooldown_${knockType}`)
                                        if(hell.typeId == "minecraft:player") {
                                            hell.inputPermissions.movementEnabled = false
                                            hell.setDynamicProperty("attacking",1)
                                            system.runTimeout(()=>{
                                                hell.inputPermissions.movementEnabled = true
                                                hell.setDynamicProperty("attacking",0)
                                            },knoks[0])
                                        } else {
                                            hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                            hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                        }
                                        if(!hell.hasTag("Unbreakable")) {
                                            hell.playAnimation(`animation.zombie_paced.${knoks[1]}`)
                                        }
                                    } 
                                } catch(err) {
                                    if(hell.typeId == "minecraft:player") {
                                        hell.inputPermissions.movementEnabled = false
                                        system.runTimeout(()=>{
                                            hell.inputPermissions.movementEnabled = true
                                        },knoks[0])
                                    } else {
                                        
                                        hell.addEffect("weakness", knoks[0], { amplifier: 100, showParticles: false })
                                        hell.addEffect("slowness", knoks[0], { amplifier: 100, showParticles: false })
                                    }
                                }
                            }
                            
                            if(knockCheck == "knock_player") {
                                player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, launch_power[0], launch_power[1])
                            } else if(knockCheck == "initial_knockback_to_target") {
                                player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, ((launch_power[0] * 0.5) * -1 ), launch_power[1])
                            }
                            hell.dimension.spawnParticle(`combat:${particleMap.get(particle)}`,hell.location);
                            
                            if(launch_power[1] > 0.5){
                                checkInAir.set(hell.id,200)
                                onAirEntity(player, hell)
                                hell.playAnimation('animation.zombie_paced.on_air')
                                try{
                                    hell.triggerEvent("combat:cooldown_on_air")
                                } catch(err) {
                                    console.warn("hit entity has no event")
                                }
                               
                            }
                            if(launch_power[0] >= 3 && launch_power[1] < 1.1) {
                                let newLauncher = Math.max((launch_power[0] + (generalis.getObjective("Strength").getScore(player)/10)),0)
                                hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                                outsideLoop(player, hell,newLauncher, "x", false)
                            } else if(launch_power[1] < 0) {
                                let newLauncher = Math.max((launch_power[1] + (generalis.getObjective("Strength").getScore(player)/100)),0)
                                hell.runCommand(`execute as @s run scoreboard players set @s knocked 2`)
                                outsideLoop(player, hell, newLauncher, "y", false)
                            }
                            switch(effect) {
                                case "lashes": {
                                    let newRedux = JSON.parse(hell.getDynamicProperty("resetingStatus"))
                                    if(newRedux.reductionsTriggers[0] == 3) {
                                        newRedux["reductions"][0] = (parseInt(newRedux.reductions[0]) + (dmg * 0.5))
                                        newRedux["reductionsTimers"][0] = 30
                                        newRedux["reductionsTriggers"][0] = 0
                                        let Loa = coordExtractor(hell,1)
                                        hell.dimension.spawnParticle(`combat:bleed_activate`,Loa);
                                    } else {
                                        newRedux["reductionsTriggers"][0] = (parseInt(newRedux.reductionsTriggers[0]) + 1)
                                    }
                                    hell.setDynamicProperty("resetingStatus",JSON.stringify(newRedux))
                                } break;
                                case "armorBreaker": {
                                    let newRedux = JSON.parse(hell.getDynamicProperty("resetingStatus"))
                                    if(newRedux.reductionsTriggers[0] == 3) {
                                        newRedux["reductions"][1] = (parseInt(newRedux.reductions[0]) + (dmg * 0.5))
                                        newRedux["reductionsTimers"][1] = 30
                                        newRedux["reductionsTriggers"][1] = 0
                                        let Loa = coordExtractor(hell,1)
                                        hell.dimension.spawnParticle(`combat:bleed_activate`,Loa);
                                    } else {
                                        newRedux["reductionsTriggers"][1] = (parseInt(newRedux.reductionsTriggers[0]) + 1)
                                    }
                                    hell.setDynamicProperty("resetingStatus",JSON.stringify(newRedux))
                                } break;
                                default: {
                                    if(effect !='00' && effect != undefined) {
                                        for(let i of effect) {
                                            hell.addEffect(`${potionTypes.get(i)}`, 200, { amplifier: 2, showParticles: false })
                                            
                                        }
                                    }
                                } break;
                            }
                            resolve("attack_finished")
                        }
                    }
                    resolve("nothing")
                }
            },atkspd);
        } catch(err) {
            resolve("attack_finished")
        }     
       
    })
    
}

async function attackMobChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber) {
    let comboers
    let hits = 0
    if(knockCheck == "initial_knockback_to_target") {
        let loc = coordExtractor(player, 0)
        let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
        let Hit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, lof);
        Hit.runCommand(`tag @s add ${player.nameTag.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
        try{
            let target = targetPickerMeikyu(player, Hit, 16, 1)
            let entity = target[0] 
            let distance = getDistance(player, entity)
            const dista = Math.min(12,(distance * 1.5))
            let rover = system.runInterval(()=>{
                player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, dista, 1)
            },(Math.floor(atkspd * 0.1)))
            system.runTimeout(()=>{
                system.clearRun(rover)
            },atkspd)
        } catch(err) {

        }
    }
    if(knockCheck == "jump_attack"){
        let loc = coordExtractor(player, 0)
        let lof = Vector3.Add(loc, Vector3.Scale(player.getViewDirection(), dist));
        let target = distancedTargetPicker(player, (dist + 5))
        for(let Jk of target){
            let distance = getDistance(player,Jk)
            launchPlayer(player, distance, 0.6)
        }
    }
    while (hits < hitNumber && comboers != "clashed" && comboers != "countered") {
        player.removeTag("attack")
        world.scoreboard.getObjective("clash").setScore(player, 0)
        let comboer = await attackMobRepeater(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber)
        comboers = comboer
        hits = hits + 1;
        player.removeTag("parriable")
    };
    return new Promise((resolve) => {
        if(hits >= hitNumber||comboers == "clashed"||comboers == "countered") {
            resolve(comboers)
        }
    })
    
}

export async function attackMobHumanoidMeikyu(player, range, damage, block_damage, cooldown, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, combo_length, stunDamage, NAT, Unbreakable, damageType, item, hitNumber) {
    player.addEffect("weakness", atkspd + cooldown, { amplifier: 100, showParticles: false })
    let comboGet = player.getDynamicProperty("combo")
    world.scoreboard.getObjective("stunned").setScore(player, 0)
    world.scoreboard.getObjective("clash").addScore(player, 0)
    if(Unbreakable == true) {
        player.addTag("Unbreakable")
    }
    const waiter = await attackMobChecks(player, range, damage, block_damage, atkspd, dist, targetNum, targetType, effect, launch_power, knockType, knockCheck, particle, stunDamage, Unbreakable, damageType, item, hitNumber)
    let comboed = false
    player.removeTag("attack")
    player.removeTag("Unbreakable")
    world.scoreboard.getObjective("clash").setScore(player, 0)
    if(comboGet >= combo_length ||  waiter == "nothing" && waiter != "attack_finished" && waiter != "blocked" && waiter != "countered" && waiter != "clashed" && waiter != "parried") {
        comboed = true
        system.runTimeout(()=>{  
            try{
                player.setDynamicProperty("combo",1)
                player.setDynamicProperty("attacking",0)
                player?.triggerEvent("attack_again")
            } catch {
                
            }
        },(cooldown + NAT))
    } else if(player.getDynamicProperty("attacking") == 1 && waiter == "attack_finished" && comboGet <= combo_length) {
        let newCombo = comboGet + 1
        player.setDynamicProperty("combo", newCombo)
        system.runTimeout(()=>{
            try{
                player?.triggerEvent("attack_again")
                player.setDynamicProperty("attacking",0)
            } catch {
                
            }
        },NAT)
    } else if(waiter == "blocked") {
        let newCombo = comboGet + 1
        player.setDynamicProperty("combo", newCombo)
        system.runTimeout(()=>{
            try{
                player?.triggerEvent("attack_again")
                player.setDynamicProperty("attacking",0)
            } catch {
                
            }
        },NAT + 10)
        if(player.typeId == "minecraft:ravager") {
            let hp = player.getProperty("stat:stun_times")
            player.setProperty("stat:stun_times",(hp + 1))
        }
    } else if(waiter == ("parried")) {
        player.setDynamicProperty("combo",1)
        system.runTimeout(()=>{
            player.setDynamicProperty("attacking",0)
            player.triggerEvent("attack_again")
        },(NAT + cooldown + 20))
        if(player.typeId == "minecraft:ravager") {
            let hp = player.getProperty("stat:stun_times")
            player.setProperty("stat:stun_times",(hp + 1))
        }
    } else if(waiter == ("countered")) {
        player.setDynamicProperty("combo",1)
        system.runTimeout(()=>{
            try{
                player.triggerEvent("attack_again")
                player.setDynamicProperty("attacking",0)
            } catch {
                
            }
            
        },(NAT + cooldown))
    } else if(waiter == ("clashed")) {
        player.addEffect("slowness", 20, {amplifier: 10, showParticles: false})
        system.runTimeout(()=>{
        try{
            player.triggerEvent("attack_again")
            player.setDynamicProperty("attacking",0)
        } catch {
            
        }
    },(cooldown + 20))
    } else {
        system.runTimeout(()=>{
        try{
            player.triggerEvent("attack_again")
            player.setDynamicProperty("attacking",0)
        } catch {
            
        }
    },(cooldown))
    }
}


export async function plunge(player, range, damage, cooldown, atkspd, dist, xback, yback, weaponType) {
    let stunned = world.scoreboard.getObjective("stunned").getScore(player)
    player.addEffect("slow_falling", 100, { amplifier: 3, showParticles: false })
    const plungers = system.runInterval(() => {
        if (stunned == 1) {
            player.setDynamicProperty("attacking",0)
            system.clearRun(plungers);
            player.removeTag("attack")
            return;
        } else if (stunned == 0 && player.getDynamicProperty("attacking") == 1) {
            launchPlayer(player, xback, yback)
            let plungerst = system.runInterval(()=>{
                let ground = player.isOnGround
                player.runCommandAsync("tag @s add attack")
                if(ground){
                    player.runCommand(`tp @s ^^^`)
                    player.inputPermissions.cameraEnabled = false
                    player.inputPermissions.movementEnabled = false
                    let loc = coordExtractor(player, 0)
                    
                    let Kit = player.dimension.spawnEntity(`pixel:hit_box<range:line_target>`, loc);
                    player.runCommand(`execute as @s run camerashake add @s 0.5 0.3`)
                    Kit.runCommandAsync(`tag @s add ${player.nameTag.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>/\s/\{\}\[\]\\\/]/gi, '')}`)
                    player.dimension.spawnParticle('minced:pushback',player.location);
                    world.getDimension(player.dimension.id).playSound(`random.combat_fall.land`,player.location)
                    let newTarget = targetPickerMeikyu(player, Kit, (range * 2), 100)
                    player.playAnimation(`animation.minced.${weaponType}.attack_on_air_land`)
                    for(let hell of newTarget){
                        hell.applyKnockback(hell.getViewDirection().x, hell.getViewDirection().z, (-xback + (yback * 0.2)), 0.5)
                        hell.applyDamage((damage - (damage * 0.5)), {damagingEntity: player, cause: EntityDamageCause.void })
                    }
                    system.clearRun(plungerst)
                    system.runTimeout(()=>{
                        player.setDynamicProperty("attacking",0),
                        player.inputPermissions.cameraEnabled = true
                        player.inputPermissions.movementEnabled = true
                        player.removeTag("attack")
                    },(cooldown + atkspd))
                }
            },1)
        }
	        
        system.clearRun(plungers);
    },atkspd);
   
}


