extend("fiskheroes:hero_basic");
loadTextures({
    //Turbo Base Mode
    "null": "pkg:null",
    "base": "pkg:turbo_base_suit",
    "lights": "pkg:turbo_base_lights",
    //Turbo Strength Mode
    "strength": "pkg:turbo_strenght_suit",
    "strength_lights": "pkg:turbo_strenght_lights",
    //Turbo Flight Mode
    "flight": "pkg:turbo_flight_suit",
    "flight_lights": "pkg:turbo_flight_lights",
    //Turbo Stealth Mode
    "stealth": "pkg:turbo_stealth_suit",
    "stealth_lights": "pkg:turbo_stealth_lights",
    //Turbo Speed Mode
    "speed": "pkg:turbo_speed_suit",
    "speed_lights": "pkg:turbo_speed_lights",
    //Turbo Scuba Mode
    "scuba": "pkg:turbo_scuba_suit",
    "scuba_lights": "pkg:turbo_scuba_lights",
    "lashing": "pkg:lash",
    "lash": "pkg:energy_rope",
    "lashup": "pkg:energy_grap",
    //Turbo Super Mode
    "super": "pkg:turbo_super_mod",
    "super_cape": "pkg:turbo_super_cape.tx.json"
});

var utils = implement("fiskheroes:external/utils");
var capes = implement("fiskheroes:external/capes");
var stealth;
var strength;
var flight;
var speed;
var scuba;
var supermode;

var lash

var glow
var glow2
var glow3
var glow4
var glow5
var glow6
var glow7

function init(renderer) {
    parent.init(renderer);
    renderer.showModel("CHESTPLATE", "head", "headwear", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
    renderer.fixHatLayer("CHESTPLATE");
    renderer.setLights((entity, renderLayer) => {
        if (!entity.isDisplayStand() && renderLayer == "CHESTPLATE") {
            var timer = entity.getInterpolatedData("pkg:dyn/turbo_timer");
            return timer == 0 ? "null" : timer < 1 ? "lights" : "lights";
        }
        return "lights";
    });
    renderer.setTexture((entity, renderLayer) => {
        if (!entity.isDisplayStand() && renderLayer == "CHESTPLATE") {
            var timer = entity.getInterpolatedData("pkg:dyn/turbo_timer");
            return timer == 0 ? "null" : timer < 1 ? "base" : "base";
        }
        return "base";
    });
}

function initEffects(renderer) {
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    cape = capes.createDefault(renderer, 24, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("super_cape");
    cape.effect.width = 15;

    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0x00DAFF);

    utils.addCameraShake(renderer, 0.015, 1.5, "fiskheroes:flight_boost_timer");

    stealth = renderer.createEffect("fiskheroes:overlay");
    stealth.texture.set("stealth");

    strength = renderer.createEffect("fiskheroes:overlay");
    strength.texture.set("strength", "strength_lights");

    flight = renderer.createEffect("fiskheroes:overlay");
    flight.texture.set("flight", "flight_lights");

    supermode = renderer.createEffect("fiskheroes:overlay");
    supermode.texture.set("super");

    var webs = renderer.bindProperty("fiskheroes:webs");
    webs.textureRope.set("lash");
    webs.textureRopeBase.set("lashup");

    var model_lash = renderer.createResource("MODEL", "pkg:turbokanca");
    model_lash.texture.set("lashing");
    lash = renderer.createEffect("fiskheroes:model").setModel(model_lash);
    lash.anchor.set("rightArm");
    lash.setScale(1.0);

    speed = renderer.createEffect("fiskheroes:overlay");
    speed.texture.set("speed", "speed_lights");

    stealth = renderer.createEffect("fiskheroes:overlay");
    stealth.texture.set("stealth", "stealth_lights");

    scuba = renderer.createEffect("fiskheroes:overlay");
    scuba.texture.set("scuba", "scuba_lights");
    //Turbo Mod

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/turbo_timer') > 0 && entity.getInterpolatedData('pkg:dyn/turbo_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/turbo_timer') > 0 && entity.getInterpolatedData('pkg:dyn/turbo_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/turbo_timer') > 0 && entity.getInterpolatedData('pkg:dyn/turbo_timer') < 1);

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/scuba_timer') > 0 && entity.getInterpolatedData('pkg:dyn/scuba_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/scuba_timer') > 0 && entity.getInterpolatedData('pkg:dyn/scuba_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/scuba_timer') > 0 && entity.getInterpolatedData('pkg:dyn/scuba_timer') < 1);

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/strength_timer') > 0 && entity.getInterpolatedData('pkg:dyn/strength_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/strength_timer') > 0 && entity.getInterpolatedData('pkg:dyn/strength_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/strength_timer') > 0 && entity.getInterpolatedData('pkg:dyn/strength_timer') < 1);

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/stealth_timer') > 0 && entity.getInterpolatedData('pkg:dyn/stealth_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/stealth_timer') > 0 && entity.getInterpolatedData('pkg:dyn/stealth_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/stealth_timer') > 0 && entity.getInterpolatedData('pkg:dyn/stealth_timer') < 1);

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/flight_timer') > 0 && entity.getInterpolatedData('pkg:dyn/flight_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/flight_timer') > 0 && entity.getInterpolatedData('pkg:dyn/flight_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/flight_timer') > 0 && entity.getInterpolatedData('pkg:dyn/flight_timer') < 1);

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/speed_timer') > 0 && entity.getInterpolatedData('pkg:dyn/speed_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/speed_timer') > 0 && entity.getInterpolatedData('pkg:dyn/speed_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/speed_timer') > 0 && entity.getInterpolatedData('pkg:dyn/speed_timer') < 1);

    utils.bindParticles(renderer, "pkg:turbo_energy_blue").setCondition(entity => entity.getInterpolatedData('pkg:dyn/super_timer') > 0 && entity.getInterpolatedData('pkg:dyn/super_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/super_timer') > 0 && entity.getInterpolatedData('pkg:dyn/super_timer') < 1);
    utils.bindParticles(renderer, "pkg:turbo_smoke").setCondition(entity => entity.getInterpolatedData('pkg:dyn/super_timer') > 0 && entity.getInterpolatedData('pkg:dyn/super_timer') < 1);


    glow = renderer.createEffect("fiskheroes:glowerlay");
    glow.color.set(0x00FFFF);

    glow2 = renderer.createEffect("fiskheroes:glowerlay");
    glow2.color.set(0x00FFFF);

    glow3 = renderer.createEffect("fiskheroes:glowerlay");
    glow3.color.set(0x00FFFF);

    glow4 = renderer.createEffect("fiskheroes:glowerlay");
    glow4.color.set(0x00FFFF);

    // HEAT_VISION
    utils.bindBeam(renderer, "fiskheroes:heat_vision", "fiskheroes:cold_beam", "head", 0x00FFFF, [
        { "firstPerson": [2.2, 0.0, 2.0], "offset": [2.2, -3.3, -4.0], "size": [1.0, 0.5] },
        { "firstPerson": [-2.2, 0.0, 2.0], "offset": [-2.2, -3.3, -4.0], "size": [1.0, 0.5] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));

    glow5 = renderer.createEffect("fiskheroes:glowerlay");
    glow5.color.set(0x00FFFF);

    glow6 = renderer.createEffect("fiskheroes:glowerlay");
    glow6.color.set(0x00FFFF);

    glow7 = renderer.createEffect("fiskheroes:glowerlay");
    glow7.color.set(0x00FFFF);

    utils.bindTrail(renderer, "pkg:energy");

    // Beam
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "pkg:lightning", "rightArm", 0xD9FFFF, [
        { "firstPerson": [-4.5, 3.75, -8.0], "offset": [-0.5, 9.0, 0.0], "size": [3.0, 3.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_antimatter"));

    utils.bindBeam(renderer, "fiskheroes:energy_projection", "pkg:lightning", "body", 0xD9FFFF, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [4.0, 4.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));

    utils.bindBeam(renderer, "fiskheroes:lightning_cast", "fiskheroes:lightning_cast", "rightArm", 0xD9FFFF, [
        { "firstPerson": [-8.0, 4.5, -10.0], "offset": [-0.5, 9.0, 0.0], "size": [0.75, 0.75] }
    ]);

    // Flight
    utils.bindTrail(renderer, "pkg:shazam_flight").setCondition(entity => entity.getData("fiskheroes:flying"));
    utils.bindTrail(renderer, "pkg:wizard_shazam");
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "flight.FLIGHT", "fiskheroes:flight/propelled_hands.anim.json");
    utils.addHoverAnimation(renderer, "flight.HOVER", "fiskheroes:flight/idle/propelled_hands");
    addAnimationWithData(renderer, "turbo.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8;

    utils.addFlightAnimation(renderer, "super.FLIGHT", "fiskheroes:flight/default_arms_forward.anim.json").setCondition(entity => entity.getData("pkg:dyn/super_timer") > 0 && entity.getData("pkg:dyn/super_timer") < 1);

    addAnimation(renderer, "WALL_RUN", "pkg:wall_running").setData((entity, data) => {
        var input_rotate = entity.getInterpolatedData("pkg:dyn/climb") > 0 ? 1 : 0;
        data.load(0, entity.getInterpolatedData("pkg:dyn/climb") * 2);
        data.load(1, entity.getInterpolatedData("pkg:dyn/climb") * 2);
        data.load(2, input_rotate); // rotation data var doesnt work for this
        data.load(4, -(input_rotate / 3.5));

    })

    renderer.removeCustomAnimation("basic.AIMING");

    addAnimationWithData(renderer, "spiderman.AIMING", "fiskheroes:web_aim_right", "fiskheroes:web_aim_right_timer")
        .priority = 2;

    addAnimationWithData(renderer, "spiderman.AIMING_LEFT", "fiskheroes:web_aim_left", "fiskheroes:web_aim_left_timer")
        .priority = 2;

    addAnimationWithData(renderer, "spiderman.WEB_RAPPEL", "fiskheroes:web_rappel", "fiskheroes:web_rappel_timer")
        .priority = 5;

    utils.addAnimationEvent(renderer, "WEBSWING_DEFAULT", "fiskheroes:swing_default");
    utils.addAnimationEvent(renderer, "WEBSWING_RIGHT", "fiskheroes:swing_right");
    utils.addAnimationEvent(renderer, "WEBSWING_LEFT", "fiskheroes:swing_left");
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_DEFAULT", [
        "fiskheroes:swing_roll",
        "fiskheroes:swing_roll2",
        "fiskheroes:swing_roll5"
    ]);
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_RIGHT", "fiskheroes:swing_rotate_right");
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_LEFT", "fiskheroes:swing_rotate_left");
    utils.addAnimationEvent(renderer, "WEBSWING_ZIP", "fiskheroes:swing_zip");
    utils.addAnimationEvent(renderer, "WEBSWING_DIVE", [
        "fiskheroes:swing_dive",
        "fiskheroes:swing_dive2"
    ]);
    utils.addAnimationEvent(renderer, "WEBSWING_LEAP", "fiskheroes:swing_springboard");
    utils.addAnimationEvent(renderer, "WEBSWING_SHOOT_RIGHT", "fiskheroes:web_swing_shoot_right");
    utils.addAnimationEvent(renderer, "WEBSWING_SHOOT_LEFT", "fiskheroes:web_swing_shoot_left");
    utils.addAnimationEvent(renderer, "WEBSHOOTER_SHOOT_RIGHT", "fiskheroes:web_shoot_right");
    utils.addAnimationEvent(renderer, "WEBSHOOTER_SHOOT_LEFT", "fiskheroes:web_shoot_left");
    utils.addAnimationEvent(renderer, "CEILING_CRAWL", "fiskheroes:crawl_ceiling");

    addAnimationWithData(renderer, "antimonitor.ANTIBLAST", "fiskheroes:aiming", "fiskheroes:beam_charge");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (entity.getData("pkg:dyn/lash_timer") > 0.4) {
        var lash_anchor = lash.anchor.set("rightArm");
        var lash_offSet = lash.setOffset(0, 6, -4.0);
        var lash_rot = lash.setRotation(-35, -90, -35);

        lash.anchor = lash_anchor, lash_offSet, lash_rot;
        lash.render();
    }
    if (renderLayer == "CHESTPLATE") {
        stealth.opacity = entity.getInterpolatedData("pkg:dyn/stealth_timer");
        stealth.render();
    }
    if (renderLayer == "CHESTPLATE") {
        strength.opacity = entity.getInterpolatedData("pkg:dyn/strength_timer");
        strength.render();
    }
    if (renderLayer == "CHESTPLATE") {
        flight.opacity = entity.getInterpolatedData("pkg:dyn/flight_timer");
        flight.render();
    }
    if (renderLayer == "CHESTPLATE") {
        speed.opacity = entity.getInterpolatedData("pkg:dyn/speed_timer");
        speed.render();
    }
    if (renderLayer == "CHESTPLATE") {
        scuba.opacity = entity.getInterpolatedData("pkg:dyn/scuba_timer");
        scuba.render();
    }
    if (renderLayer == "CHESTPLATE") {
        supermode.opacity = entity.getInterpolatedData("pkg:dyn/super_timer");
        supermode.render();
    }
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity);
    }
    glow.opacity = entity.getData('pkg:dyn/turbo_timer') > 0 && entity.getData('pkg:dyn/turbo_timer') < 1;
    glow.render();

    glow2.opacity = entity.getData('pkg:dyn/scuba_timer') > 0 && entity.getData('pkg:dyn/scuba_timer') < 1;
    glow2.render();

    glow3.opacity = entity.getData('pkg:dyn/speed_timer') > 0 && entity.getData('pkg:dyn/speed_timer') < 1;
    glow3.render();

    glow4.opacity = entity.getData('pkg:dyn/flight_timer') > 0 && entity.getData('pkg:dyn/flight_timer') < 1;
    glow4.render();

    glow5.opacity = entity.getData('pkg:dyn/strength_timer') > 0 && entity.getData('pkg:dyn/strength_timer') < 1;
    glow5.render();

    glow6.opacity = entity.getData('pkg:dyn/stealth_timer') > 0 && entity.getData('pkg:dyn/stealth_timer') < 1;
    glow6.render();

    glow7.opacity = entity.getData('pkg:dyn/super_timer') > 0 && entity.getData('pkg:dyn/super_timer') < 1;
    glow7.render();
}