def gen(self, lev): """Generate the monster based on dungeon level.""" if lev < 2: lvl = random.choice([lev]*4 + [lev+1]) else: lvl = random.choice([lev-1] + [lev]*3 + [lev+1]) if lvl >= 10: #if we're at level 10, face Dragons! self.dragongen(lvl) else: with open('data/pq_bestiary.json') as f: pq_monsters = json.load(f) self.level = [lvl, lvl] self.name = random.choice(pq_monsters[str(lvl)].keys()) this_monster = pq_monsters[str(lvl)][self.name] for i in range(0, 6): stat_roll = random.choice([random.randint(1, 6) \ for j in range(0, 6)]) self.stats[i] = stat_roll + this_monster['stat'][i] self.skill = this_monster['skill'] for i in range(0, lvl): hpi = random.choice([random.randint(max([1, \ self.stats[3] / 2]), self.stats[3]) for j in range(0, 6)]) self.hitpoints = [x + hpi for x in self.hitpoints] spi = random.choice([random.randint(1, self.stats[5]) \ for j in range(0, 6)]) + 2 * (lvl - 1) self.skillpoints = [spi, spi] self.treasure = pq_treasuregen(lvl) self.combat['atk'] = [0, self.stats[0]] self.combat['dfn'] = [0, self.stats[1]] self.flee = this_monster.get("flee",True)
def addshopitem(self): """Add an item to the shop. Currently, this algorithm makes the shop suck.""" shop_items = pq_treasuregen(self.questlevel) for i in shop_items.keys(): if shop_items[i] and i != "gp" and shop_items[i] not in self.store: self.store.append(shop_items[i])
def gen(self, lvl): """Generate the monster based on dungeon level.""" if lvl >= 10: #if we're at level 10, face Dragons! self.dragongen(lvl) else: with open('data/pq_bestiary.json') as f: pq_monsters = json.load(f) self.level = [lvl, lvl] self.name = random.choice(pq_monsters[str(lvl)].keys()) this_monster = pq_monsters[str(lvl)][self.name] for i in range(0, 6): stat_roll = random.choice([random.randint(1, 6) \ for j in range(0, 6)]) self.stats[i] = stat_roll + this_monster['stat'][i] self.skill = this_monster['skill'] for i in range(0, lvl): hpi = random.choice([random.randint(max([1, \ self.stats[3] / 2]), self.stats[3]) for j in range(0, 6)]) self.hitpoints = [x + hpi for x in self.hitpoints] spi = random.choice([random.randint(1, self.stats[5]) \ for j in range(0, 6)]) + 2 * (lvl - 1) self.skillpoints = [spi, spi] self.treasure = pq_treasuregen(lvl) self.combat['atk'] = [0, self.stats[0]] self.combat['dfn'] = [0, self.stats[1]] self.flee = this_monster.get("flee", True)
def __init__(self, lvl, character): """Initialize puzzle encounter based on dungeon level.""" riddle = riddlegen() self.char = character self.answer = riddle[0] self.riddle = riddle[1] self.riddleguess = 3 riches = [] while not riches: treasure = pq_treasuregen(lvl + 2) for t in treasure.keys(): if t == 'gp': continue if treasure[t]: riches.append(treasure[t]) self.riches = random.choice(riches) self.numcode = numgen() self.numguess = 10 self.gold = sum([random.randint(1, 100) for i in range(lvl)]) self.damage = 0 self.trial_num = lvl self.knowledge = lvl / 2 self.thing = random.choice(['mysterious dark spirit', 'regal sphinx', \ 'magic mirror', 'blind oracle']) self.choice = "" self.finished = False
def addshopitem(self): """Add an item to the shop. Currently, this algorithm makes the shop suck.""" shop_items = pq_treasuregen(self.questlevel) for i in shop_items.keys(): if shop_items[i] and i != 'gp' and shop_items[i] not in self.store: self.store.append(shop_items[i])
def dragongen(self, lvl): """Generate a random dragon based on dungeon level, for level 10+ """ self.level = [lvl, lvl] color = random.choice([random.choice(pq_dragonskill.keys()) for i in range(0, 6)]) self.name = dragon_namegen(2, 6)[0] + " the " + color + " Dragon" for i in range(0, 6): statroll = random.choice([random.randint(1, 6) for j in range(0, 6)]) self.stats[i] = statroll + lvl - 5 self.skill = pq_dragonskill[color] for i in range(0, lvl): hpi = random.choice([random.randint(max([1, self.stats[3] / 2]), self.stats[3]) for j in range(0, 6)]) self.hitpoints = [x + hpi for x in self.hitpoints] spi = random.choice([random.randint(1, self.stats[5]) for j in range(0, 6)]) + 2 * (lvl - 1) self.skillpoints = [spi, spi] self.treasure = pq_treasuregen(lvl) self.combat["atk"] = [lvl / 3, self.stats[0]] self.combat["dfn"] = [lvl / 3, self.stats[1]] self.flee = False
def dragongen(self, lvl): """Generate a random dragon based on dungeon level, for level 10+ """ self.level = [lvl, lvl] color = random.choice([random.choice(pq_dragonskill.keys()) \ for i in range(0, 6)]) self.name = dragon_namegen(2, 6) + ' the ' + color + ' Dragon' for i in range(0, 6): statroll = random.choice([random.randint(1, 6) for j in range(0, 6)]) self.stats[i] = statroll + lvl - 5 self.skill = pq_dragonskill[color] for i in range(0, lvl): hpi = random.choice([random.randint(max([1, int(self.stats[3] / 2)]), self.stats[3]) for j in range(0, 6)]) self.hitpoints = [x + hpi for x in self.hitpoints] spi = random.choice([random.randint(1, int(self.stats[5])) for j in range(0, 6)]) + 2 * (lvl - 1) self.skillpoints = [spi, spi] self.treasure = pq_treasuregen(lvl) self.combat['atk'] = [lvl / 3, self.stats[0]] self.combat['dfn'] = [lvl / 3, self.stats[1]] self.flee = False
def explore(self): """Explore the dungeon!""" room = random.choice([random.randint(1, 20) for i in range(6)]) self.whereareyou = "dungeon" if room <= 2: print "You find a flight of stairs, leading down! " "Go down, or Stay?" choice = choose_from_list( "Stairs> ", ["down", "go down", "stay"], rand=False, character=self.character, allowed=["sheet", "help", "equip"], ) if choice != "stay": self.godownstairs() else: print "You decide to stick around on level " + str(self.dungeonlevel) + " a little while longer." return elif room > 2 and room <= 5: msg = "You found a chest! " chest = pq_treasuregen(self.dungeonlevel) self.character.defeat_enemy(0, chest) loot = [] for i in chest.keys(): if chest[i]: if i == "gp": loot.append(str(chest[i]) + " gp") elif i == "ring": loot.append("a Ring of " + chest[i]) else: loot.append("a " + chest[i]) if not loot: msg += "Sadly, it was empty." else: msg += "Inside, you find " + ", ".join(loot) + "." print msg return elif room > 5 and room <= 8: msg = ( "The room echoes with a hollow emptiness, and you " "reflect on the vagaries of living life alone... Then " "you eat" + sandgen() + ", and get ready to kill more things." ) print textwrap.fill(msg), "\nYou regain " + str(self.dungeonlevel) + " hp and sp!" self.character.sammich(self.dungeonlevel) return elif room > 8 and room <= 10: self.whereareyou = "puzzle" self.puzzle = PQ_Puzzle(self.dungeonlevel, self.character) self.puzzle.puzzleinit() elif room > 10: msg = "You've stumbled on an enemy! It seems to be... " questcheck = self.maxdungeonlevel - self.questlevel cutoff = float(1 + questcheck) / float(10 + 2 * questcheck) if ( self.dungeonlevel == self.questlevel and self.quest and self.character.queststatus == "active" and random.random() < cutoff ): self.combat = PQ_Combat(self.dungeonlevel, self.character, self.quest) msg += self.quest.name + "!" else: self.combat = PQ_Combat(self.dungeonlevel, self.character, None) if self.dungeonlevel >= 10: msg += self.combat.enemy.name + "!" else: msg += "a " + self.combat.enemy.name + "!" if self.combat.turnorder[0] == "player": msg += " You get the jump on it." else: msg += " It gets the jump on you." print msg self.whereareyou = "combat" self.combat.advance_turn() self.combat = None
def explore(self): """Explore the dungeon!""" room = random.choice([random.randint(1, 20) for i in range(6)]) self.whereareyou = "dungeon" if room <= 2: send_to_console("You find a flight of stairs, leading down! " \ +color.BOLD+"Go down, or Stay?"+color.END) choice = choose_from_list("Stairs> ", \ ["down", "go down", "stay"], rand=False, \ character=self.character, allowed=['sheet', 'help', 'equip']) if choice != "stay": self.godownstairs() else: send_to_console("You decide to stick around on level " + \ str(self.dungeonlevel) + " a little while longer.") return elif room > 2 and room <= 5: msg = color.BOLD + "You found a chest! " + color.END chest = pq_treasuregen(self.dungeonlevel) self.character.defeat_enemy(0, chest) loot = [] for i in chest.keys(): if chest[i]: if i == 'gp': loot.append(str(chest[i]) + " gp") elif i == 'ring': loot.append("a Ring of " + chest[i]) else: loot.append("a " + chest[i]) if not loot: msg += "Sadly, it was empty." else: msg += "Inside, you find " + color.BOLD + ", ".join( loot) + "." + color.END send_to_console(msg) return elif room > 5 and room <= 8: msg = "The room echoes with a hollow emptiness, and you " \ "reflect on the vagaries of living life alone... Then " \ "you eat" + sandgen() + ", and get ready to kill more things." send_to_console(textwrap.fill(msg), "\nYou regain " + \ str(self.dungeonlevel) + " hp and sp!") self.character.sammich(self.dungeonlevel) return elif room > 8 and room <= 10: self.whereareyou = "puzzle" self.puzzle = PQ_Puzzle(self.dungeonlevel, self.character) self.puzzle.puzzleinit() #elif room > 10 and room <= 12: # self.whereareyou = "trap" # #elif room > 12: elif room > 10: msg = "You've stumbled on an enemy! It seems to be... " questcheck = self.maxdungeonlevel - self.questlevel cutoff = float(1 + questcheck) / float(10 + 2 * questcheck) if self.dungeonlevel == self.questlevel and self.quest and \ self.character.queststatus == "active" and random.random() \ < cutoff: self.combat = PQ_Combat(self.dungeonlevel, self.character, \ self.quest) msg += color.BOLD + self.quest.name + color.END + '!' else: self.combat = PQ_Combat(self.dungeonlevel, \ self.character, None) if self.dungeonlevel >= 10: msg += color.RED + self.combat.enemy.name + color.END + '!' else: msg += 'a ' + color.BOLD + self.combat.enemy.name + color.END + '!' if self.combat.turnorder[0] == 'player': msg += ' You get the jump on it.' else: msg += ' It gets the jump on you.' send_to_console(msg) self.whereareyou = "combat" self.combat.advance_turn() self.combat = None
def addshopitem(self): """Add an item to the shop.""" shop_items = pq_treasuregen(self.character.level[1]) for i in shop_items.keys(): if shop_items[i] and i != 'gp' and shop_items[i] not in self.store: self.store.append(shop_items[i])