extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "gowhp:atreus/atreus_layer1",
    "layer2": "gowhp:atreus/atreus_layer2",
    "bow": "gowhp:atreus/atreus_talon_bow",
    "arrow": "gowhp:atreus/atreus_arrow",
    "quiver": "gowhp:atreus/atreus_quiver",
    "runic_wolves": "gowhp:atreus/runic_wolves"
});

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

function init(renderer) {
    parent.init(renderer);
    initEffects(renderer);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    addAnimation(renderer, "atreus.SPRINT", "gowhp:sprint_atreus")
        .setData((entity, data) => data.load(1.0))
        .setCondition(entity => (entity.isSprinting()))
        .priority = 21;
}

function initEffects(renderer) {
    utils.addLivery(renderer, "COMPOUND_BOW", "bow");
    utils.addLivery(renderer, "ARROW", "arrow");
    utils.addLivery(renderer, "QUIVER", "quiver");

    var runicsummonenergy_color = 0x368BC1;
    var runicsummonenergy_beam = renderer.createResource("BEAM_RENDERER", "gowhp:runicsummonenergy");

    runicsummonenergyarms = utils.createLines(renderer, runicsummonenergy_beam, runicsummonenergy_color, [
        {"start": [-0.3, -1.0, -1.1], "end": [-1.7, 4.5, -1.1], "size": [10.0, 10.0]},
        {"start": [-1.7, -1.0, -1.1], "end": [-0.3, 4.5, -1.1], "size": [10.0, 10.0]},
        {"start": [-1.7, 4.0, -1.1], "end": [-0.3, 6.5, -1.1], "size": [10.0, 10.0]},
        {"start": [-0.3, 4.0, -1.1], "end": [-1.7, 6.5, -1.1], "size": [10.0, 10.0]},

        {"start": [-0.3, -1.0, 1.1], "end": [-1.7, 4.5, 1.1], "size": [10.0, 10.0]},
        {"start": [-1.7, -1.0, 1.1], "end": [-0.3, 4.5, 1.1], "size": [10.0, 10.0]},
        {"start": [-1.7, 4.0, 1.1], "end": [-0.3, 6.5, 1.1], "size": [10.0, 10.0]},
        {"start": [-0.3, 4.0, 1.1], "end": [-1.7, 6.5, 1.1], "size": [10.0, 10.0]},

        {"start": [-1.8, -1.0, 1.0], "end": [-1.8, 4.5, -1.0], "size": [10.0, 10.0]},
        {"start": [-1.8, -1.0, -1.0], "end": [-1.8, 4.5, 1.0], "size": [10.0, 10.0]},
        {"start": [-1.8, 4.0, -1.0], "end": [-1.8, 6.5, 1.0], "size": [10.0, 10.0]},
        {"start": [-1.8, 4.0, 1.0], "end": [-1.8, 6.5, -1.0], "size": [10.0, 10.0]},
    ]);
    runicsummonenergyarms.anchor.set("rightArm");
    runicsummonenergyarms.setScale(1.5);
    runicsummonenergyarms.mirror = true;

    utils.bindBeam(renderer, "fiskheroes:charged_beam", "gowhp:wrathofthewolf", "head", 0x368BC1, [
        { "offset": [12.0, 10.0, 3.0], "size": [6.0, 6.0] },
        { "offset": [-12.0, 10.0, 3.0], "size": [6.0, 6.0] }
    ]);

    var runic_wolves_walk = renderer.createResource("MODEL", "gowhp:runic_wolves");
    runic_wolves_walk.texture.set("runic_wolves");
    runic_wolves_walk.bindAnimation("gowhp:runicwolfwalk").setData((entity, data) => {
        data.load(entity.getInterpolatedData("fiskheroes:beam_shooting_timer"));
    });
    runic_wolves_walk.bindAnimation("gowhp:runicwolfmove").setData((entity, data) => {
        data.load(entity.getInterpolatedData("fiskheroes:beam_shooting_timer"));
    });
    runic_wolves = renderer.createEffect("fiskheroes:model").setModel(runic_wolves_walk);
    runic_wolves.anchor.set("head");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (entity.getData("fiskheroes:beam_charge")){
        runicsummonenergyarms.progress = Math.max(1 - (1 - entity.getInterpolatedData('fiskheroes:beam_charge')) * 1, 0);
        runicsummonenergyarms.opacity = Math.max(1 - (1 - entity.getInterpolatedData('fiskheroes:beam_charge')) * 1, 0);
        runicsummonenergyarms.render();
    }
    if (entity.getData("fiskheroes:beam_shooting_timer")){
        runic_wolves.render();
    }
}