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

function init(hero) {
    hero.setName("Superman");
    hero.setTier(9);
    hero.setVersion("Kingdom Come");
	
    hero.setChestplate("item.superhero_armor.piece.chestpiece");
    hero.setLeggings("item.superhero_armor.piece.pants");
    hero.setBoots("item.superhero_armor.piece.boots");
    
    hero.addPowers("dhhp:kryptonian_physiology");
	
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("PUNCH_DAMAGE", 12., 0);
    hero.addAttribute("SPRINT_SPEED", 0.45, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 2.0, 0);
    hero.addAttribute("MAX_HEALTH", 4.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", -0.75, 1);
    hero.addAttribute("IMPACT_DAMAGE", 0.25, 1);
	
    hero.addKeyBind("HEAT_VISION", "key.heatVision", 1);
	hero.addKeyBind("CHARGED_BEAM", "key.heatVision", 1);
	hero.addKeyBind("SLOW_MOTION", "key.slowMotion", 2);
	hero.addKeyBind("HOVER", "Hover", 3);
	hero.addKeyBind("POWER", "Solar Absorption", 4);
	hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 5);

    hero.addKeyBindFunc("func_TELEPORT", teleportOverrideKey, "Exit Orbit", 5); 

    hero.setHasProperty(hasProperty);
    hero.addAttributeProfile("ACTIVE", activeProfile);
    hero.setAttributeProfile(getAttributeProfile);
	hero.setKeyBindEnabled(isKeyBindEnabled);
	hero.setModifierEnabled(isModifierEnabled);	
}



function activeProfile(profile) {
	profile.inheritDefaults();
	profile.addAttribute("KNOCKBACK", 3.0, 0);
    profile.addAttribute("JUMP_HEIGHT", 2.5, 0);
    profile.addAttribute("PUNCH_DAMAGE", 14.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.85, 1);
	profile.addAttribute("IMPACT_DAMAGE", 0.9, 1);
}

function getAttributeProfile(entity) {
    if (entity.getData("dhhp:dyn/powered")) {
        return "ACTIVE";
    }
    return null;
}

function isKeyBindEnabled(entity, keyBind) {
	var y = entity.posY();
	///var moon = entity.world().getDimension() == 4;
    switch (keyBind) {
	case "POWER":
        return (y) >=  350 || entity.getData("dhhp:dyn/powered");
	case "HEAT_VISION":
        return !entity.getData("dhhp:dyn/powered") && entity.getData("fiskheroes:glide_flying_timer") == 0;
	case "CHARGED_BEAM":
        return entity.getData("dhhp:dyn/powered") && entity.getData("fiskheroes:glide_flying_timer") == 0;
	case "HOVER":
        return !entity.getData("fiskheroes:gliding");
    case "func_TELEPORT":
        return (y) >=  3000;
    case "SUPER_SPEED":
        return (y) <=  3000;
    default:
        return true
    }
}

function isModifierEnabled(entity, modifier) {
		
	if (modifier.name() == "fiskheroes:gliding") {
        var powered = entity.getData("dhhp:dyn/powered");
        return (modifier.id() == "powered" ? powered : !powered);
    }
	switch (modifier.name()) {
	case "fiskheroes:heat_vision":
        return !entity.getData("dhhp:dyn/powered");
	case "fiskheroes:healing_factor":
        return  entity.posY() >=  350;
	case "fiskheroes:flight":
        return  !entity.getData("fiskheroes:gliding");
	case "fiskheroes:hover":
        return  !entity.getData("fiskheroes:gliding");
	case "fiskheroes:charged_beam":
        return entity.getData("dhhp:dyn/powered");
    default:
        return true;
    }
}

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() + 1;
    
    manager.setData(player, "fiskheroes:teleport_dest", new DimensionalCoords(x, y, z, dim));
    manager.setData(player, "fiskheroes:teleport_delay", 6);
    return true;
}