extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "soulhp:doctor_doom_layer1",
    "layer2": "soulhp:doctor_doom_layer2",
    "cape": "soulhp:doctor_doom_cape",
    "jetpack": "soulhp:doctor_doom_jetpack"
});

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

var cape;
var color = 0X00FF00;
var jetpack;
var booster;
function initEffects(renderer) {
    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(color);
    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 entity.getData("fiskheroes:flight_boost_timer") == 0;
    });

    utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "fiskheroes:line", "rightArm", color, [{
                "firstPerson": [-3, 2, -3.0],
                "offset": [-3, 8.0, 0],
                "size": [1, 1]
            }
        ]);

    utils.bindBeam(renderer, "fiskheroes:charged_beam", "soulhp:laser", "rightArm", color, [{
                "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"));

    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    cape = capes.createDefault(renderer, 20, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 11;

    jetpack = renderer.createEffect("fiskheroes:model");
    jetpack.setModel(utils.createModel(renderer, "soulhp:HipJetpack", "jetpack", null));
    jetpack.anchor.set("body");

    var fire = renderer.createResource("ICON", "fiskheroes:repulsor_layer_%s");
    booster = renderer.createEffect("fiskheroes:booster")
    booster.setIcon(fire).setOffset(-5, 11, 0).setSize(1.1, 4.4);
    booster.anchor.set("body");
    booster.mirror = true;

}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.BLOCKING");
    renderer.removeCustomAnimation("basic.CHARGED_BEAM");

    utils.addFlightAnimation(renderer, "doctor_doom.FLIGHT", "soulhp:doctor_doom/propelled.anim.json");

    addAnimationWithData(renderer, "doctor_doom.CHARGED_BEAM", "fiskheroes:aiming", "fiskheroes:beam_charge");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity);
        jetpack.render()
        jetpack.opacity = entity.getInterpolatedData("fiskheroes:flight_timer") * 2

        var boost = entity.getInterpolatedData("fiskheroes:flight_boost_timer");
        booster.progress = entity.getInterpolatedData("fiskheroes:dyn/booster_timer");
        booster.speedScale = 1.6 * boost;
        booster.flutter = 1 + boost;

        booster.render();
    }
}