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

function init(hero) {
    hero.setName("Devastator/\u00A7d\u00A7lKNIGHTS\u00A7r");
    hero.setTier(9);

    hero.setHelmet("item.superhero_armor.piece.helmet");
    hero.setChestplate("item.superhero_armor.piece.chestpiece");
    hero.setLeggings("item.superhero_armor.piece.pants");
    hero.setBoots("item.superhero_armor.piece.boots");
    
    hero.addPowers("knights:doomsday_virus");
	
    hero.addAttribute("FALL_RESISTANCE", 100, 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", 5.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", -0.75, 1);
    hero.addAttribute("IMPACT_DAMAGE", 0.25, 1);
	
    hero.addKeyBind("ENERGY_PROJECTION", "Heat Vision", 1);
    hero.addKeyBind("EARTHQUAKE", "key.earthquake", 2);
    hero.addKeyBindFunc("func_GIANT_MODE", giantModeKey, "ENRAGED POWER", 3);
	hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 4);

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

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 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("knights: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("knights:dyn/powered");
	case "HEAT_VISION":
        return !entity.getData("knights:dyn/powered") && entity.getData("fiskheroes:glide_flying_timer") == 0;
	case "CHARGED_BEAM":
        return entity.getData("knights: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("knights:dyn/powered");
        return (modifier.id() == "powered" ? powered : !powered);
    }
	switch (modifier.name()) {
	case "fiskheroes:heat_vision":
        return !entity.getData("knights: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("knights: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;
}