def nextturn(self, curplayer):
        for ids in self.traders:
            if ids.fortrade == None:
                tradable = []
                for idss in ids.cards:
                    if idss.dropable:
                        tradable.append(idss)
                ids.fortrade = random.choice(tradable)
                medit(
                    'Время вышло! Была выбрана случайная карта для обмена: "' +
                    ids.fortrade.name + '".', ids.trademessage.chat.id,
                    ids.trademessage.message_id)
        self.traders[0].cards.remove(self.traders[0].fortrade)
        self.traders[1].cards.remove(self.traders[1].fortrade)
        self.traders[0].cards.append(self.traders[1].fortrade)
        self.traders[1].cards.append(self.traders[0].fortrade)
        bot.send_message(
            self.traders[0].id,
            'Обменом получена карта: "' + self.traders[1].fortrade.name + '"!')
        bot.send_message(
            self.traders[1].id,
            'Обменом получена карта: "' + self.traders[0].fortrade.name + '"!')

        curplayer.active = True
        self.currentplayer.active = False
        self.currentplayer = curplayer
        self.currentplayer.turn(self.id)
        self.dropvars()
        self.gametimer = threading.Timer(40, self.nextplayer)
        self.gametimer.start()
Beispiel #2
0
def inline(call): 
    cgame=None
    for ids in game.games:
        g=game.games[ids]
        if call.from_user.id in g.players:
            cgame=g
            try:
                cunit=cgame.players[cgame.currentplayer.id]
            except:
                cunit=None
    if cgame!=None and cunit!=None:
        if cunit.id==call.from_user.id:
            if call.data=='endturn':
                cgame.timer.cancel()
                medit('Выбрано: закончить ход.', call.message.chat.id, call.message.message_id)
                cgame.endturn()
            if call.data=='p_attack':
                units.choicetarget(cunit)
                
            if 'atk' in call.data:
                cgame.currentplayer=None
                medit('Выбрано: атака.', call.message.chat.id, call.message.message_id)
                t=int(call.data.split(' ')[1])
                target=findunit(cgame, t)
                target.recievehit(cunit)
                cgame.endturn()
        else:
            bot.answer_callback_query(call.id, 'Сейчас не ваш ход!')
 def m_update(self):  # Обновление списка игроков
     kb = types.InlineKeyboardMarkup()
     kb.add(
         types.InlineKeyboardButton(text='Присоединиться',
                                    callback_data='join'))
     text = 'Набор участников для экспедиции открыт! Жмите "Присоединиться" для вступления в игру.\nСписок игроков:\n\n'
     for ids in self.playerlist:
         text += self.playerlist[ids].name + '\n'
     medit(text,
           self.message.chat.id,
           self.message.message_id,
           reply_markup=kb)
Beispiel #4
0
def attackmenu(player):
    text = playerinfo(player)
    kb = types.InlineKeyboardMarkup()
    kb.add(
        types.InlineKeyboardButton(text='Физ. атака',
                                   callback_data='p_attack'),
        types.InlineKeyboardButton(text='Скиллы', callback_data='skills'))
    kb.add(
        types.InlineKeyboardButton(text='Инвентарь',
                                   callback_data='inventory'),
        types.InlineKeyboardButton(text='Сменить руку',
                                   callback_data='handchange'))
    kb.add(
        types.InlineKeyboardButton(text='Закончить ход',
                                   callback_data='endturn'))
    if player.message == None:
        msg = bot.send_message(player.id, text, reply_markup=kb)
        player.message = msg
    else:
        medit(text, player.message.chat.id, player.message.message_id)
    def nextplayer(self):
        try:
            if self.onclock == True:
                np = self.currentplayer.number + 1
                if np > len(self.playerlist):
                    np = 1
            else:
                np = self.currentplayer.number - 1
                if np < 1:
                    np = len(self.playerlist)
            for ids in self.playerlist:
                if self.playerlist[ids].number == np:
                    curplayer = self.playerlist[ids]
            if self.currentplayer.ready == False:
                medit('Время вышло!', self.currentplayer.message.chat.id,
                      self.currentplayer.message.message_id)
            self.trade(self.currentplayer, curplayer)

        except Exception as e:
            print('Ошибка:\n', traceback.format_exc())
            bot.send_message(441399484, traceback.format_exc())
Beispiel #6
0
def choicetarget(player):
    cgame = findgame(player=player)
    if cgame != None:
        kb = types.InlineKeyboardMarkup()
        enemys = []
        for ids in cgame.players:
            target = cgame.players[ids]
            if target.team != player.team:
                enemys.append(target)
        for ids in enemys:
            kb.add(
                types.InlineKeyboardButton(text=ids.name + '(' + str(ids.hp) +
                                           '♥️)',
                                           callback_data='atk ' + str(ids.id)))
        kb.add(
            types.InlineKeyboardButton(text='Отмена',
                                       callback_data='mainmenu'))
        if player.message != None:
            medit('Выберите цель.',
                  player.message.chat.id,
                  player.message.message_id,
                  reply_markup=kb)
        else:
            bot.send_message(player['id'], 'Выберите цель.', reply_markup=kb)
Beispiel #7
0
    def turn(self):
        self.second += 1

        for ids in self.teams:
            team = self.teams[ids]
            for unit in team['army']:
                team['army'][unit].shootcd -= 1

        for ids in self.teams:
            team = self.teams[ids]
            for unit in team['army']:
                if team['army'][unit].dead == False:
                    if team['army'][unit].shootcd <= 0:
                        team['army'][unit].shoot(self.teams)
                        team['army'][unit].shootcd = team['army'][
                            unit].shootspeed[1]

        for ids in self.teams:
            team = self.teams[ids]
            for unit in team['army']:
                if team['army'][unit].hp <= 0:
                    team['army'][unit].dead = True

        if self.second % 1 == 0:
            users = []
            for ids in self.teams:
                user = self.teams[ids]['player']
                if user['sendresults'] != False and user[
                        'message'] != None and user['id'] != None:
                    pass  # medit(результаты хп)
                    enemys = ''
                    allies = ''
                    for idss in self.teams:
                        team = self.teams[idss]
                        if team['player']['id'] == user['id']:
                            x = 'ally'
                        else:
                            x = 'enemy'
                        for z in team['army']:
                            unit = team['army'][z]
                            hp = round((unit.hp / unit.maxhp) * 100, 1)
                            if x == 'enemy':
                                emoj = '🔴'
                                enemys += emoj + '|' + unit.name + ': ♥️' + str(
                                    hp) + '%\n'
                            else:
                                emoj = '🔵'
                                allies += emoj + '|' + unit.name + ': ♥️' + str(
                                    hp) + '%\n'
                    try:
                        medit(
                            'Ситуация на поле боя:\n\nСоюзники:\n' + allies +
                            '\nСоперники:\n' + enemys, user['message'].chat.id,
                            user['message'].message_id)
                    except:
                        pass

        alive = []
        for ids in self.teams:
            team = self.teams[ids]
            dead = 0
            for unit in team['army']:
                if team['army'][unit].dead == True:
                    dead += 1
            if dead != len(team['army']):
                alive.append(team)
        if len(alive) <= 1:
            self.endgame(alive)
        else:
            t = threading.Timer(1, self.turn)
            t.start()
Beispiel #8
0
def inline(call):
    if call.data == 'join':
        try:
            game = games[call.message.chat.id]
        except:
            game = None
        if game != None:
            if game.started == False:
                if call.from_user.id not in game.playerlist:
                    game.createplayer(call.from_user)
                    bot.send_message(
                        call.message.chat.id,
                        call.from_user.first_name + ' присоединился!')
                    game.m_update()
        else:
            bot.send_message(
                call.message.chat.id, call.from_user.first_name +
                ', в этом чате нет запущенной игры! Сначала начните её ' +
                'командой /creategame.')
    else:
        try:
            kb = types.InlineKeyboardMarkup()
            game = games[int(call.data.split(' ')[1])]
            for ids in game.playerlist:
                if game.playerlist[ids].id == call.from_user.id:
                    user = game.playerlist[ids]
            chat = game
            if 'playcard' in call.data:
                for ids in user.cards:
                    print(ids)
                    print(ids.name)
                    kb.add(
                        types.InlineKeyboardButton(text=ids.name,
                                                   callback_data='info ' +
                                                   str(chat.id) + ' ' +
                                                   ids.code))
                medit('Выберите карту:',
                      call.message.chat.id,
                      call.message.message_id,
                      reply_markup=kb)

            if 'info' in call.data:
                x = call.data.split(' ')[2]
                text = 'none'
                card = None
                for ids in user.cards:
                    if ids.code == x:
                        card = ids
                print('Карта: ')
                print(card)
                if card != None:
                    text = card.info
                    if card.type != 'unknown' and card.type != 'infection':
                        kb.add(
                            types.InlineKeyboardButton(
                                text='⚡️Использовать карту',
                                callback_data='usecard ' + str(chat.id) + ' ' +
                                card.code))
                    kb.add(
                        types.InlineKeyboardButton(text='↩️Назад',
                                                   callback_data='mainmenu ' +
                                                   str(chat.id)))
                    medit(text,
                          call.message.chat.id,
                          call.message.message_id,
                          reply_markup=kb,
                          parse_mode='markdown')

            if 'trade' in call.data:
                x = call.data.split(' ')[2]
                card = None
                for ids in user.cards:
                    if ids.code == x:
                        card = ids
                if card != None:
                    user.fortrade = card
                    medit('Выбрано для обмена: "' + card.name + '".',
                          call.message.chat.id, call.message.message_id)
                else:
                    bot.answer_callback_query(call.id, 'У вас этого нет!')

            if 'usecard' in call.data:
                x = call.data.split(' ')[2]
                card = None
                for ids in user.cards:
                    if ids.code == x:
                        card = ids
                try:
                    trgt = call.data.split(' ')[3]
                    for ids in chat.playerlist:
                        if chat.playerlist[ids].id == int(trgt):
                            target = chat.playerlist[ids]
                except:
                    target = None
                if card != None:
                    print(card)
                    if card.type == 'action' or card.type == 'barrier':
                        if user.active:
                            if card.targetable:
                                if target == None:
                                    if card.targetall:
                                        enemies = findallenemy(user, game)
                                    else:
                                        enemies = findnearenemy(user, game)
                                    if card.target_self:
                                        enemies.append(user)
                                    for ids in enemies:
                                        kb.add(
                                            types.InlineKeyboardButton(
                                                text=ids.name,
                                                callback_data='usecard ' +
                                                str(chat.id) + ' ' + x + ' ' +
                                                str(ids.id)))
                                    kb.add(
                                        types.InlineKeyboardButton(
                                            text='Назад',
                                            callback_data='mainmenu'))
                                    medit('Выберите цель для карты "' +
                                          card.name + '":',
                                          call.message.chat.id,
                                          call.message.message_id,
                                          reply_markup=kb)
                                else:
                                    if card.cancancelled != []:
                                        t = threading.Timer(
                                            10,
                                            card.use,
                                            args=[user, target, chat])
                                        t.start()
                                        target.defmenu(card)
                                    else:
                                        card.use(user, target, chat)
                                    medit('Выбрано: "' + card.name + '".',
                                          call.message.chat.id,
                                          call.message.message_id)
                            else:
                                try:
                                    enm = call.data.split(' ')[3]
                                except:
                                    enm = None
                                enemy = None
                                if enm != None:
                                    for ids in chat.playerlist:
                                        if chat.playerlist[ids].id == int(enm):
                                            enemy = chat.playerlist[ids]
                                else:
                                    enemy = user
                                if card.cancancelled != []:
                                    t = threading.Timer(
                                        10, card.use, args=[user, enemy, chat])
                                    t.start()
                                    enemy.defmenu(card)
                                else:
                                    card.use(user, enemy, chat)
                                medit('Выбрано: "' + card.name + '".',
                                      call.message.chat.id,
                                      call.message.message_id)
                        else:
                            bot.answer_callback_query(call.id,
                                                      'Сейчас не ваш ход!')

                    elif card.type == 'defence':
                        if user.active == False and user.attacked:
                            pass
                        else:
                            bot.answer_callback_query(
                                call.id,
                                'Эту карту можно сыграть только в ответ на сыгранную на вас карту!'
                            )

        except Exception as e:
            print('Ошибка:\n', traceback.format_exc())
            bot.send_message(441399484, traceback.format_exc())