Ejemplo n.º 1
0
 def compute(self, source, player):
     self._cards = []
     # Untap myself
     if self.cardtype == None:
         if source.canUntap(): self._cards.append(source)
         else: return False
     # otherwise see if there are enough cards for untapping
     else:
         prompt = "Select %d %s(s) for untapping" % (
             self.number - len(self._cards), self.cardtype)
         while True:
             card = player.getTarget(self.cardtype,
                                     zone="battlefield",
                                     from_player="you",
                                     required=False,
                                     prompt=prompt)
             if card == False: return False
             if card in self._cards:
                 prompt = "Card already selected - select again"
                 player.send(InvalidTargetEvent(), target=card)
             elif not card.tapped:
                 prompt = "Card already untapped - select again"
                 player.send(InvalidTargetEvent(), target=card)
             elif not card.canUntap():
                 prompt = "Card cannot be untapped - select again"
                 player.send(InvalidTargetEvent(), target=card)
             else:
                 self._cards.append(card)
                 prompt = "Select %d %s(s) for untapping" % (
                     self.number - len(self._cards), self.cardtype)
             if len(self._cards) == self.number: break
     return True
Ejemplo n.º 2
0
    def get(self, source):
        if isinstance(self.selector, str):
            if self.selector == "opponent": selector = source.controller.choose_opponent()
            elif self.selector == "active_player":
                import engine.GameKeeper
                selector = engine.GameKeeper.Keeper.active_player
            else: selector = source.controller
        if isPlayer(self.selector): selector = self.selector
        else: selector = source.controller
        i = 0
        targets = []
        while i < self.number:
            target = selector.getTarget(self.target_types,zone=self.zone,from_player=self.player,required=False,prompt=self.get_prompt(i, source.name))
            if target == False:
                if not self.up_to or len(targets) == 0: return False
                else: break
            elif target.canBeTargetedBy(source) and not target in targets:
                targets.append(target)
                i += 1
            else: selector.send(InvalidTargetEvent(), target=target)

        # Now distribute among them if we need to
        if self.distribute > 0:
            self.distribution = selector.getDistribution(amount=self.distribute, targets=targets, prompt="Distribute %d %s among targets"%(self.distribute, self.distribute_type))

        # Got our targets, now save info:
        for target in targets:
            target.isTargetedBy(source)
        self.target = targets
        return True
Ejemplo n.º 3
0
 def enterBattlefieldWith(source):
     cards = set()
     if source.controller.you_may("Sacrifice creatures to %s" %
                                  source.name):
         i = 0
         num_creatures = len(source.controller.battlefield.get(isCreature))
         while i < num_creatures:
             creature = source.controller.getTarget(
                 isCreature,
                 zone="battlefield",
                 from_player="you",
                 required=False,
                 prompt=
                 "Select any number of creatures to sacrifice: (%d selected so far)"
                 % i)
             if creature == False: break
             elif not creature in cards:
                 cards.add(creature)
                 i += 1
             else:
                 source.controller.send(InvalidTargetEvent(),
                                        target=creature)
         for card in cards:
             source.controller.sacrifice(card)
         source.devoured = cards
         if cards:
             source.add_counters(PowerToughnessCounter(1, 1),
                                 len(cards) * value)
Ejemplo n.º 4
0
 def compute(self, source, player):
     if self.cardtype == None:
         # Target myself
         if self.enough_counters(source): self._card = source
         else: return False
     else:
         prompt = "Select %s from which to remove %d %s counter(s)" % (
             self.cardtype, self.number, self.counter_type)
         if not self.counter_type:
             prompt = "Select %s from which to remove %d counter(s)" % (
                 self.cardtype, self.number)
         while True:
             card = player.getTarget(self.cardtype,
                                     zone="battlefield",
                                     from_player="you",
                                     required=False,
                                     prompt=prompt)
             if card == False: return False
             if not self.enough_counters(card):
                 prompt = "Card doesn't have enough %s counters - select again" % self.counter_type
                 player.send(InvalidTargetEvent(), target=card)
             else:
                 self._card = card
                 break
     if not self.counter_type:
         sellist = list(
             set([counter.ctype for counter in self._card.counters]))
         if len(sellist) == 1: self.counter_type = sellist[0]
         else:
             self.counter_type = player.make_selection(
                 sellist, prompt='Choose a counter')
     return True
Ejemplo n.º 5
0
 def compute(self, source, player):
     self._cards = []
     if self.cardtype == None:
         # Sacrifice myself
         if str(source.zone) == "battlefield": self._cards.append(source)
         else: return False
     else:
         prompt = "Select %d %s(s) for sacrifice" % (
             self.number - len(self._cards), self.cardtype)
         if self.msg: prompt = self.msg
         while True:
             card = player.getTarget(self.cardtype,
                                     zone="battlefield",
                                     from_player="you",
                                     required=False,
                                     prompt=prompt)
             if card == False: return False
             if card in self._cards:
                 prompt = "Card already selected - select again"
                 player.send(InvalidTargetEvent(), target=card)
             else:
                 self._cards.append(card)
                 prompt = "Select %d %s(s) for sacrifice" % (
                     self.number - len(self._cards), self.cardtype)
                 if self.msg: prompt = self.msg
             if len(self._cards) == self.number: break
     return True
Ejemplo n.º 6
0
    def get(self, source):
        if self.msg: prompt=self.msg
        else:
            if self.zone != "battlefield":
                if self.player == None: zl = " in any %s"%self.zone
                elif self.player == "you": zl = " in your %s"%self.zone
                else: zl = " in opponent %s"%self.zone
            else:
                if self.player == None: zl = ""
                elif self.player == "you": zl = " you control"
                else: zl = " opponent controls"
            prompt="Target %s%s for %s"%(' or '.join([str(t) for t in self.target_types]), zl, source)
        if self.selector == "opponent": selector = source.controller.choose_opponent()
        elif self.selector == "active_player":
            from engine.GameKeeper import Keeper
            selector = Keeper.active_player
        else: selector = source.controller
        # If required, make sure there is actually a target available
        if self.required and not self.targeting_player:
            perm = []
            if self.zone != "battlefield":
                zones = [getattr(selector, self.zone)] + [getattr(opponent, self.zone) for opponent in selector.opponents]
                if self.player == "you": zones = zones[:1]
                elif self.player == "opponent": zones = zones[1:]
                for ttype in self.target_types:
                    for zone in zones:
                        perm.extend([p for p in zone.get(ttype) if p.canBeTargetedBy(source)])
            else:
                for ttype in self.target_types:
                    if self.player == None:
                        perm.extend([p for p in selector.battlefield.get(ttype, all=True) if p.canBeTargetedBy(source)])
                    elif self.player == "you":
                        perm.extend([p for p in selector.battlefield.get(ttype) if p.canBeTargetedBy(source)])
                    else:
                        for opponent in selector.opponents:
                            perm.extend([p for p in opponent.battlefield.get(ttype) if p.canBeTargetedBy(source)])

            numtargets = len(perm)
            if numtargets == 0: return False
            elif numtargets == 1: self.target = perm[0]
            else:
                while True:
                    self.target = selector.getTarget(self.target_types,zone=self.zone,from_player=self.player,required=self.required,prompt=prompt)
                    if self.target.canBeTargetedBy(source): break
        else:
            self.target = selector.getTarget(self.target_types,zone=self.zone,from_player=self.player,required=False,prompt=prompt)
            if self.target == False: return False
        if self.target.canBeTargetedBy(source):
            self.target.isTargetedBy(source)
            self.is_valid = True
            return True
        else:
            selector.send(InvalidTargetEvent(), target=self.target)
            return False
Ejemplo n.º 7
0
 def compute(self, source, player):
     self._cards = []
     if self.cardtype == None:
         if str(source.zone) == self.from_zone: self._cards.append(source)
         else: return False
     else:
         prompt = "Select %d %s(s) to %s" % (self.number - len(
             self._cards), self.cardtype, self.action_txt % '')
         while True:
             card = player.getTarget(self.cardtype,
                                     zone=self.from_zone,
                                     from_player="you",
                                     required=False,
                                     prompt=prompt)
             if card == False: return False
             if card in self._cards:
                 prompt = "%s already selected - select again" % card
                 player.send(InvalidTargetEvent(), target=card)
             else:
                 self._cards.append(card)
                 prompt = "Select %d %s(s) to %s" % (self.number - len(
                     self._cards), self.cardtype, self.action_txt % '')
             if len(self._cards) == self.number: break
     return True