extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "tgheroes:cyborg/cyborg_layer1",
    "layer2": "tgheroes:cyborg/cyborg_layer2",
    "lights_layer1": "tgheroes:cyborg/cyborg_lights1",
    "lights_layer2": "tgheroes:cyborg/cyborg_lights2",	
	"cannon_inner": "fiskheroes:iron_man_mk50_cannon_inner",
	"cannon1": "tgheroes:cyborg/cyborg_crab1",
    "cannon2": "tgheroes:cyborg/cyborg_crab2",
    "cannon1_lights": "fiskheroes:iron_man_mk50_cannon1_lights",
    "cannon2_lights": "fiskheroes:iron_man_mk50_cannon2_lights"
});

var utils = implement("fiskheroes:external/utils");
var boosters = implement("fiskheroes:external/bloom_booster");
var booster_boots;
var booster_back;
var glow;
var mk50_cannon = implement("fiskheroes:external/mk50_cannon");
var cannon;
var metal_heat;

function init(renderer) {
    parent.init(renderer);
    renderer.setLights((entity, renderLayer) => renderLayer == "LEGGINGS" ? "lights_layer2" : renderLayer != "BOOTS" ? "lights_layer1" : null);
}

function initEffects(renderer) {
	cannon = mk50_cannon.create(renderer, "rightArm", 0x00ACFF);
	
	glow = renderer.createEffect("fiskheroes:glowerlay");
    glow.color.set(0xffffff);
	utils.bindParticles(renderer, "fiskheroes:harbinger_glow");
   
	var beam = renderer.createResource("BEAM_RENDERER", "fiskheroes:atom_booster");
    var blue_fire = renderer.createResource("ICON", "fiskheroes:deep_blue_fire_layer_%s");
    var color = 0x0033FF;
    booster_boots = boosters.create(renderer, "rightLeg", true, color, blue_fire, beam).setOffset(0.0, 7.0, 2.0).setSize(1.5, 3.0);
    booster_back = boosters.create(renderer, "body", true, color, blue_fire, beam).setOffset(1.5, 6.0, 1.75).setRotation(15.0, 0.0, 5.0);

	metal_heat = renderer.createEffect("fiskheroes:metal_heat");
    metal_heat.includeEffects(cannon.c1, cannon.c2);
	
    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0x00bfff);
    forcefield.setShape(36, 18).setOffset(0.0, 6.0, 0.0).setScale(1.5);
    forcefield.setCondition(entity => {
        forcefield.opacity = entity.getInterpolatedData("fiskheroes:shield_blocking_timer") * 0.15;
        return true;
    });
	
	utils.addCameraShake(renderer, 0.015, 1.5, "fiskheroes:flight_boost_timer");
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
	renderer.removeCustomAnimation("basic.BLOCKING");
    addAnimationWithData(renderer, "basic.BLOCKING", "fiskheroes:aiming", "fiskheroes:shield_blocking_timer").priority = -5;
    utils.addHoverAnimation(renderer, "atom.HOVER", "fiskheroes:flight/idle/default_back");
    utils.addFlightAnimation(renderer, "atom.FLIGHT", "fiskheroes:flight/propelled.anim.json", (entity, data) => {
        data.load(0, entity.getInterpolatedData("fiskheroes:flight_timer"));
        data.load(1, entity.getInterpolatedData("fiskheroes:flight_boost_timer"));
    });
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm) {
		if (renderLayer == "CHESTPLATE") {
            var boost = entity.getInterpolatedData("fiskheroes:flight_boost_timer");
            booster_back.speedScale = 0.5 * boost;
            booster_back.flutter = 1 + boost;

            var f = Math.min(Math.max(boost * 3 - 1.25, 0), 1);
            f = entity.isSprinting() ? 0.5 - Math.cos(2 * f * Math.PI) / 2 : 0;
            booster_back.setSize(1.5 + f * 2, 3.5 - f * 2);
            booster_back.render(entity, entity.getInterpolatedData("fiskheroes:dyn/booster_timer"));
        }
        else if (renderLayer == "BOOTS") {
            var boost = entity.getInterpolatedData("fiskheroes:flight_boost_timer");
            booster_boots.speedScale = 0.5 * boost;
            booster_boots.flutter = 1 + boost;

            booster_boots.setRotation(15 - 10 * boost, 0, 0);
            booster_boots.render(entity, entity.getInterpolatedData("fiskheroes:dyn/booster_timer"));
        }
    }
	glow.opacity = entity.getInterpolatedData("fiskheroes:teleport_timer");
    glow.render();
	cannon.render(entity.getInterpolatedData("fiskheroes:aimed_timer"));
	metal_heat.opacity = entity.getInterpolatedData("fiskheroes:metal_heat");
    metal_heat.render();
}
