extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "pkg:morgana_suit",
    "layer2": "pkg:morgana_suit",
    "cape":"pkg:morgana_cape"
});

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

var helmet;
var helmet2;
var physics;
var cape;
var color = 0xF2C40A;
var chest;

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) {
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1).setYOffset(1);

    utils.bindCloud(renderer, "fiskheroes:telekinesis", "pkg:telekenesis_morgana");
    utils.bindCloud(renderer, "fiskheroes:teleportation", "pkg:teleport_morgana");

    helmet2 = renderer.createEffect("fiskheroes:antennae").setSegments(8);
    helmet2.anchor.set("head");
    helmet2.angle = -110.0;
    helmet2.offset = 4.5;

    helmet = renderer.createEffect("fiskheroes:ears");
    helmet.anchor.set("head");
    helmet.angle = 15;
    helmet.inset = -0.03;

    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", 0xF2C40A, [
        { "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 = 0xF2C40A;
    var magic = renderer.bindProperty("fiskheroes:spellcasting");
    magic.colorGeneric.set(0xF2C40A);
    magic.colorEarthCrack.set(0xF2C40A);
    magic.colorAtmosphere.set(0xF2C40A);
    magic.colorWhip.set(color);

    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0xF2AD2E);
    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) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
    helmet.render();
    helmet2.render();
    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)
    });
    }