extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "pkg:ven-ghan_suit",
    "layer2": "pkg:ven-ghan_suit",
    "scabbard": "pkg:joker_scabbard",
    "gun": "pkg:ven-ghan-gun",
    "bomb": "pkg:ven-ghan-bomb",
    "sword":"pkg:vengahn_sword"
});

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

var scabbard;
var gun;
var gun_back;

var sword
var sword_back

function initEffects(renderer) {

    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0x9B00EB);

    gun = renderer.createEffect("fiskheroes:model");
    gun.setModel(utils.createModel(renderer, "pkg:ven-ghan_gun", "gun", null));
    gun.anchor.set("rightArm");
    gun.mirror = false;

    gun_back = renderer.createEffect("fiskheroes:model");
    gun_back.setModel(utils.createModel(renderer, "pkg:ven-ghan_gun", "gun", null));
    gun_back.anchor.set("rightArm");
    gun_back.setScale(0.3)
    gun_back.mirror = false;

    sword = renderer.createEffect("fiskheroes:model");
    sword.setModel(utils.createModel(renderer, "pkg:venghansword", "sword"));
    sword.anchor.set("rightArm");
    sword.setOffset(2, 8, -1.55)
    sword.setScale(1.0)
    sword.setRotation(90, 90, 0)

    sword_back = renderer.createEffect("fiskheroes:model");
    sword_back.setModel(utils.createModel(renderer, "pkg:venghansword", "sword", null));
    sword_back.anchor.set("rightArm");
    sword_back.setScale(0.3)
    sword_back.mirror = false;


    utils.addLivery(renderer, "GRENADE", "bomb");

    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "rightLeg", "scale": 0.7, "offset": [-2.4, 0.5, 1.25], "rotation": [90.0, 0.0, 0.0] },
    ]).slotIndex = 1;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        // this is the issue >> scabbard.render();
    }
    gun.opacity = !entity.getInterpolatedData("pkg:dyn/gun");
    gun.render();
    if (renderLayer == "CHESTPLATE") {
        var back_anchor = gun.anchor.set("body");
        var back_offSet = gun.setOffset(4.25, 0, 3.0);
        var back_rot = gun.setRotation(90, -35, 90);
        var back_scale = gun.setScale(0.7)

        gun_back.anchor = back_anchor, back_offSet, back_rot, back_scale;
        gun_back.opacity = entity.getInterpolatedData("pkg:dyn/gun");
        gun_back.render();
    }
    sword.opacity = !entity.getInterpolatedData("fiskheroes:aiming");
    sword.render();
    if (renderLayer == "CHESTPLATE") {
        var back_anchor = sword.anchor.set("body");
        var back_offSet = sword.setOffset(-3.25, 0, 3.0);
        var back_rot = sword.setRotation(-90, 90, -90);
        var back_scale = sword.setScale(0.7)

        sword_back.anchor = back_anchor, back_offSet, back_rot, back_scale;
        sword_back.opacity = entity.getInterpolatedData("fiskheroes:aiming");
        sword_back.render();
    }
}