import { world,system} from "@minecraft/server"

function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
  }


world.afterEvents.entitySpawn.subscribe((entityEvent) => {
    const entity=entityEvent.entity
    if (entity.typeId == "edx:blazeblade_dash" ) {
        var blazeblades = world.getDimension("Nether").getEntities({
            type: 'edx:blazeblade',
            location: { x: entity.location.x, y: entity.location.y, z: entity.location.z },
            maxDistance: 5,
        });
        for (let blazeblade of blazeblades) {
            var direction=blazeblade.getViewDirection()
            blazeblade.applyImpulse({ x:direction.x*4 , y: direction.y, z: direction.z*4 }) 
        };


        var blazeblades2 = world.getDimension("Nether").getEntities({
            type: 'edx:blazeblade2',
            location: { x: entity.location.x, y: entity.location.y, z: entity.location.z },
            maxDistance: 5,
        });
        for (let blazeblade2 of blazeblades2) {
            var direction=blazeblade2.getViewDirection()
            blazeblade2.applyImpulse({ x:direction.x*6 , y: direction.y, z: direction.z*6 }) 
        }  
    
    }
    if (entity.typeId == "edx:blazeblade_solar_flare" ) {
        var players = world.getDimension("Nether").getPlayers({
            location: { x: entity.location.x, y: entity.location.y, z: entity.location.z },
            maxDistance: 64,
        });
        for (let player of players) {
            if (player.hasTag("easy") ) {
                player.setOnFire(3, false);
            }
            else if (player.hasTag("normal") ) {
                player.setOnFire(5, false);
            }
            else if (player.hasTag("hard") ) {
                player.setOnFire(8, false);
            }
         }
    }
    if (entity.typeId == "edx:blazeblade_dig" ) {
        var players = world.getDimension("Nether").getPlayers({
            location: { x: entity.location.x, y: entity.location.y, z: entity.location.z },
            maxDistance: 1,
        });
        for (let player of players) {
            if (player.hasTag("easy") ) {
                player.setOnFire(6, false);
                player.applyKnockback(0,0,0,2);
                player.applyDamage(4,{
                    cause: "fire" ,
                },)
            }
            else if (player.hasTag("normal") ) {
                player.setOnFire(8, false);
                player.applyKnockback(0,0,0,2);
                player.applyDamage(6,{
                    cause: "fire" ,
                },)
            }
            else if (player.hasTag("hard") ) {
                player.setOnFire(10, false);
                player.applyKnockback(0,0,0,3);
                player.applyDamage(8,{
                    cause: "fire" ,
                })
            }
         }
    }
    if (entity.typeId == "edx:blazeblade_sun" ) {
        var players = world.getDimension("Nether").getPlayers({
            location: { x: entity.location.x, y: entity.location.y, z: entity.location.z },
            maxDistance: 5,
        });
        for (let player of players) {
            if (player.hasTag("easy") ) {
                player.setOnFire(3, false);
                player.applyKnockback(0,0,0,1);
                player.applyDamage(8,{
                    cause: "fire" ,
                },)
            }
            else if (player.hasTag("normal") ) {
                player.setOnFire(5, false);
                player.applyKnockback(0,0,0,1);
                player.applyDamage(14,{
                    cause: "fire" ,
                },)
            }
            else if (player.hasTag("hard") ) {
                player.setOnFire(7, false);
                player.applyKnockback(0,0,0,1);
                player.applyDamage(20,{
                    cause: "fire" ,
                })
            }
         }
        
    
    }
    if (entity.typeId == "edx:blazeblade_fire_charge" ) {
        entity.applyImpulse(entity.getViewDirection())
    }

  });