예제 #1
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
예제 #2
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
예제 #3
0
 def sell_loot(self, sell, count = 1):
     """Character-side loot sale (removing item 
     from lootbag, adding gp)"""
     if type(sell) is list:
         sell = sell[0]
     lowitems = [x.lower() for x in self.loot['items']]
     if sell.lower() not in lowitems: 
         return False
     value = max([pq_item_worth(sell)/2, 1])
     loot = []
     for j in sorted(self.loot['items']):
         if sell.lower() == j.lower() and count > 0:
             self.loot['gp'] += value
             count -= 1
         else:
             loot.append(j)
     self.loot['items'] = loot
     return True
예제 #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
예제 #5
0
 def sell_loot(self, sell, count=1):
     """Character-side loot sale (removing item 
     from lootbag, adding gp)"""
     if type(sell) is list:
         sell = sell[0]
     lowitems = [x.lower() for x in self.loot['items']]
     if sell.lower() not in lowitems:
         return False
     value = max([pq_item_worth(sell) / 2, 1])
     loot = []
     for j in sorted(self.loot['items']):
         if sell.lower() == j.lower() and count > 0:
             self.loot['gp'] += value
             count -= 1
         else:
             loot.append(j)
     self.loot['items'] = loot
     return True
예제 #6
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()
예제 #7
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()