extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "wv:sw/scarlet_witch_layer1",
    "layer2": "wv:sw/scarlet_witch_layer2"
});
var beam
var chest
var overlay
var utils = implement("fiskheroes:external/utils");
var color = 0xAA0000;
var charge_right;



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


function initEffects(renderer) {
    // parent.initEffects();
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(0.75).setYOffset(1);

    utils.bindCloud(renderer, "fiskheroes:telekinesis", "wv:tele");
    renderer.bindProperty("fiskheroes:spellcasting").colorGeneric.set(color);

    // Energy proj
    utils.bindBeam(renderer, "fiskheroes:energy_projection", "wv:charge", "rightArm", color, [
        { "firstPerson": [-3.75, 3.0, -8.0], "offset": [-0.5, 12.0, 0.0], "size": [1.5, 1.5] },
        { "firstPerson": [3.75, 3.0, -8.0], "offset": [-0.5, 12.0, 0.0], "size": [1.5, 1.5], "anchor": "leftArm" }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));

    var hand = renderer.createResource("BEAM_RENDERER", "wv:hand");

    hand_punch = utils.createLines(renderer, hand, "0xAA0000", [{
        "start": [0, -0.1, 0],
        "end": [0, 0.1, 0],
        "size": [3, 3]
    }
    ]);
    hand_punch.anchor.set("rightArm");
    hand_punch.setOffset(0.5, 9.0, 0.0).setRotation(0.0, 0.0, 0.0).setScale(16);
    hand_punch.mirror = true;

    var charge = renderer.createResource("BEAM_RENDERER", "wv:charge");

    charge_right = utils.createLines(renderer, charge, "0xAA0000", [{
        "start": [0, -0.1, 0],
        "end": [0, 0.1, 0],
        "size": [3, 3]
    }
    ]);
    charge_right.anchor.set("rightArm");
    charge_right.setOffset(0.5, 9.0, 0.0).setRotation(0.0, 0.0, 0.0).setScale(16);
    charge_right.mirror = true;
}
function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.ENERGY_PROJ");
    renderer.removeCustomAnimation("basic.TELEKINESIS");
    renderer.removeCustomAnimation("basic.AIMING");
    utils.addFlightAnimation(renderer, "shazam.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "vision.HOVER", "fiskheroes:flight/idle/neutral");
    addAnimationWithData(renderer, "scarlet_witch.DUAL_AIMING", "fiskheroes:dual_aiming", "fiskheroes:aiming_timer")
    .priority = 10;

  

    addAnimation(renderer, "scarlet_witch.HOLOSTAND", "wv:levitation")
    .setData((entity, data) => {
        var holo = entity.getInterpolatedData("wv:dyn/holoanimation");
        data.load(4*holo <= 0.95 ? 4*holo : 0.95);
    });
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
    if (entity.isWearingFullSuit()) {
        if (entity.isPunching()|| entity.getData("fiskheroes:flight_timer") || entity.getData("fiskheroes:aiming_timer") == 1 || entity.getInterpolatedData("wv:dyn/holoanimation") > 0) {
            hand_punch.render();
        }
    }
    }
