Beispiel #1
0
    def setup(self):
        """
        Setup test cases
        """
        self.character = (CharacterBuilder()
                          .with_hit_points(10)
                          .with_max_hp(20)
                          .build())

        effect_config = {'healing wind':
                            {'type': Heal,
                             'duration': 0,
                             'frequency': 0,
                             'tick': 0,
                             'healing': 1,
                             'icon': 'icon',
                             'title': 'Cure minor wounds',
                             'description': 'Cures small amount of damage'}}

        self.effects = get_effect_creator(effect_config)

        self.effect_handle = EffectHandle(trigger = 'on spell hit',
                                          effect = 'healing wind',
                                          parameters = {},
                                          charges = 1)

        self.spell = (SpellBuilder()
                        .with_effect_handle(self.effect_handle)
                        .with_target(self.character)
                        .build())
Beispiel #2
0
    def test_casting_spell_raises_spirit_changed_event(self):
        """
        Since casting spells uses spirit, an appropriate event should be raised
        """
        spell = (SpellBuilder()
                     .with_spirit(10)
                     .build())

        caster = (CharacterBuilder()
                      .with_spirit(20)
                      .build())

        listener = EventListener()
        caster.register_for_updates(listener)

        effects_factory = mock()

        action = SpellCastingAction(caster = caster,
                                    spell = spell,
                                    effects_factory = effects_factory)
        action.execute()

        events = [event for event in listener.events
                  if e_event_type(event) == 'spirit points changed']

        assert_that(len(events), is_(equal_to(1)))
Beispiel #3
0
class TestSpellEffects:
    """
    Tests for spell effects
    """

    def __init__(self):
        """
        Default constructor
        """
        self.effect = None
        self.effect_handle = None
        self.spell = None
        self.effects = None

    def setup(self):
        """
        Setup test cases
        """
        self.character = CharacterBuilder().with_hit_points(10).with_max_hp(20).build()

        effect_config = {
            "healing wind": {
                "type": Heal,
                "duration": 0,
                "frequency": 0,
                "tick": 0,
                "healing": 1,
                "icon": "icon",
                "title": "Cure minor wounds",
                "description": "Cures small amount of damage",
            }
        }

        self.effects = get_effect_creator(effect_config)

        self.effect_handle = EffectHandle(trigger="on spell hit", effect="healing wind", parameters={}, charges=1)

        self.spell = SpellBuilder().with_effect_handle(self.effect_handle).with_target(self.character).build()

    def test_triggering_effect(self):
        """
        Casting a spell should trigger the effect
        """
        self.spell.cast(self.effects)

        assert_that(self.character.hit_points, is_(greater_than(10)))
Beispiel #4
0
    def test_casting_spell_uses_spirit(self):
        """
        Casting a spell should use spirit energy
        """
        spell = (SpellBuilder()
                     .with_spirit(10)
                     .build())

        caster = (CharacterBuilder()
                      .with_spirit(20)
                      .build())
        effects_factory = mock()

        action = SpellCastingAction(caster = caster,
                                    spell = spell,
                                    effects_factory = effects_factory)
        action.execute()

        assert_that(caster.spirit, is_(equal_to(10)))
Beispiel #5
0
    def setup(self):
        """
        Setup test cases
        """
        self.character = CharacterBuilder().with_hit_points(10).with_max_hp(20).build()

        effect_config = {
            "healing wind": {
                "type": Heal,
                "duration": 0,
                "frequency": 0,
                "tick": 0,
                "healing": 1,
                "icon": "icon",
                "title": "Cure minor wounds",
                "description": "Cures small amount of damage",
            }
        }

        self.effects = get_effect_creator(effect_config)

        self.effect_handle = EffectHandle(trigger="on spell hit", effect="healing wind", parameters={}, charges=1)

        self.spell = SpellBuilder().with_effect_handle(self.effect_handle).with_target(self.character).build()