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)
def actv_handle_target_selection(g, card, players): plsel = False selected = [] disables = [] target_list, tl_valid = card.target(g, g.me, players) if target_list is not None: selected = target_list[:] # 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) shootdown = act.action_shootdown() if shootdown is not None: if shootdown.ui_meta.target_independent: reason = shootdown.ui_meta.shootdown_message raise ActionDisplayResult(False, reason, False, [], []) disables.append(p) plsel = True for i in disables: try: target_list.remove(i) except ValueError: pass try: rst, reason = card.ui_meta.is_action_valid(g, [card], target_list) except Exception as e: log.exception(e) raise ActionDisplayResult(False, u'[card.ui_meta.is_action_valid错误]', False, [], []) if not rst: raise ActionDisplayResult(False, reason, plsel, disables, selected) if not tl_valid: # honor result of game logic raise ActionDisplayResult(False, u'您选择的目标不符合规则', plsel, disables, selected) return target_list, disables, reason
def on_selection_change(self): parent = self.parent skills = parent.get_selected_skills() cards = 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 cards: while True: if len(cards) != 1: break card = cards[0] from ..cards import VirtualCard if not (card.is_card(VirtualCard) or card.resides_in in (g.me.cards, g.me.showncards)): break 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 rst: if tl_valid: act = thbactions.ActionStageLaunchCard( g.me, target_list, card) if act.can_fire(): self.set_valid() else: self.set_text(u'您不能这样出牌') else: self.set_text(u'您选择的目标不符合规则') return self.set_text(u'您选择的牌不符合出牌规则') else: self.set_text(u'请出牌…') parent.end_select_player()