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

function init(hero) {
    hero.setName("Thor/Mjolnir");
    hero.setTier(9);
    
    hero.setChestplate("item.superhero_armor.piece.chestplate");
    hero.setLeggings("item.superhero_armor.piece.leggings");
    hero.setBoots("item.superhero_armor.piece.boots");

    hero.addPowers("jmctheroes:asgardian_physiology", "jmctheroes:god_of_thunder", "jmctheroes:mjolnir");
    hero.addAttribute("FALL_RESISTANCE", 34.0, 0);
    hero.addAttribute("JUMP_HEIGHT", 1.75, 0);
    hero.addAttribute("PUNCH_DAMAGE", 11.75, 0);
    hero.addAttribute("SPRINT_SPEED", 0.55, 1);
    
    hero.addKeyBind("MJOLNIR", "Summon Mjolnir", 1);
    hero.addKeyBind("THUNDER_GOD", "God Of Thunder", 2);
    hero.addKeyBindFunc("func_TELEPORT", teleportOverrideKey, "Interstellar Travel", 3); 

    hero.setModifierEnabled(isModifierEnabled);
    hero.addAttributeProfile("WEAPON", weaponProfile);
    hero.addAttributeProfile("THUNDER", thunderProfile);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setAttributeProfile(getProfile);
    hero.setHasProperty(hasProperty);

}

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

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 weaponProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("FALL_RESISTANCE", 1.0, 1);
    profile.addAttribute("JUMP_HEIGHT", 2.5, 0);
    profile.addAttribute("PUNCH_DAMAGE", 13.8, 0);
}

function thunderProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("JUMP_HEIGHT", 2.75, 0);
    profile.addAttribute("PUNCH_DAMAGE", 15, 0);
    profile.addAttribute("SPRINT_SPEED", 0.65, 1);
}

function getProfile(entity) {
    if (entity.getData("jmctheroes:dyn/mjolnir")) {
        return "WEAPON";
    }
    else if (entity.getData("jmctheroes:dyn/thunder")) {
        return "THUNDER";
    }
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() == "fiskheroes:lightning_cast") {
        return (entity.getData("jmctheroes:dyn/thunder"));
    }
    else if (modifier.name() == "fiskheroes:gliding") {
        return (entity.getData("jmctheroes:dyn/mjolnir"));
    }
    else if (modifier.name() == "jmctheroes:dyn/thunder") {
        return (entity.getData("jmctheroes:dyn/mjolnir"));
    }
    return true;
}

function isKeyBindEnabled(entity, keyBind) {
    var height = entity.posY();
    switch (keyBind) {
    case "THUNDER_GOD":
        return (entity.getData("jmctheroes:dyn/mjolnir"));
    case "func_TELEPORT":
        return entity.getData("jmctheroes:dyn/mjolnir") && (height) >= 512;
    default:
        return true;
    }    
}
