function init(hero) {
    hero.setName("Batman");
    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.setHelmet("item.superhero_armor.piece.cowl");
    
    hero.addPowers("kryp:human_physiology", "kryp:batsuit");
    hero.addAttribute("PUNCH_DAMAGE", 6.5, 0);
    hero.addAttribute("WEAPON_DAMAGE", 3.5, 0);
    hero.addAttribute("BASE_SPEED", -0.2, 1);
    hero.addAttribute("JUMP_HEIGHT", 1.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 10.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.3, 1);
    hero.addAttribute("IMPACT_DAMAGE", 0.5, 1);
    
    hero.addKeyBind("WEB_ZIP", "Shoot", 2);
    hero.addKeyBind("UTILITY_BELT", "key.utilityBelt", 4);
    hero.addKeyBindFunc("func_GIANT_MODE", giantModeKey, "Grapple-Gun", 3);
    hero.addKeyBind("NANITE_TRANSFORM", "Bat-Suit", 5);
    
    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.supplyFunction("canAim", canAim);;
    hero.setHasProperty(hasProperty);
    hero.setTierOverride(getTierOverride);
    
    hero.addAttributeProfile("SUPER", superProfile);
    hero.addAttributeProfile("GIANT_MODE", giantProfile);
    hero.addAttributeProfile("SUITUP", suitupProfile);
    hero.setAttributeProfile(getProfile);
    hero.setDefaultScale(defaultScale);
    hero.setDamageProfile(getProfile);
    hero.addDamageProfile("BLADE", {
        "types": {
            "SHARP": 1.0,
            "ENERGY": 0.7
        }
    });
    
    hero.addSoundEvent("MASK_OPEN", "fiskheroes:mk50_mask_open");
    hero.addSoundEvent("AIM_STOP", "fiskheroes:cape_close");
    hero.addSoundEvent("MASK_CLOSE", "fiskheroes:mk50_mask_close");
    hero.addSoundEvent("PUNCH", "kryp:punch");
}

function giantModeKey(player, manager) {
    var flag = player.getData("fiskheroes:dyn/giant_mode");
    manager.setData(player, "fiskheroes:dyn/giant_mode", !flag);
    manager.setData(player, "fiskheroes:size_state", flag ? -1 : 1);
    return true;
}


function giantProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", -30.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 10.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0, 2);
}

function getTierOverride(entity) {
    return entity.getData("fiskheroes:dyn/nanites") ? 10 : 0;
}

function suitupProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 6.5, 0);
    profile.addAttribute("FALL_RESISTANCE", 10.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0, 2);
}


function getAttributeProfile(entity) {
    return entity.getData("fiskheroes:dyn/giant_mode_timer") > 0 ? "GIANT_MODE" : null;
}

function defaultScale(entity) {
    if (entity.getData('fiskheroes:dyn/nanites')) {
        return 1.0;
    }
    return 1.0;
}

function isKeyBindEnabled(entity, keyBind) {
    return keyBind != "CHARGED_BEAM" || entity.getData("fiskheroes:beam_charge") == 0 && entity.getData("fiskheroes:aimed_timer") == 1;
}

function canAim(entity) {
    return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:beam_charge") == 0 && entity.getData('fiskheroes:time_since_damaged') > 10;
}

function superProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 3, 0);
    profile.addAttribute("FALL_RESISTANCE", 2.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0, 0);
}

function getProfile(entity) {
    if (entity.getData("fiskheroes:dyn/giant_mode") ) {
        return "GIANT_MODE";
    } else if (!entity.getData("fiskheroes:dyn/nanites")) {
        return "SUPER";
    }
    
    return entity.getData("fiskheroes:blade") ? "BLADE" : null;
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("fiskheroes:dyn/nanites") || modifier.name() == "fiskheroes:propelled_flight" && entity.getData("fiskheroes:dyn/nanite_timer") < 1)) {
        return false;
    }
  
    switch (modifier.name()) {
    case "fiskheroes:energy_blast":
        return entity.getData("fiskheroes:aimed_timer") >= 1;
    case "fiskheroes:blade":
        return !entity.getData("fiskheroes:aiming") && !entity.getData("fiskheroes:shield");
    case "fiskheroes:regeneration":
        return !entity.getData("fiskheroes:blade");
    case "fiskheroes:flight":
        return entity.getData("fiskheroes:dyn/nanites") && !entity.isSprinting() && !entity.getData("fiskheroes:gliding");
    case "fiskheroes:charged_beam":
            return  !entity.getData("fiskheroes:dyn/giant_mode");
    case "fiskheroes:fiskheroes:gliding":
            return !entity.getData("fiskheroes:dyn/nanites");
    case "fiskheroes:slow_motion":
            return !entity.getData("fiskheroes:dyn/giant_mode");
    case "fiskheroes:energy_projection":
            return  !entity.getData("fiskheroes:dyn/nanites");
    case "fiskheroes:water_breathing":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("fiskheroes:dyn/nanites");
    default:
        return false;
    }
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("fiskheroes:dyn/nanites") || modifier.name() == "fiskheroes:propelled_flight" && entity.getData("fiskheroes:dyn/nanite_timer") < 1)) {
        return false;
    }
  
    switch (modifier.name()) {
    case "fiskheroes:blade":
        return !entity.getData("fiskheroes:aiming") && !entity.getData("fiskheroes:shield");
    case "fiskheroes:regeneration":
        return !entity.getData("fiskheroes:blade");
    case "fiskheroes:flight":
        return entity.getData("fiskheroes:dyn/nanites") && !entity.isSprinting() && !entity.getData("fiskheroes:gliding");
    case "fiskheroes:web_zip":
            return entity.getData("fiskheroes:dyn/giant_mode");
    case "fiskheroes:energy_projection":
            return  !entity.getData("fiskheroes:dyn/nanites");
    case "fiskheroes:water_breathing":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("fiskheroes:dyn/nanites");
    default:
        return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "NANITE_TRANSFORM") {
        return entity.getData("fiskheroes:dyn/giant_mode") == 0;
    }
    if (keyBind == "func_GIANT_MODE") {
        return !entity.getData("fiskheroes:dyn/nanites") == 0;
    }
    if (keyBind == "func_GIANT_MODE") {
        return entity.getData("fiskheroes:web_zip") == 0;
    }
    if (keyBind == "WEB_ZIP") {
        return !entity.getData("fiskheroes:dyn/giant_mode") == 0;
    }
    if (keyBind == "CHARGED_BEAM") {
        return !entity.getData("fiskheroes:dyn/nanites") == 0;
    }
    if (keyBind == "ENERGY_PROJECTION") {
        return !entity.getData("fiskheroes:dyn/giant_mode") == 0;
    }
    else if (!entity.getData("fiskheroes:dyn/nanites") && !entity.getData("fiskheroes:dyn/giant_mode")) {
        return false;
    }
    
    switch (keyBind) {
    case "SHIELD":
        return entity.isSneaking() || entity.isBookPlayer();
    case "BLADE":
        return !entity.isSneaking() && !entity.getData("fiskheroes:shield");
    default:
        return true;
    }
}

function hasProperty(entity, property) {
    switch (property) {
    case "BREATHE_SPACE":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("fiskheroes:dyn/nanites");
    default:
        return false;
    }
}

function canAim(entity) {
    return entity.getHeldItem().isEmpty() && entity.getData("fiskheroes:dyn/nanites") && !entity.getData("fiskheroes:jetpacking") && !entity.getData("fiskheroes:shield");
}