Example #1
0
    def __call__(self, caster):
        """
        Performs the casting

        :param caster: character doing the casting
        :type caster: Character
        """
        add_history_value(caster, 'hit_points')

        spell_factory = SpellGeneratorBuilder().build()

        effects_factory = get_effect_creator({
            'heal medium wounds': {
                'type': Heal,
                'duration': None,
                'frequency': None,
                'tick': 0,
                'healing': 10,
                'icon': None,
                'title': 'Heal medium wounds',
                'description': 'Heals medium amount of damage'
            },  # noqa
            'cause wound': {
                'type': DamageEffect,
                'duration': None,
                'frequency': None,
                'tick': 0,
                'damage': 5,
                'damage_type': 'magic',
                'icon': None,
                'title': 'Cause minor wound',
                'description': 'Causes minor amount of damage'
            },  # noqa
            'fire': {
                'type': DamageEffect,
                'duration': 30,
                'frequency': 5,
                'tick': 0,
                'damage': 3,
                'damage_type': 'fire',
                'icon': None,
                'title': 'Fire',
                'description': 'You are on fire!'
            }
        })

        spell_casting_factory = (
            SpellCastingFactoryBuilder().with_spell_factory(
                spell_factory).with_effects_factory(effects_factory).build())

        set_action_factory(ActionFactoryBuilder().with_spellcasting_factory(
            spell_casting_factory).build()
                           )  # TODO: mutating global state is bad

        if self.target:
            direction = find_direction(caster.location, self.target.location)
        else:
            direction = 1

        cast(caster, direction=direction, spell_name=self.spell_name)
Example #2
0
    def __call__(self, caster):
        """
        Performs the casting

        :param caster: character doing the casting
        :type caster: Character
        """
        add_history_value(caster, 'hit_points')

        spell_factory = SpellGeneratorBuilder().build()

        effects_factory = get_effect_creator({'heal medium wounds':
                                        {'type': Heal,
                                         'duration': None,
                                         'frequency': None,
                                         'tick': 0,
                                         'healing': 10,
                                         'icon': None,
                                         'title': 'Heal medium wounds',
                                         'description': 'Heals medium amount of damage'},  # noqa
                                    'cause wound':
                                        {'type': DamageEffect,
                                         'duration': None,
                                         'frequency': None,
                                         'tick': 0,
                                         'damage': 5,
                                         'damage_type': 'magic',
                                         'icon': None,
                                         'title': 'Cause minor wound',
                                         'description': 'Causes minor amount of damage'},  # noqa
                                    'fire':
                                        {'type': DamageEffect,
                                         'duration': 30,
                                         'frequency': 5,
                                         'tick': 0,
                                         'damage': 3,
                                         'damage_type': 'fire',
                                         'icon': None,
                                         'title': 'Fire',
                                         'description': 'You are on fire!'}})

        spell_casting_factory = (SpellCastingFactoryBuilder()
                                 .with_spell_factory(spell_factory)
                                 .with_effects_factory(effects_factory)
                                 .build())

        set_action_factory(ActionFactoryBuilder()
                           .with_spellcasting_factory(spell_casting_factory)
                           .build()) # TODO: mutating global state is bad

        if self.target:
            direction = find_direction(caster.location,
                                       self.target.location)
        else:
            direction = 1

        cast(caster,
             direction=direction,
             spell_name=self.spell_name)
Example #3
0
    def test_spell_casting_executes_action(self):
        """
        Casting a spell should activate the action
        """
        magic_factory = SpellCastingFactoryBuilder().build()
        action = mock()
        when(action).is_legal().thenReturn(True)

        when(magic_factory).get_action(any()).thenReturn(
            action)  #pylint: disable-msg=E1103

        set_action_factory(ActionFactoryBuilder().with_spellcasting_factory(
            magic_factory).build())

        caster = (CharacterBuilder().build())

        cast(caster, direction=1, spell_name='healing wind')

        verify(action).execute()
Example #4
0
    def _move(self, key, modifiers):
        """
        Process movement key

        :param key: key triggering the processing
        :type key: int
        """
        player = self.model.player
        direction = self.move_key_map[key]

        if modifiers & Qt.ControlModifier:
            if direction != 9:
                pyherc.vtable["\ufdd0:attack"](player, direction)
        elif modifiers & Qt.AltModifier:
            if direction != 9:
                cast(player, direction, "fireball")

        else:
            self.move_controller.move_or_attack(player, direction)
Example #5
0
    def _move(self, key, modifiers):
        """
        Process movement key

        :param key: key triggering the processing
        :type key: int
        """
        player = self.model.player
        direction = self.move_key_map[key]

        if modifiers & Qt.ControlModifier:
            if direction != 9:
                pyherc.vtable['\ufdd0:attack'](player, direction)
        elif modifiers & Qt.AltModifier:
            if direction != 9:
                cast(player, direction, 'fireball')

        else:
            self.move_controller.move_or_attack(player, direction)
Example #6
0
    def test_spell_casting_executes_action(self):
        """
        Casting a spell should activate the action
        """
        magic_factory = SpellCastingFactoryBuilder().build()
        action = mock()
        when(action).is_legal().thenReturn(True)

        when(magic_factory).get_action(any()).thenReturn(action) #pylint: disable-msg=E1103

        set_action_factory(ActionFactoryBuilder()
                           .with_spellcasting_factory(magic_factory)
                           .build())

        caster = (CharacterBuilder()
                        .build())

        cast(caster,
             direction = 1,
             spell_name = 'healing wind')

        verify(action).execute()