Пример #1
0
    def test_timed_effect_is_triggered(self):
        """
        Test that timed effect is triggered only after enough time
        has passed
        """
        effect_factory = EffectsFactory()
        effect_factory.add_effect(
                            'major heal',
                            {'type': Heal,
                            'duration': 12,
                            'frequency': 3,
                            'tick': 3,
                            'healing': 10})

        potion = (ItemBuilder()
                        .with_effect(
                            EffectHandleBuilder()
                                .with_trigger('on drink')
                                .with_effect('major heal')
                                .with_charges(2))
                        .build())

        action_factory = ActionFactory(model = mock(),
                                       factories = [DrinkFactory(effect_factory)])

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

        character.drink(potion)

        assert_that(character, has_effects(1))
Пример #2
0
    def test_creating_effect(self):
        """
        Test that effect can be created and triggered immediately
        """
        effect_factory = EffectsFactory()
        effect_factory.add_effect(
                            'major heal',
                            {'type': Heal,
                            'duration': 0,
                            'frequency': 0,
                            'tick': 0,
                            'healing': 10})

        potion = (ItemBuilder()
                        .with_effect(
                            EffectHandleBuilder()
                                .with_trigger('on drink')
                                .with_effect('major heal')
                                .with_charges(2))
                        .build())

        action_factory = ActionFactory(model = mock(),
                                       factories = [DrinkFactory(effect_factory)])

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

        character.drink(potion)

        assert_that(character.hit_points, is_(equal_to(10)))
        assert_that(character, has_no_effects())
Пример #3
0
    def test_creating_poison(self):
        """
        Test that poison effect can be created
        """
        character = CharacterBuilder().build()
        factory = EffectsFactory()
        factory.add_effect('poison',
                            {'type': Poison,
                            'duration': 150,
                            'frequency': 30,
                            'tick': 10,
                            'damage': 5})

        effect = factory.create_effect('poison',
                                       target = character)

        assert_that(effect.duration, is_(equal_to(150)))
        assert_that(effect.frequency, is_(equal_to(30)))
        assert_that(effect.damage, is_(equal_to(5)))
        assert_that(effect.target, is_(equal_to(character)))
Пример #4
0
    def setup(self):
        """
        Setup test case
        """
        self.model = mock()

        effect_factory = EffectsFactory()
        effect_factory.add_effect(
                            'poison',
                            {'type': Poison,
                            'duration': 12,
                            'frequency': 3,
                            'tick': 3,
                            'damage': 5})

        action_factory = (ActionFactoryBuilder()
                            .with_attack_factory()
                            .with_effect_factory(effect_factory)
                            .build())

        self.attacker = (CharacterBuilder()
                            .with_action_factory(action_factory)
                            .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_action_factory(action_factory)
                            .with_location((5, 4))
                            .with_hit_points(50)
                            .with_model(self.model)
                            .build())

        level = (LevelBuilder()
                    .with_character(self.attacker)
                    .with_character(self.defender)
                    .build())
Пример #5
0
    def initialise_factories(self, level_config):
        """
        Initialises action factory, sub factories and various generators
        """
        self.logger.info('Initialising action sub system')

        walk_factory = WalkFactory()
        move_factory = MoveFactory(walk_factory)

        effect_factory = EffectsFactory()

        configurators = self.get_configurators(level_config,
                                               'init_effects')

        for configurator in configurators:
            effects = configurator()
            for effect in effects:
                effect_factory.add_effect(effect[0], effect[1])

        unarmed_combat_factory = UnarmedCombatFactory(effect_factory)
        melee_combat_factory = MeleeCombatFactory(effect_factory)
        attack_factory = AttackFactory([
                                        unarmed_combat_factory,
                                        melee_combat_factory])

        drink_factory = DrinkFactory(effect_factory)

        inventory_factory = InventoryFactory(PickUpFactory())

        self.action_factory = ActionFactory(
                                            self.model,
                                            [move_factory,
                                            attack_factory,
                                            drink_factory,
                                            inventory_factory])

        self.logger.info('Action sub system initialised')