extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarredheroes:harleyquinn/hq_classic_layer1",
    "layer2": "skarredheroes:harleyquinn/hq_classic_layer2",
	"roller_skates": "skarredheroes:harleyquinn/roller_skates_classic",
	"hair": "skarredheroes:harleyquinn/jester",
	"mallet" : "skarredheroes:harleyquinn/mallet"
});

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

var l_leg;
var r_leg;
var hair;
var mallet;

function init(renderer) {
    parent.init(renderer);
}

function initEffects(renderer) {
	
	var model_malletfp = renderer.createResource("MODEL", "skarredheroes:mallet");
	model_malletfp.texture.set("mallet");
    malletfp = renderer.createEffect("fiskheroes:model").setModel(model_malletfp);
    malletfp.anchor.set("rightArm");
	malletfp.setScale(1.00);
	malletfp.setOffset(0,0,0);
	malletfp.setRotation(-5, 0, 0);
	
	var model_mallet = renderer.createResource("MODEL", "skarredheroes:mallet");
    model_mallet.bindAnimation("skarredheroes:mallet").setData((entity, data) => data.load(entity.getInterpolatedData("skarredheroes:dyn/hammer_punching")));
	model_mallet.texture.set("mallet");
    mallet = renderer.createEffect("fiskheroes:model").setModel(model_mallet);
    mallet.anchor.set("rightArm");
	mallet.setScale(1.00);
	mallet.setOffset(-1,0,0);
	mallet.setRotation(-5, 0, 0);
	
	var model_hair = renderer.createResource("MODEL", "skarredheroes:jester");
	model_hair.texture.set("hair");
    hair = renderer.createEffect("fiskheroes:model").setModel(model_hair);
    hair.anchor.set("head");
	
    var model_l_leg = renderer.createResource("MODEL", "skarredheroes:rollerskate_left");
    model_l_leg.texture.set("roller_skates");
    l_leg = renderer.createEffect("fiskheroes:model").setModel(model_l_leg);
    l_leg.anchor.set("leftLeg");

    var model_r_leg = renderer.createResource("MODEL", "skarredheroes:rollerskate_right");
    model_r_leg.texture.set("roller_skates");
    r_leg = renderer.createEffect("fiskheroes:model").setModel(model_r_leg);
    r_leg.anchor.set("rightLeg");
	
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1.5).setYOffset(1);
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "HELMET") {
		hair.render();
	}
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
		chest.render();
		if (entity.getData('fiskheroes:blade_timer') >= 0.3) {
            mallet.render();
		}
	}
    if (isFirstPersonArm && renderLayer == "CHESTPLATE") {
		if (entity.getData('fiskheroes:blade_timer') >= 0.3) {
            malletfp.render();
		}
	}
	if (!isFirstPersonArm && renderLayer == "BOOTS") {
		if (entity.getData("fiskheroes:speeding")) {
			l_leg.render();
			r_leg.render();
		}
    }
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    var anim_sprint = renderer.createResource("ANIMATION", "fiskheroes:speedster_sprint");
    anim_sprint.setData((entity, data) => data.load(entity.getInterpolatedData("fiskheroes:dyn/speed_sprint_timer")));
    renderer.addCustomAnimation("harley.SPRINT", anim_sprint);

    addAnimationWithData(renderer, "harley.BELT", "skarredheroes:belt", "fiskheroes:blade_timer");

    renderer.removeCustomAnimation("basic.BLOCKING");

    addAnimationWithData(renderer, "harley.FP", "skarredheroes:malletfp", "fiskheroes:blade_timer");
	
	addAnimation(renderer, "mallet.HOLD", "skarredheroes:holdMallet").setData((entity, data) => {
		data.load(0, entity.getInterpolatedData('skarredheroes:dyn/hammer_punching'));
		data.load(1, entity.getInterpolatedData('fiskheroes:blade_timer'));
		}).setCondition(entity => (entity.getData('fiskheroes:blade_timer') >= 0.3)).priority = 10;
	
    addAnimation(renderer, "harley.IDLE", "skarredheroes:skates").setData((entity, data) => {
        data.load(1);
    })
}
