extend("fiskheroes:hero_basic");
loadTextures({
	"hair": "tgheroes:elektra/elektra_hair",
	"suit": "tgheroes:elektra/elektra_suit",
    "leggings": "tgheroes:elektra/elektra_legs",
    "boots": "tgheroes:elektra/elektra_boots",
	"suit_hair": "tgheroes:elektra/elektra_suit_hair",
	"sai": "tgheroes:elektra/sai",
	"chokuto": "tgheroes:elektra/elektra_sword",
	"sheath": "fiskheroes:prometheus_sheath"
});

var chest;
var scabbard;
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 model_sai = renderer.createResource("MODEL", "tgheroes:elektra_sai");
    model_sai.texture.set("sai");
    model_sai.generateMirror();

    sai = renderer.createEffect("fiskheroes:model").setModel(model_sai);
    sai.setScale(1);
    sai.mirror = true;
	
	sheath = renderer.createEffect("fiskheroes:model");
    sheath.setModel(utils.createModel(renderer, "fiskheroes:prometheus_sheath", "sheath"));
    sheath.anchor.set("body");
	renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 0.535, "offset": [-5.03, 1.28, 2.43], "rotation": [-150.0, 90.0, 0.0] }
    ]);
	utils.addLivery(renderer, "CHOKUTO", "chokuto");
	
}

function render(entity, renderLayer, isFirstPersonArm) {
        if (entity.getData("fiskheroes:blade_timer") > 0.3) {
            var blade_anchor = sai.anchor.set("rightArm");
            var blade_offSet = sai.setOffset(1.0, 8.0, -3.0);
            var blade_rot = sai.setRotation(90, 0, 0);
           
            sai.anchor = blade_anchor, blade_offSet, blade_rot;
            sai.render();
		}
		else {
			var leg_anchor = sai.anchor.set("rightLeg");
            var leg_offSet = sai.setOffset(3.0, -3.0, 0.0);
            var leg_rot = sai.setRotation(180, 90, 0);
           
            sai.anchor = leg_anchor, leg_offSet, leg_rot;
            sai.render();
        }     
    chest.render();
	sheath.render();
}
