예제 #1
0
    def apply_action(self):
        self.act.cancelled = True
        _from, _to = self.pl
        tgt = self.target
        from itertools import chain
        allcards = list(chain.from_iterable([_from.equips, _from.fatetell]))

        if not allcards:
            # Dropped by Exinwan
            return False

        card = user_input([tgt], ChooseIndividualCardInputlet(self, allcards))
        if not card:
            card = random_choose_card([_from.equips, _from.fatetell])

        if card.resides_in is _from.fatetell:
            if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                migrate_cards([card], _to.fatetell)
            else:
                migrate_cards([card], _to.cards, unwrap=True)

        elif card.resides_in is _from.equips:
            cats = set([c.equipment_category for c in _to.equips])
            migrate_cards([card], _to.cards)
            if card.equipment_category not in cats:
                if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                    Game.getgame().process_action(
                        LaunchCard(_to, [_to], card)
                    )
        else:
            assert False, 'WTF?!'

        return True
예제 #2
0
파일: yugi.py 프로젝트: TimLang/thbattle
    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
예제 #3
0
    def testProphetInputlet(self):
        from game import autoenv
        autoenv.init('Server')

        from game.autoenv import user_input
        from gamepack.thb.inputlets import ProphetInputlet

        g, p = self.makeGame()

        cards = g.deck.getcards(5)
        c0, c1, c2, c3, c4 = cards

        ilet = ProphetInputlet(self, cards=cards)
        ilet.set_result([c2, c3, c1], [c0, c4])
        eq_(ilet.data(), [[2, 3, 1], [0, 4]])

        p.client.gdlist.append([r'>I:Prophet:\d+', [[2, 3, 1], [0, 4]]])
        ilet = ProphetInputlet(self, cards=cards)
        eq_(user_input([p], ilet), [[c2, c3, c1], [c0, c4]])

        p.client.gdlist.append([r'>I:Prophet:\d+', [[2, 3], [0, 4]]])
        ilet = ProphetInputlet(self, cards=cards)
        eq_(user_input([p], ilet), [cards, []])

        p.client.gdlist.append([r'>I:Prophet:\d+', [[2, 3, 1, 0], [0, 4]]])
        ilet = ProphetInputlet(self, cards=cards)
        eq_(user_input([p], ilet), [cards, []])

        p.client.gdlist.append([r'>I:Prophet:\d+', [[2, 3, 0], [0, 4]]])
        ilet = ProphetInputlet(self, cards=cards)
        eq_(user_input([p], ilet), [cards, []])
예제 #4
0
    def apply_action(self):
        src = self.source
        tgt = self.target
        options = (
            Card.SPADE, Card.HEART,
            Card.CLUB, Card.DIAMOND,
        )

        suit = user_input([tgt], ChooseOptionInputlet(self, options))
        card = user_input([tgt], ChoosePeerCardInputlet(self, src, ('cards', 'showncards')))
        card = card or random_choose_card([src.cards, src.showncards])

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

        g = Game.getgame()
        g.players.exclude(src).reveal(card)
        migrate_cards([card], tgt.showncards)

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

        g.process_action(DrawCards(src, 1))

        return rst
예제 #5
0
    def testChoosePeerCardInputlet(self):
        from game.autoenv import user_input
        from gamepack.thb.inputlets import ChoosePeerCardInputlet
        from gamepack.thb.cards import migrate_cards

        g, p = self.makeGame()
        tgt = g.players[1]

        cards = g.deck.getcards(5)
        migrate_cards(cards, tgt.cards, no_event=True)

        showncards = g.deck.getcards(5)
        migrate_cards(showncards, tgt.showncards, no_event=True)

        ilet = ChoosePeerCardInputlet(self, target=tgt, categories=['cards'])
        ilet.set_card(cards[1])
        eq_(ilet.data(), cards[1].syncid)

        p.client.gdlist.append([r'>I:ChoosePeerCard:\d+', cards[2].syncid])
        ilet = ChoosePeerCardInputlet(self, target=tgt, categories=['cards'])
        eq_(user_input([p], ilet), cards[2])

        p.client.gdlist.append([r'>I:ChoosePeerCard:\d+', showncards[2].syncid])
        ilet = ChoosePeerCardInputlet(self, target=tgt, categories=['cards'])
        eq_(user_input([p], ilet), None)

        p.client.gdlist.append([r'>I:ChoosePeerCard:\d+', 343434])
        ilet = ChoosePeerCardInputlet(self, target=tgt, categories=['cards'])
        eq_(user_input([p], ilet), None)
예제 #6
0
    def handle(self, evt_type, act):
        if evt_type != 'action_after': return act
        if not isinstance(act, PlayerDeath): return act

        g = Game.getgame()

        tgt = act.target
        force = tgt.force
        if len(force.pool) <= 1:
            forces = g.forces[:]
            forces.remove(force)
            g.winners = forces[0][:]
            raise GameEnded

        g = Game.getgame()

        pool = tgt.force.pool
        assert pool

        mapping = {tgt: pool}
        with InputTransaction('ChooseGirl', [tgt], mapping=mapping) as trans:
            c = user_input([tgt], ChooseGirlInputlet(g, mapping), timeout=30, trans=trans)
            c = c or [_c for _c in pool if not _c.chosen][0]
            c.chosen = tgt
            pool.remove(c)
            trans.notify('girl_chosen', c)

        tgt = g.switch_character(tgt, c)
        g.process_action(DrawCards(tgt, 4))

        if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
            g.process_action(RedrawCards(tgt, tgt))

        return act
예제 #7
0
파일: thb2v2.py 프로젝트: feisuzhu/thbattle
    def handle(self, evt_type, act):
        if evt_type != "action_before":
            return act
        if not isinstance(act, DeadDropCards):
            return act

        g = Game.getgame()
        tgt = act.target
        for f in g.forces:
            if tgt in f:
                break
        else:
            assert False, "WTF?!"

        other = BatchList(f).exclude(tgt)[0]
        if other.dead:
            return act

        if user_input([other], ChooseOptionInputlet(self, ("inherit", "draw"))) == "inherit":
            g.process_action(HeritageAction(other, tgt))

        else:
            g.process_action(DrawCards(other, 2))

        return act
예제 #8
0
    def do_effect(self, src, tgt, _type):
        if not src.has_skill(LoongPunch): return
        if not (tgt.cards or tgt.showncards): return
        if not user_input([src], ChooseOptionInputlet(self, (False, True))): return

        g = Game.getgame()
        g.process_action(LoongPunchAction(src, tgt, _type))
예제 #9
0
파일: marisa.py 프로젝트: 17night/thbattle
    def apply_action(self):
        src = self.source
        tgt = self.target
        g = Game.getgame()

        c = user_input([src], ChoosePeerCardInputlet(self, tgt, ('cards', 'showncards', 'equips')))
        c = c or random_choose_card([tgt.cards, tgt.showncards])
        if not c: return False
        src.reveal(c)
        migrate_cards([c], src.cards)
        src.tags['borrow_tag'] = src.tags['turn_count']

        if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
            g.process_action(LaunchCard(tgt, [src], Daze(tgt), bypass_check=True))

        return True
예제 #10
0
파일: shizuha.py 프로젝트: 17night/thbattle
    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
예제 #11
0
파일: seija.py 프로젝트: feisuzhu/thbattle
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, BaseAttack):
            if hasattr(act, 'roukanken_tag'):
                return act

            src = act.source
            tgt = act.target
            g = Game.getgame()

            # if tgt is g.current_player: return act
            if not tgt.has_skill(Reversal):
                return act

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

            def nhand(p):
                return len(p.cards) + len(p.showncards)

            g.process_action(DrawCards(tgt, 1))
            if nhand(tgt) > nhand(src):
                g.process_action(LaunchCard(src, [tgt], ReversalDuel(src)))
                act.cancelled = True

        return act
예제 #12
0
파일: cirno.py 프로젝트: feisuzhu/thbattle
    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
예제 #13
0
    def handle(self, p, trans):
        if not p.has_skill(VengeOfTsukumogami):
            return True

        if not isinstance(trans.action, DropCards):
            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
예제 #14
0
파일: ran.py 프로젝트: AojiaoZero/thbattle
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, InstantSpellCardAction):
            if isinstance(act, Reject): return act
            g = Game.getgame()
            target = g.current_turn

            for p in g.players.exclude(target):
                if p.dead: continue
                if not p.has_skill(ExtremeIntelligence): continue
                if p.tags['ran_ei'] >= p.tags['turn_count'] + 1: continue

                try:
                    tl = act.target_list
                except AttributeError:
                    tl = [act.target]
                if any(t.dead for t in tl): return act

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

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

        elif evt_type == 'game_begin':
            g = Game.getgame()
            for p in g.players:
                if isinstance(p, Ran):
                    p.tags['ran_ei'] = 0  # for ui

        return act
예제 #15
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            g = Game.getgame()
            src, tgt = act.source, act.target
            if not (src and src.has_skill(Disarm)): return act
            if tgt.dead: return act
            pact = g.action_stack[-1]
            pcard = getattr(pact, 'associated_card', None)
            if not pcard: return act

            if not pcard.is_card(AttackCard) and not (pcard.is_card(DuelCard) and pact.source is src):
                return act

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

            cl = list(tgt.cards) + list(tgt.showncards)
            g.process_action(ShowCards(tgt, cl, [src]))

            if g.SERVER_SIDE:
                l = [c.is_card(AttackCard) or 'spellcard' in c.category for c in cl]
            else:
                l = [False for c in cl]

            l = sync_primitive(l, g.players)
            cl = list(itertools.compress(cl, l))
            g.process_action(DisarmHideAction(src, tgt, cl))

        elif evt_type == 'action_after' and isinstance(act, FinalizeStage):
            tgt = act.target
            g = Game.getgame()
            g.process_action(DisarmReturningAction(tgt, tgt))

        return act
예제 #16
0
파일: kyouko.py 프로젝트: feisuzhu/thbattle
    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:
                return act

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

            if not VirtualCard.unwrap([card]):
                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
예제 #17
0
    def apply_action(self):
        src, tgt = self.source, self.target
        g = Game.getgame()

        catnames = ('cards', 'showncards', 'equips', 'fatetell')
        cats = [getattr(tgt, i) for i in catnames]

        l = []
        for i in xrange(2):
            if not (tgt.cards or tgt.showncards or tgt.equips or tgt.fatetell):
                break

            card = user_input(
                [src], ChoosePeerCardInputlet(self, tgt, catnames)
            )

            if not card:
                card = random_choose_card(cats)
            if card:
                l.append(card)
                g.players.exclude(tgt).reveal(card)
                g.process_action(DropCards(src, tgt, [card]))

        self.cards = l
        return True
예제 #18
0
파일: yuuka.py 프로젝트: feisuzhu/thbattle
    def handle(self, evt_type, act):
        if evt_type != 'action_before':
            return act

        if not isinstance(act, InstantSpellCardAction):
            return act

        if isinstance(act, Reject):
            # HACK
            return act

        if ForEach.is_group_effect(act):
            return act

        src = act.source
        tgt = act.target

        if not src or tgt is src:
            return act

        if not tgt.has_skill(ReversedScales):
            return act

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

        g = Game.getgame()
        g.process_action(ReversedScalesAction(tgt, act))

        return act
예제 #19
0
 def apply_action(self):
     self.fts.cancelled = True
     tgt = self.target
     if not tgt.fatetell: return True
     card = user_input([tgt], ChooseIndividualCardInputlet(self, tgt.fatetell))
     card and Game.getgame().process_action(DropCards(tgt, [card]))
     return True
예제 #20
0
파일: youmu.py 프로젝트: 17night/thbattle
    def apply_action(self):
        g = Game.getgame()
        card = self.associated_card
        target = self.target
        equips = target.equips
        g = Game.getgame()
        cat = card.equipment_category

        with MigrateCardsTransaction(self) as trans:
            if cat == 'weapon':
                weapons = [e for e in equips if e.equipment_category == 'weapon']
                if len(weapons) > 1:
                    e = user_input(
                        [target], ChooseIndividualCardInputlet(self, weapons),
                    ) or random_choose_card([weapons])
                    migrate_cards([e], g.deck.droppedcards, unwrap=True, trans=trans)

            else:
                for oc in equips:
                    if oc.equipment_category == cat:
                        migrate_cards([oc], g.deck.droppedcards, unwrap=True, trans=trans)
                        break

            migrate_cards([card], target.equips, trans=trans)

        return True
예제 #21
0
 def apply_action(self):
     src, tgt = self.source, self.target
     c = user_input([src], ChoosePeerCardInputlet(self, tgt, ('cards', 'showncards', 'equips')))
     if not c: return False
     src.reveal(c)
     migrate_cards([c], src.cards)
     return True
예제 #22
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
예제 #23
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            src = act.source
            tgt = act.target
            if not (src and src.has_skill(FerryFee)): return act
            dist = LaunchCard.calc_distance(src, FerryFee(src))
            if not dist.get(tgt, 10000) <= 0: return act
            if user_input([src], ChooseOptionInputlet(self, (False, True))):
                catnames = ('cards', 'showncards', 'equips')
                card = user_input([src], ChoosePeerCardInputlet(self, tgt, catnames))
                card = card or random_choose_card([tgt.cards, tgt.showncards, tgt.equips])
                if not card: return act
                g = Game.getgame()
                g.process_action(FerryFeeEffect(src, tgt, card))

        return act
예제 #24
0
파일: yukari.py 프로젝트: 17night/thbattle
    def apply_action(self):
        tgt = self.target
        src = self.source

        catnames = ('cards', 'showncards', 'equips', 'fatetell')
        cats = [getattr(tgt, i) for i in catnames]
        card = user_input([src], ChoosePeerCardInputlet(self, tgt, catnames))
        card = card or random_choose_card(cats)
        if not card:
            return False

        self.card = card
        src.reveal(card)

        src.tags['spirit_away_tag'] += 1

        cl = getattr(tgt, 'yukari_dimension', None)
        if cl is None:
            cl = CardList(tgt, 'yukari_dimension')
            tgt.yukari_dimension = cl
            tgt.showncardlists.append(cl)

        migrate_cards([card], cl)

        return True
예제 #25
0
파일: kokoro.py 프로젝트: 17night/thbattle
    def apply_action(self):
        tgt = self.target
        g = Game.getgame()
        n = 1 + tgt.maxlife - tgt.life
        cards = g.deck.getcards(n)

        tgt.reveal(cards)
        putback, acquire = user_input([tgt], self.inputlet_cls(self, cards), timeout=20)
        for c in acquire:
            c.detach()

        assert not putback or set(putback) == set(g.deck.getcards(len(putback)))

        deck = g.deck.cards
        for i, c in enumerate(putback):
            deck[i] = c

        assert not putback or putback == g.deck.getcards(len(putback))

        if acquire:
            g.process_action(ShowCards(tgt, acquire))
            migrate_cards(acquire, tgt.cards)

        self.acquire = acquire

        return True
예제 #26
0
파일: kogasa.py 프로젝트: TimLang/thbattle
    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
예제 #27
0
파일: youmu.py 프로젝트: feng2606/thbattle
    def apply_action(self):
        g = Game.getgame()
        card = self.associated_card
        target = self.target
        equips = target.equips
        g = Game.getgame()
        cat = card.equipment_category
        if cat == 'weapon':
            weapons = [e for e in equips if e.equipment_category == 'weapon']
            if len(weapons) > 1:
                e = user_input(
                    [target],
                    ChooseIndividualCardInputlet(self, weapons),
                ) or random_choose_card([weapons])
                g.process_action(DropCards(target, [e]))
                weapons.remove(e)

            weapons.append(card)
            cls = set([i.__class__ for i in weapons])
            l = set([HakuroukenCard, RoukankenCard])
            if cls == l and not target.has_skill(Xianshiwangzhi):
                g.process_action(XianshiwangzhiAwake(target, target))

        else:
            for oc in equips:
                if oc.equipment_category == cat:
                    g.process_action(DropCards(target, [oc]))
                    break

        migrate_cards([card], target.equips)
        return True
예제 #28
0
파일: alice.py 프로젝트: TimLang/thbattle
    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))
예제 #29
0
 def apply_action(self):
     src, tgt = self.source, self.target
     c = user_input([src],
                    ChoosePeerCardInputlet(
                        self, tgt, ('cards', 'showncards', 'equips')))
     if not c: return False
     src.reveal(c)
     migrate_cards([c], src.cards)
     return True
예제 #30
0
    def testChooseIndividualCardInputlet(self):
        from game.autoenv import user_input
        from gamepack.thb.inputlets import ChooseIndividualCardInputlet

        g, p = self.makeGame()
        cards = g.deck.getcards(5)

        ilet = ChooseIndividualCardInputlet(self, cards=cards)
        ilet.set_card(cards[1])
        eq_(ilet.data(), cards[1].syncid)

        p.client.gdlist.append([r'>I:ChooseIndividualCard:\d+', cards[2].syncid])
        ilet = ChooseIndividualCardInputlet(self, cards=cards)
        eq_(user_input([p], ilet), cards[2])

        p.client.gdlist.append([r'>I:ChooseIndividualCard:\d+', 343434])
        ilet = ChooseIndividualCardInputlet(self, cards=cards)
        eq_(user_input([p], ilet), None)
예제 #31
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
예제 #32
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
예제 #33
0
    def apply_action(self):
        src, tgt = self.source, self.target
        g = Game.getgame()

        equip = user_input([src], ChoosePeerCardInputlet(self, tgt, ['equips']))
        equip = equip or random_choose_card([tgt.equips])
        g.process_action(DropCards(src, tgt, [equip]))
        self.card = equip

        return True
예제 #34
0
    def handle(self, evt_type, act):
        if evt_type == 'action_apply' and isinstance(act, PlayerTurn):
            tgt = act.target
            if not tgt.has_skill(Prophet): return act
            if not user_input([tgt], ChooseOptionInputlet(self,
                                                          (False, True))):
                return act
            Game.getgame().process_action(ProphetAction(tgt, tgt))

        return act
예제 #35
0
    def testChooseIndividualCardInputlet(self):
        from game.autoenv import user_input
        from gamepack.thb.inputlets import ChooseIndividualCardInputlet

        g, p = self.makeGame()
        cards = g.deck.getcards(5)

        ilet = ChooseIndividualCardInputlet(self, cards=cards)
        ilet.set_card(cards[1])
        eq_(ilet.data(), cards[1].syncid)

        p.client.gdlist.append(
            [r'>I:ChooseIndividualCard:\d+', cards[2].syncid])
        ilet = ChooseIndividualCardInputlet(self, cards=cards)
        eq_(user_input([p], ilet), cards[2])

        p.client.gdlist.append([r'>I:ChooseIndividualCard:\d+', 343434])
        ilet = ChooseIndividualCardInputlet(self, cards=cards)
        eq_(user_input([p], ilet), None)
예제 #36
0
    def apply_action(self):
        src = self.source
        tgt = self.target
        g = Game.getgame()

        c = user_input([src],
                       ChoosePeerCardInputlet(
                           self, tgt, ('cards', 'showncards', 'equips')))
        c = c or random_choose_card([tgt.cards, tgt.showncards])
        if not c: return False
        src.reveal(c)
        migrate_cards([c], src.cards)
        src.tags['borrow_tag'] = src.tags['turn_count']

        if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
            g.process_action(
                LaunchCard(tgt, [src], Daze(tgt), bypass_check=True))

        return True
예제 #37
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            src = act.source
            tgt = act.target
            if not (src and src.has_skill(FerryFee)): return act
            if not (tgt.cards or tgt.showncards or tgt.equips): return act
            dist = LaunchCard.calc_distance(src, FerryFee(src))
            if not dist.get(tgt, 10000) <= 0: return act
            if user_input([src], ChooseOptionInputlet(self, (False, True))):
                catnames = ('cards', 'showncards', 'equips')
                card = user_input([src],
                                  ChoosePeerCardInputlet(self, tgt, catnames))
                card = card or random_choose_card(
                    [tgt.cards, tgt.showncards, tgt.equips])
                if not card: return act
                g = Game.getgame()
                g.process_action(FerryFeeEffect(src, tgt, card))

        return act
예제 #38
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
예제 #39
0
파일: thbkof.py 프로젝트: zzkklep/thbattle
    def switch(p):
        g = Game.getgame()
        mapping = {p: p.choices}

        with InputTransaction('ChooseGirl', [p], mapping=mapping) as trans:
            rst = user_input([p], ChooseGirlInputlet(g, mapping), timeout=30, trans=trans)
            rst = rst or p.choices[0]

        p = g.next_character(p, rst)
        p.choices.remove(rst)
        return p
예제 #40
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
예제 #41
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
예제 #42
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
예제 #43
0
    def handle(self, evt_type, act):
        if evt_type == 'action_apply' and isinstance(act, PlayerDeath):
            g = Game.getgame()

            tgt = act.target
            force = tgt.force
            if len(force.pool) <= 1:
                forces = g.forces[:]
                forces.remove(force)
                g.winners = forces[0][:]
                g.game_end()

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

            tgt = act.target
            pool = tgt.force.pool
            assert pool

            mapping = {tgt: pool}
            with InputTransaction('ChooseGirl', [tgt],
                                  mapping=mapping) as trans:
                c = user_input([tgt],
                               ChooseGirlInputlet(g, mapping),
                               timeout=30,
                               trans=trans)
                c = c or [_c for _c in pool if not _c.chosen][0]
                c.chosen = tgt
                pool.remove(c)
                trans.notify('girl_chosen', (tgt, c))

            tgt = g.switch_character(tgt, c)

            c = getattr(g, 'current_player', None)

            g.process_action(DistributeCards(tgt, 4))

            if user_input([tgt], ChooseOptionInputlet(self, (False, True))):
                g.process_action(RedrawCards(tgt, tgt))

        return act
예제 #44
0
 def apply_action(self):
     g = Game.getgame()
     tgt = self.target
     place = user_input([tgt], ChooseOptionInputlet(self, ('top', 'bottom')))
     sk = self.card
     assert sk.is_card(LunaString)
     c = sk.associated_cards[0]
     sk.associated_cards[:] = []
     sk.cost_detached = True
     self.place = place  # for ui
     migrate_cards([c], g.deck.cards, unwrap=True, front=(place == 'top'))
     return True
예제 #45
0
    def apply_action(self):
        tgt = self.target
        equips = tgt.equips
        weapons = [e for e in equips if e.equipment_category == 'weapon']
        e = user_input(
            [tgt],
            ChooseIndividualCardInputlet(self, weapons),
        ) or random_choose_card([weapons])
        g = Game.getgame()
        g.process_action(DropCards(tgt, tgt, [e]))

        return True
예제 #46
0
 def apply_action(self):
     g = Game.getgame()
     src = self.source
     tgt = self.target
     c = user_input([src],
                    ChoosePeerCardInputlet(self, tgt,
                                           ('cards', 'showncards')))
     c = c or random_choose_card([tgt.cards, tgt.showncards])
     if not c: return False
     g.players.exclude(tgt).reveal(c)
     g.process_action(DropCards(tgt, [c]))
     return True
예제 #47
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
예제 #48
0
    def apply_action(self):
        src, tgt = self.source, self.target
        ttags(src)['dismantle'] = True

        g = Game.getgame()
        c = user_input([src], ChoosePeerCardInputlet(self, tgt, ('equips', )))
        c = c or random_choose_card([tgt.equips])
        if not c: return False

        g.process_action(Reforge(src, tgt, c))
        g.process_action(DrawCards(tgt, 1))

        return True
예제 #49
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))
예제 #50
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(M*******t): return act
            if not act.amount: return act

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

            Game.getgame().process_action(MasochistAction(tgt, act.amount))

        return act
예제 #51
0
    def testChooseOptionInputlet(self):
        from game import autoenv
        from game.autoenv import user_input
        from client.core import TheChosenOne, PeerPlayer

        from thb.thb3v3 import THBattle
        from 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)
        g.gr_groups = WeakSet()

        ilet = ChooseOptionInputlet(self, (False, True))

        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, (False, True))

        eq_(user_input([p], ilet), True)
        eq_(user_input([p], ilet, type='all'), {p: False})
        eq_(user_input([p], ilet, type='any'), (p, True))
예제 #52
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            src, tgt = act.source, act.target
            if not src: return act
            if not src.has_skill(ReimuClear): return act
            if src is tgt: return act
            if src.dead or tgt.dead: return act

            if user_input([src], ChooseOptionInputlet(self, (False, True))):
                g = Game.getgame()
                g.process_action(ReimuClearAction(src, tgt))

        return act
예제 #53
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
예제 #54
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, BaseDuel)):
            src = act.source
            st = src.tags
            if not st['flan_cs'] >= st['turn_count']: return act
            if not Game.getgame().current_turn is src: return act
            if not src.has_skill(CriticalStrike): return act
            tgt = act.target
            if isinstance(act, BaseAttack):
                st['flan_targets'].append(tgt)
                act.damage += 1
            elif isinstance(act, BaseDuel):
                act.source_damage += 1

        elif evt_type == 'action_can_fire':
            arg = act
            act, valid = arg
            if not isinstance(act, ActionStageLaunchCard): return arg
            c = act.card
            src = act.source
            tags = src.tags
            if not src.has_skill(CriticalStrike): return arg
            if not tags['flan_cs'] >= tags['turn_count']: return arg
            if not c.is_card(AttackCard): return arg
            if src.has_skill(ElementalReactorSkill): return arg
            if set(act.target_list) & set(tags['flan_targets']):
                return (act, False)

            return arg

        elif evt_type == 'action_stage_action':
            tgt = act
            tags = tgt.tags
            if not tgt.has_skill(CriticalStrike): return act
            if not tags['flan_cs'] >= tags['turn_count']: return act
            AttackCardHandler.set_freeattack(tgt)

        return act
예제 #55
0
파일: alice.py 프로젝트: yuzishui/thbattle
    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
예제 #56
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
예제 #57
0
파일: alice.py 프로젝트: GavinHill/thbattle
    def apply_action(self):
        g = Game.getgame()
        cl = self.cards
        track_ids = set([c.track_id for c in cl])

        src, tgt = self.source, self.target
        for c in cl:
            c = user_input([src], ChoosePeerCardInputlet(self, tgt, ('cards', 'showncards', 'equips')))
            c = c or random_choose_card([tgt.cards, tgt.showncards, tgt.equips])
            if not c: return True
            g.players.reveal(c)
            g.process_action(DollBlastEffect(src, tgt, c, c.track_id in track_ids))

        return True
예제 #58
0
    def apply_action(self):
        self.dcs.cancelled = True
        tgt = self.target

        for p in self.pl:
            c = user_input([tgt],
                           ChoosePeerCardInputlet(self, p,
                                                  ('cards', 'showncards')))
            c = c or random_choose_card([p.cards, p.showncards])
            if not c: continue
            tgt.reveal(c)
            migrate_cards([c], tgt.cards)

        return True
예제 #59
0
    def apply_action(self):
        g = Game.getgame()
        src, tgt = self.source, self.target
        src.tags['riverside_tag'] = src.tags['turn_count']
        tgt.tags['riverside_target'] = g.turn_count
        minhp = min([p.life for p in g.players if not p.dead])
        if tgt.life == minhp:
            has_card = tgt.cards or tgt.showncards or tgt.equips
            if has_card and user_input(
                [src], ChooseOptionInputlet(self, ('drop', 'draw'))) == 'drop':
                self.action = 'drop'
                catnames = ('cards', 'showncards', 'equips')
                card = user_input([src],
                                  ChoosePeerCardInputlet(self, tgt, catnames))
                card = card or random_choose_card(
                    [tgt.cards, tgt.showncards, tgt.equips])
                g.players.reveal(card)
                g.process_action(DropCards(src, tgt, [card]))
            else:
                self.action = 'draw'
                g.process_action(DrawCards(src, 1))

        return True
예제 #60
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