extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "diminpack:redvolt_3",
    "lights": "diminpack:redvolt_3_lights",
    "cape": "fiskheroes:the_monitor_cape"
});
var capes = implement("fiskheroes:external/capes");
var cape;
var mandalas = implement("fiskheroes:external/tao_mandalas");
var eldritch_sword = implement("fiskheroes:external/eldritch_sword");

var utils = implement("fiskheroes:external/utils");
var flames = implement("fiskheroes:external/flames");
var speedster = implement("fiskheroes:external/speedster_utils");
var eyes;
var hand_flames;
var head_flames;

var shield;
var sword;
var spell;
var prop_beam;

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

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

function initEffects(renderer) {
    var chain = utils.bindCloud(renderer, "fiskheroes:telekinesis_chain", "diminpack:photo_hold");
    chain.anchor.set("rightArm");
    chain.setOffset(-0.5, 10.0, 0.0);
    chain.setFirstPerson(-4.75, 4.0, -8.5);
    var color = 0xD1D1D1;
    var tao_mandala = renderer.createResource("SHAPE", "fiskheroes:tao_mandala");
    var beam = renderer.createResource("BEAM_RENDERER", "fiskheroes:line");
    spell = renderer.createEffect("fiskheroes:lines").setShape(tao_mandala).setRenderer(beam);
    spell.color.set(color);
    spell.setOffset(1.0, 8.0, 0.0).setScale(3.2);
    spell.anchor.set("rightArm");
    spell.mirror = true;

    shield = mandalas.create(renderer, color, tao_mandala, beam);
    sword = eldritch_sword.create(renderer, color, beam);
    sword.setOffset(1.0, 9.4, -4.0).setRotation(10.0, 0.0, 0.0).setScale(16.0);

    var magic = renderer.bindProperty("fiskheroes:spellcasting");
    magic.colorGeneric.set(0xD1D1D1);
    magic.colorEarthCrack.set(0xD1D1D1);
    magic.colorAtmosphere.set(0xD1D1D1);
    magic.colorWhip.set(color);
    /* Charged Beam
    var beam = renderer.createResource("BEAM_RENDERER", "fiskheroes:mysterio_beam");
    prop_beam = renderer.bindProperty("fiskheroes:energy_projection").setAnchor("leftArm");
    var constln = renderer.createResource("BEAM_CONSTELLATION", null);
    constln.bindBeam({ "firstPerson": [10.0, 0.0, -20.0], "offset": [0.0, 0.0, 0.0], "size": [2.5, 2.5] });
    prop_beam.setConstellation(constln);
    prop_beam.setRenderer(beam);
    utils.bindBeam(renderer, "fiskheroes:energy_projection", "fiskheroes:cold_beam", "head", color, [{
        "firstPerson": [10.0, 0.0, -20.0], "offset": [0.0, 0.0, 0.0], "size": [2.5, 2.5]
                    }
                ]).setCondition(entity =>  (entity.ticksExisted() * 6 % 360) > num && (entity.ticksExisted() * 6 % 360) < num);*/

    utils.bindBeam(renderer, "fiskheroes:energy_projection", "fiskheroes:energy_projection", "leftArm", 0xD1D1D1, [
      { "firstPerson": [10.0, 0.0, -20.0], "offset": [0.0, 0.0, 0.0], "size": [2.5, 2.5] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_charged_beam"));
    
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "fiskheroes:charged_beam", "body", 0xD1D1D1, [
      { "firstPerson": [0.0, 10.0, 0.0], "offset": [0.0, 2.0, 0.0], "size": [4.0, 4.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_charged_beam"));
    
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.2;
    cape = capes.createDefault(renderer, 21, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");

    utils.addCameraShake(renderer, 0.015, 1.5, "fiskheroes:flight_boost_timer");
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.AIMING");
    addAnimationWithData(renderer, "basic.AIMING", "fiskheroes:dual_aiming", "fiskheroes:aiming_timer")
        .priority = 10;
    utils.addAnimationEvent(renderer, "FLIGHT_DIVE", "fiskheroes:iron_man_dive");
    utils.addAnimationEvent(renderer, "FLIGHT_DIVE_ROLL", "fiskheroes:falcon_dive_roll");
    addAnimationWithData(renderer, "barrel.ROLL", "fiskheroes:flight/barrel_roll", "fiskheroes:barrel_roll_timer")
    .priority = 10;

    renderer.removeCustomAnimation("basic.ENERGY_PROJ");
    addAnimationWithData(renderer, "basic.ENERGY_PROJ", "fiskheroes:aiming_left", "fiskheroes:energy_projection_timer")
    renderer.removeCustomAnimation("basic.BLOCKING");
    addAnimationWithData(renderer, "basic.BLOCKING", "fiskheroes:dual_aiming", "fiskheroes:shield_blocking_timer")
        .priority = -5;
    utils.addFlightAnimation(renderer, "firestorm.FLIGHT", "fiskheroes:flight/propelled_hands.anim.json");
    utils.addHoverAnimation(renderer, "firestorm.HOVER", "fiskheroes:flight/idle/propelled_hands");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE" && entity.isWearingFullSuit()) {
        if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
            cape.render(entity);
        }
        spell.progress = entity.getInterpolatedData("fiskheroes:spellcast_timer");
        spell.render();
        //prop_beam.color.setHSB((entity.ticksExisted()*3 % 360)/360, 0.722, 1);
        shield.render(entity, isFirstPersonArm);
        sword.render(entity.getInterpolatedData("fiskheroes:blade_timer"));
    }
}

