Example #1
0
 def run(self, gamedata, *args):
     if len(gamedata.gravedigger_offerings) == 0:
         print("No items left.")
         return QUIT, gamedata
     i = input("Type 'quit' or the name of the item you want to buy:\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.gravedigger_offerings)
     allowed_inputs.append("quit")
     print(allowed_inputs)
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next((x for x in gamedata.gravedigger_offerings if x.name == i), None)
         if gamedata.player.gold < chosen_item.price:
             print("You do not have enough money to buy this item")
             return CHOOSE, gamedata
         gamedata.player.gold -= math.floor(chosen_item.price)
         print("You have chosen {0}.\nYou now have {1} gold.\nAdded item to your inventory.\n"
               .format(chosen_item.name, gamedata.player.gold))
         gamedata.player.inventory.append(chosen_item)
         if chosen_item.type != "consumable":
             util.update_player_stats(gamedata.player, chosen_item)
         gamedata.gravedigger_offerings.remove(chosen_item)
         return LIST, gamedata
     else:
         print("Please insert the name of the item you want to buy or 'quit'")
         util.print_gravedigger_offering(gamedata)
         return CHOOSE, gamedata
Example #2
0
 def run(self, gamedata, *args):
     if len(gamedata.player.inventory) == 0:
         print("You do not have anything to store.")
         return QUIT, gamedata
     print("This are your items in your inventory:")
     util.print_inventory_contents(gamedata.player)
     i = input(
         "What item do you want to store in your chest? Else 'quit'\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.player.inventory)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next(
             (x for x in gamedata.player.inventory if x.name == i), None)
         gamedata.player.chest = []
         gamedata.player.chest.append(chosen_item)
         print(
             "You have choosen {0} to add to your chest.\nRemoved item from inventory.\n"
             .format(chosen_item.name))
         gamedata.player.inventory.remove(chosen_item)
         return DECIDE, gamedata
     else:
         print(
             "Please insert the name of the item you want to store or 'quit'."
         )
         return STORE, gamedata
Example #3
0
    def run(self, gamedata, *args):
        if len(gamedata.player.inventory) == 0:
            print("Your inventory is empty.")
            return QUIT, gamedata
        util.print_inventory_contents(gamedata.player)
        i = input(
            "Type 'quit' or the name of the item you want to use/drop:\n> ")
        allowed_inputs = []
        for item in gamedata.player.inventory:
            allowed_inputs.append(item.name)
        allowed_inputs.append("quit")
        if util.check_input(i, *allowed_inputs):
            if i == "quit":
                return QUIT, gamedata
            inventory_names = util.get_inventory_names(
                gamedata.player.inventory)
            if i in inventory_names:
                chosen_item = next(
                    (x for x in gamedata.player.inventory if x.name == i),
                    None)
                i2 = input(
                    "Do you want to 'use' or 'drop' {0}? Else 'quit'.\n> ".
                    format(chosen_item.name))  # print name of item
                if util.check_input(i2, "use", "drop",
                                    "quit"):  # check if input2 is legal
                    if i2 == "drop":
                        print("Droppend {0}".format(chosen_item.name))
                        gamedata.player.inventory.remove(chosen_item)
                        return LIST, gamedata
                    if i2 == "quit":
                        return LIST, gamedata
                    if i2 == "use":  # TODO implement use of potions
                        if chosen_item.type == "consumable":
                            util.update_player_stats(gamedata.player,
                                                     chosen_item)
                            gamedata.player.inventory.remove(chosen_item)
                            print("Increased your {0} by {1}".format(
                                chosen_item.influenced_attribute,
                                chosen_item.value))
                            return LIST, gamedata
                        else:
                            print(
                                "{0} is not consumable. Please choose another item"
                                .format(chosen_item.name))
                            return LIST, gamedata

                else:
                    return LIST, gamedata

        else:
            return LIST, gamedata
Example #4
0
    def run(self, gamedata, *args):
        i = input("Type 'quit' or the name of the item you want to sell:\n> ")
        allowed_inputs = util.get_inventory_names(gamedata.player.inventory)
        allowed_inputs.append("quit")
        if util.check_input(i, *allowed_inputs):
            if i == "quit":
                return QUIT, gamedata
            chosen_item = next((x for x in gamedata.player.inventory if x.name == i), None)
            gamedata.player.gold += math.floor(chosen_item.price * 0.5)
            print("You have choosen {0}.\nYou now have {1} gold.\nRemoved item from inventory.\n"
                  .format(chosen_item.name, gamedata.player.gold))

            gamedata.player.inventory.remove(chosen_item)
            return LIST, gamedata
        else:
            return CHOOSE, gamedata
Example #5
0
 def run(self, gamedata, *args):
     i = input("Type 'quit' or the name of the item you want to buy:\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.druid_offerings)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next(
             (x for x in gamedata.druid_offerings if x.name == i), None)
         if gamedata.player.gold < chosen_item.price:
             print("You do not have enough money to buy this item")
             return CHOOSE, gamedata
         gamedata.player.gold -= math.floor(chosen_item.price)
         print(
             "You have choosen {0}.\nYou now have {1} gold.\nAdded item to your inventory.\n"
             .format(chosen_item.name, gamedata.player.gold))
         gamedata.player.inventory.append(chosen_item)
         return LIST, gamedata
     else:
         print(
             "Please insert the name of the item you want to buy or 'quit'")
         return CHOOSE, gamedata
Example #6
0
 def run(self, gamedata, *args):
     if len(gamedata.player.chest) == 0:
         print("Your chest is empty.")
         return START, gamedata
     util.print_chest_items(gamedata.player.chest)
     i = input("What item do you want to take from the chest?\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.player.chest)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next(
             (x for x in gamedata.player.chest if x.name == i), None)
         gamedata.player.inventory.append(chosen_item)
         print(
             "You have choosen {0} to add to your inventory.\nRemoved item from chest.\n"
             .format(chosen_item.name))
         gamedata.player.chest.remove(chosen_item)
         return START, gamedata
     else:
         print(
             "Please insert the name of the item you want to take or 'quit'."
         )
         return TAKE, gamedata