Esempio n. 1
0
 def add(self, ability, tag=''):
     if isiterable(ability):
         self._abilities.extend(ability)
     else:
         ability.tag = tag
         self._abilities.append(ability)
         if ability.keyword: self._keywords[ability.keyword] = ability
Esempio n. 2
0
 def add(self, ability, tag=''):
     if isiterable(ability):
         self._abilities.extend(ability)
     else:
         ability.tag = tag
         self._abilities.append(ability)
         if ability.keyword: self._keywords[ability.keyword] = ability
Esempio n. 3
0
 def set_copy(self, chargroup, extra_chars=None):
     # find last copy effect
     chargroup = chargroup.copy()
     if extra_chars:
         if not isiterable(extra_chars): extra_chars = (extra_chars,)
         chargroup.add(*extra_chars)
     chargroup._copyable = True
     return self._insert_into_stacking(chargroup, pos=self._after_last_copyable_index)
Esempio n. 4
0
 def getCardSelection(self, selection, number, cardtype=isCard, zone=None, player=None, required=True, prompt=''):
     def filter(action):
         if isinstance(action, CancelAction):
             if not required: return action
             else: return False
         if not isinstance(action, PassPriority): return action.selection
         else: return False
     if not isiterable(cardtype): cardtype = (cardtype,)
     def check_card(card):
         valid = True
         for ctype in cardtype:
             if ctype(card): break
         else: valid = False
         return valid
     if number > len(selection): number = len(selection)
     if not zone: zone = str(selection[0].zone)
     if not player: player = selection[0].controller
     context = {'get_cards': True, 'list':selection, 'numselections': number, 'required': required, 'process': filter, 'from_zone': zone, 'from_player': player, 'check_card': check_card}
     sel = self.input(context, "%s: %s"%(self.name,prompt))
     if isinstance(sel, CancelAction): return []
     else: return sel
Esempio n. 5
0
 def getCardSelection(self, selection, number, cardtype=isCard, zone=None, player=None, required=True, prompt=''):
     def filter(action):
         if isinstance(action, CancelAction):
             if not required: return action
             else: return False
         if not isinstance(action, PassPriority): return action.selection
         else: return False
     if not isiterable(cardtype): cardtype = (cardtype,)
     def check_card(card):
         valid = True
         for ctype in cardtype:
             if ctype(card): break
         else: valid = False
         return valid
     if number > len(selection): number = len(selection)
     if not zone: zone = str(selection[0].zone)
     if not player: player = selection[0].controller
     context = {'get_cards': True, 'list':selection, 'numselections': number, 'required': required, 'process': filter, 'from_zone': zone, 'from_player': player, 'check_card': check_card}
     sel = self.input(context, "%s: %s"%(self.name,prompt))
     if isinstance(sel, CancelAction): return []
     else: return sel
Esempio n. 6
0
    def getTarget(self, target_types, zone=None, from_player=None, required=True, prompt='Select target'):
        # If required is True (default) then you can't cancel the request for a target
        if not isiterable(target_types): target_types = (target_types,)
        def filter(action):
            # This function is really convoluted
            # If I return False here then the input function will keep cycling until valid input
            if isinstance(action, CancelAction):
                if not required: return action
                else: return False
            elif isinstance(action, PassPriority): return False

            target = action.selection
            if isPlayer(target) or ((not zone or str(target.zone) == zone) and (not from_player or (from_player == "you" and target.controller == self) or (from_player == "opponent" and target.controller in self.opponents))):
                for target_type in target_types:
                    if target_type(target): return target
            # Invalid target
            self.send(InvalidTargetEvent(), target=target)
            return False
        context = {'get_target': True, 'process': filter}
        target = self.input(context, "%s: %s"%(self.name,prompt))

        if isinstance(target, CancelAction) or isinstance(target, PassPriority): return False
        return target
Esempio n. 7
0
    def getTarget(self, target_types, zone=None, from_player=None, required=True, prompt='Select target'):
        # If required is True (default) then you can't cancel the request for a target
        if not isiterable(target_types): target_types = (target_types,)
        def filter(action):
            # This function is really convoluted
            # If I return False here then the input function will keep cycling until valid input
            if isinstance(action, CancelAction):
                if not required: return action
                else: return False
            elif isinstance(action, PassPriority): return False

            target = action.selection
            if isPlayer(target) or ((not zone or str(target.zone) == zone) and (not from_player or (from_player == "you" and target.controller == self) or (from_player == "opponent" and target.controller in self.opponents))):
                for target_type in target_types:
                    if target_type(target): return target
            # Invalid target
            self.send(InvalidTargetEvent(), target=target)
            return False
        context = {'get_target': True, 'process': filter}
        target = self.input(context, "%s: %s"%(self.name,prompt))

        if isinstance(target, CancelAction) or isinstance(target, PassPriority): return False
        return target