extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "pkg:anodite_layer1",
    "layer2": "pkg:anodite_layer2",
    "lights": "pkg:anodite_lights"
});

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


var spell;
function init(renderer) {
    parent.init(renderer);
    renderer.setLights((entity, renderLayer) => renderLayer == "CHESTPLATE" ? "lights" : null);

    renderer.showModel("CHESTPLATE", "head", "headwear", "body", "rightArm", "leftArm");
    renderer.fixHatLayer("CHESTPLATE");
}

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

    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0xCD00FF);
    forcefield.setShape(36, 18).setOffset(0.0, 6.0, 0.0).setScale(1.25);
    forcefield.setCondition(entity => {
        forcefield.opacity = entity.getInterpolatedData("fiskheroes:shield_blocking_timer") * 0.15;
        return true;
    });

    utils.setOpacityWithData(renderer, 0.0, 1.0, "fiskheroes:shadowform_timer");
    utils.bindCloud(renderer, "fiskheroes:particle_cloud", "fiskheroes:shadow_smoke").setCondition(entity => entity.getData("fiskheroes:shadowform"));
    utils.bindTrail(renderer, "fiskheroes:anti_monitor").setCondition(entity => entity.getData("fiskheroes:size_state") > 0);

    // charged beam
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "pkg:lightning", "rightArm", 0xCD00FF, [
        { "firstPerson": [-4.5, 3.75, -8.0], "offset": [-0.5, 9.0, 0.0], "size": [3.0, 3.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_antimatter"));

    // energy projection
    utils.bindBeam(renderer, "fiskheroes:energy_projection", "pkg:lightning", "body", 0xCD00FF, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [4.0, 4.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));

    //lightning cast
    utils.bindBeam(renderer, "fiskheroes:lightning_cast", "fiskheroes:lightning_cast", "rightArm", 0xCD00FF, [
        { "firstPerson": [-8.0, 4.5, -10.0], "offset": [-0.5, 9.0, 0.0], "size": [0.75, 0.75] }
    ]);

    utils.bindTrail(renderer, "pkg:anodite_lightning").setCondition(entity => entity.getData("fiskheroes:flying"));

    var color = 0xCD00FF;
    var magic = renderer.bindProperty("fiskheroes:spellcasting");
    magic.colorGeneric.set(0xCD00FF);
    magic.colorEarthCrack.set(0xCD00FF);
    magic.colorAtmosphere.set(0xCD00FF);
    magic.colorWhip.set(color);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "firestorm.FLIGHT", "fiskheroes:flight/propelled_hands.anim.json");
    utils.addHoverAnimation(renderer, "firestorm.HOVER", "fiskheroes:flight/idle/propelled_hands");
    addAnimationWithData(renderer, "iron_man.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8; 
    utils.addHoverAnimation(renderer, "general_zod.HOVER", "fiskheroes:flight/idle/neutral");

    addAnimationWithData(renderer, "antimonitor.ANTIBLAST", "fiskheroes:aiming", "fiskheroes:beam_charge");
}

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

        if (!isFirstPersonArm) {
            chest.render();
        }
    }
    }
