var landing = implement("pkg:external/superhero_landing_1");

function init(hero) {
    hero.setName("General Zod");
    hero.setTier(7);

    hero.setChestplate("item.superhero_armor.piece.chestpiece");
    hero.setLeggings("item.superhero_armor.piece.pants");
    hero.setBoots("item.superhero_armor.piece.boots");

    hero.addPowers("pkg:kryptonian_physiology", "pkg:unleashed_rage");
    hero.addAttribute("PUNCH_DAMAGE", 12.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", -2.5, 0);
    hero.addAttribute("SPRINT_SPEED", 0.25, 1);
    hero.addAttribute("JUMP_HEIGHT", 2.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 5.0, 0);

    hero.addKeyBind("SUPER_SPEED", "Super Speed", 1);
    hero.addKeyBind("GROUND_SMASH", "Ground Smash", 2);
    hero.addKeyBind("ENERGY_PROJECTION", "Frost Breath", 2);
    hero.addKeyBind("CHARGED_PUNCH", "Supersonic Punch", 3);
    hero.addKeyBind("HEAT_VISION", "Heat Vision", 4);
    hero.addKeyBind("CHARGED_BEAM", "Heat Vision", 4);
    hero.addKeyBind("UNLEASHED_RAGE", "Unleash Rage", 5);
    hero.addKeyBind("TELEPORT", "Go to the Moon(You need to look to the moon)", 1);

    hero.setDefaultScale(1.1);
    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setHasProperty((entity, property) => property == "BREATHE_SPACE");
    hero.addAttributeProfile("PUNCH", punchProfile);
    hero.addAttributeProfile("BLUNT", bluntProfile);
    hero.setAttributeProfile(getAttributeProfile);

    hero.setTickHandler((entity, manager) => {
        landing.tick(entity, manager);
    });
}

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

function bluntProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 15, 0);
    profile.addAttribute("FALL_RESISTANCE", 3.5, 0);
    profile.addAttribute("BASE_SPEED", -0.1, 1);
    profile.addAttribute("KNOCKBACK", 30, 0);
}

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


function isKeyBindEnabled(entity, keyBind) {
    if (entity.isSprinting() && entity.getData("fiskheroes:flying")) {
        return false;
    }
    switch (keyBind) {
        case "HEAT_VISION":
            return !entity.getData("pkg:dyn/rage");
        case "CHARGED_BEAM":
            return entity.getData("pkg:dyn/rage");
        case "SUPER_SPEED":
            return !entity.getData("fiskheroes:flying");
        case "GROUND_SMASH":
            return !entity.getData("fiskheroes:flying");
        case "UNLEASH_RAGE":
            return !entity.getData("pkg:dyn/rage_cooldown");
        case "UNLEASHED_RAGE":
            return !entity.isSneaking();
        case "TELEPORT":
            return entity.getData("fiskheroes:flying");
        default:
            return true;
    }

}

function isModifierEnabled(entity, modifier) {
    switch (modifier.name()) {
        case "fiskheroes:super_speed":
            return !entity.getData("fiskheroes:flying");
        case "fiskheroes:ground_smash":
            return !entity.getData("fiskheroes:flying");
        default:
            return true;
    }

}