Example #1
0
    def handle(self, evt_type, act):
        if evt_type == 'choose_target':
            act, tl = arg = act
            card = act.card
            if not card.is_card(HarvestCard): return arg
            pl = [p for p in tl if p.has_skill(AkiTribute) and not p.dead]
            assert len(pl) <= 1, 'Multiple AkiTributes!'
            if not pl: return arg
            p = pl[0]
            tl.remove(p)
            tl.insert(0, p)
            return act, tl

        elif evt_type == 'harvest_finish':
            g = Game.getgame()
            pl = [p for p in g.players if p.has_skill(AkiTribute) and not p.dead]
            assert len(pl) <= 1, 'Multiple AkiTributes!'
            if not pl: return act

            src = pl[0]
            cards = [c for c in act.cards if c.detached]
            if not cards: return act

            candidates = [p for p in g.players if not p.dead]
            pl = user_choose_players(self, src, candidates)
            if not pl: return act

            tgt, = pl
            g.process_action(AkiTributeCollectCard(src, tgt, cards))

        return act
Example #2
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            src = act.source
            if not src: return act
            if not src.has_skill(DestructionImpulse): return act

            g = Game.getgame()
            ttags(src)['destruction_tag'] = True

        elif evt_type == 'action_after' and isinstance(act, PlayerTurn):
            tgt = act.target
            if not tgt.has_skill(DestructionImpulse): return act

            g = Game.getgame()
            if ttags(tgt)['destruction_tag']: return act

            dist = LaunchCard.calc_distance(tgt, DestructionImpulse(tgt))
            dist.pop(tgt, '')

            for k in dist:
                dist[k] = max(dist[k], 0)

            nearest = min(dist.values())
            candidates = [p for p, d in dist.items() if d == nearest]
            candidates = [p for p in g.players if p in candidates]  # order matters

            if len(candidates) > 1:
                pl = user_choose_players(self, tgt, candidates)
                p = pl[0] if pl else candidates[0]
            else:
                p = candidates[0]

            g.process_action(DestructionImpulseAction(tgt, p))

        return act
Example #3
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, PlayerDeath):
            src = act.source
            if not src or not src.has_skill(S****t):
                return act

            dist = LaunchCard.calc_distance(src, AttackCard())
            candidates = [k for k, v in dist.items() if v <= 0 and k is not src]

            if not candidates:
                return act

            pl = user_choose_players(self, src, candidates)
            if pl:
                Game.getgame().process_action(SadistAction(src, pl[0]))

        elif evt_type == 'action_before' and isinstance(act, Damage):
            src = act.source
            tgt = act.target

            if not src or src is tgt:
                return act

            if not src.has_skill(S****t):
                return act

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

        return act
Example #4
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
Example #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
Example #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
Example #7
0
    def handle(self, evt_type, act):
        if evt_type == 'action_done' and isinstance(act, Attack):
            src = act.source
            tgt = act.target

            if src.dead or tgt.dead:
                return act

            if not src.has_skill(Resonance):
                return act

            g = Game.getgame()
            pl = [p for p in g.players if not p.dead and p not in (src, tgt)]

            if not pl:
                return act

            pl = user_choose_players(self, src, pl)

            if not pl:
                return act

            g.process_action(ResonanceAction(src, pl[0], tgt))

        return act
Example #8
0
    def handle(self, evt_type, act):
        if evt_type == 'choose_target':
            act, tl = arg = act
            card = act.card
            if not card.is_card(HarvestCard): return arg
            pl = [p for p in tl if p.has_skill(AkiTribute) and not p.dead]
            assert len(pl) <= 1, 'Multiple AkiTributes!'
            if not pl: return arg
            p = pl[0]
            tl.remove(p)
            tl.insert(0, p)
            return act, tl

        elif evt_type == 'harvest_finish':
            g = Game.getgame()
            pl = [
                p for p in g.players if p.has_skill(AkiTribute) and not p.dead
            ]
            assert len(pl) <= 1, 'Multiple AkiTributes!'
            if not pl: return act

            src = pl[0]
            cards = [c for c in act.cards if c.detached]
            if not cards: return act

            candidates = [p for p in g.players if not p.dead]
            pl = user_choose_players(self, src, candidates)
            if not pl: return act

            tgt, = pl
            g.process_action(AkiTributeCollectCard(src, tgt, cards))

        return act
Example #9
0
    def handle(self, evt_type, act):
        if evt_type == 'action_done' and isinstance(act, Attack):
            src = act.source
            tgt = act.target

            if src.dead or tgt.dead:
                return act

            if not src.has_skill(Resonance):
                return act

            g = Game.getgame()
            pl = [p for p in g.players if not p.dead and p not in (src, tgt)]

            if not pl:
                return act

            pl = user_choose_players(self, src, pl)

            if not pl:
                return act

            g.process_action(ResonanceAction(src, pl[0], tgt))

        return act
Example #10
0
    def apply_action(self):
        g = Game.getgame()
        src = self.source
        pl = [p for p in g.players if not p.dead and p.life < p.maxlife]
        beneficiary, = user_choose_players(self, src, pl) or (None,)
        if beneficiary is None:
            return False

        g.process_action(LittleLegionCoverEffect(src, beneficiary, 1))
        return True
Example #11
0
    def apply_action(self):
        g = Game.getgame()
        src = self.source
        pl = [p for p in g.players if not p.dead and p.life < p.maxlife]
        beneficiary, = user_choose_players(self, src, pl) or (None, )
        if beneficiary is None:
            return False

        g.process_action(LittleLegionCoverEffect(src, beneficiary, 1))
        return True
Example #12
0
    def apply_action(self):
        g = Game.getgame()
        src = self.source
        pl = [p for p in g.players if not p.dead and p is not src]
        victim, = user_choose_players(self, src, pl) or (None,)
        if victim is None:
            return False

        lc = LaunchCard(src, [victim], LittleLegionAttackCard(src), bypass_check=True)
        g.process_action(lc)
        return True
Example #13
0
    def apply_action(self):
        g = Game.getgame()
        src = self.source
        pl = [p for p in g.players if not p.dead]
        attacker, victim = user_choose_players(self, src, pl) or (None, None)
        if attacker is None:
            return False

        self.target_list = attacker, victim

        g.process_action(LaunchCard(src, [attacker, victim], LittleLegionDollControlCard(attacker)))
        return True
Example #14
0
    def handle(self, evt_type, act):
        if evt_type == 'action_apply' and isinstance(act, PlayerTurn):
            tgt = act.target
            if not tgt.has_skill(Qiliao): return act
            qi = getattr(tgt, 'meirin_qiliao', None)
            if not qi: return act
            g = Game.getgame()
            pl = user_choose_players(self, tgt, [p for p in g.players if not p.dead])
            if not pl: return act
            g.process_action(QiliaoRecoverAction(tgt, pl[0]))

        return act
Example #15
0
    def apply_action(self):
        g = Game.getgame()
        src = self.source
        pl = [p for p in g.players if not p.dead and p is not src]
        victim, = user_choose_players(self, src, pl) or (None, )
        if victim is None:
            return False

        lc = LaunchCard(src, [victim],
                        LittleLegionAttackCard(src),
                        bypass_check=True)
        g.process_action(lc)
        return True
Example #16
0
    def apply_action(self):
        g = Game.getgame()
        src = self.source
        pl = [p for p in g.players if not p.dead]
        attacker, victim = user_choose_players(self, src, pl) or (None, None)
        if attacker is None:
            return False

        self.target_list = attacker, victim

        g.process_action(
            LaunchCard(src, [attacker, victim],
                       LittleLegionDollControlCard(attacker)))
        return True
Example #17
0
    def apply_action(self):
        tgt = self.target
        g = Game.getgame()
        g.process_action(DrawCards(tgt, 1))

        ttags(tgt)['miracle_times'] += 1

        if ttags(tgt)['miracle_times'] == 3:
            candidates = [p for p in g.players if not p.dead and p.life < p.maxlife]
            if candidates:
                beneficiery, = user_choose_players(self, tgt, candidates) or (None,)
                if beneficiery:
                    g.process_action(MiracleHeal(tgt, beneficiery))

        return True
Example #18
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, DrawCardStage):
            tgt = act.target

            if not tgt.has_skill(Jolly): return act

            g = Game.getgame()
            pl = user_choose_players(self, tgt, [p for p in g.players if not p.dead])
            if not pl: pl = [tgt]

            p = pl[0]

            g.process_action(JollyDrawCard(tgt, p))

        return act
Example #19
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, DropCardStage):
            g = Game.getgame()
            tgt = act.target
            if not tgt.has_skill(Shipwreck):
                return act

            candidates = [p for p in g.players if not p.dead and (p.cards or p.showncards or p.equips)]
            victim, = user_choose_players(self, tgt, candidates) or (None,)
            if not victim:
                return act

            act.__class__ = ShipwreckDropCardStage
            act.init(victim=victim)

        return act
Example #20
0
    def handle(self, p, arg):
        if not p.has_skill(LittleLegion):
            return True

        equips = p.equips
        if not any(_from is equips for _, _from, _, _ in arg.get_movements()):
            return True

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

        tl = user_choose_players(self, p, g.players.exclude(p))
        if tl:
            assert len(tl) == 1
            g.process_action(LittleLegionAction(p, tl[0]))

        return True
Example #21
0
    def handle(self, evt_type, act):
        if evt_type == 'action_before' and isinstance(act, DropCardStage):
            g = Game.getgame()
            tgt = act.target
            if not tgt.has_skill(Shipwreck):
                return act

            candidates = [
                p for p in g.players
                if not p.dead and (p.cards or p.showncards or p.equips)
            ]
            victim, = user_choose_players(self, tgt, candidates) or (None, )
            if not victim:
                return act

            act.__class__ = ShipwreckDropCardStage
            act.init(victim=victim)

        return act
Example #22
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(Virtue):
                return act

            g = Game.getgame()
            pl = [p for p in g.players if not p.dead and p is not tgt]
            pl = pl and user_choose_players(self, tgt, pl)
            if not pl:
                return act

            act.cancelled = True
            g.process_action(VirtueAction(tgt, pl[0]))

        return act
Example #23
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(Virtue):
                return act

            g = Game.getgame()
            pl = [p for p in g.players if not p.dead and p is not tgt]
            pl = pl and user_choose_players(self, tgt, pl)
            if not pl:
                return act

            act.cancelled = True
            g.process_action(VirtueAction(tgt, pl[0]))

        return act
Example #24
0
    def handle(self, p, arg):
        if not p.has_skill(LittleLegion):
            return True

        equips = p.equips
        if not any(_from is equips for _, _from, _, _ in arg.get_movements()):
            return True

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

        tl = user_choose_players(self, p, g.players.exclude(p))
        if tl:
            assert len(tl) == 1
            g.process_action(LittleLegionAction(p, tl[0]))

        return True
Example #25
0
    def handle(self, evt_type, act):
        if evt_type == 'action_after' and isinstance(act, Damage):
            src = act.source
            if not src: return act
            if not src.has_skill(DestructionImpulse): return act

            g = Game.getgame()
            ttags(src)['destruction_tag'] = True

        elif evt_type == 'action_after' and isinstance(act, PlayerTurn):
            tgt = act.target
            if not tgt.has_skill(DestructionImpulse): return act

            g = Game.getgame()
            if ttags(tgt)['destruction_tag']: return act

            dist = LaunchCard.calc_distance(tgt, DestructionImpulse(tgt))
            dist.pop(tgt, '')

            for k in dist:
                dist[k] = max(dist[k], 0)

            nearest = min(dist.values())
            candidates = [p for p, d in dist.items() if d == nearest]
            candidates = [p for p in g.players
                          if p in candidates]  # order matters

            if len(candidates) > 1:
                pl = user_choose_players(self, tgt, candidates)
                p = pl[0] if pl else candidates[0]
            else:
                p = candidates[0]

            g.process_action(DestructionImpulseAction(tgt, p))

        return act