Example #1
0
async def quick_details(message):
    params = message.content.split()
    try:
        box = int(params[1])
        index = int(params[2])
    except Exception:
        try:
            if params[1] == '-1':
                #return the latest poke
                box = 0
                index = 0
            else:
                raise IndexError
        except:
            await client.send_message(message.channel, 'Invalid Format.')
            return
    if not await is_player(message):
        return
    await client.send_message(message.channel, 'Accessing PC...')
    player = instances.read_playerfile(message.author.id)
    try:
        await show_poke_details(message,
                                player.boxes[box - 1].pokemon[index - 1])
        await client.send_message(message.channel, 'PC Closed.')
    except Exception:
        await client.send_message(message.channel, 'Box index out of bounds.')
Example #2
0
async def test_fight(message):
    player = instances.read_playerfile(message.author.id)
    p1 = battle.BattlePlayer(client, player, message.author)
    robot_poke = p1.curr_party[0].poke.to_dict()
    robot_poke['name'] += '_bot'
    robot_poke = instances.read_pokedict(robot_poke)
    p2 = battle.BattleAI('Mr. Roboto', [robot_poke], 'RAND', 'Hey, I won!',
                         'Hey, You won!')
    battle_instance = battle.Battle(p1, p2, client, message.channel)
    await battle_instance.play_battle()
Example #3
0
async def party_details(message):
    params = message.content.split()
    try:
        index = int(params[1])
    except Exception:
        await client.send_message(message.channel, 'Invalid Format.')
        return
    if not await is_player(message):
        return
    player = instances.read_playerfile(message.author.id)
    try:
        await show_poke_details(message, player.party[index - 1])
    except Exception:
        await client.send_message(message.channel,
                                  'Party index out of bounds.')
Example #4
0
async def ai_exhibition(client, message, ai_id):
    ai_id = regex.sub(r'[ \t]+$', '', ai_id)
    ai_id = regex.sub(r'[^\w\s]', '', ai_id)
    ai_id = regex.sub(r'[\s]', '_', ai_id)
    ai_id = ai_id.lower()
    try:
        npc = load_npc_file(ai_id)
    except FileNotFoundError:
        await client.send_message(
            message.channel,
            f"Error. Tried to fight someone that doesn't exist\n(Tried: {ai_id}"
        )
        return
    try:
        player = BattlePlayer(client,
                              instances.read_playerfile(message.author.id),
                              message.author)
    except Exception:
        await client.send_message(message.channel, 'Error...you dont exist?')
        return
    bat = Battle(player, npc, client, message.channel)
    await bat.play_battle()
Example #5
0
async def encounter_poke(message):
    #check if current user is a player
    if not await is_player(message):
        return
    player = instances.read_playerfile(message.author.id)
    #check if the correct amount of time has passed
    with open(TIMESTAMP_FILE, 'r') as f:
        time_data = json.load(f)
    if player.id in time_data:
        last_time = time_data[player.id]
        diff = int(time.time()) - last_time
        if diff < cooldown:
            remain = cooldown - diff
            if remain > 40:
                remain = await seconds_to_minutes(remain)
                await client.send_message(
                    message.channel, 'Please wait ' + str(remain) +
                    ' minute(s) before finding another!')
            else:
                await client.send_message(
                    message.channel, 'Please wait ' + str(remain) +
                    ' seconds(s) before finding another!')
            return
    #-------END OF CHECKS-------
    #set up pokemon. Keeps trying if none found, and if location contains none,
    #keep going to new locations until a poke is found.
    poke = None
    tries = 5
    while poke == None:
        while poke == None and tries >= 0:
            poke = instances.make_for_encounter(await get_location())
            print(poke)
            tries -= 1

        if poke == None:
            poke = instances.make_for_encounter(await get_location(force=True))

    output = 'A wild ' + str(poke.name).title() + ' Appears!'
    output += '\nLevel:    ' + str(poke.level)
    await client.send_message(message.channel, output)
    await send_pic(message, poke)
    output = '----------------'

    #check if the player even has a party.
    #if no party, always catch pokemon and never fight

    if player.party == []:
        await client.send_message(message.channel, output)
        await catch_poke(message, player, poke)
        done = True
    else:
        done = False
    while not done:
        output += '\nCatch or Fight? (c/f)'
        await client.send_message(message.channel, output)
        response = await client.wait_for_message(author=message.author,
                                                 channel=message.channel)
        try:
            response = response.content.lower()
        except Exception:  #the response is in a fucky wucky format
            output = 'Invalid Response.\n'
        else:
            if response == 'c':
                done = True
                await catch_poke(message, player, poke)
            elif response == 'f':
                done = True
                await fight_wild(message, player, poke)
            else:
                output = 'Invalid Response.'
    #player should have encountered a poke to get here
    #update the players timeout, they will have to wait through the timeout again after
    with open(TIMESTAMP_FILE, 'r') as f:
        time_data = json.load(f)
    time_data[player.id] = int(time.time())
    with open(TIMESTAMP_FILE, 'w') as f:
        json.dump(time_data, f)
    instances.write_player(player)
Example #6
0
async def show_party(message):
    if not await is_player(message):
        return
    player = instances.read_playerfile(message.author.id)
    await client.send_message(message.channel, player.str_party())
Example #7
0
async def show_boxes(message, curr_box=0):
    if not await is_player(message):
        return
    await client.send_message(message.channel, 'Booting PC...')
    player = instances.read_playerfile(message.author.id)
    if player.boxes == []:
        await client.send_message(
            message.channel, 'You have no boxes! catch some pokemon first!')
        return
    if curr_box >= len(player.boxes):
        await client.send_message(message.channel,
                                  'Box index out of range. Opening Box 1.')
        curr_box = 0
    done = False
    disp_pc = True
    disp_party = True
    disp_cmds = True
    fails = 0
    while not done:
        #Pc list:
        if disp_pc:
            output = '```---- ' + player.name + '\'s PC ----'
            output += '\nBox ' + player.boxes[curr_box].name
            output += ' (' + str(curr_box + 1) + '/' + str(len(
                player.boxes)) + '):\n'
            output += str(player.boxes[curr_box])
            output += '```'
            await client.send_message(message.channel, output)
            disp_pc = False
        if disp_party:
            await client.send_message(message.channel, player.str_party())
            disp_party = False
        if disp_cmds:
            #Commands:
            output = '```\nCommands:'
            output += '\n"help" --- Show this command list'
            output += '\n"show" --- Reshow the pc'
            output += '\n"details <index>" --- Show more details on specified pokemon'
            output += '\n"party" --- Show current party'
            output += '\n"take <index> <partyindex>" --- Add box pokemon at given index to party, swapping with the existing pokemon.'
            output += '\n"deposit <partyindex>" --- deposit a pokemon into the box.'
            if curr_box < len(player.boxes) - 1:
                output += '\n">" -- next box'
            if curr_box > 0:
                output += '\n"<" -- previous box'
            output += '\n"exit" or "c" -- close pc'
            output += '```'
            await client.send_message(message.channel, output)
            disp_cmds = False
        response = await client.wait_for_message(author=message.author,
                                                 channel=message.channel,
                                                 timeout=PC_TIMEOUT)
        if response != None:
            response = response.content.lower()
            if response == None:
                done = True
            elif response == '>' and curr_box < len(player.boxes) - 1:
                curr_box += 1
                disp_pc = True
            elif response == '<' and curr_box > 0:
                curr_box -= 1
                disp_pc = True
            elif response in exits:
                done = True
            elif response == 'help':
                show_cmds = True
            elif response == 'details':
                disp_pc = True
            elif response == 'party':
                disp_party = True
            elif response.startswith('details '):
                num = None
                try:
                    num = int(response[8:])
                except Exception:
                    await client.send_message(message.channel,
                                              'Invalid Index/Format.')
                else:
                    try:
                        await show_poke_details(
                            message, player.boxes[curr_box].pokemon[num - 1])
                    except Exception:
                        await client.send_message(message.channel,
                                                  'Invalid Index/Format.')
            elif response.startswith('*'):
                num = None
                try:
                    num = int(response[1:])
                except Exception:
                    await client.send_message(message.channel,
                                              'Invalid Index/Format.')
                else:
                    try:
                        await show_poke_details(
                            message, player.boxes[curr_box].pokemon[num - 1])
                    except Exception:
                        await client.send_message(message.channel,
                                                  'Invalid Index/Format.')
            elif response.startswith('take '):
                try:
                    params = response.split()
                    if len(params) == 2:
                        pc_index = int(params[1]) - 1
                        party_index = len(player.party)
                    elif len(params) == 3:
                        pc_index = int(params[1]) - 1
                        party_index = int(params[2]) - 1
                    else:
                        raise Exception

                except Exception as e:
                    print(e)
                    await client.send_message(message.channel,
                                              'Invalid Index/Format.')
                else:
                    if pc_index > len(
                            player.boxes[curr_box]) - 1 or party_index > 5:
                        await client.send_message(message.channel,
                                                  'Index too large!')
                    else:
                        if party_index > len(player.party) - 1:
                            player.party.append(
                                player.boxes[curr_box].pop(pc_index))
                        else:
                            temp = player.party[party_index]
                            player.party[party_index] = player.boxes[curr_box][
                                pc_index]
                            player.boxes[curr_box][pc_index] = temp
                        disp_party = True
            elif response.startswith('deposit '):
                try:
                    params = response.split()
                    party_index = int(params[1]) - 1
                except Exception as e:
                    print(e)
                    await client.send_message(message.channel,
                                              'Invalid Index/Format.')
                else:
                    if party_index > len(player.party) - 1:
                        await client.send_message(message.channel,
                                                  'Party index out of range!')
                    else:
                        if player.boxes[curr_box].is_full():
                            curr_box += 1
                        player.add_poke(player.party.pop(party_index))
                        disp_party = True
            else:
                fails += 1
                if fails == 3:
                    done = True

        else:
            done = True
    await client.send_message(message.channel, player.name + '\'s PC closed.')
    instances.write_player(player)