extend("fiskheroes:hero_basic");
loadTextures({
	"hair": "tgheroes:witch/comics/witch_wig",
	"suit": "tgheroes:witch/comics/witch_suit",
    "leggings": "tgheroes:witch/comics/witch_legs",
    "boots": "tgheroes:witch/comics/witch_boots",
	"suit_hair": "tgheroes:witch/comics/witch_suit_hair",
	"cape": "tgheroes:witch/comics/witch_cape"
});

var magic;
var magic2;
var chest;
var utils = implement("fiskheroes:external/utils");
var capes = implement("fiskheroes:external/capes");
var cape;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "CHESTPLATE") {
            return entity.getWornHelmet().suitType() == $SUIT_NAME ? "suit_hair" : "suit";
        }
	    else if (renderLayer == "LEGGINGS") {
            return entity.getWornChestplate().suitType() == $SUIT_NAME ? "leggings" : "leggings";
		}
        return renderLayer == "HELMET" ? "hair" : "boots" 
    });

    renderer.showModel("HELMET", "head", "headwear", "body");
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
    renderer.showModel("LEGGINGS", "body", "rightLeg", "leftLeg");
}

function initEffects(renderer) {
	var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.3;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;
    cape = capes.createDefault(renderer, 24, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 16;
	
	var magic3 = renderer.bindProperty("fiskheroes:spellcasting");
    magic3.colorEarthCrack.set(0x76181a);
    magic3.colorAtmosphere.set(0x76181a);

	var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0x76181a);
    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.bindBeam(renderer, "fiskheroes:repulsor_blast", "tgheroes:chaos_beam", "rightArm", 0xff242a, [
        { "firstPerson": [-4.5, 3.75, -7.0], "offset": [-0.5, 9.0, 0.0], "size": [1.5, 1.5] }
    ]);
	
	var beam = renderer.createResource("BEAM_RENDERER", "tgheroes:chaos_beam");
    magic = utils.createLines(renderer, beam, 0x76181a, [
        {"start": [0, 0.8, 0], "end": [0.0, -1.0, 0.0], "size": [3.0, 3.0, 3.0]},
    ]);
    magic.setOffset(-1.0, 8.0, 0.0).setScale(4.3);
    magic.anchor.set("leftArm");
    magic.mirror = true;
	
	magic2 = utils.createLines(renderer, beam, 0xff0000, [
    {"start": [0, 0.8, 0], "end": [0.0, -1.0, 0.0], "size": [3.0, 3.0, 3.0]},
    ]);
    magic2.setOffset(1.0, 8.0, 0.0).setScale(4.3);
    magic2.anchor.set("rightArm");
    magic2.mirror = true;
	
	utils.bindCloud(renderer, "fiskheroes:telekinesis", "tgheroes:chaos_telekinesis");
	
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1).setYOffset(1);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "magic1.FLIGHT", "fiskheroes:flight/propelled_hands.anim.json");
    utils.addHoverAnimation(renderer, "magic1.HOVER", "fiskheroes:flight/idle/propelled_hands");
	 renderer.removeCustomAnimation("basic.BLOCKING");
    addAnimationWithData(renderer, "basic.BLOCKING", "fiskheroes:aiming", "fiskheroes:shield_blocking_timer")
        .priority = -5;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
	
	if (renderLayer == "CHESTPLATE") {
	magic.progress = entity.getInterpolatedData("fiskheroes:aiming") || entity.getInterpolatedData("fiskheroes:flying") || entity.getInterpolatedData("fiskheroes:shield") || entity.getInterpolatedData("fiskheroes:telekinesis") || entity.getInterpolatedData("fiskheroes:spell_fraction");
	magic.render();
	magic2.progress = entity.getInterpolatedData("fiskheroes:aiming") || entity.getInterpolatedData("fiskheroes:flying") || entity.getInterpolatedData("fiskheroes:shield") || entity.getInterpolatedData("fiskheroes:telekinesis") || entity.getInterpolatedData("fiskheroes:spell_fraction");
	magic2.render();
	cape.render(entity);
    }
	
}
