extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "tgheroes:hammer/rb/hammer_rb_noskin_layer1",
    "layer2": "tgheroes:hammer/rb/hammer_rb_layer2",
    "mjolner": "tgheroes:thor/mjolner",
	"cape": "tgheroes:hammer/rb/hammer_rb_cape"
});

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

function initEffects(renderer) {
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.3;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    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_mjolner = renderer.createResource("MODEL", "tgheroes:mjolner");
    model_mjolner.texture.set("mjolner");


    mjolner = renderer.createEffect("fiskheroes:model").setModel(model_mjolner);
    mjolner.anchor.set("rightArm");
    mjolner.setScale(1);

	
	var beam = renderer.createResource("BEAM_RENDERER", "tgheroes:doom_beam");
    utils.bindBeam(renderer, "fiskheroes:charged_beam", beam, "rightArm", 0x0022FF, [
        {"firstPerson": [-3.0, 1.0, -5.0], "offset": [0.0, 0.0, 0.0], "size": [4.0, 4.0] }
    ]);

}

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

    // Charged Beam
    addAnimation(renderer, "LIGHTNING", "tgheroes:thor_aim").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:flight/thor.anim.json");
    utils.addHoverAnimation(renderer, "thor.HOVER", "fiskheroes:flight/idle/martian_comics");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
        if (entity.getData("fiskheroes:blade_timer") > 0.9) {
            var blade_anchor = mjolner.anchor.set("rightArm");
            var blade_offSet = mjolner.setOffset(1.0, 8.0, -6.5);
            var blade_rot = mjolner.setRotation(90, 90, 0);
        			
            mjolner.anchor = blade_anchor, blade_offSet, blade_rot;
            mjolner.render();
        }
}
		        if (renderLayer == "CHESTPLATE") {
            cape.render(entity);
}
}