Esempio n. 1
0
    def testChooseOptionInputlet(self):
        from game import autoenv
        from game.autoenv import user_input
        from client.core import TheChosenOne, PeerPlayer

        from gamepack.thb.thb3v3 import THBattle
        from gamepack.thb.inputlets import ChooseOptionInputlet
        from utils import BatchList

        autoenv.init('Server')
        g = THBattle()
        g.IS_DEBUG = True
        pl = [create_mock_player([]) for i in xrange(6)]
        p = pl[0]
        g.me = p
        p.client.gdlist.extend([
            ['I:ChooseOption:1', True],
            ['I&:ChooseOption:2', False],
            ['I|:ChooseOption:3', True],
        ])
        p.client.gdevent.set()
        g.players = BatchList(pl)
        hook_game(g)

        ilet = ChooseOptionInputlet(self)

        eq_(user_input([p], ilet), True)
        eq_(user_input([p], ilet, type='all'), {p: False})
        eq_(user_input([p], ilet, type='any'), (p, True))

        for p in pl:
            eq_(p.client.gdhistory, [
                ['RI:ChooseOption:1', True],
                ['RI&:ChooseOption:2', False],
                ['RI|:ChooseOption:3', True],
            ])

        autoenv.init('Client')
        g = THBattle()
        pl = [PeerPlayer() for i in xrange(6)]
        svr = MockConnection([
            ['RI:ChooseOption:1', True],
            ['RI&:ChooseOption:2', False],
            ['RI|:ChooseOption:3', True],
        ])
        p = TheChosenOne(svr)
        pl[0] = p
        g.me = p
        svr.gdevent.set()
        g.players = BatchList(pl)
        hook_game(g)
        assert autoenv.Game.getgame() is g

        ilet = ChooseOptionInputlet(self)

        eq_(user_input([p], ilet), True)
        eq_(user_input([p], ilet, type='all'), {p: False})
        eq_(user_input([p], ilet, type='any'), (p, True))
Esempio n. 2
0
    def getInputletInstances(self):
        from gamepack.thb.cards import AttackCard
        from gamepack.thb.characters.youmu import Youmu
        from gamepack.thb.common import CharChoice
        from gamepack.thb.inputlets import ActionInputlet
        from gamepack.thb.inputlets import ChooseGirlInputlet
        from gamepack.thb.inputlets import ChooseIndividualCardInputlet
        from gamepack.thb.inputlets import ChooseOptionInputlet
        from gamepack.thb.inputlets import ChoosePeerCardInputlet
        from gamepack.thb.inputlets import ProphetInputlet

        g, p = self.makeGame()

        ilets = [
            ActionInputlet(self, ['cards', 'showncards'], []),
            ChooseGirlInputlet(self, {p: [CharChoice(Youmu)]}),
            ChooseIndividualCardInputlet(self, [AttackCard()]),
            ChooseOptionInputlet(self),
            ChoosePeerCardInputlet(self, p, ['cards']),
            ProphetInputlet(self, [AttackCard()]),
        ]

        for i in ilets:
            i.actor = p

        return g, p, ilets
Esempio n. 3
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and hasattr(act, 'associated_card'):
            g = Game.getgame()
            lc = g.action_stack[-1]

            for lc in reversed(g.action_stack):
                if isinstance(lc,
                              (LaunchCard,
                               LaunchFatetellCard)) and lc.card_action is act:
                    break
            else:
                return act

            me = g.current_player
            if not me or not me.has_skill(Tianyi):
                return act

            while True:
                if isinstance(act, SpellCardAction): break
                if isinstance(act, ForEach) and issubclass(
                        act.action_cls, SpellCardAction):
                    break  # Another HACK
                return act

            if ttags(me)['mima_tianyi']:
                return act

            if not user_input([me], ChooseOptionInputlet(self, (False, True))):
                return act

            g.process_action(TianyiAction(me, lc))

        return act
Esempio n. 4
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, Damage):
            if act.cancelled:
                return act

            src, tgt = act.source, act.target
            if not (src and src.has_skill(PerfectFreeze)):
                return act

            g = Game.getgame()
            for lc in reversed(g.action_stack):
                if isinstance(lc, LaunchCard):
                    break
            else:
                return act

            if src is not lc.source:
                return act

            c = lc.card
            if not c.is_card(AttackCard) and not c.is_card(DuelCard):
                return act

            if not user_input([src], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act

            g.process_action(PerfectFreezeAction(src, tgt, act))

        return act
Esempio n. 5
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, DropCardStage):
            self.n = n = act.dropn
            if n <= 0:
                return act

            tgt = act.target
            if not tgt.has_skill(AutumnWind):
                return act

            g = Game.getgame()
            if not user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                return act

            candidates = [
                p for p in g.players if
                p is not tgt and
                (p.cards or p.showncards or p.equips) and
                not p.dead
            ]

            pl = candidates and user_choose_players(self, tgt, candidates)
            if not pl:
                return act

            g.process_action(AutumnWindAction(tgt, pl))

        return act
Esempio n. 6
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            tgt = act.target
            if tgt.dead:
                return act

            if not tgt.has_skill(Echo):
                return act

            g = Game.getgame()
            pact = g.action_stack[-1]
            card = getattr(pact, 'associated_card', None)
            if not card or not card.is_card(PhysicalCard):
                return act

            if not card.detached or card.unwrapped:
                return act

            if not user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act

            attack = card.is_card(AttackCard)
            pl = attack and user_choose_players(
                self, tgt, [p for p in g.players if not p.dead])
            p = pl[0] if pl else tgt

            g.process_action(EchoAction(tgt, p, card))

        return act
Esempio n. 7
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, Damage):
            if act.cancelled: return act

            src = act.source
            tgt = act.target
            if tgt.has_skill(FourOfAKind) and act.amount <= tgt.life:
                if user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                    g = Game.getgame()
                    g.process_action(FourOfAKindAction(tgt, act))

            if src and src.has_skill(FourOfAKind):
                g = Game.getgame()

                for a in reversed(g.action_stack):
                    if isinstance(a, LaunchCard):
                        break
                else:
                    return act

                if src.life == 1:
                    act.amount += 1

        return act
Esempio n. 8
0
    def apply_action(self):
        src = self.source
        tgt = self.target
        options = (
            Card.SPADE, Card.HEART,
            Card.CLUB, Card.DIAMOND,
        )

        card = self.associated_card
        detach_cards([card])
        suit = user_input([tgt], ChooseOptionInputlet(self, options))

        src.tags['surprise_tag'] = src.tags['turn_count']
        assert card

        g = Game.getgame()
        g.players.reveal(card.associated_cards)
        migrate_cards([card], tgt.showncards, unwrap=True)

        if card.suit != suit:
            g.process_action(Damage(src, tgt))
            rst = True
        else:
            rst = False

        return rst
Esempio n. 9
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, BaseAttack) and not marked(act, 'freaking_power'):
            src = act.source
            if not src.has_skill(FreakingPower): return act
            if not user_input([src], ChooseOptionInputlet(self, (False, True))):
                return act
            tgt = act.target
            Game.getgame().process_action(FreakingPowerAction(act))

        elif evt_type == 'action_after' and isinstance(act, Damage):
            g = Game.getgame()

            pact = g.action_stack[-1]
            if not marked(pact, 'freaking_power'):
                return act

            src, tgt = pact.source, act.target
            if tgt.dead: return act

            catnames = ('cards', 'showncards', 'equips')
            card = user_input([src], ChoosePeerCardInputlet(self, tgt, catnames))
            if card:
                g.players.exclude(tgt).reveal(card)
                g.process_action(DropCards(src, tgt, [card]))

        return act
Esempio n. 10
0
    def handle(self, p, trans):
        if not p.has_skill(VengeOfTsukumogami):
            return True

        if isinstance(trans.action, (LaunchCard, UseCard)):
            return True

        for cards, _from, to, is_bh in trans.get_movements():
            if _from is None or _from.type != 'equips':
                continue

            if _from.owner is p:
                continue

            if to.type != 'droppedcard':
                continue

            self.target = tgt = _from.owner
            for c in cards:
                self.card = c

                if tgt.dead:
                    break

                if not user_input([p], ChooseOptionInputlet(self, (False, True))):
                    break

                Game.getgame().process_action(VengeOfTsukumogamiAction(p, tgt, c))

        return True
Esempio n. 11
0
    def fire(self, src, tgt, cards):
        self.target = tgt  # for ui

        if not user_input([src], ChooseOptionInputlet(self, (False, True))):
            return

        g = Game.getgame()
        g.process_action(DollBlastAction(src, tgt, cards))
Esempio n. 12
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, basic.Attack):
            src = act.source
            if not src.has_skill(HouraiJewelSkill): return act
            if isinstance(act, HouraiJewelAttack): return act
            if user_input([src], ChooseOptionInputlet(self, (False, True))):
                act.__class__ = classmix(HouraiJewelAttack, act.__class__)

        return act
Esempio n. 13
0
    def handle(self, evt_type, act):
        if evt_type == 'action_apply' and isinstance(act, ActionStage):
            tgt = act.target
            if not tgt.has_skill(self.skill): return act
            if not user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act
            Game.getgame().process_action(self.action(tgt, tgt))

        return act
Esempio n. 14
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, DrawCardStage):
            if act.cancelled: return act
            tgt = act.target
            if not tgt.has_skill(CriticalStrike): return act
            if not user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                return act

            Game.getgame().process_action(CriticalStrikeAction(tgt, tgt))

            act.amount = max(0, act.amount - 1)

        elif evt_type == 'action_apply' and isinstance(act, BaseAttack):
            src = act.source
            tags = src.tags
            if not self.in_critical_strike(src):
                return act

            tgt = act.target
            if isinstance(act, BaseAttack):
                tags['flan_targets'].append(tgt)
                act.damage += 1

        elif evt_type == 'action_before' and isinstance(act, Damage):
            g = Game.getgame()
            pact = g.action_stack[-1]
            if not isinstance(pact, BaseDuel):
                return act

            src, tgt = act.source, act.target

            if not self.in_critical_strike(src):
                return act

            act.amount += 1

        elif evt_type == 'action_shootdown':
            if not isinstance(act, ActionStageLaunchCard): return act
            c = act.card
            src = act.source
            tags = src.tags
            if not self.in_critical_strike(src): return act
            if not c.is_card(AttackCard): return act
            if src.has_skill(ElementalReactorSkill): return act
            if set(act.target_list) & set(tags['flan_targets']):
                raise CriticalStrikeLimit

            return act

        elif evt_type == 'action_stage_action':
            tgt = act
            if not self.in_critical_strike(tgt): return act
            AttackCardHandler.set_freeattack(tgt)

        return act
Esempio n. 15
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Heal):
            tgt = act.target
            if not tgt.has_skill(MahjongDrug): return act
            card = getattr(act, 'associated_card', None)
            if not card or not card.is_card(HealCard): return act

            if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                Game.getgame().process_action(MahjongDrugAction(tgt, tgt))

        return act
Esempio n. 16
0
 def handle(self, evt_type, act):
     if evt_type == 'action_before' and isinstance(act, FatetellStage):
         tgt = act.target
         if not tgt.has_skill(TreasureHunt): return act
         g = Game.getgame()
         while True:
             if not user_input([tgt],
                               ChooseOptionInputlet(self, (False, True))):
                 return act
             if not g.process_action(TreasureHuntAction(tgt, tgt)):
                 return act
     return act
Esempio n. 17
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, Damage):
            tgt = act.target
            if act.source is None: return act
            if act.amount < tgt.life: return act
            if tgt.tags['books'] < 2: return act
            g = Game.getgame()
            if tgt is g.koakuma: return act
            if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                g.process_action(BookShootdownCompromise(act))

        return act
Esempio n. 18
0
    def handle(self, evt_type, act):
        if evt_type == 'fatetell':
            tgt = act.target
            if not tgt.has_skill(YinYangOrbSkill): return act
            if not user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act

            g = Game.getgame()
            g.process_action(YinYangOrb(act))

        return act
Esempio n. 19
0
    def apply_action(self):
        src, tgt = self.source, self.target
        g = Game.getgame()

        has_card = src.cards or src.showncards or src.equips

        if has_card and user_input(
            [tgt], ChooseOptionInputlet(self, ('drop', 'draw'))) == 'drop':
            g.process_action(KanakoFaithCounteract(tgt, src))
        else:
            g.process_action(KanakoFaithCheers(tgt, src))

        return True
Esempio n. 20
0
    def process(self, src, tgt):
        if src is None or tgt is None:
            return

        if not src.has_skill(Rosa):
            return

        if not tgt.cards:
            return

        if user_input([src], ChooseOptionInputlet(self, (False, True))):
            g = Game.getgame()
            g.process_action(MindReadEffect(src, tgt))
Esempio n. 21
0
    def handle(self, evt_type, arg):
        if evt_type == 'choose_target':
            lca, tl = arg
            if 'equipment' not in lca.card.category: return arg

            src = lca.source
            if src.dead or not src.has_skill(LittleLegion): return arg
            if not user_input([src], ChooseOptionInputlet(self,
                                                          (False, True))):
                return arg
            g = Game.getgame()
            g.process_action(LittleLegionDrawCards(src, 1))

        return arg
Esempio n. 22
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, PlayerDeath):
            g = Game.getgame()
            p = getattr(g, 'current_player', None)

            if not p: return act
            if p is act.target: return act
            if not p.has_skill(Summon): return act
            if p.tags['summon_used']: return act
            if not user_input([p], ChooseOptionInputlet(self, (False, True))):
                return act

            g.process_action(SummonAction(p, act.target))

        return act
Esempio n. 23
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, basic.BaseAttack):
            if act.cancelled: return act
            src = act.source
            if not src.has_skill(HakuroukenSkill): return act
            card = act.associated_card
            if not card.suit == Card.CLUB: return act

            if not user_input([src], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act

            Game.getgame().process_action(Hakurouken(src, act.target))

        return act
Esempio n. 24
0
 def handle(self, evt_type, act):
     from .basic import BaseAttack
     if not evt_type == 'action_after': return act
     if not isinstance(act, BaseAttack): return act
     if not act.succeeded: return act
     src = act.source
     tgt = act.target
     if tgt.dead: return act
     if not tgt.cards: return act
     if not src.has_skill(NenshaPhoneSkill): return act
     if not user_input([src], ChooseOptionInputlet(self, (False, True))):
         return act
     g = Game.getgame()
     g.process_action(NenshaPhone(src, tgt))
     return act
Esempio n. 25
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and ForEach.is_group_effect(act):
            g = Game.getgame()
            tgt = act.target
            if not tgt.has_skill(GodDescendant):
                return act

            opt = user_input([tgt], ChooseOptionInputlet(self, ('skip', 'draw', None)))

            if opt == 'skip':
                g.process_action(GodDescendantSkipAction(tgt, tgt, act))
            elif opt == 'draw':
                g.process_action(GodDescendantDrawAction(tgt, tgt, act))

        return act
Esempio n. 26
0
    def handle(self, evt_type, arg):
        if evt_type == 'character_debut':
            old, new = arg
            if not new.has_skill(AssaultKOF):
                return arg

            g = Game.getgame()
            op = g.get_opponent(new)
            lc = LaunchCard(new, [op], AssaultAttack(new))
            if not lc.can_fire():
                return arg

            if user_input([new], ChooseOptionInputlet(self, (False, True))):
                g.process_action(lc)

        return arg
Esempio n. 27
0
    def handle(self, p, act):
        if p.dead: return act
        if not p.has_skill(Trial): return act

        self.act = act

        if not user_input([p], ChooseOptionInputlet(self, (False, True))):
            return act

        cards = user_choose_cards(self, p, ('cards', 'showncards', 'equips'))

        if cards:
            c = cards[0]
            Game.getgame().process_action(TrialAction(p, act.target, act, c))

        return act
Esempio n. 28
0
    def handle(self, evt_type, act):
        from .basic import BaseUseGraze
        if evt_type == 'action_apply' and isinstance(act, BaseUseGraze):
            tgt = act.target
            if not tgt.has_skill(OpticalCloakSkill): return act
            if act.card: return act

            if not user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act

            g = Game.getgame()
            if g.process_action(OpticalCloak(tgt, tgt)):
                act.card = OpticalCloakSkill(tgt)

        return act
Esempio n. 29
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(
                act, spellcard.SpellCardAction):
            tgt = act.target
            if not tgt.has_skill(MaidenCostume): return act
            if act.cancelled: return act
            if isinstance(act, spellcard.Reject):
                return act  # can't respond to reject

            if not user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act

            Game.getgame().process_action(MaidenCostumeAction(tgt, act))

        return act
Esempio n. 30
0
    def apply_action(self):
        src, tgt = self.source, self.target
        g = Game.getgame()

        choice = user_input([tgt],
                            ChooseOptionInputlet(self, ('duel', 'attack')))

        if choice == 'duel':
            cls = KanakoFaithDuel
        elif choice == 'attack':
            cls = KanakoFaithAttack
        else:
            cls = KanakoFaithAttack

        g.process_action(LaunchCard(tgt, [src], cls(tgt), bypass_check=True))

        return True