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

function init(hero) {
    hero.setName("Red Lantern Corp");
    hero.setTier(7);
    
    hero.setChestplate("Ring");

    hero.addPowers("jmctheroes:red_lantern_corp_ring");
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("JUMP_HEIGHT", 1.5, 0);
    hero.addAttribute("PUNCH_DAMAGE", 9.7, 0);
    hero.addAttribute("SPRINT_SPEED", 0.5, 1);
    
    hero.addKeyBind("SHIELD", "Rage Energy Shield", 1);
    hero.addKeyBind("ENERGY_PROJECTION", "Rage Energy Beam", 2);
    hero.addKeyBind("SPELL_MENU", "Rage Energy Whip", 3);
    hero.addKeyBind("CHARGED_BEAM", "Rage Plasma", 4);
    hero.addKeyBind("LANTERN", "Transform", 5);

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

    hero.addAttributeProfile("INACTIVE", inactiveProfile);
    hero.addAttributeProfile("SHIELD", shieldProfile);
    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setTierOverride(getTierOverride);
    hero.setAttributeProfile(getProfile);
    hero.setHasProperty(hasProperty);
} 

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) {
    switch (property) {
    case "BREATHE_SPACE":
        return entity.getData("jmctheroes:dyn/suit");
    default:
        return false;
    }
}

function shieldProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 10.2, 0);
    profile.addAttribute("IMPACT_DAMAGE", 0.8, 1);
}

function inactiveProfile(profile) {
    profile.revokeAugments();
}

function getProfile(entity) {
    if (!entity.getData("jmctheroes:dyn/suit")) {
        return "INACTIVE";
    }
    else if (entity.getData("fiskheroes:shield")) {
        return "SHIELD";
    }
}

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("fiskheroes:gliding");
    case "fiskheroes:lightning_cast":
        return entity.getData("jmctheroes:dyn/suit");
    case "fiskheroes:gliding":
        return entity.getData("jmctheroes:dyn/suit");
    case "fiskheroes:energy_projection":
        return entity.getData("jmctheroes:dyn/suit");
    case "fiskheroes:spellcasting":
        return entity.getData("jmctheroes:dyn/suit");
    case "fiskheroes:charged_beam":
        return entity.getData("jmctheroes:dyn/suit");
    default:
        return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "LANTERN") {
        return entity.getData("fiskheroes:mask_open_timer") == 0;
    }
    else if (!entity.getData("jmctheroes:dyn/suit")) {
        return false;
    }

    var height = entity.posY();
    switch (keyBind) {
    case "func_TELEPORT":
        return entity.getData("jmctheroes:dyn/suit") && (height) >= 512;
    case "SHIELD":
        return !entity.getData("fiskheroes:gliding");
    case "ENERGY_PROJECTION":
        return entity.getData("jmctheroes:dyn/suit");
    case "SPELL_MENU":
        return entity.getData("jmctheroes:dyn/suit") && (height) < 512;
    case "CHARGED_BEAM":
        return entity.getData("jmctheroes:dyn/suit");
    default:
        return true;
    }
}

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