Esempio n. 1
0
def travel(player):
    with Locations[player.position] as pos:
        print("You are leaving %s." % (pos.name))
        traveller = {0: 'Return'}
        print('Type the number of the town you want to travel to.')
        for num, location in enumerate(sorted(pos.destinations), 1):
            traveller[num] = Locations[location.strip()].name
            print(num, Locations[location.strip()].name)
        print(0, traveller[0])
        while True:
            choice = univ.IntChoice(len(traveller), ['x', 'q', 'm'], [0])
            if choice == 0 or choice == 'x':
                print('Returning to %s...' % (pos.name))
                return (player, displayPlaces)
            elif choice == 'q':
                print("Quitting...")
                return (player, quit)
            elif choice == 'm':
                action = ingameMenu.menu(player)
                if action:
                    return action
            else:
                player.position = sorted(pos.destinations)[choice - 1]
                print('You have moved to %s.' %
                      (Locations[player.position].name))
                print(Locations[player.position].desc)
                return (player, displayPlaces)
Esempio n. 2
0
def eqptMenu(player):
    options = {1: "Equip items from inventory", 2: "Unequip items", 0: "Leave"}
    while True:
        print("\n===Currently equipped items===")
        for slot in player.equipment:
            if player.equipment[slot]:
                print("%s: %s" % (slotnames[slot - 1],
                                  univ.Items[player.equipment[slot]].name))
            else:
                print("%s: None" % slotnames[slot - 1])
        print("\nWhat would you like to do?")
        for option in options:
            print(option, options[option])
        choice = univ.IntChoice(len(options), [], [0])
        if choice == 1:
            print("\nEquipment in your inventory:")
            alleqpt = []
            for item in player.inventory:
                try:
                    if univ.Items[item].slot and player.inventory[item]:
                        alleqpt.append(item)
                except AttributeError as e:
                    pass
            for num, item in enumerate(alleqpt, 1):
                print(num, univ.Items[item].name, player.inventory[item])
            print("x Return")
            print("Which item do you want to equip?")
            choice = univ.IntChoice(len(alleqpt), ["x"], [])
            if choice == "x":
                return
            else:
                player.equip(univ.Items[alleqpt[choice - 1]])
                player.save()
        elif choice == 2:
            print("\n===Currently equipped items===")
            for slot in player.equipment:
                if player.equipment[slot]:
                    print("%s: %s" % (slotnames[slot - 1],
                                      univ.Items[player.equipment[slot]].name))
            print("\nWhich slot do you want to unequip?")
            choice = univ.IntChoice(10, [], [0])
            if choice == 0:
                return player, menu
            player.unequip(choice)
            player.save()
        elif choice == 0:
            return player, menu
Esempio n. 3
0
def load(player):
    level = 1 + (player.exp['fishing']) / 10
    DropTable = {}
    #Load up the location's available item drops
    with open('./Locations/l0023_t.json', 'r') as file:
        reader = json.load(file)["items"]

    #Create rarity denominator and create the rarity drop table. Uncommon items are twice as rare as common items etc
    for a in range(len(rarity_new)):
        DropTable[a + 1] = []

    #Load up items suitable for the player's level
    for a in range(0, len(reader)):
        itemnamecode = reader[a]["code"]
        if level >= int(
                univ.ListOfItems[itemnamecode].minlvl
        ):  #Adds 'item' to the pool if the player's level is greater than 'min_lvl' Found in allitems_m.csv)
            DropTable[reader[a]["rarity"]].append(itemnamecode)

    print("How many times would you like to fish? You have %s fishing juice." %
          (player.inventory["i00000"]))
    collect = univ.IntChoice(player.inventory["i00000"] + 1, ['x'], [0])
    if collect == 'x' or collect == 0:
        return
    else:
        while collect > 0:
            collect -= 1
            player.inventory["i00000"] -= 1
            tier = 0
            max_roll = (2**rarity_new[-1][1]) - 1
            var = rand.randint(1, max_roll)
            for a in range(len(rarity_new), 0,
                           -1):  # Counts backwards from Common
                if (max_roll - 2**(a - 1) + 1) <= var <= max_roll:
                    # print("The succesful bound is (%s,%s)." % ((max_roll - 2**(a-1)+1), max_roll))
                    # print("Success. %s corresponds to a %s item." % (var, rarity_new[a-1][0]))
                    chosen_rarity = rarity_new[a - 1][1]
                    break
                else:
                    # print("The bounds were (%s,%s)." % ((max_roll - 2**(a-1)+1), max_roll))
                    max_roll -= 2**(a - 1)

            while DropTable[chosen_rarity] == []:
                chosen_rarity += 1

            chosen_item = rand.choice(DropTable[chosen_rarity])
            chosen_item_name = univ.ListOfItems[chosen_item].name
            player.inventory[chosen_item] += 1
            print(
                "You have successfully fished a %s. This is a [%s] item.You have %s %s."
                % (chosen_item_name, rarity_new[chosen_rarity - 1][0],
                   player.inventory[chosen_item], chosen_item_name))
    player.save()
Esempio n. 4
0
def displayPlaces(player):
    with Locations[player.position] as pos:
        print("You are currently at %s." % (pos.name))
        while True:
            print("Which place do you want to go into?")
            for num, place in sorted(pos.places.items())[1:]:
                print(num, pos.places[num][0])
            print(0, pos.places[0][0])
            choice = univ.IntChoice(len(pos.places), ['x', 'm', 'q'], [0])
            if choice == 'x' or choice == 0:
                return (player, travel)
            elif choice == 'q':
                print("Quitting...")
                return (player, quit)
            elif choice == 'm':
                return ingameMenu.menu(player)
            else:
                return (player, pos.places[choice][1].takeaction)
Esempio n. 5
0
 def accept(self, player):
     while True:
         print("\nYou can sell the following items here:\n")
         selldict = {0: 'Leave'}
         for num, key in enumerate(self.acceptList, 1):
             selldict[num] = key
             print(num, "%s: %sx    Sale price: %s each" %
                   (univ.Items[key[0]].name, player.inventory[key[0]],
                    key[1]))  # key[1] is the price
         print(0, selldict[0])
         print('Which item would you like to sell?')
         choice = univ.IntChoice(len(selldict), ['x'], [0])
         if choice == 'x' or choice == 0:
             break
         else:
             key = selldict[choice]
             while True:
                 print("The shop has %s [ %s ]" %
                       (self.stock[key[0]], univ.Items[key[0]].name))
                 try:
                     sale_q = int(
                         input(
                             "How many [ %s ] do you want to sell? Max: [ %s ] Sale price: [ %s ] %s\n>> "
                             % (univ.Items[key[0]].name,
                                player.inventory[key[0]], key[1],
                                univ.Items[self.currency].name)))
                     if 0 <= sale_q <= player.inventory[key[0]]:
                         player.inventory[key[0]] -= sale_q
                         try:
                             self.stock[key[0]] += sale_q
                         except KeyError:
                             self.stock.update({key[0]: sale_q})
                         self.update()
                         player.inventory[self.currency] += sale_q * key[1]
                         print("You now have %s %s." %
                               (player.inventory[key[0]],
                                univ.Items[key[0]].name))
                         player.disp_currency(self.currency)
                         player.save()
                         break
                     else:
                         univ.error(1)
                 except ValueError:
                     univ.error(2)
Esempio n. 6
0
 def vend(self, player):
     print("The shop has the following items for sale:")
     buydict = {0: "Leave"}
     for num, key in enumerate(self.vendList, 1):
         buydict[num] = key
         print(num, "%s: %s" % (univ.Items[key[0]].name, key[1]))
     print(0, buydict[0])
     player.disp_currency(self.currency)
     while True:
         print("Which item would you like to buy? 'x' to return")
         choice = univ.IntChoice(len(buydict), ['x'], [0])
         if choice == 'x' or choice == 0:
             break
         else:
             with univ.Items[buydict[choice][0]] as buyitem:
                 while True:
                     buy_q = input(
                         "How many [ %s ] would you like to purchase? Purchase price: [ %s ] %s. 'x' to cancel\n>> "
                         % (buyitem.name, buydict[choice][1],
                            univ.Items[self.currency].name))
                     if buy_q == 'x':
                         break
                     try:
                         quantity = int(buy_q)
                         if player.inventory[
                                 self.
                                 currency] < quantity * buydict[choice][1]:
                             print("You don't have enough money for that. "
                                   )  # univ.error(0)
                         else:
                             player.inventory[buyitem.code] += quantity
                             player.inventory[
                                 self.
                                 currency] -= quantity * buydict[choice][1]
                             print("You now have %s %s." %
                                   (player.inventory[buyitem.code],
                                    buyitem.name))
                             player.disp_currency(self.currency)
                             # player.save()
                             break
                     except ValueError:
                         univ.error(0)
                     break
Esempio n. 7
0
 def takeaction(self, player):
     while True:
         print("\nWhat do you want to do?")
         for key, val in sorted(self.actions.items())[1:]:
             print(key, val[0])
         print(0, self.actions[0][0])
         choice = univ.IntChoice(len(self.actions), ['x', 'm', 'q'], [0])
         if choice == 'q':
             print("Quitting...")
             return (player, quit)
         elif choice == 'x' or choice == 0:
             return self.leave(player)
         elif choice == 'm':
             action = ingameMenu.menu(player)
             if action:
                 return action
         else:
             self.actions[choice][1](
                 player
             )  # value of [choice] key in self.actions, 2nd entry (always a func), called with (player) as parameter
Esempio n. 8
0
def menu(player):
    menu_options = {
        1: ("Display Inventory", disp_inv),
        2: ("Display Position", disp_pos),
        3: ("Other Info", info),
        4: ("Save", save),
        5: ("Back to game", back),
        6: ("Help", helptext),
        7: ("Equipment", eqptMenu),
        0: ("Exit Game", exit)
    }
    while True:
        print("\n" + "MENU".center(30, '=') + "\n")
        for key in menu_options:
            print(str(key) + ". " + menu_options[key][0])
        print("\nEnter the corresponding number:\n")
        choice = univ.IntChoice(len(menu_options), ['x'], [0])
        if choice == 'x':
            return (player, "prev")
        var = menu_options[choice][1](player)
        if var:
            return var
        input("Press enter to continue.")