Esempio n. 1
0
    def add(self, obj, from_top=0, shuffle=True):
        """ Note: the library is reversed; i.e. self.elements[0] is the last card

        When you draw, you draw from self.pop(), or self.elements[-1]
        """
        if type(obj) is str:
            obj = cards.card_from_name(obj)
        assert isinstance(obj, gameobject.GameObject)
        obj.controller = self.controller
        obj.game = self.controller.game
        obj.zone = self

        if from_top == 0:
            self.elements.append(obj)
        elif from_top == -1:  # put on bottom
            self.elements = [obj] + self.elements
        else:
            self.elements = self.elements[:-from_top] + [
                obj
            ] + self.elements[-from_top:]

        if shuffle:
            self.shuffle()

        return obj
Esempio n. 2
0
    def add(self, obj, status_mod=None, modi_func=None):
        if type(obj) is str:  # convert string (card's name) to a Card object
            obj = cards.card_from_name(obj)
        obj.controller = self.controller

        if isinstance(obj, card.Card):  # convert card to Permanent
            obj = permanent.make_permanent(
                obj, status_mod,
                modi_func)  # this will call Battlefield.add(...) again
        else:
            obj.zone = self
            self.elements.append(obj)
            obj.status = permanent.Status(
            )  # reset status upon entering battlefield
            if status_mod:
                if 'tapped' in status_mod:
                    status.tapped = True

            if modi_func:  # apply "enter the battlefield with ..." effects: e.g. tapped
                modi_func(self)

            obj.trigger('onEtB', obj)
            obj.controller.trigger('onControllerPermanentEtB', obj)
            obj.game.trigger('onPermanentEtB', obj)
            if obj.is_creature:
                obj.controller.trigger('onControllerCreatureEtB', obj)
                obj.game.trigger('onCreatureEtB', obj)
Esempio n. 3
0
    def play_card(self, card):
        if isinstance(card, str):  # convert card name to Card object
            card = cards.card_from_name(card)

        _play = play.Play(card.play_func)
        if _play.is_mana_ability or _play.is_special_action:  # applies instantly
            _play.apply()
        else:
            self.game.stack.add(play)  # add to stack
Esempio n. 4
0
    def add(self, obj):
        if type(obj) is str:  # convert string (card's name) to a Card object
            obj = cards.card_from_name(obj)

        if type(obj) is list:
            for o in obj:
                o.zone = self
                if not isinstance(self, Stack):
                    assert isinstance(o, gameobject.GameObject)
                o.controller = self.controller
            self.elements.extend(obj)
            return obj

        if not isinstance(self, Stack):
            assert isinstance(obj, gameobject.GameObject)
            obj.controller = self.controller
            obj.game = self.controller.game

        obj.zone = self
        self.elements.append(obj)
        return obj