extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarlet:wonder_woman/ww_layer1",
    "layer2": "skarlet:wonder_woman/ww_layer2",
    "mask": "skarlet:wonder_woman/ww_mask",
    "chest": "skarlet:wonder_woman/ww_chest",
    "cape": "skarlet:wonder_woman/ww_cape",
    "capehair": "skarlet:wonder_woman/ww_cape_hair",
    "shield": "skarlet:wonder_woman/ww_shield",
    "lasso": "skarlet:wonder_woman/lasso",
    "lasso_rope": "skarlet:wonder_woman/lasso_rope",
    "null": "skarlet:null"
});

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

var physics;

var cape;

var lasso_side;
var lasso_hand;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "CHESTPLATE") {
            return entity.getWornHelmet().suitType() == $SUIT_NAME ? "layer1" : "chest";
        }
		if (renderLayer == "HELMET") {
			return entity.getWornChestplate().suitType() == $SUIT_NAME ? "layer1" : "mask";
		}
        return renderLayer == "BOOTS" ? "layer2" : "layer1";
    });

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

function initEffects(renderer) {
    model_lasso_side = renderer.createResource("MODEL", "skarlet:lasso_side");
    model_lasso_side.texture.set(null, "lasso");

    lasso_side = renderer.createEffect("fiskheroes:model").setModel(model_lasso_side);
    lasso_side.anchor.set("body");

    model_lasso_hand = renderer.createResource("MODEL", "skarlet:lasso_hand");
    model_lasso_hand.texture.set(null, "lasso");

    lasso_hand = renderer.createEffect("fiskheroes:model").setModel(model_lasso_hand);
    lasso_hand.anchor.set("rightArm");

    utils.addLivery(renderer, "SHIELD", "shield");
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1.5).setYOffset(1);
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.weight = 1.3;
    physics.maxFlare = 0.4;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;
    cape = capes.createDefault(renderer, 24, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.width = 14;
	
    var webs = renderer.bindProperty("fiskheroes:webs");

    webs.textureRopeBase.set(null, "null");
    webs.textureRope.set(null, "lasso_rope");

    utils.bindTrail(renderer, "skarlet:wonder_woman");

    var equipped = renderer.bindProperty("fiskheroes:equipped_item");
    equipped.setItems([
        { "anchor": "body", "scale": 1.0, "offset": [0.0, 5.0, 3.75], "rotation": [90.0, -180.0, 0.0] }
    ]).slotIndex = 0;
    equipped.addOffset("QUIVER", -0.5, 0.0, 1.36);
	
    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 0.535, "offset": [-5.03, -1.28, 3.03], "rotation": [-150.0, 90.0, 0.0] }
    ]).slotIndex = 1;
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "mmc.FLIGHT", "fiskheroes:flight/martian_comics.anim.json");
    utils.addHoverAnimation(renderer, "mmc.HOVER", "fiskheroes:flight/idle/martian_comics");
    
    utils.addAnimationEvent(renderer, "WEBSWING_DEFAULT", "fiskheroes:swing_default");
    utils.addAnimationEvent(renderer, "WEBSWING_RIGHT", "fiskheroes:swing_right");
    utils.addAnimationEvent(renderer, "WEBSWING_LEFT", "fiskheroes:swing_left");

    renderer.reprioritizeDefaultAnimation("BLOCK_CAPS_SHIELD", -9);
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity);
        chest.render();
        if (entity.getEquipmentInSlot(4).nbt().getString('HeroType') == 'skarlet:wonder_woman_comics') {
			cape.effect.texture.set("capehair");
        } else {
			cape.effect.texture.set("cape");
		}
        if (!entity.getData("fiskheroes:web_swinging")) {
            lasso_side.render();
        } 
    }
    if (entity.getData("fiskheroes:web_swinging") && !(entity.getData("fiskheroes:web_swinging_timer") > 0)) {
        lasso_hand.render();
    }
}
