extend("ahhp:hero_with_models");

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

loadTextures({
    "cape": "ahhp:superman_returns_cape",
    "model": "ahhp:superman_returns_model"
});

function getColor() {
    return 0x0951D8;
}

function getTrail() {
    return "ahhp:superman_returns";
}

function init(renderer) {
    parent.init(renderer);
    renderer.fixHatLayer("CHESTPLATE");
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm");
    renderer.showModel("LEGGINGS", "rightLeg", "leftLeg");
    initEffects(renderer);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimationWithLanding(renderer, "superman.FLIGHT", "fiskheroes:flight/default_arms_forward.anim.json");
    utils.addHoverAnimation(renderer, "superman.HOVER", "fiskheroes:flight/idle/neutral");
    addAnimationWithData(renderer, "superman.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8;
    addAnimationWithData(renderer, "superman.ROLL", "fiskheroes:flight/barrel_roll", "fiskheroes:barrel_roll_timer")
        .priority = 10;
}

function initEffects(renderer) {
    utils.bindBeam(renderer, "fiskheroes:heat_vision", "fiskheroes:heat_vision", "head", 0xFF0000, [
        { "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_heat_vision"));
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "ahhp:super_breath", "head", getColor(), [
        { "firstPerson": [0.0, 2.0, 2.0], "offset": [0.0, -2.0, -3.0], "size": [1.0, 1.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_antimatter"));
    models = models_stuff.noHelmetModels(renderer, "superman_returns");
    models_stuff.bindSpeedingTrail(renderer, getTrail());
    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("cape");
    cape.effect.width = 14;

}

function render(entity, renderLayer, isFirstPersonArm) {
    models.render(entity, renderLayer);
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity);
    }
}
