extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "fan:marvel/alast12",
    "layer2": "fan:marvel/alast2",
    "pants": "fan:marvel/alastpants",
    "boots": "fan:marvel/alastboots",
    "wing_angel": "fan:228/angel/angel_wings",
    "hat1": "fan:marvel/hat1",
    "tentacle": "fan:tentacle",
    "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;

            var ock_arm = utils.createModel(renderer, "fan:model", "tentacle");
        var ock_claw = utils.createModel(renderer, "fan:luc", "tentacle");
        ock_claw.bindAnimation("fiskheroes:ock_claw").setData((entity, data) => {
            var t = entity.as("TENTACLE");
            data.load(0, 1 - Math.min(t.getCaster().getInterpolatedData("fiskheroes:tentacle_extend_timer") * 2, 1));
            data.load(1, t.getIndex());
            data.load(2, t.getGrabTimer());
            data.load(3, t.getStrikeTimer());
            
        });
        
        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"));
        
        var tentacles = renderer.bindProperty("fiskheroes:tentacles").setTentacles([
            { "offset": [0, -9.5, -2.0], "direction": [-13.0, -3.0, -9.0] }
        ]);
        tentacles.anchor.set("body");
        tentacles.setSegmentModel(ock_arm);
        tentacles.setHeadModel(ock_claw);
        tentacles.segmentLength = 1;
        tentacles.segments = 100;
	
        ears = renderer.createEffect("fiskheroes:model");
        ears.setModel(utils.createModel(renderer, "fan:hat1", "hat1"));
        ears.anchor.set("head");
        ears.setScale(1);
        ears.setOffset(4, -11, 4);
        ears.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_angel");
	model_wings.bindAnimation("fan:wings_slow_flap").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && !entity.isSprinting() && entity.loop(35)));
	model_wings.bindAnimation("fan:wings_fast_flop").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && entity.isSprinting() && entity.loop(20)));
	model_wings.bindAnimation("fan:wings_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_angel");
	model_wings_arch.bindAnimation("fan:wings_slow_flap").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && !entity.isSprinting() && entity.loop(35)));
	model_wings_arch.bindAnimation("fan:wings_fast_flop").setData((entity,data) => data.load(entity.getInterpolatedData('fiskheroes:flight_timer')
    && entity.isSprinting() && entity.loop(20)));
	model_wings_arch.bindAnimation("fan:wings_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);

    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.setOpacityWithData(renderer, 0.0, 0.999, "fiskheroes:shadowform_timer");
    utils.bindCloud(renderer, "fiskheroes:particle_cloud", "fiskheroes:shadow_smoke").setCondition(entity => entity.getData("fiskheroes:shadowform"));

}

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

       addAnimationWithData(renderer, "two.PUNCH", "fan:shue_arm_left_punch").setData((entity,data) => data.load(entity.getData("fiskheroes:blade_timer") > 0.3 && entity.isPunching())).priority = 5;	

	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;

}

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();
    }
        ears.render();
}

 