Beispiel #1
0
 def sheetstring(self):
     """Return a string containing the character sheet"""
     self.charsheetstring = []
     self.charsheetstring.append(color.BOLD + color.GREEN + self.name[0] + \
         color.END + ' (Player: ' + self.name[1] + ')')
     self.charsheetstring.append(color.BOLD + ' '.join([self.raceclass[ \
         0].capitalize(), self.raceclass[1].capitalize(), \
         str(self.level[1])]) + color.END)
     statstring = sum([[color.BOLD + pq_stats_short[i] + color.END, \
         str(self.stats[i])] for i in range(0,6)], [])
     feats = collapse_stringlist(self.feats, True, True)
     feats = ', '.join(sorted(feats))
     self.charsheetstring.append('; '.join([' '.join(statstring), color.BOLD + \
         'hp ' +  color.END + str(self.hitpoints[0]) + '/' + \
         str(self.hitpoints[1]), color.BOLD + 'sp ' + color.END + \
         str(self.skillpoints[0]) + '/' + str(self.skillpoints[1]), \
         color.BOLD + 'exp ' + color.END + str(self.level[0]) + '/' + \
         str(self.level[1]*10)]))
     self.charsheetstring.append(textwrap.fill(feats))
     if not self.gear['armor']['name']:
         armor = color.BOLD + 'Armor:' + color.END + ' None (0)'
     else:
         armor = color.BOLD + 'Armor:' + color.END + ' ' + \
             self.gear['armor']['name'] + ' (' + \
             str(self.gear['armor']['rating']) + ')'
     if not self.gear['weapon']['name']:
         weapon = color.BOLD + 'Weapon:' + color.END + ' None (-1)'
     else:
         weapon = color.BOLD + 'Weapon:' + color.END + ' '+  \
             self.gear['weapon']['name'] + ' (' + \
             str(self.gear['weapon']['rating']) + ')'
     if not self.gear['ring']:
         ring = color.BOLD + 'Ring:' + color.END + ' None'
     else:
         ring = color.BOLD + 'Ring:' + color.END + ' ' + self.gear['ring']
     self.charsheetstring.append('; '.join([
         color.BOLD + 'Skills: ' + color.END + ', '.join(self.skill), armor,
         weapon, ring
     ]))
     lootbag = collapse_stringlist(self.loot['items'], True, True)
     for i, f in enumerate(lootbag):
         for l in f.split():
             if l.lower() in [x.lower() for x in pq_magic['ring'].keys()]:
                 lootbag[i] = "Ring of " + lootbag[i]
     if not lootbag:
         lootbag = 'None'
     else:
         lootbag = ', '.join(lootbag)
     self.charsheetstring.append(textwrap.fill(str(self.loot['gp']) + \
         ' gp; loot: ' + lootbag))
     return self.charsheetstring
 def sheetstring(self):
     """Return a string containing the character sheet"""
     self.charsheetstring = []
     self.charsheetstring.append(color.BOLD + color.GREEN + self.name[0] + \
         color.END + ' (Player: ' + self.name[1] + ')')
     self.charsheetstring.append(color.BOLD + ' '.join([self.raceclass[ \
         0].capitalize(), self.raceclass[1].capitalize(), \
         str(self.level[1])]) + color.END)
     statstring = sum([[color.BOLD + pq_stats_short[i] + color.END, \
         str(self.stats[i])] for i in range(0,6)], [])
     feats = collapse_stringlist(self.feats, True, True)
     feats = ', '.join(sorted(feats))
     self.charsheetstring.append('; '.join([' '.join(statstring), color.BOLD + \
         'hp ' +  color.END + str(self.hitpoints[0]) + '/' + \
         str(self.hitpoints[1]), color.BOLD + 'sp ' + color.END + \
         str(self.skillpoints[0]) + '/' + str(self.skillpoints[1]), \
         color.BOLD + 'exp ' + color.END + str(self.level[0]) + '/' + \
         str(self.level[1]*10)]))
     self.charsheetstring.append(textwrap.fill(feats))
     if not self.gear['armor']['name']:
         armor = color.BOLD + 'Armor:' + color.END + ' None (0)'
     else:
         armor = color.BOLD + 'Armor:' + color.END + ' ' + \
             self.gear['armor']['name'] + ' (' + \
             str(self.gear['armor']['rating']) + ')'
     if not self.gear['weapon']['name']:
         weapon = color.BOLD + 'Weapon:' + color.END + ' None (-1)'
     else:
         weapon = color.BOLD + 'Weapon:' + color.END + ' '+  \
             self.gear['weapon']['name'] + ' (' + \
             str(self.gear['weapon']['rating']) + ')'
     if not self.gear['ring']:
         ring = color.BOLD + 'Ring:' + color.END + ' None'
     else:
         ring = color.BOLD + 'Ring:' + color.END + ' ' + self.gear['ring']
     self.charsheetstring.append('; '.join([color.BOLD + 'Skills: ' + 
         color.END + ', '.join(self.skill), armor, weapon, ring]))
     lootbag = collapse_stringlist(self.loot['items'], True, True)
     for i, f in enumerate(lootbag):
         for l in f.split():
             if l.lower() in [x.lower() for x in pq_magic['ring'].keys()]:
                 lootbag[i] = "Ring of " + lootbag[i]
     if not lootbag:
         lootbag = 'None'
     else:
         lootbag = ', '.join(lootbag)
     self.charsheetstring.append(textwrap.fill(str(self.loot['gp']) + \
         ' gp; loot: ' + lootbag))
     return self.charsheetstring
Beispiel #3
0
def display_itemlist(itemlist, sell=False):
    """Format a list of items for display in the shop."""
    unique_items = collapse_stringlist(itemlist, sortit = True, \
        addcounts = False)
    items_with_counts = collapse_stringlist(itemlist, sortit = True, \
        addcounts = True)
    items = []
    for j, i in enumerate(unique_items):
        price = pq_item_worth(i)
        if sell:
            price = max([price / 2, 1])
        if i.lower() in [x.lower() for x in pq_magic['ring'].keys()]:
            items.append(str(j + 1) + ". Ring of " + items_with_counts[j] + \
                " (" + str(price) + ")")
        else:
            items.append(str(j + 1) + ". " + items_with_counts[j] + \
                " (" + str(price) + ")")
    return items
Beispiel #4
0
def display_itemlist(itemlist, sell = False):
    """Format a list of items for display in the shop."""
    unique_items = collapse_stringlist(itemlist, sortit = True, \
        addcounts = False)
    items_with_counts = collapse_stringlist(itemlist, sortit = True, \
        addcounts = True)
    items = []
    for j, i in enumerate(unique_items):
        price = pq_item_worth(i)
        if sell:
            price = max([price / 2, 1])
        if i.lower() in [x.lower() for x in pq_magic['ring'].keys()]:
            items.append(str(j + 1) + ". Ring of " + items_with_counts[j] + \
                " (" + str(price) + ")")
        else:
            items.append(str(j + 1) + ". " + items_with_counts[j] + \
                " (" + str(price) + ")")
    return items
 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 #6
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 #7
0
def display_itemlist(itemlist, sell=False):
    """Format a list of items for display in the shop."""
    items = collapse_stringlist(itemlist, sortit=True, addcounts=True)
    for j, i in enumerate(items):
        price = pq_item_worth(i)
        if sell:
            price = max([price / 2, 1])
        if i.lower() in [x.lower() for x in pq_magic["ring"].keys()]:
            items[j] = str(j + 1) + ". Ring of " + i + " (" + str(price) + ")"
        else:
            items[j] = str(j + 1) + ". " + i + " (" + str(price) + ")"
    return items
 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 #9
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 #10
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()