def checkItems(): items = [] for item in ITEM: image = 'RPGFiles/Art/Icons/Item/%s.png' % smartCapitalize(item) if not isfile(image): items.append(item) return items
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
def getImage(self): image = 'RPGFiles/Art/Location/%s.png' % smartCapitalize(self.name) if os.path.isfile(image): return image else: return 'RPGFiles/Art/Location/NOPIC.png'
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
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
def getImage(self): image = 'RPGFiles/Art/Icons/Tech/%s.png' % smartCapitalize(self.name) if isfile(image): return image else: return 'RPGFiles/Art/Icons/NOPIC.png'
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 == ''