var firestorm = implement("pkg:external/sabbac_base");
var landing = implement("pkg:external/superhero_landing_1");
var utils = implement("fiskheroes:external/utils");

function init(hero) {
    hero.setName("Sabbac");
    hero.setTier(8);

    hero.setHelmet("item.superhero_armor.piece.helmet");
    hero.setChestplate("item.superhero_armor.piece.jacket");
    hero.setLeggings("item.superhero_armor.piece.pants");
    hero.setBoots("item.superhero_armor.piece.shoes");

    hero.addPowers("pkg:sabbac_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 5.0, 0);
    hero.addAttribute("JUMP_HEIGHT", 0.5, 0);
    hero.addAttribute("FALL_RESISTANCE", 5.0, 0);

    hero.addKeyBind("AIM", "key.shoot", 1);
    hero.addKeyBind("CHARGED_PUNCH", "Fire Punch", 3);
    hero.addKeyBind("CHARGED_BEAM", "Hell Fire", 2);


    hero.setDamageProfile(entity => !entity.getHeldItem().isWeapon() ? "PUNCH" : null);
    hero.addDamageProfile("PUNCH", {
        "types": {
            "BLUNT": 1.0,
            "MAGIC": 0.7
        }
    });

    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.addAttributeProfile("HELL", hellProfile);
    hero.setAttributeProfile(getAttributeProfile);
    hero.setHasProperty((entity, property) => property == "MASK_TOGGLE");
    hero.setAttributeProfile(getAttributeProfile);
    hero.addAttributeProfile("PUNCH", punchProfile);
    hero.addAttributeProfile("BLUNT", bluntProfile);
    hero.supplyFunction("canAim", canAim);

    firestorm.init(hero);
    hero.setTickHandler((entity, manager) => {
        utils.flightOnIntangibility(entity, manager);
        landing.tick(entity, manager);
    });
}

function isKeyBindEnabled(entity, keyBind) {
    switch (keyBind) {
        default:
            return true;
    }

}

function isModifierEnabled(entity, modifier) {
    switch (modifier.name()) {
        default:
            return true;
    }
}

function getAttributeProfile(entity) {
    return entity.getData("fiskheroes:beam_charging") || entity.getData("fiskheroes:beam_shooting") ? "SCREAM" : null;

}

function hellProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("BASE_SPEED", -0.4, 0);

}

function canAim(entity) {
    return entity.getHeldItem().isEmpty()
}

function punchProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 25, 0);
    profile.addAttribute("KNOCKBACK", 30.0, 0);
}

function bluntProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 20, 0);
}

function getAttributeProfile(entity) {
    return entity.getData("fiskheroes:punchmode") ? "PUNCH" : "BLUNT";
}