extend("fiskheroes:hero_basic");
loadTextures({
	"hair": "tgheroes:black_widow/endgame/widow_hair",
	"suit": "tgheroes:black_widow/endgame/widow_suit",
    "leggings": "tgheroes:black_widow/endgame/widow_legs",
    "boots": "tgheroes:black_widow/endgame/widow_boots",
	"suit_hair": "tgheroes:black_widow/endgame/widow_suit_hair",
	"batton": "tgheroes:black_widow/black_widow_batton"
});

var chest;

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);
	initEquipped(renderer);
	
    var model_batton = renderer.createResource("MODEL", "tgheroes:bwbatton");
    model_batton.texture.set("batton");
    model_batton.generateMirror();

    batton = renderer.createEffect("fiskheroes:model").setModel(model_batton);
    batton.anchor.set("rightArm");
    batton.setScale(1);
    batton.mirror = true;

	var model_back1 = renderer.createResource("MODEL", "tgheroes:bwbatton");
    model_back1.texture.set("batton");

    back1 = renderer.createEffect("fiskheroes:model").setModel(model_back1);
    back1.anchor.set("rightArm");
    back1.setScale(1);	
	
	var model_back2 = renderer.createResource("MODEL", "tgheroes:bwbatton");
    model_back2.texture.set("batton");

    back2 = renderer.createEffect("fiskheroes:model").setModel(model_back2);
    back2.anchor.set("rightArm");
    back2.setScale(1);	
}

function initEquipped(renderer) {
	utils.addLivery(renderer, "BERETTA_93", "gun");
	
    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "rightLeg", "scale": 0.7, "offset": [-2.4, 0.5, 1.25], "rotation": [90.0, 0.0, 0.0] },
        { "anchor": "leftLeg", "scale": 0.7, "offset": [2.4, 0.5, 1.25], "rotation": [90.0, 0.0, 0.0] }
    ]);
}


function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
    if (renderLayer == "CHESTPLATE") {
        if (entity.getData("fiskheroes:blade_timer") > 0.3) {
            var blade_anchor = batton.anchor.set("rightArm");
            var blade_offSet = batton.setOffset(1.0, 8.0, 0.0);
            var blade_rot = batton.setRotation(0, 180, 0);
          
  
            batton.anchor = blade_anchor, blade_offSet, blade_rot;
            batton.render();
        }
        else {
            var back_anchor = back1.anchor.set("body");
            var back_offSet = back1.setOffset(4.0, -1.0, 4.0);
            var back_rot = back1.setRotation(-90, 40, 0);
            var back_anchor = back2.anchor.set("body");
            var back_offSet = back2.setOffset(-4.0, -1.5, 4.0);
            var back_rot = back2.setRotation(-90, -40, 0);

            back2.anchor = back_anchor, back_offSet, back_rot;
            back2.render();
            back1.anchor = back_anchor, back_offSet, back_rot;
            back1.render();
        }

    }
}
