extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "wv:agatha/agatha_layer1",
    "layer2": "wv:agatha/agatha_layer2"
});
var chest
var utils = implement("fiskheroes:external/utils");
var color = 0xAA00AA;


function init(renderer) {
    parent.init(renderer);
    renderer.showModel("CHESTPLATE", "head", "headwear", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
    renderer.fixHatLayer("CHESTPLATE");
}


function initEffects(renderer) {
    // parent.initEffects();
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(0.75).setYOffset(1);

    utils.bindCloud(renderer, "fiskheroes:telekinesis", "wv:atele");
    utils.bindCloud(renderer, "fiskheroes:teleportation", "fiskheroes:breach");
 
    // poof
    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0xAA00AA);
    forcefield.setOffset(0.0, 6.0, 0.0)
    forcefield.setCondition(entity => {
        forcefield.opacity = Math.max(entity.getInterpolatedData("fiskheroes:beam_shooting_timer") / 2, 0);
        forcefield.setScale(entity.getInterpolatedData("fiskheroes:beam_shooting_timer") * 3);
        return true;
    });
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "wv:invis", "head", 0xAA00AA, [{
        "firstPerson": [0, 0, 0],
        "offset": [0, 0, 0],
        "size": [0, 0]
    }
    ]);
    

    // pew pew
    utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "fiskheroes:cold_beam", "rightArm", 0xAA00AA, [{
        "firstPerson": [-3.75, 3.0, -8.0],
        "offset": [-0.5, 12.0, 0.0],
        "size": [1.5, 1.5]
    }
    ]);
    var hand = renderer.createResource("BEAM_RENDERER", "wv:hand");

    hand_punch = utils.createLines(renderer, hand, "0xAA00AA", [{
        "start": [0, -0.1, 0],
        "end": [0, 0.1, 0],
        "size": [3, 3]
    }
    ]);
    hand_punch.anchor.set("rightArm");
    hand_punch.setOffset(0, 9.0, 0.0).setRotation(0.0, 0.0, 0.0).setScale(16);
    hand_punch.mirror = true;

    var charge = renderer.createResource("BEAM_RENDERER", "wv:charge");

    charge_right = utils.createLines(renderer, charge, "0xAA00AA", [{
        "start": [0, -0.1, 0],
        "end": [0, 0.1, 0],
        "size": [3, 3]
    }
    ]);
    charge_right.anchor.set("rightArm");
    charge_right.setOffset(0, 9.0, 0.0).setRotation(0.0, 0.0, 0.0).setScale(16);
    charge_right.mirror = true;
}


function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.CHARGED_BEAM");
    utils.addFlightAnimation(renderer, "shazam.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "vision.HOVER", "fiskheroes:flight/idle/neutral");


    addAnimation(renderer, "agatha.HOLOSTAND", "wv:levitation")
        .setData((entity, data) => {
            var f = entity.getInterpolatedData("wv:dyn/holoanimation");
            data.load(4 * f <= 0.95 ? 4 * f : 0.95);
        });
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
    if (entity.isWearingFullSuit()) {
        if (entity.isPunching() || entity.getData("fiskheroes:flight_timer") || entity.getData("fiskheroes:aiming_timer") == 1 || entity.getInterpolatedData("wv:dyn/holoanimation") > 0) {
            hand_punch.render();
        }
    }
}