Exemple #1
0
    def load_items_to_backpack(self, temp):
        backpack = temp.split(';\n')
        if len(backpack) != 1:
            result = []
            for i in range(len(backpack) - 1):
                temp = backpack[i]
                x = Item()
                x.load(temp)
                result.append(x)

            self.add_to_backpack(result)
Exemple #2
0
def spawn_item(description, it_type='consumable', effect='healing', add=1):
    x = Item()
    x.description = description
    x.type = it_type
    x.effect = effect
    x.add = add
    return x
Exemple #3
0
    def load_item(self, temp):
        if temp[0] == 'gold':
            self.gold = int(temp[1])
        elif temp[1] != '0':

            x = Item()
            x.load(temp[1])

            if temp[0] == 'head':
                self.head = [x]

            if temp[0] == 'arms':
                self.arms = [x]

            if temp[0] == 'body':
                self.body = [x]

            if temp[0] == 'legs':
                self.legs = [x]

            if temp[0] == 'weapon':
                self.weapon = [x]
Exemple #4
0
def buy_menu(bot, call):
    game_user = game_control()
    game_user.load(call.from_user.id)

    if 'back' in call.data.split('<-'):
        text, keyboard = main_menu(game_user)
        bot.edit_message_text(chat_id=game_user.user_id,
                              message_id=call.message.message_id,
                              text=text,
                              reply_markup=keyboard,
                              parse_mode='Markdown')
        return 0

    conn = sqlite3.connect('game_folder/shop.bd')
    c = conn.cursor()
    c.execute('SELECT * FROM items WHERE user_id = ?', [game_user.user_id])
    items = c.fetchall()
    conn.close()

    if len(items) == 0:
        keyboard = items_for_selling(game_user.user_id)
    else:
        keyboard = telebot.types.InlineKeyboardMarkup(True)
        result_items = []
        items_lines = []
        prices = []
        for i in range(len(items)):
            temp = Item()
            temp.load(items[i][1][:-1])
            line = temp.inventory_line()

            result_items.append(temp)
            items_lines.append(temp.description[:25])

            price = int(items[i][2])
            prices.append(price)
            price = ' ({0} gold)'.format(price)
            callback_data = 'buy<-' + temp.description[:25]
            button = telebot.types.InlineKeyboardButton(
                line + price, callback_data=callback_data)
            keyboard.row(button)

        if call.data != 'buy' and call.data.split('<-')[1] in items_lines:
            idx = items_lines.index(call.data.split('<-')[1])
            if game_user.character.inventory.gold - prices[idx] >= 0:
                game_user.character.inventory.gold -= prices[idx]
                game_user.character.add_to_backpack([result_items[idx]])
                result_items.pop(idx)
                prices.pop(idx)

                keyboard = telebot.types.InlineKeyboardMarkup(True)
                for i in range(len(result_items)):
                    line = result_items[i].inventory_line()
                    price = ' ({0} gold)'.format(prices[i])
                    callback_data = 'buy<-' + result_items[i].description
                    button = telebot.types.InlineKeyboardButton(
                        line + price, callback_data=callback_data)
                    keyboard.row(button)
            else:
                bot.send_message(game_user.user_id,
                                 'You don\'t have enough money')
                return 0

    button = telebot.types.InlineKeyboardButton('Back',
                                                callback_data='buy<-back')
    keyboard.row(button)
    text = 'Let\'s see how I can help you\nYou have *{0} gold*'.format(
        game_user.character.inventory.gold)
    game_user.save(call.from_user.id)
    bot.edit_message_text(chat_id=game_user.user_id,
                          message_id=call.message.message_id,
                          text=text,
                          reply_markup=keyboard,
                          parse_mode='Markdown')
    return 0
def random_consumable(not_random=''):
    result = Item()
    result.type = 'consumable'

    consumables = ['potion of healing', 'great potion of healing', 'scroll of teleportation', 'map']
    
    if not_random in consumables:
        result.description = not_random
        if not_random == 'potion of healing':
            result.effect = 'healing'
            result.add = 4
        if not_random == 'great potion of healing':
            result.effect = 'healing'
            result.add = 7
        if not_random in ['scroll of teleportation','map']:
            result.effect = 'travel'

    else:
        roll = numpy.random.randint(low=0, high=len(consumables))
        result.description = consumables[roll]
        if roll < 2:
            result.effect = 'healing'
            if roll == 0:
                result.add = 4
            if roll == 1:
                result.add = 7
        if roll == 2 or roll == 3:
            result.effect = 'travel'

    return result
def random_equipment(not_random=''):

    weapons = ['longsword', 'shortsword', 'greatsword', 'battleaxe', 'handaxe', 
        'glaive', 'halberd', 'twin swords', 'spear', 'dagger', 'rapier', 'trident', 
        'mace', 'warhammer', 'maul', 'scimitar', 'club', 'claimore', 'zweihander', 
        'estoc', 'katana', 'falchion', 'sabre', 'staff']


    head_arcane = ['cap', 'wizzard hat']
    head_physical = ['mail coif', 'great helm', 'sallet', 'barbute', 'close helm', 'foil hat']

    body_arcane = ['hood', 'robe', 'mantle', 'cloak']
    body_physical = ['plate armor', 'mail shirt', 'breastplate', 'brigandine', 'cuirass']

    arms = ['gloves', 'mittens', 'gauntlets']

    legs = ['greaves', 'pants', 'trousers', 'shirts']

    result = Item()
    result.type = 'equipable'
    damage_type = Damage(numpy.random.randint(low=0, high=len(Damage))).value

    roll_meta = numpy.random.randint(low=0, high=5)
    if roll_meta == 0 or not_random == 'weapon':
        roll = numpy.random.randint(low=0, high=len(weapons))
        result.description = game_folder.generate_dungeon.random_material(weapons[roll], metal=True)
        result.effect = 'weapon'

        min_dmg = numpy.random.randint(low=1, high=3)
        max_dmg = numpy.random.randint(low=3, high=6)
        dmg = str(min_dmg)+';'+str(max_dmg)
        result.add = [dmg, damage_type]


    elif roll_meta == 1 or not_random == 'head':
        head = head_arcane+head_physical
        roll = numpy.random.randint(low=0, high=len(head))
        if head[roll] in head_arcane:
            result.description = game_folder.generate_dungeon.random_material(head[roll], fabric=True)
        else:
            result.description = game_folder.generate_dungeon.random_material(head[roll], metal=True)
        result.effect = 'head'
        prot = round(numpy.random.rand()/4,2)
        result.add = [prot, damage_type]


    elif roll_meta == 2 or not_random == 'body':
        body = body_arcane+body_physical
        roll = numpy.random.randint(low=0, high=len(body))
        if body[roll] in body_arcane:
            result.description = game_folder.generate_dungeon.random_material(body[roll], fabric=True)
        else:
            result.description = game_folder.generate_dungeon.random_material(body[roll], metal=True)
        result.effect = 'body'
        prot = round(numpy.random.rand()/2,2)
        result.add = [prot, damage_type]


    elif roll_meta == 3 or not_random == 'arms':
        roll = numpy.random.randint(low=0, high=len(arms))
        if arms[roll] == 'gauntlets':
            result.description = game_folder.generate_dungeon.random_material(arms[roll], metal=True)
        else:
            result.description = game_folder.generate_dungeon.random_material(arms[roll], fabric=True)
        result.effect = 'arms'
        prot = round(numpy.random.rand()/4,2)
        result.add = [prot, damage_type]


    elif roll_meta == 4 or not_random == 'legs':
        roll = numpy.random.randint(low=0, high=len(legs))
        if legs[roll] == 'greaves':
            result.description = game_folder.generate_dungeon.random_material(legs[roll], metal=True)
        else:
            result.description = game_folder.generate_dungeon.random_material(legs[roll], fabric=True)
        result.effect = 'legs'
        prot = round(numpy.random.rand()/4,2)
        result.add = [prot, damage_type]

    return result
def random_stats(role='warrior'):
    if role == 'warrior':
        weapons = ['sword', 'shield', 'plate', 'mail', 'axe', 'mace', 'spear', 'warhammer', 'maul', \
        'glaive', 'halberd', 'scimitar', 'dagger']
    if role == 'mage':
        weapons = ['cap', 'hood', 'hat', 'robe', 'stick', 'staff', 'wand', 'rod', 'sword', \
        'mantle', 'cloak', 'ring']


    result = Item()

    roll = numpy.random.randint(low=0, high=len(weapons))
    if weapons[roll] in ['hat', 'hood', 'robe', 'mantle', 'cloak']:
        result.description = game_folder.generate_dungeon.random_material(weapons[roll], fabric=True)
    else:
        result.description = game_folder.generate_dungeon.random_material(weapons[roll], metal=True)
    result.type = 'stats'

    roll_stat = numpy.random.randint(low=0, high=3)
    roll_add = numpy.random.randint(low=1, high=5)
    if roll_stat == 0:
        result.effect = 'strength'
        result.add = roll_add
    if roll_stat == 1:
        result.effect = 'intellect'
        result.add = roll_add
    if roll_stat == 2:
        result.effect = 'endurance'
        result.add = roll_add

    return result
Exemple #8
0
def game(bot, message):
    game_user = game_control()
    game_user.load(message.from_user.id)
    logging.info(message.from_user.first_name + ' is playing')

    if game_user.creating_character:
        if message.text.lower() == 'yes' and game_user.veteran_character:
            game_user.creating_character = False
            game_user.last_status = 1  # sending player to shop
            game_user.save(game_user.user_id)

            keyboard = telebot.types.ReplyKeyboardMarkup(True)
            keyboard.row('Next')
            bot.send_message(game_user.user_id,
                             'Adventures of ' + game_user.character.name +
                             ' continues!',
                             reply_markup=keyboard)
            return 0
        if message.text.lower() == 'no' and game_user.veteran_character:
            game_user.character.delete_from_repository(game_user.user_id,
                                                       folder='game_folder/')
            game_user.delete(game_user.user_id)
            game_user.create(game_user.user_id)
            create_character(bot, message, True)
            return 0
        if game_user.veteran_character:
            bot.send_message(
                game_user.user_id,
                'Answer with yes (continue as this character) or no (start with a new one)'
            )
            return 0

        status_change = create_character(bot, message, False)
        try:
            game_user.load(game_user.user_id)
        except:
            return 1
        game_user.creating_character = status_change

        if status_change == False:
            # trying to get some item from storage
            temp = Item()
            result = temp.transfer_from_storage(game_user.user_id,
                                                folder='game_folder/')
            if result:
                game_user.character.add_to_backpack([temp])
                text = 'You have recieved an item left for you by another player.'+\
                '\nIt\'s '+temp.description
                keyboard = telebot.types.ReplyKeyboardMarkup(True)
                keyboard.row(u'\U0001F44D', 'Into the dungeon')
                bot.send_message(game_user.user_id,
                                 text,
                                 reply_markup=keyboard)
        game_user.save(game_user.user_id)
        return 0

    if len(game_user.dungeon) == 0:

        # rewarding for transfered item
        if len(game_user.character.backpack
               ) != 0 and game_user.veteran_character == False:
            effect = game_user.character.backpack[0].effect.split(',')
            game_user.character.backpack[0].effect = effect[0]
            item_type = game_user.character.backpack[0].type.split(',')
            game_user.character.backpack[0].type = item_type[0]
            game_user.save(game_user.user_id)
            if message.text == u'\U0001F44D':
                add_likes(bot, message, int(effect[1]), int(item_type[1]),
                          numpy.random.randint(low=46, high=55))
            if message.text.lower() == 'into the dungeon':
                add_likes(bot, message, int(effect[1]), int(item_type[1]),
                          numpy.random.randint(low=26, high=35))

        # visiting shop
        if game_user.veteran_character and game_user.last_status == 1:
            game_user.last_status = 0
            game_user.in_shop = True
            game_user.save(game_user.user_id)
            open_shop(bot, game_user, folder='game_folder/')
            return 0

        if game_user.in_shop:
            bot.send_message(
                game_user.user_id,
                'If you want to continue, press close in the shop window')
            return 0

        # generating dungeon
        oppening, creators, doom = game_folder.generate_dungeon.main(
            game_user.character,
            game_user.user_id,
            folder='game_folder/',
            veteran=game_user.veteran_character)
        game_user.load(
            game_user.user_id)  # now dungeon part was added to the database

        game_user.creators = creators
        game_user.doom = doom
        game_user.save(game_user.user_id)
        bot.send_message(game_user.user_id, oppening)

        buffer = game_folder.generate_dungeon.draw_dungeon(
            game_user.dungeon, [game_user.x, game_user.y],
            game_user.user_id,
            folder='game_folder/',
            map_found=game_user.has_map)
        keyboard = move_keyboard(game_user)
        bot.send_photo(game_user.user_id, photo=buffer, reply_markup=keyboard)
        bot.send_message(game_user.user_id,
                         game_user.dungeon[game_user.in_room_now].description)
        return 0

    if game_user.is_fighting:
        game_user = fight(bot, message, game_user)
        game_user.save(game_user.user_id)
        if game_user.dead:
            return 1
        else:
            return 0

    if game_user.is_being_teleported:
        try:
            game_user.teleport(int(message.text))
            text = 'Winds of magic swirl around you as you finish reading the scroll. '+\
            'You open your eyes in completly different place. '+game_user.dungeon[game_user.in_room_now].description

            buffer = game_folder.generate_dungeon.draw_dungeon(
                game_user.dungeon, [game_user.x, game_user.y],
                game_user.user_id,
                folder='game_folder/',
                map_found=game_user.has_map)
            bot.send_photo(game_user.user_id, photo=buffer)

            game_user.check_completion()
            if game_user.complete:
                if len(game_user.character.show_backpack()) != 0:
                    text = 'Congratulations! You have completed the dungeon.'+\
                    ' Do you want to help other players and leave one of your items for future adventurers?'
                    keyboard = telebot.types.ReplyKeyboardMarkup(True)
                    keyboard.row('Yes', 'No')
                    bot.send_message(game_user.user_id,
                                     text,
                                     reply_markup=keyboard)
                    game_user.save(game_user.user_id)
                    return 0
                else:
                    end_game(bot, message, game_user)
                    game_user.save(game_user.user_id)
                    return 1

            game_user.save(game_user.user_id)
            keyboard = move_keyboard(game_user)
            bot.send_message(game_user.user_id, text, reply_markup=keyboard)

            if game_user.is_fighting:
                game_user = fight(bot, message, game_user)
                game_user.save(game_user.user_id)
                if game_user.dead:
                    return 1
        except:
            import traceback
            bot.send_message(game_user.user_id,
                             'Enter the number of the room on the map')
            traceback.print_exc()
        return 0

    if game_user.complete:
        if message.text.lower() == 'yes':
            game_user.last_status = 1
            open_inventory(bot, game_user)
            game_user.save(game_user.user_id)
            return 0
        elif message.text.lower() == 'no':
            end_game(bot, message, game_user)
            return 1
        else:
            bot.send_message(game_user.user_id, 'Select one of the buttons')

    # blocks move, look around, search, backpack buttons if backpack is open
    if game_user.last_status == 1:
        bot.send_message(game_user.user_id,
                         'You need to close the backpack to do that')
        return 0

    if message.text.lower() == 'look around':
        bot.send_message(
            game_user.user_id,
            game_user.dungeon[game_user.in_room_now].look_around())
        return 0

    if message.text.lower() == 'search':
        items, text = game_user.dungeon[game_user.in_room_now].loot_room()
        if len(items) != 0:
            game_user.character.add_to_backpack(items)
        game_user.save(game_user.user_id)
        bot.send_message(game_user.user_id, text)
        return 0

    if message.text.lower() == 'backpack':
        game_user.last_status = 1
        open_inventory(bot, game_user)
        game_user.save(game_user.user_id)
        return 0

    moves = game_user.determine_possible_moves()
    if message.text in moves:
        game_user.move(message.text)
        game_user.check_completion()
        n = game_user.how_many_rooms_left()

        if game_user.complete:
            if len(game_user.character.show_backpack()) != 0:
                game_user.save(game_user.user_id)
                text = 'Congratulations! You have completed the dungeon.'+\
                ' Do you want to help other players and leave one of your items for future adventurers?'
                keyboard = telebot.types.ReplyKeyboardMarkup(True)
                keyboard.row('Yes', 'No')
                bot.send_message(game_user.user_id,
                                 text,
                                 reply_markup=keyboard)
                return 0
            else:
                end_game(bot, message, game_user)
                return 1

        buffer = game_folder.generate_dungeon.draw_dungeon(
            game_user.dungeon, [game_user.x, game_user.y],
            game_user.user_id,
            folder='game_folder/',
            map_found=game_user.has_map)
        keyboard = move_keyboard(game_user)
        bot.send_photo(game_user.user_id, photo=buffer, reply_markup=keyboard)
        bot.send_message(
            game_user.user_id,
            game_user.dungeon[game_user.in_room_now].description +
            '\nYou have ' + str(n) + ' more unexplored rooms.')

        if game_user.is_fighting:
            game_user = fight(bot, message, game_user)
            game_user.save(game_user.user_id)
            if game_user.dead:
                return 1
        else:
            game_user.save(game_user.user_id)
            return 0

    logging.info("Recieved: " + message.text)