Exemple #1
0
    def active_action_disp(ilet, skills, rawcards, params, players):
        g = Game.getgame()

        stage = ilet.initiator

        if not skills and not rawcards:
            raise ActionDisplayResult(False, stage.ui_meta.idle_prompt, False,
                                      [], [])

        usage = getattr(ilet.initiator, 'card_usage', 'none')

        if skills:
            if any(not g.me.has_skill(s) for s in skills):
                raise ActionDisplayResult(False, u'您不能这样出牌', False, [], [])
            cards = [thbactions.skill_wrap(g.me, skills, rawcards, params)]
            usage = cards[0].usage if usage == 'launch' else usage
        else:
            cards = rawcards

        card = actv_handle_card_selection(g, stage, cards)
        players, disables, prompt = actv_handle_target_selection(
            g, card, players)

        act = thbactions.ActionStageLaunchCard(g.me, players, card)

        shootdown = act.action_shootdown()
        if shootdown is not None:
            raise ActionDisplayResult(False,
                                      shootdown.ui_meta.shootdown_message,
                                      True, disables, players)

        raise ActionDisplayResult(True, prompt, True, disables, players)
Exemple #2
0
    def passive_action_disp(ilet, skills, rawcards, params, players):
        g = Game.getgame()

        usage = getattr(ilet.initiator, 'card_usage', 'none')

        if skills:
            if any(not g.me.has_skill(s) for s in skills):
                raise ActionDisplayResult(False, u'您不能这样出牌', False, [], [])
            cards = [thbactions.skill_wrap(g.me, skills, rawcards, params)]
            usage = cards[0].usage if usage == 'launch' else usage
        else:
            cards = rawcards

        cards, prompt_card = pasv_handle_card_selection(g, ilet, cards)
        plsel, disables, players, prompt_target = pasv_handle_player_selection(
            g, ilet, players)

        verify = getattr(ilet.initiator, 'ask_for_action_verify', None)
        rst = not verify or verify(g.me, cards, players)
        if not rst:
            raise ActionDisplayResult(False, rst.ui_meta.shootdown_message,
                                      plsel, disables, players)

        raise ActionDisplayResult(True, prompt_target or prompt_card, plsel,
                                  disables, players)
Exemple #3
0
    def active_action_disp(ilet, skills, rawcards, params, players):
        g = Game.getgame()

        stage = ilet.initiator

        if not skills and not rawcards:
            raise ActionDisplayResult(False, stage.ui_meta.idle_prompt, False, [], [])

        usage = getattr(ilet.initiator, 'card_usage', 'none')

        if skills:
            if any(not g.me.has_skill(s) for s in skills):
                raise ActionDisplayResult(False, u'您不能这样出牌', False, [], [])
            cards = [thbactions.skill_wrap(g.me, skills, rawcards, params)]
            usage = cards[0].usage if usage == 'launch' else usage
        else:
            cards = rawcards

        card = actv_handle_card_selection(g, stage, cards)
        players, disables, prompt = actv_handle_target_selection(g, card, players)

        act = thbactions.ActionStageLaunchCard(g.me, players, card)

        shootdown = act.action_shootdown()
        if shootdown is not None:
            raise ActionDisplayResult(False, shootdown.ui_meta.shootdown_message, True, disables, players)

        raise ActionDisplayResult(True, prompt, True, disables, players)
Exemple #4
0
    def try_skill_find(self):
        p = self.ilet.actor
        cl = list(p.cards) + list(p.showncards)
        wrapped = skill_wrap(p, [Find], cl, {})
        act = ActionStageLaunchCard(p, [p], wrapped)
        if act.can_fire():
            self.ilet.set_result(skills=[Find], cards=cl, players=[p])
            return True

        return False
Exemple #5
0
    def passive_action_disp(ilet, skills, rawcards, params, players):
        g = Game.getgame()

        usage = getattr(ilet.initiator, 'card_usage', 'none')

        if skills:
            if any(not g.me.has_skill(s) for s in skills):
                raise ActionDisplayResult(False, u'您不能这样出牌', False, [], [])
            cards = [thbactions.skill_wrap(g.me, skills, rawcards, params)]
            usage = cards[0].usage if usage == 'launch' else usage
        else:
            cards = rawcards

        cards, prompt_card = pasv_handle_card_selection(g, ilet, cards)
        plsel, disables, players, prompt_target = pasv_handle_player_selection(g, ilet, players)

        verify = getattr(ilet.initiator, 'ask_for_action_verify', None)
        rst = not verify or verify(g.me, cards, players)
        if not rst:
            raise ActionDisplayResult(False, rst.ui_meta.shootdown_message, plsel, disables, players)

        raise ActionDisplayResult(True, prompt_target or prompt_card, plsel, disables, players)
Exemple #6
0
    def on_selection_change(self):
        parent = self.parent
        skills = parent.get_selected_skills()
        cards = rawcards = parent.get_selected_cards()

        g = Game.getgame()

        if skills:
            cards = [skills[0].wrap(cards, g.me)]
            for skill_cls in skills[1:]:
                try:
                    isc = getattr(cards[0].ui_meta, 'is_complete', None)
                    if not isc:
                        self.set_text(u'您不能像这样组合技能')
                        return
                    rst, reason = isc(g, cards)
                    if not rst:
                        self.set_text(reason)
                        return
                except Exception as e:
                    self.set_text(u'[card.ui_meta.is_complete错误]')
                    import traceback
                    traceback.print_exc()
                    return

                cards = [skill_cls.wrap(cards, g.me)]

        if not cards:
            self.set_text(u'请出牌…')
            parent.end_select_player()
            return

        if len(cards) != 1:
            self.set_text(u'请选择一张牌使用')
            parent.end_select_player()
            return

        card = cards[0]

        from ..cards import VirtualCard
        if not card.is_card(VirtualCard):
            if not card.resides_in in (g.me.cards, g.me.showncards):
                self.set_text(u'您选择的牌不符合出牌规则')
                parent.end_select_player()
                return

        target_list, tl_valid = card.target(g, g.me,
                                            parent.get_selected_players())
        if target_list is not None:
            parent.set_selected_players(target_list)
            disables = []
            # if card.target in (thbcards.t_One, thbcards.t_OtherOne):
            if card.target.__name__ in ('t_One', 't_OtherOne'):
                for p in g.players:
                    act = thbactions.ActionStageLaunchCard(g.me, [p], card)
                    if not act.can_fire():
                        disables.append(p)

            parent.begin_select_player(disables)
            for i in disables:
                try:
                    target_list.remove(i)
                except ValueError:
                    pass

        try:
            rst, reason = card.ui_meta.is_action_valid(g, cards, target_list)
        except Exception as e:
            log.exception(e)
            rst, reason = (True, u'[card.ui_meta.is_action_valid错误]')

        self.set_text(reason)
        if not rst:
            return

        if tl_valid:
            act = thbactions.ActionStageLaunchCard(g.me, target_list, card)

            if skills:
                card = thbactions.skill_wrap(g.me,
                                             skills,
                                             rawcards,
                                             no_reveal=True)

            if card and act.can_fire():
                self.set_valid()
            else:
                self.set_text(u'您不能这样出牌')
        else:
            self.set_text(u'您选择的目标不符合规则')
Exemple #7
0
    def on_selection_change(self):
        parent = self.parent
        skills = parent.get_selected_skills()
        cards = rawcards = parent.get_selected_cards()

        g = Game.getgame()

        if skills:
            cards = [skills[0].wrap(cards, g.me)]
            for skill_cls in skills[1:]:
                try:
                    isc = getattr(cards[0].ui_meta, 'is_complete', None)
                    if not isc:
                        self.set_text(u'您不能像这样组合技能')
                        return
                    rst, reason = isc(g, cards)
                    if not rst:
                        self.set_text(reason)
                        return
                except Exception as e:
                    self.set_text(u'[card.ui_meta.is_complete错误]')
                    import traceback
                    traceback.print_exc()
                    return

                cards = [skill_cls.wrap(cards, g.me)]

        if not cards:
            self.set_text(u'请出牌…')
            parent.end_select_player()
            return

        if len(cards) != 1:
            self.set_text(u'请选择一张牌使用')
            parent.end_select_player()
            return

        card = cards[0]

        from ..cards import VirtualCard
        if not card.is_card(VirtualCard):
            if not card.resides_in in (g.me.cards, g.me.showncards):
                self.set_text(u'您选择的牌不符合出牌规则')
                parent.end_select_player()
                return

        target_list, tl_valid = card.target(g, g.me, parent.get_selected_players())
        if target_list is not None:
            parent.set_selected_players(target_list)
            disables = []
            # if card.target in (thbcards.t_One, thbcards.t_OtherOne):
            if card.target.__name__ in ('t_One', 't_OtherOne'):
                for p in g.players:
                    act = thbactions.ActionStageLaunchCard(g.me, [p], card)
                    if not act.can_fire():
                        disables.append(p)

            parent.begin_select_player(disables)
            for i in disables:
                try:
                    target_list.remove(i)
                except ValueError:
                    pass

        try:
            rst, reason = card.ui_meta.is_action_valid(g, cards, target_list)
        except Exception as e:
            log.exception(e)
            rst, reason = (True, u'[card.ui_meta.is_action_valid错误]')

        self.set_text(reason)
        if not rst:
            return

        if tl_valid:
            act = thbactions.ActionStageLaunchCard(g.me, target_list, card)

            if skills:
                card = thbactions.skill_wrap(g.me, skills, rawcards, no_reveal=True)

            if card and act.can_fire():
                self.set_valid()
            else:
                self.set_text(u'您不能这样出牌')
        else:
            self.set_text(u'您选择的目标不符合规则')