import { world, system } from "@minecraft/server";
import * as utils from "./utils";
import * as Vector3 from "./vector3";

const PROJECTILE_SPEED = 1;

export async function onScriptEventReceive(event) {
    const necromancer = event.sourceEntity;

    if (event.message === "BASIC") basicAttack(necromancer);
}

function basicAttack(necromancer) {
    const lookDirection = necromancer.getViewDirection();

    const projectileEntity = necromancer.dimension.spawnEntity("goe_bos:necromancer_projectile", necromancer.getHeadLocation());
    const projectile = projectileEntity.getComponent("minecraft:projectile");
    projectile.owner = necromancer;
    projectile.shoot({
        x: lookDirection.x * PROJECTILE_SPEED,
        y: lookDirection.y * PROJECTILE_SPEED,
        z: lookDirection.z * PROJECTILE_SPEED
    });
}