示例#1
0
文件: bot.py 项目: Tydus/BloodBound
    def skill10(self):
        player = self.victim

        if self.available_curse == []:
            self.log.append(_("%s have no curse books left") % player)
            return

        candidate = [x for x in self.players if x != player]

        while self.available_curse != []:
            __, selection = yield from single_choice(
                original_message=self.m,
                candidate=list(map(E.get, self.available_curse)),
                whitelist=[target],
                text=self.generate_game_message(
                    _("%s select a curse book:") % target.mention_html(), ),
                static_buttons=self.static_buttons,
            )
            curse = self.available_curse[selection]

            __, selection = yield from single_choice(
                original_message=self.m,
                candidate=candidate,
                whitelist=[player],
                text=self.generate_game_message(
                    _("%s give a curse book to a player:") % player, ),
                static_buttons=self.static_buttons,
            )
            target = candidate[selection]

            self.player_data[target]['item'].append(curse)
            self.available_curse.remove(curse)
            candidate.remove(target)

            self.log.append(_("%s gave %s to %s") % (player, E[curse], target))
示例#2
0
文件: bot.py 项目: Tydus/BloodBound
    def skill4(self):
        if not self.saved_victim:
            return

        player = self.victim

        data = self.player_data[self.saved_victim]

        if not data['token_used']:
            selection = 0  # kill
            self.log.append(
                _("%s has no token shown, %s must kill %s") % (
                    self.saved_victim,
                    self.victim,
                    self.saved_victim,
                ))
        else:
            __, selection = yield from single_choice(
                original_message=self.m,
                candidate=[_("Kill"), _("Heal")],
                whitelist=[player],
                text=self.generate_game_message(
                    _("%s select kill or heal:") % player.mention_html(), ),
                static_buttons=self.static_buttons,
            )

        if selection == 0:
            # Temporarily switch victim
            self.victim = self.saved_victim
            self.log.append(_("%s killed %s") % (player, self.saved_victim))
            yield from self.select_and_apply_token()
            self.victim = player

        else:
            candidate = data['token_used']
            if len(candidate) == 1:
                selected_token = candidate[0]
            else:
                __, selection = yield from single_choice(
                    original_message=self.m,
                    candidate=[E[i[0]] for i in candidate],
                    whitelist=[self.saved_victim],
                    text=self.generate_game_message(
                        _("%s select token for healing:") %
                        self.saved_victim.mention_html(), ),
                    static_buttons=self.static_buttons,
                )

                selected_token = candidate[selection]

            self.log.append(_("%s healed %s") % (player, self.saved_victim))

            data['token_available'].append(selected_token[-1])
            data['token_used'].remove(selected_token)
示例#3
0
文件: bot.py 项目: Tydus/BloodBound
    def skill6(self):
        player = self.victim
        pdata = self.player_data[player]

        if pdata['token_available'] == []:
            self.log.append(
                _("%s already has 3 tokens, not triggering skill") % player, )
            return

        color = self.available_shields[pdata['rank']]

        candidate = [x for x in self.players if x != player]

        __, selection = yield from single_choice(
            original_message=self.m,
            candidate=candidate,
            whitelist=[player],
            text=self.generate_game_message(
                _("%s give a shield to a player:") % player.mention_html(), ),
            static_buttons=self.static_buttons,
        )

        target = candidate[selection]
        data = self.player_data[target]

        if ('sword%s' % color[0]) not in pdata['item']:
            pdata['item'].append('sword%s' % color[0])
        data['item'].append('shield%s' % color[0])

        self.log.append(_("%s gave a shield to %s") % (player, target))

        self.shields.append({'sword': player, 'shield': target})
示例#4
0
文件: bot.py 项目: Tydus/BloodBound
    def skill3(self):
        player = self.victim
        pdata = self.player_data[player]

        for i in [_("1st"), _("2nd")]:
            candidate = [
                x for x in self.players
                if x != player and x not in pdata['checked']
            ]

            if not candidate:
                self.log.append(_("No enough player to be checked."))
                break

            __, selection = yield from single_choice(
                original_message=self.m,
                candidate=candidate,
                whitelist=[player],
                text=self.generate_game_message(
                    _("%s select %s player to check:") %
                    (player.mention_html(), i), ),
                static_buttons=self.static_buttons,
            )

            target = candidate[selection]
            pdata['checked'].append(target)
            self.log.append(_("%s checked %s") % (player, target))
示例#5
0
文件: bot.py 项目: Tydus/BloodBound
    def select_and_apply_token(self, instruction=None, forced=None):
        data = self.player_data[self.victim]

        if not data['token_available']:
            self.game_end = True
            return None

        if forced:
            selected_token = forced
            assert selected_token in data['token_available']
        else:
            while True:
                candidate = ['r', 'b', 'w', 's']

                update, selection = yield from single_choice(
                    original_message=self.m,
                    candidate=list(map(E.get, candidate)),
                    whitelist=[self.victim],
                    static_buttons=self.static_buttons,
                    text=self.generate_game_message(
                        instruction or (_("%s select token:") %
                                        self.victim.mention_html(), ), ),
                )

                # validate token selection
                selected_token = candidate[selection]

                if selected_token in data['token_available']:
                    break

                # white faction
                if 'a' in data['token_available'] and selected_token != 's':
                    selected_token += 'a'
                    break

                update.callback_query.answer(
                    _("Selection invalid, please retry."), True)

        # convert skill token to display token
        if selected_token == 's':
            selected_token = str(abs(data['rank']) % 10) + 's'

        data['token_available'].remove(selected_token[-1])
        data['token_used'].append(selected_token)

        # Skill 6
        if data['token_available'] == [] and abs(data['rank']) == 6:
            self.skill6_invalidate()

        return selected_token
示例#6
0
文件: bot.py 项目: Tydus/BloodBound
    def get_action(self):
        data = self.player_data[self.knife]

        if abs(data['rank']) == 10 and data['token_available'] == []:
            # Skill 10
            self.log.append(_("Inquisitor %s cannot attack") % self.knife)
            is_give = 1
            new_message = True
        else:
            update, selection = yield from single_choice(
                original_message=self.m,
                candidate=[_("Attack"), _("Pass")],
                whitelist=[self.knife],
                text=self.generate_game_message(
                    _("%s select action") % self.knife.mention_html(), ),
                static_buttons=self.static_buttons,
                new_message=True,
            )
            is_give = (selection == 1)
            new_message = False
            self.m = update.callback_query.message

        candidate = [x for x in self.players if x != self.knife]
        update, selection = yield from single_choice(
            original_message=self.m,
            candidate=candidate,
            whitelist=[self.knife],
            text=self.generate_game_message(
                _("%s select target") % self.knife.mention_html(), ),
            static_buttons=self.static_buttons,
            new_message=new_message,
        )
        self.m = update.callback_query.message
        target = candidate[selection]

        return target, is_give
示例#7
0
文件: bot.py 项目: Tydus/BloodBound
    def skill9(self):
        player = self.victim

        candidate = [
            x for x in self.players
            if x != player and 'fan' not in self.player_data[x]['item']
        ]

        __, selection = yield from single_choice(
            original_message=self.m,
            candidate=candidate,
            whitelist=[player],
            text=self.generate_game_message(
                _("%s give the fan to a player:") % player.mention_html(), ),
            static_buttons=self.static_buttons,
        )

        target = candidate[selection]
        self.player_data[target]['item'].append('fan')
        self.log.append(_("%s gave a fan to %s") % (player, target))
示例#8
0
文件: bot.py 项目: Tydus/BloodBound
    def skill2(self):
        player = self.victim

        candidate = [x for x in self.players if x != player]

        __, selection = yield from single_choice(
            original_message=self.m,
            candidate=candidate,
            whitelist=[player],
            text=self.generate_game_message(
                _("%s a player to trigger skill:") % player.mention_html(), ),
            static_buttons=self.static_buttons,
        )
        self.victim = candidate[selection]
        self.log.append(_("%s casted skill on %s") % (player, self.victim))

        for i in [_("1st"), _("2nd")]:
            yield from self.select_and_apply_token(
                instruction=_("%s select %s token:") %
                (self.victim.mention_html, i), )
示例#9
0
文件: bot.py 项目: Tydus/BloodBound
    def skill8(self):
        player = self.victim
        pdata = self.player_data[player]

        if 'staff' not in pdata['item']:
            pdata['item'].append('staff')

            # Permanently convert available color tokens to 'white'
            pdata['token_available'] = list(
                map(
                    lambda x: 's' if x == 's' else 'w',
                    pdata['token_available'],
                ))

        candidate = [
            x for x in self.players
            if x != player and 'staff' not in self.player_data[x]['item']
        ]

        __, selection = yield from single_choice(
            original_message=self.m,
            candidate=candidate,
            whitelist=[player],
            text=self.generate_game_message(
                _("%s give the staff to a player:") % player.mention_html(), ),
            static_buttons=self.static_buttons,
        )

        target = candidate[selection]
        data = self.player_data[target]
        data['item'].append('staff')

        # Permanently convert available color tokens to 'white'
        data['token_available'] = list(
            map(
                lambda x: 's' if x == 's' else 'w',
                data['token_available'],
            ))

        self.log.append(_("%s gave a staff to %s") % (player, target))
示例#10
0
文件: bot.py 项目: Tydus/BloodBound
    def skill5(self):
        player = self.victim

        candidate = [x for x in self.players if x != player]

        __, selection = yield from single_choice(
            original_message=self.m,
            candidate=candidate,
            whitelist=[player],
            text=self.generate_game_message(
                _("%s a player to trigger skill:") % player.mention_html(), ),
            static_buttons=self.static_buttons,
        )

        self.victim = candidate[selection]
        self.log.append(_("%s casted skill on %s") % (player, self.victim))

        if 's' in self.player_data[self.victim]['token_available']:
            forced = 's'
        else:
            forced = None
        yield from self.select_and_apply_token(forced=forced)
示例#11
0
文件: bot.py 项目: Tydus/BloodBound
    def interfere(self):
        self.saved_victim = None

        candidate = []
        for player, data in self.player_data.items():
            if player == self.knife or player == self.victim:
                continue
            if 's' in data['token_available']:
                candidate.append(player)

        if len(candidate) == 0:
            return

        guardians = []
        blacklist = []

        # stick to a same ID so consequential choices (made by other players) can also be accepted
        # repeated-choice will be blocked by blacklist
        id = uuid.uuid4()

        # TODO: set a timeout

        while len(candidate) != len(blacklist):
            update, selection = yield from single_choice(
                original_message=self.m,
                candidate=[_("Interfere"), _("Pass")],
                whitelist=candidate,
                blacklist=blacklist,
                id=id,
                text=self.generate_game_message(
                    _("everyone else select interfere or pass")),
                static_buttons=self.static_buttons,
            )

            blacklist.append(update.effective_user)

            if selection == 0:  # interfere
                guardians.append(update.effective_user)

            self.log.append(
                _("%s choosed %s") % (
                    update.effective_user,
                    [_("Interfere"), _("Pass")][selection],
                ))

            #self.display_game_message()

        # victim decide
        if len(guardians) == 0:
            return

        __, selection = yield from single_choice(
            original_message=self.m,
            candidate=guardians + [_("None")],
            whitelist=[self.victim],
            static_buttons=self.static_buttons,
            text=self.generate_game_message(
                _("%s accept interfere?") % self.victim.mention_html(), ),
        )

        if selection == len(guardians):  # The (n+1)-th button
            self.log.append(_("%s rejected interference") % self.victim)
        else:
            self.log.append(
                _("%s accepted %s's interference") %
                (self.victim, guardians[selection]))
            self.saved_victim, self.victim = self.victim, guardians[selection]
            return True

        return False