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)
Exemple #2
0
    def test_creating_poison(self):
        """
        Test that poison effect can be created
        """
        character = CharacterBuilder().build()
        effects = get_effect_creator(
            {
                "poison": {
                    "type": Poison,
                    "duration": 150,
                    "frequency": 30,
                    "tick": 10,
                    "damage": 5,
                    "icon": 101,
                    "title": "Moderate poison",
                    "description": "Causes damage",
                }
            }
        )

        effect = effects("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)))
        assert_that(effect.icon, is_(equal_to(101)))
        assert_that(effect.title, is_(equal_to("Moderate poison")))
        assert_that(effect.description, is_(equal_to("Causes damage")))
Exemple #3
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())
    def test_creating_poison(self):
        """
        Test that poison effect can be created
        """
        character = CharacterBuilder().build()
        effects = get_effect_creator({
            'poison': {
                'type': Poison,
                'duration': 150,
                'frequency': 30,
                'tick': 10,
                'damage': 5,
                'icon': 101,
                'title': 'Moderate poison',
                'description': 'Causes damage'
            }
        })

        effect = effects('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)))
        assert_that(effect.icon, is_(equal_to(101)))
        assert_that(effect.title, is_(equal_to('Moderate poison')))
        assert_that(effect.description, is_(equal_to('Causes damage')))
    def setup(self):
        """
        Setup the test case
        """
        self.rng = Random()
        self.model = mock()

        self.effect_factory = get_effect_creator({
            'heal': {
                'type': Heal,
                'duration': 0,
                'frequency': 0,
                'tick': 0,
                'healing': 10,
                'icon': 101,
                'title': 'title',
                'description': 'major heal'
            }
        })

        drink_factory = DrinkFactory(self.effect_factory)
        set_action_factory(ActionFactory(self.model, drink_factory))

        self.character = (
            CharacterBuilder().with_hit_points(1).with_max_hp(5).build())
        effect = (HealBuilder().with_duration(0).with_frequency(0).with_tick(
            0).with_healing(5).with_target(self.character).build())

        self.potion = (
            ItemBuilder().with_name('healing potion').with_effect_handle(
                EffectHandleBuilder().with_trigger('on drink').with_effect(
                    'heal')).build())

        self.character.inventory.append(self.potion)
Exemple #6
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)
Exemple #7
0
    def initialise_factories(self, context):
        """
        Initialises action factory, sub factories and various generators
        """
        effect_config = {}
        configurators = self.get_configurators(context.config_package,
                                               'init_effects')

        for configurator in configurators:
            effects = configurator(context)
            for effect in effects:
                effect_config[effect[0]] = effect[1]

        effect_factory = get_effect_creator(effect_config)

        pyherc.vtable["\ufdd0:create-effect"] = effect_factory      

        drink_factory = DrinkFactory(effect_factory)

        inventory_factory = InventoryFactory([PickUpFactory(),
                                              DropFactory(),
                                              EquipFactory(),
                                              UnEquipFactory()])

        spell_factory = SpellGenerator()

        spell_casting_factory = SpellCastingFactory(spell_factory,
                                                    effect_factory)

        mitosis_factory = MitosisFactory(self.creature_generator,
                                         self.rng,
                                         60)

        metamorphosis_factory = MetamorphosisFactory(self.creature_generator,
                                                     self.rng)

        dig_factory = DigFactory(self.rng)

        trapping_factory = TrappingFactory(self.trap_generator)

        self.action_factory = ActionFactory(self.model,
                                            [drink_factory,
                                             inventory_factory,
                                             spell_casting_factory,
                                             mitosis_factory,
                                             metamorphosis_factory,
                                             dig_factory,
                                             trapping_factory])

        set_action_factory(self.action_factory)

        self.rules_engine = RulesEngine(self.action_factory)
Exemple #8
0
    def initialise_factories(self, context):
        """
        Initialises action factory, sub factories and various generators
        """
        effect_config = {}
        configurators = self.get_configurators(context.config_package,
                                               'init_effects')

        for configurator in configurators:
            effects = configurator(context)
            for effect in effects:
                effect_config[effect[0]] = effect[1]

        effect_factory = get_effect_creator(effect_config)

        pyherc.vtable["\ufdd0:create-effect"] = effect_factory

        drink_factory = DrinkFactory(effect_factory)

        inventory_factory = InventoryFactory(
            [PickUpFactory(),
             DropFactory(),
             EquipFactory(),
             UnEquipFactory()])

        spell_factory = SpellGenerator()

        spell_casting_factory = SpellCastingFactory(spell_factory,
                                                    effect_factory)

        mitosis_factory = MitosisFactory(self.creature_generator, self.rng, 60)

        metamorphosis_factory = MetamorphosisFactory(self.creature_generator,
                                                     self.rng)

        dig_factory = DigFactory(self.rng)

        trapping_factory = TrappingFactory(self.trap_generator)

        self.action_factory = ActionFactory(self.model, [
            drink_factory, inventory_factory, spell_casting_factory,
            mitosis_factory, metamorphosis_factory, dig_factory,
            trapping_factory
        ])

        set_action_factory(self.action_factory)

        self.rules_engine = RulesEngine(self.action_factory)
Exemple #9
0
    def setup(self):
        """
        Setup the test case
        """
        self.rng = Random()
        self.model = mock()

        self.effect_factory = get_effect_creator({'heal':
                                  {'type': Heal,
                                   'duration': 0,
                                   'frequency': 0,
                                   'tick': 0,
                                   'healing': 10,
                                   'icon': 101,
                                   'title': 'title',
                                   'description': 'major heal'}})

        drink_factory = DrinkFactory(self.effect_factory)
        set_action_factory(ActionFactory(self.model,
                                         drink_factory))

        self.character = (CharacterBuilder()
                            .with_hit_points(1)
                            .with_max_hp(5)
                            .build())
        effect = (HealBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_healing(5)
                    .with_target(self.character)
                    .build())

        self.potion = (ItemBuilder()
                            .with_name('healing potion')
                            .with_effect_handle(
                                EffectHandleBuilder()
                                    .with_trigger('on drink')
                                    .with_effect('heal'))
                            .build())

        self.character.inventory.append(self.potion)
    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())
    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))
    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())
Exemple #13
0
    def test_creating_poison(self):
        """
        Test that poison effect can be created
        """
        character = CharacterBuilder().build()
        effects = get_effect_creator({'poison':
                                        {'type': Poison,
                                         'duration': 150,
                                         'frequency': 30,
                                         'tick': 10,
                                         'damage': 5,
                                         'icon': 101,
                                         'title': 'Moderate poison',
                                         'description': 'Causes damage'}})

        effect = effects('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)))
        assert_that(effect.icon, is_(equal_to(101)))
        assert_that(effect.title, is_(equal_to('Moderate poison')))
        assert_that(effect.description, is_(equal_to('Causes damage')))
Exemple #14
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()