extend("skarlet:blue_beetle_base");
loadTextures({
});

var utils = implement("fiskheroes:external/utils");
var boosters = implement("fiskheroes:external/bloom_booster");

var booster_back;
var booster_back2;
var booster_back3;

function initEffects(renderer) {
    parent.initEffects(renderer);
        
    utils.bindTrail(renderer, "skarlet:blue_beetle").setCondition(entity => 
	(entity.getInterpolatedData("fiskheroes:blade_timer") < 1 && entity.getInterpolatedData("fiskheroes:blade_timer") > 0) || 
	(entity.getInterpolatedData("skarlet:dyn/buster_sword_timer") < 1 && entity.getInterpolatedData("skarlet:dyn/buster_sword_timer") > 0) || 
	(entity.getInterpolatedData("fiskheroes:shield_timer") < 1 && entity.getInterpolatedData("fiskheroes:shield_timer") > 0) || 
	(entity.getInterpolatedData("fiskheroes:flight_timer") < 0.5 && entity.getInterpolatedData("fiskheroes:flight_timer") > 0) || 
	(entity.getInterpolatedData("fiskheroes:flight_boost_timer") < 0.5 && entity.getInterpolatedData("fiskheroes:flight_boost_timer") > 0) || 
    (entity.getInterpolatedData("fiskheroes:aimed_timer") < 1 && entity.getInterpolatedData("fiskheroes:aimed_timer") > 0));
	
    var beam = renderer.createResource("BEAM_RENDERER", "skarlet:booster");
    var fire = renderer.createResource("ICON", "fiskheroes:blue_fire_layer_%s");
    var color = 0x00FFFF;
    booster_back = boosters.create(renderer, "body", true, color, fire, beam).setOffset(1.5, 7.6, 2.35).setRotation(20.0, 0.0, 15.0);
    booster_back2 = boosters.create(renderer, "body", true, color, fire, beam).setOffset(1.5, 5.6, 2.35).setRotation(20.0, 0.0, 15.0);
    booster_back3 = boosters.create(renderer, "body", true, color, fire, beam).setOffset(1.5, 3.6, 2.35).setRotation(20.0, 0.0, 15.0);
	
    utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "skarlet:blue_beetle_blaster", "rightArm", 0x00FFFF, [
        { "firstPerson": [-4.5, 3.75, -7.0], "offset": [-0.5, 9.0, 0.0], "size": [3.5, 3.5] }
    ]);
}
function render(entity, renderLayer, isFirstPersonArm) {
    parent.render(entity, renderLayer, isFirstPersonArm);

	if (!isFirstPersonArm && renderLayer == "CHESTPLATE") { 

		var boost = entity.getInterpolatedData("fiskheroes:flight_boost_timer");
		booster_back.speedScale = 0.5 * boost;
		booster_back.flutter = 1 + boost;

		var f = Math.min(Math.max(boost * 3 - 1.25, 0), 1);
		f = entity.isSprinting() ? 0.5 - Math.cos(2 * f * Math.PI) / 2 : 0;
		booster_back.setSize(1.5 + f * 2, 3.5 - f * 2);
		booster_back.render(entity, entity.getInterpolatedData("fiskheroes:flight_timer"));
	
		booster_back2.speedScale = 0.5 * boost;
		booster_back2.flutter = 1 + boost;

		var f = Math.min(Math.max(boost * 3 - 1.25, 0), 1);
		f = entity.isSprinting() ? 0.5 - Math.cos(2 * f * Math.PI) / 2 : 0;
		booster_back2.setSize(1.5 + f * 2, 3.5 - f * 2);
		booster_back2.render(entity, entity.getInterpolatedData("fiskheroes:flight_timer"));
	
		booster_back3.speedScale = 0.5 * boost;
		booster_back3.flutter = 1 + boost;

		var f = Math.min(Math.max(boost * 3 - 1.25, 0), 1);
		f = entity.isSprinting() ? 0.5 - Math.cos(2 * f * Math.PI) / 2 : 0;
		booster_back3.setSize(1.5 + f * 2, 3.5 - f * 2);
		booster_back3.render(entity, entity.getInterpolatedData("fiskheroes:flight_timer"));
	}
}
    
