extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "pkg:doctor_doom_layer1",
    "layer2": "pkg:doctor_doom_layer2",
    "null": "pkg:null",
    "cape":"pkg:doctor_doom_cape"
});

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

var boosters;
var physics;
var cape;
var color = 0x00750E;

var repulsor;

function init(renderer) {
    parent.init(renderer);
    physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.weight = 1.2;
    physics.maxFlare = 1;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.5;
    physics.flareElasticity = 8;

    cape = capes.create(renderer, 24, "fiskheroes:cape_default.mesh.json");
    cape.effect.texture.set("cape");

    renderer.showModel("CHESTPLATE", "head", "headwear", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
    renderer.fixHatLayer("CHESTPLATE");
}


function initEffects(renderer) {


    utils.bindCloud(renderer, "fiskheroes:telekinesis", "pkg:telekinesis_loki");
    utils.bindCloud(renderer, "fiskheroes:teleportation", "pkg:teleport_loki");

    repulsor = renderer.createEffect("fiskheroes:overlay");

    boosters = iron_man_boosters.create(renderer, "pkg:repulsor_layer_%s", true);

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

    var beam = renderer.createResource("BEAM_RENDERER", "pkg:low_beam");
    utils.bindBeam(renderer, "fiskheroes:energy_projection", beam, "body", 0x00750E, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [8.0, 8.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));

    var color = 0x00750E;
    var magic = renderer.bindProperty("fiskheroes:spellcasting");
    magic.colorGeneric.set(0x00750E);
    magic.colorEarthCrack.set(0x00750E);
    magic.colorAtmosphere.set(0x00750E);
    magic.colorWhip.set(color);

    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0x00750E);
    forcefield.setShape(36, 18).setOffset(0.0, 6.0, 0.0).setScale(1.25);
    forcefield.setCondition(entity => {
        forcefield.opacity = entity.getInterpolatedData("fiskheroes:shield_blocking_timer") * 0.15;
        return true;
    });

}

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

    addAnimationWithData(renderer, "iron_man.ROLL", "fiskheroes:flight/barrel_roll", "fiskheroes:barrel_roll_timer")
        .priority = 10;

}

function render(entity, renderLayer, isFirstPersonArm) {
    var f = entity.getInterpolatedData("fiskheroes:flight_timer");
    cape.render({
        "wind": 1 + 0.3 * f,
        "windFactor": 1 - 0.7 * f,
        "flutter": physics.getFlutter(entity),
        "flare": physics.getFlare(entity)
    });
    boosters.render(entity, renderLayer, isFirstPersonArm, false);

    if (renderLayer == "CHESTPLATE") {
        repulsor.opacity = entity.getInterpolatedData("fiskheroes:dyn/booster_r_timer");
        repulsor.texture.set(null, "repulsor");
        repulsor.render();
        repulsor.opacity = entity.getInterpolatedData("fiskheroes:dyn/booster_l_timer");
        repulsor.texture.set(null, "repulsor_left");
        repulsor.render();
    }
    else if (renderLayer == "BOOTS") {
        repulsor.opacity = entity.getInterpolatedData("fiskheroes:dyn/booster_timer");
        repulsor.texture.set(null, "repulsor_boots");
        repulsor.render();
    }
}