var DimensionalCoords = Java.type('com.fiskmods.heroes.common.DimensionalCoords');

function init(hero) {
    hero.setName("Invincible/Mark Grayson");
    hero.setVersion("Invincible");
    hero.setTier(9);
    
    hero.setHelmet("Cowl");
    hero.setChestplate("item.superhero_armor.piece.torso");
    hero.setLeggings("item.superhero_armor.piece.leggings");
    hero.setBoots("item.superhero_armor.piece.boots");
    
    hero.addPowers("jmctheroes:viltrumite_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 11.7, 0);
    hero.addAttribute("SPRINT_SPEED", 0.35, 1);
    hero.addAttribute("JUMP_HEIGHT", 1.5, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 2.0, 0);
    
    hero.addKeyBind("EARTHQUAKE", "key.earthquake", 1);
    hero.addKeyBind("GROUND_SMASH", "key.groundSmash", 2);
    hero.addKeyBind("SLOW_MOTION", "key.slowMotion", 3);
    hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 4);

    hero.addKeyBindFunc("func_TELEPORT", teleportOverrideKey, "Interstellar Travel", 5); 

    hero.setHasProperty(hasProperty);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setModifierEnabled(isModifierEnabled);
}

function teleportOverrideKey(player, manager) {
    var x = player.posX();
    var y = player.posY();
    var z = player.posZ();
    var dim = player.world().getDimension();
    
    
    manager.setData(player, "fiskheroes:teleport_dest", new DimensionalCoords(x, y, z, dim + 1));
    manager.setData(player, "fiskheroes:teleport_delay", 6);
    return true;
}

function hasProperty(entity, property) {
    return property == "BREATHE_SPACE";
}


function isModifierEnabled(entity, modifier) {
    if (modifier.name() == "fiskheroes:regeneration") {
        return entity.getHealth() < 3;
    }
    else if (modifier.name() == "fiskheroes:flight") {
        return !entity.getData("fiskheroes:gliding");
    }
    else if (modifier.name() == "fiskheroes:super_speed") {
        return !entity.isOnGround();
    }
    return true;
}

function isKeyBindEnabled(entity, keyBind) {
    var height = entity.posY();
    switch (keyBind) {
    case "SUPER_SPEED":
        return !entity.isOnGround();
    case "func_TELEPORT":
        return entity.getData("fiskheroes:gliding") && (height) >= 512;
    default:
        return true;
    }
}