def test_detect_mismatch_in_collection(self):
        """
        Test that matcher can detect a mismatch in collection
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger='on drink',
                               effect=None,
                               parameters=None,
                               charges=1)

        handle2 = EffectHandle(trigger='on kick',
                               effect=None,
                               parameters=None,
                               charges=1)

        handle3 = EffectHandle(trigger='on burn',
                               effect=None,
                               parameters=None,
                               charges=1)

        collection.add_effect_handle(handle1)
        collection.add_effect_handle(handle2)

        matcher = ContainsEffectHandle([handle1, handle2, handle3])

        assert_that(matcher._matches(collection), is_(equal_to(False)))
示例#2
0
    def test_match_any(self):
        """
        Test that matcher can match to any handle
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)

        matcher = ContainsEffectHandle(None)

        assert_that(matcher._matches(collection), is_(equal_to(True)))
示例#3
0
    def test_match_single_handle(self):
        """
        Test that single handle can be matched
        """
        collection = EffectsCollection()
        handle = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle)

        matcher = ContainsEffectHandle(handle)

        assert_that(matcher._matches(collection), is_(equal_to(True)))
示例#4
0
    def test_detect_sinle_mismatch(self):
        """
        Test that missing a single handle is detected correctly
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)

        handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1)

        matcher = ContainsEffectHandle(handle2)

        assert_that(matcher._matches(collection), is_(equal_to(False)))
    def test_match_any(self):
        """
        Test that matcher can match to any handle
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger='on drink',
                               effect=None,
                               parameters=None,
                               charges=1)

        collection.add_effect_handle(handle1)

        matcher = ContainsEffectHandle(None)

        assert_that(matcher._matches(collection), is_(equal_to(True)))
    def test_match_single_handle(self):
        """
        Test that single handle can be matched
        """
        collection = EffectsCollection()
        handle = EffectHandle(trigger='on drink',
                              effect=None,
                              parameters=None,
                              charges=1)

        collection.add_effect_handle(handle)

        matcher = ContainsEffectHandle(handle)

        assert_that(matcher._matches(collection), is_(equal_to(True)))
示例#7
0
    def test_match_multiple_handles(self):
        """
        Test that matcher can match multiple handlers
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)
        collection.add_effect_handle(handle2)

        matcher = ContainsEffectHandle([handle1, handle2])

        assert_that(matcher._matches(collection), is_(equal_to(True)))
示例#8
0
    def test_detect_mismatch_in_collection(self):
        """
        Test that matcher can detect a mismatch in collection
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1)

        handle3 = EffectHandle(trigger="on burn", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)
        collection.add_effect_handle(handle2)

        matcher = ContainsEffectHandle([handle1, handle2, handle3])

        assert_that(matcher._matches(collection), is_(equal_to(False)))
    def test_detect_sinle_mismatch(self):
        """
        Test that missing a single handle is detected correctly
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger='on drink',
                               effect=None,
                               parameters=None,
                               charges=1)

        collection.add_effect_handle(handle1)

        handle2 = EffectHandle(trigger='on kick',
                               effect=None,
                               parameters=None,
                               charges=1)

        matcher = ContainsEffectHandle(handle2)

        assert_that(matcher._matches(collection), is_(equal_to(False)))
示例#10
0
    def test_match_multiple_handles(self):
        """
        Test that matcher can match multiple handlers
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger='on drink',
                               effect=None,
                               parameters=None,
                               charges=1)

        handle2 = EffectHandle(trigger='on kick',
                               effect=None,
                               parameters=None,
                               charges=1)

        collection.add_effect_handle(handle1)
        collection.add_effect_handle(handle2)

        matcher = ContainsEffectHandle([handle1, handle2])

        assert_that(matcher._matches(collection), is_(equal_to(True)))
示例#11
0
class Spell():
    """
    Class to represent spells

    .. versionadded:: 0.9
    """

    @log_debug
    def __init__(self):
        """
        Default constructor
        """
        self.targets = []
        self.effects = EffectsCollection()
        self.spirit = 0

    @log_debug
    def add_effect_handle(self, handle):
        """
        Add effect handle

        :param handle: effect handle to add
        :type handle: EffectHandle
        """
        self.effects.add_effect_handle(handle)

    @log_debug
    def get_effect_handles(self, trigger=None):
        """
        Get effect handles

        :param trigger: optional trigger type
        :type trigger: string

        :returns: effect handles
        :rtype: [EffectHandle]
        """
        return self.effects.get_effect_handles(trigger)

    @log_debug
    def remove_effect_handle(self, handle):
        """
        Remove given handle

        :param handle: handle to remove
        :type handle: EffectHandle
        """
        self.effects.remove_effect_handle(handle)

    @log_info
    def cast(self, effects_factory):
        """
        Cast the spell

        :param effects_factory: factory for creating effects
        :type effects_factory: EffectsFactory
        """
        handles = self.effects.get_effect_handles('on spell hit')
        effects = []

        targets = (x.target for x in self.targets
                   if x.target)

        for target in targets:
            for handle in handles:
                effects.append(effects_factory(key=handle.effect,
                                               target=target))

        for effect in effects:
            if not effect.duration or effect.duration <= 0:
                effect.trigger()
            else:
                effect.target.add_effect(effect)
示例#12
0
class Spell():
    """
    Class to represent spells

    .. versionadded:: 0.9
    """
    @log_debug
    def __init__(self):
        """
        Default constructor
        """
        self.targets = []
        self.effects = EffectsCollection()
        self.spirit = 0

    @log_debug
    def add_effect_handle(self, handle):
        """
        Add effect handle

        :param handle: effect handle to add
        :type handle: EffectHandle
        """
        self.effects.add_effect_handle(handle)

    @log_debug
    def get_effect_handles(self, trigger=None):
        """
        Get effect handles

        :param trigger: optional trigger type
        :type trigger: string

        :returns: effect handles
        :rtype: [EffectHandle]
        """
        return self.effects.get_effect_handles(trigger)

    @log_debug
    def remove_effect_handle(self, handle):
        """
        Remove given handle

        :param handle: handle to remove
        :type handle: EffectHandle
        """
        self.effects.remove_effect_handle(handle)

    @log_info
    def cast(self, effects_factory):
        """
        Cast the spell

        :param effects_factory: factory for creating effects
        :type effects_factory: EffectsFactory
        """
        handles = self.effects.get_effect_handles('on spell hit')
        effects = []

        targets = (x.target for x in self.targets if x.target)

        for target in targets:
            for handle in handles:
                effects.append(
                    effects_factory(key=handle.effect, target=target))

        for effect in effects:
            if not effect.duration or effect.duration <= 0:
                effect.trigger()
            else:
                effect.target.add_effect(effect)