//Soul = 1, Time = 2, Space = 3, Reality = 4, Power = 5, Mind = 6

function init(hero) {
    hero.setName("Thanos");
    hero.setTier(1);
    
    hero.setChestplate("Infinity Gauntlet");

    hero.addPowers("jmctheroes:soul_stone", "jmctheroes:time_stone", "jmctheroes:space_stone", "jmctheroes:reality_stone", "jmctheroes:power_stone", "jmctheroes:mind_stone");
    
    hero.addKeyBind("TELEKINESIS", "\u00A76Grab an Entities Soul", 1);

    hero.addKeyBind("SUPER_SPEED", "\u00A7aTime-Speed", 1);
    hero.addKeyBind("SLOW_MOTION", "\u00A7aSlow Time", 2);

    hero.addKeyBind("SHIELD", "\u00A7bForcefield", 1);
    hero.addKeyBind("TELEPORT", "\u00A7bTeleport", 2);

    hero.addKeyBind("SHADOWFORM", "\u00A7cRearrange Atoms", 1);
    hero.addKeyBind("SHADOWDOME", "\u00A7cReality Warp", 2);
    hero.addKeyBind("SPELL_MENU", "\u00A7cDuplication", 3);
    hero.addKeyBind("SIZE_MANIPULATION", "\u00A7cSize Illusion", 4);

    hero.addKeyBind("CHARGED_BEAM", "\u00A75Charged Beam", 1);

    hero.addKeyBind("ENERGY_PROJECTION", "\u00A7eEnergy Blast", 1);

    

    hero.addKeyBindFunc("func_STONES_NEXT", nextStoneKey, "Next Stone", 5);
    hero.addKeyBindFunc("func_STONES_PREV", prevStoneKey, "Previous Stone", 5);


    hero.addAttributeProfile("SOUL", soulProfile);
    hero.addAttributeProfile("TIME", timeProfile);
    hero.addAttributeProfile("SPACE", spaceProfile);
    hero.addAttributeProfile("REALITY", realityProfile);
    hero.addAttributeProfile("POWER", powerProfile);
    hero.addAttributeProfile("MIND", mindProfile);

    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setAttributeProfile(getProfile);
    hero.setTierOverride(getTierOverride);
}

function getTierOverride(entity) {
    var stone = entity.getData("jmctheroes:dyn/stones")

    if (stone == 1) {
        return 4;
    }
    else if (stone == 2) {
        return 2;
    }
    else if (stone == 3) {
        return 3;
    }
    else if (stone == 4) {
        return 3;
    }
    else if (stone == 5) {
        return 2;
    }
    else if (stone == 6) {
        return 2;
    }
    return 1;
}

function prevStoneKey(player, manager) {
    var flag = player.getData("jmctheroes:dyn/stones");
    if (flag == 1) {
        manager.setDataWithNotify(player, "jmctheroes:dyn/stones", 6);
        return true;
    }
    if (flag >= 1) {
        manager.setDataWithNotify(player, "jmctheroes:dyn/stones", player.getData("jmctheroes:dyn/stones") - 1);
    return true;
    }
    
    manager.setDataWithNotify(player, "jmctheroes:dyn/stones", 6);
    return true;
}

function nextStoneKey(player, manager) {
    var flag = player.getData("jmctheroes:dyn/stones");
    if (flag == 6) {
        manager.setDataWithNotify(player, "jmctheroes:dyn/stones", 1);
        return true;
    }
    if (flag >= 1) {
        manager.setDataWithNotify(player, "jmctheroes:dyn/stones", player.getData("jmctheroes:dyn/stones") + 1);
    return true;
    }
    
    manager.setDataWithNotify(player, "jmctheroes:dyn/stones", 1);
    return true;
}

function soulProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 7.5, 0);
    profile.addAttribute("WEAPON_DAMAGE", -2.5, 0);
    profile.addAttribute("JUMP_HEIGHT", 1.5, 0);
    profile.addAttribute("FALL_RESISTANCE", 1.0, 1);
}

function timeProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 7.5, 0);
    profile.addAttribute("WEAPON_DAMAGE", -2.5, 0);
    profile.addAttribute("JUMP_HEIGHT", 1.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 12.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.75, 1);
    profile.addAttribute("BASE_SPEED_LEVELS", 3.0, 0);
}

function spaceProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 7.5, 0);
    profile.addAttribute("WEAPON_DAMAGE", -2.5, 0);
    profile.addAttribute("JUMP_HEIGHT", 1.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 12.0, 0);
}

function realityProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 8.1, 0);
    profile.addAttribute("WEAPON_DAMAGE", -2.5, 0);
    profile.addAttribute("JUMP_HEIGHT", 1.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 1.0, 1);
    profile.addAttribute("SPRINT_SPEED", 0.40, 1);
}

function powerProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 9.7, 0);
    profile.addAttribute("WEAPON_DAMAGE", -1.0, 0);
    profile.addAttribute("JUMP_HEIGHT", 3.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 12.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.40, 1);
}

function mindProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 7.5, 0);
    profile.addAttribute("WEAPON_DAMAGE", -2.5, 0);
    profile.addAttribute("JUMP_HEIGHT", 1.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 12.0, 0);
}

function getProfile(entity) {
    if (entity.getData("jmctheroes:dyn/stones") == 1) {
        return "SOUL";
    }
    else if (entity.getData("jmctheroes:dyn/stones") == 2) {
        return "TIME";
    }
    else if (entity.getData("jmctheroes:dyn/stones") == 3) {
        return "SPACE";
    }
    else if (entity.getData("jmctheroes:dyn/stones") == 4) {
        return "REALITY";
    }
    else if (entity.getData("jmctheroes:dyn/stones") == 5) {
        return "POWER";
    }
    else if (entity.getData("jmctheroes:dyn/stones") == 6) {
        return "MIND";
    }
}

function hasProperty(entity, property) {
    switch (property) {
    case "BREATHE_SPACE":
        return entity.getData("jmctheroes:dyn/stones") == 1 || entity.getData("jmctheroes:dyn/stones") == 3;
    default:
        return false;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    
    switch (keyBind) {
    case "TELEKINESIS":
        return (entity.getData("jmctheroes:dyn/stones") == 1);


    case "SUPER_SPEED":
        return (entity.getData("jmctheroes:dyn/stones") == 2);
    case "SLOW_MOTION":
        return (entity.getData("jmctheroes:dyn/stones") == 2);

    case "SHIELD":
        return (entity.getData("jmctheroes:dyn/stones") == 3);
    case "TELEPORT":
        return (entity.getData("jmctheroes:dyn/stones") == 3);
    
    case "SHADOWFORM":
        return (entity.getData("jmctheroes:dyn/stones") == 4);
    case "SHADOWDOME":
        return (entity.getData("jmctheroes:dyn/stones") == 4);
    case "SPELL_MENU":
        return (entity.getData("jmctheroes:dyn/stones") == 4);
    case "SIZE_MANIPULATION":
        return (entity.getData("jmctheroes:dyn/stones") == 4);

    case "CHARGED_BEAM":
        return (entity.getData("jmctheroes:dyn/stones") == 5);

    case "ENERGY_PROJECTION":
        return (entity.getData("jmctheroes:dyn/stones") == 6);

    case "func_STONES_NEXT":
        return !entity.isSneaking();
    case "func_STONES_PREV":
        return entity.isSneaking();
    default:
        return true;
    }    
}


function isModifierEnabled(entity, modifier) {

    if (modifier.name() == "fiskheroes:healing_factor") {
        return (entity.getData("jmctheroes:dyn/stones") == 1);
    }
    else if (modifier.name() == "fiskheroes:fire_immunity") {
        return (entity.getData("jmctheroes:dyn/stones") == 1);
    }
    else if (modifier.name() == "fiskheroes:projectile_immunity") {
        return (entity.getData("jmctheroes:dyn/stones") == 1);
    }
    else if (modifier.name() == "fiskheroes:damage_immunity") {
        return (entity.getData("jmctheroes:dyn/stones") == 1);
    }
    else if (modifier.name() == "fiskheroes:telekinesis") {
        return (entity.getData("jmctheroes:dyn/stones") == 1);
    }

    else if (modifier.name() == "fiskheroes:super_speed") {
        return (entity.getData("jmctheroes:dyn/stones") == 2);
    }
    else if (modifier.name() == "fiskheroes:slow_motion") {
        return (entity.getData("jmctheroes:dyn/stones") == 2);
    }

    else if (modifier.name() == "fiskheroes:shield") {
        return (entity.getData("jmctheroes:dyn/stones") == 3);
    }
    else if (modifier.name() == "fiskheroes:teleportation") {
        return (entity.getData("jmctheroes:dyn/stones") == 3);
    }

    else if (modifier.name() == "fiskheroes:shadowform") {
        return (entity.getData("jmctheroes:dyn/stones") == 4);
    }
    else if (modifier.name() == "fiskheroes:shadowdome") {
        return (entity.getData("jmctheroes:dyn/stones") == 4);
    }
    else if (modifier.name() == "fiskheroes:size_manipulation") {
        return (entity.getData("jmctheroes:dyn/stones") == 4);
    }
    else if (modifier.name() == "fiskheroes:flight") {
        return (entity.getData("jmctheroes:dyn/stones") == 4) && (entity.getData("fiskheroes:shadowform"));
    }

    else if (modifier.name() == "fiskheroes:charged_beam") {
        return (entity.getData("jmctheroes:dyn/stones") == 5);
    }
    else if (modifier.name() == "fiskheroes:lightning_cast") {
        return (entity.getData("jmctheroes:dyn/stones") == 5);
    }
    else if (modifier.name() == "fiskheroes:leaping") {
        return (entity.getData("jmctheroes:dyn/stones") == 5);
    }

    else if (modifier.name() == "fiskheroes:energy_projection") {
        return (entity.getData("jmctheroes:dyn/stones") == 6);
    }
    return true;
}