Exemple #1
0
async def learnmove(message, send):
    content = getContent(message)
    if not content:
        return await send(commandlist[getCommand(message)][1])
    try:
        movename, slot = content.rsplit(' ', 1)
        slot = int(slot)
        if slot < 1 or slot > 4:
            raise UserWarning(
                "@mention Invalid slot. It has to be between 1–4!")
    except:
        movename = content
        slot = None

    pokedata = database.loadPokedata(message.author)
    move = pokedex.getMoveByName(movename, pokedata.getPokemon())

    oldMove = pokedata.learnMove(move, slot)
    database.savePokedata(pokedata)

    if slot and oldMove != None:
        return await send(
            '1, 2 and... Poof! @poss @pokemon forgot **{}** and... @pokemon learned {}!'
            .format(oldMove, move))
    else:
        return await send('@poss @pokemon learned {}!'.format(move))
Exemple #2
0
async def battles(message, send):
    pokedata = database.loadPokedata(message.author)
    won = pokedata.getStatistic('battlesWon')
    lost = pokedata.getStatistic('battlesLost')
    raise UserWarning(
        "Your @pokemon has won {} and lost {} battles so far!".format(
            won, lost))
Exemple #3
0
async def whatis(message, send):
    content = getContent(message)
    if not content:
        return await send(commandlist[getCommand(message)][1])

    user = findMember(message, content)
    pokemon = str(database.loadPokedata(user, False))
    m = '{} is {} {}!'.format(user.mention, aOrAn(pokemon), pokemon)
    return await send(m)
Exemple #4
0
async def heal(message, send):
    pokedata = database.loadPokedata(message.author)
    if pokedata.getHp() != 0:
        return await send(
            "Your Pokemon can still fight! Only fainted Pokemon are able to `!heal`."
        )
    pokedata.fullRestore()
    database.savePokedata(pokedata)

    hp = pokedata.getHp()
    m = '@poss @pokemon was fully restored to ({0}/{0}) hp!'.format(hp)
    return await send(m)
Exemple #5
0
async def trainev(message, send):
    value, stat = getArgs(message)
    if not value.isdigit():
        return await send(commandlist[getCommand(message)][1])
    value = int(value)
    stat = pokedex.checkStat(stat)

    pokedata = database.loadPokedata(message.author)
    result = pokedata.trainEV(value, stat)
    database.savePokedata(pokedata)
    return await send(
        "@poss @pokemon trained and increased its {}-EV by ({})!".format(
            stat, result))
Exemple #6
0
async def admin(message, send):
    args = getArgs(message)
    try:
        value = int(args[0])
    except:
        raise UserWarning("@mention Invalid stage. It has to be between -6–6!")
    try:
        stat = args[1]
    except:
        return await send(commandlist[getCommand(message)][1])

    pokedata = database.loadPokedata(message.author)
    log = []
    pokedex.raiseStage(pokedata, value, stat, log)
    database.savePokedata(pokedata)

    log = '\n'.join(log)
    log = log.replace('@attacker', str(pokedata))
    return await send(log)
Exemple #7
0
async def resetev(message, send):
    pokedata = database.loadPokedata(message.author)
    pokedata.resetEV()
    database.savePokedata(pokedata)
    return await send("Your Pokemon's EVs have been reset!")
Exemple #8
0
async def moveset(message, send):
    pokedata = database.loadPokedata(message.author)
    table = pokedata.getMovesetTable()
    return await send("@poss @pokemon {}".format(table))
Exemple #9
0
async def stages(message, send):
    pokedata = database.loadPokedata(message.author)
    stages = pokedata.getStages()
    table = ['{:>8}: {}'.format(stat, stages[stat]) for stat in stages]
    return await send("@poss @pokemon```Python\n{}```".format('\n'.join(table))
                      )
Exemple #10
0
async def attack(message, send):
    content = getContent(message)

    if getCommand(message) == 'attack':
        # !attack USER with MOVE
        result = re.search('(.*)\swith\s(.*)', content)
        if not result:
            return await send(commandlist[getCommand(message)][1])
        other = findMember(message, result.group(1))
        move = pokedex.getMoveByName(result.group(2))
    elif getCommand(message) == 'use':
        # !use MOVE on USER
        result = re.search('(.*)\son\s(.*)', content)
        if result:
            move = pokedex.getMoveByName(result.group(1))
            other = findMember(message, result.group(2))
        else:
            result = re.search('(.*)', content)
            if result:
                move = pokedex.getMoveByName(result.group(1))
                other = message.author
            else:
                return await send(commandlist[getCommand(message)][1])
    else:
        return await send(commandlist[getCommand(message)][1])

    pokeAtk = database.loadPokedata(message.author)
    if message.author.id == other.id:
        pokeDef = pokeAtk
    else:
        pokeDef = database.loadPokedata(other, False)
    attacker = pokeAtk.getOwner()
    defender = pokeDef.getOwner()

    if not pokeAtk.knowsMove(move):
        raise UserWarning(
            "Your @pokemon doesn't know that move yet. Use `!learnmove` to learn it!"
        )
    if not pokeAtk.canUseMove(move):
        raise UserWarning("{} is out of PP!".format(move))

    if pokeAtk.getHp() == 0:
        raise UserWarning(
            "Your @pokemon is unable to fight. Use `!heal` first!".format())
    if pokeDef.getHp() == 0:
        raise UserWarning(
            "The opponent's {} is unable to fight.".format(pokeDef))

    remaining = attacker.getTimeRemaining('attack',
                                          pokeAtk.getAttackCooldown())
    if remaining > 0:
        waitTime = getDurationString(remaining)
        raise UserWarning(
            '@mention Your attack refreshes in _{}_.'.format(waitTime))
    attacker.setTimestamp('attack')

    # Attack start
    try:
        log = []

        channel = database.loadChannel(message.channel)

        clearOldWeather(message, send)
        weather = {'current': channel.getWeather(), 'new': None}

        pokedex.attack(pokeAtk, pokeDef, log, move, weather)

        if pokeAtk == pokeDef and pokeAtk.getHp() == 0:
            log += ["Your @attacker fainted!"]
        else:
            if pokeDef.getHp() == 0:
                won = pokeAtk.incStatistic('battlesWon', 1)
                pokeDef.incStatistic('battlesLost', 1)
                log += ["Opponent's @defender fainted!"]
                if won > 0 and won % 10 == 0:
                    attacker.incCaps(1)
                    log += [
                        "{} You earned a bottlecap! Use it to `!hypertrain`.".
                        format(message.author.mention)
                    ]
            if pokeAtk.getHp() == 0:
                won = pokeDef.incStatistic('battlesWon', 1)
                pokeAtk.incStatistic('battlesLost', 1)
                log += ["Your @attacker fainted!"]
                if won > 0 and won % 10 == 0:
                    defender.incCaps(1)
                    log += [
                        "{} You earned a bottlecap! Use it to `!hypertrain`.".
                        format(other.mention)
                    ]
        raise pokedex.EndAttack()
    except pokedex.EndAttack as msg:
        database.saveUser(attacker)
        database.saveUser(defender)

        if str(msg):
            log += [str(msg)]
        log = '\n'.join(log)
        log = log.replace('@attacker', str(pokeAtk))
        log = log.replace('@defender', str(pokeDef))
        await send(log)

    if weather['new']:
        await activateWeather(message, send, weather['new'])