extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarredheroes:halo/halo_layer1",
    "layer2": "skarredheroes:halo/halo_layer2",
	"lights": "skarredheroes:halo/halo_lights.tx.json",
	"camo": "skarredheroes:halo/camo_shield",
	"camo_lights": "skarredheroes:halo/camo_shield_lights",
	"light": "skarredheroes:halo/light"
});

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

var Colors = {
    RED: 0xFF0000,
    ORANGE: 0xFF6A00,
    YELLOW: 0xFFD800,
    GREEN: 0x00D211,
    BLUE: 0x0026FF,
    INDIGO: 0x9000D3,
    VIOLET: 0xF200FF
};

var chest;
var camo;
var light;

var aura;

function init(renderer) {
    parent.init(renderer);
    renderer.setLights((entity, renderLayer) => !entity.isDisplayStand() ? "lights" : null);
}

function initEffects(renderer) {
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1).setYOffset(1);
	
    var magic = renderer.bindProperty("fiskheroes:spellcasting");
    magic.colorGeneric.set(0x21B165);

    camo = renderer.createEffect("fiskheroes:shield");
	camo.texture.set("camo", "camo_lights");
    camo.anchor.set("head");
    camo.setCurve(0.0, 0.0);
    camo.setOffset(0.0, 15.5, -12.0);
	camo.setRotation(0.0, -90.0, 0.0);
    camo.large = true;
	camo.setScale(8.5);
	
    light = renderer.createEffect("fiskheroes:shield");
	light.texture.set(null, "light");
    light.anchor.set("head");
    light.setCurve(0.0, 0.0);
    light.setOffset(0.0, 15.5, -12.0);
	light.setRotation(0.0, -90.0, 0.0);
    light.large = true;
	light.setScale(8.5);
	
    
    aura = auras.create(renderer, utils, "skarredheroes:aura_beam", 0xFFFFFF);
    
	
    utils.bindParticles(renderer, "skarredheroes:blue_aura")
        .setCondition(entity => (entity.getData("fiskheroes:heat_vision") && entity.getData("skarredheroes:dyn/auras") == 4));

    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0xFF0000);
    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 true;
    });

    utils.bindCloud(renderer, "fiskheroes:telekinesis", "skarredheroes:halo_telekinesis");
    utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "skarredheroes:repulsor_blast", "body", 0xFFC249, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [2.0, 2.0] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_antimatter"));
	
    utils.bindBeam(renderer, "fiskheroes:energy_projection", "skarredheroes:violet_aura_beam", "rightArm", 0xF200FF, [
        { "firstPerson": [-3.75, 3.0, -7.0], "offset": [0.0, 9.0, 0.0], "size": [1.5, 1.5] },
        { "firstPerson": [3.75, 3.0, -7.0], "offset": [0.0, 9.0, 0.0], "size": [1.5, 1.5], "anchor": "leftArm" }
    ]);

    utils.bindBeam(renderer, "fiskheroes:heat_vision", "fiskheroes:energy_projection", "body", 0xFF1000, [

    ]);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "halo.FLIGHT", "fiskheroes:flight/martian_comics.anim.json");
    utils.addHoverAnimation(renderer, "halo.HOVER", "fiskheroes:flight/idle/martian_comics");

    renderer.reprioritizeDefaultAnimation("PUNCH", -9);
    renderer.reprioritizeDefaultAnimation("AIM_BOW", -9);
	
    renderer.removeCustomAnimation("basic.BLOCKING");
    renderer.removeCustomAnimation("basic.CHARGED_BEAM");
    renderer.removeCustomAnimation("basic.ENERGY_PROJ");
    renderer.removeCustomAnimation("basic.AIMING");

    addAnimationWithData(renderer, "basic.BLOCK", "skarredheroes:red_aura", "fiskheroes:shield_blocking_timer");
    addAnimationWithData(renderer, "basic.AIMING", "skarredheroes:dual_hand_beam", "fiskheroes:aiming_timer");
    addAnimationWithData(renderer, "halo.BLAST", "fiskheroes:dual_hand_beam", "fiskheroes:beam_charge");
    addAnimationWithData(renderer, "halo.PROJ", "fiskheroes:dual_aiming", "fiskheroes:energy_projection");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!entity.getData('skarredheroes:dyn/rainbow')) {
        if (entity.getData("fiskheroes:shield_blocking")) {
            aura.render(renderLayer, 1.0, Colors.RED);
        }
        else if (entity.getData("fiskheroes:flying") || entity.getData('fiskheroes:telekinesis') && entity.getData('fiskheroes:grab_id') > -1) {
            aura.render(renderLayer, 1.0, Colors.ORANGE);
        }
        else if (entity.getData("fiskheroes:aiming")) {
            aura.render(renderLayer, 1.0, Colors.YELLOW);
        }
        else if (entity.getInterpolatedData("fiskheroes:spellcast_timer") > 0) {
            aura.render(renderLayer, 1.0, Colors.GREEN);
        }
        else if (entity.getInterpolatedData("fiskheroes:heat_vision") > 0) {
            aura.render(renderLayer, 1.0,+ Colors.BLUE);
			if (isFirstPersonArm) {
				light.render();
				light.anchor.ignoreAnchor(true);
            }
        }
        else if (entity.getInterpolatedData("fiskheroes:teleport_timer") > 0) {
            aura.render(renderLayer, 1.0, Colors.INDIGO);
        }
        else if (entity.getData('fiskheroes:time_since_damaged') >= 80 && entity.getHealth() < 20 && entity.getData('skarredheroes:dyn/auras') == 6) {
            aura.render(renderLayer, 1.0, Colors.VIOLET);
        }
    }
	
            if (isFirstPersonArm) {
                camo.anchor.ignoreAnchor(true);
            }
            else {
                camo.anchor.ignoreAnchor(false);
            }
	
    if (renderLayer == "CHESTPLATE" && !isFirstPersonArm) {
        chest.render();
    }
	
    if (renderLayer == "HELMET" || renderLayer == "CHESTPLATE" || renderLayer == "LEGGINGS" || renderLayer == "BOOTS") {
        var flight = entity.getInterpolatedData("fiskheroes:flight_timer") || entity.getData('fiskheroes:telekinesis') && entity.getData('fiskheroes:grab_id') > -1;

        var dmg = entity.getData('fiskheroes:time_since_damaged') >= 80 && entity.getHealth() < 20 && entity.getData('skarredheroes:dyn/auras') == 6 || entity.getData('skarredheroes:dyn/rainbow');
		
        //if (entity.getData("fiskheroes:aiming")) {
			//camo.unfold = entity.getInterpolatedData("fiskheroes:aiming_timer");
            //camo.render();
       // }

    }
}
