extend("fiskheroes:hero_basic");
loadTextures({
	"layer1": "tgheroes:iceman/iceman_layer1",
	"layer2": "tgheroes:iceman/iceman_layer2",
	"icicle": "tgheroes:iceman/iceman_icicle"
});

var utils = implement("fiskheroes:external/utils");
var spikeL;
var spikeR;

function initEffects(renderer) {
	utils.bindBeam(renderer, "fiskheroes:charged_beam", "fiskheroes:cold_beam", "body", 0x87cefa, [
        { "firstPerson": [-3.75, 3.0, -8.0], "offset": [0.5, 12.0, 0.0], "size": [3.0, 3.0], "anchor": "rightArm" }
    ]);
	
	spikeL = renderer.createEffect("fiskheroes:shield");
    spikeL.texture.set("icicle");
    spikeL.anchor.set("rightArm");
    spikeL.setRotation(0.0, 0.0, -3.125).setCurve(20.0, 90.0);
    spikeR = renderer.createEffect("fiskheroes:shield");
    spikeR.texture.set("icicle");
    spikeR.anchor.set("rightArm");
    spikeR.setRotation(0.0, 180.0, -3.125).setCurve(20.0, 90.0);
	
    utils.bindParticles(renderer, "tgheroes:iceman_ice").setCondition(entity => entity.getData("fiskheroes:flying"));
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.AIMING");
    renderer.removeCustomAnimation("basic.CHARGED_BEAM");

    addAnimation(renderer, "basic.AIMING", "fiskheroes:aiming").setData((entity, data) => {
        var charge = entity.getInterpolatedData("fiskheroes:beam_charge");
        data.load(Math.max(entity.getInterpolatedData("fiskheroes:aiming_timer"), entity.getData("fiskheroes:beam_charging") ? Math.min(charge * 3, 1) : Math.max(charge * 5 - 4, 0)));
    });

    utils.addFlightAnimation(renderer, "thor.FLIGHT", "tgheroes:iceman_flight");
    utils.addHoverAnimation(renderer, "thor.HOVER", "tgheroes:iceman_flight");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {       

        spikeL.unfold = spikeR.unfold = entity.getInterpolatedData("fiskheroes:blade_timer");

        var f = Math.min(spikeL.unfold * 5, 1);
        spikeL.setOffset(2.25 + 1.0 * f, 8.0 + 2.0 * f, 0.0);
        spikeR.setOffset(-0.25 - 1.0 * f, 8.0 + 2.0 * f, 0.0);
        spikeL.render();
        spikeR.render();

        
    }
}