Exemplo n.º 1
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)
             send_message(
                 self.defender_lobby.chat_id,
                 'Битва проиграна! Вас может осадить чат {}'.format(
                     self.attacker_lobby.name))
         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)
             send_message(
                 self.defender_lobby.chat_id,
                 'Битва проиграна! Вас может ограбить чат {}'.format(
                     self.attacker_lobby.name))
     else:
         if self.mode == 'siege':
             send_message(
                 self.attacker_lobby.chat_id,
                 '{} отбивает вашу попытку осады!'.format(
                     self.defender_lobby.name))
             send_message(
                 self.defender_lobby.chat_id,
                 'Вы успешно обороняетесь от {}!'.format(
                     self.attacker_lobby.name))
         elif self.mode == 'attack':
             send_message(
                 self.attacker_lobby.chat_id,
                 '{} успешно обороняется!'.format(self.defender_lobby.name))
             send_message(
                 self.defender_lobby.chat_id,
                 'Вы успешно обороняетесь от {}!'.format(
                     self.attacker_lobby.name))
     for user_id in self.get_all_user_ids():
         if user_id in occupied_list:
             occupied_list.remove(user_id)
Exemplo n.º 2
0
 def ask_attack(self, user_id, message_id):
     if current_war.stage == 'siege':
         string = 'Выберите чат для начала осады'
         targets = self.get_target_chats()
         buttons = []
         for target in targets:
             buttons.append(
                 keyboards.Button(target.name + ' - ' +
                                  str(self.get_attack_price(target)),
                                  callback_data='_'.join(
                                      ['mngt', 'attack', target.chat_id])))
         keyboard = keyboards.form_keyboard(*buttons)
     elif current_war.stage == 'attack':
         string = 'Выберите чат на атаки'
         targets = self.get_target_chats()
         buttons = []
         for target in targets:
             buttons.append(
                 keyboards.Button(target.name,
                                  callback_data='_'.join(
                                      ['mngt', 'attack', target.chat_id])))
         keyboard = keyboards.form_keyboard(*buttons)
     else:
         delete_message(user_id, message_id)
         return False
     if self.ask_rights(user_id) == 'admin':
         edit_message(user_id, message_id, string, reply_markup=keyboard)
     else:
         self.send_message('У вас нет прав. Вы бесправный.')
Exemplo n.º 3
0
 def activate(self):
     keyboard = keyboards.form_keyboard(
         *keyboards.get_item_buttons(self.unit),
         keyboards.MenuButton(self.unit, 'back'))
     self.unit.controller.edit_message(localization.LangTuple(
         'utils', 'items'),
                                       reply_markup=keyboard)
Exemplo n.º 4
0
 def get_item_menu(self, item_id, item_name):
     buttons = []
     item = self.get_item_object(item_id, item_name=item_name)
     table_row = item.table_row
     actions = self.get_item_actions(item, item_id)
     for action in actions:
         buttons.append(
             keyboards.DungeonButton(action[0],
                                     self.member,
                                     'item',
                                     action[1],
                                     item_id,
                                     item_name,
                                     named=True))
     buttons.append(
         keyboards.DungeonButton('Назад',
                                 self.member,
                                 'item',
                                 'menu',
                                 named=True))
     keyboard = keyboards.form_keyboard(*buttons)
     text = LangTuple(table_row, 'name').translate(self.member.lang) + '\n' \
            + LangTuple(table_row, 'desc').translate(self.member.lang)
     self.member.edit_message(text, reply_markup=keyboard)
     self.member.menu.update()
Exemplo n.º 5
0
 def update_menu(self):
     buttons = self.inventory_buttons()
     keyboard = form_keyboard(*buttons)
     self.member.edit_message(LangTuple('utils_inventory',
                                        'name').translate(self.member.lang),
                              reply_markup=keyboard)
     self.member.menu.update()
Exemplo n.º 6
0
 def send_choice(self, member):
     text = 'Выберите предмет, который хотите улучшить'
     buttons = []
     valid_items = [
         item for item in member['inventory'] if 'improved' in item.keys()
     ]
     if 'improved' in member['weapon']:
         valid_items.append(member['weapon'])
     for item in valid_items:
         if not item['improved']:
             buttons.append(
                 keyboards.DungeonButton(member.inventory.get_item_name(
                     item, member.lang),
                                         member,
                                         'location',
                                         'improve',
                                         item['id'],
                                         named=True))
     buttons.append(
         keyboards.DungeonButton('Закрыть',
                                 member,
                                 'menu',
                                 'main',
                                 named=True))
     keyboard = keyboards.form_keyboard(*buttons)
     member.edit_message(text, reply_markup=keyboard)
Exemplo n.º 7
0
 def get_exit_keyboard(mmbr):
     keyboard = form_keyboard(
         DungeonButton('Покинуть карту',
                       mmbr,
                       'menu',
                       'defeat',
                       named=True))
     return keyboard
Exemplo n.º 8
0
 def target_keyboard(self):
     return keyboards.form_keyboard(
         *[
             keyboards.OptionObject(
                 self,
                 name=(unit.name if isinstance(unit.name, str) else
                       unit.name.str(self.unit.controller.lang)),
                 option=unit) for unit in self.targets()
         ], keyboards.MenuButton(self.unit, 'back'))
Exemplo n.º 9
0
 def activate(self):
     keyboard = keyboards.form_keyboard(
         *[
             ability.button() for ability in self.unit.abilities
             if ability.available()
         ], keyboards.MenuButton(self.unit, 'back'))
     self.unit.controller.edit_message(localization.LangTuple(
         'utils', 'abilities'),
                                       reply_markup=keyboard)
Exemplo n.º 10
0
 def get_action(self):
     keyboard = keyboards.form_keyboard()
     for target in self.targets():
         if target in self.unit.team.actors:
             if target.alive() and target != self.unit:
                 keyboard.add(self.special_button(target))
         else:
             keyboard.add(keyboards.AttackButton(self.unit, target))
     self.create_menu(keyboard)
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def get_action_keyboard(self, member):
     buttons = self.get_button_list()
     buttons = [(self.get_button_tuples(member.lang)[str(button[0])],
                 button[1]) for button in buttons]
     keyboard = form_keyboard(*[
         self.create_button(
             button[0], member, 'location', button[1], named=True)
         for button in buttons
     ])
     return keyboard
Exemplo n.º 13
0
 def keyboard(self):
     buttons = [
         types.InlineKeyboardButton(
             url='https://telegram.me/test_env_2_bot?start=join_{}'.format(
                 self.id),
             text='Присоединиться'),
         keyboards.Button('Начать бой',
                          '_'.join(['lobby',
                                    str(self.id), 'startlobby']))
     ]
     keyboard = keyboards.form_keyboard(*buttons, row_width=2)
     return keyboard
Exemplo n.º 14
0
 def get_action_keyboard(self, member):
     buttons = self.get_button_list()['encounter']
     print(buttons)
     if buttons:
         buttons = [(self.get_button_tuples(member.lang)[str(button[0])], str(button[0])) for button in buttons]
         keyboard = form_keyboard(*[self.create_button(button[0], member, 'location', str(button[1]),
                                                       named=True) for button in buttons])
         self.action_expected = True
         return keyboard
     else:
         self.action_expected = False
         return
Exemplo n.º 15
0
    def get_victory_keyboard(self):
        self.state = 'totem_available'
        buttons = [('Взять тотем', 'take_totem'),
                   ('Оставить тотем', 'leave_totem')]

        keyboard = keyboards.form_keyboard(*[
            self.create_button(button[0],
                               self.dungeon.party.leader,
                               'location',
                               button[1],
                               named=True) for button in buttons
        ])
        return keyboard
Exemplo n.º 16
0
 def run(self):
     self.member.occupied = True
     buttons = []
     for ability in self.ability_list:
         buttons.append(
             keyboards.DungeonButton(
                 'name',
                 self,
                 'lvl',
                 ability,
                 special=abilities.ability_dict[ability](
                     None).get_table_row(),
             ))
     buttons.append(
         keyboards.DungeonButton('Назад', self, 'lvl', 'back', named=True))
     keyboard = keyboards.form_keyboard(*buttons)
     self.member.send_message('Выберите новую способность',
                              reply_markup=keyboard)
Exemplo n.º 17
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)
Exemplo n.º 18
0
    def menu_keyboard(self):
        buttons = list()

        buttons.append(
            keyboards.DungeonButton('Инвентарь',
                                    self,
                                    'menu',
                                    'inventory',
                                    named=True))
        buttons.append(
            keyboards.DungeonButton('На карту',
                                    self,
                                    'menu',
                                    'map',
                                    named=True))
        buttons.append(
            keyboards.DungeonButton('Покинуть карту',
                                    self,
                                    'menu',
                                    'leave',
                                    named=True))
        if len(self.dungeon.party.members) > 1:
            buttons.append(
                keyboards.DungeonButton('Обмен',
                                        self,
                                        'menu',
                                        'give',
                                        named=True))

        idle_buttons = self.dungeon.party.current_location.get_button_list(
        )['idle']
        idle_buttons = [(self.dungeon.party.current_location.get_button_tuples(
            self.lang)[str(button[0])], str(button[0]))
                        for button in idle_buttons]
        for button in idle_buttons:
            buttons.append(
                keyboards.DungeonButton(button[0],
                                        self,
                                        'location',
                                        str(button[1]),
                                        named=True))
        keyboard = form_keyboard(*buttons)
        return keyboard
Exemplo n.º 19
0
 def ask_target(self, spell_tuple):
     self.unit.active = True
     string = 'Выберите цель.'
     targets = [*self.unit.targets(), *self.unit.get_allies()]
     buttons = []
     for target in targets:
         buttons.append(
             keyboards.FightButton(
                 (target.name if isinstance(target.name, str) else
                  target.name.str(self.unit.controller.lang)),
                 self.unit,
                 self.types[0],
                 self.name,
                 str(target),
                 spell_tuple,
                 named=True))
     buttons.append(keyboards.MenuButton(self.unit, 'back'))
     keyboard = keyboards.form_keyboard(*buttons)
     self.unit.controller.edit_message(string, reply_markup=keyboard)
Exemplo n.º 20
0
 def ask_start_option(self):
     buttons = []
     weapon_list = [
         weapon for weapon in weapons.weapon_list
         if 'arsenal' in weapon.types
     ]
     for w in weapon_list:
         buttons.append(
             keyboards.AbilityChoice(self,
                                     self.actor,
                                     option=w.name,
                                     name=localization.LangTuple(
                                         '_'.join(['weapon', w.name]),
                                         'name').translate(
                                             self.actor.lang)))
         buttons.append(keyboards.WeaponInfo(w, self.actor))
     keyboard = keyboards.form_keyboard(*buttons)
     self.actor.active = True
     self.actor.edit_message(localization.LangTuple('abilities_arsenal',
                                                    'options'),
                             reply_markup=keyboard)
Exemplo n.º 21
0
 def ask_start_option(self):
     buttons = []
     weapon_list = [
         weapon for weapon in weapons.weapon_list
         if 'unique' not in weapon.types
     ]
     weapon_list = random.sample(set(weapon_list), 3)
     for w in weapon_list:
         buttons.append(
             keyboards.AbilityChoice(self,
                                     self.actor,
                                     option=w.name,
                                     name=localization.LangTuple(
                                         '_'.join(['weapon', w.name]),
                                         'name').translate(
                                             self.actor.lang)))
     keyboard = keyboards.form_keyboard(*buttons)
     self.actor.active = True
     self.actor.edit_message(localization.LangTuple(
         'abilities_weapon-master', 'options'),
                             reply_markup=keyboard)
Exemplo n.º 22
0
 def get_buttons_members_to_give(self, item_id):
     buttons = []
     members = self.dungeon.party.member_dict
     for key in members:
         if key != self.chat_id:
             call_data = item_id
             buttons.append(
                 keyboards.DungeonButton(members[key].name,
                                         self,
                                         'item',
                                         'give',
                                         str(call_data),
                                         str(key),
                                         named=True))
     buttons.append(
         keyboards.DungeonButton('Закрыть',
                                 self,
                                 'menu',
                                 'main',
                                 named=True))
     keyboard = form_keyboard(*buttons)
     return keyboard
Exemplo n.º 23
0
 def menu_keyboard(self):
     buttons = list()
     buttons.append(
         keyboards.DungeonButton('Инвентарь',
                                 self,
                                 'menu',
                                 'inventory',
                                 named=True))
     buttons.append(
         keyboards.DungeonButton('На карту',
                                 self,
                                 'menu',
                                 'map',
                                 named=True))
     buttons.append(
         keyboards.DungeonButton('Покинуть карту',
                                 self,
                                 'menu',
                                 'leave',
                                 named=True))
     if len(self.dungeon.party.members) > 1:
         buttons.append(
             keyboards.DungeonButton('Обмен',
                                     self,
                                     'menu',
                                     'give',
                                     named=True))
     for button in self.dungeon.party.current_location.buttons(self):
         buttons.append(
             keyboards.DungeonButton(button['name'],
                                     self,
                                     'location',
                                     button['act'],
                                     named=True))
     keyboard = form_keyboard(*buttons)
     return keyboard
Exemplo n.º 24
0
 def inventory_menu(self, give=False):
     buttons = self.inventory_buttons() if not give else self.give_buttons()
     keyboard = form_keyboard(*buttons)
     self.member.edit_message(
         text='Инвентарь' if not give else 'Выберите предмет для передачи.',
         reply_markup=keyboard)
Exemplo n.º 25
0
 def target_keyboard(self, action=None, row_width=2):
     return keyboards.form_keyboard(*self.options_keyboard(action=action),
                                    keyboards.MenuButton(self.unit, 'back'),
                                    row_width=row_width)
Exemplo n.º 26
0
 def generate_map_keyboard(self):
     buttons = [
         room.return_button()
         for room in self.party.current_location.get_visible()
     ]
     return keyboards.form_keyboard(*buttons, row_width=3)
Exemplo n.º 27
0
 def get_menu_keyboard(self):
     buttons = [action.button_to_page() for action in self.children_actions]
     if self.parent_menu is not None:
         buttons.append(self.get_parent_menu().button_to_page(name='Назад'))
     return form_keyboard(*buttons)
Exemplo n.º 28
0
 def get_action(self):
     keyboard = keyboards.form_keyboard(*self.attack_buttons())
     if self.special_available(target=None):
         keyboard.add(self.special_button(target=None))
     self.create_menu(keyboard)
Exemplo n.º 29
0
 def get_action(self):
     keyboard = keyboards.form_keyboard()
     for target in self.targets():
         keyboard.add(keyboards.AttackButton(self.unit, target), self.special_button(target=target)) if \
             self.special_available(target=target) else keyboard.add(keyboards.AttackButton(self.unit, target))
     self.create_menu(keyboard)
Exemplo n.º 30
0
 def target_keyboard(self):
     return keyboards.form_keyboard(*self.options_keyboard(),
                                    keyboards.MenuButton(self.unit, 'back'), row_width=3)