extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "tgheroes:spawn/spawn_suit",
    "cape": "tgheroes:spawn/spawn_cape"
});

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

function init(renderer) {
    parent.init(renderer);
    renderer.showModel("HELMET", "head", "headwear", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
    renderer.fixHatLayer("HELMET");
}

function initEffects(renderer) {
	physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.weight = 1.2;
    physics.maxFlare = 1;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.5;
    physics.flareElasticity = 8;
    physics.setTickHandler(entity => {
        
        physics.headingAngle = 90 -  20;
        physics.restAngle = 40;
        physics.restFlare =  1.0;
        physics.idleFlutter = 0.15 + 0.25 ;
        physics.flutterSpeed =  0.3;
    });

    cape = capes.create(renderer, 26, "fiskheroes:cape_default.mesh.json");
	cape.effect.width = 18;
    cape.effect.texture.set("cape");
	utils.bindCloud(renderer, "fiskheroes:teleportation", "tgheroes:doorman_teleport");
	
	utils.bindBeam(renderer, "fiskheroes:charged_beam", "fiskheroes:energy_projection", "rightArm", 0x5aa64a, [
        { "firstPerson": [-3.75, 3.0, -8.0], "offset": [0.5, 12.0, 0.0], "size": [3.0, 3.0],}
    ]);
	utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "fiskheroes:repulsor_blast", "rightArm", 0x5aa64a, [
        { "firstPerson": [-4.5, 3.75, -7.0], "offset": [-0.5, 9.0, 0.0], "size": [2.0, 2.0] }
    ]);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "spawn.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "spawn.HOVER", "fiskheroes:flight/idle/default");
	
	renderer.removeCustomAnimation("basic.CHARGED_BEAM");
    addAnimationWithData(renderer, "antimonitor.ANTIBLAST", "fiskheroes:aiming", "fiskheroes:beam_charge");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm) {
            
            cape.render({
                "wind": 1 + 0.3 ,
                "windFactor": 1 - 0.7 ,
                "flutter": physics.getFlutter(entity),
                "flare": physics.getFlare(entity)
            });
        }
}