extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "fan:alast1",
    "layer2": "fan:alast2",
    "pants": "fan:alastpants",
    "boots": "fan:alastboots",
    "tentacle": "fan:tentacle",
    "shadowdome": "fan:shadow",
    "ears": "fan:ears" 
});
var utils = implement("fiskheroes:external/utils");

var ears;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "LEGGINGS") {
            return entity.getWornChestplate().suitType() == $SUIT_NAME ? "pants" : "layer2";
        }
        return renderLayer == "BOOTS" ? "boots" : "layer1";
    });
    
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
}

function render(entity, renderLayer) {
    ears.render();
    if (renderLayer == "LEGGINGS") {
        
    }};
    
    function initEffects(renderer) {
        ears = renderer.createEffect("fiskheroes:model");
        ears.setModel(utils.createModel(renderer, "fan:ears", "ears"));
        ears.anchor.set("head");
        ears.setScale(1);
        ears.setOffset(4, -11, 4);
        ears.setRotation(90, 90, -90)
     
	var shadowdome = renderer.bindProperty("fiskheroes:shadowdome");
	shadowdome.texture.set("shadowdome", "shadowdome");
	shadowdome.setShape(36, 36);
 
    var forcefield = renderer.bindProperty("fiskheroes:forcefield");
    forcefield.color.set(0xf92424);
    forcefield.setShape(36, 18).setOffset(0.0, 16.0, 0.0).setScale(3);
    forcefield.setCondition(entity => {
        forcefield.opacity = entity.getInterpolatedData("fiskheroes:shield_blocking_timer") * 0.5;
        return true;
    });

        var ock_arm = utils.createModel(renderer, "fan:tentacle", "tentacle");
        var ock_claw = utils.createModel(renderer, "fan:tentacle_end", "tentacle");
        ock_claw.bindAnimation("fiskheroes:ock_claw").setData((entity, data) => {
            var t = entity.as("TENTACLE");
            data.load(0, 1 - Math.min(t.getCaster().getInterpolatedData("fiskheroes:tentacle_extend_timer") * 2, 1));
            data.load(1, t.getIndex());
            data.load(2, t.getGrabTimer());
            data.load(3, t.getStrikeTimer());
            
        });
        
        utils.setOpacityWithData(renderer, 0.0, 1.0, "fiskheroes:shadowform_timer");
        utils.bindCloud(renderer, "fiskheroes:particle_cloud", "fiskheroes:shadow_smoke").setCondition(entity => entity.getData("fiskheroes:shadowform"));
        
        var tentacles = renderer.bindProperty("fiskheroes:tentacles").setTentacles([
            { "offset": [2.0, -4.5, -2.0], "direction": [13.0, 10.0, -10.0] },
            { "offset": [-2.0, -4.5, -2.0], "direction": [-13.0, 10.0, -10.0] },
            { "offset": [2.0, -7.5, -2.0], "direction": [13.0, -10.0, -10.0] },
            { "offset": [-2.0, -7.5, -2.0], "direction": [-13.0, -10.0, -10.0] }
        ]);
        tentacles.anchor.set("body");
        tentacles.setSegmentModel(ock_arm);
        tentacles.setHeadModel(ock_claw);
        tentacles.segmentLength = 1;
        tentacles.segments = 25;
    }
