extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "fan:marvel/Adam1",
    "layer2": "fan:marvel/adam2",
    "pants": "fan:marvel/adampants",
    "boots": "fan:marvel/adamboots",
    "wing_angel": "fan:228/angel/wings",
    "adam": "fan:marvel/adam",
    "shadowdome": "fan:circ",
    "wing_arch": "fan:228/angel/xor_wings/arch_wings.tx.json"
 
});
var utils = implement("fiskheroes:external/utils");
var flames = implement("fiskheroes:external/flames");
var heatR;
var heatL;
var hand_flames;


var ears;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "LEGGINGS") {
            return entity.getWornChestplate().suitType() == $SUIT_NAME ? "pants" : "layer2";
        }
        return renderLayer == "BOOTS" ? "boots" : "layer1";
    });
    
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
}

function render(entity, renderLayer) {
    ears.render();
    if (renderLayer == "LEGGINGS") {
        
    }};

function initEffects(renderer) {
	night_v = renderer.bindProperty("fiskheroes:night_vision");
    night_v.firstPersonOnly = false;
	
        adam = renderer.createEffect("fiskheroes:model");
        adam.setModel(utils.createModel(renderer, "fan:adam", "adam"));
        adam.anchor.set("head");
        adam.setScale(1);
        adam.setOffset(4, -11, 4);
        adam.setRotation(90, 90, -90);

	var shadowdome = renderer.bindProperty("fiskheroes:shadowdome");
	shadowdome.texture.set("shadowdome", "shadowdome");
	shadowdome.setShape(36, 36); 

	overlay = renderer.createEffect("fiskheroes:overlay");
    overlay.texture.set("layer_arch_suit");
	
	var model_wings = renderer.createResource("MODEL", "fan:wings_adam");
	model_wings.bindAnimation("fan:adamwings_slow_flap").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && !entity.isSprinting() && entity.loop(35)));
	model_wings.bindAnimation("fan:adamwings_fast_flop").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && entity.isSprinting() && entity.loop(20)));
	model_wings.bindAnimation("fan:adamwings_off").setData((entity,data) => data.load(!entity.getInterpolatedData('fiskheroes:flight_timer')));
    model_wings.texture.set("wing_angel");
    wings = renderer.createEffect("fiskheroes:model").setModel(model_wings);
    wings.anchor.set("body");
	wings.setOffset(0.0, 0.0, 1.0);


    var model_wings_arch = renderer.createResource("MODEL", "fan:wings_adam");
	model_wings_arch.bindAnimation("fan:adamwings_slow_flap").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && !entity.isSprinting() && entity.loop(35)));
	model_wings_arch.bindAnimation("fan:adamwings_fast_flop").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && entity.isSprinting() && entity.loop(20)));
	model_wings_arch.bindAnimation("fan:adamwings_off").setData((entity,data) => data.load(!entity.getInterpolatedData('fiskheroes:flight_timer')));
	model_wings_arch.bindAnimation("fan:wings_shield").setData((entity,data) => data.load(entity.getInterpolatedData("fiskheroes:shield_blocking_timer")));
    model_wings_arch.texture.set("wing_arch");
    wings_arch = renderer.createEffect("fiskheroes:model").setModel(model_wings_arch);
    wings_arch.anchor.set("body");
	wings_arch.setOffset(0.0, 0.0, 1.0);

    utils.bindBeam(renderer, "fiskheroes:energy_projection", "fan:adam", "rightArm", 0xfdf568, [
        { "firstPerson": [-5.5, 4.75, -10.0], "offset": [-0.5, 9.0, 0.0], "size": [3.0, 3.0, -3.0] },
        { "firstPerson": [5.5, 4.75, -10.0], "offset": [0.5, 9.0, 0.0], "size": [3.0, 3.0, -3.0], "anchor": "leftArm" }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fan:adam1"));


    var energy_blast = renderer.createResource("BEAM_RENDERER", "fan:adam");
    var constln = renderer.createResource("BEAM_CONSTELLATION", null);
    var energy_blast_beam = constln.bindBeam({ "firstPerson": [-5.5, 4.75, -10.0], "offset": [-0.5, 9.0, 0.0], "size": [3.0, 3.0, -3.0] });
    
    var repulsor_blast = renderer.bindProperty("fiskheroes:repulsor_blast");
    repulsor_blast.setConstellation(constln);
    repulsor_blast.setRenderer(energy_blast);
    repulsor_blast.color.set(0xfdf568);

    repulsor_blast.setCondition(entity => {
        if (Math.random() < 0.5) {
            repulsor_blast.setAnchor("rightArm");
            energy_blast_beam.firstPerson.x = -5.5;
            energy_blast_beam.offset.x = -0.5;
        }
        else {
            repulsor_blast.setAnchor("leftArm");
            energy_blast_beam.firstPerson.x = 5.5;
            energy_blast_beam.offset.x = 0.5;
        }
        
        return true;
    });

    arms_blast = utils.createLines(renderer, "fan:adamhands", 0xfdf568, [
        {"start": [0, 0.5, 0], "end": [0.0, 1.0, 0.0], "size": [10.0, 3.0]},
    ]);
    arms_blast.anchor.set("rightArm");
    arms_blast.setOffset(1, 4.25, 0).setRotation(0.0, 0.0, 0.0).setScale(8.0, 6.0, 8.0);
    arms_blast.mirror = true;

    energy_proj = renderer.createEffect("fiskheroes:overlay");

    arms = renderer.createEffect("fiskheroes:overlay");
    arms.texture.set(null, "arm");

    var beam = renderer.createResource("BEAM_RENDERER", "fan:extremis_heat_beam");
    heatR = utils.createLines(renderer, beam, 0xF2400D, [
        { "start": [0, 0.8, 0], "end": [0.0, -1.0, 0.0], "size": [2.5, 2.5, 2.5] },
    ]);
    heatR.setOffset(1.0, 8.0, 0.0).setScale(4.3);
    heatR.anchor.set("rightArm");
    heatR.mirror = true;

    heatL = utils.createLines(renderer, beam, 0xF2400D, [
        { "start": [0, 0.8, 0], "end": [0.0, -1.0, 0.0], "size": [2.5, 2.5, 2.5] },
    ]);
    heatL.setOffset(-1.0, 8.0, 0.0).setScale(4.3);
    heatL.anchor.set("leftArm");
    heatL.mirror = true;

    utils.bindBeam(renderer, "fiskheroes:charged_beam", "fiskheroes:cold_beam", "head", 0xF2400D, [
        { "firstPerson": [0, 3.0, 0.0], "offset": [0, -1.1, -4.0], "size": [6.0, 5.5] },
    ])

    var fire = renderer.createResource("ICON", "fiskheroes:fire_layer_%s");
    hand_flames = flames.createHands(renderer, fire, true);

    utils.bindCloud(renderer, "fiskheroes:teleportation", "fan:wanda_tele");
    utils.bindParticles(renderer, "fan:fire").setCondition(entity => entity.getData('fiskheroes:teleport_timer') != 0);

}

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

	utils.addFlightAnimation(renderer, "wings.FLIGHT", "fiskheroes:flight/propelled_hands.anim.json");
    utils.addHoverAnimation(renderer, "wings.HOVER", "fiskheroes:flight/idle/propelled_hands");
	utils.addAnimationEvent(renderer, "FLIGHT_DIVE", "fiskheroes:iron_man_dive");
	addAnimationWithData(renderer, "wings.ROLL", "fiskheroes:flight/barrel_roll", "fiskheroes:barrel_roll_timer")
        .priority = 10

  addAnimationWithData(renderer, "kang.ENERGY_PROJ", "fiskheroes:dual_aiming", "fiskheroes:aiming_timer")
        .priority = -5;

}

function render(entity, renderLayer, isFirstPersonArm) {
	overlay.opacity = entity.getInterpolatedData("fan:dyn/archangel_timer") > 0
	overlay.render();
	
	if (entity.getInterpolatedData("fan:dyn/archangel_timer") == 0){
        wings.render();
    }
        if (renderLayer == "CHESTPLATE") {
        heatR.progress = entity.getInterpolatedData("fiskheroes:blade");
        heatR.render();
        heatL.progress = entity.getInterpolatedData("fiskheroes:blade");
        heatL.render();
        hand_flames.render(entity.getInterpolatedData("fiskheroes:blade"));
        hand_flames.render();
    }
       if (entity.getInterpolatedData("fan:dyn/archangel_timer") > 0){
        wings_arch.render();
    }
        adam.render();
}

 