Esempio n. 1
0
    def end_dungeon(self, defeat=False, boss_beaten=False):
        farmed_resources = 0
        for member in self.party.members:
            for item in member.inventory:
                item_obj = standart_actions.get_class(item[0]['name'])
                if 'resource' in item_obj.core_types:
                    farmed_resources += item_obj.resources * member.inventory[
                        item[1]][1]
        if boss_beaten:
            farmed_resources *= 2
        if defeat:
            farmed_resources = 0
        self.delete_map()
        try:
            if not defeat:
                for team in self.teams:
                    for key in team:
                        dynamic_dicts.occupied_list.remove(key)
        except:
            pass
        for member in self.party.members:
            del dynamic_dicts.dungeons[member.chat_id]

        message = self.form_result_string(
            farmed_resources, self.party.collected_receipts.to_string('rus'))
        bot_methods.send_message(self.chat_id, message)
        chat = pyossession.get_chat(self.chat_id)
        chat.add_resources(farmed_resources)
        chat.add_receipt(self.party.collected_receipts)
        if not defeat:
            chat.add_receipt(self.party.collected_receipts)
        user_list = list(
            map(get_user, [member.chat_id for member in self.party.members]))
        self.party.distribute_experience(user_list)
Esempio n. 2
0
 def send_page(self):
     self.form_actions()
     text = self.get_menu_string()
     if self.call is None:
         send_message(self.user_id, text, reply_markup=self.get_menu_keyboard())
     else:
         edit_message(self.user_id, self.call.message.message_id, text, reply_markup=self.get_menu_keyboard())
Esempio n. 3
0
 def get_results(self):
     from chat_wars.chat_main import Chat, User
     pyossession = Pyossession(Chat, User)
     chats = pyossession.get_chats()
     for chat in chats:
         war_data = chat.get_current_war_data()
         if war_data['attacked_by_chats']:
             for attacked_chat in war_data['attacked_by_chats']:
                 won_chat = pyossession.get_chat(attacked_chat)
                 prize_amount = chat.get_prize()
                 chat.add_resources(-prize_amount)
                 won_chat.add_resources(prize_amount)
                 send_message(
                     chat.chat_id,
                     'Чат {} отнимает у вас {} ресурсов'.format(
                         won_chat.name, prize_amount))
                 send_message(
                     won_chat.chat_id,
                     'Вы отнимаете {} ресурсов у чата {}'.format(
                         prize_amount, chat.name))
         chat.set_current_war_data({
             "attacked_by_chats": [],
             "attacks_left": 1,
             "chats_besieged": []
         })
Esempio n. 4
0
 def unit_talk(self, unit_id, message):
     unit = self.units_dict[unit_id]
     if not unit.controller.talked:
         unit.controller.talked = True
         for fighter in self.units:
             if not fighter.controller.ai and unit != fighter:
                 bot_methods.send_message(fighter.controller.chat_id, '{}: {}'.format(unit.name, message))
Esempio n. 5
0
def start(message):
    keyboard = telebot.types.InlineKeyboardMarkup()
    keyboard.add(
        telebot.types.InlineKeyboardButton('Тест', callback_data='test'))
    bot_methods.send_message(message.from_user.id,
                             'тест',
                             reply_markup=keyboard)
Esempio n. 6
0
 def announce(self, lang_tuple, image=None):
     for listener in [listener for listener in self.listeners]:
         text = lang_tuple.translate(listener.lang)
         if image is None:
             bot_methods.send_message(listener.chat_id, text)
         else:
             bot_methods.send_image(image, listener.chat_id, text)
Esempio n. 7
0
 def pop_info(self, call):
     try:
         bot_methods.answer_callback_query(call=call,
                                           text=self.info_string().translate(self.unit.controler.lang))
     except bot_methods.telebot.apihelper.ApiException:
         bot_methods.send_message(call.message.chat.id,
                                  message=self.info_string().translate(self.unit.controler.lang))
Esempio n. 8
0
 def send_message(self, lang_tuple, reply_markup=None):
     if isinstance(lang_tuple, str):
         return bot_methods.send_message(self.chat_id,
                                         lang_tuple, reply_markup=reply_markup)
     else:
         return bot_methods.send_message(self.chat_id,
                                         lang_tuple.translate(self.lang), reply_markup=reply_markup)
Esempio n. 9
0
 def marauder(self, target_chat_id):
     target_chat = pyossession.get_chat(target_chat_id)
     send_message(target_chat.chat_id,
                  'Чат {} раграбляет ваши сокровища!'.format(self.name))
     send_message(self.chat_id, 'Чат {} ограблен!'.format(target_chat.name))
     war_data = target_chat.get_current_war_data()
     war_data['attacked_by_chats'].append(self.chat_id)
     target_chat.set_current_war_data(war_data)
Esempio n. 10
0
 def win_siege(self, target_chat_id):
     target_chat = pyossession.get_chat(target_chat_id)
     send_message(target_chat.chat_id,
                  'Чат {} осаждает ваши укрепления!'.format(self.name))
     send_message(self.chat_id,
                  'Вы успешно осаждаете чат {}'.format(target_chat.name))
     war_data = self.get_current_war_data()
     war_data['chats_besieged'].append(target_chat_id)
     self.set_current_war_data(war_data)
Esempio n. 11
0
    def advance(self):

        self.exhaustion += 1
        if self.exhaustion >= self.max_exhaustion and not any(
                status['name'] == 'exhausted' for status in self['statuses']):
            bot_methods.send_message(self.chat_id,
                                     'Вы чувствуете себя ужасно усталым.')
            self['statuses'].append(
                standart_actions.object_dict['exhausted']().to_dict())
Esempio n. 12
0
def send_mob_choice(chat_id):
    mob_list = ['dragon', 'ogre', 'goblin']
    buttons = []
    for mob in mob_list:
        buttons.append(
            keyboards.Button(mob, 'mobchoice_{}_{}'.format(mob, chat_id)))
    keyboard = keyboards.form_keyboard(*buttons)
    bot_methods.send_message(chat_id,
                             'Выберите противника',
                             reply_markup=keyboard)
Esempio n. 13
0
def join_game(fight_id, user_id, name):
    import dynamic_dicts
    if fight_id in dynamic_dicts.lobby_list and not dynamic_dicts.lobby_list[
            fight_id].started:
        if not user_exists(user_id):
            add_user(user_id, pending_tutorial=True)
        user = get_user(user_id)
        unit_dict = user.get_fight_unit_dict(name=name)
        dynamic_dicts.lobby_list[fight_id].player_join(user_id,
                                                       unit_dict=unit_dict)
        send_message(user_id, 'Вы успешно присоединились.')
    def take_key(self, call):
        self.reset_message('text_2')
        self.key_taken = True
        for member in self.dungeon.party.members:
            member.message_id = None
            member.add_item('tutorial_key')
            bot_methods.send_message(
                member.chat_id,
                '<Вы подняли ключ. Поднятые предметы появляются у вас в инвентаре.>'
            )

        self.dungeon.party.member_dict[call.from_user.id].member_menu_start()
Esempio n. 15
0
def game(message):
    if len(message.text.split(' ')) > 1:
        data = message.text.split(' ')[1].split('_')
        import dynamic_dicts
        if data[1] in dynamic_dicts.lobby_list:
            chat_main.add_user(message.from_user.id)
            user = chat_menu.get_user(message.from_user.id)
            unit_dict = user.get_unit_dict(name=message.from_user.first_name)
            dynamic_dicts.lobby_list[data[1]].player_join(message.from_user.id,
                                                          unit_dict=unit_dict)
            bot_methods.send_message(message.from_user.id,
                                     'Вы успешно присоединились.')
Esempio n. 16
0
    def join_forbidden(self, user_id):
        if self.started:
            return True

        if user_id in dynamic_dicts.occupied_list:
            bot_methods.send_message(user_id,
                                     'Вы не можете сейчас присоединиться.')
            return True

        if any(user_id in team for team in self.teams):
            self.error('player_exists')
            return True

        return False
Esempio n. 17
0
 def run(self):
     path = file_manager.my_path + '/files/images/backgrounds/camp.jpg'
     bot_methods.send_image(image_generator.create_dungeon_image(path,
                                                                 (self.get_image(key) for key in self.team)),
                            self.chat_id)
     # len(self.teams)
     self.complexity = 1
     self.create_dungeon_map()
     dynamic_dicts.dungeons[self.id] = self
     self.add_party(player_list=self.team)
     for member in self.party.members:
         dynamic_dicts.dungeons[member.chat_id] = self
     bot_methods.send_message(self.chat_id, localization.LangTuple('utils', 'fight_start')
                              .translate(self.lang))
     del dynamic_dicts.lobby_list[self.id]
     self.map.start()
Esempio n. 18
0
 def send_message(self, text, reply_markup=None, image=None):
     if image is None:
         self.message_id = bot_methods.send_message(
             self.chat_id, text, reply_markup=reply_markup).message_id
     else:
         self.message_id = bot_methods.send_image(
             image, self.chat_id, text,
             reply_markup=reply_markup).message_id
     return self.message_id
Esempio n. 19
0
 def send_equipment_choice(self,
                           lobby_id,
                           chat_id,
                           equipment_type,
                           message_id=None):
     message = self.form_equipment_message(lobby_id, equipment_type)
     buttons = self.create_choice_equipment(lobby_id, chat_id,
                                            equipment_type)
     for button in self.choice_button(lobby_id, equipment_type):
         buttons.append(button)
     keyboard = keyboards.form_keyboard(*buttons)
     if message_id is None:
         send_message(self.user_id, message, reply_markup=keyboard)
     else:
         edit_message(chat_id=self.user_id,
                      message_id=message_id,
                      message_text=message,
                      reply_markup=keyboard)
Esempio n. 20
0
 def send_lobby(self):
     if self.image is None:
         message = bot_methods.send_message(self.chat_id,
                                            self.create_lobby(),
                                            reply_markup=self.keyboard())
     else:
         message = bot_methods.send_image(open(self.image, 'rb'),
                                          self.chat_id,
                                          message=self.create_lobby(),
                                          reply_markup=self.keyboard())
     self.message_id = message.message_id
Esempio n. 21
0
 def distribute_loot(self, loot_container):
     loot_receivers = list(self.members)
     random.shuffle(loot_receivers)
     if not loot_container.empty():
         player_containers = loot_container.random_split(
             len(loot_receivers))
         loot_list = dict(zip(loot_receivers, player_containers))
         for member in loot_receivers:
             message = LangTuple('dungeon', 'loot').translate(member.lang)
             if not loot_list[member].empty():
                 item_list = loot_list[member].to_string(member.lang)
                 message += '\n' + LangTuple('dungeon',
                                             'found', format_dict={'name': member.name,
                                                                   'item': item_list}). \
                     translate(member.lang) if loot_list[member] else \
                     '\n' + LangTuple('dungeon', 'full-inv', format_dict={'name': member}). \
                         translate(member.lang)
                 self.member_dict[
                     member.chat_id].inventory += loot_list[member]
             bot_methods.send_message(member.chat_id, message)
Esempio n. 22
0
 def next_step(self, chat_id):
     if self.stage == 'before_siege':
         self.start_siege()
         send_message(chat_id, 'Текущий этап войны - осада.')
     elif self.stage == 'siege':
         self.stage = 'before_attack'
         self.refresh_users()
         send_message(chat_id, 'Текущий этап войны - мир.')
     elif self.stage == 'before_attack':
         self.start_attack()
         send_message(chat_id, 'Текущий этап войны - атака.')
     elif self.stage == 'attack':
         self.stage = 'before_siege'
         self.refresh_users()
         self.get_results()
         send_message(chat_id, 'Текущий этап войны - мир.')
Esempio n. 23
0
 def process_results(self, fight_results):
     if fight_results['won_team'] == 'attacker':
         if self.mode == 'siege':
             button = keyboards.Button('Осадить',
                                       callback_data='_'.join([
                                           'mngt',
                                           str(self.attacker_lobby.chat_id),
                                           'besiege',
                                           str(self.defender_lobby.chat_id),
                                           current_war.id
                                       ]))
             keyboard = keyboards.form_keyboard(button)
             send_message(self.attacker_lobby.chat_id,
                          'Битва выиграна! Вы можете осадить чат {}'.format(
                              self.defender_lobby.name),
                          reply_markup=keyboard)
         elif self.mode == 'attack':
             button = keyboards.Button('Грабить!',
                                       callback_data='_'.join([
                                           'mngt',
                                           str(self.attacker_lobby.chat_id),
                                           'marauder',
                                           str(self.defender_lobby.chat_id),
                                           current_war.id
                                       ]))
             keyboard = keyboards.form_keyboard(button)
             send_message(
                 self.attacker_lobby.chat_id,
                 'Битва выиграна! Вы можете ограбить чат {}'.format(
                     self.defender_lobby.name),
                 reply_markup=keyboard)
     else:
         if self.mode == 'siege':
             send_message(
                 self.attacker_lobby.chat_id,
                 '{} отбивает вашу попытку осады!'.format(
                     self.defender_lobby.name))
         elif self.mode == 'attack':
             send_message(
                 self.attacker_lobby.chat_id,
                 '{} успешно обороняется!'.format(self.defender_lobby.name))
     for user_id in self.get_all_user_ids():
         if user_id in occupied_list:
             occupied_list.remove(user_id)
Esempio n. 24
0
def game_exists_error(chat_id):
    bot_methods.send_message(chat_id,
                             localization.LangTuple('errors', 'game_exists'))
Esempio n. 25
0
 def send_movement_map(self):
     keyboard = self.generate_map_keyboard()
     for member in self.party.members:
         member.message_id = bot_methods.send_message(
             member.chat_id, member.member_string(),
             reply_markup=keyboard).message_id
Esempio n. 26
0
 def greetings_message(self):
     for member in self.dungeon.party.members:
         message = LangTuple(self.table_row, 'greeting').translate(member.lang)
         bot_methods.send_message(member.chat_id, message)
Esempio n. 27
0
 def error(self, error):
     bot_methods.send_message(
         self.chat_id,
         localization.LangTuple('errors', error).translate(self.lang))
Esempio n. 28
0
 def send_message(self, text, image=None):
     send_message(chat_id=self.chat_id, message=text)
Esempio n. 29
0
 def send_message(self, *args):
     message = PlayerString(self)
     message.row(*args)
     message.construct()
     for chat_id in self.chat_id:
         bot_methods.send_message(chat_id, message.result_dict[self.lang])
Esempio n. 30
0
 def add_experience(self, experience):
     send_message(self.user_id, 'Вы получаете {} опыта'.format(experience))
     sql_alchemy.SqlUser.add_experience(self, experience)