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({
    "lights": "ahhp:darkseid_model_lights",
    "model": "ahhp:darkseid_model"
});

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

function initAnimations(renderer) {
    addAnimation(renderer, "darkseid.base", "ahhp:darkseid")
        .setData((entity, data) => data.load(entity.isAlive()))
        .setCondition(entity => (!entity.isSneaking() && entity.getHeldItem().isEmpty()) && entity.getData("fiskheroes:shield_blocking_timer") == 0)
        .priority = 10;
    addAnimationWithData(renderer, "darkseid.BLOCKING", "ahhp:force_field_holding", "fiskheroes:shield_blocking_timer")
        .priority = -5;
    utils.addFlightAnimationWithLanding(renderer, "darkseid.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "darkseid.HOVER", "fiskheroes:flight/idle/neutral");
    addAnimationWithData(renderer, "darkseid.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8;
}

function initEffects(renderer) {
    models_stuff.setOpacityWithoutMask(renderer);
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "ahhp:omega_beam", "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_antimatter"));
    glow = renderer.createEffect("fiskheroes:glowerlay");
    glow.color.set(0x1F4480);
    utils.bindCloud(renderer, "fiskheroes:teleportation", "fiskheroes:breach");

    utils.bindParticles(renderer, "fiskheroes:harbinger_glow");

    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0x16089E);
    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;
    });

    models = models_stuff.basicModels(renderer, "darkseid");
    models_stuff.bindSpeedingTrail(renderer, "ahhp:darkseidspeeding");
    models_stuff.bindGrowShrinkTrail(renderer, "ahhp:darkseidgrowing");
    utils.bindParticles(renderer, "fiskheroes:black_manta_dceu_eyes").setCondition(entity => entity.getData("fiskheroes:beam_charging") && entity.getData("fiskheroes:beam_charge") < 1);
}

function render(entity, renderLayer, isFirstPersonArm) {
    models.render(entity, renderLayer);
}
