extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "wv:monica/rambeau_layer1",
    "layer2": "wv:monica/rambeau_layer2"
});
var chest
var utils = implement("fiskheroes:external/utils");
var color = 0x55FFFF;

var charge_right;
var aura_head;
var aura_head2;
var aura_body;
var aura_arms;
var aura_arms2;
var aura_legs;
var aura_legs2;

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.bindBeam(renderer, "fiskheroes:energy_projection", "wv:charge", "rightArm", color, [{
                "firstPerson": [-3.75, 3.0, -8.0],
                "offset": [0, 12.0, 0.0],
                "size": [1.5, 1.5]
            },
        ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_energy_projection"));

    utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "fiskheroes:cold_beam", "rightArm", color, [{
                "firstPerson": [-3.75, 3.0, -8.0],
                "offset": [-0.5, 12.0, 0.0],
                "size": [1.5, 1.5]
            }
        ]);

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

    hand_punch = utils.createLines(renderer, hand, "0x55FFFF", [{
                    "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 = false;

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

    charge_right = utils.createLines(renderer, charge, "0x55FFFF", [{
                    "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 = false;

    //Aura Head
    var beam = 0x999999; 
    aura_head = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.1, 0.0],
                    "size": [8.1, 8.1]
                }
            ]);
    aura_head.anchor.set("head");
    aura_head.setOffset(0.0, 0.0, 0.0).setRotation(0, 0, 0.0).setScale(16.0, 8.0, 16.0);
    aura_head.mirror = false;

    aura_head2 = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.1, 0.0],
                    "size": [8.1, 8.1]
                }
            ]);
    aura_head2.anchor.set("head");
    aura_head2.setOffset(0.0, -4.0, 4.0).setRotation(90, 0, 0.0).setScale(16.0, 8.0, 16.0);
    aura_head2.mirror = false;

    //Aura Body
    aura_body = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.0, 0.0],
                    "size": [4.0, 8.0]
                }
            ]);
    aura_body.anchor.set("body");
    aura_body.setOffset(0.0, 12.0, 0.0).setRotation(0, 0, 0.0).setScale(16.0, 12.0, 16.0);
    aura_body.mirror = false;

    //Aura Arms
    aura_arms = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.0, 0.0],
                    "size": [4.0, 4.0]
                }
            ]);
    aura_arms.anchor.set("rightArm");
    aura_arms.setOffset(1.0, 10.0, 0.0).setRotation(0, 0, 0.0).setScale(16.0, 12.0, 16.0);
    aura_arms.mirror = true;

    aura_arms2 = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.0, 0.0],
                    "size": [12.0, 4.0]
                }
            ]);
    aura_arms2.anchor.set("rightArm");
    aura_arms2.setOffset(1.0, 4.0, 2.0).setRotation(90, 0, 0.0).setScale(16.0, 4.0, 16.0);
    aura_arms2.mirror = true;

    //Aura Legs
    aura_legs = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.0, 0.0],
                    "size": [4.0, 4.0]
                }
            ]);
    aura_legs.anchor.set("rightLeg");
    aura_legs.setOffset(0.0, 12.0, 0.0).setRotation(0, 0, 0.0).setScale(16.0, 12.0, 16.0);
    aura_legs.mirror = true;

    aura_legs2 = utils.createLines(renderer, "wv:aura", beam, [{
                    "start": [0.0, 0.0, 0.0],
                    "end": [0.0, -1.0, 0.0],
                    "size": [12.0, 4.0]
                }
            ]);
    aura_legs2.anchor.set("rightLeg");
    aura_legs2.setOffset(0.0, 6.0, 2.0).setRotation(90, 0, 0.0).setScale(16.0, 4.0, 16.0);
    aura_legs2.mirror = true;
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.BLOCKING");
    renderer.removeCustomAnimation("basic.ENERGY_PROJ");
    utils.addFlightAnimation(renderer, "shazam.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "vision.HOVER", "fiskheroes:flight/idle/neutral");
    addAnimationWithData(renderer, "iron_man.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
    .priority = -8;
   
    addAnimationWithData(renderer, "billy.TELEKINESIS", "fiskheroes:aiming", "fiskheroes:energy_projection_timer");
    //addAnimationWithData(renderer, "billy.TELEKINESIS", "wv:photon_blast", "fiskheroes:energy_projection_timer");
    addAnimationWithData(renderer, "charge", "wv:charge", "fiskheroes:shield_timer");

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

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

    aura_head.opacity = glow;
    aura_head.render();
    aura_head2.opacity = glow;
    aura_head2.render()

    aura_body.opacity = glow;
    aura_body.render();

    aura_arms.opacity = glow;
    aura_arms.render();
    aura_arms2.opacity = glow;
    aura_arms2.render();

    aura_legs.opacity = glow;
    aura_legs.render();
    aura_legs2.opacity = glow;
    aura_legs2.render();
}
