extend("fiskheroes:hero_basic");
loadTextures({
	"hair": "tgheroes:coll/coll_hair",
	"suit": "tgheroes:coll/coll_suit_nohair",
    "leggings": "tgheroes:coll/coll_legs",
    "boots": "tgheroes:coll/coll_boots",
	"suit_hair": "tgheroes:coll/coll_suit",
	"katana": "tgheroes:coll/coll_katana"
});

var chest;
var chi;
var chi2;
var utils = implement("fiskheroes:external/utils");

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");
}

function initEffects(renderer) {
	
	chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1).setYOffset(1);
    var beam = renderer.createResource("BEAM_RENDERER", "tgheroes:chi_beam");
    chi = utils.createLines(renderer, beam, 0xffffff, [
        {"start": [0, 0.8, 0], "end": [0.0, -1.0, 0.0], "size": [3.0, 3.0, 3.0]},
    ]);
    chi.setOffset(-1.0, 8.0, 0.0).setScale(4.3);
    chi.anchor.set("leftArm");
    chi.mirror = true;
	
	chi2 = utils.createLines(renderer, beam, 0xffffff, [
    {"start": [0, 0.8, 0], "end": [0.0, -1.0, 0.0], "size": [3.0, 3.0, 3.0]},
    ]);
    chi2.setOffset(1.0, 8.0, 0.0).setScale(4.3);
    chi2.anchor.set("rightArm");
    chi2.mirror = true;
	
	utils.addLivery(renderer, "KATANA", "katana");

    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 0.535, "offset": [-3.05, 0.52, 3.0], "rotation": [-148.0, 90.0, 0.0] }
    ]).slotIndex = 0;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
	chi.progress = entity.getInterpolatedData("fiskheroes:blade");
	chi.render();
	chi2.progress = entity.getInterpolatedData("fiskheroes:blade");
	chi2.render();
    }
	 if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
}