extend("gowhp:kratos_upgraded");
loadTextures({
    "layer1": "gowhp:kratos/kratos_ragnarok_layer1",
    "layer2": "gowhp:kratos/kratos_ragnarok_layer2",
    "draupnir": "gowhp:kratos/draupnir",
    "draupnirspear": "gowhp:kratos/draupnirspear",
    "draupnirspear_lights": "gowhp:kratos/draupnirspear_lights"
});

var draupnirspearthrow;

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

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    addAnimation(renderer, "kratos.DISPLAY", "gowhp:artilleryoftheancients_charge")
        .setData((entity, data) => data.load(1.0))
        .setCondition(entity => (entity.as("DISPLAY").getDisplayType() == "HOLOGRAM" || entity.as("DISPLAY").getDisplayType() == "DATABASE_PREVIEW" || entity.as("DISPLAY").getDisplayType() == "FABRICATOR_PREVIEW" || entity.as("DISPLAY").getDisplayType() == "ITERATOR_PREVIEW" || entity.as("DISPLAY").getDisplayType() == "BOOK_PREVIEW"))
        .priority = 18;
    addAnimationWithData(renderer, "kratos.DRAUPNIRSPEAREQUIP", "gowhp:draupnirspearequip", "gowhp:dyn/draupnirspear_timer");
    addAnimationWithData(renderer, "kratos.DRAUPNIRSPEARBLOCKING", "gowhp:weaponfirstperson", "fiskheroes:shield_blocking_timer").setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear")));
    addAnimationWithData(renderer, "kratos.WHISPEROFTHEWORLDCHARGE", "gowhp:whisperoftheworld_charge", "fiskheroes:beam_charge").setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0 && entity.getData("fiskheroes:beam_charging") && !entity.getData("fiskheroes:beam_shooting")));
    addAnimationWithData(renderer, "kratos.WHISPEROFTHEWORLD", "gowhp:whisperoftheworld", "fiskheroes:beam_charge").setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0 && entity.getData("fiskheroes:beam_shooting")));
    addAnimationWithData(renderer, "kratos.WHISPEROFTHEWORLDDONE", "gowhp:whisperoftheworld", "fiskheroes:beam_charge").setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0 && !entity.getData("fiskheroes:beam_charging")));
    addAnimationWithData(renderer, "kratos.ARTILLERYOFTHEANCIENTSCHARGE", "gowhp:artilleryoftheancients_charge", "fiskheroes:beam_charge").setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1 && entity.getData("fiskheroes:beam_charging") && !entity.getData("fiskheroes:beam_shooting")));
    addAnimationWithData(renderer, "kratos.ARTILLERYOFTHEANCIENTS", "gowhp:artilleryoftheancients", "fiskheroes:beam_charge").setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1));
}

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

    var draupnirspearspin = renderer.createResource("MODEL", "gowhp:draupnirspear");
    draupnirspearspin.texture.set("draupnirspear", "draupnirspear_lights");
    draupnirspearspin.bindAnimation("gowhp:draupnirspearspin").setData((entity, data) => {
		data.load((entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0 && entity.getInterpolatedData("fiskheroes:beam_charge")));
	});
    draupnirspearspin.bindAnimation("gowhp:draupnirspearflag").setData((entity, data) => {
		data.load(entity.getData("gowhp:dyn/draupnirspear") * entity.loop(20) % 20);
	});
    draupnirspear = renderer.createEffect("fiskheroes:model").setModel(draupnirspearspin);
    draupnirspear.anchor.set("rightArm");
    draupnirspear.setScale(0.7);
    draupnirspear.setRotation(90.0, 90.0, 0.0);
    draupnirspear.setOffset(1.0, 9.0, -7.0);

    var draupnirspearspinfp = renderer.createResource("MODEL", "gowhp:draupnirspear");
    draupnirspearspinfp.texture.set("draupnirspear", "draupnirspear_lights");
    draupnirspearspinfp.bindAnimation("gowhp:draupnirspearflag").setData((entity, data) => {
		data.load(entity.getData("gowhp:dyn/draupnirspear") * entity.loop(20) % 20);
	});
    draupnirspearfp = renderer.createEffect("fiskheroes:model").setModel(draupnirspearspinfp);
    draupnirspearfp.anchor.set("rightArm");
    draupnirspearfp.setScale(0.7);
    draupnirspearfp.setRotation(90.0, 90.0, 0.0);
    draupnirspearfp.setOffset(1.0, 9.0, 0.0);

    var artilleryoftheancientsspearanimation1 = renderer.createResource("MODEL", "gowhp:draupnirspear");
    artilleryoftheancientsspearanimation1.texture.set("draupnirspear", "draupnirspear_lights");
    artilleryoftheancientsspearanimation1.bindAnimation("gowhp:draupnirspearartilleryoftheancients").setData((entity, data) => {
        data.load((entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1 && entity.getInterpolatedData("fiskheroes:beam_shooting")));
      });
    artilleryoftheancientsspear1 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear1.anchor.set("rightArm");
    artilleryoftheancientsspear1.setScale(0.7);
    artilleryoftheancientsspear1.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear1.setOffset(0.0, 100.0, 0.0);

    artilleryoftheancientsspear2 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear2.anchor.set("rightArm");
    artilleryoftheancientsspear2.setScale(0.7);
    artilleryoftheancientsspear2.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear2.setOffset(40.0, 90.0, 0.0);

    artilleryoftheancientsspear3 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear3.anchor.set("rightArm");
    artilleryoftheancientsspear3.setScale(0.7);
    artilleryoftheancientsspear3.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear3.setOffset(20.0, 80.0, 0.0);

    artilleryoftheancientsspear4 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear4.anchor.set("rightArm");
    artilleryoftheancientsspear4.setScale(0.7);
    artilleryoftheancientsspear4.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear4.setOffset(10.0, 110.0, 0.0);

    artilleryoftheancientsspear5 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear5.anchor.set("rightArm");
    artilleryoftheancientsspear5.setScale(0.7);
    artilleryoftheancientsspear5.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear5.setOffset(15.0, 120.0, 0.0);

    artilleryoftheancientsspear6 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear6.anchor.set("rightArm");
    artilleryoftheancientsspear6.setScale(0.7);
    artilleryoftheancientsspear6.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear6.setOffset(5.0, 140.0, 0.0);

    artilleryoftheancientsspear7 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear7.anchor.set("rightArm");
    artilleryoftheancientsspear7.setScale(0.7);
    artilleryoftheancientsspear7.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear7.setOffset(-40.0, 95.0, 0.0);

    artilleryoftheancientsspear8 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear8.anchor.set("rightArm");
    artilleryoftheancientsspear8.setScale(0.7);
    artilleryoftheancientsspear8.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear8.setOffset(-20.0, 150.0, 0.0);

    artilleryoftheancientsspear9 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear9.anchor.set("rightArm");
    artilleryoftheancientsspear9.setScale(0.7);
    artilleryoftheancientsspear9.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear9.setOffset(-10.0, 125.0, 0.0);

    artilleryoftheancientsspear10 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear10.anchor.set("rightArm");
    artilleryoftheancientsspear10.setScale(0.7);
    artilleryoftheancientsspear10.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear10.setOffset(-5.0, 100.0, 0.0);

    artilleryoftheancientsspear11 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear11.anchor.set("rightArm");
    artilleryoftheancientsspear11.setScale(0.7);
    artilleryoftheancientsspear11.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear11.setOffset(-15.0, 85.0, 0.0);

    artilleryoftheancientsspear12 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear12.anchor.set("rightArm");
    artilleryoftheancientsspear12.setScale(0.7);
    artilleryoftheancientsspear12.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear12.setOffset(60.0, 40.0, 0.0);

    artilleryoftheancientsspear13 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear13.anchor.set("rightArm");
    artilleryoftheancientsspear13.setScale(0.7);
    artilleryoftheancientsspear13.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear13.setOffset(50.0, 60.0, 0.0);

    artilleryoftheancientsspear14 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear14.anchor.set("rightArm");
    artilleryoftheancientsspear14.setScale(0.7);
    artilleryoftheancientsspear14.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear14.setOffset(-60.0, 50.0, 0.0);

    artilleryoftheancientsspear15 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear15.anchor.set("rightArm");
    artilleryoftheancientsspear15.setScale(0.7);
    artilleryoftheancientsspear15.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear15.setOffset(-50.0, 65.0, 0.0);

    artilleryoftheancientsspear16 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear16.anchor.set("rightArm");
    artilleryoftheancientsspear16.setScale(0.7);
    artilleryoftheancientsspear16.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear16.setOffset(60.0, 105.0, 0.0);

    artilleryoftheancientsspear17 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear17.anchor.set("rightArm");
    artilleryoftheancientsspear17.setScale(0.7);
    artilleryoftheancientsspear17.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear17.setOffset(-25.0, 120.0, 0.0);

    artilleryoftheancientsspear18 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear18.anchor.set("rightArm");
    artilleryoftheancientsspear18.setScale(0.7);
    artilleryoftheancientsspear18.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear18.setOffset(-35.0, 145.0, 0.0);

    artilleryoftheancientsspear19 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear19.anchor.set("rightArm");
    artilleryoftheancientsspear19.setScale(0.7);
    artilleryoftheancientsspear19.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear19.setOffset(30.0, 115.0, 0.0);

    artilleryoftheancientsspear20 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear20.anchor.set("rightArm");
    artilleryoftheancientsspear20.setScale(0.7);
    artilleryoftheancientsspear20.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear20.setOffset(20.0, 130.0, 0.0);

    artilleryoftheancientsspear21 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear21.anchor.set("rightArm");
    artilleryoftheancientsspear21.setScale(0.7);
    artilleryoftheancientsspear21.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear21.setOffset(10.0, 70.0, 0.0);

    artilleryoftheancientsspear22 = renderer.createEffect("fiskheroes:model").setModel(artilleryoftheancientsspearanimation1);
    artilleryoftheancientsspear22.anchor.set("rightArm");
    artilleryoftheancientsspear22.setScale(0.7);
    artilleryoftheancientsspear22.setRotation(-90.0, 0.0, 0.0);
    artilleryoftheancientsspear22.setOffset(-10.0, 75.0, 0.0);

    draupnir = renderer.createEffect("fiskheroes:model");
    draupnir.setModel(utils.createModel(renderer, "gowhp:draupnir", "draupnir"));
    draupnir.anchor.set("rightArm");

    var draupnirspearequip_color = 0x835E39;
    var draupnirspearequip_effect = renderer.createResource("BEAM_RENDERER", "gowhp:draupnirspearequip");

    draupnirspearequip = utils.createLines(renderer, draupnirspearequip_effect, draupnirspearequip_color, [
        {"start": [-1.0, 9.0, -1.5], "end": [-1.0, 9.0, -95.0], "size": [10.0, 10.0]},
        {"start": [-1.0, 9.0, -1.5], "end": [-1.0, 9.0, 70.0], "size": [10.0, 10.0]},
    ]);
    draupnirspearequip.anchor.set("rightArm");
    draupnirspearequip.setScale(1.0);
    draupnirspearequip.mirror = false;

    utils.bindBeam(renderer, "fiskheroes:charged_beam", "gowhp:whisperoftheworld", "rightArm", 0xD3D3D3, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [40.0, 40.0] }
    ]).setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0)).setParticles(renderer.createResource("PARTICLE_EMITTER", "gowhp:whisperoftheworld"));;

    utils.bindBeam(renderer, "fiskheroes:charged_beam", "gowhp:invisible", "rightArm", 0xD3D3D3, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [40.0, 40.0] }
    ]).setCondition(entity => (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1)).setParticles(renderer.createResource("PARTICLE_EMITTER", "gowhp:artilleryoftheancientsshoot"));

    utils.bindParticles(renderer, "gowhp:artilleryoftheancients").setCondition(entity => entity.getData("gowhp:dyn/draupnirspear") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1 && entity.getInterpolatedData("fiskheroes:beam_shooting_timer") > 0);

    var draupnirspearrunicchargeshake = renderer.bindProperty("fiskheroes:camera_shake").setCondition(entity => ((entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0 || entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1) && !entity.getData("gowhp:dyn/leviathanaxe_runic_cycle") == 0 && entity.getData("fiskheroes:beam_charging") && !entity.getData("fiskheroes:beam_shooting")));
    draupnirspearrunicchargeshake.factor = 0.05;

    var draupnirspearrunicshake = renderer.bindProperty("fiskheroes:camera_shake").setCondition(entity => ((entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 0 || entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1) && !entity.getData("gowhp:dyn/leviathanaxe_runic_cycle") == 0 && entity.getData("fiskheroes:beam_charging") && entity.getInterpolatedData("fiskheroes:beam_shooting_timer") > 0));
    draupnirspearrunicshake.factor = 0.1;
}

function render(entity, renderLayer, isFirstPersonArm) {
    parent.render(entity, renderLayer, isFirstPersonArm);
    if (renderLayer == "CHESTPLATE") {
        draupnir.render();
    }
    if (!isFirstPersonArm && (entity.getInterpolatedData("gowhp:dyn/draupnirspear_timer") > 0.5) && (entity.getHeldItem().isEmpty()) || ((entity.as("DISPLAY").getDisplayType() == "HOLOGRAM" || entity.as("DISPLAY").getDisplayType() == "DATABASE_PREVIEW" || entity.as("DISPLAY").getDisplayType() == "FABRICATOR_PREVIEW" || entity.as("DISPLAY").getDisplayType() == "ITERATOR_PREVIEW" || entity.as("DISPLAY").getDisplayType() == "BOOK_PREVIEW") && entity.getWornChestplate().suitType().startsWith("gowhp:kratos_ragnarok"))) {
        draupnirspear.render();
    }
    if (isFirstPersonArm && (entity.getInterpolatedData("gowhp:dyn/draupnirspear_timer") > 0.5) && (entity.getHeldItem().isEmpty())) {
        draupnirspearfp.render();
    }
    if (entity.getInterpolatedData('gowhp:dyn/draupnirspear_timer') > 0 && entity.getInterpolatedData('gowhp:dyn/draupnirspear_timer') < 0.5){
        draupnirspearequip.progress = Math.max(1 - (1 - entity.getInterpolatedData('gowhp:dyn/draupnirspear_timer')) * 1, 0);
        draupnirspearequip.opacity = Math.max(1 - (1 - entity.getInterpolatedData('gowhp:dyn/draupnirspear_timer')) * 1, 0);
        draupnirspearequip.render();
    }
    if (entity.getData("gowhp:dyn/draupnirspear") && entity.getData("fiskheroes:beam_shooting") && entity.getData("gowhp:dyn/draupnirspear_runic_cycle") == 1){
        artilleryoftheancientsspear1.render();
        artilleryoftheancientsspear2.render();
        artilleryoftheancientsspear3.render();
        artilleryoftheancientsspear4.render();
        artilleryoftheancientsspear5.render();
        artilleryoftheancientsspear6.render();
        artilleryoftheancientsspear7.render();
        artilleryoftheancientsspear8.render();
        artilleryoftheancientsspear9.render();
        artilleryoftheancientsspear10.render();
        artilleryoftheancientsspear11.render();
        artilleryoftheancientsspear12.render();
        artilleryoftheancientsspear13.render();
        artilleryoftheancientsspear14.render();
        artilleryoftheancientsspear15.render();
        artilleryoftheancientsspear16.render();
        artilleryoftheancientsspear17.render();
        artilleryoftheancientsspear18.render();
        artilleryoftheancientsspear19.render();
        artilleryoftheancientsspear20.render();
        artilleryoftheancientsspear21.render();
        artilleryoftheancientsspear22.render();
    }
}
