extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "tgheroes:moon_knight/moon_knight_layer1",
    "layer2": "tgheroes:moon_knight/moon_knight_layer2",
    "crescent": "tgheroes:moon_knight/crescent",
	"rope": "tgheroes:moon_knight/mk_rope",
	"grapple": "tgheroes:moon_knight/moon_knight_grap",
	"cape": "tgheroes:moon_knight/moon_knight_cape"
});

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


function initEffects(renderer) {
    var webs = renderer.bindProperty("fiskheroes:webs");
    webs.textureRope.set("rope");
    webs.textureRopeBase.set("grapple");

    var model_crescent = renderer.createResource("MODEL", "tgheroes:crescent");
    model_crescent.texture.set("crescent");
    model_crescent.generateMirror();

    crescent = renderer.createEffect("fiskheroes:model").setModel(model_crescent);
    crescent.anchor.set("rightArm");
    crescent.setScale(1);
    crescent.mirror = true;
	
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;

    cape = capes.createGlider(renderer, 24, "tgheroes:cape_moonknight.mesh.json", physics);
    cape.effect.texture.set("cape");
}



function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity, entity.getInterpolatedData("fiskheroes:wing_animation_timer"));
    }
		else if (renderLayer == "CHESTPLATE") {
        if (entity.getData("fiskheroes:blade_timer") > 0.2) {
            var blade_anchor = crescent.anchor.set("rightArm");
            var blade_offSet = crescent.setOffset(1.0, 8.0, 0.0);
            var blade_rot = crescent.setRotation(90, 180, 90);
            
            crescent.anchor = blade_anchor, blade_offSet, blade_rot;
            crescent.render();
        }
	}
}