Ejemplo n.º 1
0
def login():

    # if operation is of uploading file
    operation = request.form['operation']

    if operation == 'upload_file':
        # extract data from received request
        file_name = request.form['file_name']
        usr_id = request.form['user_id']
        file_data = request.files['file_data']

        if file_name.endswith(".csv"):
            # save the file data to a file
            file_operations.save_file(file_data, file_name)
            # make an entry to db as who uploaded which file
            file_operations.add_to_db(usr_id, file_name)

        elif file_name.endswith(".log"):
            # this is for collecting logs
            file_operations.update_logs_file(file_data)

        return 'upload successful'

    # if the user requested for assigning USER id
    elif operation == 'assign_usr_id':
        return str(file_operations.assign_usr_id())
Ejemplo n.º 2
0
def delete(userId, opponentId):
    duels = read_file("duels.txt")
    file = []
    for d in duels:
        splitDuel = d.split("[:]")
        if splitDuel[0] != (str(userId)
                            or str(opponentId)) and splitDuel[2] != (
                                str(userId) or str(opponentId)):
            file.append(d)
    save_file("duels.txt", file)
Ejemplo n.º 3
0
def party_abandon(userId):
    parties = read_file('parties.txt')

    file = []

    for party in parties:
        split_party = party.split('[:]')

        if split_party[0] != str(userId):
            file.append(party)

    save_file('parties.txt', file)

    return f'<@!{userId}> Successfully abandoned your party'
Ejemplo n.º 4
0
def party_add(userId, pokemonName):
    pokemon = find_pokemon(pokemonName.lower())

    if pokemon != None:
        parties = read_file('parties.txt')

        for party in parties:
            split_party = party.split('[:]')
            if (split_party[0] == str(userId)):
                return f'<@!{userId}> You already have a party, you must abandon it to create a new one!'

        parties.append(f'{userId}[:]{pokemonName}[:]{pokemon}\n')

        save_file('parties.txt', parties)

        return f'Adding {pokemonName} to your party! Your move set will be {find_move_names(pokemon["moves"])}'
    else:
        return 'Could not find that pokemon, also note that only gen 1 is allowed'
Ejemplo n.º 5
0
def duel(userId, opponentId, level):
    if userId == opponentId:
        return "You cant duel yourself, stupid, dumb, white, idiot"
    parties = read_file("parties.txt")
    userParty = None
    opponentParty = None
    for p in parties:
        party = party_parser(p)
        if party["userId"] == userId:
            userParty = party
        elif party["userId"] == opponentId:
            opponentParty = party
    print(userParty)
    if userParty is None:
        return f'<@!{userId}>, you do not have a party'
    elif opponentParty is None:
        return f"<@!{opponentId}>, you do not have a party"

    duels = read_file('duels.txt')
    for d in duels:
        split_duel = d.split('[:]')
        if (split_duel[0] == str(userId)) and split_duel[2] == str(opponentId):
            return "You already got a battle with this fella!"

    userParty['pokemon']['stats'] = {
        'hp':
        calculate_health(userParty['pokemon']['stats']['hp'], level),
        'attack':
        calculate_stat(userParty['pokemon']['stats']['attack'], level),
        'defense':
        calculate_stat(userParty['pokemon']['stats']['defense'], level),
        'special-attack':
        calculate_stat(userParty['pokemon']['stats']['special-attack'], level),
        'special-defense':
        calculate_stat(userParty['pokemon']['stats']['special-defense'],
                       level),
        'speed':
        calculate_stat(userParty['pokemon']['stats']['speed'], level),
    }

    opponentParty['pokemon']['stats'] = {
        'hp':
        calculate_health(opponentParty['pokemon']['stats']['hp'], level),
        'attack':
        calculate_stat(opponentParty['pokemon']['stats']['attack'], level),
        'defense':
        calculate_stat(opponentParty['pokemon']['stats']['defense'], level),
        'special-attack':
        calculate_stat(opponentParty['pokemon']['stats']['special-attack'],
                       level),
        'special-defense':
        calculate_stat(opponentParty['pokemon']['stats']['special-defense'],
                       level),
        'speed':
        calculate_stat(opponentParty['pokemon']['stats']['speed'], level),
    }

    duels.append(
        f'{userId}[:]{userParty["pokemon"]}[:]{opponentId}[:]{opponentParty["pokemon"]}[:]{level}'
    )

    save_file("duels.txt", duels)

    return "Duel!"
Ejemplo n.º 6
0
def save_temp(userId, speed, effect, opponentId):
    temp = read_file('temp.txt')

    temp.append(f'{userId}[:]{speed}[:]{effect}[:]{opponentId}')

    save_file('temp.txt', temp)
Ejemplo n.º 7
0
def executeMove(moveText, defenderId, userId):
    duels = read_file("duels.txt")
    defender = None
    attacker = None

    effects = []

    for d in duels:
        selected_duel = duel_parser(d)
        if selected_duel["userId"] == userId and selected_duel[
                "opponentId"] == defenderId:
            attacker = selected_duel["userPokemon"]
            defender = selected_duel["opponentPokemon"]
        elif selected_duel["userId"] == defenderId and selected_duel[
                "opponentId"] == userId:
            attacker = selected_duel["opponentPokemon"]
            defender = selected_duel["userPokemon"]
    move = None
    moves = attacker["moves"]
    for m in moves:
        print(m["name"])
        if moveText == m["name"]:
            move = m
    if move is None:
        return "That is not a valid move, fool"
    if move["pp"] == 0:
        return f"<@!{userId}> has no pp, zero"

    move["pp"] = int(move["pp"]) - 1
    accuracy = move["accuracy"]

    if random.randint(0, 100) >= accuracy:
        save_temp(userId, 0, [], defenderId)
        return "You missed your attack"

    power = move["power"]
    moveType = move["type"]
    attackerLevel = attacker["level"]
    attackingStat = attacker["stats"]["attack"]
    specialAttackingStat = attacker["stats"]["special-attack"]
    attackerTypeList = attacker["types"]

    defendingAttack = defender["stats"]["defense"]
    defendingSpecialAttack = defender["stats"]["special-defense"]
    defendingTypesList = defender["types"]

    damageType = move["damage_class"]["type"]
    rightHalf = None

    for element in move["stat_changes"]:
        statChange = element["change"]
        if statChange > 0:
            effects.append({
                "action": element["name"],
                "target": "self",
                "change": statChange
            })
            #statusMove(attacker,statChange,element["name"])
        elif statChange < 0:
            effects.append({
                "action": element["name"],
                "target": "opponent",
                "change": statChange
            })
            # statusMove(attacker,statChange,element["name"])
    if damageType == "status":
        return "You did status"
    if damageType == "physical":
        rightHalf = rightHalfEquation(attackingStat, defendingAttack, power)
    elif damageType == "special":
        rightHalf = rightHalfEquation(specialAttackingStat,
                                      defendingSpecialAttack, power)
    finalModifier = modifier(moveType, attackerTypeList,
                             (random.randint(85, 100)) / 100,
                             move["damage_class"]["relations"],
                             defendingTypesList)
    print(attackerLevel, rightHalf, finalModifier)
    damage = -round(
        ((((((2 * attackerLevel) / 5) + 2) * rightHalf) / 50) + 2) *
        finalModifier, 2)
    print("Took", damage, "points of damage")
    print(move["pp"])
    effects.append({"action": "hp", "target": "opponent", "change": damage})
    speed = attacker["stats"]["speed"]
    var = get_temp(userId, defenderId)
    moveList = ""
    if var is not None:
        if int(speed) > int(var["speed"]):
            for effect in effects:
                if effect["target"] == "self":
                    if effect["action"] in attacker["stats"]:
                        attacker["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    else:
                        move[effect["target"]] += round(effect["change"], 2)
                    moveList = moveList + f'<@!{userId}> increased their {effect["action"]} by {effect["change"]}\n'
                else:
                    if effect["action"] in defender["stats"]:
                        defender["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{userId}> decreased <@!{defenderId}>\'s {effect["action"]} by {effect["change"]}\n'
            for effect in var["effects"]:
                if effect["target"] == "self":
                    if effect["action"] in defender["stats"]:
                        defender["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{defenderId}> increased their {effect["action"]} by {effect["change"]}\n'
                else:
                    if effect["action"] in attacker["stats"]:
                        attacker["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{defenderId}> decreased <@!{userId}>\'s {effect["action"]} by {effect["change"]}\n'
        else:
            for effect in var["effects"]:
                if effect["target"] == "self":
                    if effect["action"] in defender["stats"]:
                        defender["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{defenderId}> increased their {effect["action"]} by {effect["change"]}\n'
                else:
                    if effect["action"] in attacker["stats"]:
                        attacker["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{defenderId}> decreased <@!{userId}>\'s {effect["action"]} by {effect["change"]}\n'
            for effect in effects:
                if effect["target"] == "self":
                    if effect["action"] in attacker["stats"]:
                        attacker["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{userId}> increased their {effect["action"]} by {effect["change"]}\n'
                else:
                    if effect["action"] in defender["stats"]:
                        defender["stats"][effect["action"]] += round(
                            effect["change"], 2)
                    moveList = moveList + f'<@!{userId}> decreased <@!{defenderId}>\'s {effect["action"]} by {effect["change"]}\n'
        temp = read_file('temp.txt')

        file = []
        for t in temp:
            split_temp = t.split('[:]')
            if split_temp[0] != (str(userId)
                                 or str(defenderId)) and split_temp[3] != (
                                     str(userId) or str(defenderId)):
                file.append(t)

        save_file('temp.txt', file)
    else:
        save_temp(userId, speed, effects, defenderId)
        return "mover recorded good sir"

    update_file(
        "duels.txt",
        f'{userId}[:]{attacker}[:]{defenderId}[:]{defender}[:]{attackerLevel}')

    if int(attacker["stats"]["hp"]) <= 0:
        moveList = moveList + f'<@!{userId}> fainted! <@!{defenderId}> is the winner with {defender["stats"]["hp"]} remaining!!'
        delete(userId, defenderId)
    elif int(defender["stats"]["hp"]) <= 0:
        moveList = moveList + f'<@!{defenderId}> fainted! <@!{userId}> is the winner with {attacker["stats"]["hp"]} remaining!!'
        delete(userId, defenderId)
    else:
        moveList = moveList + f'<@!{userId}>\'s health is {attacker["stats"]["hp"]} and <@!{defenderId}>\'s health is {defender["stats"]["hp"]}'
    return moveList