extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "tgheroes:guardians/lord_layer1",
    "layer2": "tgheroes:guardians/lord_layer2",
	"mask": "tgheroes:guardians/lord_mask.tx.json",
    "gun": "tgheroes:guardians/element_gun",
    "jet": "tgheroes:guardians/jet"
});

var utils = implement("fiskheroes:external/utils");
var jet;
var booster_boots;
var boosters = implement("fiskheroes:external/bloom_booster");


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 model_gun = renderer.createResource("MODEL", "tgheroes:quill_blaster");
    model_gun.texture.set("gun");
    gun = renderer.createEffect("fiskheroes:model").setModel(model_gun);
    gun.setScale(1.0);
	
	jet = renderer.createEffect("fiskheroes:model");
    jet.setModel(utils.createModel(renderer, "tgheroes:boot_jet", null, "jet"));
    jet.anchor.set("leftLeg");
	jet.mirror = true;
	jet.setScale(1.0);
	jet.setOffset(-1.8, -13.0, 0.0);
	
	utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "fiskheroes:repulsor_blast", "body", 0xff242a, [
        { "firstPerson": [-4.5, 3.75, -7.0], "offset": [-0.5, 9.0, 0.0], "size": [1.0, 1.0],  "anchor": "rightArm" },
		{ "firstPerson": [4.5, 3.75, -8.0], "offset": [0.5, 9.0, 0.0], "size": [1.0, 1.0], "anchor": "leftArm" }
    ]);
	
	var beam = renderer.createResource("BEAM_RENDERER", "fiskheroes:atom_booster");
    var fire = renderer.createResource("ICON", "fiskheroes:fire_layer_%s");
    var color = 0xffa200;
	booster_boots = boosters.create(renderer, "rightLeg", true, color, fire, beam).setOffset(3.0, 10.0, 0.0).setSize(2.0, 3.0);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    addAnimationWithData(renderer, "basic.ANTIBLAST", "tgheroes:dual_aim", "fiskheroes:aiming");
    utils.addFlightAnimationWithLanding(renderer, "iron_man.FLIGHT", "fiskheroes:flight/iron_man.anim.json");
    utils.addHoverAnimation(renderer, "iron_man.HOVER", "fiskheroes:flight/idle/iron_man");
}

function render(entity, renderLayer, isFirstPersonArm) {   
	if (renderLayer == "CHESTPLATE" || renderLayer == "LEGGINGS"){
		if (entity.getData("tgheroes:dyn/element_gun") > 0.5) {
            var blade_anchor = gun.anchor.set("rightArm");
            var blade_offSet = gun.setOffset(1.0, 9.0, -2.0);
            var blade_rot = gun.setRotation(90, 0, 0);
			gun.anchor = blade_anchor, blade_offSet, blade_rot;
            gun.render();
			var blade_anchor = gun.anchor.set("leftArm");
            var blade_offSet = gun.setOffset(0.0, 9.0, -2.0);
            var blade_rot = gun.setRotation(90, 0, 0);
			gun.anchor = blade_anchor, blade_offSet, blade_rot;
            gun.render();

		} 	
		else {
			var blade_anchor = gun.anchor.set("leftLeg");
            var blade_offSet = gun.setOffset(-3.0, 1.0, -3.0);
            var blade_rot = gun.setRotation(90, 0, 0);
			gun.anchor = blade_anchor, blade_offSet, blade_rot;
            gun.render();
			
			var blade_anchor = gun.anchor.set("rightLeg");
            var blade_offSet = gun.setOffset(3.0, 1.0, -3.0);
            var blade_rot = gun.setRotation(90, 0, 0);
			gun.anchor = blade_anchor, blade_offSet, blade_rot;
            gun.render();	
		}
	}	
	if (renderLayer == "BOOTS") {
        jet.render();
    }
	
	if (!isFirstPersonArm) {
		if (renderLayer == "BOOTS") {
            var boost = entity.getInterpolatedData("fiskheroes:flight_boost_timer");
            booster_boots.speedScale = 0.5 * boost;
            booster_boots.flutter = 1 + boost;

            booster_boots.render(entity, entity.getInterpolatedData("fiskheroes:dyn/booster_timer"));
        }
    }
}