示例#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)
示例#2
0
    def __call__(self, character):
        """
        Execute the action
        """
        set_action_factory(ActionFactoryBuilder().with_gain_domain_factory().
                           build())  # TODO: mutating global state is bad

        gain_domain(character=character, item=self.item, domain=self.domain)
示例#3
0
    def action_factorize(*args, **kwargs):
        """
        Inject action factory
        """
        context = args[0]

        if not hasattr(context, 'action_factory'):
            context.action_factory = (ActionFactoryBuilder(
            ).with_drink_factory().with_inventory_factory().build())

            set_action_factory(context.action_factory)

        return fn(*args, **kwargs)
示例#4
0
    def setup(self):
        """
        Setup test case
        """
        self.model = Model()

        self.character = (CharacterBuilder().with_model(
            self.model).with_location((1, 1)).build())

        self.model.dungeon = (LevelBuilder().with_character(
            self.character).build())

        self.listener = mock()

        self.model.register_event_listener(self.listener)

        set_action_factory(ActionFactoryBuilder().build())
示例#5
0
    def __call__(self, actor):
        """
        Performs the drop action

        :param actor: character dropping the item
        :type actor: Character
        """
        add_history_value(actor, 'location')
        add_history_value(actor, 'level')
        add_history_value(actor, 'inventory')
        add_history_value(actor, 'tick')

        set_action_factory(
            ActionFactoryBuilder().with_drink_factory().with_inventory_factory(
            ).build())  # TODO: mutating global state is bad

        drop_item(actor, self.item)
示例#6
0
    def setup(self):
        """
        Test setup
        """
        self.level = LevelBuilder().build()

        self.monster_1 = (CharacterBuilder().with_name('Pete').build())

        self.monster_2 = (CharacterBuilder().with_name('Uglak').build())

        self.monster_1.artificial_intelligence = lambda: None
        self.monster_2.artificial_intelligence = lambda: None

        add_character(self.level, (5, 5), self.monster_1)
        add_character(self.level, (6, 5), self.monster_2)

        set_action_factory(ActionFactoryBuilder().build())
示例#7
0
    def test_creating_action(self):
        """
        Test that action can be created
        """
        spell_factory = mock()
        when(spell_factory).build().thenReturn(spell_factory)
        when(spell_factory).create_spell(any(), any()).thenReturn([mock()])
        spell_factory.spell_list = {'healing wind': mock()}
        action_factory = (ActionFactoryBuilder().with_spellcasting_factory(
            SpellCastingFactoryBuilder().with_spell_factory(
                spell_factory).build()).build())

        action = action_factory.get_action(
            SpellCastingParameters(self,
                                   direction=1,
                                   spell_name='healing wind'))

        assert_that(action, is_not(None))
示例#8
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()
示例#9
0
    def __call__(self, character):
        """
        Performs taking a single step

        :param character: character walking
        :type character: Character
        """
        add_history_value(character, 'tick')

        action_factory = (ActionFactoryBuilder().build())

        directions = [
            direction for direction in range(1, 9)
            if pyherc.vtable['\ufdd0:is-move-legal'](character, direction)
        ]

        assert len(directions) > 0

        pyherc.vtable['\ufdd0:move'](character=character,
                                     direction=directions[0])
示例#10
0
    def __call__(self, attacker):
        """
        Performs the hit

        :param attacker: character attacking
        :type attacker: Character
        """
        add_history_value(self.target, 'hit_points')

        rng = mock()
        when(rng).randint(1, 6).thenReturn(1)

        action_factory = (ActionFactoryBuilder().with_drink_factory().
                          with_inventory_factory().build())

        set_action_factory(
            action_factory)  # TODO: mutating global state is bad

        pyherc.vtable['\ufdd0:attack'](attacker,
                                       find_direction(attacker.location,
                                                      self.target.location))
示例#11
0
    def setup(self):
        """
        Setup test case
        """
        self.model = mock()

        effects = get_effect_creator({'poison':
                                        {'type': Poison,
                                         'duration': 12,
                                         'frequency': 3,
                                         'tick': 3,
                                         'damage': 5,
                                         'icon': 101,
                                         'title': 'poison',
                                         'description': 'Causes damage'}})

        pyherc.vtable['\ufdd0:create-effect'] = effects
        
        set_action_factory(ActionFactoryBuilder()
                           .with_effect_factory(effects)
                           .build())

        self.attacker = (CharacterBuilder()
                         .with_location((5, 5))
                         .with_effect_handle(EffectHandleBuilder()
                                             .with_trigger('on attack hit')
                                             .with_effect('poison'))
                         .with_model(self.model)
                         .build())

        self.defender = (CharacterBuilder()
                         .with_location((5, 4))
                         .with_hit_points(50)
                         .with_model(self.model)
                         .build())

        (LevelBuilder().with_character(self.attacker)
                       .with_character(self.defender)
                       .build())
示例#12
0
    def setup(self):
        """
        Setup the test case
        """
        self.character = (CharacterBuilder().with_model(Model()).build())

        self.level1 = (LevelBuilder().with_floor_tile("floor").with_wall_at(
            (1, 0)).build())

        self.level2 = (LevelBuilder().with_floor_tile("floor").build())
        self.portal1 = Portal((None, None), None)

        self.portal1.icon = 1
        self.portal2 = Portal(("stairs", "stairs"), None)
        self.portal2 = Portal(("stairs", "stairs"), None)

        add_portal(self.level1, (5, 5), self.portal1)
        add_portal(self.level2, (10, 10), self.portal2, self.portal1)

        add_character(self.level1, (5, 5), self.character)

        set_action_factory(ActionFactoryBuilder().build())
示例#13
0
    def setup(self):
        """
        Setup test cases
        """
        self.item = (ItemBuilder()
                        .build())

        self.model = Model()

        self.level = LevelBuilder().build()

        self.character = (CharacterBuilder()
                            .with_location((5, 5))
                            .with_level(self.level)
                            .with_model(self.model)
                            .build())

        add_item(self.level, (5, 5), self.item)

        set_action_factory(ActionFactoryBuilder()
                           .with_inventory_factory()
                           .build())
示例#14
0
    def test_creating_effect(self):
        """
        Test that effect can be created and triggered immediately
        """
        effect_factory = get_effect_creator({'major heal':
                                                {'type': Heal,
                                                 'duration': 0,
                                                 'frequency': 0,
                                                 'tick': 0,
                                                 'healing': 10,
                                                 'icon': 100,
                                                 'title': 'healig',
                                                 'description': 'healing'}})

        pyherc.vtable['\ufdd0:create-effect'] = effect_factory
        
        potion = (ItemBuilder()
                  .with_effect_handle(EffectHandleBuilder()
                               .with_trigger('on drink')
                               .with_effect('major heal')
                               .with_charges(2))
                  .build())

        set_action_factory(ActionFactoryBuilder()
                           .with_drink_factory(DrinkFactoryBuilder()
                                               .with_effect_factory(effect_factory))  # noqa
                           .build())

        character = (CharacterBuilder()
                     .with_hit_points(1)
                     .with_max_hp(10)
                     .build())

        drink(character,
              potion)

        assert_that(character.hit_points, is_(equal_to(10)))
        assert_that(character, has_no_effects())
示例#15
0
    def test_drinking_triggers_effect(self):
        """
        Test that timed effect is triggered only after enough time
        has passed
        """
        effect_factory = get_effect_creator({'major heal':
                                                {'type': Heal,
                                                 'duration': 12,
                                                 'frequency': 3,
                                                 'tick': 3,
                                                 'healing': 10,
                                                 'icon': 100,
                                                 'title': 'healig',
                                                 'description': 'healing'}})

        pyherc.vtable['\ufdd0:create-effect'] = effect_factory
        
        potion = (ItemBuilder()
                  .with_effect_handle(EffectHandleBuilder()
                               .with_trigger('on drink')
                               .with_effect('major heal')
                               .with_charges(2))
                  .build())

        set_action_factory(ActionFactoryBuilder()
                           .with_drink_factory(DrinkFactoryBuilder()
                                               .with_effect_factory(effect_factory))  # noqa
                           .build())

        character = (CharacterBuilder()
                     .with_hit_points(1)
                     .with_max_hp(10)
                     .build())

        drink(character,
              potion)

        assert_that(character, has_effects(1))
示例#16
0
    def setup(self):
        """
        Setup for testcases
        """
        self.model = Model()

        set_action_factory(ActionFactoryBuilder().build())

        self.character1 = (CharacterBuilder().with_model(
            self.model).with_hit_points(10).with_attack(3).with_body(
                5).build())

        self.effect = DamageModifier(modifier=1,
                                     damage_type='crushing',
                                     duration=None,
                                     frequency=None,
                                     tick=None,
                                     icon=101,
                                     title='Weakness against crushing',
                                     description='This character is weak')
        self.effect.multiple_allowed = True

        self.character2 = (CharacterBuilder().with_model(
            self.model).with_hit_points(10).with_attack(3).with_body(
                5).with_effect(self.effect).build())

        self.model.dungeon = Dungeon()
        self.level = (LevelBuilder().with_character(self.character1,
                                                    at_(5, 5)).with_character(
                                                        self.character2,
                                                        at_(6, 5)).build())

        self.model.dungeon.levels = self.level

        self.rng = mock()
        when(self.rng).randint(1, 6).thenReturn(1)
    def setup(self):
        """
        Setup test cases
        """
        self.character = (CharacterBuilder().with_hit_points(10).build())

        self.target = (CharacterBuilder().with_hit_points(10).build())

        self.level = (LevelBuilder().build())

        add_character(self.level, (2, 2), self.character)
        add_character(self.level, (5, 2), self.target)

        bow = (ItemBuilder().with_name('bow').with_required_ammunition_type(
            'arrow').with_damage(1, 'crushing').build())
        self.arrows = (ItemBuilder().with_name('arrows').with_ammunition_type(
            'arrow').with_range_damage(3, 'piercing').with_count(10).build())

        self.character.inventory.append(bow)
        self.character.inventory.append(self.arrows)
        self.character.inventory.weapon = bow
        self.character.inventory.projectiles = self.arrows

        set_action_factory(ActionFactoryBuilder().build())
 def setup(self):
     """
     Setup test case
     """
     set_action_factory(
         ActionFactoryBuilder().with_inventory_factory().build())