Exemple #1
0
async def leaderBoards(board, message):
    global leaderboardtimer
    newlist = {}
    badboard = False
    for player in PLAYER:
        if board == 'level':
            newlist[player] = PLAYER[player].level
        elif board == 'life':
            newlist[player] = PLAYER[player].maxlife
        elif board == 'mana':
            newlist[player] = PLAYER[player].maxmana
        elif board == 'focus':
            newlist[player] = PLAYER[player].maxfocus
        elif board == 'vigor':
            newlist[player] = PLAYER[player].vigor
        elif board == 'power':
            newlist[player] = PLAYER[player].power
        elif board == 'finesse':
            newlist[player] = PLAYER[player].finesse
        elif board == 'will':
            newlist[player] = PLAYER[player].will
        elif board == 'guard':
            newlist[player] = PLAYER[player].guard
        elif board == 'magic':
            newlist[player] = PLAYER[player].magic
        elif board == 'speed':
            newlist[player] = PLAYER[player].speed
        elif board == 'luck':
            newlist[player] = PLAYER[player].luck
        elif board == 'ides':
            newlist[player] = PLAYER[player].money
        elif board == 'kills':
            newlist[player] = PLAYER[player].kills
        elif board == 'deaths':
            newlist[player] = PLAYER[player].deaths
        elif board == 'timeouts':
            newlist[player] = PLAYER[player].timeouts
        elif board == 'runaways':
            newlist[player] = PLAYER[player].runaway
        elif board == 'killstreak':
            newlist[player] = PLAYER[player].killstreak
        else:
            await chat(message, "Leaderboards for that stat do not exist!")
            badboard = True
            break
    sortedlist = sorted(newlist.items(), key=operator.itemgetter(1))
    sortedlist.reverse()
    while len(sortedlist) < 5:
        sortedlist.append('No Data')
    if badboard is False:
        leaderboardtimer = time.time()
        await chat(
            message,
            blockify(("Top 5 players in %s are:\n" % board.title()) +
                     ("1. %s\n" % (leaderBoardsSorting(sortedlist[0]))) +
                     ("2. %s\n" % (leaderBoardsSorting(sortedlist[1]))) +
                     ("3. %s\n" % (leaderBoardsSorting(sortedlist[2]))) +
                     ("4. %s\n" % (leaderBoardsSorting(sortedlist[3]))) +
                     ("5. %s" % (leaderBoardsSorting(sortedlist[4])))))
Exemple #2
0
 async def examineItem(self, item, PLAYER):
     if item in ITEM:
         item_obj = None
         types = ['Weapons', 'Shields', 'Charms', 'Items']
         if ITEM[item].typeof in types:
             type = ITEM[item].typeof[:len(ITEM[item].typeof) - 1].capitalize()
         else:
             type = ITEM[item].typeof.capitalize()
         equipment = [self.weapon.name, self.armor.name, self.shield.name, self.charm.name]
         inventory = [item.name for item in self.inventory]
         itemlist = equipment + inventory
         if self.state == State.SHOPPING:
             itemlist += self.location.shopitem
         elif len(self.tempslot) == 1:
             itemlist.append(self.tempslot[0].name)
         if item in itemlist:
             item_obj = ITEM[item]
         if item_obj is not None:
             str = item_obj.getImage()
             if str != 'RPGFiles/Art/Icons/NOPIC.png':
                 img = image_editor.size128(str, string=True)
                 img.save('temp%s.png' % self.id)
                 await idchat(self.id, blockify(type + "\n%s" % (item_obj.description)), ['temp%s.png' % self.id])
                 os.remove('temp%s.png' % self.id)
             else:
                 await idchat(self.id, blockify(type + "\n%s" % (item_obj.description)))
         else:
             await idchat(self.id, ("You can't find the item to examine..."))
     elif item in TECH:
         tech_obj = None
         tech = item
         if self.state == State.TRAINING:
             examinelist = self.location.traineritem
             if tech in examinelist:
                 tech_obj = TECH[tech]
         else:
             techlist = [TECH[tech].name for tech in self.skills] + [TECH[tech].name for tech in self.spells]
             if tech in techlist:
                 tech_obj = TECH[tech]
         if tech_obj is not None:
             await idchat(self.id, blockify(TECH[tech].description))
         else:
             await idchat(self.id, "No one around knows that spell or skill...")
     else:
         await idchat(self.id, "'%s' does not exist!" % item)
Exemple #3
0
 async def displayTravel(self):
     loc = self.allowedlocations
     loc.sort()
     stringofitems = ''
     for i in loc:
         if i == self.location.name:
             stringofitems += i + " <-- You are here!\n"
         else:
             stringofitems += i + "\n"
     await idchat(self.id, "Travel Locations:\n%s" % (blockify(stringofitems)))
Exemple #4
0
async def leaderBoards(list):
    newlist = {}
    for player in list:
        newlist[player] = list[player]
    sortedlist = sorted(newlist.items(), key=operator.itemgetter(1))
    sortedlist.reverse()
    while len(sortedlist) < 10:
        sortedlist.append('No Data')
    text = ""
    count = 0
    while count < 10:
        if sortedlist[count] != 'No Data':
            text += "%s. %s: %s\n" % (count + 1,
                                      nameFromID(sortedlist[count][0]),
                                      sortedlist[count][1])
        count += 1
    await triviaChat(blockify(text))
Exemple #5
0
async def handleCommand(message):
    content = message.content.lower()
    if message.content == "-joinRPG":
        await startRPG(message)
        return
    elif message.content == "-lbs" or message.content == "-leaderboards":
        board = message.content[5:].lower()
        await chat(
            message,
            blockify(
                "Choices:\n  level\n  life\n  mana\n  focus\n  vigor\n  power\n  finesse\n  will\n  guard\n  "
                +
                "magic\n  speed\n  luck\n  ides\n  kills\n  deaths\n  timeouts\n  runaways\n  killstreak\n"
            ))
        return
    elif message.content[:
                         5] == "-lbs " or message.content[:
                                                          14] == "-leaderboards ":
        split = message.content.split(' ')
        board = split[1]
        await leaderBoards(board, message)
        return
    if message.author.name in PLAYER:
        if PLAYER[message.author.name].id == -1:
            PLAYER[message.author.name].id = message.author.id
        if PLAYER[message.author.name].id == message.author.id:
            if message.channel != '':
                PLAYER[message.author.name].lastchannel = str(message.channel)
            PLAYER[message.author.name].lastmessage = content
            for text in rpgCommands:
                text = rpgSymbol + text
                if message.content.find(text) != -1:
                    await PLAYER[message.author.name
                                 ].handleCharacterCommand(RPGTestMode)
                    return
        else:
            await chat(
                message,
                ("You do not own %s!" % PLAYER[message.author.name].name))
Exemple #6
0
 async def playerTurn(self, player, target, escape):
     # commands = ['-fight', '-attack', '-check', '-use', '-escape']
     # notFound = True
     if player.lastmessage == '-fight' or player.lastmessage == '-attack':
         await self.damageRoll(player, target)
         player.energy -= player.weapon.energyuse
         if player.energy >= 1000 and target.life > 0:
             await idchat(player.id,
                          ("You still have %s energy!" % (player.energy)))
         player.lastmessage = ''
         player.chargecount = 1
     elif player.lastmessage == '-check':
         for player in self.players:
             if player.name == player.name:
                 await idchat(
                     player.id,
                     blockify((
                         "%s\n Life: %s\n Will: %s\nPower: %s\nGuard: %s\nSpeed: %s\n Luck: %s\n%s"
                         % (unbold(target.name), target.life,
                            (target.will + target.statchange['will']),
                            (target.power + target.statchange['power']),
                            (target.guard + target.statchange['guard']),
                            (target.speed + target.statchange['speed']),
                            (target.luck + target.statchange['luck']),
                            target.description))))
             elif player.name == target.name:
                 await idchat(player.id,
                              "%s is checking you out!" % (player.name))
             else:
                 await idchat(
                     player.id,
                     "%s is checking out %s!" % (player.name, target.name))
         player.energy -= 100
         if player.energy >= 1000 and target.life > 0:
             await idchat(player.id,
                          ("You still have %s energy!" % (player.energy)))
         player.lastmessage = ''
     elif player.lastmessage[:5] == '-use ':
         itemname = smartCapitalize(player.lastmessage[5:])
         if itemname not in ITEM:
             await idchat(self.id, "'%s' does not exist!" % itemname)
         elif ITEM[itemname] in player.inventory:
             item = ITEM[itemname]
             if await item.useItemBattle(self, player, target, self.players,
                                         escape):
                 return True
         else:
             await idchat(player.id,
                          "You don't have %s!" % (bold(itemname)))
         if player.energy >= 1000 and target.life > 0:
             await idchat(player.id,
                          "You still have %s energy!" % (player.energy))
         player.lastmessage = ''
     elif player.lastmessage[:6] == '-cast ':
         spellname = smartCapitalize(player.lastmessage[6:])
         if spellname not in TECH:
             await idchat(player.id, "This spell does not exist!")
         elif TECH[spellname] in player.spells:
             spell = TECH[spellname]
             if spell.battle is False:
                 await idchat(
                     player.id,
                     "You can't use %s in this way." % (bold(spellname)))
             else:
                 for player in self.players:
                     if player.name == player.name:
                         await idchat(player.id, "%s" % (spell.usedtext))
                     else:
                         await idchat(
                             player.id, "%s used %s!" %
                             (player.name, bold(spell.name)))
                 player.energy -= item.energyuse
                 player.life = min(
                     player.life +
                     ceil(player.get('maxlife') * (spell.curelife / 100)),
                     player.get('maxlife'))
                 if spell.curestatus == 0:
                     await player.clearStatusEffects()
                     await player.clearStatChanges()
                 for stat in player.statchange:
                     player.statchange[stat] += spell.buff[stat]
                 await target.evaluateStatus(target, spell.statusinflict,
                                             spell.statuschance)
         else:
             await idchat(player.id,
                          "You don't know %s!" % (bold(spellname)))
         if player.energy >= 1000 and target.life > 0:
             await idchat(player.id,
                          "You still have %s energy!" % (player.energy))
         player.lastmessage = ''
     elif player.lastmessage == '-escape':
         if escape is True:
             escaperoll = randint(1, 100)
             escapechance = ((player.life / player.get('maxlife')) *
                             (player.get('speed') / target.get('speed')) +
                             player.get('luck') * 0.002) * 100
             if escapechance >= escaperoll:
                 await idchat(player.id, "You escape!")
                 player.runaway += 1
                 player.lastmessage = ''
                 return True
             else:
                 await idchat(player.id, "You fail to escape!")
                 player.energy -= 200
                 if player.energy >= 1000 and target.life > 0:
                     await idchat(
                         player.id,
                         "You still have %s energy!" % (player.energy))
         else:
             await idchat(player.id, "You can not escape!")
         player.lastmessage = ''
     return False
Exemple #7
0
async def handleTriviaCommand(message):
    global triviaBot
    if message.content == '!start':
        await triviaChat(
            "Start should be in this format: '!start <number of questions> <categories seperated by ',' or all>'"
        )
    elif message.content[:7] == '!start ':
        message.content = message.content.lower()
        split = message.content.split(" ")
        if len(split) >= 3 and is_number(split[1]):
            categories = []
            if split[2] != 'all':
                categoriesCheck = split[2].split(',')
                for category in categoriesCheck:
                    if category.title() in questionPool:
                        categories.append(category)
                if len(categories) > 0:
                    triviaBot = Trivia(categories, int(split[1]))
                    await triviaBot.startTrivia()
            else:
                for category in questionPool:
                    categories.append(category)
                triviaBot = Trivia(categories, int(split[1]))
                await triviaBot.startTrivia()
        else:
            await triviaChat(
                "Start should be in this format: '!start <number of questions> <categories seperated by ',' or all>'"
            )
    elif message.content == '!add':
        await triviaChat(
            "Questions should be added in this format: '!add (Category|Question|Answer)' (ex: !add (FinalFantasy|What are the iconic yellow chickens called?|Chocobo) )"
        )
    elif message.content[:5] == '!add ':
        cmd = message.content[5:]
        print(cmd)
        if len(cmd) > 0:
            split2 = cmd[1:len(cmd) - 1].split("|")
            print(split2)
            if len(split2) == 3:
                await addQuestion(split2[0].title(), split2[1],
                                  split2[2].title())
                await triviaChat("Question has been added!")
            else:
                await triviaChat(
                    "Questions should be added in this format: '!add (Category|Question|Answer)' (ex: !add (FinalFantasy|What are the iconic yellow chickens called?|Chocobo) )"
                )
        else:
            await triviaChat(
                "Questions should be added in this format: '!add (Category|Question|Answer)' (ex: !add (FinalFantasy|What are the iconic yellow chickens called?|Chocobo) )"
            )
    elif message.content == '!categories':
        text = ''
        for c in questionPool:
            text += "%s : %s\n" % (c, len(questionPool[c]))
        await triviaChat(blockify(text))
    elif message.content == '!stop':
        if triviaBot is not None:
            triviaBot.stop()
            triviaBot = None
            await triviaChat("The trivia bot has been stopped!")
        else:
            await triviaChat("The trivia bot is not running!")
    elif message.content == '!leaderboards' or message.content == '!lbs':
        await leaderBoards()
    elif message.content == '!commands' or message.content == '!cmds':
        text_block = ''
        for type in Commands:
            text_block += type + '\n'
            for command in Commands[type]:
                text_block += "  " + command + "  :  " + Commands[type][
                    command] + '\n'
        await triviaChat(blockify(text_block))
    else:
        if triviaBot is not None:
            triviaBot.lastAnswer = [message.author, message.content]
            await triviaBot.checkAnswer()
Exemple #8
0
 async def shopping(self, player):
     if self.hasshop is False:
         await idchat(player.id,
                      "There is no shop in %s!" % (bold(self.name)))
     elif player.state == State.SHOPPING:
         await idchat(player.id, "You are already shopping!")
     elif player.state == State.TRAINING:
         await idchat(player.id, "You can't shop while training!")
     elif player.state == State.ENCOUNTER:
         await idchat(player.id, "You can't shop during an encounter!")
     else:
         player.state = State.SHOPPING
         await idchat(
             player.id,
             "%s\nYou have %s Ides. What would you like to do? (-commands)"
             % (self.shopopening, player.money))
         player.lastmessage = ''
         rumorcount = 0
         buysomething = False
         while True:
             await asyncio.sleep(1)
             if player.lastmessage == "-commands" or player.lastmessage == "-cmds":
                 await idchat(
                     player.id,
                     blockify(
                         createCommandsBlock(
                             ['Shopping', 'Inventory', 'Other', 'Debug'])))
                 player.lastmessage = ''
             elif player.lastmessage[:5] == "-buy ":
                 itemname = smartCapitalize(player.lastmessage[5:])
                 splititem = itemname.split(' ')
                 amount = splititem[len(splititem) - 1]
                 if is_number(amount) and int(amount) > 0:
                     amount = int(amount)
                     itemname = ''
                     i = 0
                     j = len(splititem) - 2
                     for text in splititem:
                         if i < j:
                             itemname += text + ' '
                         elif i == j:
                             itemname += text
                         i += 1
                 else:
                     amount = 1
                 if itemname not in ITEM:
                     await idchat(player.id,
                                  "'%s' does not exist!" % itemname)
                 else:
                     itemfound = False
                     for item in self.shopitem:
                         if item == itemname:
                             check = await player.checkinventoryslots()
                             if check >= amount:
                                 if player.money > ITEM[
                                         itemname].price * amount:
                                     player.money -= ITEM[
                                         itemname].price * amount
                                     num = amount
                                     while num > 0:
                                         player.inventory.insert(
                                             0, ITEM[itemname])
                                         num -= 1
                                     await idchat(
                                         player.id,
                                         "You bought %s x%s for %s ides!" %
                                         (bold(itemname), amount,
                                          ITEM[itemname].price * amount))
                                     await player.save()
                                     buysomething = True
                                 else:
                                     await idchat(
                                         player.id,
                                         "You don't have enough ides!")
                             elif check < amount:
                                 await idchat(
                                     player.id,
                                     "You don't have enough space for %s x%s!"
                                     % (bold(itemname), amount))
                             itemfound = True
                             break
                     if itemfound is False:
                         await idchat(
                             player.id,
                             "The shop doesn't sell %s!" % (bold(itemname)))
                 player.lastmessage = ''
             elif player.lastmessage[:6] == "-sell ":
                 itemname = smartCapitalize(player.lastmessage[6:])
                 splititem = itemname.split(' ')
                 amount = splititem[len(splititem) - 1]
                 if is_number(amount) and int(amount) > 0:
                     amount = int(amount)
                     itemname = ''
                     i = 0
                     j = len(splititem) - 2
                     for text in splititem:
                         if i < j:
                             itemname += text + ' '
                         elif i == j:
                             itemname += text
                         i += 1
                 else:
                     amount = 1
                 sold = False
                 num = 0
                 for item in player.inventory:
                     if item.name == itemname:
                         num += 1
                 if itemname not in ITEM:
                     await idchat(player.id,
                                  "'%s' does not exist!" % itemname)
                 elif num >= amount:
                     item = ITEM[itemname]
                     player.money += floor(item.price * amount / 2)
                     await idchat(
                         player.id, "You sold %s x%s for %s ides!" %
                         (bold(itemname), amount,
                          floor(item.price * amount / 2)))
                     num = amount
                     while num > 0:
                         player.inventory.remove(item)
                         num -= 1
                     sold = True
                     await player.save()
                 elif itemname in [
                         player.weapon.name, player.shield.name,
                         player.armor.name, player.charm.name
                 ]:
                     await idchat(
                         player.id,
                         "You can't sell something you have equipped!")
                 elif sold is False:
                     await idchat(
                         player.id, "You do not have %s x%s" %
                         (bold(itemname), amount))
                 player.lastmessage = ''
             elif player.lastmessage == "-list all":
                 text_to_send = ''
                 imageCategories = []
                 for listname in [
                         'weapons', 'shields', 'armor', 'charms', 'items'
                 ]:
                     shopdict = {}
                     imageList = []
                     typestring = listname.capitalize()
                     for item in self.shopitem:
                         if item in ITEM and ITEM[item].typeof == typestring:
                             shopdict[item] = ITEM[item].price
                             imageList.append(ITEM[item].getImage())
                     liststring = typestring + '\n'
                     for item in shopdict:
                         liststring += ('  %s: %s\n' %
                                        (item, shopdict[item]))
                     text_to_send += liststring
                     imageCategories.append(imageList)
                 image_editor.createShop(imageCategories, player.id)
                 await idchat(player.id, blockify(text_to_send),
                              ['temp_shop_%s.jpg' % player.id])
                 os.remove('temp_shop_%s.jpg' % player.id)
                 player.lastmessage = ''
             elif player.lastmessage[:6] == "-list ":
                 listname = player.lastmessage[6:].lower()
                 shopdict = {}
                 imageList = []
                 if listname in [
                         'weapons', 'shields', 'armor', 'charms', 'items'
                 ]:
                     typestring = listname.capitalize()
                     for item in self.shopitem:
                         if item in ITEM and ITEM[item].typeof == typestring:
                             shopdict[item] = ITEM[item].price
                             imageList.append(ITEM[item].getImage())
                     liststring = ''
                     for item in shopdict:
                         liststring += ('%s: %s\n' % (item, shopdict[item]))
                     image_editor.createShop([imageList], player.id)
                     await idchat(player.id, blockify(liststring),
                                  ['temp_shop_%s.jpg' % player.id])
                     os.remove('temp_shop_%s.jpg' % player.id)
                 else:
                     await idchat(player.id, "That list does not exist!")
                 player.lastmessage = ''
             elif player.lastmessage == "-rumors":
                 await idchat(player.id,
                              "%s" % (self.shoprumor[rumorcount]))
                 if rumorcount < len(self.shoprumor) - 1:
                     rumorcount += 1
                 player.lastmessage = ''
             elif player.lastmessage == '-leave':
                 if buysomething is False:
                     await idchat(player.id, "%s" % (self.shopclosingnobuy))
                 elif buysomething is True:
                     await idchat(player.id, "%s" % (self.shopclosingbuy))
                 break
         player.state = State.NORMAL
Exemple #9
0
 async def training(self, player):
     if self.hastrainer is False:
         await idchat(player.id,
                      "There is no trainer in %s!" % (bold(self.name)))
     elif player.state == State.SHOPPING:
         await idchat(player.id, "You can't train while shopping!")
     elif player.state == State.ENCOUNTER:
         await idchat(player.id, "You can't train during an encounter!")
     elif player.state == State.TRAINING:
         await idchat(player.id, "You are already training!")
     else:
         player.state = State.TRAINING
         await idchat(
             player.id,
             "%s\nYou have %s Potential! What would you like to do? (-commands)"
             % (self.traineropening, player.potential))
         player.lastmessage = ''
         rumorcount = 0
         while True:
             await asyncio.sleep(1)
             if player.lastmessage == "-commands" or player.lastmessage == "-cmds":
                 await idchat(
                     player.id,
                     blockify(
                         createCommandsBlock(
                             ['Training', 'Inventory', 'Other', 'Debug'])))
                 player.lastmessage = ''
             elif player.lastmessage[:7] == "-train ":
                 if player.lastmessage[7:].find(' ') != -1:
                     cmd = player.lastmessage[7:].split(' ')
                     attribute = cmd[0]
                     value = cmd[1]
                     attribute = attribute.lower()
                     if is_number(value) is True and int(value) > 0:
                         value = int(value)
                         if attribute in [
                                 'vigor', 'power', 'finesse', 'guard',
                                 'will', 'magic', 'luck', 'speed'
                         ] and value <= player.potential:
                             if attribute == 'vigor':
                                 player.vigor += value
                                 player.maxlife += (value * 4)
                                 player.life += (value * 4)
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Vigor and %s Life!" %
                                     (value, (value * 4)))
                             elif attribute == 'power':
                                 player.power += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Power!" % (value))
                             elif attribute == 'finesse':
                                 player.finesse += value
                                 player.maxfocus += value
                                 player.focus += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Finesse and %s Focus!" %
                                     (value, value))
                             elif attribute == 'guard':
                                 player.guard += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Guard!" % (value))
                             elif attribute == 'will':
                                 player.will += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Will!" % (value))
                             elif attribute == 'speed':
                                 player.speed += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Speed!" % (value))
                             elif attribute == 'magic':
                                 player.magic += value
                                 player.maxmana += value
                                 player.mana += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Magic and %s Mana!" %
                                     (value, value))
                             elif attribute == 'luck':
                                 player.luck += value
                                 player.respecpoints += value
                                 player.potential -= value
                                 await idchat(
                                     player.id,
                                     "You gained %s Luck!" % (value))
                             await idchat(
                                 player.id,
                                 "You have %s Potential remaining!" %
                                 (player.potential))
                         elif value > player.potential:
                             await idchat(
                                 player.id,
                                 "You don't have enough potential for that!"
                             )
                         else:
                             await idchat(
                                 player.id,
                                 "You need to input an attribute and a number of points greater than zero (example: -train power 3 )!"
                             )
                     else:
                         await idchat(
                             player.id,
                             "You need to input an attribute and a number of points greater than zero (example: -train power 3 )!"
                         )
                 else:
                     await idchat(
                         player.id,
                         "You need to input an attribute and a number of points greater than zero (example: -train power 3 )!"
                     )
                 player.lastmessage = ''
                 await player.save()
             elif player.lastmessage[:7] == "-learn ":
                 if self.name == 'Prison of Hope':
                     await idchat(
                         player.id,
                         "I am afraid my frailty prevents me from teaching you some of my greater techniques."
                     )
                 else:
                     itemname = smartCapitalize(player.lastmessage[7:])
                     if itemname not in TECH:
                         await idchat(player.id,
                                      "%s is not a spell nor skill.")
                     else:
                         itemfound = False
                         for item in self.traineritem:
                             if item == itemname:
                                 if item not in player.skills and item not in player.spells:
                                     if (TECH[itemname].prereq
                                             in player.skills
                                             or TECH[itemname].prereq
                                             in player.skills
                                         ) or TECH[itemname].prereq is None:
                                         if player.potential >= TECH[
                                                 itemname].potentialcost:
                                             player.potential -= TECH[
                                                 itemname].potentialcost
                                             player.respecpoints += TECH[
                                                 itemname].potentialcost
                                             if TECH[itemname].type == 'Spell':
                                                 player.spells.append(
                                                     TECH[itemname])
                                             else:
                                                 player.skills.append(
                                                     TECH[itemname])
                                             await idchat(
                                                 player.id,
                                                 "You learned %s for %s Potential!"
                                                 % (bold(itemname),
                                                    TECH[itemname].
                                                    potentialcost))
                                             await player.save()
                                             await idchat(
                                                 player.id,
                                                 "You have %s Potential left!"
                                                 % (player.potential))
                                         else:
                                             await idchat(
                                                 player.id,
                                                 "You don't have enough Potential!"
                                             )
                                     else:
                                         await idchat(
                                             player.id,
                                             "You need to learn %s before I can teach you %s."
                                             % (bold(TECH[itemname].prereq),
                                                bold(itemname)))
                                 else:
                                     await idchat(
                                         player.id,
                                         "I can't teach you what you already know!"
                                     )
                                 itemfound = True
                                 break
                         if itemfound is False:
                             await idchat(
                                 player.id,
                                 "Sorry, I can't teach %s to you." %
                                 (bold(itemname)))
                 player.lastmessage = ''
             elif player.lastmessage[:6] == "-list ":
                 if self.name == 'Prison of Hope':
                     await idchat(
                         player.id,
                         "I am afraid my frailty prevents me from teaching you some of my greater techniques."
                     )
                 elif player.lastmessage == "-list all":
                     text_to_send = ''
                     for listname in ['spells', 'skills']:
                         trainerdict = {}
                         typestring = listname.capitalize()
                         for item in self.traineritem:
                             if item in TECH and TECH[
                                     item].typeof == typestring:
                                 trainerdict[item] = TECH[
                                     item].potentialcost
                         liststring = typestring + '\n'
                         for item in trainerdict:
                             liststring += ('  %s: %s\n' %
                                            (item, trainerdict[item]))
                         text_to_send += liststring
                     await idchat(player.id, blockify(text_to_send))
                     player.lastmessage = ''
                 else:
                     listname = player.lastmessage[6:].lower()
                     trainerdict = {}
                     if listname in ['spells', 'skills']:
                         typestring = listname.capitalize()
                         for item in self.traineritem:
                             if item in TECH and TECH[
                                     item].typeof == typestring:
                                 trainerdict[item] = TECH[
                                     item].potentialcost
                         liststring = ''
                         for item in trainerdict:
                             liststring += ('%s: %s\n' %
                                            (item, trainerdict[item]))
                         await idchat(player.id, blockify(liststring))
                     else:
                         await idchat(
                             player.id,
                             "That list does not exist!" % (liststring))
                 player.lastmessage = ''
             elif player.lastmessage == "-rumors":
                 await idchat(player.id,
                              "%s" % (self.trainerrumor[rumorcount]))
                 if rumorcount < len(self.trainerrumor) - 1:
                     rumorcount += 1
                 player.lastmessage = ''
             elif player.lastmessage == "-respec":
                 await idchat(
                     player.id,
                     "Are you sure you wish to return all your potential? You will have to relearn all your spells and skills as well as retrain all of your attributes. Also, it's not cheap at 2500 ides (-accept|-decline)."
                 )
                 while True:
                     await asyncio.sleep(1)
                     if player.lastmessage == '-accept' and player.money >= 2500:
                         player.potential = player.potential + player.respecpoints
                         player.respecpoints = 0
                         player.maxlife = 40 + (player.level - 1) * 10
                         player.life = 40 + (player.level - 1) * 10
                         player.maxmana = 10
                         player.mana = 10
                         player.maxfocus = 10
                         player.focus = 10
                         player.vigor = 10
                         player.power = 10
                         player.finesse = 10
                         player.will = 10
                         player.guard = 10
                         player.magic = 10
                         player.speed = 10
                         player.luck = 10
                         player.skills = []
                         player.spells = []
                         await player.clearStatChanges()
                         player.money -= 2500
                         await player.save()
                         await idchat(
                             player.id,
                             "Your mind and body feel the same now as when you first picked up your sword and decided to carve your own fate. A world of potential is laid before you. (Don't forget to spend your points!)"
                         )
                         break
                     elif player.lastmessage == '-accept':
                         await idchat(
                             player.id,
                             "You cannot afford this special training.")
                         break
                     elif player.lastmessage == '-decline':
                         await idchat(player.id,
                                      "Ahh, maybe another time then.")
                         break
                 player.lastmessage = ''
             elif player.lastmessage == '-leave':
                 await idchat(player.id, "%s" % (self.trainerclosing))
                 break
         player.state = State.NORMAL
Exemple #10
0
 async def handleCharacterCommand(self, RPGTestMode):
     if self.lastmessage[:9] == '-examine ':
         item = smartCapitalize(self.lastmessage[9:])
         await self.examineItem(item, PLAYER)
     elif self.lastmessage[:5] == '-use ' and self.state != State.ENCOUNTER:
         item = smartCapitalize(self.lastmessage[5:])
         await self.useItem(item)
     elif self.lastmessage == '-shop':
         await self.location.shopping(self)
     elif self.lastmessage == '-trainer':
         await self.location.training(self)
     elif self.lastmessage == '-travel':
         await self.displayTravel()
     elif self.lastmessage == '-location' or self.lastmessage == '-loc':
         await idchat(self.id, ("You are at %s!" % (bold(PLAYER[self.name].location.name))))
     elif self.lastmessage == '-commands all' or self.lastmessage == '-cmds all':
         await allCommands(self.id)
     elif self.lastmessage == '-commands' or self.lastmessage == '-cmds':
         if self.state == State.ENCOUNTER:
             await idchat(self.id, blockify(createCommandsBlock(['Battle', 'Inventory', 'Other', 'Debug'])))
         elif self.state != State.SHOPPING and self.state != State.TRAINING and self.state != State.ENCOUNTER:
             await idchat(self.id, blockify(createCommandsBlock(['Inventory', 'Travel', 'Instance', 'Other', 'Debug'])))
     elif self.lastmessage[:8] == '-travel ':
         if self.state == State.NORMAL:
             location = smartCapitalize(self.lastmessage[8:])
             if location in PLAYER[self.name].allowedlocations and location != PLAYER[self.name].location:
                 await self.travel(location)
             elif location == PLAYER[self.name].location:
                 await idchat(self.id, ("You are already at %s!" % (bold(location))))
             else:
                 await idchat(self.id, ("You don't know how to get to %s!" % (bold(location))))
         elif PLAYER[self.name].state == State.SHOPPING:
             await idchat(self.id, ("You can't travel while in the shop!"))
         elif PLAYER[self.name].state == State.TRAINING:
             await idchat(self.id, ("You can't travel while training!"))
         else:
             await idchat(self.id, ("You can't travel during an encounter!"))
     elif self.lastmessage == '-surroundings' or self.lastmessage == '-look':
         await idchat(self.id, "%s" % (self.location.surroundings))
     elif self.lastmessage == '-stats':
         await self.displayStats()
     elif self.lastmessage == '-inv' or self.lastmessage == '-inventory':
         await self.displayInventory()
     elif self.lastmessage[:9] == '-discard ':
         itemname = smartCapitalize(self.lastmessage[9:])
         await self.discarditem(itemname)
     elif self.lastmessage[:7] == '-equip ':
         itemname = smartCapitalize(self.lastmessage[7:])
         await self.equipitem(itemname)
     elif self.lastmessage == '-encounter' or self.lastmessage == '-enc':
         if self.location.name in hostilelocationlist:
             if self.state == State.SHOPPING:
                 await idchat(self.id, ("You are busy shopping!"))
             elif self.state == State.TRAINING:
                 await idchat(self.id, ("You are busy training!"))
             else:
                 enc = Encounter.Encounter()
                 await enc.setup([self], EncType.NORMAL)
         else:
             await idchat(self.id, ("You can't get in encounters in %s!" % bold(self.location.name)))
     elif self.lastmessage == '-encounter boss' or self.lastmessage == '-enc boss':
         if self.location.name in hostilelocationlist:
             if self.state == State.SHOPPING:
                 await idchat(self.id, ("You are busy shopping!"))
             elif self.state == State.TRAINING:
                 await idchat(self.id, ("You are busy training!"))
             else:
                 enc = Encounter.Encounter()
                 await enc.setup([self], EncType.BOSS)
         else:
             await idchat(self.id, ("You can't get in encounters in %s!" % bold(self.location.name)))
     elif self.lastmessage[:7] == '-meditate ' or self.lastmessage[:13] == '-concentrate ' or self.lastmessage[:5] == '-med ' or self.lastmessage[:5] == '-con ':
         cmd = self.lastmessage.split(' ')
         command = cmd[0]
         amount = cmd[1]
         await self.meditateconcentrate(command, amount)
     elif self.lastmessage == '-imstuck':
         for encounter in ENCOUNTERS:
             if self in encounter.players:
                 await encounter.end()
         self.state = State.NORMAL
         await idchat(self.id, "Pulled you out of combat/shop/trainer! Careful with this command as it could break things!")
     self.lastmessage == ''
Exemple #11
0
 async def displayStats(self):
     await self.clearStatChanges()
     await idchat(self.id, blockify("     Name: %s\n\n    Level: %s\n      EXP: %s/%s\nPotential: %s\n" % (self.name, self.level, self.exp, self.level * self.level, self.potential) +
                                    "\n     Life: %s/%s\n     Mana: %s/%s\n    Focus: %s/%s\n" % (self.life, self.get('maxlife'), self.mana, self.get('maxmana'), self.focus, self.get('maxfocus')) +
                                    "\n    Vigor: %s\n    Power: %s\n  Finesse: %s\n     Will: %s\n" % (self.vigor, self.get('power'), self.get('finesse'), self.get('will')) +
                                    "    Guard: %s\n    Speed: %s\n     Luck: %s\n" % (self.get('guard'), self.get('speed'), self.get('luck'))))
Exemple #12
0
 async def displayInventory(self):
     stacks = {}
     for item in self.inventory:
         if item.name not in stacks:
             stacks[item.name] = 1
         else:
             stacks[item.name] += 1
     sortedstacks = sorted(stacks.items(), key=operator.itemgetter(1), reverse=True)
     stringofitems = ''
     if len(sortedstacks) == 0:
         stringofitems = 'Nothing...'
     else:
         if len(sortedstacks) < 3:
             item, number = sortedstacks[0]
             if number == 1:
                 stringofitems = '%s' % item
             else:
                 stringofitems = '%s x%s' % (item, number)
         else:
             item, number = sortedstacks[0]
             if number == 1:
                 stringofitems = '%s,' % item
             else:
                 stringofitems = '%s x%s,' % (item, number)
         if len(sortedstacks) >= 2:
             for itempair in sortedstacks[1:len(stacks) - 1]:
                 item, number = itempair
                 if number == 1:
                     stringofitems += (' %s,' % item)
                 else:
                     stringofitems += (' %s x%s,' % (item, number))
         if len(sortedstacks) == 1:
             pass
         else:
             item, number = sortedstacks[len(stacks) - 1]
             if number == 1:
                 stringofitems += ' and %s' % item
             else:
                 stringofitems += ' and %s x%s' % (item, number)
     imageList = []
     equipList = []
     for item in sortedstacks:
         num = item[1]
         while num > 0:
             imageList.append(ITEM[item[0]].getImage())
             num -= 1
     equipList.append(self.weapon.getImage())
     equipList.append(self.shield.getImage())
     equipList.append(self.armor.getImage())
     equipList.append(self.charm.getImage())
     image = image_editor.createInventory(equipList, imageList, self.id)
     if image is not None:
         if self.weapon is None or self.weapon.is2handed is False:
             await idchat(self.id, blockify("Weapon: %s\nShield: %s\n Armor: %s\n Charm: %s\n\n" % (self.weapon.name, self.shield.name, self.armor.name, self.charm.name) +
                                            "Inventory %s/%s : %s\n" % (len(self.inventory), self.inventorymax, stringofitems) +
                                            "Ides: %s" % (self.money)), ['temp_inv_%s.jpg' % self.id])
         else:
             await idchat(self.id, blockify("Weapon: %s\nShield: %s (Inactive)\nArmor: %s\nCharm: %s\n\n" % (self.weapon.name, self.shield.name, self.armor.name, self.charm.name) +
                                            "Inventory %s/%s : %s\n" % (len(self.inventory), self.inventorymax, stringofitems) +
                                            "Ides: %s" % (self.money)), ['temp_inv_%s.jpg' % self.id])
     else:
         if self.weapon is None or self.weapon.is2handed is False:
             await idchat(self.id, blockify("Weapon: %s\nShield: %s\n Armor: %s\n Charm: %s\n\n" % (self.weapon.name, self.shield.name, self.armor.name, self.charm.name) +
                                            "Inventory %s/%s : %s\n" % (len(self.inventory), self.inventorymax, stringofitems) +
                                            "Ides: %s" % (self.money)))
         else:
             await idchat(self.id, blockify("Weapon: %s\nShield: %s (Inactive)\nArmor: %s\nCharm: %s\n\n" % (self.weapon.name, self.shield.name, self.armor.name, self.charm.name) +
                                            "Inventory %s/%s : %s\n" % (len(self.inventory), self.inventorymax, stringofitems) +
                                            "Ides: %s" % (self.money)))
     os.remove('temp_inv_%s.jpg' % self.id)