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

function init(hero) {
    hero.setName("Nova");
    hero.setTier(10);
    
    hero.setHelmet("Helmet");

    hero.addPowers("jmctheroes:nova_force", "jmctheroes:nova_helmet");

    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("JUMP_HEIGHT", 2.0, 0);
    hero.addAttribute("PUNCH_DAMAGE", 8.75, 0);
    hero.addAttribute("SPRINT_SPEED", 0.75, 1);

    hero.addKeyBind("CHARGED_BEAM", "Energy Beam", 1);
    hero.addKeyBind("SHIELD", "Energy Shield", 2);
    hero.addKeyBind("NOVAFORCE", "Toggle Nova Force", 3);
    hero.addKeyBind("HOVER", "Hover", 4);
    hero.addKeyBind("SUIT", "Materialise Suit", 5);

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

    hero.setHasProperty(hasProperty);
    hero.setAttributeProfile(getProfile);
    hero.setTierOverride(getTierOverride);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setModifierEnabled(isModifierEnabled);
    hero.addAttributeProfile("NOVA", novaProfile);
}

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 novaProfile(profile) {
    profile.revokeAugments();
}

function getProfile(entity) {
    if (!entity.getData("jmctheroes:dyn/suit")) {
        return "NOVA";
    }
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("jmctheroes:dyn/suit"))) {
        return false;
    }
  
    switch (modifier.name()) {
    case "fiskheroes:shield":
        return (entity.getData("jmctheroes:dyn/suit"));
    case "fiskheroes:charged_beam":
        return (entity.getData("jmctheroes:dyn/suit"));
    case "fiskheroes:gliding":
        return (entity.getData("jmctheroes:dyn/novaforce"));
    case "fiskheroes:lightning_cast":
        return (entity.getData("jmctheroes:dyn/novaforce"));
    case "fiskheroes:propelled_flight":
        return (entity.getData("jmctheroes:dyn/suit_timer") == 1) && (!entity.getData("jmctheroes:dyn/novaforce"));
    case "fiskheroes:hover":
        return (entity.getData("jmctheroes:dyn/suit")) && (!entity.getData("jmctheroes:dyn/novaforce"));
    case "jmctheroes:dyn/novaforce":
        return (entity.getData("jmctheroes:dyn/suit"));
    default:
        return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    var height = entity.posY();
    switch (keyBind) {
    case "SUIT":
        return !entity.getData("jmctheroes:dyn/novaforce");
    case "CHARGED_BEAM":
        return entity.getData("jmctheroes:dyn/suit");
    case "SHIELD":
        return entity.getData("jmctheroes:dyn/suit") && !entity.getData("jmctheroes:dyn/novaforce");
    case "NOVAFORCE":
        return entity.getData("jmctheroes:dyn/suit");
    case "HOVER":
        return (entity.getData("jmctheroes:dyn/suit")) && (!entity.getData("jmctheroes:dyn/novaforce")) && (height) < 512;
    case "func_TELEPORT":
        return entity.getData("jmctheroes:dyn/suit") && (height) >= 512;
    default:
        return true;
    }
}

function hasProperty(entity, property) {
    switch (property) {
    case "BREATHE_SPACE":
        return entity.getData("jmctheroes:dyn/suit");
    default:
        return false;
    }
}

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