Beispiel #1
0
 def chargen(self, player):
     """
     Generate a new character using (possibly random) race, class, 
     and feat choices.
     """
     send_to_console(textwrap.fill("It's time to generate a character! At any " \
         "of the prompts below, enter 'random' (no quotes) to use " \
         "a random choice."))
     send_to_console("Available races: " +
                     ", ".join(sorted(pq_races.keys())))
     race = choose_from_list("Race> ", pq_races.keys(), rand=True, \
         character=self, allowed=['sheet', 'help'])
     send_to_console("Available classes: " +
                     ", ".join(sorted(pq_classes.keys())))
     clas = choose_from_list("Class> ", pq_classes.keys(), rand=True, \
         character=self, allowed=['sheet', 'help'])
     nfeat = 2 if race.lower() == "human" else 1
     send_to_console("Available feats: " +
                     ", ".join(sorted(pq_feats.keys())))
     feats = []
     for i in range(nfeat):
         feat = choose_from_list("Feat> ", pq_feats.keys(), rand=True, \
             character=self, allowed=['sheet', 'help'])
         feats.append(feat)
     self.chargenerate(race, clas, feats, player)
     self.tellchar()
 def chargen(self, player):
     """
     Generate a new character using (possibly random) race, class, 
     and feat choices.
     """
     import json
     print textwrap.fill("It's time to generate a character! At any " \
         "of the prompts below, enter 'random' (no quotes) to use " \
         "a random choice.")
     self.name = [color.GREEN + web_namegen(5, 12, 2).replace('\n', ' ') \
         + color.END, player]
     self.level = [0, 1]
     with open('data/pq_classes.json') as f:
         pq_classes = json.load(f)
     with open('data/pq_races.json') as f:
         pq_races = json.load(f)
     print "Available races: " + ", ".join(sorted(pq_races.keys()))
     race = choose_from_list("Race> ", pq_races.keys(), rand=True, \
         character=self, allowed=['sheet', 'help'])
     print "Available classes: " + ", ".join(sorted(pq_classes.keys()))
     clas = choose_from_list("Class> ", pq_classes.keys(), rand=True, \
         character=self, allowed=['sheet', 'help'])
     nfeat = 2 if race.lower() == "human" else 1
     print "Available feats: " + ", ".join(sorted(pq_feats.keys()))
     feats = []
     for i in range(nfeat):
         feat = choose_from_list("Feat> ", pq_feats.keys(), rand=True, \
             character=self, allowed=['sheet', 'help'])
         feats.append(feat)
     self.raceclass = [race, clas]
     self.loot["gp"] = 0
     for i in range(0, 6):
         statroll = random.choice([random.randint(1, 4) \
             for j in range(0, 6)])
         self.stats[i] = statroll + \
             pq_classes[self.raceclass[1]]['stat'][i] + \
             pq_races[self.raceclass[0]]['stat'][i]
     self.feats = feats
     for i in feats:
         for j in pq_feats.keys():
             if i.lower() == 'improvedinitiative': 
                 self.combat['initiative'] += 2
             elif i.lower() == j.lower():
                 self.stats[pq_feats[j]] += 2
                 break
     self.hitpoints = [self.stats[3], self.stats[3]]
     self.skillpoints = [self.stats[5], self.stats[5]]
     self.gear['armor']['name'] = pq_gear['rarmor'][random.choice \
         (pq_gear['rarmor'].keys())]['0']
     self.gear['armor']['rating'] = 0
     self.gear['weapon']['name'] = pq_gear['rweapon'][random.choice \
         (pq_gear['rweapon'].keys())]['0']
     self.gear['weapon']['rating'] = 0
     self.gear['ring'] = ''
     self.combat['atk'] = [self.gear['weapon']['rating'], self.stats[0]]
     self.combat['dfn'] = [self.gear['armor']['rating'], self.stats[1]]
     self.skill = []
     self.skill.append(pq_classes[self.raceclass[1]]['skill'])
     self.tellchar()
def deadchar(rpg):
    """Deal with character death"""
    print "What would you like to do? Options: "\
        "Generate (a new character), Load, Quit"
    dothis = choose_from_list("Dead> ", ["Generate", "Load", "Quit"],
                              character=rpg.character,
                              rand=False,
                              allowed=["sheet", "help"])
    if dothis == "Quit":
        confirm_quit()
        deadchar(rpg)
        return
    if dothis == "Load":
        rpg = load(rpg)
        if not rpg:
            print "I'm sorry, that didn't work... maybe you deleted " \
                "the save file? Anyway..."
            deadchar(rpg)
            return
        else:
            print "Game successfully loaded!"
            print "You begin in the town square."
            rpg.character.tellchar()
            rpg.destination("town")
            town(rpg)
            return
    if dothis == "Generate":
        rpg = generate(rpg)
        print "You begin in the town square."
        town(rpg)
        return
 def levelup(self):
     """Increasing level, including the feat choice 
     that you get every level."""
     self.level[0] -= self.level[1] * 10
     self.level[1] += 1
     print "You have leveled up! Please choose a feat; if you would like " \
         "one randomly chosen for you, enter Random."
     print "Available feats: " + ", ".join(pq_feats.keys())
     feat_choice = choose_from_list("Feat> ", pq_feats.keys(), rand=True, \
         character=self, allowed=['sheet', 'help', 'equip'])
     if feat_choice.lower() in 'improvedinitiative':
         self.combat['initiative'] += 2
         self.feats.append('ImprovedInitiative')
     else:
         for i in pq_feats.keys():
             if i.lower() == feat_choice.lower():
                 self.stats[pq_feats[i]] += 2
                 self.feats.append(i)
     self.hitpoints[1] += random.choice([random.randint(max([1, \
         self.stats[3] / 2]), 1 + self.stats[3]) for j in range(0, 6)])
     self.skillpoints[1] += 2
     self.combat['atk'] = [self.gear['weapon']['rating'], self.stats[0]]
     self.combat['dfn'] = [self.gear['armor']['rating'], self.stats[1]]
     print "Level up complete!"
     self.tellchar()
def deadchar(rpg):
    """Deal with character death"""
    send_to_console("What would you like to do? Options: "\
        "Generate (a new character), Load, Quit")
    dothis = choose_from_list("Dead> ", ["Generate", "Load", "Quit"],
        character=rpg.character, rand=False, allowed=["sheet", "help"])
    if dothis == "Quit":
        confirm_quit()
        deadchar(rpg)
        return
    if dothis == "Load":
        rpg = load(rpg)
        if not rpg:
            send_to_console("I'm sorry, that didn't work... maybe you deleted " \
                "the save file? Anyway...")
            deadchar(rpg)
            return
        else:
            send_to_console("Game successfully loaded!")
            send_to_console("You begin in the town square.")
            rpg.character.tellchar()
            rpg.destination("town")
            town(rpg)
            return
    if dothis == "Generate":
        rpg = generate(rpg)
        send_to_console("You begin in the town square.")
        town(rpg)
        return
Beispiel #6
0
 def levelup(self):
     """Increasing level, including the feat choice 
     that you get every level."""
     self.level[0] -= self.level[1] * 10
     self.level[1] += 1
     send_to_console("You have leveled up! Please choose a feat; if you would like " \
         "one randomly chosen for you, enter Random.")
     send_to_console("Available feats: " + ", ".join(pq_feats.keys()))
     feat_choice = choose_from_list("Feat> ", pq_feats.keys(), rand=True, \
         character=self, allowed=['sheet', 'help', 'equip'])
     if feat_choice.lower() in 'improvedinitiative':
         self.combat['initiative'] += 2
         self.feats.append('ImprovedInitiative')
     else:
         for i in pq_feats.keys():
             if i.lower() == feat_choice.lower():
                 self.stats[pq_feats[i]] += 2
                 self.feats.append(i)
     self.hitpoints[1] += random.choice([random.randint(max([1, \
         self.stats[3] / 2]), 1 + self.stats[3]) for j in range(0, 6)])
     self.skillpoints[1] += 2
     self.combat['atk'] = [self.gear['weapon']['rating'], self.stats[0]]
     self.combat['dfn'] = [self.gear['armor']['rating'], self.stats[1]]
     self.rpg.addshopitem()
     send_to_console("Level up complete!")
     self.tellchar()
Beispiel #7
0
 def puzzleinit(self):
     """Begin a puzzle encounter."""
     msg1 = "Exploring the depths of the Dungeon, you encounter a " + \
         self.thing + " in a lonely room."
     if self.thing == 'magic mirror':
         msg1 += " A sinister face materializes in its murky surface, " \
             "looking directly at you."
     else:
         msg1 += " The " + self.thing + " addresses you."
     msg2 = color.BOLD + " 'Welcome to the Dungeon, adventurer. Portents " \
         "have foreshadowed your coming. I am here to aid you on your " \
         "journey, should you prove worthy. I offer you choices three: " \
         "you may play a game, for Gold; solve a riddle, for Riches;" \
         " or undergo a Trial of Being, for Knowledge. Choose your prize," \
         " and choose well.'"+color.END
     msg3 = "(Your choices are Gold, Riches, Knowledge, or Skip.)"
     send_to_console(textwrap.fill(msg1 + msg2)+'\n'+msg3)
     choice = choose_from_list("Choice> ", ["gold", "riches", "knowledge", \
         "skip"], character=self.char, allowed=['sheet', 'help', 'equip'])
     self.choice = choice
     if self.choice == "gold":
         msg = "The " + self.thing + " nods approvingly. " + color.BOLD + \
             "'You have chosen the game; here are the rules. I have " \
             "selected a set of four digits, in some order. You have 10 " \
             "chances to guess the digits, in the correct order. If you " \
             "are polite, I may be persuaded to give you a hint... Now, " \
             "begin; you have 10 chances remaining.'" + color.END
         msg2 = "(Guess should be ####)"
         send_to_console(textwrap.fill(msg)+'\n'+msg2)
         self.check_numguess()
         return
     elif self.choice == "riches":
         msg = "The " + self.thing + " nods slowly. " + color.BOLD + \
             "'You have chosen the riddle; here are the rules. I will " \
             "tell you the riddle, which has an answer one word long. " \
             "You have three chances to guess the answer. If it goes " \
             "poorly, I may decide to give you a hint. Here is the riddle: "
         msg2 = "Now, begin your guess. You have three chances remaining.'"\
             + color.END
         send_to_console(textwrap.fill(msg), '\n', textwrap.fill(self.riddle), \
             '\n', msg2)
         self.check_riddleguess()
         return
     elif self.choice == "knowledge":
         msg = "The " + self.thing+"'s face spreads in a predatory smile. "\
             + color.BOLD + "'As you wish. The Trial consists of three " \
             "tests; if you succeed at all three, you will be rewarded." \
             " The first test will begin... now.'" + color.END
         send_to_console(textwrap.fill(msg))
         self.trialofbeing()
         return
     elif self.choice == "skip":
         self.failure()
 def chargen(self, player):
     """
     Generate a new character using (possibly random) race, class, 
     and feat choices.
     """
     send_to_console(textwrap.fill("It's time to generate a character! At any " \
         "of the prompts below, enter 'random' (no quotes) to use " \
         "a random choice."))
     send_to_console("Available races: " + ", ".join(sorted(pq_races.keys())))
     race = choose_from_list("Race> ", pq_races.keys(), rand=True, \
         character=self, allowed=['sheet', 'help'])
     send_to_console("Available classes: " + ", ".join(sorted(pq_classes.keys())))
     clas = choose_from_list("Class> ", pq_classes.keys(), rand=True, \
         character=self, allowed=['sheet', 'help'])
     nfeat = 2 if race.lower() == "human" else 1
     send_to_console("Available feats: " + ", ".join(sorted(pq_feats.keys())))
     feats = []
     for i in range(nfeat):
         feat = choose_from_list("Feat> ", pq_feats.keys(), rand=True, \
             character=self, allowed=['sheet', 'help'])
         feats.append(feat)
     self.chargenerate(race, clas, feats, player)
     self.tellchar()
def dungeon(rpg):
    """Maintain interaction with the dungeon"""
    dothis = ""
    while dothis != "Leave":
        if rpg.character.dead:
            return
        actions = ["Research","Leave"] if rpg.whereareyou == "start" \
            else ["Research","Backtrack"]
        send_to_console("You're in the dank dark dungeon. What do you want to do?\n"+\
            "Options: "+color.BOLD+", ".join(actions)+color.END)
        dothis = choose_from_list("Dungeon> ",
                                  actions,
                                  rand=False,
                                  character=rpg.character,
                                  allowed=["sheet", "help", "equip"])
        if dothis == "Leave":
            if rpg.whereareyou != "start":
                send_to_console("You can't leave from here; you have to backtrack " \
                    "to the start of the level.")
                dothis = ""
                continue
            else:
                rpg.destination("town")
                send_to_console("You return back" + color.BOLD + " to town." +
                                color.END)
                continue
        elif dothis == "Backtrack":
            if rpg.whereareyou == "start":
                send_to_console(
                    "You're already at the beginning of the level.")
                continue
            if rpg.check_backtrack():
                send_to_console("You successfully find your way back " \
                    "to the beginning of the level.")
                rpg.destination("start")
                continue
            else:
                send_to_console("On your way back, you get lost! You find yourself " \
                    "in another room of the dungeon...")
                rpg.destination("dungeon")
                rpg.explore()
                continue
        elif dothis == "Research":
            rpg.destination("dungeon")
            rpg.explore()
            if rpg.character.dead:
                deadchar(rpg)
            else:
                continue
def town(rpg):
    """Maintain interactions with the town of North Granby."""
    while True:
        if rpg.character.dead:
            send_to_console(color.BOLD + "You are dead!" + color.END)
            deadchar(rpg)
            break
        send_to_console("Where would you like to go?\n"+color.BOLD+"Options: Home, " \
            "City-Hall, Bazaar, Temple, or Dungeon [Level#] (max "+ \
            str(rpg.maxdungeonlevel)+")"+color.END)
        destinations = ["Dungeon", "Home", "City-Hall", "Quest", \
            "Bazaar", "Temple"] + ["Dungeon "+str(i) for i in \
            range(1, rpg.maxdungeonlevel+1)]
        goto = choose_from_list("Town> ",
                                destinations,
                                rand=False,
                                character=rpg.character,
                                allowed=["sheet", "help", "equip"])
        if goto == "Home":
            send_to_console("You returned home," \
                +color.BOLD+" game is saved "+color.END+\
                "- you had a good nigth sleep.")
            rpg.character.sleep()
            save(rpg)
            continue
        elif goto in ["City-Hall", "Quest"]:
            send_to_console("You head to the City-Hall.")
            rpg.questhall()
            continue
        elif goto == "Bazaar":
            send_to_console("You head into the shop.")
            rpg.visit_shop()
            continue
        elif goto == "Temple":
            send_to_console("You head into the Temple.")
            rpg.visit_shrine()
            continue
        else:
            goto = goto.split()
            rpg.destination("start")
            if goto[0] == "Dungeon" and len(goto) == 1:
                rpg.dungeonlevel = 1
            else:
                rpg.dungeonlevel = int(goto[1])
            send_to_console("You head into the Dungeon, level " +
                            str(rpg.dungeonlevel) + ".")
            dungeon(rpg)
            continue
def dungeon(rpg):
    """Maintain interaction with the dungeon"""
    dothis = ""
    while dothis != "Leave":
        if rpg.character.dead:
            return
        actions = ["Explore","Leave"] if rpg.whereareyou == "start" \
            else ["Explore","Backtrack"]
        print "You're in the dank dark dungeon. What do you want to do?", \
            '\n', "Options: "+", ".join(actions)
        dothis = choose_from_list("Dungeon> ",
                                  actions,
                                  rand=False,
                                  character=rpg.character,
                                  allowed=["sheet", "help", "equip"])
        if dothis == "Leave":
            if rpg.whereareyou != "start":
                print "You can't leave from here; you have to backtrack " \
                    "to the start of the level."
                dothis = ""
                continue
            else:
                rpg.destination("town")
                print "You head back to town."
                continue
        elif dothis == "Backtrack":
            if rpg.whereareyou == "start":
                print "You're already at the beginning of the level, " \
                    "Captain Redundant."
                continue
            if rpg.check_backtrack():
                print "You successfully find your way back " \
                    "to the beginning of the level."
                rpg.destination("start")
                continue
            else:
                print "On your way back, you get lost! You find yourself " \
                    "in another room of the dungeon..."
                rpg.destination("dungeon")
                rpg.explore()
                continue
        elif dothis == "Explore":
            rpg.destination("dungeon")
            rpg.explore()
            if rpg.character.dead:
                deadchar(rpg)
            else:
                continue
def town(rpg):
    """Maintain interactions with the town of North Granby."""
    while True:
        if rpg.character.dead:
            print "You are dead!"
            deadchar(rpg)
            break
        print "Where would you like to go?\n", "Options: Home, " \
            "Questhall, Shop, Shrine, or Dungeon [Level#] (max "+ \
            str(rpg.maxdungeonlevel)+")"
        destinations = ["Dungeon", "Home", "Questhall", "Quest", \
            "Shop", "Shrine"] + ["Dungeon "+str(i) for i in \
            range(1, rpg.maxdungeonlevel+1)]
        goto = choose_from_list("Town> ",
                                destinations,
                                rand=False,
                                character=rpg.character,
                                allowed=["sheet", "help", "equip"])
        if goto == "Home":
            print "You hit the sack. Once you've annoyed all " \
                "the bedbugs with your ineffectual fists, "\
                "you lay down and sleep."
            rpg.character.sleep()
            save(rpg)
            continue
        elif goto in ["Questhall", "Quest"]:
            print "You head to the Questhall."
            rpg.questhall()
            continue
        elif goto == "Shop":
            print "You head into the shop."
            rpg.visit_shop()
            continue
        elif goto == "Shrine":
            print "You head into the Shrine."
            rpg.visit_shrine()
            continue
        else:
            goto = goto.split()
            rpg.destination("start")
            if goto[0] == "Dungeon" and len(goto) == 1:
                rpg.dungeonlevel = 1
            else:
                rpg.dungeonlevel = int(goto[1])
            print "You head into the Dungeon, level " + str(
                rpg.dungeonlevel) + "."
            dungeon(rpg)
            continue
def dungeon(rpg):
    """Maintain interaction with the dungeon"""
    dothis = ""
    while dothis != "Leave":
        if rpg.character.dead:
            return
        actions = ["Explore","Leave"] if rpg.whereareyou == "start" \
            else ["Explore","Backtrack"]
        send_to_console("You're in the dank dark dungeon. What do you want to do?\n"+\
            "Options: "+", ".join(actions))
        dothis = choose_from_list("Dungeon> ", actions, rand=False,
            character=rpg.character, allowed=["sheet","help","equip"])
        if dothis == "Leave":
            if rpg.whereareyou != "start":
                send_to_console("You can't leave from here; you have to backtrack " \
                    "to the start of the level.")
                dothis = ""
                continue
            else:
                rpg.destination("town")
                send_to_console("You head back to town.")
                continue
        elif dothis == "Backtrack":
            if rpg.whereareyou == "start":
                send_to_console("You're already at the beginning of the level, " \
                    "Captain Redundant.")
                continue
            if rpg.check_backtrack():
                send_to_console("You successfully find your way back " \
                    "to the beginning of the level.")
                rpg.destination("start")
                continue
            else:
                send_to_console("On your way back, you get lost! You find yourself " \
                    "in another room of the dungeon...")
                rpg.destination("dungeon")
                rpg.explore()
                continue
        elif dothis == "Explore":
            rpg.destination("dungeon")
            rpg.explore()
            if rpg.character.dead:
                deadchar(rpg)
            else:
                continue
def town(rpg):
    """Maintain interactions with the town of North Granby."""
    while True:
        if rpg.character.dead:
            send_to_console("You are dead!")
            deadchar(rpg)
            break
        send_to_console("Where would you like to go?\n"+"Options: Home, " \
            "Questhall, Shop, Shrine, or Dungeon [Level#] (max "+ \
            str(rpg.maxdungeonlevel)+")")
        destinations = ["Dungeon", "Home", "Questhall", "Quest", \
            "Shop", "Shrine"] + ["Dungeon "+str(i) for i in \
            range(1, rpg.maxdungeonlevel+1)]
        goto = choose_from_list("Town> ", destinations, rand=False,
            character=rpg.character, allowed=["sheet","help","equip"])
        if goto == "Home":
            send_to_console("You hit the sack. Once you've annoyed all " \
                "the bedbugs with your ineffectual fists, "\
                "you lay down and sleep.")
            rpg.character.sleep()
            save(rpg)
            continue
        elif goto in ["Questhall", "Quest"]:
            send_to_console("You head to the Questhall.")
            rpg.questhall()
            continue
        elif goto == "Shop":
            send_to_console("You head into the shop.")
            rpg.visit_shop()
            continue
        elif goto == "Shrine":
            send_to_console("You head into the Shrine.")
            rpg.visit_shrine()
            continue
        else:
            goto = goto.split()
            rpg.destination("start")
            if goto[0] == "Dungeon" and len(goto) == 1:
                rpg.dungeonlevel = 1
            else:
                rpg.dungeonlevel = int(goto[1])
            send_to_console("You head into the Dungeon, level "+str(rpg.dungeonlevel)+".")
            dungeon(rpg)
            continue
Beispiel #15
0
 def equip(self):
     """Equip an item, unequipping extant item if necessary."""
     if not self.loot['items']:
         send_to_console("You have nothing to equip!")
         return
     send_to_console("What would you like to equip?")
     lootbag = ['Ring of ' + i if i in pq_magic['ring'].keys() \
         else i for i in self.loot['items']]
     lootbag_basic = collapse_stringlist(lootbag, sortit=True, \
         addcounts=False)
     send_to_console(textwrap.fill("Lootbag: " + \
         ", ".join(collapse_stringlist(lootbag, sortit=True, \
         addcounts=True))))
     equipment = choose_from_list("Equip> ", lootbag_basic, rand=False, \
         character=self, allowed=['sheet', 'help'])
     oldequip = self.changequip(equipment)
     send_to_console(equipment + " equipped!")
     if oldequip:
         send_to_console(oldequip + " unequipped!")
     return
Beispiel #16
0
 def pc_turn(self):
     """The player takes his/her turn. Joy."""
     if self.char.skillpoints[0] > 0:
         msg = "Attack, " + ", ".join(self.char.skill) + \
             ", Run Away, or Equip?"
         available = self.char.skill + ["Attack", "Run Away", "Equip"]
     else:
         msg = "You are out of skill points! Attack, Run Away, or Equip?"
         available = ["Attack", "Run Away", "Equip"]
     print textwrap.fill(msg)
     action = choose_from_list("Action> ", available, rand=False,
         character=self.char, allowed=['sheet', 'help'])
     if action == "Attack":
         self.attack_enemy(self.char, self.enemy)
     elif action in self.char.skill:
         self.use_skill(action, self.char, self.enemy)
     elif action == "Run Away":
         self.runaway(self.char)
     elif action == "Equip":
         self.char.equip()
 def equip(self):
     """Equip an item, unequipping extant item if necessary."""
     if not self.loot['items']:
         send_to_console("You have nothing to equip!")
         return
     send_to_console("What would you like to equip?")
     lootbag = ['Ring of ' + i if i in pq_magic['ring'].keys() \
         else i for i in self.loot['items']]
     lootbag_basic = collapse_stringlist(lootbag, sortit=True, \
         addcounts=False)
     send_to_console(textwrap.fill("Lootbag: " + \
         ", ".join(collapse_stringlist(lootbag, sortit=True, \
         addcounts=True))))
     equipment = choose_from_list("Equip> ", lootbag_basic, rand=False, \
         character=self, allowed=['sheet', 'help'])
     oldequip = self.changequip(equipment)
     send_to_console(equipment + " equipped!")
     if oldequip:
         send_to_console(oldequip + " unequipped!")
     return
 def equip(self):
     """Equip an item, unequipping extant item if necessary."""
     if not self.loot['items']:
         print "You have nothing to equip!"
         return
     print "What would you like to equip?"
     lootbag = ['Ring of ' + i if i in pq_magic['ring'].keys() \
         else i for i in self.loot['items']]
     lootbag_basic = collapse_stringlist(lootbag, sortit=True, \
         addcounts=False)
     print textwrap.fill("Lootbag: " + \
         ", ".join(collapse_stringlist(lootbag, sortit=True, \
         addcounts=True)))
     equipment = choose_from_list("Equip> ", lootbag_basic, rand=False, \
         character=self, allowed=['sheet', 'help'])
     equipment = equipment.replace('Ring of ', '')
     itemtype = pq_item_type(equipment)
     oldequip = ''
     if itemtype[0] == "ring":
         if self.gear['ring']:
             self.skill.remove(pq_magic['ring'][self.gear['ring']])
             self.loot['items'].append(self.gear['ring'])
             oldequip = self.gear['ring']
         self.skill.append(pq_magic['ring'][equipment])
         self.gear['ring'] = equipment
         self.loot['items'].remove(equipment)
     else:
         new_rating = pq_item_rating(itemtype, equipment)
         if self.gear[itemtype[0]]['name']:
             self.loot['items'].append(self.gear[itemtype[0]]['name'])
             oldequip = self.gear[itemtype[0]]['name']
         self.gear[itemtype[0]]['name'] = equipment
         self.gear[itemtype[0]]['rating'] = new_rating
         self.loot['items'].remove(equipment)
     self.combat['atk'] = [self.gear['weapon']['rating'], self.stats[0]]
     self.combat['dfn'] = [self.gear['armor']['rating'], self.stats[1]]
     print equipment + " equipped!"
     if oldequip:
         print oldequip + " unequipped!"
     return
Beispiel #19
0
 def pc_turn(self):
     """The player takes his/her turn. Joy."""
     if self.char.skillpoints[0] > 0:
         msg = "Attack, " + ", ".join(self.char.skill) + \
             ", Run Away, or Equip?"
         available = self.char.skill + ["Attack", "Run Away", "Equip"]
     else:
         msg = "You are out of skill points! Attack, Run Away, or Equip?"
         available = ["Attack", "Run Away", "Equip"]
     print textwrap.fill(msg)
     action = choose_from_list("Action> ",
                               available,
                               rand=False,
                               character=self.char,
                               allowed=['sheet', 'help'])
     if action == "Attack":
         self.attack_enemy(self.char, self.enemy)
     elif action in self.char.skill:
         self.use_skill(action, self.char, self.enemy)
     elif action == "Run Away":
         self.runaway(self.char)
     elif action == "Equip":
         self.char.equip()
Beispiel #20
0
 def transactions(self):
     """Handle transactions with the shop."""
     msg1 = "His current inventory is: "
     inventory = display_itemlist(self.store)
     inventory_basic = collapse_stringlist(self.store, sortit=True, addcounts=False)
     if not inventory:
         msg1 += "Nothing!"
     else:
         msg1 += " ".join(inventory) + "."
     print textwrap.fill(msg1)
     msg2 = "Your current loot bag contains " + str(self.character.loot["gp"]) + " gp, and: "
     lootbag = display_itemlist(self.character.loot["items"], True)
     lootbag_basic = collapse_stringlist(self.character.loot["items"], sortit=True, addcounts=False)
     if not lootbag:
         msg2 += "Nothing!"
     else:
         msg2 += " ".join(lootbag) + "."
     print textwrap.fill(msg2)
     print "Buy Item# [Amount], Sell Item# [Amount], or Leave."
     buylist = [
         " ".join(["buy", str(i), str(j)])
         for i in range(1, len(inventory) + 1)
         for j in range(self.store.count(inventory_basic[i - 1]))
     ] + ["buy " + str(i) for i in range(len(inventory) + 1)]
     sellist = [
         " ".join(["sell", str(i), str(j)])
         for i in range(1, len(lootbag) + 1)
         for j in range(self.character.loot["items"].count(lootbag_basic[i - 1]) + 1)
     ] + ["sell " + str(i) for i in range(len(lootbag) + 1)]
     choice = choose_from_list(
         "Shop> ", buylist + sellist + ["leave"], rand=False, character=self.character, allowed=["sheet", "help"]
     )
     if choice == "leave":
         print "You leave the shop and head back into the town square.\n"
         return
     else:
         choice = choice.split()
         try:
             item = int(choice[1])
             item = inventory_basic[item - 1] if choice[0] == "buy" else lootbag_basic[item - 1]
             worth = pq_item_worth(item)
         except ValueError:
             worth = 0
         count = 1 if len(choice) < 3 else choice[2]
         try:
             count = int(count)
         except ValueError:
             count = 1
         if not worth:
             print "I'm sorry, I don't know what that item is. " "Can you try again?"
         elif choice[0] == "buy":
             if worth > self.character.loot["gp"]:
                 print "You don't have enough gold to buy that, cheapskate!"
             else:
                 pl = "" if count == 1 else "s"
                 print "You buy " + str(count) + " " + item + pl + "!"
                 for i in range(count):
                     self.character.buy_loot(item, worth)
                     self.store.remove(item)
         elif choice[0] == "sell":
             pl = "" if count == 1 else "s"
             print "You sell " + str(count) + " " + item + pl + "!"
             self.character.sell_loot(item, count)
         self.transactions()
Beispiel #21
0
 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
Beispiel #22
0
 def transactions(self):
     """Handle transactions with the shop."""
     msg1 = "His current inventory is: "
     inventory = display_itemlist(self.store)
     inventory_basic = collapse_stringlist(self.store, sortit = True, \
         addcounts = False)
     if not inventory:
         msg1 += "Nothing!"
     else:
         msg1 += " ".join(inventory) + "."
     send_to_console(textwrap.fill(msg1))
     msg2 = "Your current loot bag contains " + \
         str(self.character.loot['gp']) + " gp, and: "
     lootbag = display_itemlist(self.character.loot['items'], True)
     lootbag_basic = collapse_stringlist(self.character.loot['items'], \
         sortit = True, addcounts = False)
     if not lootbag:
         msg2 += "Nothing!"
     else:
         msg2 += " ".join(lootbag) + "."
     send_to_console(textwrap.fill(msg2))
     send_to_console("Buy Item# [Amount], Sell Item# [Amount], or Leave.")
     buylist = [" ".join(["buy", str(i), str(j)]) for i in range(1, \
         len(inventory) + 1) for j in range(1, self.store.count( \
         inventory_basic[i - 1]) + 1)] + ["buy " + str(i) for i \
         in range(1, len(inventory) + 1)]
     sellist = [" ".join(["sell", str(i), str(j)]) for i in \
         range(1, len(lootbag) + 1) for j in range(1, self.character.loot[\
         'items'].count(lootbag_basic[i - 1]) + 1)] + \
         ["sell " + str(i) for i in range(1, len(lootbag) + 1)]
     choice = choose_from_list("Shop> ", buylist + sellist + ["leave"], \
         rand=False, character=self.character, allowed=['sheet', 'help'])
     if choice == "leave":
         send_to_console(
             "You leave the shop and head back into the town square.\n")
         return
     else:
         choice = choice.split()
         try:
             item = int(choice[1])
             item = inventory_basic[item - 1] if choice[0] == "buy" \
                 else lootbag_basic[item - 1]
             worth = pq_item_worth(item)
         except ValueError:
             worth = 0
         count = 1 if len(choice) < 3 else choice[2]
         try:
             count = int(count)
         except ValueError:
             count = 1
         if not worth:
             send_to_console("I'm sorry, I don't know what that item is. " \
                 "Can you try again?")
         elif choice[0] == "buy":
             if worth > self.character.loot['gp']:
                 send_to_console(
                     "You don't have enough gold to buy that, cheapskate!")
             else:
                 pl = "" if count == 1 else "s"
                 send_to_console("You buy " + str(count) + " " + item + pl +
                                 "!")
                 for i in range(count):
                     self.character.buy_loot(item, worth)
                     self.store.remove(item)
         elif choice[0] == "sell":
             pl = "" if count == 1 else "s"
             send_to_console("You sell " + str(count) + " " + item + pl +
                             "!")
             self.character.sell_loot(item, count)
         self.transactions()
Beispiel #23
0
 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