extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "tgheroes:kang/kang_layer1",
    "layer2": "tgheroes:kang/kang_layer2",
    "glider": "tgheroes:kang/glider",
    "cape": "tgheroes:kang/kang_cape",
	"mask": "tgheroes:kang/kang_mask.tx.json"
});

var utils = implement("fiskheroes:external/utils");
var capes = implement("fiskheroes:external/capes");
var cape;
var telekinesis;
var glow;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "HELMET" && entity.getData("fiskheroes:mask_open_timer2") > 0) {
            return "mask";
        }
        return renderLayer == "LEGGINGS" ? "layer2" : "layer1";
    });
}

function initEffects(renderer) {
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.weight = 2.0;
    physics.maxFlare = 0.2;
    physics.flareDegree = 1.2;
    physics.flareFactor = 1.0;
    physics.flareElasticity = 5;
    cape = capes.createDefault(renderer, 24, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 16;
	
	var model_glider = renderer.createResource("MODEL", "tgheroes:kangglide");
    model_glider.texture.set("glider");
    glider = renderer.createEffect("fiskheroes:model").setModel(model_glider);
    glider.anchor.set("body");
    glider.setScale(1);

	var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0x00bfff);
    forcefield.setShape(36, 18).setOffset(0.0, 6.0, 0.0).setScale(2.5);
    forcefield.setCondition(entity => {
        forcefield.opacity = entity.getInterpolatedData("fiskheroes:shield_blocking_timer") * 0.15;
        return true;
    });
	
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "tgheroes:kang_beam", "body", 0x87cefa, [
        { "firstPerson": [-3.75, 3.0, -8.0], "offset": [0.5, 12.0, 0.0], "size": [3.0, 3.0], "anchor": "leftArm" },
        { "firstPerson": [3.75, 3.0, -8.0], "offset": [-0.5, 12.0, 0.0], "size": [3.0, 3.0], "anchor": "rightArm" }
    ]);
	
    glow = renderer.createEffect("fiskheroes:glowerlay");
    glow.color.set(0x7fc7ff);
	utils.bindParticles(renderer, "fiskheroes:harbinger_glow");

	utils.bindCloud(renderer, "fiskheroes:telekinesis", "tgheroes:telekinesis_kang");
}
function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.AIMING");
    renderer.removeCustomAnimation("basic.CHARGED_BEAM");

    addAnimation(renderer, "basic.AIMING", "fiskheroes:dual_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:gliding");
    utils.addHoverAnimation(renderer, "thor.HOVER", "tgheroes:gliding");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
        if (entity.getData("tgheroes:dyn/kang_glider") > 0.5) {
            var glider_anchor = glider.anchor.set("body");
            var glider_offSet = glider.setOffset(0.0, 0.0, 0.0);      			
            glider.anchor = glider_anchor, glider_offSet;
            glider.render();
        }
}
		        if (renderLayer == "CHESTPLATE") {
            cape.render(entity);
        }

    glow.opacity = entity.getInterpolatedData("fiskheroes:teleport_timer");
    glow.render();
}