import * as mc from "@minecraft/server";

//duration in seconds, radius in blocks
export function showArea(location, dimension, duration, radius) {

    //angles in degree from top 0 to bottom 180
    horizontalCircleAtAngle(location, dimension, duration, radius, 10);
    horizontalCircleAtAngle(location, dimension, duration, radius, 30);
    horizontalCircleAtAngle(location, dimension, duration, radius, 50);
    horizontalCircleAtAngle(location, dimension, duration, radius, 70);

    horizontalCircleAtAngle(location, dimension, duration, radius, 85);

    horizontalCircleAtAngle(location, dimension, duration, radius, 100);
    horizontalCircleAtAngle(location, dimension, duration, radius, 120);
    horizontalCircleAtAngle(location, dimension, duration, radius, 140);
    horizontalCircleAtAngle(location, dimension, duration, radius, 160);

    //same with vertical rings
    verticalCircleAtAngle(location, dimension, duration, radius, 0);
    verticalCircleAtAngle(location, dimension, duration, radius, 45);
    verticalCircleAtAngle(location, dimension, duration, radius, 90);
    verticalCircleAtAngle(location, dimension, duration, radius, 135);

    return;
}

function verticalCircleAtAngle(location, dimension, duration, radius, angle) {
    let mvm = new mc.MolangVariableMap();
    mvm.setFloat(`variable.radius`, radius);
    mvm.setFloat(`variable.duration`, duration);
    mvm.setFloat(`variable.angle`, angle);

    mc.world.getDimension(dimension.id).spawnParticle('pb_red:circle_marker_vertical', location, mvm);
}

function horizontalCircleAtAngle(location, dimension, duration, radius, angle) {
    let rad = angle * 2 * Math.PI / 360;
    let height = Math.cos(rad) * radius;
    let r2 = Math.sin(rad) * radius;

    let mvm = new mc.MolangVariableMap();
    mvm.setFloat(`variable.radius`, r2);
    mvm.setFloat(`variable.duration`, duration);

    mc.world.getDimension(dimension.id).spawnParticle('pb_red:circle_marker', { x: location.x, y: location.y + height, z: location.z }, mvm);
}
