extend("fiskheroes:hero_basic");
loadTextures({
   "layer1": "pack:captain_marvel_mcu_layer1",
    "layer2": "pack:captain_marvel_mcu_layer2",
    "lights": "pack:captain_marvel_mcu_glow",
	"mask": "pack:captain_marvel_mcu_mask.tx.json",
    "collar": "fiskheroes:mysterio_collar.tx.json"
});

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


var chest;
var overlay;


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";
    });
   renderer.setLights((entity, renderLayer) => {
        if (renderLayer == "HELMET" && entity.getData("fiskheroes:mask_open_timer2") <= 0) {
            return "lights";
        }
        return renderLayer == "LEGGINGS" ? null : null;
    });
}


function initEffects(renderer) {
	
	    overlay = renderer.createEffect("fiskheroes:overlay");
    overlay.texture.set(null, "mask");
	
   utils.bindTrail(renderer, "pack:captain_marvel_blur");
	
  chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(0.75).setYOffset(1);
	
    utils.addCameraShake(renderer, 0.015, 1.5, "fiskheroes:flight_boost_timer");
    utils.bindParticles(renderer, "fiskheroes:firestorm").setCondition(entity => entity.getData("fiskheroes:flying"));
  var color = 0xFF5900;

  chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(0.75).setYOffset(1);

    utils.addCameraShake(renderer, 0.015, 1.5, "fiskheroes:flight_boost_timer");
    utils.bindParticles(renderer, "fiskheroes:firestorm").setCondition(entity => entity.getData("fiskheroes:flying"));

    // Charged Beam
    var beam = renderer.createResource("BEAM_RENDERER", "fiskheroes:mysterio_beam");
    utils.bindBeam(renderer, "fiskheroes:charged_beam", beam, "rightArm", color, [
 { "firstPerson": [-3.75, 3.0, -8.0], "offset": [-0.5, 12.0, 0.0], "size": [1.5, 1.5] },
        { "firstPerson": [3.75, 3.0, -8.0], "offset": [-0.5, 12.0, 0.0], "size": [1.5, 1.5], "anchor": "leftArm" }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_charged_beam"));

    // Energy Projection
    utils.bindBeam(renderer, "fiskheroes:energy_projection", beam, "rightArm", color, [
        { "firstPerson": [-3.75, 3.0, -8.0], "offset": [-0.5, 12.0, 0.0], "size": [1.5, 1.5] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));
}

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, "mmcw.FLIGHT", "fiskheroes:flight/default_arms_forward.anim.json");
    utils.addHoverAnimation(renderer, "mmcw.HOVER", "fiskheroes:flight/idle/neutral");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "HELMET") {
        overlay.opacity = 1 - entity.getInterpolatedData("fiskheroes:mask_open_timer2");
        if (overlay.opacity < 1) {
            overlay.render();
        }

    }
    else if (renderLayer == "CHESTPLATE") {
     
          chest.render();
        }
    }

