Esempio n. 1
0
 def test_bind(self):
     event = mock.Mock()
     binder = Bindable()
     binder.bind("test", event)
     binder.trigger("test", 1, 5, 6)
     event.assert_called_once_with(1, 5, 6)
     binder.unbind("test", event)
     binder.trigger("test")
     event.assert_called_once_with(1, 5, 6)
Esempio n. 2
0
    def __init__(self, name, mana, character_class, rarity, collectible, target_func=None,
                 filter_func=_is_spell_targetable, overload=0, ref_name=None, effects=None, buffs=None):
        """
            Creates a new :class:`Card`.

            ``target_func`` and ``filter_func`` have very specific behavior.  In use, the target function is called with
             the filter function as a parameter to generate the list of possible targets for the card, then ask the
             agent to choose the appropriate target.  The selected target will be available as the :attr:`target`
             attribute of :class:`Card`. As such, it is critical to call :meth:`use` in any overriding implementations.

            :param string name: The name of the card in English
            :param int mana: The base amount of mana this card costs
            :param int character_class: A constant from :class:`hearthbreaker.constants.CHARACTER_CLASS` denoting
                                        which character this card belongs to or
                                        :const:`hearthbreaker.constants.CHARACTER_CLASS.ALL` if neutral
            :param int rarity: A constant from :class:`hearthbreaker.constants.CARD_RARITY` denoting the rarity of the
                               card.
            :param function target_func: A function which takes a game, and returns a list of targets.  If None, then
                                         the card is assumed not to require a target.  If `target_func` returns
                                         an empty list, then the card cannot be played.  If it returns None, then the
                                         card is played, but with no target (i.e. a battlecry which has no valid target
                                         will not stop the minion from being played).

                                         See :mod:`hearthbreaker.targeting` for more details.
            :param function filter_func: A boolean function which can be used to filter the list of targets. An example
                                         for :class:`hearthbreaker.cards.spells.priest.ShadowMadness` might be a
                                         function which returns true if the target's attack is less than 3.
            :param int overload: The amount of overload on the card
            :param effects:  The effects that will be triggered for this card
            :type effects: [:class:`hearthbreaker.tags.base.Effect`]
            :param buffs:  The buffs that will be applied directly to this card
            :type buffs: [:class:`hearthbreaker.tags.base.Buff`]
        """
        Bindable.__init__(self)
        GameObject.__init__(self, effects=effects, buffs=buffs)
        self.name = name
        if ref_name:
            self.ref_name = ref_name
        else:
            self.ref_name = name
        self.mana = mana
        self.character_class = character_class
        self.rarity = rarity
        self.cancel = False
        self.targetable = target_func is not None
        if self.targetable:
            self.targets = []
            self.target = None
            self.get_targets = target_func
            self.filter_func = filter_func
        self.overload = overload
        self.drawn = True
        self.current_target = None
        self.collectible = collectible
Esempio n. 3
0
    def __init__(self, name, mana, character_class, rarity, collectible, target_func=None,
                 filter_func=_is_spell_targetable, overload=0, ref_name=None, effects=None, buffs=None):
        """
            Creates a new :class:`Card`.

            ``target_func`` and ``filter_func`` have very specific behavior.  In use, the target function is called with
             the filter function as a parameter to generate the list of possible targets for the card, then ask the
             agent to choose the appropriate target.  The selected target will be available as the :attr:`target`
             attribute of :class:`Card`. As such, it is critical to call :meth:`use` in any overriding implementations.

            :param string name: The name of the card in English
            :param int mana: The base amount of mana this card costs
            :param int character_class: A constant from :class:`hearthbreaker.constants.CHARACTER_CLASS` denoting
                                        which character this card belongs to or
                                        :const:`hearthbreaker.constants.CHARACTER_CLASS.ALL` if neutral
            :param int rarity: A constant from :class:`hearthbreaker.constants.CARD_RARITY` denoting the rarity of the
                               card.
            :param function target_func: A function which takes a game, and returns a list of targets.  If None, then
                                         the card is assumed not to require a target.  If `target_func` returns
                                         an empty list, then the card cannot be played.  If it returns None, then the
                                         card is played, but with no target (i.e. a battlecry which has no valid target
                                         will not stop the minion from being played).

                                         See :mod:`hearthbreaker.targeting` for more details.
            :param function filter_func: A boolean function which can be used to filter the list of targets. An example
                                         for :class:`hearthbreaker.cards.spells.priest.ShadowMadness` might be a
                                         function which returns true if the target's attack is less than 3.
            :param int overload: The amount of overload on the card
            :param effects:  The effects that will be triggered for this card
            :type effects: [:class:`hearthbreaker.tags.base.Effect`]
            :param buffs:  The buffs that will be applied directly to this card
            :type buffs: [:class:`hearthbreaker.tags.base.Buff`]
        """
        Bindable.__init__(self)
        GameObject.__init__(self, effects=effects, buffs=buffs)
        self.name = name
        if ref_name:
            self.ref_name = ref_name
        else:
            self.ref_name = name
        self.mana = mana
        self.character_class = character_class
        self.rarity = rarity
        self.cancel = False
        self.targetable = target_func is not None
        if self.targetable:
            self.targets = []
            self.target = None
            self.get_targets = target_func
            self.filter_func = filter_func
        self.overload = overload
        self.drawn = True
        self.current_target = None
        self.collectible = collectible
Esempio n. 4
0
 def test_bind_once(self):
     event = mock.Mock()
     event2 = mock.Mock()
     binder = Bindable()
     binder.bind_once("test", event)
     binder.bind("test", event2)
     binder.trigger("test", 1, 5, 6)
     event.assert_called_once_with(1, 5, 6)
     event2.assert_called_once_with(1, 5, 6)
     binder.trigger("test")
     event.assert_called_once_with(1, 5, 6)
     self.assertEqual(event2.call_count, 2)
Esempio n. 5
0
 def test_bind(self):
     event = mock.Mock()
     binder = Bindable()
     binder.bind("test", event)
     binder.trigger("test", 1, 5, 6)
     event.assert_called_once_with(1, 5, 6)
     binder.unbind("test", event)
     binder.trigger("test")
     event.assert_called_once_with(1, 5, 6)
Esempio n. 6
0
 def test_bind_once(self):
     event = mock.Mock()
     event2 = mock.Mock()
     binder = Bindable()
     binder.bind_once("test", event)
     binder.bind("test", event2)
     binder.trigger("test", 1, 5, 6)
     event.assert_called_once_with(1, 5, 6)
     event2.assert_called_once_with(1, 5, 6)
     binder.trigger("test")
     event.assert_called_once_with(1, 5, 6)
     self.assertEqual(event2.call_count, 2)