Esempio n. 1
0
def durability(PlayerID, outil):
    # gestion de la durabilité d'un outil
    nb = int(sql.valueAtNumber(PlayerID, outil, "inventory"))
    if nb > 0:
        sql.add(PlayerID, outil, -1, "durability")
        if sql.valueAtNumber(PlayerID, outil, "durability") <= 0:
            for c in objetOutil:
                if c.nom == outil:
                    sql.add(PlayerID, outil, c.durabilite, "durability")
            sql.add(PlayerID, outil, -1, "inventory")
            return True
    return False
Esempio n. 2
0
def end_season():
    """
    recupere le nombre de gems et le nombre de gems dans la banque,
    stock ces valeurs dans la base de donnée (table seasons) et met
    ces 2 valeurs a 0 + supprime tous les items a prix fixe dans l'inventaire
    """
    res = load_dates()
    nbs = res["total"]
    nb_invest = 0  # Nombre de joueur considéré comme ayant joué
    bank_tot = 0  # Total de la banque
    for i in range(1, sql.taille("gems") + 1):
        # Récupération des données par Joueur
        IDs = sql.userID(i, "gems")
        IDd = IDs[1]
        IDm = IDs[2]
        if IDd is not None:
            SuperID = sql.get_SuperID(IDd, "discord")
        elif IDm is not None:
            SuperID = sql.get_SuperID(IDd, "messenger")
        else:
            SuperID = 0
        PlayerID = sql.get_PlayerID(SuperID)
        solde = sql.valueAtNumber(PlayerID, "gems", "gems")
        bank = sql.valueAtNumber(PlayerID, "Solde", "bank")

        # Valeurs nécessaires au multiplicateur
        if solde != 100:
            nb_invest = nb_invest + 1
            bank_tot = bank_tot + bank

        # Sauvegarde des valeurs de la saison en  cours par Joueur
        save = sql.add(PlayerID, "idseasons", nbs, "seasons")
        print(save)
        if save != 404 and save != 102:
            sql.updateField(PlayerID, "gem", [solde, nbs], "seasons")
            sql.updateField(PlayerID, "bank", [bank, nbs], "seasons")
            # Reset solde de gems et solde de la banque
            sql.updateField(PlayerID, "gems", 100, "gems")
            sql.updateField(PlayerID, "Solde", 0, "bank")
            # Reset dans l'inventaire des objets à prix fixe du marché
            for x in GI.exception:
                if x != "bank_upgrade":
                    sql.updateField(PlayerID, x, 0, "inventory")
            # reset dans l'inventaire des objets événementiels
            for x in GF.ObjetEventEnd:
                if x != "bank_upgrade":
                    sql.updateField(PlayerID, x, 0, "inventory")
    with open('core/saisons.json', 'r') as fp:
        dict = json.load(fp)
    dict["total"] = nbs + 1
    with open('core/saisons.json', 'w') as fp:
        json.dump(dict, fp, indent=4)
    return True, nb_invest, bank_tot
Esempio n. 3
0
def startKit(ID):
    gems = sql.valueAtNumber(ID, "gems", "gems")
    if gems == 0:
        sql.addGems(ID, 100)
        sql.add(ID, "pickaxe", 1, "inventory")
        sql.add(ID, "fishingrod", 1, "inventory")
        sql.add(ID, "shovel", 1, "inventory")
        sql.add(ID, "pickaxe", 20, "durability")
        sql.add(ID, "fishingrod", 20, "durability")
        sql.add(ID, "shovel", 20, "durability")
Esempio n. 4
0
def addxp(ID, nb, nameDB):
    balXP = sql.valueAtNumber(ID, "xp", nameDB)
    if balXP != None:
        ns = balXP + int(nb)
        if ns <= 0:
            ns = 0
        sql.updateField(ID, "xp", ns, nameDB)
        return True
    else:
        return False
Esempio n. 5
0
def checklevel(ID):
    lang = sql.valueAtNumber(ID, "LANG", "IDs")
    if lang == None:
        lang = "EN"
    if ID == "Error 404":
        msg = [
            "WarningMsg",
            lang_P.forge_msg(lang, "WarningMsg", None, False, 0)
        ]
        return msg
    PlayerID = sql.get_PlayerID(ID, "gems")
    # print(PlayerID)
    msg = []
    S = success.checkSuccess(PlayerID, lang)
    try:
        lvl = sql.valueAtNumber(PlayerID, "lvl", "gems")
        xp = sql.valueAtNumber(PlayerID, "xp", "gems")
        palier = lvlPalier(lvl)
        desc = ""
        if xp >= palier:
            lvl = lvl + 1
            sql.updateField(PlayerID, "lvl", lvl, "gems")
            desc = lang_P.forge_msg(lang, "level", [lvl], False, 0)
            nbG = 100 * lvl
            sql.addGems(PlayerID, nbG)
            desc += lang_P.forge_msg(lang, "level", [nbG], False, 1)
            msg.append("Level UP")
        else:
            msg.append("Level OK")
        msg.append(desc)
        if S != []:
            msg.append(S)
    except:
        print("Level >> Le joueur n'existe pas.")
        msg.append("Level NOK")
        msg.append("Le joueur n'existe pas")
    return msg
Esempio n. 6
0
def exec_commands(c):
    """
    Va se charger d'exécuter toutes les commandes

    params :
    dict c => message

    return :
    dict => name_c, name_p, name_pl, reponse
    """
    # On récupère tous les modules dans gems
    list_here = gems.list_GG_module

    packets_list = list()
    function_dict = dict()
    res = dict()

    for i in list_here:
        # On exclut les magic func
        if "gems" in i:
            packets_list.append(i)

    for j in packets_list:
        tmp_list = list()
        tmp = dir(eval("gems." + j))

        for k in tmp:
            tmp_list.append(k)
        function_dict[str(j)] = tmp_list

    commande = c["name_c"]
    file_c = ""

    for mod_name in packets_list:
        if commande in function_dict[mod_name]:
            # Où a été trouvé la commande
            file_c = mod_name
            break
        else:
            file_c = None

    # S'il a trouvé une commande
    if file_c is not None:
        commande_forgee = "getattr(eval(file_c), commande)"
        try:
            c["param_c"]["name_pl"] = c["name_pl"]
            if c["name_pl"] != "Admin":
                ID = sql.get_SuperID(c["name_p"], c["name_pl"])
            else:
                ID = sql.get_SuperID(c["name_p"], "discord")
            if ID != "Error 404":
                c["param_c"]["lang"] = sql.valueAtNumber(ID, "LANG", "IDs")
                c["param_c"]["PlayerID"] = sql.get_PlayerID(ID, "gems")
            else:
                c["param_c"]["lang"] = "EN"
            commande_forgee = commande_forgee + '(' + str(c["param_c"]) + ')'
        except KeyError:
            pass
        # Appelle la fonction

        print(commande_forgee)
        if ID != "Error 404" or commande == "connect" or commande == "begin":
            # try:
            ret = eval(commande_forgee)
            res["reponse"] = ret
        # except:
        #     res["reponse"] = ["WarningMsg", c["param_c"]["lang"], lang_P.forge_msg(c["param_c"]["lang"], "WarningMsg", None, False, 1)]
        else:
            res["reponse"] = [
                "WarningMsg", c["param_c"]["lang"],
                lang_P.forge_msg(c["param_c"]["lang"], "WarningMsg", None,
                                 False, 0)
            ]

        res["name_c"] = commande
        res["name_p"] = c["name_p"]
        res["name_pl"] = c["name_pl"]
    else:
        res = None

    print(res)
    return res
Esempio n. 7
0
def success(param):
    lang = param["lang"]
    PlayerID = param["PlayerID"]
    msg = []
    result = []
    dict = {}
    i = -1
    for x in objetSuccess:
        if x.id > i:
            i = x.id
        dict[x.id] = x.sid
    for i in range(0, i + 1):
        iS = sql.valueAtNumber(PlayerID, i, "success")
        for x in objetSuccess:
            arg = None
            if x.id == i:
                type = x.type.split("|")
                if type[0] == "gems" or type[0] == "daily":
                    myStat = sql.valueAtNumber(PlayerID, "{0}".format(type[1]),
                                               "{0}".format(type[0]))
                    if type[0] == "gems":
                        arg = None
                    else:
                        arg = [x.objectif]

                elif type[0] == "broken":
                    myStat = sql.valueAtNumber(
                        PlayerID,
                        "{0} | broken | {1}".format(type[1],
                                                    type[2]), "statgems")
                    arg = [
                        x.objectif, type[2], "{idmoji[gem_" + type[2] + "]}"
                    ]

                elif type[0] == "mine" or type[0] == "dig" or type[0] == "fish":
                    myStat = sql.valueAtNumber(
                        PlayerID, "{0} | item | {1}".format(type[0], type[1]),
                        "statgems")
                    arg = [
                        x.objectif, type[1], "{idmoji[gem_" + type[1] + "]}"
                    ]

                elif type[0] == "buy" or type[0] == "sell":
                    if (type[0] == "buy"
                            or type[0] == "sell") and type[1] != "total":
                        myStat = sql.valueAtNumber(
                            PlayerID,
                            "{0} | item | {1}".format(type[0],
                                                      type[1]), "statgems")
                        arg = [
                            x.objectif, type[1],
                            "{idmoji[gem_" + type[1] + "]}"
                        ]
                    else:
                        myStat = sql.valueAtNumber(
                            PlayerID, "{0} | {1}".format(type[0], type[1]),
                            "statgems")
                        arg = [x.objectif]

                elif type[0] == "gamble" or type[0] == "stealing" or type[
                        0] == "slots":
                    myStat = sql.valueAtNumber(
                        PlayerID, "{0} | {1}".format(type[0], type[1]),
                        "statgems")
                    arg = [x.objectif]

                elif type[0] == "pay":
                    myStat = sql.valueAtNumber(PlayerID,
                                               "pay | {0}".format(type[1]),
                                               "statgems")
                    arg = [x.objectif]

                elif type[0] == "forge":
                    myStat = sql.valueAtNumber(
                        PlayerID, "forge | item | {0}".format(type[1]),
                        "statgems")
                    arg = [
                        x.objectif, type[1], "{idmoji[gem_" + type[1] + "]}"
                    ]

                elif type[0] == "hothouse" or type[0] == "ferment" or type[
                        0] == "cooking":
                    myStat = sql.valueAtNumber(
                        PlayerID, "{0} | {1} | item | {2}".format(
                            type[0], type[1], type[2]), "statgems")
                    if type[2] in GI.objetEmoji:
                        idmoji = ":{0}:".format(type[2])
                    else:
                        idmoji = "<:gem_{0}:{1}>".format(
                            type[2], "{idmoji[gem_" + type[2] + "]}")
                    arg = [x.objectif, type[2], idmoji]

                elif type[0] == "inv":
                    myStat = sql.valueAtNumber(PlayerID, "{0}".format(type[1]),
                                               "inventory")
                    if type[1] in GI.objetEmoji:
                        idmoji = ":{0}:".format(type[1])
                    else:
                        idmoji = "<:gem_{0}:{1}>".format(
                            type[1], "{idmoji[gem_" + type[1] + "]}")
                    arg = [x.objectif, type[1], idmoji]

                if x.sid == iS + 1:
                    result.append(
                        lang_P.forge_msg(lang, "success titre",
                                         [GF.ChiffreRomain(x.sid)], False,
                                         x.titre))
                    desc = "{0} | `{1}`/`{2}`".format(
                        lang_P.forge_msg(lang, "success desc", arg, False,
                                         x.desc), myStat, x.objectif)
                    result.append(desc)
                elif iS == dict[i] and x.sid == iS:
                    desc = "{0} | **_{1}_**".format(
                        lang_P.forge_msg(lang, "success desc", arg, False,
                                         x.desc),
                        lang_P.forge_msg(lang, "success", None, False, 2))
                    result.append(
                        lang_P.forge_msg(lang, "success titre",
                                         [GF.ChiffreRomain(x.sid)], False,
                                         x.titre))
                    result.append(desc)
    msg.append("OK")
    msg.append(lang)
    msg.append(result)
    return msg
Esempio n. 8
0
def checkSuccess(PlayerID, lang):
    result = []
    i = -1
    for x in objetSuccess:
        if x.id > i:
            i = x.id
    myStat = 0
    for i in range(0, i + 1):
        iS = sql.valueAtNumber(PlayerID, i, "success")
        for x in objetSuccess:
            if x.id == i and x.sid == iS + 1:
                type = x.type.split("|")
                nom = ""

                if type[0] == "gems" or type[0] == "daily":
                    myStat = sql.valueAtNumber(PlayerID, "{0}".format(type[1]),
                                               "{0}".format(type[0]))
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "broken":
                    myStat = sql.valueAtNumber(
                        PlayerID,
                        "{0} | broken | {1}".format(type[1],
                                                    type[2]), "statgems")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "mine" or type[0] == "dig" or type[0] == "fish":
                    myStat = sql.valueAtNumber(
                        PlayerID, "{0} | item | {1}".format(type[0], type[1]),
                        "statgems")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "buy" or type[0] == "sell" or type[
                        0] == "gamble" or type[0] == "stealing":
                    if (type[0] == "buy"
                            or type[0] == "sell") and type[1] != "total":
                        myStat = sql.valueAtNumber(
                            PlayerID,
                            "{0} | item | {1}".format(type[0],
                                                      type[1]), "statgems")
                    else:
                        myStat = sql.valueAtNumber(
                            PlayerID, "{0} | {1}".format(type[0], type[1]),
                            "statgems")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "hothouse" or type[0] == "ferment" or type[
                        0] == "cooking":
                    myStat = sql.valueAtNumber(
                        PlayerID, "{0} | {1} | item | {2}".format(
                            type[0], type[1], type[2]), "statgems")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "forge":
                    myStat = sql.valueAtNumber(
                        PlayerID, "forge | item | {0}".format(type[1]),
                        "statgems")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "pay":
                    myStat = sql.valueAtNumber(PlayerID,
                                               "pay | {0}".format(type[1]),
                                               "statgems")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

                elif type[0] == "inv":
                    myStat = sql.valueAtNumber(PlayerID, "{0}".format(type[1]),
                                               "inventory")
                    if myStat >= x.objectif:
                        nom = lang_P.forge_msg(lang, "success titre",
                                               [GF.ChiffreRomain(x.sid)],
                                               False, x.titre)

#                 elif type[0] == "":
#                     myStat = sql.valueAtNumber(PlayerID, "", "statgems")
#                     if myStat >= x.objectif:
#                         nom = lang_P.forge_msg(lang, "success titre", [GF.ChiffreRomain(x.sid)], False, x.titre)

                if nom != "":
                    sql.add(PlayerID, i, 1, "success")
                    result.append(nom)
                    desc = "{0}".format(
                        lang_P.forge_msg(lang, "success", [nom], False, 0))
                    result.append(desc)
                    if iS == 0:
                        iS = 1
                    gain = r.randint(1, 3) * (6 * (iS))
                    lvl.addxp(PlayerID, gain, "gems")
                    desc = "{0} XP".format(
                        lang_P.forge_msg(lang, "success", [gain], False, 1))
                    if iS > 2:
                        desc += GF.lootbox(PlayerID, lang, True)
                    result.append(desc)
                    return result
    return result